Browse Source

Some shader 16bit fixes

Panagiotis Christopoulos Charitos 1 year ago
parent
commit
bb7e55cd6a

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

@@ -17,8 +17,8 @@ constexpr U32 kMaxVisibleReflectionProbes = 16u;
 constexpr U32 kMaxVisibleGlobalIlluminationProbes = 8u;
 
 // Other consts
-constexpr RF32 kClusterObjectFrustumNearPlane = 0.1f / 4.0f; ///< Near plane of all clusterer object frustums.
-constexpr RF32 kSubsurfaceMin = 0.01f;
+constexpr F32 kClusterObjectFrustumNearPlane = 0.1f / 4.0f; ///< Near plane of all clusterer object frustums.
+constexpr F32 kSubsurfaceMin = 0.01f;
 constexpr U32 kMaxZsplitCount = 128u;
 constexpr U32 kClusteredShadingTileSize = 64; ///< The size of the tile in clustered shading.
 
@@ -26,9 +26,9 @@ constexpr U32 kClusteredShadingTileSize = 64; ///< The size of the tile in clust
 struct LightUnion
 {
 	Vec3 m_position; ///< Position in world space.
-	RF32 m_radius; ///< Radius
+	F32 m_radius; ///< Radius
 
-	RVec3 m_diffuseColor;
+	Vec3 m_diffuseColor;
 	U32 m_lightType; ///< 0 is point and 1 is spot
 
 	U32 m_shadow;
@@ -36,7 +36,7 @@ struct LightUnion
 	F32 m_outerCos; ///< SPOT LIGHTS
 	F32 m_padding;
 
-	RVec3 m_direction; ///< SPOT LIGHTS: Light direction.
+	Vec3 m_direction; ///< SPOT LIGHTS: Light direction.
 	F32 m_shadowAtlasTileScale; ///< POINT LIGHTS: UV scale for all tiles.
 
 	/// When it's a point light this is an array of 6 Vec2s (but because of padding it's actually Vec4s). When it's a spot light the first 4 Vec4s are
@@ -49,9 +49,9 @@ struct LightUnion
 struct PointLight
 {
 	Vec3 m_position; ///< Position in world space.
-	RF32 m_radius; ///< Radius
+	F32 m_radius; ///< Radius
 
-	RVec3 m_diffuseColor;
+	Vec3 m_diffuseColor;
 	U32 m_padding1;
 
 	U32 m_shadow;
@@ -59,7 +59,7 @@ struct PointLight
 	U32 m_padding3;
 	U32 m_padding4;
 
-	RVec3 m_padding5;
+	Vec3 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.
@@ -71,9 +71,9 @@ static_assert(sizeof(PointLight) == sizeof(LightUnion));
 struct SpotLight
 {
 	Vec3 m_position; ///< Position in world space.
-	RF32 m_radius; ///< Radius
+	F32 m_radius; ///< Radius
 
-	RVec3 m_diffuseColor;
+	Vec3 m_diffuseColor;
 	U32 m_padding1;
 
 	U32 m_shadow;
@@ -81,7 +81,7 @@ struct SpotLight
 	F32 m_outerCos;
 	F32 m_padding2;
 
-	RVec3 m_direction;
+	Vec3 m_direction;
 	F32 m_padding3;
 
 	Mat4 m_textureMatrix;

+ 8 - 8
AnKi/Shaders/Include/GpuSceneTypes.h

@@ -108,9 +108,9 @@ struct GpuSceneLightVisibleRenderablesHash
 struct GpuSceneLight
 {
 	Vec3 m_position ANKI_CPP_CODE(= Vec3(kSomeFarDistance)); ///< Position in world space.
-	RF32 m_radius ANKI_CPP_CODE(= 0.0f); ///< Radius.
+	F32 m_radius ANKI_CPP_CODE(= 0.0f); ///< Radius.
 
-	RVec3 m_diffuseColor;
+	Vec3 m_diffuseColor;
 	U32 m_visibleRenderablesHashIndex; ///< Points to a GpuSceneLightVisibleRenderablesHash
 
 	GpuSceneLightFlag m_flags;
@@ -118,8 +118,8 @@ struct GpuSceneLight
 	U32 m_uuid; ///< The UUID of that light. If it's zero the GPU will not inform the CPU about it.
 	F32 m_innerCos; ///< Only for spot light.
 
-	RVec3 m_direction; ///< Only for spot light. Light direction.
-	RF32 m_outerCos; ///< Only for spot light.
+	Vec3 m_direction; ///< Only for spot light. Light direction.
+	F32 m_outerCos; ///< Only for spot light.
 
 	Vec4 m_edgePoints[4u]; ///< Edge points in world space. Only for spot light.
 
@@ -153,7 +153,7 @@ struct GpuSceneGlobalIlluminationProbe
 
 	U32 m_volumeTexture; ///< Bindless index of the irradiance volume texture.
 	F32 m_halfTexelSizeU; ///< (1.0 / textureSize(texArr[textureIndex]).x) / 2.0
-	RF32 m_fadeDistance; ///< Used to calculate a factor that is zero when fragPos is close to AABB bounds and 1.0 at fadeDistance and less.
+	F32 m_fadeDistance; ///< Used to calculate a factor that is zero when fragPos is close to AABB bounds and 1.0 at fadeDistance and less.
 	F32 m_padding2;
 };
 constexpr U32 kSizeof_GpuSceneGlobalIlluminationProbe = 3u * sizeof(Vec4);
@@ -164,8 +164,8 @@ struct GpuSceneDecal
 {
 	U32 m_diffuseTexture;
 	U32 m_roughnessMetalnessTexture;
-	RF32 m_diffuseBlendFactor;
-	RF32 m_roughnessMetalnessFactor;
+	F32 m_diffuseBlendFactor;
+	F32 m_roughnessMetalnessFactor;
 
 	Mat4 m_textureMatrix;
 
@@ -182,7 +182,7 @@ struct GpuSceneFogDensityVolume
 	U32 m_isBox ANKI_CPP_CODE(= 1);
 
 	Vec3 m_aabbMaxOrSphereRadius ANKI_CPP_CODE(= Vec3(kSomeFarDistance));
-	RF32 m_density;
+	F32 m_density;
 };
 constexpr U32 kSizeof_GpuSceneFogDensityVolume = 2u * sizeof(Vec4);
 static_assert(sizeof(GpuSceneFogDensityVolume) == kSizeof_GpuSceneFogDensityVolume);

+ 2 - 2
AnKi/Shaders/Include/MeshTypes.h

@@ -78,10 +78,10 @@ constexpr Format kMeshletPrimitiveFormat = Format::kR8G8B8A8_Uint;
 struct UnpackedMeshVertex
 {
 	Vec3 m_position;
-	RVec3 m_normal;
+	Vec3 m_normal;
 	Vec2 m_uv;
 	UVec4 m_boneIndices;
-	RVec4 m_boneWeights;
+	Vec4 m_boneWeights;
 };
 
 /// Contains the meshlet data accessed by the task shaders (or whomever does meshlet visibility).

+ 11 - 11
AnKi/Shaders/Include/MiscRendererTypes.h

@@ -12,7 +12,7 @@ ANKI_BEGIN_NAMESPACE
 /// Directional light (sun).
 struct DirectionalLight
 {
-	RVec3 m_diffuseColor;
+	Vec3 m_diffuseColor;
 	F32 m_power;
 
 	Vec3 m_direction;
@@ -125,7 +125,7 @@ struct RtShadowsSbtBuildConstants
 struct LensFlareSprite
 {
 	Vec4 m_posScale; // xy: Position, zw: Scale
-	RVec4 m_color;
+	Vec4 m_color;
 	Vec4 m_depthPad3;
 };
 
@@ -154,12 +154,12 @@ struct PixelFailedSsr
 // Vol fog
 struct VolumetricFogConstants
 {
-	RVec3 m_fogDiffuse;
-	RF32 m_fogScatteringCoeff;
+	Vec3 m_fogDiffuse;
+	F32 m_fogScatteringCoeff;
 
-	RF32 m_fogAbsorptionCoeff;
-	RF32 m_near;
-	RF32 m_far;
+	F32 m_fogAbsorptionCoeff;
+	F32 m_near;
+	F32 m_far;
 	F32 m_zSplitCountf;
 
 	UVec3 m_volumeSize;
@@ -169,8 +169,8 @@ struct VolumetricFogConstants
 // Vol lighting
 struct VolumetricLightingConstants
 {
-	RF32 m_densityAtMinHeight;
-	RF32 m_densityAtMaxHeight;
+	F32 m_densityAtMinHeight;
+	F32 m_densityAtMaxHeight;
 	F32 m_minHeight;
 	F32 m_oneOverMaxMinusMinHeight; // 1 / (maxHeight / minHeight)
 
@@ -181,7 +181,7 @@ struct VolumetricLightingConstants
 // SSAO
 struct SsaoConstants
 {
-	RF32 m_radius; ///< In meters.
+	F32 m_radius; ///< In meters.
 	U32 m_sampleCount;
 	Vec2 m_viewportSizef;
 
@@ -193,7 +193,7 @@ struct SsaoConstants
 	F32 m_projectionMat23;
 
 	Vec2 m_padding;
-	RF32 m_ssaoPower;
+	F32 m_ssaoPower;
 	U32 m_frameCount;
 
 	Mat3x4 m_viewMat;

+ 5 - 3
AnKi/Shaders/Reflections.ankiprog

@@ -3,6 +3,8 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
+#pragma anki 16bit
+
 #pragma anki mutator SSR_SAMPLE_GBUFFER 0 1
 
 #pragma anki technique Classification comp mutators
@@ -218,8 +220,8 @@ groupshared Vec4 g_colorAndDepth[NUM_THREADS_SQRT][NUM_THREADS_SQRT];
 Vec3 doLightShading(Vec3 worldPos, Vec3 viewPos, UVec2 coord, F32 depth)
 {
 	// Read
-	GbufferInfo<RF32> gbuffer = (GbufferInfo<RF32>)0;
-	unpackGBufferNoVelocity<RF32>(g_gbufferRt0[coord], g_gbufferRt1[coord], g_gbufferRt2[coord], gbuffer);
+	GbufferInfo<F32> gbuffer = (GbufferInfo<F32>)0;
+	unpackGBufferNoVelocity<F32>(g_gbufferRt0[coord], g_gbufferRt1[coord], g_gbufferRt2[coord], gbuffer);
 
 	Vec3 outColor = gbuffer.m_emission;
 	Cluster cluster = getClusterFragCoord(g_clusters, g_globalRendererConstants, Vec3(coord.xy + 0.5, depth));
@@ -322,7 +324,7 @@ void doSsr(UVec2 logicalViewportSize, UVec2 realCoord, UVec2 logicalCoord, Vec2
 
 			// Read the light buffer
 			const Vec3 ssrColor = g_lightBufferRt.SampleLevel(g_trilinearClampSampler, hitPoint.xy, 0.0).rgb;
-			outColor = clamp(ssrColor, 0.0, kMaxRF32); // Fix the value just in case
+			outColor = clamp(ssrColor, 0.0, kMaxF32); // Fix the value just in case
 		}
 		else
 		{

+ 6 - 6
AnKi/Shaders/SsRaymarching.hlsl

@@ -156,7 +156,7 @@ void raymarchGroundTruth(Vec3 rayOrigin, // Ray origin in view space
 						 U32 stepIncrement_, // The step increment of each iteration
 						 U32 initialStepIncrement, // The initial step
 						 out Vec3 hitPoint, // Hit point in UV coordinates
-						 out RF32 attenuation)
+						 out F32 attenuation)
 {
 	attenuation = 0.0;
 	hitPoint = Vec3(uv, depthRef);
@@ -227,11 +227,11 @@ void raymarchGroundTruth(Vec3 rayOrigin, // Ray origin in view space
 			// Found it
 
 			// Compute attenuation
-			const RF32 blackMargin = 0.05 / 4.0;
-			const RF32 whiteMargin = 0.1 / 2.0;
-			const RVec2 marginAttenuation2d =
+			const F32 blackMargin = 0.05 / 4.0;
+			const F32 whiteMargin = 0.1 / 2.0;
+			const Vec2 marginAttenuation2d =
 				smoothstep(blackMargin, whiteMargin, newHit.xy) * (1.0 - smoothstep(1.0 - whiteMargin, 1.0 - blackMargin, newHit.xy));
-			const RF32 marginAttenuation = marginAttenuation2d.x * marginAttenuation2d.y;
+			const F32 marginAttenuation = marginAttenuation2d.x * marginAttenuation2d.y;
 			attenuation = marginAttenuation * cameraContribution;
 
 			hitPoint = newHit;
@@ -241,7 +241,7 @@ void raymarchGroundTruth(Vec3 rayOrigin, // Ray origin in view space
 	}
 }
 
-void rejectBackFaces(Vec3 reflection, Vec3 normalAtHitPoint, out RF32 attenuation)
+void rejectBackFaces(Vec3 reflection, Vec3 normalAtHitPoint, out F32 attenuation)
 {
 	attenuation = smoothstep(-0.17, 0.0, dot(normalAtHitPoint, -reflection));
 }