forked from dexyfex/CodeWalker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerrainVS.hlsli
87 lines (75 loc) · 1.78 KB
/
TerrainVS.hlsli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "Shadowmap.hlsli"
#include "Quaternion.hlsli"
cbuffer VSSceneVars : register(b0)
{
float4x4 ViewProj;
}
cbuffer VSEntityVars : register(b2)
{
float4 CamRel;
float4 Orientation;
uint HasSkeleton;
uint HasTransforms;
uint TintPaletteIndex;
uint Pad1;
float3 Scale;
uint Pad2;
}
cbuffer VSModelVars : register(b3)
{
float4x4 Transform;
}
cbuffer VSGeomVars : register(b4)
{
uint EnableTint;
float TintYVal;
uint Pad4;
uint Pad5;
}
struct VS_OUTPUT
{
float4 Position : SV_POSITION;
float3 Normal : NORMAL;
float4 Colour0 : COLOR0;
float4 Colour1 : COLOR1;
float4 Tint : COLOR2;
float2 Texcoord0 : TEXCOORD0;
float2 Texcoord1 : TEXCOORD1;
float2 Texcoord2 : TEXCOORD2;
float4 Shadows : TEXCOORD4;
float4 LightShadow : TEXCOORD5;
float4 Tangent : TEXCOORD6;
float4 Bitangent : TEXCOORD7;
float3 CamRelPos : TEXCOORD8;
};
Texture2D<float4> TintPalette : register(t0);
SamplerState TextureSS : register(s0);
float3 ModelTransform(float3 ipos)
{
float3 tpos = (HasTransforms == 1) ? mul(float4(ipos, 1), Transform).xyz : ipos;
float3 spos = tpos * Scale;
float3 bpos = mulvq(spos, Orientation);
return CamRel.xyz + bpos;
}
float4 ScreenTransform(float3 opos)
{
float4 pos = float4(opos, 1);
float4 cpos = mul(pos, ViewProj);
cpos.z = DepthFunc(cpos.zw);
return cpos;
}
float3 NormalTransform(float3 inorm)
{
float3 tnorm = (HasTransforms == 1) ? mul(inorm, (float3x3)Transform) : inorm;
float3 bnorm = normalize(mulvq(tnorm, Orientation));
return bnorm;
}
float4 ColourTint(float tx)
{
float4 tnt = 1;
if (EnableTint == 1)
{
tnt = TintPalette.SampleLevel(TextureSS, float2(tx, TintYVal), 0);
}
return tnt;
}