Sfoglia il codice sorgente

GBufferGeneric -> HLSL

Panagiotis Christopoulos Charitos 3 anni fa
parent
commit
ea0e043246

+ 2 - 0
AnKi/Resource/MaterialResource.cpp

@@ -611,6 +611,7 @@ Error MaterialResource::findBuiltinMutators(Program& prog)
 
 
 		++builtinMutatorCount;
 		++builtinMutatorCount;
 
 
+#if 0
 		// Find if the bindings are present
 		// Find if the bindings are present
 		ConstWeakArray<ShaderProgramBinaryBlock> storageBlocks = prog.m_prog->getBinary().m_storageBlocks;
 		ConstWeakArray<ShaderProgramBinaryBlock> storageBlocks = prog.m_prog->getBinary().m_storageBlocks;
 		U foundCount = 0;
 		U foundCount = 0;
@@ -631,6 +632,7 @@ Error MaterialResource::findBuiltinMutators(Program& prog)
 							   bonesMutatorName.cstr());
 							   bonesMutatorName.cstr());
 			return Error::kUserData;
 			return Error::kUserData;
 		}
 		}
+#endif
 
 
 		m_supportsSkinning = true;
 		m_supportsSkinning = true;
 		prog.m_presentBuildinMutators |= U32(1 << BuiltinMutatorId::kBones);
 		prog.m_presentBuildinMutators |= U32(1 << BuiltinMutatorId::kBones);

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

@@ -41,7 +41,7 @@ void RenderComponent::allocateAndSetupUniforms(const MaterialResourcePtr& mtl, c
 			static_cast<RenderableGpuView*>(alloc.allocateFrame(renderableGpuViewsUboSize, token));
 			static_cast<RenderableGpuView*>(alloc.allocateFrame(renderableGpuViewsUboSize, token));
 		ANKI_ASSERT(isAligned(alignof(RenderableGpuView), renderableGpuViews));
 		ANKI_ASSERT(isAligned(alignof(RenderableGpuView), renderableGpuViews));
 
 
-		cmdb->bindUniformBuffer(set, kMaterialBindingRenderableGpuView, alloc.getBuffer(), token.m_offset,
+		cmdb->bindStorageBuffer(set, kMaterialBindingRenderableGpuView, alloc.getBuffer(), token.m_offset,
 								token.m_range);
 								token.m_range);
 
 
 		for(U32 i = 0; i < transforms.getSize(); ++i)
 		for(U32 i = 0; i < transforms.getSize(); ++i)

+ 1 - 2
AnKi/ShaderCompiler/ShaderProgramParser.cpp

@@ -543,8 +543,7 @@ Error ShaderProgramParser::parseLine(CString line, CString fname, Bool& foundPra
 		}
 		}
 		else
 		else
 		{
 		{
-			// Some other pragma
-			ANKI_SHADER_COMPILER_LOGW("Ignoring: %s", line.cstr());
+			// Some other pragma, ignore
 			m_codeLines.pushBack(line);
 			m_codeLines.pushBack(line);
 		}
 		}
 	}
 	}

+ 0 - 8
AnKi/Shaders/ForwardShadingFog.ankiprog

@@ -8,14 +8,6 @@
 #include <AnKi/Shaders/ForwardShadingCommon.glsl>
 #include <AnKi/Shaders/ForwardShadingCommon.glsl>
 #include <AnKi/Shaders/Functions.glsl>
 #include <AnKi/Shaders/Functions.glsl>
 
 
-struct PerDraw
-{
-	Mat3x4 m_ankiTransform;
-	ANKI_RP Vec3 m_fogColor;
-	ANKI_RP F32 m_fogAlphaScale;
-	ANKI_RP F32 m_fogDistanceOfMaxThikness;
-};
-
 #pragma anki reflect AnKiLocalUniforms
 #pragma anki reflect AnKiLocalUniforms
 #pragma anki struct AnKiLocalUniforms
 #pragma anki struct AnKiLocalUniforms
 #pragma anki member ANKI_RP Vec3 m_fogColor
 #pragma anki member ANKI_RP Vec3 m_fogColor

+ 201 - 243
AnKi/Shaders/GBufferGeneric.ankiprog

@@ -3,6 +3,8 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
+#pragma anki hlsl
+
 #pragma anki mutator ANKI_LOD 0 1 2
 #pragma anki mutator ANKI_LOD 0 1 2
 #pragma anki mutator ANKI_VELOCITY 0 1
 #pragma anki mutator ANKI_VELOCITY 0 1
 #pragma anki mutator ANKI_TECHNIQUE 0 1 2
 #pragma anki mutator ANKI_TECHNIQUE 0 1 2
@@ -24,379 +26,335 @@
 #pragma anki skip_mutation ANKI_LOD 1 ANKI_TECHNIQUE 2
 #pragma anki skip_mutation ANKI_LOD 1 ANKI_TECHNIQUE 2
 #pragma anki skip_mutation ANKI_LOD 2 ANKI_TECHNIQUE 2
 #pragma anki skip_mutation ANKI_LOD 2 ANKI_TECHNIQUE 2
 
 
+// Some defines the clear up things
 #define REALLY_ALPHA_TEST (ALPHA_TEST && DIFFUSE_TEX)
 #define REALLY_ALPHA_TEST (ALPHA_TEST && DIFFUSE_TEX)
+#define UVS (ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER || REALLY_ALPHA_TEST)
+#define REALLY_VELOCITY ((ANKI_VELOCITY || ANKI_BONES) && ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER)
+#define REALLY_USING_PARALLAX \
+	(PARALLAX == 1 && ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER && ANKI_LOD == 0 && ALPHA_TEST == 0)
+
+#include <AnKi/Shaders/Include/MaterialTypes.h>
+#include <AnKi/Shaders/Include/GpuSceneTypes.h>
+#include <AnKi/Shaders/PackFunctions.hlsl>
+#include <AnKi/Shaders/Functions.hlsl>
 
 
-#include <AnKi/Shaders/GBufferCommon.glsl>
-#include <AnKi/Shaders/Functions.glsl>
+ANKI_BINDLESS_SET(kMaterialSetBindless)
 
 
-layout(set = kMaterialSetGlobal, binding = kMaterialBindingTrilinearRepeatSampler) uniform sampler u_globalSampler;
+[[vk::binding(kMaterialBindingTrilinearRepeatSampler, kMaterialSetGlobal)]] SamplerState u_globalSampler;
+[[vk::binding(kMaterialBindingLocalUniforms, kMaterialSetLocal)]] StructuredBuffer<U32> u_localUniforms;
+[[vk::binding(kMaterialBindingRenderableGpuView, kMaterialSetLocal)]] StructuredBuffer<RenderableGpuView>
+	u_renderableGpuViews;
+[[vk::binding(kMaterialBindingGlobalUniforms, kMaterialSetGlobal)]] ConstantBuffer<MaterialGlobalUniforms>
+	u_globalUniforms;
+
+#if ANKI_BONES
+[[vk::binding(kMaterialBindingBoneTransforms, kMaterialSetLocal)]] StructuredBuffer<Mat4> u_boneTransforms;
+[[vk::binding(kMaterialBindingPreviousBoneTransforms, kMaterialSetLocal)]] StructuredBuffer<Mat4>
+	u_prevFrameBoneTransforms;
+#endif
 
 
 #pragma anki reflect AnKiLocalUniforms
 #pragma anki reflect AnKiLocalUniforms
 #pragma anki struct AnKiLocalUniforms
 #pragma anki struct AnKiLocalUniforms
 #pragma anki member U32 m_normalTex if NORMAL_TEX is 1
 #pragma anki member U32 m_normalTex if NORMAL_TEX is 1
 
 
