Panagiotis Christopoulos Charitos 2 years ago
parent
commit
ecc4f50c61

+ 12 - 12
AnKi/Math/Transform.h

@@ -85,12 +85,12 @@ public:
 
 	/// @name Accessors
 	/// @{
-	const TVec<T, 4>& getOrigin() const
+	[[nodiscard]] const TVec<T, 4>& getOrigin() const
 	{
 		return m_origin;
 	}
 
-	TVec<T, 4>& getOrigin()
+	[[nodiscard]] TVec<T, 4>& getOrigin()
 	{
 		return m_origin;
 	}
@@ -101,12 +101,12 @@ public:
 		checkW();
 	}
 
-	const TMat<T, 3, 4>& getRotation() const
+	[[nodiscard]] const TMat<T, 3, 4>& getRotation() const
 	{
 		return m_rotation;
 	}
 
-	TMat<T, 3, 4>& getRotation()
+	[[nodiscard]] TMat<T, 3, 4>& getRotation()
 	{
 		return m_rotation;
 	}
@@ -116,12 +116,12 @@ public:
 		m_rotation = r;
 	}
 
-	T getScale() const
+	[[nodiscard]] T getScale() const
 	{
 		return m_scale;
 	}
 
-	T& getScale()
+	[[nodiscard]] T& getScale()
 	{
 		return m_scale;
 	}
@@ -161,13 +161,13 @@ public:
 		(*this) = getIdentity();
 	}
 
-	static TTransform getIdentity()
+	[[nodiscard]] static TTransform getIdentity()
 	{
 		return TTransform(TVec<T, 4>(T(0)), TMat<T, 3, 4>::getIdentity(), T(1));
 	}
 
 	/// @copybrief combineTTransformations
-	TTransform combineTransformations(const TTransform& b) const
+	[[nodiscard]] TTransform combineTransformations(const TTransform& b) const
 	{
 		checkW();
 		const TTransform& a = *this;
@@ -182,7 +182,7 @@ public:
 	}
 
 	/// Get the inverse transformation. Its faster that inverting a Mat4
-	TTransform getInverse() const
+	[[nodiscard]] TTransform getInverse() const
 	{
 		checkW();
 		TTransform o;
@@ -201,14 +201,14 @@ public:
 	}
 
 	/// Transform a TVec3
-	TVec<T, 3> transform(const TVec<T, 3>& b) const
+	[[nodiscard]] TVec<T, 3> transform(const TVec<T, 3>& b) const
 	{
 		checkW();
 		return (m_rotation.getRotationPart() * (b * m_scale)) + m_origin.xyz();
 	}
 
 	/// Transform a TVec4. SIMD optimized
-	TVec<T, 4> transform(const TVec<T, 4>& b) const
+	[[nodiscard]] TVec<T, 4> transform(const TVec<T, 4>& b) const
 	{
 		checkW();
 		TVec<T, 4> out = TVec<T, 4>(m_rotation * (b * m_scale), T(0)) + m_origin;
@@ -227,7 +227,7 @@ public:
 	}
 
 	ANKI_ENABLE_METHOD(std::is_floating_point<T>::value)
