Panagiotis Christopoulos Charitos 7 yıl önce
ebeveyn
işleme
a523cfece6

+ 2 - 2
samples/sponza/assets/scene.lua

@@ -2511,9 +2511,9 @@ node = scene:newDirectionalLightNode("Lamp")
 lcomp = node:getSceneNodeBase():getLightComponent()
 lcomp = node:getSceneNodeBase():getLightComponent()
 lcomp:setDiffuseColor(Vec4.new(15, 15, 15, 1))
 lcomp:setDiffuseColor(Vec4.new(15, 15, 15, 1))
 trf = Transform.new()
 trf = Transform.new()
-trf:setOrigin(Vec4.new(9.66932, 40.2052, -6.74682, 0))
+trf:setOrigin(Vec4.new(-0.637397, 34.4336, -6.74682, 0))
 rot = Mat3x4.new()
 rot = Mat3x4.new()
-rot:setAll(-0.175432, -0.931125, 0.319735, 0, -0.293426, 0.359464, 0.885825, 0, -0.939747, 0.0615835, -0.336278, 0)
+rot:setAll(1, 0, 0, 0, 0, -0.376544, 0.926399, 0, 0, -0.926399, -0.376544, 0)
 trf:setRotation(rot)
 trf:setRotation(rot)
 trf:setScale(1)
 trf:setScale(1)
 node:getSceneNodeBase():getMoveComponent():setLocalTransform(trf)
 node:getSceneNodeBase():getMoveComponent():setLocalTransform(trf)

+ 1 - 1
shaders/ApplyIrradianceToReflection.glslp

@@ -33,7 +33,7 @@ void main()
 	GbufferInfo gbuffer;
 	GbufferInfo gbuffer;
 	readGBuffer(u_gbufferTex0, u_gbufferTex1, u_gbufferTex2, sampleUv, 0.0, gbuffer);
 	readGBuffer(u_gbufferTex0, u_gbufferTex1, u_gbufferTex2, sampleUv, 0.0, gbuffer);
 
 
-	// Read the irradiance. Use the layer 0 because the C++ sets an appropriate texture view
+	// Read the irradiance. Use the layer 0 because C++ will set the appropriate texture view
 	Vec3 irradiance = textureLod(u_irradianceTex, Vec4(gbuffer.m_normal, 0.0), 0.0).rgb;
 	Vec3 irradiance = textureLod(u_irradianceTex, Vec4(gbuffer.m_normal, 0.0), 0.0).rgb;
 
 
 	// Compute the indirect term
 	// Compute the indirect term

+ 1 - 1
shaders/LightFunctions.glsl

@@ -169,7 +169,7 @@ F32 computeShadowFactorDirLight(DirectionalLight light, U32 cascadeIdx, Vec3 wor
 	F32 cascadeLinearDepth = texCoords3.z;
 	F32 cascadeLinearDepth = texCoords3.z;
 
 
 	F32 shadowFactor = textureLod(shadowMap, texCoords3.xy, 0.0).r;
 	F32 shadowFactor = textureLod(shadowMap, texCoords3.xy, 0.0).r;
-	shadowFactor = saturate(exp(ESM_CONSTANT * 100.0 * (shadowFactor - cascadeLinearDepth)));
+	shadowFactor = saturate(exp(ESM_CONSTANT * 3.0 * (shadowFactor - cascadeLinearDepth)));
 
 
 	return shadowFactor;
 	return shadowFactor;
 }
 }

+ 0 - 2
shaders/LightShading.glslp

@@ -55,8 +55,6 @@ layout(location = 1) in Vec2 in_clusterIJ;
 
 
 layout(location = 0) out Vec3 out_color;
 layout(location = 0) out Vec3 out_color;
 
 