-#pragma anki member ANKI_RP Vec3 m_diffColor if DIFFUSE_TEX is 0
+#pragma anki member Vec3 m_diffColor if DIFFUSE_TEX is 0
 #pragma anki member U32 m_diffTex if DIFFUSE_TEX is 1
 #pragma anki member U32 m_diffTex if DIFFUSE_TEX is 1
 
 
-#pragma anki member ANKI_RP F32 m_roughness if ROUGHNESS_TEX is 0
+#pragma anki member F32 m_roughness if ROUGHNESS_TEX is 0
 #pragma anki member U32 m_roughnessTex if ROUGHNESS_TEX is 1
 #pragma anki member U32 m_roughnessTex if ROUGHNESS_TEX is 1
 
 
-#pragma anki member ANKI_RP Vec3 m_specColor if SPECULAR_TEX is 0
+#pragma anki member Vec3 m_specColor if SPECULAR_TEX is 0
 #pragma anki member U32 m_specTex if SPECULAR_TEX is 1
 #pragma anki member U32 m_specTex if SPECULAR_TEX is 1
 
 
-#pragma anki member ANKI_RP F32 m_metallic if METAL_TEX is 0
+#pragma anki member F32 m_metallic if METAL_TEX is 0
 #pragma anki member U32 m_metallicTex if METAL_TEX is 1
 #pragma anki member U32 m_metallicTex if METAL_TEX is 1
 
 
-#pragma anki member ANKI_RP Vec3 m_emission if EMISSIVE_TEX is 0
+#pragma anki member Vec3 m_emission if EMISSIVE_TEX is 0
 #pragma anki member U32 m_emissiveTex if EMISSIVE_TEX is 1
 #pragma anki member U32 m_emissiveTex if EMISSIVE_TEX is 1
 
 
-#pragma anki member ANKI_RP F32 m_heightmapScale if PARALLAX is 1
+#pragma anki member F32 m_heightmapScale if PARALLAX is 1
 #pragma anki member U32 m_heightTex if PARALLAX is 1
 #pragma anki member U32 m_heightTex if PARALLAX is 1
 
 
-#pragma anki member ANKI_RP F32 m_subsurface
+#pragma anki member F32 m_subsurface
 #pragma anki struct end
 #pragma anki struct end
 
 
-layout(set = kMaterialSetLocal, binding = kMaterialBindingLocalUniforms, std430) buffer b_localUniforms
+struct VertIn
 {
 {
-	U32 u_localUniforms[];
-};
+	[[vk::location(VertexStreamId::kPosition)]] Vec3 m_position : POSITION;
+	U32 m_instanceId : SV_INSTANCEID;
 
 
-layout(set = kMaterialSetLocal, binding = kMaterialBindingRenderableGpuView) uniform b_renderableGpuView
-{
-	RenderableGpuView u_renderableGpuViews[kMaxInstanceCount];
-};
+#if ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER
+	[[vk::location(VertexStreamId::kNormal)]] RVec3 m_normal : NORMAL;
+	[[vk::location(VertexStreamId::kTangent)]] RVec4 m_tangent : TANGENT;
+#endif
 
 
-layout(set = kMaterialSetGlobal, binding = kMaterialBindingGlobalUniforms) uniform b_globalUniforms
-{
-	MaterialGlobalUniforms u_globalUniforms;
-};
+#if UVS
+	[[vk::location(VertexStreamId::kUv)]] Vec2 m_uv : TEXCOORD;
+#endif
 
 
 #if ANKI_BONES
 #if ANKI_BONES
-#	pragma anki reflect b_boneTransforms
-layout(set = kMaterialSetLocal, binding = kMaterialBindingBoneTransforms, row_major,
-	   std140) readonly buffer b_boneTransforms
-{
-	Mat4 u_boneTransforms[];
+	[[vk::location(VertexStreamId::kBoneIds)]] UVec4 m_boneIndices : COLOR0;
+	[[vk::location(VertexStreamId::kBoneWeights)]] RVec4 m_boneWeights : COLOR1;
+#endif
 };
 };
 
 
-#	pragma anki reflect b_prevFrameBoneTransforms
-layout(set = kMaterialSetLocal, binding = kMaterialBindingPreviousBoneTransforms, row_major,
-	   std140) readonly buffer b_prevFrameBoneTransforms
+struct VertOut
 {
 {
-	Mat4 u_prevFrameBoneTransforms[];
-};
-#endif
+	Vec4 m_position : SV_POSITION;
 
 
-#pragma anki start vert
-
-// Globals (always in local space)
-#if ANKI_BONES
-Vec3 g_position = in_position * u_renderableGpuViews[gl_InstanceIndex].m_positionScaleF32AndTranslationVec3.x
-				  + u_renderableGpuViews[gl_InstanceIndex].m_positionScaleF32AndTranslationVec3.yzw;
-#else
-Vec3 g_position = in_position;
+#if UVS
+	Vec2 m_uv : TEXCOORD;
 #endif
 #endif
 
 
-#if ANKI_TECHNIQUE == RENDERING_TECHNIQUE_GBUFFER
-
-#	if ANKI_BONES
-Vec3 g_prevPosition = in_position * u_renderableGpuViews[gl_InstanceIndex].m_positionScaleF32AndTranslationVec3.x
-					  + u_renderableGpuViews[gl_InstanceIndex].m_positionScaleF32AndTranslationVec3.yzw;
-#	else
-Vec3 g_prevPosition = in_position;
-#	endif
+#if REALLY_VELOCITY
+	Vec3 m_prevClipXyw : PREV_CLIP;
+	Vec3 m_crntClipXyw : CRNT_CLIP;
+#endif
 
 
-ANKI_RP Vec3 g_normal = in_normal;
-ANKI_RP Vec4 g_tangent = in_tangent;
+#if ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER
+	RVec3 m_normal : NORMAL;
+	RVec3 m_tangent : TANGENT;
+	RVec3 m_bitangent : BINTANGENT;
 #endif
 #endif
+};
 
 
-#if ANKI_TECHNIQUE == RENDERING_TECHNIQUE_GBUFFER || REALLY_ALPHA_TEST
-Vec2 g_uv = in_uv;
+#if ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER || ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER_EZ
+struct FragOut
+{
+	Vec4 m_color0 : SV_TARGET0;
+	Vec4 m_color1 : SV_TARGET1;
+	Vec4 m_color2 : SV_TARGET2;
+	Vec2 m_color3 : SV_TARGET3;
+};
 #endif
 #endif
 
 
