From 3690b082bc057d237a73d81fffcd3484b5804740 Mon Sep 17 00:00:00 2001 From: horstche Date: Wed, 20 Feb 2019 10:41:00 +0100 Subject: [PATCH] Added vertex shader PNCTT and started implementation of DiffuseSampler2. (#43) Added vertex shader PNCTT and implementation of DiffuseSampler2. --- Rendering/Shaders/BasicShader.cs | 35 ++++++++++++++++---- Shaders/BasicPS.hlsl | 11 +++++++ Shaders/BasicVS_PNCTT.hlsl | 40 +++++++++++++++++++++++ Shaders/CodeWalkerShaders.vcxproj | 10 ++++++ Shaders/CodeWalkerShaders.vcxproj.filters | 1 + 5 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 Shaders/BasicVS_PNCTT.hlsl diff --git a/Rendering/Shaders/BasicShader.cs b/Rendering/Shaders/BasicShader.cs index 216ba6c..b0e51ec 100644 --- a/Rendering/Shaders/BasicShader.cs +++ b/Rendering/Shaders/BasicShader.cs @@ -55,6 +55,10 @@ namespace CodeWalker.Rendering public struct BasicShaderPSGeomVars { public uint EnableTexture; + public uint EnableTexture2; + public uint pad1; + public uint pad2; + public uint pad3; public uint EnableTint; public uint EnableNormalMap; public uint EnableSpecMap; @@ -119,6 +123,7 @@ namespace CodeWalker.Rendering bool disposed = false; VertexShader basicvspnct; + VertexShader basicvspnctt; VertexShader basicvspncct; VertexShader basicvspncctt; VertexShader basicvspnccttt; @@ -168,6 +173,7 @@ namespace CodeWalker.Rendering public BasicShader(Device device) { byte[] vspnctbytes = File.ReadAllBytes("Shaders\\BasicVS_PNCT.cso"); + byte[] vspncttbytes = File.ReadAllBytes("Shaders\\BasicVS_PNCTT.cso"); byte[] vspncctbytes = File.ReadAllBytes("Shaders\\BasicVS_PNCCT.cso"); byte[] vspnccttbytes = File.ReadAllBytes("Shaders\\BasicVS_PNCCTT.cso"); byte[] vspncctttbytes = File.ReadAllBytes("Shaders\\BasicVS_PNCCTTT.cso"); @@ -184,6 +190,7 @@ namespace CodeWalker.Rendering byte[] psbytes = File.ReadAllBytes("Shaders\\BasicPS.cso"); basicvspnct = new VertexShader(device, vspnctbytes); + basicvspnctt = new VertexShader(device, vspncttbytes); basicvspncct = new VertexShader(device, vspncctbytes); basicvspncctt = new VertexShader(device, vspnccttbytes); basicvspnccttt = new VertexShader(device, vspncctttbytes); @@ -214,11 +221,12 @@ namespace CodeWalker.Rendering //supported layouts - requires Position, Normal, Colour, Texcoord layouts.Add(VertexType.Default, new InputLayout(device, vspnctbytes, VertexTypeDefault.GetLayout())); layouts.Add(VertexType.PNCH2, new InputLayout(device, vspnctbytes, VertexTypePNCH2.GetLayout())); - layouts.Add(VertexType.PNCTT, new InputLayout(device, vspnctbytes, VertexTypePNCTT.GetLayout())); - layouts.Add(VertexType.PNCTTT, new InputLayout(device, vspnctbytes, VertexTypePNCTTT.GetLayout())); layouts.Add(VertexType.PBBNCT, new InputLayout(device, vspnctbytes, VertexTypePBBNCT.GetLayout())); - layouts.Add(VertexType.PBBNCTT, new InputLayout(device, vspnctbytes, VertexTypePBBNCTT.GetLayout())); - layouts.Add(VertexType.PBBNCTTT, new InputLayout(device, vspnctbytes, VertexTypePBBNCTTT.GetLayout())); + + layouts.Add(VertexType.PNCTT, new InputLayout(device, vspncttbytes, VertexTypePNCTT.GetLayout())); + layouts.Add(VertexType.PNCTTT, new InputLayout(device, vspncttbytes, VertexTypePNCTTT.GetLayout())); + layouts.Add(VertexType.PBBNCTT, new InputLayout(device, vspncttbytes, VertexTypePBBNCTT.GetLayout())); + layouts.Add(VertexType.PBBNCTTT, new InputLayout(device, vspncttbytes, VertexTypePBBNCTTT.GetLayout())); layouts.Add(VertexType.PNCCT, new InputLayout(device, vspncctbytes, VertexTypePNCCT.GetLayout())); layouts.Add(VertexType.PBBNCCT, new InputLayout(device, vspncctbytes, VertexTypePBBNCCT.GetLayout())); @@ -360,12 +368,14 @@ namespace CodeWalker.Rendering { case VertexType.Default: case VertexType.PNCH2: + case VertexType.PBBNCT: + vs = basicvspnct; + break; case VertexType.PNCTT: case VertexType.PNCTTT: - case VertexType.PBBNCT: case VertexType.PBBNCTT: case VertexType.PBBNCTTT: - vs = basicvspnct; + vs = basicvspnctt; break; case VertexType.PNCCT: case VertexType.PBBNCCT: @@ -515,6 +525,7 @@ namespace CodeWalker.Rendering public override void SetGeomVars(DeviceContext context, RenderableGeometry geom) { RenderableTexture texture = null; + RenderableTexture texture2 = null; RenderableTexture tintpal = null; RenderableTexture bumptex = null; RenderableTexture spectex = null; @@ -568,11 +579,13 @@ namespace CodeWalker.Rendering texture = itex; isdistmap = true; break; + case MetaName.DiffuseSampler2: + texture2 = itex; + break; case MetaName.heightSampler: case MetaName.EnvironmentSampler: //case MetaName.SnowSampler0: //case MetaName.SnowSampler1: - //case MetaName.DiffuseSampler2: //case MetaName.DiffuseSampler3: //case MetaName.DirtSampler: //case MetaName.DirtBumpSampler: @@ -605,6 +618,7 @@ namespace CodeWalker.Rendering bool usediff = ((texture != null) && (texture.ShaderResourceView != null)); + bool usediff2 = ((texture2 != null) && (texture2.ShaderResourceView != null)); bool usebump = ((bumptex != null) && (bumptex.ShaderResourceView != null)); bool usespec = ((spectex != null) && (spectex.ShaderResourceView != null)); bool usedetl = ((detltex != null) && (detltex.ShaderResourceView != null)); @@ -658,6 +672,7 @@ namespace CodeWalker.Rendering PSGeomVars.Vars.EnableTexture = usediff ? 1u : 0u; + PSGeomVars.Vars.EnableTexture2 = usediff2 ? 1u : 0u; PSGeomVars.Vars.EnableTint = pstintflag; PSGeomVars.Vars.EnableNormalMap = usebump ? 1u : 0u; PSGeomVars.Vars.EnableSpecMap = usespec ? 1u : 0u; @@ -706,6 +721,10 @@ namespace CodeWalker.Rendering { detltex.SetPSResource(context, 4); } + if (usediff2) + { + texture2.SetPSResource(context, 5); + } if (usetint) { tintpal.SetVSResource(context, 0); @@ -864,6 +883,7 @@ namespace CodeWalker.Rendering context.PixelShader.SetShaderResource(2, null); context.PixelShader.SetShaderResource(3, null); context.PixelShader.SetShaderResource(4, null); + context.PixelShader.SetShaderResource(5, null); context.VertexShader.SetShaderResource(0, null); context.VertexShader.SetShaderResource(1, null); context.VertexShader.SetShaderResource(2, null); @@ -902,6 +922,7 @@ namespace CodeWalker.Rendering basicps.Dispose(); basicvspnct.Dispose(); + basicvspnctt.Dispose(); basicvspncct.Dispose(); basicvspncctt.Dispose(); basicvspnccttt.Dispose(); diff --git a/Shaders/BasicPS.hlsl b/Shaders/BasicPS.hlsl index ca600f4..9e452cc 100644 --- a/Shaders/BasicPS.hlsl +++ b/Shaders/BasicPS.hlsl @@ -4,6 +4,7 @@ Texture2D Colourmap : register(t0); Texture2D Bumpmap : register(t2); Texture2D Specmap : register(t3); Texture2D Detailmap : register(t4); +Texture2D Colourmap2 : register(t5); SamplerState TextureSS : register(s0); @@ -18,6 +19,10 @@ cbuffer PSSceneVars : register(b0) cbuffer PSGeomVars : register(b2) { uint EnableTexture; + uint EnableTexture2; + uint pad1; + uint pad2; + uint pad3; uint EnableTint; uint EnableNormalMap; uint EnableSpecMap; @@ -74,6 +79,12 @@ float4 main(VS_OUTPUT input) : SV_TARGET c = Colourmap.Sample(TextureSS, texc); + if (EnableTexture2 == 1) + { + float4 c2 = Colourmap2.Sample(TextureSS, input.Texcoord1); + c = c2.a * c2 + (1 - c2.a) * c; + } + if (IsDistMap) c = float4(c.rgb*2, (c.r+c.g+c.b) - 1); if ((IsDecal == 0) && (c.a <= 0.33)) discard; if ((IsDecal == 1) && (c.a <= 0.0)) discard; diff --git a/Shaders/BasicVS_PNCTT.hlsl b/Shaders/BasicVS_PNCTT.hlsl new file mode 100644 index 0000000..a96a23b --- /dev/null +++ b/Shaders/BasicVS_PNCTT.hlsl @@ -0,0 +1,40 @@ +#include "BasicVS.hlsli" + +struct VS_INPUT +{ + float4 Position : POSITION; + float3 Normal : NORMAL; + float2 Texcoord0 : TEXCOORD0; + float2 Texcoord1 : TEXCOORD1; + float4 Colour0 : COLOR0; +}; + + +VS_OUTPUT main(VS_INPUT input, uint iid : SV_InstanceID) +{ + VS_OUTPUT output; + float3 opos = ModelTransform(input.Position.xyz, input.Colour0.xyz, input.Colour0.xyz, iid); + float4 cpos = ScreenTransform(opos); + float3 bnorm = NormalTransform(input.Normal); + float3 btang = 0.5;// NormalTransform(float3(1, 0, 0)); //no tangent to use on this vertex type... + + float4 tnt = ColourTint(input.Colour0.b, 0, iid); //colour tinting if enabled + + float4 lightspacepos; + float shadowdepth = ShadowmapSceneDepth(opos, lightspacepos); + output.LightShadow = lightspacepos; + output.Shadows = float4(shadowdepth, 0, 0, 0); + + output.Position = cpos; + output.CamRelPos = opos; + output.Normal = bnorm; + output.Texcoord0 = input.Texcoord0; + output.Texcoord1 = input.Texcoord1; + output.Texcoord2 = 0.5;// input.Texcoord; + output.Colour0 = input.Colour0; + output.Colour1 = float4(0.5, 0.5, 0.5, 1); //input.Colour; + output.Tint = tnt; + output.Tangent = float4(btang, 1); + output.Bitangent = float4(cross(btang, bnorm), 0); + return output; +} \ No newline at end of file diff --git a/Shaders/CodeWalkerShaders.vcxproj b/Shaders/CodeWalkerShaders.vcxproj index 35be97d..fe475e3 100644 --- a/Shaders/CodeWalkerShaders.vcxproj +++ b/Shaders/CodeWalkerShaders.vcxproj @@ -196,6 +196,16 @@ 4.0 4.0 + + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + Vertex Vertex diff --git a/Shaders/CodeWalkerShaders.vcxproj.filters b/Shaders/CodeWalkerShaders.vcxproj.filters index 6a0df68..4309be7 100644 --- a/Shaders/CodeWalkerShaders.vcxproj.filters +++ b/Shaders/CodeWalkerShaders.vcxproj.filters @@ -22,6 +22,7 @@ +