Browse Source

Enable indirect diffuse for light shading

Panagiotis Christopoulos Charitos 6 years ago
parent
commit
811e939b14

+ 1 - 1
shaders/LightFunctions.glsl

@@ -294,7 +294,7 @@ Vec3 sampleGlobalIllumination(const Vec3 worldPos,
 	{
 	{
 		// Point to the correct UV
 		// Point to the correct UV
 		Vec3 shiftedUVw = uvw;
 		Vec3 shiftedUVw = uvw;
-		shiftedUVw.x += probe.m_volumeSizeUOver6 * F32(dir);
+		shiftedUVw.x += (1.0 / 6.0) * F32(dir);
 
 
 		irradiancePerDir[dir] =
 		irradiancePerDir[dir] =
 			textureLod(textures[nonuniformEXT(probe.m_textureIndex)], linearAnyClampSampler, shiftedUVw, 0.0).rgb;
 			textureLod(textures[nonuniformEXT(probe.m_textureIndex)], linearAnyClampSampler, shiftedUVw, 0.0).rgb;

+ 4 - 13
shaders/LightShading.glslp

@@ -164,11 +164,10 @@ void main()
 		out_color += (diffC + specC) * light.m_diffuseColor * (att * spot * max(gbuffer.m_subsurface, lambert));
 		out_color += (diffC + specC) * light.m_diffuseColor * (att * spot * max(gbuffer.m_subsurface, lambert));
 	}
 	}
 
 
-	// Refl & indirect
+	// Indirect specular
 	{
 	{
 		// Do the probe read
 		// Do the probe read
 		Vec3 specIndirect = Vec3(0.0);
 		Vec3 specIndirect = Vec3(0.0);
-		Vec3 diffIndirect = Vec3(0.0);
 
 
 		const Vec3 reflDir = reflect(-viewDir, gbuffer.m_normal);
 		const Vec3 reflDir = reflect(-viewDir, gbuffer.m_normal);
 		const F32 reflLod = F32(IR_MIPMAP_COUNT - 1u) * gbuffer.m_roughness;
 		const F32 reflLod = F32(IR_MIPMAP_COUNT - 1u) * gbuffer.m_roughness;
@@ -192,17 +191,10 @@ void main()
 			Vec4 cubeArrUv = Vec4(cubeUv, cubemapIndex);
 			Vec4 cubeArrUv = Vec4(cubeUv, cubemapIndex);
 			Vec3 c = textureLod(u_reflectionsTex, u_trilinearClampSampler, cubeArrUv, reflLod).rgb;
 			Vec3 c = textureLod(u_reflectionsTex, u_trilinearClampSampler, cubeArrUv, reflLod).rgb;
 			specIndirect += c * blendWeight;
 			specIndirect += c * blendWeight;
-
-			// Sample irradiance
-			cubeUv = intersectProbe(worldPos, gbuffer.m_normal, aabbMin, aabbMax, probeOrigin);
-			cubeArrUv = Vec4(cubeUv, cubemapIndex);
-			c = textureLod(u_irradianceTex, u_trilinearClampSampler, cubeArrUv, 0.0).rgb;
-			diffIndirect += c * blendWeight;
 		}
 		}
 
 
 		// Normalize the colors
 		// Normalize the colors
 		specIndirect /= totalBlendWeight;
 		specIndirect /= totalBlendWeight;
-		diffIndirect /= totalBlendWeight;
 
 
 		// Read the SSL result
 		// Read the SSL result
 		const Vec4 ssr = textureLod(u_ssrRt, u_trilinearClampSampler, in_uv, 0.0);
 		const Vec4 ssr = textureLod(u_ssrRt, u_trilinearClampSampler, in_uv, 0.0);
@@ -215,10 +207,10 @@ void main()
 		const Vec3 env =
 		const Vec3 env =
 			envBRDF(gbuffer.m_specular, gbuffer.m_roughness, u_integrationLut, u_trilinearClampSampler, NoV);
 			envBRDF(gbuffer.m_specular, gbuffer.m_roughness, u_integrationLut, u_trilinearClampSampler, NoV);
 
 
-		out_color += diffIndirect * gbuffer.m_diffuse + finalRefl * env;
+		out_color += finalRefl * env;
 	}
 	}
 
 
-	// Read GI
+	// Indirect diffuse
 	{
 	{
 		Vec3 diffIndirect = Vec3(0.0);
 		Vec3 diffIndirect = Vec3(0.0);
 		F32 totalBlendWeight = EPSILON;
 		F32 totalBlendWeight = EPSILON;
@@ -241,8 +233,7 @@ void main()
 		// Normalize
 		// Normalize
 		diffIndirect /= totalBlendWeight;
 		diffIndirect /= totalBlendWeight;
 
 
-		//out_color += diffIndirect * gbuffer.m_diffuse;
-		out_color = diffIndirect;
+		out_color += diffIndirect * gbuffer.m_diffuse;
 	}
 	}
 }
 }
 #pragma anki end
 #pragma anki end

