@@ -11,28 +11,18 @@ layout(set = 2, binding = 1) uniform usampler2D scramblebuf;
11
11
// vis buffer
12
12
layout(set = 2, binding = 2) uniform sampler2D depthbuf;
13
13
layout(set = 2, binding = 3) uniform usampler2D frontFacing_Object_Triangle;
14
- //layout(set = 2, binding = 3) uniform sampler2D barycentricDerivatives;
15
14
layout(set = 2, binding = 4) uniform sampler2D encodedNormal;
16
15
layout(set = 2, binding = 5) uniform sampler2D uvCoords;
16
+ //layout(set = 2, binding = 6) uniform sampler2D barycentricDerivatives; // in the future we shall compute them from triangle vertex positions
17
17
18
18
19
19
#include "bin/material_declarations.glsl"
20
-
21
- /*
22
- // something to get our GLSL intellisense to "shut up"
23
- #ifndef _NBL_EXT_MITSUBA_LOADER_VT_STORAGE_VIEW_COUNT
24
- #define _NBL_EXT_MITSUBA_LOADER_VT_STORAGE_VIEW_COUNT 4
25
- #include <nbl/builtin/glsl/virtual_texturing/impl_functions.glsl>
26
- #endif
27
- */
28
- #include <nbl/builtin/glsl/ext/MitsubaLoader/material_compiler_compatibility_impl.glsl>
29
-
30
20
vec3 normalizedV;
31
21
vec3 nbl_glsl_MC_getNormalizedWorldSpaceV()
32
22
{
33
23
return normalizedV;
34
24
}
35
- vec3 normalizedN;
25
+ vec3 normalizedN; // TODO
36
26
vec3 nbl_glsl_MC_getNormalizedWorldSpaceN()
37
27
{
38
28
return normalizedN;
@@ -128,71 +118,6 @@ bool gen_sample_ray(out float maxT, out vec3 direction, out vec3 throughput, in
128
118
return true;
129
119
}
130
120
131
- #ifdef TODO
132
- // TODO: define lower and upper bound over `lightCDF`
133
- vec3 light_sample(out vec3 incoming, in uint sampleIx, in uint scramble, inout float maxT, inout bool alive, in vec3 position)
134
- {
135
- uint lightIDSample = ugen_uniform_sample1(0u,sampleIx,scramble);
136
- vec2 lightSurfaceSample = gen_uniform_sample2(2u,sampleIx,scramble);
137
-
138
- uint lightID = upper_bound(lightIDSample,uint(lightCDF.length()-1));
139
-
140
- SLight light = light[lightID];
141
-
142
- #define SHADOW_RAY_LEN 0.93
143
- float factor; // 1.0/light_probability already baked into the light factor
144
- switch (SLight_extractType(light))
145
- {
146
- case SLight_ET_ELLIPSOID:
147
- lightSurfaceSample.x = lightSurfaceSample.x*2.0-1.0;
148
- {
149
- mat4x3 tform = light.transform;
150
- float equator = lightSurfaceSample.y*2.0*kPI;
151
- vec3 pointOnSurface = vec3(vec2(cos(equator),sin(equator))*sqrt(1.0-lightSurfaceSample.x*lightSurfaceSample.x),lightSurfaceSample.x);
152
-
153
- incoming = mat3(tform)*pointOnSurface+(tform[3]-position);
154
- float incomingInvLen = inversesqrt(dot(incoming,incoming));
155
- incoming *= incomingInvLen;
156
-
157
- maxT = SHADOW_RAY_LEN/incomingInvLen;
158
-
159
- factor = 4.0*kPI; // compensate for the domain of integration
160
- // don't normalize, length of the normal times determinant is very handy for differential area after a 3x3 matrix transform
161
- vec3 negLightNormal = light.transformCofactors*pointOnSurface;
162
-
163
- factor *= max(dot(negLightNormal,incoming),0.0)*incomingInvLen*incomingInvLen;
164
- }
165
- break;
166
- default: // SLight_ET_TRIANGLE:
167
- {
168
- vec3 pointOnSurface = transpose(light.transformCofactors)[0];
169
- vec3 shortEdge = transpose(light.transformCofactors)[1];
170
- vec3 longEdge = transpose(light.transformCofactors)[2];
171
-
172
- lightSurfaceSample.x = sqrt(lightSurfaceSample.x);
173
-
174
- pointOnSurface += (shortEdge*(1.0-lightSurfaceSample.y)+longEdge*lightSurfaceSample.y)*lightSurfaceSample.x;
175
-
176
- vec3 negLightNormal = cross(shortEdge,longEdge);
177
-
178
- incoming = pointOnSurface-position;
179
- float incomingInvLen = inversesqrt(dot(incoming,incoming));
180
- incoming *= incomingInvLen;
181
-
182
- maxT = SHADOW_RAY_LEN/incomingInvLen;
183
-
184
- factor = 0.5*max(dot(negLightNormal,incoming),0.0)*incomingInvLen*incomingInvLen;
185
- }
186
- break;
187
- }
188
-
189
- if (factor<FLT_MIN)
190
- alive = false;
191
-
192
- return light.factor*factor;
193
- }
194
- #endif
195
-
196
121
void main()
197
122
{
198
123
uvec2 outputLocation = gl_GlobalInvocationID.xy;
@@ -235,7 +160,7 @@ void main()
235
160
const vec2 NDC = vec2(outputLocation)*staticViewData.rcpPixelSize+staticViewData.rcpHalfPixelSize;
236
161
237
162
const vec3 V = mix(frustumCornersToCamera[1]*NDC.x+frustumCornersToCamera[0],frustumCornersToCamera[3]*NDC.x+frustumCornersToCamera[2],NDC.yyy); // could maybe compute this more precisely
238
- worldPosition = pc.cummon.normalMatrixAndCameraPos[3] -V*linearizeZBufferVal(revdepth);
163
+ worldPosition = pc.cummon.cameraPosition -V*linearizeZBufferVal(revdepth);
239
164
normalizedV = normalize(V);
240
165
}
241
166
@@ -252,12 +177,15 @@ void main()
252
177
material = nbl_glsl_MC_material_data_t_getOriented(InstData.data[objectID].material,precomputed.frontface);
253
178
254
179
//
255
- emissive = vec3(float(objectID),float(triangleID),0.0);// nbl_glsl_MC_oriented_material_t_getEmissive(material);
180
+ emissive = nbl_glsl_MC_oriented_material_t_getEmissive(material);
256
181
}
257
182
258
183
// normally we'd use MeshPackerV2's vertex attribute data for this, but now we read from temporary GBuffer
259
184
{
260
- normalizedN = nbl_glsl_NormalDecode_signedSpherical(normalBuffer);
185
+ const vec3 normal = nbl_glsl_NormalDecode_signedSpherical(normalBuffer);
186
+ normalizedN.x = dot(InstData.data[objectID].normalMatrixRow0,normal);
187
+ normalizedN.y = dot(InstData.data[objectID].normalMatrixRow1,normal);
188
+ normalizedN.z = dot(InstData.data[objectID].normalMatrixRow2,normal);
261
189
}
262
190
263
191
//
0 commit comments