|
| 1 | +/* |
| 2 | + * Copyright LWJGL. All rights reserved. |
| 3 | + * License terms: https://www.lwjgl.org/license |
| 4 | + */ |
1 | 5 | package org.lwjgl.demo.util; |
2 | 6 |
|
3 | 7 | import org.joml.Vector2f; |
@@ -27,22 +31,20 @@ private static int idx(int x, int y, int lod) { |
27 | 31 | private static float mix(float a, float b, float v) { |
28 | 32 | return a*(1-v) + b*v; |
29 | 33 | } |
30 | | - private static float step(float edge, float x) { |
31 | | - return x < edge ? 0 : 1; |
| 34 | + private static float step(float edge, float v) { |
| 35 | + return v < edge ? 0 : 1; |
32 | 36 | } |
33 | 37 |
|
34 | 38 | public static Vector2i sample(float[][] levels, Vector2f u, float[] pdf) { |
35 | 39 | int x = 0, y = 0; |
36 | 40 | pdf[0] = 1.0f; |
37 | 41 | for (int lod = 0; lod < levels.length; lod++) { |
38 | 42 | // here, lod=0 is the _highest_ lod level (with the smallest image dimension) |
| 43 | + // so we "ascend" the lod levels from the coarsest to the finest/biggest level. |
39 | 44 | x <<= 1; y <<= 1; |
40 | | - float s0 = levels[lod][idx(x ,y ,lod)]; |
41 | | - float s1 = levels[lod][idx(x+1,y ,lod)]; |
42 | | - float s2 = levels[lod][idx(x ,y+1,lod)]; |
43 | | - float s3 = levels[lod][idx(x+1,y+1,lod)]; |
44 | | - float left = s0 + s2; |
45 | | - float right = s1 + s3; |
| 45 | + float s0 = levels[lod][idx(x ,y ,lod)], s1 = levels[lod][idx(x+1,y ,lod)]; |
| 46 | + float s2 = levels[lod][idx(x ,y+1,lod)], s3 = levels[lod][idx(x+1,y+1,lod)]; |
| 47 | + float left = s0 + s2, right = s1 + s3; |
46 | 48 | float pLeft = left / (left + right); |
47 | 49 | float uxFactor = step(pLeft, u.x); |
48 | 50 | float pLower = mix(s0 / left, s1 / right, uxFactor); |
|
0 commit comments