+ 1 - 4
shaders/glsl_cpp_common/ClusteredShading.h

@@ -112,12 +112,9 @@ struct GlobalIlluminationProbe
 	U32 m_textureIndex;
 	U32 m_textureIndex;
 
 
 	Vec3 m_aabbMax;
 	Vec3 m_aabbMax;
-	F32 m_volumeSizeUOver6; // textureSize(texArr[m_textureIndex]).x / 6
-
-	Vec3 m_padding0;
 	F32 m_halfTexelSizeU; // (1.0 / textureSize(texArr[m_textureIndex]).x) / 2.0
 	F32 m_halfTexelSizeU; // (1.0 / textureSize(texArr[m_textureIndex]).x) / 2.0
 };
 };
-const U32 SIZEOF_GLOBAL_ILLUMINATION_PROBE = 3u * SIZEOF_VEC4;
+const U32 SIZEOF_GLOBAL_ILLUMINATION_PROBE = 2u * SIZEOF_VEC4;
 ANKI_SHADER_STATIC_ASSERT(sizeof(GlobalIlluminationProbe) == SIZEOF_GLOBAL_ILLUMINATION_PROBE)
 ANKI_SHADER_STATIC_ASSERT(sizeof(GlobalIlluminationProbe) == SIZEOF_GLOBAL_ILLUMINATION_PROBE)
 
 
 // Common uniforms for light shading passes
 // Common uniforms for light shading passes

+ 0 - 1
src/anki/renderer/ClusterBin.cpp

@@ -800,7 +800,6 @@ void ClusterBin::writeTypedObjectsToGpuBuffers(BinCtx& ctx) const
 			out.m_aabbMin = in.m_aabbMin;
 			out.m_aabbMin = in.m_aabbMin;
 			out.m_aabbMax = in.m_aabbMax;
 			out.m_aabbMax = in.m_aabbMax;
 			out.m_textureIndex = &in - &rqueue.m_giProbes.getFront();
 			out.m_textureIndex = &in - &rqueue.m_giProbes.getFront();
-			out.m_volumeSizeUOver6 = F32(in.m_cellCounts.x()) / 6.0f;
 			out.m_halfTexelSizeU = 1.0f / in.m_cellCounts.x() / 2.0f;
 			out.m_halfTexelSizeU = 1.0f / in.m_cellCounts.x() / 2.0f;
 		}
 		}
 	}
 	}

+ 1 - 1
src/anki/renderer/LightShading.cpp

@@ -138,7 +138,7 @@ void LightShading::run(RenderPassWorkContext& rgraphCtx)
 		bindStorage(cmdb, 0, 11, rsrc.m_indicesToken);
 		bindStorage(cmdb, 0, 11, rsrc.m_indicesToken);
 
 
 		cmdb->bindSampler(0, 12, m_r->getSamplers().m_nearestNearestClamp);
 		cmdb->bindSampler(0, 12, m_r->getSamplers().m_nearestNearestClamp);
-		cmdb->bindSampler(0, 13, m_r->getSamplers().m_trilinearRepeat);
+		cmdb->bindSampler(0, 13, m_r->getSamplers().m_trilinearClamp);
 		rgraphCtx.bindColorTexture(0, 14, m_r->getGBuffer().getColorRt(0));
 		rgraphCtx.bindColorTexture(0, 14, m_r->getGBuffer().getColorRt(0));
 		rgraphCtx.bindColorTexture(0, 15, m_r->getGBuffer().getColorRt(1));
 		rgraphCtx.bindColorTexture(0, 15, m_r->getGBuffer().getColorRt(1));
 		rgraphCtx.bindColorTexture(0, 16, m_r->getGBuffer().getColorRt(2));
 		rgraphCtx.bindColorTexture(0, 16, m_r->getGBuffer().getColorRt(2));

+ 3 - 8
src/anki/scene/components/GlobalIlluminationProbeComponent.h

@@ -129,14 +129,9 @@ private:
 	/// Recalc come values.
 	/// Recalc come values.
 	void updateMembers()
 	void updateMembers()
 	{
 	{
-		for(U i = 0; i < 3; ++i)
-		{
-			ANKI_ASSERT(m_aabbMax[i] > m_aabbMin[i]);
-
-			const F32 dist = m_aabbMax[i] - m_aabbMin[i];
-			m_cellCounts[i] = U32(ceil(dist / m_cellSize));
-			ANKI_ASSERT(m_cellCounts[i] > 0);
-		}
+		const Vec3 dist = m_aabbMax - m_aabbMin;
+		m_cellCounts = UVec3(dist / m_cellSize);
+		m_cellCounts = m_cellCounts.max(UVec3(1));
 	}
 	}
 };
 };
 /// @}
 /// @}