-// Perform skinning
+#pragma anki start vert
+
 #if ANKI_BONES
 #if ANKI_BONES
-void skinning()
+void skinning(VertIn input, inout Vec3 pos, inout Vec3 prevPos, inout RVec3 normal, inout RVec4 tangent)
 {
 {
-	ANKI_RP Mat4 skinMat = u_boneTransforms[in_boneIndices[0]] * in_boneWeights[0];
-	ANKI_RP Mat4 prevSkinMat = u_prevFrameBoneTransforms[in_boneIndices[0]] * in_boneWeights[0];
+	Mat4 skinMat = u_boneTransforms[input.m_boneIndices[0]] * input.m_boneWeights[0];
+	Mat4 prevSkinMat = u_prevFrameBoneTransforms[input.m_boneIndices[0]] * input.m_boneWeights[0];
 	[[unroll]] for(U32 i = 1u; i < 4u; ++i)
 	[[unroll]] for(U32 i = 1u; i < 4u; ++i)
 	{
 	{
-		skinMat += u_boneTransforms[in_boneIndices[i]] * in_boneWeights[i];
-		prevSkinMat += u_prevFrameBoneTransforms[in_boneIndices[i]] * in_boneWeights[i];
+		skinMat += u_boneTransforms[input.m_boneIndices[i]] * input.m_boneWeights[i];
+		prevSkinMat += u_prevFrameBoneTransforms[input.m_boneIndices[i]] * input.m_boneWeights[i];
 	}
 	}
 
 
-#	if ANKI_TECHNIQUE == RENDERING_TECHNIQUE_GBUFFER
-	g_prevPosition = (prevSkinMat * Vec4(g_position, 1.0)).xyz;
-	g_tangent.xyz = (skinMat * Vec4(g_tangent.xyz, 0.0)).xyz;
-	g_normal = (skinMat * Vec4(g_normal, 0.0)).xyz;
+#	if ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER
+	prevPos = mul(prevSkinMat, Vec4(pos, 1.0)).xyz;
+	tangent.xyz = mul(skinMat, Vec4(tangent.xyz, 0.0)).xyz;
+	normal = mul(skinMat, Vec4(normal, 0.0)).xyz;
 #	endif
 #	endif
+	ANKI_MAYBE_UNUSED(prevPos);
+	ANKI_MAYBE_UNUSED(tangent);
+	ANKI_MAYBE_UNUSED(normal);
 
 
-	g_position = (skinMat * Vec4(g_position, 1.0)).xyz;
-}
-#endif
-
-// Common store function
-#if ANKI_TECHNIQUE == RENDERING_TECHNIQUE_GBUFFER
-void positionUvNormalTangent()
-{
-	gl_Position = Vec4(transform(u_renderableGpuViews[gl_InstanceIndex].m_worldTransform, Vec4(g_position, 1.0)), 1.0);
-	gl_Position = u_globalUniforms.m_viewProjectionMatrix * gl_Position;
-
-	out_normal = transform(u_renderableGpuViews[gl_InstanceIndex].m_worldTransform, Vec4(g_normal, 0.0));
-	out_tangent = transform(u_renderableGpuViews[gl_InstanceIndex].m_worldTransform, Vec4(g_tangent.xyz, 0.0));
-	out_bitangent = cross(out_normal, out_tangent) * g_tangent.w;
-	out_uv = g_uv;
-}
-#endif
-
-// Store stuff for parallax mapping
-#if REALLY_USING_PARALLAX
-void parallax()
-{
-	const Vec3 n = in_normal;
-	const Vec3 t = in_tangent.xyz;
-	const Vec3 b = cross(n, t) * in_tangent.w;
-
-	// TODO
-	const Mat3 invTbn = Mat3(1.0);
-	// const Mat3 invTbn = transpose(u_globalUniforms.m_viewRotationMatrix
-	//							  * u_renderableGpuViews[gl_InstanceIndex].m_worldRotation * Mat3(t, b, n));
-
-	const Vec4 v4 =
-		Vec4(transform(u_renderableGpuViews[gl_InstanceIndex].m_worldTransform, Vec4(g_position, 1.0)), 1.0);
-	const Vec3 viewPos = u_globalUniforms.m_viewMatrix * v4;
-	out_distFromTheCamera = viewPos.z;
-
-	out_eyeTangentSpace = invTbn * viewPos;
-	out_normalTangentSpace = invTbn * n;
+	pos = mul(skinMat, Vec4(pos, 1.0)).xyz;
 }
 }
 #endif
 #endif
 
 
-#if(ANKI_VELOCITY || ANKI_BONES) && ANKI_TECHNIQUE == RENDERING_TECHNIQUE_GBUFFER
-void velocity()
+#if(ANKI_VELOCITY || ANKI_BONES) && ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER
+void velocity(RenderableGpuView view, Vec3 prevLocalPos, inout VertOut output)
 {
 {
-	const Vec3 prevLocalPos = g_prevPosition;
-
 #	if ANKI_VELOCITY
 #	if ANKI_VELOCITY
 	// Object is also moving
 	// Object is also moving
-	const Vec4 trf[3] = u_renderableGpuViews[gl_InstanceIndex].m_previousWorldTransform;
+	const Vec4 trf[3] = view.m_previousWorldTransform;
 #	else
 #	else
 	// Object is a skin that is not moving
 	// Object is a skin that is not moving
-	const Vec4 trf[3] = u_renderableGpuViews[gl_InstanceIndex].m_worldTransform;
+	const Vec4 trf[3] = view.m_worldTransform;
 #	endif
 #	endif
 
 
 	Vec4 v4 = Vec4(transform(trf, Vec4(prevLocalPos, 1.0)), 1.0);
 	Vec4 v4 = Vec4(transform(trf, Vec4(prevLocalPos, 1.0)), 1.0);
-	v4 = u_globalUniforms.m_previousViewProjectionMatrix * v4;
+	v4 = mul(u_globalUniforms.m_previousViewProjectionMatrix, v4);
 
 
-	out_prevClipXyw = v4.xyw;
-	out_crntClipXyw = gl_Position.xyw;
+	output.m_prevClipXyw = v4.xyw;
+	output.m_crntClipXyw = output.m_position.xyw;
 }
 }
 #endif
 #endif
 
 