-	String toString() const
+	[[nodiscard]] String toString() const
 	{
 		String str;
 		String b = m_origin.toString();

+ 1 - 2
AnKi/Renderer/ClusterBinning2.cpp

@@ -322,12 +322,11 @@ void ClusterBinning2::writeClusterUniformsInternal()
 		DirectionalLight& out = unis.m_directionalLight;
 
 		out.m_diffuseColor = dirLight->getDiffuseColor().xyz();
-		out.m_shadowCascadeCount = g_shadowCascadeCountCVar.get();
+		out.m_shadowCascadeCount = dirLight->getShadowEnabled() ? g_shadowCascadeCountCVar.get() : 0;
 		out.m_direction = dirLight->getDirection();
 		out.m_active = 1;
 		out.m_shadowCascadeDistances = Vec4(g_shadowCascade0DistanceCVar.get(), g_shadowCascade1DistanceCVar.get(),
 											g_shadowCascade2DistanceCVar.get(), g_shadowCascade3DistanceCVar.get());
-		out.m_shadowLayer = (dirLight->getShadowEnabled()) ? 1 : kMaxU32; // TODO RT
 
 		for(U cascade = 0; cascade < g_shadowCascadeCountCVar.get(); ++cascade)
 		{

+ 1 - 1
AnKi/Scene/Components/LightComponent.cpp

@@ -165,7 +165,7 @@ Error LightComponent::update(SceneComponentUpdateInfo& info, Bool& updated)
 		computeEdgesOfFrustum(m_spot.m_distance, m_spot.m_outerAngle, m_spot.m_outerAngle, &points[0]);
 		for(U32 i = 0; i < 4; ++i)
 		{
-			m_worldTransform.transform(points[i]);
+			points[i] = m_worldTransform.transform(points[i]);
 			gpuLight.m_edgePoints[i] = points[i].xyz0();
 		}
 

+ 5 - 3
AnKi/Shaders/ClusterBinning2.ankiprog

@@ -118,13 +118,15 @@ groupshared ExtendedClusterObjectMask s_zSplitMasks[kMaxZsplitCount];
 
 		// Iterate all triangles
 		const U32 indices[6u * 3u] = {0u, 1u, 2u, 0u, 2u, 3u, 0u, 3u, 4u, 0u, 1u, 4u, 1u, 2u, 3u, 3u, 4u, 1u};
+		const Vec3 edgePoints[5u] = {obj.m_position, obj.m_edgePoints[0].xyz, obj.m_edgePoints[1].xyz, obj.m_edgePoints[2].xyz,
+									 obj.m_edgePoints[3].xyz};
 		U32 hits = 0u;
 		U32 idx = 0u;
 		do
 		{
-			const Vec3 v0 = obj.m_edgePoints[indices[idx + 0u]].xyz;
-			const Vec3 v1 = obj.m_edgePoints[indices[idx + 1u]].xyz;
-			const Vec3 v2 = obj.m_edgePoints[indices[idx + 2u]].xyz;
+			const Vec3 v0 = edgePoints[indices[idx + 0u]];
+			const Vec3 v1 = edgePoints[indices[idx + 1u]];
+			const Vec3 v2 = edgePoints[indices[idx + 2u]];
 
 			F32 t, u, v;
 			const Bool localCollides = testRayTriangle(rayOrigin, rayDir, v0, v1, v2, false, t, u, v);

+ 0 - 1
AnKi/Shaders/ClusterBinning2PackVisibles.ankiprog

@@ -56,7 +56,6 @@ typedef GpuSceneGlobalIlluminationProbe GpuSceneType;
 	output.m_diffuseColor = input.m_diffuseColor;
 	output.m_lightType = (isPoint) ? 0 : 1;
 
-	output.m_shadowLayer = kMaxU32; // TODO rt
 	output.m_shadow = ((U32)input.m_flags & (U32)GpuSceneLightFlag::kShadow) ? 1 : 0;
 	output.m_innerCos = input.m_innerCos;
 	output.m_outerCos = input.m_outerCos;

+ 1 - 1
AnKi/Shaders/ForwardShadingCommon.hlsl

@@ -92,7 +92,7 @@ Vec3 computeLightColorHigh(Vec3 diffCol, Vec3 worldPos, Vec4 svPosition)
 		const F32 shadow = 1.0;
 #	else
 		F32 shadow = 1.0;
-		[branch] if(light.m_shadowLayer != kMaxU32)
+		[branch] if(light.m_shadow != 0u)
 		{
 			shadow = computeShadowFactorSpotLight(light, worldPos, g_shadowAtlasTex, g_shadowSampler);
 		}

+ 7 - 10
AnKi/Shaders/Include/ClusteredShadingTypes.h

@@ -37,10 +37,10 @@ struct LightUnion
 	RVec3 m_diffuseColor;
 	U32 m_lightType; ///< 0 is point and 1 is spot
 
-	U32 m_shadowLayer; ///< Shadow layer used in RT shadows
 	U32 m_shadow;
 	F32 m_innerCos; ///< SPOT LIGHTS
 	F32 m_outerCos; ///< SPOT LIGHTS
+	F32 m_padding;
 
 	RVec3 m_direction; ///< SPOT LIGHTS: Light direction.
 	F32 m_shadowAtlasTileScale; ///< POINT LIGHTS: UV scale for all tiles.
@@ -60,12 +60,12 @@ struct PointLight
 	RVec3 m_diffuseColor;
 	U32 m_padding1;
 
-	U32 m_shadowLayer; ///< Shadow layer used in RT shadows. Also used to show that it doesn't cast shadow.
 	F32 m_shadow;
 	F32 m_padding2;
 	U32 m_padding3;
+	U32 m_padding4;
 
-	RVec3 m_padding4;
+	RVec3 m_padding5;
 	F32 m_shadowAtlasTileScale; ///< UV scale for all tiles.
 
 	Vec4 m_shadowAtlasTileOffsets[6u]; ///< It's a array of Vec2 but because of padding round it up.
@@ -82,17 +82,17 @@ struct SpotLight
 	RVec3 m_diffuseColor;
 	U32 m_padding1;
 
-	U32 m_shadowLayer; ///< Shadow layer used in RT shadows. Also used to show that it doesn't cast shadow.
 	U32 m_shadow;
 	F32 m_innerCos;
 	F32 m_outerCos;
+	F32 m_padding2;
 
 	RVec3 m_direction;
-	F32 m_padding2;
+	F32 m_padding3;
 
 	Mat4 m_textureMatrix;
 
-	Vec4 m_padding3[2];
+	Vec4 m_padding4[2];
 };
 static_assert(sizeof(SpotLight) == sizeof(LightUnion));
 
@@ -107,12 +107,9 @@ struct DirectionalLight
 
 	Vec4 m_shadowCascadeDistances;
 
-	Vec3 m_padding0;
-	U32 m_shadowLayer; ///< Shadow layer used in RT shadows. Also used to show that it doesn't cast shadow.
-
 	Mat4 m_textureMatrices[kMaxShadowCascades];
 };
-constexpr U32 kSizeof_DirectionalLight = 4u * sizeof(Vec4) + kMaxShadowCascades * sizeof(Mat4);
+constexpr U32 kSizeof_DirectionalLight = 3u * sizeof(Vec4) + kMaxShadowCascades * sizeof(Mat4);
 static_assert(sizeof(DirectionalLight) == kSizeof_DirectionalLight);
 static_assert(kMaxShadowCascades == 4u); // Because m_shadowCascadeDistances is a Vec4
 

+ 0 - 19
AnKi/Shaders/Include/MiscRendererTypes.h

@@ -124,25 +124,6 @@ struct VolumetricLightingUniforms
 	F32 m_maxZSplitsToProcessf;
 };
 
