Added vertex shader PNCTT and started implementation of DiffuseSampler2. (#43)

Added vertex shader PNCTT and implementation of DiffuseSampler2.
This commit is contained in:
horstche 2019-02-20 10:41:00 +01:00 committed by dexyfex
parent 7fe0bef6bd
commit 3690b082bc
5 changed files with 90 additions and 7 deletions

View File

@ -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();

View File

@ -4,6 +4,7 @@ Texture2D<float4> Colourmap : register(t0);
Texture2D<float4> Bumpmap : register(t2);
Texture2D<float4> Specmap : register(t3);
Texture2D<float4> Detailmap : register(t4);
Texture2D<float4> 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;

View File

@ -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;
}

View File

@ -196,6 +196,16 @@
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.0</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4.0</ShaderModel>
</FxCompile>
<FxCompile Include="BasicVS_PNCTT.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.0</ShaderModel>
</FxCompile>
<FxCompile Include="BasicVS_PNCTTTX.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>

View File

@ -22,6 +22,7 @@
<FxCompile Include="ShadowVS.hlsl" />
<FxCompile Include="ShadowPS.hlsl" />
<FxCompile Include="BasicVS_PNCT.hlsl" />
<FxCompile Include="BasicVS_PNCTT.hlsl" />
<FxCompile Include="BasicVS_PNCTX.hlsl" />
<FxCompile Include="BasicVS_PNCCT.hlsl" />
<FxCompile Include="BasicVS_PNCCTT.hlsl" />