-void main()
+VertOut main(VertIn input)
 {
 {
+	const RenderableGpuView view = u_renderableGpuViews[input.m_instanceId];
+	VertOut output;
+
+	// All values in local space
 #if ANKI_BONES
 #if ANKI_BONES
-	skinning();
+	Vec3 pos =
+		input.m_position * view.m_positionScaleF32AndTranslationVec3.x + view.m_positionScaleF32AndTranslationVec3.yzw;
+#else
+	Vec3 pos = input.m_position;
 #endif
 #endif
 
 
-#if ANKI_TECHNIQUE == RENDERING_TECHNIQUE_GBUFFER
-	positionUvNormalTangent();
+	Vec3 prevPos = pos;
+	ANKI_MAYBE_UNUSED(prevPos);
 
 
-#	if REALLY_USING_PARALLAX
-	parallax();
-#	endif
-
-#	if ANKI_VELOCITY || ANKI_BONES
-	velocity();
-#	endif
+#if ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER
+	RVec3 normal = input.m_normal;
+	RVec4 tangent = input.m_tangent;
 #else
 #else
-	gl_Position = Vec4(transform(u_renderableGpuViews[gl_InstanceIndex].m_worldTransform, Vec4(g_position, 1.0)), 1.0);
-	gl_Position = u_globalUniforms.m_viewProjectionMatrix * gl_Position;
-
-#	if REALLY_ALPHA_TEST
-	out_uv = g_uv;
-#	endif
+	RVec3 normal = RVec3(0.0, 0.0, 0.0);
+	RVec4 tangent = RVec4(0.0, 0.0, 0.0, 0.0);
+	ANKI_MAYBE_UNUSED(normal);
+	ANKI_MAYBE_UNUSED(tangent);
 #endif
 #endif
-}
-#pragma anki end
-
-#pragma anki start frag
-
-#if REALLY_USING_PARALLAX
-Vec2 computeTextureCoordParallax(texture2D heightMap, sampler sampl, Vec2 uv, F32 heightMapScale)
-{
-	const U32 kMaxSamples = 25u;
-	const U32 kMinSamples = 1u;
-	const F32 kMaxEffectiveDistance = 32.0;
 
 
-	// Get that because we are sampling inside a loop
-	const Vec2 dPdx = dFdx(uv);
-	const Vec2 dPdy = dFdy(uv);
-
-	const Vec3 eyeTangentSpace = in_eyeTangentSpace;
-	const Vec3 normTangentSpace = in_normalTangentSpace;
-
-	F32 parallaxLimit = -length(eyeTangentSpace.xy) / eyeTangentSpace.z;
-	parallaxLimit *= heightMapScale;
+#if UVS
+	output.m_uv = input.m_uv;
+#endif
 
 
-	const Vec2 offsetDir = normalize(eyeTangentSpace.xy);
-	const Vec2 maxOffset = offsetDir * parallaxLimit;
+	// Do stuff
+#if ANKI_BONES
+	skinning(input, pos, prevPos, normal, tangent);
+#endif
 
 
-	const Vec3 E = normalize(eyeTangentSpace);
+	output.m_position = Vec4(transform(view.m_worldTransform, Vec4(pos, 1.0)), 1.0);
+	output.m_position = mul(u_globalUniforms.m_viewProjectionMatrix, output.m_position);
 
 
-	const F32 factor0 = -dot(E, normTangentSpace);
-	const F32 factor1 = in_distFromTheCamera / -kMaxEffectiveDistance;
-	const F32 factor = saturate((1.0 - factor0) * (1.0 - factor1));
-	const F32 sampleCountf = mix(F32(kMinSamples), F32(kMaxSamples), factor);
+#if ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER
+	output.m_normal = transform(view.m_worldTransform, Vec4(normal, 0.0));
+	output.m_tangent = transform(view.m_worldTransform, Vec4(tangent.xyz, 0.0));
+	output.m_bitangent = cross(output.m_normal, output.m_tangent) * tangent.w;
+#endif
 
 
-	const F32 stepSize = 1.0 / sampleCountf;
+#if REALLY_VELOCITY
+	velocity(view, prevPos, output);
+#endif
 
 
-	F32 crntRayHeight = 1.0;
-	Vec2 crntOffset = Vec2(0.0);
-	Vec2 lastOffset = Vec2(0.0);
+	return output;
+};
 
 
-	F32 lastSampledHeight = 1.0;
-	F32 crntSampledHeight = 1.0;
+#pragma anki end
 
 
-	U32 crntSample = 0u;
+#pragma anki start frag
 
 
-	const U32 sampleCount = U32(sampleCountf);
-	[[dont_unroll]] while(crntSample < sampleCount)
+void doAlphaTest(RF32 alpha)
+{
+	if(alpha == 0.0)
 	{
 	{
-		crntSampledHeight = textureGrad(heightMap, sampl, uv + crntOffset, dPdx, dPdy).r;
-
-		if(crntSampledHeight > crntRayHeight)
-		{
-			const F32 delta1 = crntSampledHeight - crntRayHeight;
-			const F32 delta2 = (crntRayHeight + stepSize) - lastSampledHeight;
-			const F32 ratio = delta1 / (delta1 + delta2);
-
-			crntOffset = mix(crntOffset, lastOffset, ratio);
-
-			crntSample = sampleCount + 1u;
-		}
-		else
-		{
-			crntSample++;
-
-			crntRayHeight -= stepSize;
-
-			lastOffset = crntOffset;
-			crntOffset += stepSize * maxOffset;
-
-			lastSampledHeight = crntSampledHeight;
-		}
+		discard;
 	}
 	}
-
-	return uv + crntOffset;
 }
 }
-#endif
 
 
+#if ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_SHADOWS
+void main(VertOut input)
+{
+	ANKI_MAYBE_UNUSED(input);
+#	if REALLY_ALPHA_TEST
+	const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(u_localUniforms, 0u);
+	const RVec4 diffColorA = u_bindlessTextures2dF32[localUniforms.m_diffTex].Sample(u_globalSampler, input.m_uv);
+	doAlphaTest(diffColorA.a);
+#	endif
+}
+#elif ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER_EZ
+FragOut main(VertOut input)
+{
+	ANKI_MAYBE_UNUSED(input);
+#	if REALLY_ALPHA_TEST
+	const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(u_localUniforms, 0u);
+	const RVec4 diffColorA = u_bindlessTextures2dF32[localUniforms.m_diffTex].Sample(u_globalSampler, input.m_uv);
+	doAlphaTest(diffColorA.a);
+#	endif
+	return (FragOut)0;
+}
+#elif ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER
 // Do normal mapping
 // Do normal mapping
