Browse Source

Minor refactoring

Panagiotis Christopoulos Charitos 9 years ago
parent
commit
de93022a43

+ 4 - 4
shaders/ClusterLightCommon.glsl

@@ -24,17 +24,17 @@ struct LightingUniforms
 // Point light
 // Point light
 struct PointLight
 struct PointLight
 {
 {
-	vec4 posRadius; // xyz: Light pos in eye space. w: The -1/radius
+	vec4 posRadius; // xyz: Light pos in view space. w: The -1/(radius^2)
 	vec4 diffuseColorShadowmapId; // xyz: diff color, w: shadowmap tex ID
 	vec4 diffuseColorShadowmapId; // xyz: diff color, w: shadowmap tex ID
-	vec4 specularColorTexId; // xyz: spec color, w: diffuse tex ID
+	vec4 specularColorRadius; // xyz: spec color, w: radius
 };
 };
 
 
 // Spot light
 // Spot light
 struct SpotLight
 struct SpotLight
 {
 {
-	vec4 posRadius; // xyz: Light pos in eye space. w: The -1/radius
+	vec4 posRadius; // xyz: Light pos in view space. w: The -1/(radius^2)
 	vec4 diffuseColorShadowmapId; // xyz: diff color, w: shadowmap tex ID
 	vec4 diffuseColorShadowmapId; // xyz: diff color, w: shadowmap tex ID
-	vec4 specularColorTexId; // xyz: spec color, w: diffuse tex ID
+	vec4 specularColorRadius; // xyz: spec color, w: radius
 	vec4 lightDir;
 	vec4 lightDir;
 	vec4 outerCosInnerCos;
 	vec4 outerCosInnerCos;
 	mat4 texProjectionMat;
 	mat4 texProjectionMat;

+ 2 - 2
shaders/FsCommonFrag.glsl

@@ -159,7 +159,7 @@ vec3 computeLightColor(vec3 diffCol)
 #else
 #else
 		float shadow = 1.0;
 		float shadow = 1.0;
 		float shadowmapLayerIdx = light.diffuseColorShadowmapId.w;
 		float shadowmapLayerIdx = light.diffuseColorShadowmapId.w;
-		if(light.diffuseColorShadowmapId.w < 128.0)
+		if(light.diffuseColorShadowmapId.w >= 0.0)
 		{
 		{
 			shadow = computeShadowFactorOmni(
 			shadow = computeShadowFactorOmni(
 				frag2Light, shadowmapLayerIdx, -1.0 / light.posRadius.w, u_lightingUniforms.viewMat, u_omniMapArr);
 				frag2Light, shadowmapLayerIdx, -1.0 / light.posRadius.w, u_lightingUniforms.viewMat, u_omniMapArr);
@@ -189,7 +189,7 @@ vec3 computeLightColor(vec3 diffCol)
 #else
 #else
 		float shadow = 1.0;
 		float shadow = 1.0;
 		float shadowmapLayerIdx = light.diffuseColorShadowmapId.w;
 		float shadowmapLayerIdx = light.diffuseColorShadowmapId.w;
-		if(shadowmapLayerIdx < 128.0)
+		if(shadowmapLayerIdx >= 0.0)
 		{
 		{
 			shadow = computeShadowFactorSpot(light.texProjectionMat, fragPos, shadowmapLayerIdx, 1, u_spotMapArr);
 			shadow = computeShadowFactorSpot(light.texProjectionMat, fragPos, shadowmapLayerIdx, 1, u_spotMapArr);
 		}
 		}

+ 10 - 11
shaders/Is.frag.glsl

@@ -36,7 +36,7 @@ const float SUBSURFACE_MIN = 0.05;
 	vec3 frag2Light = light.posRadius.xyz - fragPos;                                                                   \
 	vec3 frag2Light = light.posRadius.xyz - fragPos;                                                                   \
 	vec3 l = normalize(frag2Light);                                                                                    \
 	vec3 l = normalize(frag2Light);                                                                                    \
 	float nol = max(0.0, dot(normal, l));                                                                              \
 	float nol = max(0.0, dot(normal, l));                                                                              \
-	vec3 specC = computeSpecularColorBrdf(viewDir, l, normal, specCol, light.specularColorTexId.rgb, a2, nol);         \
+	vec3 specC = computeSpecularColorBrdf(viewDir, l, normal, specCol, light.specularColorRadius.rgb, a2, nol);        \
 	vec3 diffC = computeDiffuseColor(diffCol, light.diffuseColorShadowmapId.rgb);                                      \
 	vec3 diffC = computeDiffuseColor(diffCol, light.diffuseColorShadowmapId.rgb);                                      \
 	float att = computeAttenuationFactor(light.posRadius.w, frag2Light);                                               \
 	float att = computeAttenuationFactor(light.posRadius.w, frag2Light);                                               \
 	float lambert = nol;
 	float lambert = nol;
@@ -168,7 +168,6 @@ void main()
 		+ uint(in_clusterIJ.y) * CLUSTER_COUNT_X + uint(in_clusterIJ.x);
 		+ uint(in_clusterIJ.y) * CLUSTER_COUNT_X + uint(in_clusterIJ.x);
 
 
 	uint idxOffset = u_clusters[clusterIdx];
 	uint idxOffset = u_clusters[clusterIdx];
-	uint idx;
 
 
 	// Shadowpass sample count
 	// Shadowpass sample count
 	uint shadowSampleCount = computeShadowSampleCount(SHADOW_SAMPLE_COUNT, fragPos.z);
 	uint shadowSampleCount = computeShadowSampleCount(SHADOW_SAMPLE_COUNT, fragPos.z);
@@ -195,15 +194,15 @@ void main()
 
 
 		LIGHTING_COMMON_BRDF();
 		LIGHTING_COMMON_BRDF();
 
 
-		float shadow = 1.0;
 		float shadowmapLayerIdx = light.diffuseColorShadowmapId.w;
 		float shadowmapLayerIdx = light.diffuseColorShadowmapId.w;
-		if(light.diffuseColorShadowmapId.w < 128.0)
+		if(light.diffuseColorShadowmapId.w >= 0.0)
 		{
 		{
-			shadow = computeShadowFactorOmni(
-				frag2Light, shadowmapLayerIdx, 1.0 / sqrt(light.posRadius.w), u_lightingUniforms.viewMat, u_omniMapArr);
+			float shadow = computeShadowFactorOmni(
+				frag2Light, shadowmapLayerIdx, light.specularColorRadius.w, u_lightingUniforms.viewMat, u_omniMapArr);
+			lambert *= shadow;
 		}
 		}
 
 
-		out_color += (specC + diffC) * (att * max(subsurface, lambert * shadow));
+		out_color += (specC + diffC) * (att * max(subsurface, lambert));
 	}
 	}
 
 
 	// Spot lights
 	// Spot lights
@@ -216,15 +215,15 @@ void main()
 
 
 		float spot = computeSpotFactor(l, light.outerCosInnerCos.x, light.outerCosInnerCos.y, light.lightDir.xyz);
 		float spot = computeSpotFactor(l, light.outerCosInnerCos.x, light.outerCosInnerCos.y, light.lightDir.xyz);
 
 
-		float shadow = 1.0;
 		float shadowmapLayerIdx = light.diffuseColorShadowmapId.w;
 		float shadowmapLayerIdx = light.diffuseColorShadowmapId.w;
-		if(shadowmapLayerIdx < 128.0)
+		if(shadowmapLayerIdx >= 0.0)
 		{
 		{
-			shadow = computeShadowFactorSpot(
+			float shadow = computeShadowFactorSpot(
 				light.texProjectionMat, fragPos, shadowmapLayerIdx, shadowSampleCount, u_spotMapArr);
 				light.texProjectionMat, fragPos, shadowmapLayerIdx, shadowSampleCount, u_spotMapArr);
+			lambert *= shadow;
 		}
 		}
 
 
-		out_color += (diffC + specC) * (att * spot * max(subsurface, lambert * shadow));
+		out_color += (diffC + specC) * (att * spot * max(subsurface, lambert));
 	}
 	}
 
 
 #if INDIRECT_ENABLED
 #if INDIRECT_ENABLED

