|
1 | 1 | // basic settings
|
2 | 2 | #define MAX_DEPTH 2
|
3 |
| -#define SAMPLES 16 |
| 3 | +#define SAMPLES 1 |
4 | 4 |
|
5 | 5 | // firefly and variance reduction techniques
|
6 | 6 | //#define KILL_DIFFUSE_SPECULAR_PATHS
|
@@ -84,59 +84,48 @@ float Sphere_getSolidAngle(in Sphere sphere, in vec3 origin)
|
84 | 84 |
|
85 | 85 | struct Triangle
|
86 | 86 | {
|
87 |
| - /* |
88 | 87 | vec3 vertex0;
|
89 | 88 | uint bsdfLightIDs;
|
90 | 89 | vec3 vertex1;
|
91 |
| - uint padding; |
| 90 | + uint padding0; |
92 | 91 | vec3 vertex2;
|
93 |
| - uint padding; |
94 |
| - */ |
95 |
| - vec4 planeEq; |
96 |
| - vec4 boundaryPlanes[2]; |
97 |
| - float area; |
98 |
| - uint bsdfLightIDs; |
| 92 | + uint padding1; |
99 | 93 | };
|
100 | 94 |
|
101 | 95 | Triangle Triangle_Triangle(in mat3 vertices, in uint bsdfID, in uint lightID)
|
102 | 96 | {
|
103 |
| - const vec3 edges[2] = vec3[2](vertices[1]-vertices[0],vertices[2]-vertices[0]); |
104 |
| - // |
105 | 97 | Triangle tri;
|
106 |
| - tri.planeEq.xyz = cross(edges[0],edges[1]); |
107 |
| - tri.boundaryPlanes[0].xyz = cross(tri.planeEq.xyz,edges[0]); |
108 |
| - tri.boundaryPlanes[0].xyz/= dot(tri.boundaryPlanes[0].xyz,edges[1]); |
109 |
| - tri.boundaryPlanes[1].xyz = cross(edges[1],tri.planeEq.xyz); |
110 |
| - tri.boundaryPlanes[1].xyz/= dot(tri.boundaryPlanes[1].xyz,edges[0]); |
111 |
| - // |
112 |
| - tri.planeEq.w = dot(tri.planeEq.xyz, vertices[0]); |
113 |
| - tri.boundaryPlanes[0].w = -dot(tri.boundaryPlanes[0].xyz, vertices[0]); |
114 |
| - tri.boundaryPlanes[1].w = -dot(tri.boundaryPlanes[1].xyz, vertices[0]); |
115 |
| - // |
116 |
| - tri.area = length(tri.planeEq.xyz)*0.5; |
| 98 | + tri.vertex0 = vertices[0]; |
| 99 | + tri.vertex1 = vertices[1]; |
| 100 | + tri.vertex2 = vertices[2]; |
117 | 101 | //
|
118 | 102 | tri.bsdfLightIDs = bitfieldInsert(bsdfID, lightID, 16, 16);
|
119 | 103 | return tri;
|
120 | 104 | }
|
121 | 105 |
|
122 |
| - |
123 | 106 | // return intersection distance if found, FLT_NAN otherwise
|
124 | 107 | float Triangle_intersect(in Triangle tri, in vec3 origin, in vec3 direction)
|
125 | 108 | {
|
126 |
| - const float NdotD = dot(direction,tri.planeEq.xyz); |
127 |
| - const float t = (tri.planeEq.w-dot(origin,tri.planeEq.xyz))/NdotD; |
128 |
| - // speculative intersection |
129 |
| - const vec3 intersectionPoint = origin+direction*t; |
130 |
| - const float distToEdge[2] = float[2]( |
131 |
| - dot(intersectionPoint,tri.boundaryPlanes[0].xyz)+tri.boundaryPlanes[0].w, |
132 |
| - dot(intersectionPoint,tri.boundaryPlanes[1].xyz)+tri.boundaryPlanes[1].w |
133 |
| - ); |
134 |
| - return t<0.f||distToEdge[0]<0.f||distToEdge[1]<0.f||(distToEdge[0]+distToEdge[1])>1.f ? irr_glsl_FLT_NAN:t; |
| 109 | + const vec3 edges[2] = vec3[2](tri.vertex1-tri.vertex0,tri.vertex2-tri.vertex0); |
| 110 | + |
| 111 | + const vec3 h = cross(direction,edges[1]); |
| 112 | + const float a = dot(edges[0],h); |
| 113 | + |
| 114 | + const vec3 relOrigin = origin-tri.vertex0; |
| 115 | + |
| 116 | + const float u = dot(relOrigin,h)/a; |
| 117 | + |
| 118 | + const vec3 q = cross(relOrigin,edges[0]); |
| 119 | + const float v = dot(direction,q)/a; |
| 120 | + |
| 121 | + const float t = dot(edges[1],q)/a; |
| 122 | + |
| 123 | + return t>0.f&&u>=0.f&&v>=0.f&&(u+v)<=1.f ? t:irr_glsl_FLT_NAN; |
135 | 124 | }
|
136 | 125 |
|
137 | 126 | vec3 Triangle_getNormalTimesArea(in Triangle tri)
|
138 | 127 | {
|
139 |
| - return tri.planeEq.xyz; |
| 128 | + return cross(tri.vertex1-tri.vertex0,tri.vertex2-tri.vertex0)*0.5; |
140 | 129 | }
|
141 | 130 |
|
142 | 131 |
|
@@ -183,7 +172,7 @@ float BSDFNode_getMISWeight(in BSDFNode bsdf)
|
183 | 172 | {
|
184 | 173 | const float alpha = BSDFNode_getRoughness(bsdf);
|
185 | 174 | const bool notDiffuse = BSDFNode_isNotDiffuse(bsdf);
|
186 |
| - const float DIFFUSE_MIS_WEIGHT = 0.5; |
| 175 | + const float DIFFUSE_MIS_WEIGHT = 0.0; |
187 | 176 | return notDiffuse ? mix(1.0,DIFFUSE_MIS_WEIGHT,alpha):DIFFUSE_MIS_WEIGHT; // TODO: test alpha*alpha
|
188 | 177 | }
|
189 | 178 |
|
@@ -311,7 +300,7 @@ void missProgram()
|
311 | 300 | vec2 uv = SampleSphericalMap(rayStack[stackPtr]._immutable.direction);
|
312 | 301 | finalContribution *= textureLod(envMap, uv, 0.0).rgb;
|
313 | 302 | #else
|
314 |
| - const vec3 kConstantEnvLightRadiance = vec3(0.15,0.21,0.3); |
| 303 | + const vec3 kConstantEnvLightRadiance = vec3(0.0);// 0.15, 0.21, 0.3); |
315 | 304 | finalContribution *= kConstantEnvLightRadiance;
|
316 | 305 | #endif
|
317 | 306 | }
|
|
0 commit comments