Ver Fonte

Light shading -> RP

Panagiotis Christopoulos Charitos há 4 anos atrás
pai
commit
7658081b17

+ 1 - 1
AnKi/Shaders/ApplyIrradianceToReflection.ankiprog

@@ -34,7 +34,7 @@ void main()
 
 	// Read the gbuffer
 	GbufferInfo gbuffer;
-	readGBuffer(u_gbufferTex[0u], u_gbufferTex[1u], u_gbufferTex[2u], u_nearestAnyClampSampler, sampleUv, 0.0, gbuffer);
+	readGBuffer(u_gbufferTex[0u], u_gbufferTex[1u], u_gbufferTex[2u], u_nearestAnyClampSampler, sampleUv, gbuffer);
 
 	// Sample
 	const Vec3 irradiance = sampleAmbientDice(u_irradianceDice[0u].xyz, u_irradianceDice[1u].xyz,

+ 15 - 15
AnKi/Shaders/Include/ClusteredShadingTypes.h

@@ -35,17 +35,17 @@ const U32 MAX_VISIBLE_REFLECTION_PROBES = 16u;
 const U32 MAX_VISIBLE_GLOBAL_ILLUMINATION_PROBES = 8u;
 
 // Other consts
-const F32 CLUSTER_OBJECT_FRUSTUM_NEAR_PLANE = 0.1f / 4.0f; ///< The near plane of various clusterer object frustums.
+const ANKI_RP F32 CLUSTER_OBJECT_FRUSTUM_NEAR_PLANE = 0.1f / 4.0f; ///< Near plane of various clusterer object frustums.
 const U32 MAX_SHADOW_CASCADES2 = 4u;
-const F32 SUBSURFACE_MIN = 0.01f;
+const ANKI_RP F32 SUBSURFACE_MIN = 0.01f;
 
 /// Point light.
 struct PointLight
 {
 	Vec3 m_position; ///< Position in world space.
-	Vec3 m_diffuseColor;
-	F32 m_radius; ///< Radius
-	F32 m_squareRadiusOverOne; ///< 1/(radius^2).
+	ANKI_RP Vec3 m_diffuseColor;
+	ANKI_RP F32 m_radius; ///< Radius
+	ANKI_RP F32 m_squareRadiusOverOne; ///< 1/(radius^2).
 	U32 m_shadowLayer; ///< Shadow layer used in RT shadows. Also used to show that it doesn't cast shadow.
 	F32 m_shadowAtlasTileScale; ///< UV scale for all tiles.
 	Vec2 m_shadowAtlasTileOffsets[6u];
@@ -58,13 +58,13 @@ struct SpotLight
 {
 	Vec3 m_position; ///< Position in world space.
 	Vec3 m_edgePoints[4u]; ///< Edge points in world space.
-	Vec3 m_diffuseColor;
-	F32 m_radius; ///< Max distance.
-	F32 m_squareRadiusOverOne; ///< 1/(radius^2).
+	ANKI_RP Vec3 m_diffuseColor;
+	ANKI_RP F32 m_radius; ///< Max distance.
+	ANKI_RP F32 m_squareRadiusOverOne; ///< 1/(radius^2).
 	U32 m_shadowLayer; ///< Shadow layer used in RT shadows. Also used to show that it doesn't cast shadow.
-	Vec3 m_direction; ///< Light direction.
-	F32 m_outerCos;
-	F32 m_innerCos;
+	ANKI_RP Vec3 m_direction; ///< Light direction.
+	ANKI_RP F32 m_outerCos;
+	ANKI_RP F32 m_innerCos;
 	Vec2 m_padding;
 	Mat4 m_textureMatrix;
 };
@@ -92,12 +92,12 @@ ANKI_SHADER_STATIC_ASSERT(alignof(SpotLightBinning) == alignof(SpotLight));
 /// Directional light (sun).
 struct DirectionalLight
 {
-	Vec3 m_diffuseColor;
+	ANKI_RP Vec3 m_diffuseColor;
 	U32 m_cascadeCount; ///< If it's zero then it doesn't cast shadow.
-	Vec3 m_direction;
+	ANKI_RP Vec3 m_direction;
 	U32 m_active;
-	F32 m_effectiveShadowDistance;
-	F32 m_shadowCascadesDistancePower;
+	ANKI_RP F32 m_effectiveShadowDistance;
+	ANKI_RP F32 m_shadowCascadesDistancePower;
 	U32 m_shadowLayer; ///< Shadow layer used in RT shadows. Also used to show that it doesn't cast shadow.
 	U32 m_padding;
 	Mat4 m_textureMatrices[MAX_SHADOW_CASCADES2];

+ 1 - 2
AnKi/Shaders/IrradianceDice.ankiprog

@@ -144,8 +144,7 @@ void main()
 		gbufferUv.x *= 1.0 / 6.0;
 		gbufferUv.x += (1.0 / 6.0) * F32(f);
 		GbufferInfo gbuffer;
-		readGBuffer(u_gbufferTex[0u], u_gbufferTex[1u], u_gbufferTex[2u], u_nearestAnyClampSampler, gbufferUv, 0.0,
-					gbuffer);
+		readGBuffer(u_gbufferTex[0u], u_gbufferTex[1u], u_gbufferTex[2u], u_nearestAnyClampSampler, gbufferUv, gbuffer);
 
 		// Sample irradiance
 		Vec3 firstBounceIrradiance =

+ 6 - 6
AnKi/Shaders/LightFunctions.glsl

@@ -156,10 +156,10 @@ Vec3 envBRDF(Vec3 specular, F32 roughness, texture2D integrationLut, sampler int
 	return specular * envBRDF.x + min(1.0, 50.0 * specular.g) * envBRDF.y;
 }
 
-F32 computeSpotFactor(Vec3 l, F32 outerCos, F32 innerCos, Vec3 spotDir)
+ANKI_RP F32 computeSpotFactor(ANKI_RP Vec3 l, ANKI_RP F32 outerCos, ANKI_RP F32 innerCos, ANKI_RP Vec3 spotDir)
 {
-	const F32 costheta = -dot(l, spotDir);
-	const F32 spotFactor = smoothstep(outerCos, innerCos, costheta);
+	const ANKI_RP F32 costheta = -dot(l, spotDir);
+	const ANKI_RP F32 spotFactor = smoothstep(outerCos, innerCos, costheta);
 	return spotFactor;
 }
 
@@ -300,10 +300,10 @@ Vec3 computeCubemapVecCheap(Vec3 r, F32 R2, Vec3 f)
 	return r;
 }
 
-F32 computeAttenuationFactor(F32 squareRadiusOverOne, Vec3 frag2Light)
+ANKI_RP F32 computeAttenuationFactor(ANKI_RP F32 squareRadiusOverOne, ANKI_RP Vec3 frag2Light)
 {
-	const F32 fragLightDist = dot(frag2Light, frag2Light);
-	F32 att = 1.0 - fragLightDist * squareRadiusOverOne;
+	const ANKI_RP F32 fragLightDist = dot(frag2Light, frag2Light);
+	ANKI_RP F32 att = 1.0 - fragLightDist * squareRadiusOverOne;
 	att = max(0.0, att);
 	return att * att;
 }

+ 20 - 20
AnKi/Shaders/LightShading.ankiprog

@@ -42,16 +42,16 @@ layout(set = 0, binding = 16) uniform texture2D u_resolvedSm;
 
 layout(location = 0) in Vec2 in_uv;
 
-layout(location = 0) out Vec3 out_color;
+layout(location = 0) out ANKI_RP Vec3 out_color;
 
 // Common code for lighting
 #define LIGHTING_COMMON_BRDF() \
-	const Vec3 frag2Light = light.m_position - worldPos; \
-	const Vec3 l = normalize(frag2Light); \
-	const Vec3 specC = specularIsotropicLobe(gbuffer, viewDir, l); \
-	const Vec3 diffC = diffuseLobe(gbuffer.m_diffuse); \
-	const F32 att = computeAttenuationFactor(light.m_squareRadiusOverOne, frag2Light); \
-	F32 lambert = max(0.0, dot(gbuffer.m_normal, l));
+	const ANKI_RP Vec3 frag2Light = light.m_position - worldPos; \
+	const ANKI_RP Vec3 l = normalize(frag2Light); \
+	const ANKI_RP Vec3 specC = specularIsotropicLobe(gbuffer, viewDir, l); \
+	const ANKI_RP Vec3 diffC = diffuseLobe(gbuffer.m_diffuse); \
+	const ANKI_RP F32 att = computeAttenuationFactor(light.m_squareRadiusOverOne, frag2Light); \
+	ANKI_RP F32 lambert = max(0.0, dot(gbuffer.m_normal, l));
 
 void main()
 {
@@ -76,15 +76,15 @@ void main()
 
 	// Decode GBuffer
 	GbufferInfo gbuffer;
-	readGBuffer(u_msRt0, u_msRt1, u_msRt2, u_nearestAnyClampSampler, in_uv, 0.0, gbuffer);
+	readGBuffer(u_msRt0, u_msRt1, u_msRt2, u_nearestAnyClampSampler, in_uv, gbuffer);
 	gbuffer.m_subsurface = max(gbuffer.m_subsurface, SUBSURFACE_MIN);
 
 	// SM
 #if USE_SHADOW_LAYERS
-	F32 resolvedSm[MAX_RT_SHADOW_LAYERS];
+	ANKI_RP F32 resolvedSm[MAX_RT_SHADOW_LAYERS];
 	unpackRtShadows(textureLod(u_shadowLayersTex, u_nearestAnyClampSampler, in_uv, 0.0), resolvedSm);
 #else
-	Vec4 resolvedSm = textureLod(u_resolvedSm, u_trilinearClampSampler, in_uv, 0.0);
+	ANKI_RP Vec4 resolvedSm = textureLod(u_resolvedSm, u_trilinearClampSampler, in_uv, 0.0);
 	U32 resolvedSmIdx = 0u;
 #endif
 
@@ -92,11 +92,11 @@ void main()
 	out_color = gbuffer.m_diffuse * gbuffer.m_emission;
 
 	// Dir light
-	const Vec3 viewDir = normalize(u_clusteredShading.m_cameraPosition - worldPos);
+	const ANKI_RP Vec3 viewDir = normalize(u_clusteredShading.m_cameraPosition - worldPos);
 	const DirectionalLight dirLight = u_clusteredShading.m_directionalLight;
 	if(dirLight.m_active != 0u)
 	{
-		F32 shadowFactor;
+		ANKI_RP F32 shadowFactor;
 		if(dirLight.m_cascadeCount > 0u)
 		{
 #if USE_SHADOW_LAYERS
@@ -111,12 +111,12 @@ void main()
 			shadowFactor = 1.0;
 		}
 
-		const Vec3 l = -dirLight.m_direction;
+		const ANKI_RP Vec3 l = -dirLight.m_direction;
 
-		const F32 lambert = max(gbuffer.m_subsurface, dot(l, gbuffer.m_normal));
+		const ANKI_RP F32 lambert = max(gbuffer.m_subsurface, dot(l, gbuffer.m_normal));
 
-		const Vec3 diffC = diffuseLobe(gbuffer.m_diffuse);
-		const Vec3 specC = specularIsotropicLobe(gbuffer, viewDir, l);
+		const ANKI_RP Vec3 diffC = diffuseLobe(gbuffer.m_diffuse);
+		const ANKI_RP Vec3 specC = specularIsotropicLobe(gbuffer, viewDir, l);
 
 		out_color += (diffC + specC) * dirLight.m_diffuseColor * (shadowFactor * lambert);
 	}
@@ -133,9 +133,9 @@ void main()
 		ANKI_BRANCH if(light.m_shadowAtlasTileScale >= 0.0)
 		{
 #if USE_SHADOW_LAYERS
-			const F32 shadow = resolvedSm[light.m_shadowLayer];
+			const ANKI_RP F32 shadow = resolvedSm[light.m_shadowLayer];
 #else
-			const F32 shadow = resolvedSm[resolvedSmIdx++];
+			const ANKI_RP F32 shadow = resolvedSm[resolvedSmIdx++];
 #endif
 			lambert *= shadow;
 		}
@@ -157,9 +157,9 @@ void main()
 		ANKI_BRANCH if(light.m_shadowLayer != MAX_U32)
 		{
 #if USE_SHADOW_LAYERS
-			const F32 shadow = resolvedSm[light.m_shadowLayer];
+			const ANKI_RP F32 shadow = resolvedSm[light.m_shadowLayer];
 #else
-			const F32 shadow = resolvedSm[resolvedSmIdx++];
+			const ANKI_RP F32 shadow = resolvedSm[resolvedSmIdx++];
 #endif
 			lambert *= shadow;
 		}

+ 13 - 13
AnKi/Shaders/PackFunctions.glsl

@@ -134,13 +134,13 @@ const F32 MIN_ROUGHNESS = 0.05;
 // G-Buffer structure
 struct GbufferInfo
 {
-	Vec3 m_diffuse;
-	Vec3 m_specular;
-	Vec3 m_normal;
-	F32 m_roughness;
-	F32 m_metallic;
-	F32 m_subsurface;
-	F32 m_emission;
+	ANKI_RP Vec3 m_diffuse;
+	ANKI_RP Vec3 m_specular;
+	ANKI_RP Vec3 m_normal;
+	ANKI_RP F32 m_roughness;
+	ANKI_RP F32 m_metallic;
+	ANKI_RP F32 m_subsurface;
+	ANKI_RP F32 m_emission;
 	Vec2 m_velocity;
 };
 
@@ -156,29 +156,29 @@ void writeGBuffer(GbufferInfo g, out Vec4 rt0, out Vec4 rt1, out Vec4 rt2, out V
 	rt3 = g.m_velocity;
 }
 
-Vec3 unpackNormalFromGBuffer(Vec4 gbuffer)
+ANKI_RP Vec3 unpackNormalFromGBuffer(Vec4 gbuffer)
 {
 	return signedOctDecode(gbuffer.gba);
 }
 
 // Read from G-buffer
-Vec3 readNormalFromGBuffer(texture2D rt2, sampler sampl, Vec2 uv)
+ANKI_RP Vec3 readNormalFromGBuffer(texture2D rt2, sampler sampl, Vec2 uv)
 {
 	return unpackNormalFromGBuffer(textureLod(rt2, sampl, uv, 0.0));
 }
 
 // Read the roughness from G-buffer
-F32 readRoughnessFromGBuffer(texture2D rt1, sampler sampl, Vec2 uv)
+ANKI_RP F32 readRoughnessFromGBuffer(texture2D rt1, sampler sampl, Vec2 uv)
 {
-	F32 r = textureLod(rt1, sampl, uv, 0.0).r;
+	ANKI_RP F32 r = textureLod(rt1, sampl, uv, 0.0).r;
 	r = r * (1.0 - MIN_ROUGHNESS) + MIN_ROUGHNESS;
 	return r;
 }
 
 // Read part of the G-buffer
-void readGBuffer(texture2D rt0, texture2D rt1, texture2D rt2, sampler sampl, Vec2 uv, F32 lod, out GbufferInfo g)
+void readGBuffer(texture2D rt0, texture2D rt1, texture2D rt2, sampler sampl, Vec2 uv, out GbufferInfo g)
 {
-	Vec4 comp = textureLod(rt0, sampl, uv, 0.0);
+	ANKI_RP Vec4 comp = textureLod(rt0, sampl, uv, 0.0);
 	g.m_diffuse = comp.xyz;
 	g.m_subsurface = comp.w;
 

+ 1 - 1
AnKi/Shaders/TraditionalDeferredShading.ankiprog

@@ -93,7 +93,7 @@ void main()
 
 	// Decode and process gbuffer
 	GbufferInfo gbuffer;
-	readGBuffer(u_msRt0, u_msRt1, u_msRt2, u_msSampler, uvToRead, 0.0, gbuffer);
+	readGBuffer(u_msRt0, u_msRt1, u_msRt2, u_msSampler, uvToRead, gbuffer);
 	gbuffer.m_subsurface = max(gbuffer.m_subsurface, SUBSURFACE_MIN * 8.0);
 
 	const Vec4 worldPos4 = u_unis.m_invViewProjMat * Vec4(UV_TO_NDC(uvToWrite), depth, 1.0);