-// Pack visible clusterer objects
-struct PointLightExtra
-{
-	Vec2 m_padding0;
-	U32 m_shadowLayer;
-	F32 m_shadowAtlasTileScale;
-
-	Vec4 m_shadowAtlasTileOffsets[6u];
-};
-
-// Pack visible clusterer objects
-struct SpotLightExtra
-{
-	Vec3 m_padding;
-	U32 m_shadowLayer;
-
-	Mat4 m_textureMatrix;
-};
-
 struct HzbUniforms
 {
 	Mat4 m_reprojectionMatrix; ///< For the main camera.

+ 1 - 1
AnKi/Shaders/LightShading.ankiprog

@@ -130,7 +130,7 @@ RVec3 main(Vec4 svPosition : SV_POSITION, Vec2 uv : TEXCOORD) : SV_TARGET0
 
 		const F32 spot = computeSpotFactor(l, light.m_outerCos, light.m_innerCos, light.m_direction);
 
-		[branch] if(light.m_shadowLayer != kMaxU32)
+		[branch] if(light.m_shadow)
 		{
 			const RF32 shadow = resolvedSm[resolvedSmIdx++];
 			lambert *= shadow;

+ 1 - 1
AnKi/Shaders/ShadowmapsResolve.hlsl

@@ -195,7 +195,7 @@ RVec4 main(Vec2 uv : TEXCOORD) : SV_TARGET0
 		cluster.m_spotLightsMask &= ~(ExtendedClusterObjectMask(1) << ExtendedClusterObjectMask(idx));
 		const SpotLight light = g_spotLights[idx];
 
-		[branch] if(light.m_shadowLayer != kMaxU32)
+		[branch] if(light.m_shadow)
 		{
 #if PCF
 			const RF32 shadowFactor = computeShadowFactorSpotLightPcf(light, worldPos, g_shadowAtlasTex, g_linearAnyClampShadowSampler, randFactor);

+ 1 - 1
AnKi/Shaders/VolumetricLightingAccumulation.ankiprog

@@ -153,7 +153,7 @@ Vec4 accumulateLightsAndFog(Cluster cluster, Vec3 worldPos, F32 negativeZViewSpa
 		factor *= phaseFunction(viewDir, light.m_direction, kPhaseFunctionAnisotropy);
 
 #if ENABLE_SHADOWS
-		if(light.m_shadowLayer != kMaxU32)
+		if(light.m_shadow)
 		{
 			factor *= computeShadowFactorSpotLight(light, worldPos, g_shadowAtlasTex, g_linearAnyClampShadowSampler);
 		}