-const F32 SUBSURFACE_MIN = 0.05;
-
 // Note: All calculations in world space
 // Note: All calculations in world space
 void readReflectionsAndIrradianceFromProbes(U32 idxOffset,
 void readReflectionsAndIrradianceFromProbes(U32 idxOffset,
 	Vec3 worldPos,
 	Vec3 worldPos,

+ 14 - 1
shaders/TraditionalDeferredShading.glslp

@@ -92,6 +92,7 @@ void main()
 	// Decode and process gbuffer
 	// Decode and process gbuffer
 	GbufferInfo gbuffer;
 	GbufferInfo gbuffer;
 	readGBuffer(u_msRt0, u_msRt1, u_msRt2, uvToRead, 0.0, gbuffer);
 	readGBuffer(u_msRt0, u_msRt1, u_msRt2, uvToRead, 0.0, gbuffer);
+	gbuffer.m_subsurface = max(gbuffer.m_subsurface, SUBSURFACE_MIN * 8.0);
 
 
 	Vec4 worldPos4 = u_unis.m_invViewProjMat * Vec4(UV_TO_NDC(uv), depth, 1.0);
 	Vec4 worldPos4 = u_unis.m_invViewProjMat * Vec4(UV_TO_NDC(uv), depth, 1.0);
 	Vec3 worldPos = worldPos4.xyz / worldPos4.w;
 	Vec3 worldPos = worldPos4.xyz / worldPos4.w;
@@ -121,7 +122,19 @@ void main()
 	F32 spot = computeSpotFactor(l, u_unis.m_outerCos, u_unis.m_innerCos, u_unis.m_lightDir);
 	F32 spot = computeSpotFactor(l, u_unis.m_outerCos, u_unis.m_innerCos, u_unis.m_lightDir);
 	F32 factor = att * spot * max(lambert, gbuffer.m_subsurface);
 	F32 factor = att * spot * max(lambert, gbuffer.m_subsurface);
 #else
 #else
-	F32 shadowFactor = computeShadowFactorDirLight(u_unis.m_lightMatrix, worldPos, u_shadowMap);
+	F32 linearDepth = linearizeDepth(depth, u_unis.m_near, u_unis.m_far);
+	F32 shadowFactor;
+	if(linearDepth * (u_unis.m_far - u_unis.m_near) < u_unis.m_effectiveShadowDistance)
+	{
+		// Acceptable distance
+
+		shadowFactor = computeShadowFactorDirLight(u_unis.m_lightMatrix, worldPos, u_shadowMap);
+	}
+	else
+	{
+		shadowFactor = 1.0;
+	}
+
 	F32 lambert = dot(l, gbuffer.m_normal);
 	F32 lambert = dot(l, gbuffer.m_normal);
 	F32 factor = shadowFactor * max(gbuffer.m_subsurface, lambert);
 	F32 factor = shadowFactor * max(gbuffer.m_subsurface, lambert);
 #endif
 #endif

+ 1 - 0
shaders/glsl_cpp_common/ClusteredShading.h

@@ -16,6 +16,7 @@ const U32 TYPED_OBJECT_COUNT = 5u;
 const F32 INVALID_TEXTURE_INDEX = -1.0;
 const F32 INVALID_TEXTURE_INDEX = -1.0;
 const F32 LIGHT_FRUSTUM_NEAR_PLANE = 0.1 / 4.0; // The near plane on the shadow map frustums.
 const F32 LIGHT_FRUSTUM_NEAR_PLANE = 0.1 / 4.0; // The near plane on the shadow map frustums.
 const U32 MAX_SHADOW_CASCADES = 4u;
 const U32 MAX_SHADOW_CASCADES = 4u;
+const F32 SUBSURFACE_MIN = 0.05;
 
 
 // See the documentation in the ClustererBin class.
 // See the documentation in the ClustererBin class.
 struct ClustererMagicValues
 struct ClustererMagicValues

+ 3 - 2
shaders/glsl_cpp_common/TraditionalDeferredShading.h

@@ -68,14 +68,15 @@ struct DeferredDirectionalLightUniforms
 	F32 m_padding;
 	F32 m_padding;
 
 
 	Vec2 m_fbSize;
 	Vec2 m_fbSize;
-	Vec2 m_padding1;
+	F32 m_near;
+	F32 m_far;
 
 
 	// Light props
 	// Light props
 	Vec3 m_diffuseColor;
 	Vec3 m_diffuseColor;
 	F32 m_padding2;
 	F32 m_padding2;
 
 
 	Vec3 m_lightDir;
 	Vec3 m_lightDir;
-	F32 m_padding3;
+	F32 m_effectiveShadowDistance;
 
 
 	Mat4 m_lightMatrix;
 	Mat4 m_lightMatrix;
 };
 };