-#if ANKI_TECHNIQUE == RENDERING_TECHNIQUE_GBUFFER
-ANKI_RP Vec3 readNormalFromTexture(ANKI_RP texture2D map, sampler sampl, highp Vec2 texCoords)
+RVec3 readNormalFromTexture(VertOut input, Texture2D<RVec4> map, SamplerState sampl, Vec2 texCoords)
 {
 {
 	// First read the texture
 	// First read the texture
-	const ANKI_RP Vec3 nAtTangentspace = normalize((texture(map, sampl, texCoords).rgb - 0.5) * 2.0);
+	const RVec3 nAtTangentspace = normalize((map.Sample(sampl, texCoords).rgb - 0.5) * 2.0);
 
 
-	const ANKI_RP Vec3 n = normalize(in_normal);
-	const ANKI_RP Vec3 t = normalize(in_tangent);
-	const ANKI_RP Vec3 b = normalize(in_bitangent);
+	const RVec3 n = normalize(input.m_normal);
+	const RVec3 t = normalize(input.m_tangent);
+	const RVec3 b = normalize(input.m_bitangent);
 
 
-	ANKI_RP Vec3 tbnMat[3u];
-	tbnMat[0] = Vec3(t.x, b.x, n.x);
-	tbnMat[1] = Vec3(t.y, b.y, n.y);
-	tbnMat[2] = Vec3(t.z, b.z, n.z);
-	return rotate(tbnMat, nAtTangentspace);
-}
-#endif
+	RVec3 tbnMat[3u];
+	tbnMat[0] = RVec3(t.x, b.x, n.x);
+	tbnMat[1] = RVec3(t.y, b.y, n.y);
+	tbnMat[2] = RVec3(t.z, b.z, n.z);
 
 
-void doAlphaText(F32 alpha)
-{
-	if(alpha == 0.0)
-	{
-		discard;
-	}
+	return rotate(tbnMat, nAtTangentspace);
 }
 }
 
 
-void main()
+FragOut main(VertOut input)
 {
 {
 	const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(u_localUniforms, 0u);
 	const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(u_localUniforms, 0u);
 
 
-#if ANKI_TECHNIQUE == RENDERING_TECHNIQUE_GBUFFER
 #	if REALLY_USING_PARALLAX
 #	if REALLY_USING_PARALLAX
-	const Vec2 uv = computeTextureCoordParallax(u_bindlessTextures2dF32[localUniforms.m_heightTex], u_globalSampler,
-												in_uv, localUniforms.m_heightmapScale);
+	// TODO
+	const Vec2 uv = input.m_uv;
 #	else
 #	else
-	const Vec2 uv = in_uv;
+	const Vec2 uv = input.m_uv;
 #	endif
 #	endif
+	ANKI_MAYBE_UNUSED(uv);
 
 
 #	if DIFFUSE_TEX
 #	if DIFFUSE_TEX
 #		if REALLY_ALPHA_TEST
 #		if REALLY_ALPHA_TEST
-	const ANKI_RP Vec4 diffColorA = texture(u_bindlessTextures2dF32[localUniforms.m_diffTex], u_globalSampler, uv);
-	doAlphaText(diffColorA.a);
-	const ANKI_RP Vec3 diffColor = diffColorA.rgb;
+	const RVec4 diffColorA = u_bindlessTextures2dF32[localUniforms.m_diffTex].Sample(u_globalSampler, uv);
+	doAlphaTest(diffColorA.a);
+	const RVec3 diffColor = diffColorA.rgb;
 #		else
 #		else
-	const ANKI_RP Vec3 diffColor = texture(u_bindlessTextures2dF32[localUniforms.m_diffTex], u_globalSampler, uv).rgb;
+	const RVec3 diffColor = u_bindlessTextures2dF32[localUniforms.m_diffTex].Sample(u_globalSampler, uv).rgb;
 #		endif
 #		endif
 #	else
 #	else
-	const ANKI_RP Vec3 diffColor = localUniforms.m_diffColor;
+	const RVec3 diffColor = localUniforms.m_diffColor;
 #	endif
 #	endif
 
 
 #	if SPECULAR_TEX
 #	if SPECULAR_TEX
-	const ANKI_RP Vec3 specColor = texture(u_bindlessTextures2dF32[localUniforms.m_specTex], u_globalSampler, uv).rgb;
+	const RVec3 specColor = u_bindlessTextures2dF32[localUniforms.m_specTex].Sample(u_globalSampler, uv).rgb;
 #	else
 #	else
-	const ANKI_RP Vec3 specColor = localUniforms.m_specColor;
+	const RVec3 specColor = localUniforms.m_specColor;
 #	endif
 #	endif
 
 
 #	if ROUGHNESS_TEX
 #	if ROUGHNESS_TEX
-	const ANKI_RP F32 roughness = texture(u_bindlessTextures2dF32[localUniforms.m_roughnessTex], u_globalSampler, uv).g;
+	const RF32 roughness = u_bindlessTextures2dF32[localUniforms.m_roughnessTex].Sample(u_globalSampler, uv).g;
 #	else
 #	else
-	const ANKI_RP F32 roughness = localUniforms.m_roughness;
+	const RF32 roughness = localUniforms.m_roughness;
 #	endif
 #	endif
 
 
 #	if METAL_TEX
 #	if METAL_TEX
-	const ANKI_RP F32 metallic = texture(u_bindlessTextures2dF32[localUniforms.m_metallicTex], u_globalSampler, uv).b;
+	const RF32 metallic = u_bindlessTextures2dF32[localUniforms.m_metallicTex].Sample(u_globalSampler, uv).b;
 #	else
 #	else
-	const ANKI_RP F32 metallic = localUniforms.m_metallic;
+	const RF32 metallic = localUniforms.m_metallic;
 #	endif
 #	endif
 
 
 #	if NORMAL_TEX
 #	if NORMAL_TEX
-	const ANKI_RP Vec3 normal =
-		readNormalFromTexture(u_bindlessTextures2dF32[localUniforms.m_normalTex], u_globalSampler, uv);
+	const RVec3 normal =
+		readNormalFromTexture(input, u_bindlessTextures2dF32[localUniforms.m_normalTex], u_globalSampler, uv);
 #	else
 #	else
-	const ANKI_RP Vec3 normal = normalize(in_normal);
+	const RVec3 normal = normalize(input.m_normal);
 #	endif
 #	endif
 
 
 #	if EMISSIVE_TEX
 #	if EMISSIVE_TEX
-	const ANKI_RP Vec3 emission =
-		texture(u_bindlessTextures2dF32[localUniforms.m_emissiveTex], u_globalSampler, uv).rgb;
+	const RVec3 emission = u_bindlessTextures2dF32[localUniforms.m_emissiveTex].Sample(u_globalSampler, uv).rgb;
 #	else
 #	else
-	const ANKI_RP Vec3 emission = localUniforms.m_emission;
+	const RVec3 emission = localUniforms.m_emission;
 #	endif
 #	endif
 
 
 #	if ANKI_VELOCITY || ANKI_BONES
 #	if ANKI_VELOCITY || ANKI_BONES
-	const Vec2 prevNdc = in_prevClipXyw.xy / in_prevClipXyw.z;
-	const Vec2 crntNdc = in_crntClipXyw.xy / in_crntClipXyw.z;
+	const Vec2 prevNdc = input.m_prevClipXyw.xy / input.m_prevClipXyw.z;
+	const Vec2 crntNdc = input.m_crntClipXyw.xy / input.m_crntClipXyw.z;
 
 
 	// It's NDC_TO_UV(prevNdc) - NDC_TO_UV(crntNdc) or:
 	// It's NDC_TO_UV(prevNdc) - NDC_TO_UV(crntNdc) or:
 	const Vec2 velocity = (prevNdc - crntNdc) * 0.5;
 	const Vec2 velocity = (prevNdc - crntNdc) * 0.5;
 #	else
 #	else
-	const Vec2 velocity = Vec2(1.0);
+	const Vec2 velocity = Vec2(1.0, 1.0);
 #	endif
 #	endif
 
 
-	packGBuffer(diffColor, normal, specColor, roughness, localUniforms.m_subsurface, emission, metallic, velocity);
-#elif ANKI_TECHNIQUE == RENDERING_TECHNIQUE_GBUFFER_EZ
-	out_gbuffer0 = Vec4(0.0);
-	out_gbuffer1 = Vec4(0.0);
-	out_gbuffer2 = Vec4(0.0);
-	out_gbuffer3 = Vec2(0.0);
-#endif
-
-#if ANKI_TECHNIQUE != RENDERING_TECHNIQUE_GBUFFER && REALLY_ALPHA_TEST
-	doAlphaText(texture(u_bindlessTextures2dF32[localUniforms.m_diffTex], u_globalSampler, in_uv).a);
-#endif
+	GbufferInfo g;
+	g.m_diffuse = diffColor;
+	g.m_normal = normal;
+	g.m_f0 = specColor;
+	g.m_roughness = roughness;
+	g.m_subsurface = localUniforms.m_subsurface;
+	g.m_emission = emission;
+	g.m_metallic = metallic;
+	g.m_velocity = velocity;
+
+	FragOut output;
+	packGBuffer(g, output.m_color0, output.m_color1, output.m_color2, output.m_color3);
+	return output;
 }
 }