+ 0 - 1
shaders/LightFunctions.glsl

@@ -10,7 +10,6 @@
 
 
 #include "shaders/Common.glsl"
 #include "shaders/Common.glsl"
 
 
-const float ATTENUATION_BOOST = 0.05;
 const float OMNI_LIGHT_FRUSTUM_NEAR_PLANE = 0.1 / 4.0;
 const float OMNI_LIGHT_FRUSTUM_NEAR_PLANE = 0.1 / 4.0;
 
 
 const uint SHADOW_SAMPLE_COUNT = 16;
 const uint SHADOW_SAMPLE_COUNT = 16;

+ 2 - 2
shaders/Volumetric.frag.glsl

@@ -58,7 +58,7 @@ vec3 computeLightColor(vec3 fragPos[MAX_SAMPLES_PER_CLUSTER], uint iterCount, ui
 			float shadow = 1.0;
 			float shadow = 1.0;
 #if ENABLE_SHADOWS
 #if ENABLE_SHADOWS
 			float shadowmapLayerIdx = light.diffuseColorShadowmapId.w;
 			float shadowmapLayerIdx = light.diffuseColorShadowmapId.w;
-			if(light.diffuseColorShadowmapId.w < 128.0)
+			if(light.diffuseColorShadowmapId.w >= 0.0)
 			{
 			{
 				shadow = computeShadowFactorOmni(
 				shadow = computeShadowFactorOmni(
 					frag2Light, shadowmapLayerIdx, -1.0 / light.posRadius.w, u_lightingUniforms.viewMat, u_omniMapArr);
 					frag2Light, shadowmapLayerIdx, -1.0 / light.posRadius.w, u_lightingUniforms.viewMat, u_omniMapArr);
@@ -87,7 +87,7 @@ vec3 computeLightColor(vec3 fragPos[MAX_SAMPLES_PER_CLUSTER], uint iterCount, ui
 			float shadow = 1.0;
 			float shadow = 1.0;
 #if ENABLE_SHADOWS
 #if ENABLE_SHADOWS
 			float shadowmapLayerIdx = light.diffuseColorShadowmapId.w;
 			float shadowmapLayerIdx = light.diffuseColorShadowmapId.w;
-			if(shadowmapLayerIdx < 128.0)
+			if(shadowmapLayerIdx >= 0.0)
 			{
 			{
 				shadow =
 				shadow =
 					computeShadowFactorSpot(light.texProjectionMat, fragPos[i], shadowmapLayerIdx, 1, u_spotMapArr);
 					computeShadowFactorSpot(light.texProjectionMat, fragPos[i], shadowmapLayerIdx, 1, u_spotMapArr);

+ 4 - 4
src/anki/renderer/LightBin.cpp

@@ -33,7 +33,7 @@ class ShaderLight
 public:
 public:
 	Vec4 m_posRadius;
 	Vec4 m_posRadius;
 	Vec4 m_diffuseColorShadowmapId;
 	Vec4 m_diffuseColorShadowmapId;
-	Vec4 m_specularColorTexId;
+	Vec4 m_specularColorRadius;
 };
 };
 
 
 class ShaderPointLight : public ShaderLight
 class ShaderPointLight : public ShaderLight
@@ -75,7 +75,7 @@ public:
 static const U MAX_TYPED_LIGHTS_PER_CLUSTER = 16;
 static const U MAX_TYPED_LIGHTS_PER_CLUSTER = 16;
 static const U MAX_PROBES_PER_CLUSTER = 12;
 static const U MAX_PROBES_PER_CLUSTER = 12;
 static const U MAX_DECALS_PER_CLUSTER = 8;
 static const U MAX_DECALS_PER_CLUSTER = 8;
-static const F32 INVALID_TEXTURE_INDEX = 128.0;
+static const F32 INVALID_TEXTURE_INDEX = -1.0;
 
 
 class ClusterLightIndex
 class ClusterLightIndex
 {
 {
@@ -693,7 +693,7 @@ I LightBin::writePointLight(
 		slight.m_diffuseColorShadowmapId.w() = lightc.getShadowMapIndex();
 		slight.m_diffuseColorShadowmapId.w() = lightc.getShadowMapIndex();
 	}
 	}
 
 
-	slight.m_specularColorTexId = lightc.getSpecularColor();
+	slight.m_specularColorRadius = Vec4(lightc.getSpecularColor().xyz(), lightc.getRadius());
 
 
 	return i;
 	return i;
 }
 }
@@ -728,7 +728,7 @@ I LightBin::writeSpotLight(const LightComponent& lightc,
 	light.m_diffuseColorShadowmapId = Vec4(lightc.getDiffuseColor().xyz(), shadowmapIndex);
 	light.m_diffuseColorShadowmapId = Vec4(lightc.getDiffuseColor().xyz(), shadowmapIndex);
 
 
 	// Spec color
 	// Spec color
-	light.m_specularColorTexId = lightc.getSpecularColor();
+	light.m_specularColorRadius = Vec4(lightc.getSpecularColor().xyz(), lightc.getDistance());
 
 
 	// Light dir
 	// Light dir
 	Vec3 lightDir = -lightMove.getWorldTransform().getRotation().getZAxis();
 	Vec3 lightDir = -lightMove.getWorldTransform().getRotation().getZAxis();