+ 4 - 1
src/anki/renderer/Indirect.cpp

@@ -97,7 +97,7 @@ Error Indirect::initGBuffer(const ConfigSet& config)
 
 
 		for(U j = 0; j < GBUFFER_COLOR_ATTACHMENT_COUNT; ++j)
 		for(U j = 0; j < GBUFFER_COLOR_ATTACHMENT_COUNT; ++j)
 		{
 		{
-			m_gbuffer.m_fbDescr.m_colorAttachments[j].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
+			m_gbuffer.m_fbDescr.m_colorAttachments[j].m_loadOperation = AttachmentLoadOperation::CLEAR;
 		}
 		}
 
 
 		m_gbuffer.m_fbDescr.m_depthStencilAttachment.m_aspect = DepthStencilAspectBit::DEPTH;
 		m_gbuffer.m_fbDescr.m_depthStencilAttachment.m_aspect = DepthStencilAspectBit::DEPTH;
@@ -210,6 +210,7 @@ Error Indirect::initShadowMapping(const ConfigSet& cfg)
 		inf.m_compareOperation = CompareOperation::LESS_EQUAL;
 		inf.m_compareOperation = CompareOperation::LESS_EQUAL;
 		inf.m_addressing = SamplingAddressing::CLAMP;
 		inf.m_addressing = SamplingAddressing::CLAMP;
 		inf.m_mipmapFilter = SamplingFilter::BASE;
 		inf.m_mipmapFilter = SamplingFilter::BASE;
+		inf.m_minMagFilter = SamplingFilter::LINEAR;
 		m_shadowMapping.m_shadowSampler = getGrManager().newSampler(inf);
 		m_shadowMapping.m_shadowSampler = getGrManager().newSampler(inf);
 	}
 	}
 
 
@@ -436,6 +437,8 @@ void Indirect::runLightShading(U32 faceIdx, RenderPassWorkContext& rgraphCtx)
 		UVec4(0, 0, m_lightShading.m_tileSize, m_lightShading.m_tileSize),
 		UVec4(0, 0, m_lightShading.m_tileSize, m_lightShading.m_tileSize),
 		Vec2(faceIdx * (1.0f / 6.0f), 0.0f),
 		Vec2(faceIdx * (1.0f / 6.0f), 0.0f),
 		Vec2((faceIdx + 1) * (1.0f / 6.0f), 1.0f),
 		Vec2((faceIdx + 1) * (1.0f / 6.0f), 1.0f),
+		probe.m_renderQueues[faceIdx]->m_cameraNear,
+		probe.m_renderQueues[faceIdx]->m_cameraFar,
 		(hasDirLight) ? &probe.m_renderQueues[faceIdx]->m_directionalLight : nullptr,
 		(hasDirLight) ? &probe.m_renderQueues[faceIdx]->m_directionalLight : nullptr,
 		rqueue.m_pointLights,
 		rqueue.m_pointLights,
 		rqueue.m_spotLights,
 		rqueue.m_spotLights,

+ 1 - 0
src/anki/renderer/RenderQueue.h

@@ -283,6 +283,7 @@ public:
 
 
 	F32 m_cameraNear;
 	F32 m_cameraNear;
 	F32 m_cameraFar;
 	F32 m_cameraFar;
