diff --git a/resources/shaders/compiled/NormalsPixel.spv b/resources/shaders/compiled/NormalsPixel.spv index a89e73044..25c600b1f 100644 Binary files a/resources/shaders/compiled/NormalsPixel.spv and b/resources/shaders/compiled/NormalsPixel.spv differ diff --git a/resources/shaders/compiled/PPEndPixel.spv b/resources/shaders/compiled/PPEndPixel.spv index 6b749480f..855cd283b 100644 Binary files a/resources/shaders/compiled/PPEndPixel.spv and b/resources/shaders/compiled/PPEndPixel.spv differ diff --git a/resources/shaders/compiled/PPFxaaPixel.spv b/resources/shaders/compiled/PPFxaaPixel.spv index 9b223d760..3f8fb5ae4 100644 Binary files a/resources/shaders/compiled/PPFxaaPixel.spv and b/resources/shaders/compiled/PPFxaaPixel.spv differ diff --git a/resources/shaders/compiled/PPNoisePixel.spv b/resources/shaders/compiled/PPNoisePixel.spv index 98b69ed15..94ed2318c 100644 Binary files a/resources/shaders/compiled/PPNoisePixel.spv and b/resources/shaders/compiled/PPNoisePixel.spv differ diff --git a/resources/shaders/compiled/PPOutlinePixel.spv b/resources/shaders/compiled/PPOutlinePixel.spv index 27bae6550..8c9a310e5 100644 Binary files a/resources/shaders/compiled/PPOutlinePixel.spv and b/resources/shaders/compiled/PPOutlinePixel.spv differ diff --git a/resources/shaders/compiled/ParticlePixel.spv b/resources/shaders/compiled/ParticlePixel.spv index 3c55acbfa..3cff7ae54 100644 Binary files a/resources/shaders/compiled/ParticlePixel.spv and b/resources/shaders/compiled/ParticlePixel.spv differ diff --git a/resources/shaders/compiled/ParticleVertex.spv b/resources/shaders/compiled/ParticleVertex.spv index 3abcafc8f..5c9846c8e 100644 Binary files a/resources/shaders/compiled/ParticleVertex.spv and b/resources/shaders/compiled/ParticleVertex.spv differ diff --git a/resources/shaders/compiled/PointShadowMapPixel.spv b/resources/shaders/compiled/PointShadowMapPixel.spv index b0aefbb1f..03e0eb94d 100644 Binary files a/resources/shaders/compiled/PointShadowMapPixel.spv and b/resources/shaders/compiled/PointShadowMapPixel.spv differ diff --git a/resources/shaders/compiled/PointShadowMapSkinnedVertex.spv b/resources/shaders/compiled/PointShadowMapSkinnedVertex.spv index e1682ba20..09ef50286 100644 Binary files a/resources/shaders/compiled/PointShadowMapSkinnedVertex.spv and b/resources/shaders/compiled/PointShadowMapSkinnedVertex.spv differ diff --git a/resources/shaders/compiled/PointShadowMapVertex.spv b/resources/shaders/compiled/PointShadowMapVertex.spv index 66692d563..fd6d46354 100644 Binary files a/resources/shaders/compiled/PointShadowMapVertex.spv and b/resources/shaders/compiled/PointShadowMapVertex.spv differ diff --git a/resources/shaders/compiled/PostProcessVertex.spv b/resources/shaders/compiled/PostProcessVertex.spv index a07b8b31b..114965e5b 100644 Binary files a/resources/shaders/compiled/PostProcessVertex.spv and b/resources/shaders/compiled/PostProcessVertex.spv differ diff --git a/resources/shaders/compiled/SkyboxPixel.spv b/resources/shaders/compiled/SkyboxPixel.spv index 082239557..1a60234fe 100644 Binary files a/resources/shaders/compiled/SkyboxPixel.spv and b/resources/shaders/compiled/SkyboxPixel.spv differ diff --git a/resources/shaders/compiled/SkyboxVertex.spv b/resources/shaders/compiled/SkyboxVertex.spv index 40778369c..2f2893be8 100644 Binary files a/resources/shaders/compiled/SkyboxVertex.spv and b/resources/shaders/compiled/SkyboxVertex.spv differ diff --git a/resources/shaders/compiled/ToonPixel.spv b/resources/shaders/compiled/ToonPixel.spv index 15e35f4ad..feb4c85db 100644 Binary files a/resources/shaders/compiled/ToonPixel.spv and b/resources/shaders/compiled/ToonPixel.spv differ diff --git a/resources/shaders/compiled/ToonSkinnedVertex.spv b/resources/shaders/compiled/ToonSkinnedVertex.spv index ed6dbeee3..57e77e3c1 100644 Binary files a/resources/shaders/compiled/ToonSkinnedVertex.spv and b/resources/shaders/compiled/ToonSkinnedVertex.spv differ diff --git a/resources/shaders/compiled/ToonVertex.spv b/resources/shaders/compiled/ToonVertex.spv index e43db8592..e7983f3e2 100644 Binary files a/resources/shaders/compiled/ToonVertex.spv and b/resources/shaders/compiled/ToonVertex.spv differ diff --git a/resources/shaders/compiled/UniShadowMapSkinnedVertex.spv b/resources/shaders/compiled/UniShadowMapSkinnedVertex.spv index b9fc45d8a..838645406 100644 Binary files a/resources/shaders/compiled/UniShadowMapSkinnedVertex.spv and b/resources/shaders/compiled/UniShadowMapSkinnedVertex.spv differ diff --git a/resources/shaders/compiled/UniShadowMapVertex.spv b/resources/shaders/compiled/UniShadowMapVertex.spv index deb38758f..c188a0f19 100644 Binary files a/resources/shaders/compiled/UniShadowMapVertex.spv and b/resources/shaders/compiled/UniShadowMapVertex.spv differ diff --git a/resources/shaders/compiled/WireframePixel.spv b/resources/shaders/compiled/WireframePixel.spv index 171feaad8..56ecea557 100644 Binary files a/resources/shaders/compiled/WireframePixel.spv and b/resources/shaders/compiled/WireframePixel.spv differ diff --git a/resources/shaders/compiled/WireframeVertex.spv b/resources/shaders/compiled/WireframeVertex.spv index 8860f51a5..24b2fe764 100644 Binary files a/resources/shaders/compiled/WireframeVertex.spv and b/resources/shaders/compiled/WireframeVertex.spv differ diff --git a/resources/shaders/source/Normals.psh b/resources/shaders/source/Normals.psh index 1e7f2dd3a..c7f86a3e2 100644 --- a/resources/shaders/source/Normals.psh +++ b/resources/shaders/source/Normals.psh @@ -6,8 +6,8 @@ struct PSInput float4 Pos : SV_POSITION; float3 Normal : NORMAL; float2 UV : TEX_COORD; - uint MaterialIndex; - float4 WorldPos; + uint MaterialIndex : MAT_INDEX; + float4 WorldPos : WORLD_POS; }; struct PSOutput @@ -20,16 +20,14 @@ SamplerState Textures_sampler; // By convention, texture samplers must use the StructuredBuffer Materials : register(t1); -const float Epsilon = 1e-10; - -float3 RGBtoHSV(in float3 RGB) +float3 RGBtoHSV(in float3 RGB, float epsilon) { float4 P = (RGB.g < RGB.b) ? float4(RGB.bg, -1.0, 2.0/3.0) : float4(RGB.gb, 0.0, -1.0/3.0); float4 Q = (RGB.r < P.x) ? float4(P.xyw, RGB.r) : float4(RGB.r, P.yzx); float C = Q.x - min(Q.w, Q.y); - float H = abs((Q.w - Q.y) / (6.0 * C + Epsilon) + Q.z); + float H = abs((Q.w - Q.y) / (6.0 * C + epsilon) + Q.z); float3 HCV = float3(H, C, Q.x); - float S = HCV.y / (HCV.z + Epsilon); + float S = HCV.y / (HCV.z + epsilon); return float3(HCV.x, S, HCV.z); } @@ -45,14 +43,16 @@ float3 HSVtoRGB(in float3 HSV) void main(in PSInput PSIn, out PSOutput PSOut) { + const float Epsilon = 1e-10; + float4 Color; - float3 viewDir = normalize(cameraPosition - PSIn.WorldPos); + float3 viewDir = normalize(cameraPosition - PSIn.WorldPos.xyz); if (Materials[PSIn.MaterialIndex].useTextureNormals) { uint normalIndex = Materials[PSIn.MaterialIndex].normalTexIndex; - float3 textureNormals = normalize(Textures[normalIndex].Sample(Textures_sampler, PSIn.UV)); - Color = float4(normalize(textureNormals.xyz * float3(2.0) - float3(1.0)), 1.0f); + float3 textureNormals = normalize(Textures[normalIndex].Sample(Textures_sampler, PSIn.UV)).xyz; + Color = float4(normalize(textureNormals.xyz * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0)), 1.0f); } else { @@ -60,7 +60,7 @@ void main(in PSInput PSIn, out PSOutput PSOut) Color = float4(vertexNormals, 1.0f); } - float3 colHsv = RGBtoHSV(float3(Color.r, Color.g, Color.b)); + float3 colHsv = RGBtoHSV(float3(Color.r, Color.g, Color.b), Epsilon); colHsv.y *= Materials[PSIn.MaterialIndex].normalIntensity; Color.rgb = HSVtoRGB(colHsv.rgb); diff --git a/resources/shaders/source/PPFxaa.psh b/resources/shaders/source/PPFxaa.psh index 12ea72936..c01608866 100644 --- a/resources/shaders/source/PPFxaa.psh +++ b/resources/shaders/source/PPFxaa.psh @@ -39,9 +39,9 @@ void main(in PSInput PSIn, out PSOutput PSOut) colorTex.GetDimensions(screenWidth, screenHeight); float2 texelSize = float2(1.0 / screenWidth, 1.0 / screenHeight); - /*********************** - / Get edge luminance - /***********************/ + // + // Get edge luminance + // // Get luminance for four texels in a cross shape surrounding the current texel float curLuma = RgbToLuma(colorTex.Sample(smplr, PSIn.UV).rgb); float downLuma = RgbToLuma(colorTex.Sample(smplr, PSIn.UV + (float2( 0, -1) * texelSize)).rgb); @@ -75,9 +75,9 @@ void main(in PSInput PSIn, out PSOutput PSOut) float rightCornerLuma = LRLuma + URLuma; float upCornerLuma = URLuma + ULLuma; - /********************** - / Get edge orientation - /**********************/ + // + // Get edge orientation + // // Get an estimated gradient along the horizontal and vertical axes. float edgeHoriz = abs(-2.0 * leftLuma + leftCornerLuma) + abs(-2.0 * curLuma + downUpLuma) * 2.0 + abs(-2.0 * rightLuma + rightCornerLuma); float edgeVert = abs(-2.0 * upLuma + upCornerLuma) + abs(-2.0 * curLuma + leftRightLuma) * 2.0 + abs(-2.0 * downLuma + downCornerLuma); @@ -95,9 +95,9 @@ void main(in PSInput PSIn, out PSOutput PSOut) bool isGradient1Steepest = abs(gradient1) >= abs(gradient2); float scaledGradient = 0.25 * max(abs(gradient1), abs(gradient2)); - /****************************** - / Average luma values at edge - /******************************/ + // + // Average luma values at edge + // float stepLength = isHorizontalEdge ? texelSize.y : texelSize.x; float localAvgLuma = 0.0; @@ -123,9 +123,9 @@ void main(in PSInput PSIn, out PSOutput PSOut) currentUV.x += stepLength * 0.5; } - /************************ - / Explore bounds of edge - /************************/ + // + // Explore bounds of edge + // float2 offset = isHorizontalEdge ? float2(texelSize.x, 0.0) : float2(0.0, texelSize.y); float2 newUV1 = currentUV - offset; float2 newUV2 = currentUV + offset; @@ -187,9 +187,9 @@ void main(in PSInput PSIn, out PSOutput PSOut) } } - /***************** - / Estimate offset - /*****************/ + // + // Estimate offset + // float distance1 = isHorizontalEdge ? (PSIn.UV.x - newUV1.x) : (PSIn.UV.y - newUV1.y); float distance2 = isHorizontalEdge ? (newUV2.x - PSIn.UV.x) : (newUV2.y - PSIn.UV.y); @@ -206,9 +206,9 @@ void main(in PSInput PSIn, out PSOutput PSOut) bool correctVariation = ((isDirection1 ? endLuma1 : endLuma2) < 0.0) != isCurLumaSmaller; float finalOffset = correctVariation ? pixelOffset : 0.0; - /*********************** - / Subpixel antialiasing - /***********************/ + // + // Subpixel antialiasing + // // Get full weighted luminance average over 3x3 neighborhood float iterationsF = float(Iterations); float averageLuma = (1.0 / iterationsF) * (2.0 * (downUpLuma + leftRightLuma) + leftCornerLuma + rightCornerLuma); diff --git a/resources/shaders/source/PPNoise.psh b/resources/shaders/source/PPNoise.psh index 7a999f3c5..466de9dd6 100644 --- a/resources/shaders/source/PPNoise.psh +++ b/resources/shaders/source/PPNoise.psh @@ -37,15 +37,15 @@ void main(in PSInput PSIn, out PSOutput PSOut) SamplerState smplr = ColorSinks_sampler; Texture2D sceneColorTex = PostProcessSinks[0]; Texture2D noiseTex = Textures[noiseTexIndex]; - float3 sceneColor = sceneColorTex.Sample(smplr, PSIn.UV); - float3 noiseColor = noiseTex.Sample(smplr, PSIn.UV * noiseTexTiling); + float3 sceneColor = sceneColorTex.Sample(smplr, PSIn.UV).xyz; + float3 noiseColor = noiseTex.Sample(smplr, PSIn.UV * noiseTexTiling).xyz; // Gradient for mask float3 gradient = lerp(gradientStart, gradientEnd, PSIn.UV.y); float4 gradientApplied = float4(lerp(sceneColor, sceneColor + gradient, gradientAmount), 1.0f); // Noise - float3 luma = RgbToLuma(gradientApplied); + float3 luma = RgbToLuma(gradientApplied.xyz); float3 noiseApplied = lerp(sceneColor, sceneColor + noiseColor, (1-luma.r) * noiseTexAmount); PSOut.Color = float4(noiseApplied, 1.0f); diff --git a/resources/shaders/source/PPOutline.psh b/resources/shaders/source/PPOutline.psh index 37826a712..cc7a797b9 100644 --- a/resources/shaders/source/PPOutline.psh +++ b/resources/shaders/source/PPOutline.psh @@ -32,7 +32,7 @@ float SampleNormalizeDepth(Texture2D tex, SamplerState smplr, float2 uv) { float rawDepth = tex.Sample(smplr, uv).r; float3 ndc = float3(uv * 2.0 - 1.0, rawDepth); - float4 view = cameraInvProjection * float4(ndc, 1.0); + float4 view = mul(float4(ndc, 1.0), cameraInvProjection); view.xyz /= view.w; float linearDepth = -view.z; return (linearDepth - nearClip) / (farClip - nearClip); @@ -64,10 +64,10 @@ float OutlineDepth(Texture2D depthTex, float viewDirDepthOffset, SamplerState sm float OutlineNormals(Texture2D normalsTex, float intensity, SamplerState smplr, float2 LLUV, float2 URUV, float2 LRUV, float2 ULUV) { // Sample normals texture at four corners - float3 normalsLL = normalsTex.Sample(smplr, LLUV); - float3 normalsUR = normalsTex.Sample(smplr, URUV); - float3 normalsLR = normalsTex.Sample(smplr, LRUV); - float3 normalsUL = normalsTex.Sample(smplr, ULUV); + float3 normalsLL = normalsTex.Sample(smplr, LLUV).xyz; + float3 normalsUR = normalsTex.Sample(smplr, URUV).xyz; + float3 normalsLR = normalsTex.Sample(smplr, LRUV).xyz; + float3 normalsUL = normalsTex.Sample(smplr, ULUV).xyz; // Get the difference between the diagonals float3 normalsDiagDif0 = (normalsUR - normalsLL) * intensity; diff --git a/resources/shaders/source/Particle.psh b/resources/shaders/source/Particle.psh index e533eddd9..ead87ab3b 100644 --- a/resources/shaders/source/Particle.psh +++ b/resources/shaders/source/Particle.psh @@ -1,9 +1,9 @@ struct PSInput { - float4 Pos : SV_POSITION; - float2 UV : TEX_COORD; - float4 Color; - uint TextureIndex; + float4 Pos : SV_POSITION; + float2 UV : TEX_COORD; + float4 Color : COLOR; + uint TextureIndex : TEX_INDEX; }; struct PSOutput diff --git a/resources/shaders/source/Particle.vsh b/resources/shaders/source/Particle.vsh index 8c5b1e977..bafde72fe 100644 --- a/resources/shaders/source/Particle.vsh +++ b/resources/shaders/source/Particle.vsh @@ -2,16 +2,16 @@ struct VSInput { - float3 Pos : ATTRIB0; - float2 UV : ATTRIB1; + float3 Pos : POSITION; + float2 UV : TEXCOORD0; }; struct PSOutput { float4 Pos : SV_POSITION; float2 UV : TEX_COORD; - float4 Color; - uint TextureIndex; + float4 Color : COLOR; + uint TextureIndex : TEX_INDEX; }; StructuredBuffer Particles; diff --git a/resources/shaders/source/PointShadowMap.psh b/resources/shaders/source/PointShadowMap.psh index b7c346336..26d42f3d9 100644 --- a/resources/shaders/source/PointShadowMap.psh +++ b/resources/shaders/source/PointShadowMap.psh @@ -4,8 +4,8 @@ struct PSInput { - float4 Pos : SV_POSITION; - float4 WorldPos; + float4 Pos : SV_POSITION; + float4 WorldPos : WORLD_POS; }; struct PSOutput diff --git a/resources/shaders/source/PointShadowMap.vsh b/resources/shaders/source/PointShadowMap.vsh index aa2025bf6..e1e4d3565 100644 --- a/resources/shaders/source/PointShadowMap.vsh +++ b/resources/shaders/source/PointShadowMap.vsh @@ -4,13 +4,13 @@ struct VSInput { - float3 Pos : ATTRIB0; + float3 Pos : ATTRIB0; }; struct PSInput { - float4 Pos : SV_POSITION; - float4 WorldPos; + float4 Pos : SV_POSITION; + float4 WorldPos : WORLD_POS; }; StructuredBuffer Transforms; diff --git a/resources/shaders/source/PointShadowMapSkinned.vsh b/resources/shaders/source/PointShadowMapSkinned.vsh index 3863c6950..4f93475c7 100644 --- a/resources/shaders/source/PointShadowMapSkinned.vsh +++ b/resources/shaders/source/PointShadowMapSkinned.vsh @@ -11,8 +11,8 @@ struct VSInput struct PSInput { - float4 Pos : SV_POSITION; - float4 WorldPos; + float4 Pos : SV_POSITION; + float4 WorldPos : WORLD_POS; }; StructuredBuffer Transforms; diff --git a/resources/shaders/source/Skybox.psh b/resources/shaders/source/Skybox.psh index 05f5922c4..5fbe18e13 100644 --- a/resources/shaders/source/Skybox.psh +++ b/resources/shaders/source/Skybox.psh @@ -5,8 +5,8 @@ SamplerState Textures_sampler; // By convention, texture samplers must use the struct PSInput { - float4 Pos : SV_POSITION; - float3 UVW; + float4 Pos : SV_POSITION; + float3 UVW : U_V_W; }; struct PSOutput diff --git a/resources/shaders/source/Skybox.vsh b/resources/shaders/source/Skybox.vsh index 3186e8d56..0de3164a6 100644 --- a/resources/shaders/source/Skybox.vsh +++ b/resources/shaders/source/Skybox.vsh @@ -7,8 +7,8 @@ struct VSInput struct PSInput { - float4 Pos : SV_POSITION; - float3 UVW; + float4 Pos : SV_POSITION; + float3 UVW : U_V_W; }; static float4x4 localModelMatrix = float4x4( diff --git a/resources/shaders/source/Toon.psh b/resources/shaders/source/Toon.psh index 2cce2865c..b00d922bf 100644 --- a/resources/shaders/source/Toon.psh +++ b/resources/shaders/source/Toon.psh @@ -6,10 +6,10 @@ struct PSInput float4 Pos : SV_POSITION; float3 Normal : NORMAL; float2 UV : TEX_COORD; - uint MaterialIndex; - float4 WorldPos; - float3 LocalPos; - float3 ViewDir; + uint MaterialIndex : MAT_INDEX; + float4 WorldPos : WORLD_POS; + float3 LocalPos : LOCAL_POS; + float3 ViewDir : VIEW_DIR; }; struct PSOutput @@ -22,8 +22,6 @@ SamplerState Textures_sampler; // By convention, texture samplers must use the StructuredBuffer Materials : register(t1); -const float Epsilon = 1e-10; - float Band(float lightAmount) { if (lightAmount * 100 < 0.05f) @@ -39,8 +37,8 @@ void main(in PSInput PSIn, out PSOutput PSOut) MaterialData material = Materials[PSIn.MaterialIndex]; // Get texture colors - uint TexIndex = material.diffuseTexIndex; - uint NormalIndex = material.normalTexIndex; + uint TexIndex = NonUniformResourceIndex(material.diffuseTexIndex); + uint NormalIndex = NonUniformResourceIndex(material.normalTexIndex); float4 Diffuse = Textures[TexIndex].Sample(Textures_sampler, PSIn.UV); float4 Normals = Textures[NormalIndex].Sample(Textures_sampler, PSIn.UV); @@ -83,7 +81,7 @@ void main(in PSInput PSIn, out PSOutput PSOut) float3 normals = PSIn.Normal; if (material.useTextureNormals) { - normals = normalize(Normals.xyz * float3(2.0) - float3(1.0)); + normals = normalize(Normals.xyz * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0)); } float3 result = 0.0f; @@ -112,19 +110,21 @@ void main(in PSInput PSIn, out PSOutput PSOut) // Calculate shadow factor float shadowFactor = 1.0f; + TextureCube pointDepthTex; + Texture2D uniDepthTex; if (Lights[i].castsShadows) { if (Lights[i].type == 1) { - TextureCube depthTex = PointShadowMapSinks[pointShadowMapIndex]; - float rawShadow = PointShadowCalculation(PSIn.WorldPos, Lights[i].position, depthTex, PSIn.Normal); + pointDepthTex = PointShadowMapSinks[pointShadowMapIndex]; + float rawShadow = PointShadowCalculation(PSIn.WorldPos, Lights[i].position, pointDepthTex, PSIn.Normal); shadowFactor += (rawShadow); pointShadowMapIndex++; } else { - Texture2D depthTex = UniShadowMapSinks[uniShadowMapIndex]; - float rawShadow = UniShadowCalculation(Lights[i].type == 0, mul(mul(PSIn.WorldPos, LightMatrices[Lights[i].lightMatrixIndex].viewProjection), biasMat), depthTex); + uniDepthTex = UniShadowMapSinks[uniShadowMapIndex]; + float rawShadow = UniShadowCalculation(Lights[i].type == 0, mul(mul(PSIn.WorldPos, LightMatrices[Lights[i].lightMatrixIndex].viewProjection), biasMat), uniDepthTex); shadowFactor += (rawShadow); uniShadowMapIndex++; } @@ -132,7 +132,7 @@ void main(in PSInput PSIn, out PSOutput PSOut) shadowFactor = min((1-shadowFactor) + 1.0f, 1.0f); diffuseAmt = max(diffuseAmt * shadowFactor, 0.0f); - specularAmt = max(diffuseAmt * shadowFactor, 0.0f); + specularAmt = max(specularAmt * shadowFactor, 0.0f); // Apply lighting influences and shadows result += ((diffuseAmt * influence.diffuseColor * color.rgb) + (specularAmt * influence.specularColor * color.rgb )); @@ -142,7 +142,7 @@ void main(in PSInput PSIn, out PSOutput PSOut) if (material.useHatchTexture) { // Get hatching texture and tiling property - uint hatchTexIndex = material.hatchTexIndex; + uint hatchTexIndex = NonUniformResourceIndex(material.hatchTexIndex); float hatchTiling = material.hatchTiling; float hatchLight = Textures[hatchTexIndex].Sample(Textures_sampler, PSIn.UV * hatchTiling).r; float hatchMedium = Textures[hatchTexIndex].Sample(Textures_sampler, PSIn.UV * hatchTiling).g; diff --git a/resources/shaders/source/Toon.vsh b/resources/shaders/source/Toon.vsh index 2994efdec..a3c476f04 100644 --- a/resources/shaders/source/Toon.vsh +++ b/resources/shaders/source/Toon.vsh @@ -13,9 +13,9 @@ struct PSInput float4 Pos : SV_POSITION; float3 Normal : NORMAL; float2 UV : TEX_COORD; - uint MaterialIndex; - float4 WorldPos; - float3 LocalPos; + uint MaterialIndex : MAT_INDEX; + float4 WorldPos : WORLD_POS; + float3 LocalPos : LOCAL_POS; }; StructuredBuffer Transforms; @@ -28,7 +28,7 @@ void main(in VSInput VSIn, uint InstanceID : SV_InstanceID, out PSInput PSIn) float4 TransformedPos = mul(float4(VSIn.Pos, 1.0), Transforms[transformIndex].model); PSIn.Pos = mul(TransformedPos, cameraViewProjection); PSIn.UV = VSIn.UV; - PSIn.Normal = normalize( mul(float4(VSIn.Normal, 0.0), Transforms[transformIndex].model)); + PSIn.Normal = normalize( mul(float4(VSIn.Normal, 0.0), Transforms[transformIndex].model)).xyz; PSIn.WorldPos = TransformedPos; PSIn.LocalPos = VSIn.Pos.xyz; PSIn.MaterialIndex = materialIndex; diff --git a/resources/shaders/source/ToonSkinned.vsh b/resources/shaders/source/ToonSkinned.vsh index 4d59b3cfe..5dd9ad57e 100644 --- a/resources/shaders/source/ToonSkinned.vsh +++ b/resources/shaders/source/ToonSkinned.vsh @@ -14,9 +14,9 @@ struct PSInput float4 Pos : SV_POSITION; float3 Normal : NORMAL; float2 UV : TEX_COORD; - uint MaterialIndex; - float4 WorldPos; - float3 LocalPos; + uint MaterialIndex : MAT_INDEX; + float4 WorldPos : WORLD_POS; + float3 LocalPos : LOCAL_POS; }; StructuredBuffer Transforms; @@ -61,7 +61,7 @@ void main(in VSInput VSIn, uint InstanceID : SV_InstanceID, out PSInput PSIn) float4 worldPos = mul(pos, Transforms[transformIndex].model); PSIn.Pos = mul(worldPos, cameraViewProjection); PSIn.UV = VSIn.UV; - PSIn.Normal = normalize(mul(normal, Transforms[transformIndex].model)); + PSIn.Normal = normalize(mul(normal, Transforms[transformIndex].model)).xyz; PSIn.LocalPos = VSIn.Pos.xyz; PSIn.WorldPos = worldPos; PSIn.MaterialIndex = instance.materialIndex; diff --git a/resources/shaders/source/UniShadowMapSkinned.vsh b/resources/shaders/source/UniShadowMapSkinned.vsh index 8d390ad83..6980e1b90 100644 --- a/resources/shaders/source/UniShadowMapSkinned.vsh +++ b/resources/shaders/source/UniShadowMapSkinned.vsh @@ -14,9 +14,9 @@ struct PSInput float4 Pos : SV_POSITION; float3 Normal : NORMAL; float2 UV : TEX_COORD; - uint MaterialIndex; - float3 WorldPos; - float3 LocalPos; + uint MaterialIndex : MAT_INDEX; + float3 WorldPos : WORLD_POS; + float3 LocalPos : LOCAL_POS; }; StructuredBuffer Transforms; diff --git a/resources/shaders/source/core/Animation.fxh b/resources/shaders/source/core/Animation.fxh index bc34390c3..acd0c0623 100644 --- a/resources/shaders/source/core/Animation.fxh +++ b/resources/shaders/source/core/Animation.fxh @@ -6,15 +6,19 @@ bool IsValidBoneIndex(uint boneIndex) bool IsValidAnimationTransform(float4x4 mat) { // Check for zero matrix, ignoring homogenous coord - return all(mat[0] != 0.0) || - all(mat[1] != 0.0) || - all(mat[2] != 0.0) || - mat[3].xyz != float3(0.0, 0.0, 0.0); + return + any(mat[0]) || + any(mat[1]) || + any(mat[2]) || + any(mat[3].xyz); } float4x4 CombineBoneMatrices(uint base, uint4 boneOffsets, float4 boneWeights) { - float4x4 boneTransform = float4x4(0.0); + float4x4 boneTransform = float4x4(0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0); for (int i = 0; i < 4; i++) { if (boneWeights[i] > 0.0f) diff --git a/script/shaders.ps1 b/script/shaders.ps1 index a2024689a..c6fd3df95 100644 --- a/script/shaders.ps1 +++ b/script/shaders.ps1 @@ -13,15 +13,11 @@ param [bool]$DebugMode = $false ) -$Compiler = $Env:VULKAN_SDK + "\Bin\glslangValidator.exe" +$Compiler = $Env:VULKAN_SDK + "\Bin\dxc.exe" $Optimizer = $Env:VULKAN_SDK + "\Bin\spirv-opt.exe" -$Preamble = "#pragma pack_matrix(row_major)" if ($DebugMode) { - $CompilerOutputDir = Join-Path $OutputDir "debug" - if (-not (Test-Path -Path $OutputDir)) { - New-Item -Path $OutputDir -ItemType Directory | Out-Null - } + $CompilerOutputDir = $OutputDir } else { $CompilerOutputDir = Join-Path $OutputDir "temp" @@ -37,10 +33,10 @@ Write-Host "--Compiling Shaders--" Get-ChildItem -Path $InputDir | Where-Object { $_.Extension -eq '.psh' -or $_.Extension -eq '.vsh' } | ForEach-Object { if ($_.Extension -eq '.psh') { - $Stage = 'frag' + $Profile = 'ps_6_6' $FileName = "$($_.BaseName)Pixel.spv" } elseif ($_.Extension -eq '.vsh') { - $Stage = 'vert' + $Profile = 'vs_6_6' $FileName = "$($_.BaseName)Vertex.spv" } else { return @@ -50,18 +46,20 @@ ForEach-Object { $InputFile = Join-Path $InputDir $_.Name $OutputFile = Join-Path $CompilerOutputDir $FileName $Args = @( - '-V', # create SPIRV binary w/ Vulkan semantics - '-D', # input is HLSL - "-P$Preamble", # prepended our definitions to each source file - '-e', 'main', # entry point - '-fhlsl_functionality1', # enable functionality1 extension - "-S", $Stage, # explicitly specify shader stage - "-o", $OutputFile, + '-spirv', # generate SPIR-V for Vulkan + '-fspv-target-env=vulkan1.2', # target Vulkan 1.2 + '-fspv-extension=SPV_GOOGLE_hlsl_functionality1', # SPIR-V HLSL semantics + '-fspv-extension=SPV_KHR_non_semantic_info', # SPIR-V HLSL semantics + '-fspv-extension=SPV_EXT_descriptor_indexing', # Allow for descriptor indexing + '-Zpr', # pack matrices in row-major order + '-E', 'main', # entry point + '-T', $Profile, # shader profile (vs_6_0, ps_6_0) + '-Fo', $OutputFile, # output file $InputFile ) if ($DebugMode) { - $Args = @('-g') + $Args + $Args = @('-Zi', '-fspv-debug=line') + $Args } & $Compiler @Args diff --git a/source/ncengine/graphics2/diligent/DiligentEngine.cpp b/source/ncengine/graphics2/diligent/DiligentEngine.cpp index 08cce5d03..5137dc181 100644 --- a/source/ncengine/graphics2/diligent/DiligentEngine.cpp +++ b/source/ncengine/graphics2/diligent/DiligentEngine.cpp @@ -70,6 +70,7 @@ DiligentEngine::DiligentEngine(const Diligent::EngineCreateInfo& engineCreateInf } auto engineCI = EngineVkCreateInfo{engineCreateInfo}; + engineCI.Features.ShaderResourceRuntimeArrays = DEVICE_FEATURE_STATE_ENABLED; pFactoryVk->CreateDeviceAndContextsVk(engineCI, &m_pDevice, &m_pImmediateContext); if (!m_pDevice || !m_pImmediateContext) {