Panagiotis Christopoulos Charitos 10 éve
szülő
commit
9ccddccf2c

+ 10 - 8
shaders/BsCommonFrag.glsl → shaders/FsCommonFrag.glsl

@@ -5,7 +5,7 @@
 
 
 // Common code for all fragment shaders of BS
 // Common code for all fragment shaders of BS
 #pragma anki include "shaders/Common.glsl"
 #pragma anki include "shaders/Common.glsl"
-#pragma anki include "shaders/MsBsCommon.glsl"
+#pragma anki include "shaders/MsFsCommon.glsl"
 #pragma anki include "shaders/LinearDepth.glsl"
 #pragma anki include "shaders/LinearDepth.glsl"
 
 
 // Global resources
 // Global resources
@@ -126,13 +126,14 @@ void particleSoftColorAlpha(in sampler2D depthMap, in vec3 icolor,
 #	define computeLightColor_DEFINED
 #	define computeLightColor_DEFINED
 vec3 computeLightColor(vec3 diffCol)
 vec3 computeLightColor(vec3 diffCol)
 {
 {
-	vec3 outColor = diffCol * u_sceneAmbientColor.rgb;
+	vec3 outColor = diffCol * u_lightingUniforms.sceneAmbientColor.rgb;
 
 
 	// Compute frag pos in view space
 	// Compute frag pos in view space
 	vec3 fragPos;
 	vec3 fragPos;
 	{
 	{
 		float depth = gl_FragCoord.z;
 		float depth = gl_FragCoord.z;
-		fragPos.z = u_projectionParams.z / (u_projectionParams.w + depth);
+		fragPos.z = u_lightingUniforms.projectionParams.z
+			/ (u_lightingUniforms.projectionParams.w + depth);
 
 
 		const vec2 screenSize = vec2(
 		const vec2 screenSize = vec2(
 			1.0 / float(ANKI_RENDERER_WIDTH),
 			1.0 / float(ANKI_RENDERER_WIDTH),
@@ -140,7 +141,7 @@ vec3 computeLightColor(vec3 diffCol)
 
 
 		vec2 ndc = gl_FragCoord.xy * screenSize * 2.0 - 1.0;
 		vec2 ndc = gl_FragCoord.xy * screenSize * 2.0 - 1.0;
 
 
-		fragPos.xy = ndc * u_projectionParams.xy * fragPos.z;
+		fragPos.xy = ndc * u_lightingUniforms.projectionParams.xy * fragPos.z;
 	}
 	}
 
 
 	// Find the cluster and then the light counts
 	// Find the cluster and then the light counts
@@ -151,9 +152,10 @@ vec3 computeLightColor(vec3 diffCol)
 		uint k = calcClusterSplit(fragPos.z);
 		uint k = calcClusterSplit(fragPos.z);
 
 
 		vec2 tilef = gl_FragCoord.xy / float(TILE_SIZE);
 		vec2 tilef = gl_FragCoord.xy / float(TILE_SIZE);
-		uint tile = uint(tilef.y) * u_tileCount.x + uint(tilef.x);
+		uint tile = uint(tilef.y) * u_lightingUniforms.tileCount.x
+			+ uint(tilef.x);
 
 
-		uint cluster = u_clusters[tile + k * u_tileCount.z];
+		uint cluster = u_clusters[tile + k * u_lightingUniforms.tileCount.z];
 
 
 		lightOffset = cluster >> 16u;
 		lightOffset = cluster >> 16u;
 		pointLightsCount = (cluster >> 8u) & 0xFFu;
 		pointLightsCount = (cluster >> 8u) & 0xFFu;
@@ -242,8 +244,8 @@ void fog(in sampler2D depthMap, in vec3 color, in float fogScale)
 
 
 	vec2 texCoords = gl_FragCoord.xy * screenSize;
 	vec2 texCoords = gl_FragCoord.xy * screenSize;
 	float depth = texture(depthMap, texCoords).r;
 	float depth = texture(depthMap, texCoords).r;
-	float zNear = u_nearFarClustererDivisor.x;
-	float zFar = u_nearFarClustererDivisor.y;
+	float zNear = u_lightingUniforms.nearFarClustererDivisor.x;
+	float zFar = u_lightingUniforms.nearFarClustererDivisor.y;
 	float linearDepth = (2.0 * zNear) / (zFar + zNear - depth * (zFar - zNear));
 	float linearDepth = (2.0 * zNear) / (zFar + zNear - depth * (zFar - zNear));
 
 
 	float depth2 = gl_FragCoord.z;
 	float depth2 = gl_FragCoord.z;

+ 2 - 2
shaders/BsCommonVert.glsl → shaders/FsCommonVert.glsl

@@ -3,8 +3,8 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-// Common code for all vertex shaders of BS
-#pragma anki include "shaders/MsBsCommon.glsl"
+// Common code for all vertex shaders of FS
+#pragma anki include "shaders/MsFsCommon.glsl"
 
 
 layout(location = POSITION_LOCATION) in vec3 in_position;
 layout(location = POSITION_LOCATION) in vec3 in_position;
 layout(location = SCALE_LOCATION) in float in_scale;
 layout(location = SCALE_LOCATION) in float in_scale;

+ 4 - 3
shaders/IsLp.frag.glsl

@@ -36,7 +36,8 @@ vec3 getFragPosVSpace()
 	float depth = textureRt(u_msDepthRt, in_texCoord).r;
 	float depth = textureRt(u_msDepthRt, in_texCoord).r;
 
 
 	vec3 fragPos;
 	vec3 fragPos;
-	fragPos.z = u_projectionParams.z / (u_projectionParams.w + depth);
+	fragPos.z = u_lightingUniforms.projectionParams.z
+		/ (u_lightingUniforms.projectionParams.w + depth);
 	fragPos.xy = in_projectionParams * fragPos.z;
 	fragPos.xy = in_projectionParams * fragPos.z;
 
 
 	return fragPos;
 	return fragPos;
@@ -87,7 +88,7 @@ void main()
 	float a2 = pow(max(EPSILON, specPower), 2.0);
 	float a2 = pow(max(EPSILON, specPower), 2.0);
 
 
 	// Ambient color
 	// Ambient color
-	out_color = diffCol * u_sceneAmbientColor.rgb;
+	out_color = diffCol * u_lightingUniforms.sceneAmbientColor.rgb;
 
 
 	// Get counts and offsets
 	// Get counts and offsets
 	uint k = calcClusterSplit(fragPos.z);
 	uint k = calcClusterSplit(fragPos.z);
@@ -142,7 +143,7 @@ void main()
 	}
 	}
 
 
 #if GROUND_LIGHT
 #if GROUND_LIGHT
-	out_color += max(dot(normal, u_groundLightDir.xyz), 0.0)
+	out_color += max(dot(normal, u_lightingUniforms.groundLightDir.xyz), 0.0)
 		* vec3(0.01, 0.001, 0.001);
 		* vec3(0.01, 0.001, 0.001);
 #endif
 #endif
 
 

+ 1 - 1
shaders/IsLp.vert.glsl

@@ -43,7 +43,7 @@ void main()
 	vec2 pos = out_texCoord * 2.0 - 1.0;
 	vec2 pos = out_texCoord * 2.0 - 1.0;
 
 
 	gl_Position = vec4(pos, 0.0, 1.0);
 	gl_Position = vec4(pos, 0.0, 1.0);
-	out_projectionParams = u_projectionParams.xy * pos;
+	out_projectionParams = u_lightingUniforms.projectionParams.xy * pos;
 }
 }
 
 
 
 

+ 3 - 2
shaders/LightFunctions.glsl

@@ -19,7 +19,8 @@ uint calcClusterSplit(float zVspace)
 {
 {
 	zVspace = -zVspace;
 	zVspace = -zVspace;
 	float fk = sqrt(
 	float fk = sqrt(
-		(zVspace - u_nearFarClustererDivisor.x) / u_nearFarClustererDivisor.z);
+		(zVspace - u_lightingUniforms.nearFarClustererDivisor.x)
+		/ u_lightingUniforms.nearFarClustererDivisor.z);
 	uint k = uint(fk);
 	uint k = uint(fk);
 	return k;
 	return k;
 }
 }
@@ -124,7 +125,7 @@ float computeShadowFactorSpot(mat4 lightProjectionMat, vec3 fragPos,
 //==============================================================================
 //==============================================================================
 float computeShadowFactorOmni(vec3 frag2Light, float layer, float radius)
 float computeShadowFactorOmni(vec3 frag2Light, float layer, float radius)
 {
 {
-	vec3 dir = (u_viewMat * vec4(-frag2Light, 1.0)).xyz;
+	vec3 dir = (u_lightingUniforms.viewMat * vec4(-frag2Light, 1.0)).xyz;
 	vec3 dirabs = abs(dir);
 	vec3 dirabs = abs(dir);
 	float dist = -max(dirabs.x, max(dirabs.y, dirabs.z));
 	float dist = -max(dirabs.x, max(dirabs.y, dirabs.z));
 	dir = normalize(dir);
 	dir = normalize(dir);

+ 16 - 11
shaders/LightResources.glsl

@@ -9,15 +9,20 @@
 #pragma anki include "shaders/Common.glsl"
 #pragma anki include "shaders/Common.glsl"
 
 
 // Common uniforms between lights
 // Common uniforms between lights
+struct LightingUniforms
+{
+	vec4 projectionParams;
+	vec4 sceneAmbientColor;
+	vec4 groundLightDir;
+	vec4 nearFarClustererDivisor;
+	mat4 viewMat;
+	uvec4 tileCount;
+};
+
 layout(std140, row_major, SS_BINDING(LIGHT_SET, LIGHT_SS_BINDING))
 layout(std140, row_major, SS_BINDING(LIGHT_SET, LIGHT_SS_BINDING))
 	readonly buffer _s0
 	readonly buffer _s0
 {
 {
-	vec4 u_projectionParams;
-	vec4 u_sceneAmbientColor;
-	vec4 u_groundLightDir;
-	vec4 u_nearFarClustererDivisor;
-	mat4 u_viewMat;
-	uvec4 u_tileCount;
+	LightingUniforms u_lightingUniforms;
 };
 };
 
 
 #ifdef FRAGMENT_SHADER
 #ifdef FRAGMENT_SHADER
@@ -30,6 +35,11 @@ struct PointLight
 	vec4 specularColorTexId; // xyz: spec color, w: diffuse tex ID
 	vec4 specularColorTexId; // xyz: spec color, w: diffuse tex ID
 };
 };
 
 
+layout(std140, SS_BINDING(LIGHT_SET, LIGHT_SS_BINDING + 1)) readonly buffer _s1
+{
+	PointLight u_pointLights[];
+};
+
 // Spot light
 // Spot light
 struct SpotLight
 struct SpotLight
 {
 {
@@ -41,11 +51,6 @@ struct SpotLight
 	mat4 texProjectionMat;
 	mat4 texProjectionMat;
 };
 };
 
 
-layout(std140, SS_BINDING(LIGHT_SET, LIGHT_SS_BINDING + 1)) readonly buffer _s1
-{
-	PointLight u_pointLights[];
-};
-
 layout(std140, SS_BINDING(LIGHT_SET, LIGHT_SS_BINDING + 2)) readonly buffer _s2
 layout(std140, SS_BINDING(LIGHT_SET, LIGHT_SS_BINDING + 2)) readonly buffer _s2
 {
 {
 	SpotLight u_spotLights[];
 	SpotLight u_spotLights[];

+ 1 - 1
shaders/MsCommonFrag.glsl

@@ -10,7 +10,7 @@ layout(early_fragment_tests) in;
 #endif
 #endif
 
 
 #pragma anki include "shaders/Pack.glsl"
 #pragma anki include "shaders/Pack.glsl"
-#pragma anki include "shaders/MsBsCommon.glsl"
+#pragma anki include "shaders/MsFsCommon.glsl"
 
 
 //==============================================================================
 //==============================================================================
 // Variables                                                                   =
 // Variables                                                                   =

+ 2 - 2
shaders/MsCommonVert.glsl

@@ -3,7 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#pragma anki include "shaders/MsBsCommon.glsl"
+#pragma anki include "shaders/MsFsCommon.glsl"
 
 
 //
 //
 // Attributes
 // Attributes
@@ -37,7 +37,7 @@ layout(location = 1) out mediump vec3 outNormal;
 layout(location = 2) out mediump vec4 outTangent;
 layout(location = 2) out mediump vec4 outTangent;
 
 
 // For env mapping. AKA view vector
 // For env mapping. AKA view vector
-layout(location = 3) out mediump vec3 outVertPosViewSpace; 
+layout(location = 3) out mediump vec3 outVertPosViewSpace;
 #endif
 #endif
 
 
 #if INSTANCE_ID_FRAGMENT_SHADER
 #if INSTANCE_ID_FRAGMENT_SHADER

+ 0 - 0
shaders/MsBsCommon.glsl → shaders/MsFsCommon.glsl