+	F32 m_effectiveShadowDistance;
 
 
 	FillCoverageBufferCallback m_fillCoverageBufferCallback = nullptr;
 	FillCoverageBufferCallback m_fillCoverageBufferCallback = nullptr;
 	void* m_fillCoverageBufferCallbackUserData = nullptr;
 	void* m_fillCoverageBufferCallbackUserData = nullptr;

+ 14 - 0
src/anki/renderer/TraditionalDeferredShading.cpp

@@ -82,6 +82,8 @@ void TraditionalDeferredLightShading::drawLights(const Mat4& vpMat,
 	const UVec4& viewport,
 	const UVec4& viewport,
 	const Vec2& gbufferTexCoordsMin,
 	const Vec2& gbufferTexCoordsMin,
 	const Vec2& gbufferTexCoordsMax,
 	const Vec2& gbufferTexCoordsMax,
+	F32 cameraNear,
+	F32 cameraFar,
 	DirectionalLightQueueElement* directionalLight,
 	DirectionalLightQueueElement* directionalLight,
 	ConstWeakArray<PointLightQueueElement> plights,
 	ConstWeakArray<PointLightQueueElement> plights,
 	ConstWeakArray<SpotLightQueueElement> slights,
 	ConstWeakArray<SpotLightQueueElement> slights,
@@ -120,6 +122,18 @@ void TraditionalDeferredLightShading::drawLights(const Mat4& vpMat,
 		unis->m_lightDir = directionalLight->m_direction;
 		unis->m_lightDir = directionalLight->m_direction;
 		unis->m_lightMatrix = directionalLight->m_textureMatrices[0];
 		unis->m_lightMatrix = directionalLight->m_textureMatrices[0];
 
 
+		unis->m_near = cameraNear;
+		unis->m_far = cameraFar;
+
+		if(directionalLight->m_shadowCascadeCount > 0)
+		{
+			unis->m_effectiveShadowDistance = directionalLight->m_shadowRenderQueues[0]->m_effectiveShadowDistance;
+		}
+		else
+		{
+			unis->m_effectiveShadowDistance = 0.0f;
+		}
+
 		drawQuad(cmdb);
 		drawQuad(cmdb);
 	}
 	}
 
 

+ 2 - 0
src/anki/renderer/TraditionalDeferredShading.h

@@ -31,6 +31,8 @@ public:
 		const UVec4& viewport,
 		const UVec4& viewport,
 		const Vec2& gbufferTexCoordsMin,
 		const Vec2& gbufferTexCoordsMin,
 		const Vec2& gbufferTexCoordsMax,
 		const Vec2& gbufferTexCoordsMax,
+		F32 cameraNear,
+		F32 cameraFar,
 		DirectionalLightQueueElement* directionalLight,
 		DirectionalLightQueueElement* directionalLight,
 		ConstWeakArray<PointLightQueueElement> plights,
 		ConstWeakArray<PointLightQueueElement> plights,
 		ConstWeakArray<SpotLightQueueElement> slights,
 		ConstWeakArray<SpotLightQueueElement> slights,

+ 1 - 0
src/anki/scene/Visibility.cpp

@@ -38,6 +38,7 @@ void VisibilityContext::submitNewWork(const FrustumComponent& frc, RenderQueue&
 	rqueue.m_previousViewProjectionMatrix = frc.getPreviousViewProjectionMatrix();
 	rqueue.m_previousViewProjectionMatrix = frc.getPreviousViewProjectionMatrix();
 	rqueue.m_cameraNear = frc.getFrustum().getNear();
 	rqueue.m_cameraNear = frc.getFrustum().getNear();
 	rqueue.m_cameraFar = frc.getFrustum().getFar();
 	rqueue.m_cameraFar = frc.getFrustum().getFar();
+	rqueue.m_effectiveShadowDistance = frc.getEffectiveShadowDistance();
 
 
 	auto alloc = m_scene->getFrameAllocator();
 	auto alloc = m_scene->getFrameAllocator();