+#endif
 
 
 #pragma anki end
 #pragma anki end

+ 0 - 360
AnKi/Shaders/GBufferGeneric2.ankiprog

@@ -1,360 +0,0 @@
-// Copyright (C) 2009-2022, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-#pragma anki hlsl
-
-#pragma anki mutator ANKI_LOD 0 1 2
-#pragma anki mutator ANKI_VELOCITY 0 1
-#pragma anki mutator ANKI_TECHNIQUE 0 1 2
-#pragma anki mutator ANKI_BONES 0 1
-#pragma anki mutator DIFFUSE_TEX 0 1
-#pragma anki mutator SPECULAR_TEX 0 1
-#pragma anki mutator ROUGHNESS_TEX 0 1
-#pragma anki mutator METAL_TEX 0 1
-#pragma anki mutator NORMAL_TEX 0 1
-#pragma anki mutator PARALLAX 0 1
-#pragma anki mutator EMISSIVE_TEX 0 1
-#pragma anki mutator ALPHA_TEST 0 1
-
-#pragma anki skip_mutation ALPHA_TEST 1 DIFFUSE_TEX 0
-#pragma anki skip_mutation ANKI_VELOCITY 1 ANKI_TECHNIQUE 1
-#pragma anki skip_mutation ANKI_VELOCITY 1 ANKI_TECHNIQUE 2
-#pragma anki skip_mutation ANKI_LOD 1 ANKI_TECHNIQUE 1
-#pragma anki skip_mutation ANKI_LOD 2 ANKI_TECHNIQUE 1
-#pragma anki skip_mutation ANKI_LOD 1 ANKI_TECHNIQUE 2
-#pragma anki skip_mutation ANKI_LOD 2 ANKI_TECHNIQUE 2
-
-// Some defines the clear up things
-#define REALLY_ALPHA_TEST (ALPHA_TEST && DIFFUSE_TEX)
-#define UVS (ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER || REALLY_ALPHA_TEST)
-#define REALLY_VELOCITY ((ANKI_VELOCITY || ANKI_BONES) && ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER)
-#define REALLY_USING_PARALLAX \
-	(PARALLAX == 1 && ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER && ANKI_LOD == 0 && ALPHA_TEST == 0)
-
-#include <AnKi/Shaders/Include/MaterialTypes.h>
-#include <AnKi/Shaders/Include/GpuSceneTypes.h>
-#include <AnKi/Shaders/PackFunctions.hlsl>
-#include <AnKi/Shaders/Functions.hlsl>
-
-ANKI_BINDLESS_SET(kMaterialSetBindless)
-
-[[vk::binding(kMaterialBindingTrilinearRepeatSampler, kMaterialSetGlobal)]] SamplerState u_globalSampler;
-[[vk::binding(kMaterialBindingLocalUniforms, kMaterialSetLocal)]] StructuredBuffer<U32> u_localUniforms;
-[[vk::binding(kMaterialBindingRenderableGpuView, kMaterialSetLocal)]] StructuredBuffer<RenderableGpuView>
-	u_renderableGpuViews;
-[[vk::binding(kMaterialBindingGlobalUniforms, kMaterialSetGlobal)]] ConstantBuffer<MaterialGlobalUniforms>
-	u_globalUniforms;
-
-#if ANKI_BONES
-[[vk::binding(kMaterialBindingBoneTransforms, kMaterialSetLocal)]] StructuredBuffer<Mat4> u_boneTransforms;
-[[vk::binding(kMaterialBindingPreviousBoneTransforms, kMaterialSetLocal)]] StructuredBuffer<Mat4>
-	u_prevFrameBoneTransforms;
-#endif
-
-#pragma anki reflect AnKiLocalUniforms
-#pragma anki struct AnKiLocalUniforms
-#pragma anki member U32 m_normalTex if NORMAL_TEX is 1
-
-#pragma anki member Vec3 m_diffColor if DIFFUSE_TEX is 0
-#pragma anki member U32 m_diffTex if DIFFUSE_TEX is 1
-
-#pragma anki member F32 m_roughness if ROUGHNESS_TEX is 0
-#pragma anki member U32 m_roughnessTex if ROUGHNESS_TEX is 1
-
-#pragma anki member Vec3 m_specColor if SPECULAR_TEX is 0
-#pragma anki member U32 m_specTex if SPECULAR_TEX is 1
-
-#pragma anki member F32 m_metallic if METAL_TEX is 0
-#pragma anki member U32 m_metallicTex if METAL_TEX is 1
-
-#pragma anki member Vec3 m_emission if EMISSIVE_TEX is 0
-#pragma anki member U32 m_emissiveTex if EMISSIVE_TEX is 1
-
-#pragma anki member F32 m_heightmapScale if PARALLAX is 1
-#pragma anki member U32 m_heightTex if PARALLAX is 1
-
-#pragma anki member F32 m_subsurface
-#pragma anki struct end
-
-struct VertIn
-{
-	[[vk::location(VertexStreamId::kPosition)]] Vec3 m_position : POSITION;
-	U32 m_instanceId : SV_INSTANCEID;
-
-#if ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER
-	[[vk::location(VertexStreamId::kNormal)]] RVec3 m_normal : NORMAL;
-	[[vk::location(VertexStreamId::kTangent)]] RVec4 m_tangent : TANGENT;
-#endif
-
-#if UVS
-	[[vk::location(VertexStreamId::kUv)]] Vec2 m_uv : TEXCOORD;
-#endif
-
-#if ANKI_BONES
-	[[vk::location(VertexStreamId::kBoneIds)]] UVec4 m_boneIndices : COLOR0;
-	[[vk::location(VertexStreamId::kBoneWeights)]] RVec4 m_boneWeights : COLOR1;
-#endif
-};
-
-struct VertOut
-{
-	Vec4 m_position : SV_POSITION;
-
-#if UVS
-	Vec2 m_uv : TEXCOORD;
-#endif
-
-#if REALLY_VELOCITY
-	Vec3 m_prevClipXyw : PREV_CLIP;
-	Vec3 m_crntClipXyw : CRNT_CLIP;
-#endif
-
-#if ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER
-	RVec3 m_normal : NORMAL;
-	RVec3 m_tangent : TANGENT;
-	RVec3 m_bitangent : BINTANGENT;
-#endif
-};
-
-#if ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER || ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER_EZ
-struct FragOut
-{
-	Vec4 m_color0 : SV_TARGET0;
-	Vec4 m_color1 : SV_TARGET1;
-	Vec4 m_color2 : SV_TARGET2;
-	Vec2 m_color3 : SV_TARGET3;
-};
-#endif
-
-#pragma anki start vert
-
-#if ANKI_BONES
-void skinning(VertIn input, inout Vec3 pos, inout Vec3 prevPos, inout RVec3 normal, inout RVec4 tangent)
-{
-	Mat4 skinMat = u_boneTransforms[input.m_boneIndices[0]] * input.m_boneWeights[0];
-	Mat4 prevSkinMat = u_prevFrameBoneTransforms[input.m_boneIndices[0]] * input.m_boneWeights[0];
-	[[unroll]] for(U32 i = 1u; i < 4u; ++i)
-	{
-		skinMat += u_boneTransforms[input.m_boneIndices[i]] * input.m_boneWeights[i];
-		prevSkinMat += u_prevFrameBoneTransforms[input.m_boneIndices[i]] * input.m_boneWeights[i];
-	}
-
-#	if ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER
-	prevPos = mul(prevSkinMat, Vec4(pos, 1.0)).xyz;
-	tangent.xyz = mul(skinMat, Vec4(tangent.xyz, 0.0)).xyz;
-	normal = mul(skinMat, Vec4(normal, 0.0)).xyz;
-#	endif
-	ANKI_MAYBE_UNUSED(prevPos);
-	ANKI_MAYBE_UNUSED(tangent);
-	ANKI_MAYBE_UNUSED(normal);
-
-	pos = mul(skinMat, Vec4(pos, 1.0)).xyz;
-}
-#endif
-
-#if(ANKI_VELOCITY || ANKI_BONES) && ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER
-void velocity(RenderableGpuView view, Vec3 prevLocalPos, inout VertOut output)
-{
-#	if ANKI_VELOCITY
-	// Object is also moving
-	const Vec4 trf[3] = view.m_previousWorldTransform;
-#	else
-	// Object is a skin that is not moving
-	const Vec4 trf[3] = view.m_worldTransform;
-#	endif
-
-	Vec4 v4 = Vec4(transform(trf, Vec4(prevLocalPos, 1.0)), 1.0);
-	v4 = mul(u_globalUniforms.m_previousViewProjectionMatrix, v4);
-
-	output.m_prevClipXyw = v4.xyw;
-	output.m_crntClipXyw = output.m_position.xyw;
-}
-#endif
-
-VertOut main(VertIn input)
-{
-	const RenderableGpuView view = u_renderableGpuViews[input.m_instanceId];
-	VertOut output;
-
-	// All values in local space
-#if ANKI_BONES
-	Vec3 pos =
-		input.m_position * view.m_positionScaleF32AndTranslationVec3.x + view.m_positionScaleF32AndTranslationVec3.yzw;
-#else
-	Vec3 pos = input.m_position;
-#endif
-
-	Vec3 prevPos = pos;
-	ANKI_MAYBE_UNUSED(prevPos);
-
-#if ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER
-	RVec3 normal = input.m_normal;
-	RVec4 tangent = input.m_tangent;
-#else
-	RVec3 normal = RVec3(0.0, 0.0, 0.0);
-	RVec4 tangent = RVec4(0.0, 0.0, 0.0, 0.0);
-	ANKI_MAYBE_UNUSED(normal);
-	ANKI_MAYBE_UNUSED(tangent);
-#endif
-
-#if UVS
-	output.m_uv = input.m_uv;
-#endif
-
-	// Do stuff
-#if ANKI_BONES
-	skinning(input, pos, prevPos, normal, tangent);
-#endif
-
-	output.m_position = Vec4(transform(view.m_worldTransform, Vec4(pos, 1.0)), 1.0);
-	output.m_position = mul(u_globalUniforms.m_viewProjectionMatrix, output.m_position);
-
-#if ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER
-	output.m_normal = transform(view.m_worldTransform, Vec4(normal, 0.0));
-	output.m_tangent = transform(view.m_worldTransform, Vec4(tangent.xyz, 0.0));
-	output.m_bitangent = cross(output.m_normal, output.m_tangent) * tangent.w;
-#endif
-
-#if REALLY_VELOCITY
-	velocity(view, prevPos, output);
-#endif
-
-	return output;
-};
-
-#pragma anki end
-
-#pragma anki start frag
-
-void doAlphaTest(RF32 alpha)
-{
-	if(alpha == 0.0)
-	{
-		discard;
-	}
-}
-
-#if ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_SHADOWS
-void main(VertOut input)
-{
-	ANKI_MAYBE_UNUSED(input);
-#	if REALLY_ALPHA_TEST
-	const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(u_localUniforms, 0u);
-	const RVec4 diffColorA = u_bindlessTextures2dF32[localUniforms.m_diffTex].Sample(u_globalSampler, input.m_uv);
-	doAlphaTest(diffColorA.a);
-#	endif
-}
-#elif ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER_EZ
-FragOut main(VertOut input)
-{
-	ANKI_MAYBE_UNUSED(input);
-#	if REALLY_ALPHA_TEST
-	const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(u_localUniforms, 0u);
-	const RVec4 diffColorA = u_bindlessTextures2dF32[localUniforms.m_diffTex].Sample(u_globalSampler, input.m_uv);
-	doAlphaTest(diffColorA.a);
-#	endif
-	return (FragOut)0;
-}
-#elif ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER
-// Do normal mapping
-RVec3 readNormalFromTexture(VertOut input, Texture2D<RVec4> map, SamplerState sampl, Vec2 texCoords)
-{
-	// First read the texture
-	const RVec3 nAtTangentspace = normalize((map.Sample(sampl, texCoords).rgb - 0.5) * 2.0);
-
-	const RVec3 n = normalize(input.m_normal);
-	const RVec3 t = normalize(input.m_tangent);
-	const RVec3 b = normalize(input.m_bitangent);
-
-	RVec3 tbnMat[3u];
-	tbnMat[0] = RVec3(t.x, b.x, n.x);
-	tbnMat[1] = RVec3(t.y, b.y, n.y);
-	tbnMat[2] = RVec3(t.z, b.z, n.z);
-
-	return rotate(tbnMat, nAtTangentspace);
-}
-
-FragOut main(VertOut input)
-{
-	const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(u_localUniforms, 0u);
-
-#	if REALLY_USING_PARALLAX
-	// TODO
-	const Vec2 uv = input.m_uv;
-#	else
-	const Vec2 uv = input.m_uv;
-#	endif
-	ANKI_MAYBE_UNUSED(uv);
-
-#	if DIFFUSE_TEX
-#		if REALLY_ALPHA_TEST
-	const RVec4 diffColorA = u_bindlessTextures2dF32[localUniforms.m_diffTex].Sample(u_globalSampler, uv);
-	doAlphaTest(diffColorA.a);
-	const RVec3 diffColor = diffColorA.rgb;
-#		else
-	const RVec3 diffColor = u_bindlessTextures2dF32[localUniforms.m_diffTex].Sample(u_globalSampler, uv).rgb;
-#		endif
-#	else
-	const RVec3 diffColor = localUniforms.m_diffColor;
-#	endif
-
-#	if SPECULAR_TEX
-	const RVec3 specColor = u_bindlessTextures2dF32[localUniforms.m_specTex].Sample(u_globalSampler, uv).rgb;
-#	else
-	const RVec3 specColor = localUniforms.m_specColor;
-#	endif
-
-#	if ROUGHNESS_TEX
-	const RF32 roughness = u_bindlessTextures2dF32[localUniforms.m_roughnessTex].Sample(u_globalSampler, uv).g;
-#	else
-	const RF32 roughness = localUniforms.m_roughness;
-#	endif
-
-#	if METAL_TEX
-	const RF32 metallic = u_bindlessTextures2dF32[localUniforms.m_metallicTex].Sample(u_globalSampler, uv).b;
-#	else
-	const RF32 metallic = localUniforms.m_metallic;
-#	endif
-
-#	if NORMAL_TEX
-	const RVec3 normal =
-		readNormalFromTexture(input, u_bindlessTextures2dF32[localUniforms.m_normalTex], u_globalSampler, uv);
-#	else
-	const RVec3 normal = normalize(input.m_normal);
-#	endif
-
-#	if EMISSIVE_TEX
-	const RVec3 emission = u_bindlessTextures2dF32[localUniforms.m_emissiveTex].Sample(u_globalSampler, uv).rgb;
-#	else
-	const RVec3 emission = localUniforms.m_emission;
-#	endif
-
-#	if ANKI_VELOCITY || ANKI_BONES
-	const Vec2 prevNdc = input.m_prevClipXyw.xy / input.m_prevClipXyw.z;
-	const Vec2 crntNdc = input.m_crntClipXyw.xy / input.m_crntClipXyw.z;
-
-	// It's NDC_TO_UV(prevNdc) - NDC_TO_UV(crntNdc) or:
-	const Vec2 velocity = (prevNdc - crntNdc) * 0.5;
-#	else
-	const Vec2 velocity = Vec2(1.0, 1.0);
-#	endif
-
-	GbufferInfo g;
-	g.m_diffuse = diffColor;
-	g.m_normal = normal;
-	g.m_f0 = specColor;
-	g.m_roughness = roughness;
-	g.m_subsurface = localUniforms.m_subsurface;
-	g.m_emission = emission;
-	g.m_metallic = metallic;
-	g.m_velocity = velocity;
-
-	FragOut output;
-	packGBuffer(g, output.m_color0, output.m_color1, output.m_color2, output.m_color3);
-	return output;
-}
-#endif
-
-#pragma anki end

+ 2 - 0
AnKi/Shaders/Include/Common.h

@@ -101,6 +101,8 @@ void maybeUnused(T a)
 #	define ANKI_SPECIALIZATION_CONSTANT_VEC3(n, id) _ANKI_SCONST_X3(Vec3, F32, n, id)
 #	define ANKI_SPECIALIZATION_CONSTANT_VEC3(n, id) _ANKI_SCONST_X3(Vec3, F32, n, id)
 #	define ANKI_SPECIALIZATION_CONSTANT_VEC4(n, id) _ANKI_SCONST_X4(Vec4, F32, n, id)
 #	define ANKI_SPECIALIZATION_CONSTANT_VEC4(n, id) _ANKI_SCONST_X4(Vec4, F32, n, id)
 
 
+#	pragma pack_matrix(row_major)
+
 typedef float F32;
 typedef float F32;
 constexpr uint kSizeof_F32 = 4u;
 constexpr uint kSizeof_F32 = 4u;
 typedef float2 Vec2;
 typedef float2 Vec2;