@@ -47,7 +47,7 @@ layout(location = 1) out vec4 outBrightColor;
4747layout (set = 0 , binding = 2 ) uniform sampler2DArray shadowMap;
4848layout (set = 0 , binding = 4 ) uniform samplerCube irradianceMap;
4949layout (set = 0 , binding = 5 ) uniform accelerationStructureEXT TLAS;
50- layout (set = 0 , binding = 6 ) uniform sampler2D blueNoiseMap ;
50+ layout (set = 0 , binding = 6 ) uniform sampler2D samplerMap ;
5151layout (set = 0 , binding = 7 ) uniform sampler3D voxelMap;
5252// G-BUFFER
5353layout (set = 1 , binding = 0 ) uniform sampler2D positionBuffer;
@@ -56,7 +56,7 @@ layout(set = 1, binding = 2) uniform sampler2D colorBuffer;
5656layout (set = 1 , binding = 3 ) uniform sampler2D materialBuffer;
5757layout (set = 1 , binding = 4 ) uniform sampler2D emissionBuffer;
5858layout (set = 1 , binding = 5 ) uniform sampler2D preCompositionBuffer;
59-
59+ // TEMPORAL
6060layout (set = 1 , binding = 6 ) uniform sampler2D prevBuffer;
6161
6262// SETTINGS
@@ -87,70 +87,6 @@ int g_isReflective;
8787vec4 g_temp;
8888
8989
90-
91- vec3 GI(vec3 worldPos, vec3 worldNormal){
92- const float VOXEL_SIZE = 1.0 / float (settings.vxgi.resolution);
93- const float ISQRT2 = 0.707106 ;
94- const float ANGLE_MIX = 0.5 ; // Angle mix (1.0f => orthogonal direction, 0.0f => direction of normal).
95- const float w[3 ] = {1.0 , 1.0 , 1.0 }; // Cone weights.
96-
97- // Find a base for the side cones with the normal as one of its base vectors.
98- const vec3 ortho = normalize (orthogonal(worldNormal));
99- const vec3 ortho2 = normalize (cross (ortho, worldNormal));
100-
101- // Find base vectors for the corner cones too.
102- const vec3 corner = 0.5 * (ortho + ortho2);
103- const vec3 corner2 = 0.5 * (ortho - ortho2);
104-
105- // Find start position of trace (start with a bit of offset).
106- const vec3 N_OFFSET = worldNormal * (1 + 4 * ISQRT2) * VOXEL_SIZE;
107- const vec3 C_ORIGIN = worldPos + N_OFFSET;
108-
109- // Accumulate indirect diffuse light.
110- vec3 indirect = vec3 (0 );
111-
112- // We offset forward in normal direction, and backward in cone direction.
113- // Backward in cone direction improves GI, and forward direction removes
114- // artifacts.
115- const float CONE_OFFSET = - 0.01 ;
116- const float CONE_SPREAD = 0.325 ;
117-
118- // Trace front cone
119- indirect += w[0 ] * traceVoxelCone(voxelMap, C_ORIGIN + CONE_OFFSET * worldNormal, worldNormal,CONE_SPREAD, VOXEL_SIZE );
120-
121- // Trace 4 side cones.
122- const vec3 s1 = mix (worldNormal, ortho, ANGLE_MIX);
123- indirect += w[1 ] * traceVoxelCone(voxelMap, C_ORIGIN + CONE_OFFSET * ortho, s1,CONE_SPREAD, VOXEL_SIZE );
124-
125- const vec3 s2 = mix (worldNormal, - ortho, ANGLE_MIX);
126- indirect += w[1 ] * traceVoxelCone(voxelMap, C_ORIGIN - CONE_OFFSET * ortho, s2,CONE_SPREAD, VOXEL_SIZE );
127-
128- const vec3 s3 = mix (worldNormal, ortho2, ANGLE_MIX);
129- indirect += w[1 ] * traceVoxelCone(voxelMap, C_ORIGIN + CONE_OFFSET * ortho2, s3,CONE_SPREAD, VOXEL_SIZE );
130-
131- const vec3 s4 = mix (worldNormal, - ortho2, ANGLE_MIX);
132- indirect += w[1 ] * traceVoxelCone(voxelMap, C_ORIGIN - CONE_OFFSET * ortho2, s4,CONE_SPREAD, VOXEL_SIZE );
133-
134- // Trace 4 corner cones.
135- const vec3 c1 = mix (worldNormal, corner, ANGLE_MIX);
136- indirect += w[2 ] * traceVoxelCone(voxelMap, C_ORIGIN + CONE_OFFSET * corner, c1,CONE_SPREAD, VOXEL_SIZE );
137-
138- const vec3 c2 = mix (worldNormal, - corner, ANGLE_MIX);
139- indirect += w[2 ] * traceVoxelCone(voxelMap, C_ORIGIN - CONE_OFFSET * corner, c2,CONE_SPREAD, VOXEL_SIZE );
140-
141- const vec3 c3 = mix (worldNormal, corner2, ANGLE_MIX);
142- indirect += w[2 ] * traceVoxelCone(voxelMap, C_ORIGIN + CONE_OFFSET * corner2, c3,CONE_SPREAD, VOXEL_SIZE );
143-
144- const vec3 c4 = mix (worldNormal, - corner2, ANGLE_MIX);
145- indirect += w[2 ] * traceVoxelCone(voxelMap, C_ORIGIN - CONE_OFFSET * corner2, c4,CONE_SPREAD, VOXEL_SIZE );
146-
147- // Return result.
148- // return DIFFUSE_INDIRECT_FACTOR * material.diffuseReflectivity * acc * (material.diffuseColor + vec3(0.001f));
149- return indirect;
150-
151-
152- }
153-
15490void main()
15591{
15692
@@ -209,55 +145,27 @@ void main()
209145 brdf.F0 = vec3 (0.04 );
210146 brdf.F0 = mix (brdf.F0, brdf.albedo, brdf.metalness);
211147 brdf.emission = g_emission;
212- // Indirect Component ____________________________
213- if (settings.vxgi.enabled == 1 ){
214- vec3 diffuseIndirect = vec3 (0.0 );
215-
216- const float VOXEL_SIZE = 1.0 / float (settings.vxgi.resolution);
217148
218149
219- // Offset startPos to avoid self occlusion
220- vec3 startPos = modelPos + modelNormal * VOXEL_SIZE;
221-
222- float coneTraceCount = 0.0 ;
223- float cosSum = 0.0 ;
224- for (int i = 0 ; i < DIFFUSE_CONE_COUNT; ++ i)
225- {
226- float cosTheta = dot (modelNormal, DIFFUSE_CONE_DIRECTIONS[i]);
227-
228- if (cosTheta < 0.0 )
229- continue ;
230-
231- coneTraceCount += 1.0 ;
232- diffuseIndirect += traceVoxelCone(voxelMap, startPos, DIFFUSE_CONE_DIRECTIONS[i],DIFFUSE_CONE_APERTURE , VOXEL_SIZE );
233- }
234-
235- diffuseIndirect /= coneTraceCount;
236- // indirectContribution.a *= u_ambientOcclusionFactor;
237-
238- diffuseIndirect.rgb *= g_albedo * settings.vxgi.strength;
239-
240-
241- indirect = diffuseIndirect.rgb;
150+ // Indirect Component ____________________________
151+ if (settings.vxgi.enabled == 1 ){
242152
153+ vec4 diffuseIndirect = diffuseVoxelGI(voxelMap, modelPos, modelNormal, settings.vxgi, scene.maxCoord.x- scene.minCoord.x);
243154
244- // indirect = GI(modelPos, modelNormal)*settings.vxgi.strength* g_albedo;
245- indirect*= settings.enableAO == 1 ? (brdf.ao * SSAO) : brdf.ao;
155+ indirect = diffuseIndirect.rgb * g_albedo;
156+ indirect*= settings.enableAO == 1 ? (brdf.ao * SSAO) : brdf.ao; // Add ambient occlusion
246157
247158 // vec3 specularConeDirection = reflect(normalize(camera.position.xyz-modelPos), modelNormal);
248159 // vec3 specularIndirect = vec3(0.0);
249-
250-
251160 // specularIndirect = traceVoxelCone(voxelMap, startPos, specularConeDirection, max(brdf.roughness, 0.05) , VOXEL_SIZE );
252161 // // specularIndirect = castCone(startPos, specularConeDirection, max(roughness, MIN_SPECULAR_APERTURE), MAX_TRACE_DISTANCE, minLevel).rgb * specColor.rgb * u_indirectSpecularIntensity;
253162 // indirect2+=specularIndirect;
254163 }
255-
256-
257164 // Direct Component ________________________
258165 for (int i = 0 ; i < scene.numLights; i++ ) {
259166 // If inside liught area influence
260167 if (isInAreaOfInfluence(scene.lights[i].position, g_pos,scene.lights[i].areaEffect,int (scene.lights[i].type))){
168+
261169 // Direct Component ________________________
262170 vec3 lighting = vec3 (0.0 );
263171 lighting = evalSchlickSmithBRDF(
@@ -266,7 +174,8 @@ void main()
266174 scene.lights[i].color * computeAttenuation(scene.lights[i].position, g_pos,scene.lights[i].areaEffect,int (scene.lights[i].type)) * scene.lights[i].intensity, // radiance
267175 brdf
268176 );
269- // Shadow Component ________________________
177+
178+ // Visibility Component ________________________
270179 if (scene.lights[i].shadowCast == 1 ) {
271180 if (scene.lights[i].shadowType == 0 ) // Classic
272181 lighting *= computeShadow(shadowMap, scene.lights[i], i, modelPos);
@@ -275,7 +184,7 @@ void main()
275184 if (scene.lights[i].shadowType == 2 ) // Raytraced
276185 lighting *= computeRaytracedShadow(
277186 TLAS,
278- blueNoiseMap ,
187+ samplerMap ,
279188 modelPos,
280189 scene.lights[i].type != DIRECTIONAL_LIGHT ? scene.lights[i].worldPosition.xyz - modelPos : scene.lights[i].shadowData.xyz,
281190 int (scene.lights[i].shadowData.w),
0 commit comments