forked from dexyfex/CodeWalker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerrainPS_Deferred.hlsl
227 lines (196 loc) · 7.89 KB
/
TerrainPS_Deferred.hlsl
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include "TerrainPS.hlsli"
PS_OUTPUT main(VS_OUTPUT input)
{
float4 vc0 = input.Colour0;
float4 vc1 = input.Colour1;
float2 tc0 = input.Texcoord0;
float2 tc1 = input.Texcoord1;
float2 tc2 = input.Texcoord2;
float2 sc0 = tc0;
float2 sc1 = tc0;
float2 sc2 = tc0;
float2 sc3 = tc0;
float2 sc4 = tc0;
float2 scm = tc1;
////switch (ShaderName)
////{
//// case 3965214311: //terrain_cb_w_4lyr_cm_pxm_tnt vt: PNCTTTX_3 //vb_35_beache
//// case 4186046662: //terrain_cb_w_4lyr_cm_pxm vt: PNCTTTX_3 //cs6_08_struct08
//// //vc1 = vc0;
//// //sc1 = tc0*25;
//// //sc2 = sc1;
//// //sc3 = sc1;
//// //sc4 = sc1;
//// //scm = tc0;
//// break;
////}
float4 bc0 = float4(0.5, 0.5, 0.5, 1);
//if (EnableVertexColour)
//{
// bc0 = vc0;
//}
if (RenderMode == 8) //direct texture - choose texcoords
{
if (RenderSamplerCoord == 2) sc0 = tc1;
else if (RenderSamplerCoord == 3) sc0 = tc2;
}
float4 c0 = (EnableTexture0 == 1) ? Colourmap0.Sample(TextureSS, sc0) : bc0;
float4 c1 = (EnableTexture1 == 1) ? Colourmap1.Sample(TextureSS, sc1) : bc0;
float4 c2 = (EnableTexture2 == 1) ? Colourmap2.Sample(TextureSS, sc2) : bc0;
float4 c3 = (EnableTexture3 == 1) ? Colourmap3.Sample(TextureSS, sc3) : bc0;
float4 c4 = (EnableTexture4 == 1) ? Colourmap4.Sample(TextureSS, sc4) : bc0;
float4 m = (EnableTextureMask == 1) ? Colourmask.Sample(TextureSS, scm) : vc1;
float4 b0 = (EnableNormalMap == 1) ? Normalmap0.Sample(TextureSS, sc0) : float4(0.5, 0.5, 0.5, 1);// float4(input.Normal, 0);
float4 b1 = (EnableNormalMap == 1) ? Normalmap1.Sample(TextureSS, sc1) : b0;
float4 b2 = (EnableNormalMap == 1) ? Normalmap2.Sample(TextureSS, sc2) : b0;
float4 b3 = (EnableNormalMap == 1) ? Normalmap3.Sample(TextureSS, sc3) : b0;
float4 b4 = (EnableNormalMap == 1) ? Normalmap4.Sample(TextureSS, sc4) : b0;
float4 tv=0, nv=0;
float4 t1, t2, n1, n2;
switch (ShaderName)
{
case 137526804: //terrain_cb_w_4lyr_lod vt: PNCCT //brdgeplatform_01_lod..
//return float4(vc1.rgb, vc1.a*0.5 + 0.5);
t1 = c1*(1 - vc1.b) + c2*vc1.b;
t2 = c3*(1 - vc1.b) + c4*vc1.b;
tv = t1*(1 - vc1.g) + t2*vc1.g;
n1 = b1*(1 - vc1.b) + b2*vc1.b;
n2 = b3*(1 - vc1.b) + b4*vc1.b;
nv = n1*(1 - vc1.g) + n2*vc1.g;
break;
default:
case 2535953532: //terrain_cb_w_4lyr_2tex_blend_lod vt: PNCCTT //cs1_12_riverbed1_lod..
//return float4(vc0.rgb, vc0.a*0.5 + 0.5);
//return float4(vc1.rgb, vc1.a*0.5 + 0.5);
vc1 = m*(1 - vc0.a) + vc1*vc0.a;
t1 = c1*(1 - vc1.b) + c2*vc1.b;
t2 = c3*(1 - vc1.b) + c4*vc1.b;
tv = t1*(1 - vc1.g) + t2*vc1.g;
n1 = b1*(1 - vc1.b) + b2*vc1.b;
n2 = b3*(1 - vc1.b) + b4*vc1.b;
nv = n1*(1 - vc1.g) + n2*vc1.g;
break;
case 653544224: //terrain_cb_w_4lyr_2tex_blend_pxm_spm vt: PNCCTTTX //ch2_04_land06, rd_04_20..
case 2486206885: //terrain_cb_w_4lyr_2tex_blend_pxm vt: PNCCTTTX //cs2_06c_lkbed_05..
case 1888432890: //terrain_cb_w_4lyr_2tex_pxm vt: PNCCTTTX //ch1_04b_vineland01..
//return float4(0, 1, 0, 1);
vc1 = m*(1 - vc0.a) + vc1*vc0.a; //perhaps another sampling of the mask is needed here
t1 = c1*(1 - vc1.b) + c2*vc1.b;
t2 = c3*(1 - vc1.b) + c4*vc1.b;
tv = t1*(1 - vc1.g) + t2*vc1.g;
n1 = b1*(1 - vc1.b) + b2*vc1.b;
n2 = b3*(1 - vc1.b) + b4*vc1.b;
nv = n1*(1 - vc1.g) + n2*vc1.g;
break;
case 3051127652: //terrain_cb_w_4lyr vt: PNCCTX //ss1_05_gr..
case 646532852: //terrain_cb_w_4lyr_spec vt: PNCCTX //hw1_07_grnd_c..
//return float4(1, 1, 0, 1);
vc1 = m*(1 - vc0.a) + vc1*vc0.a; //perhaps another sampling of the mask is needed here
t1 = c1*(1 - vc1.b) + c2*vc1.b;
t2 = c3*(1 - vc1.b) + c4*vc1.b;
tv = t1*(1 - vc1.g) + t2*vc1.g;
n1 = b1*(1 - vc1.b) + b2*vc1.b;
n2 = b3*(1 - vc1.b) + b4*vc1.b;
nv = n1*(1 - vc1.g) + n2*vc1.g;
break;
case 2316006813: //terrain_cb_w_4lyr_2tex_blend vt: PNCCTTX //ch2_04_land02b, vb_34_beachn_01..
case 3112820305: //terrain_cb_w_4lyr_2tex vt: PNCCTTX //ch1_05_land5..
case 2601000386: //terrain_cb_w_4lyr_spec_pxm vt: PNCCTTX_2 //ch2_03_land05, grnd_low2.. _road
case 4105814572: //terrain_cb_w_4lyr_pxm vt: PNCCTTX_2 //ch2_06_house02.. vb_35_beache
case 3400824277: //terrain_cb_w_4lyr_pxm_spm vt: PNCCTTX_2 //ch2_04_land02b, ch2_06_terrain01a .. vb_35_beacha
//return float4(1, 1, 1, 1);
vc1 = m*(1 - vc0.a) + vc1*vc0.a; //perhaps another sampling of the mask is needed here
t1 = c1*(1 - vc1.b) + c2*vc1.b;
t2 = c3*(1 - vc1.b) + c4*vc1.b;
tv = t1*(1 - vc1.g) + t2*vc1.g;
n1 = b1*(1 - vc1.b) + b2*vc1.b;
n2 = b3*(1 - vc1.b) + b4*vc1.b;
nv = n1*(1 - vc1.g) + n2*vc1.g;
break;
case 295525123: //terrain_cb_w_4lyr_cm vt: PNCTTX //_prewtrproxy_2..
case 417637541: //terrain_cb_w_4lyr_cm_tnt vt: PNCTTX //_prewtrproxy_2.. //golf course..
//tv = 1;// c1;// *vc0.r; //TODO!
//nv = b0;
vc1 = m; //needs work!
t1 = c1*(1 - vc1.b) + c2*vc1.b;
t2 = c3*(1 - vc1.b) + c4*vc1.b;
tv = t1*(1 - vc1.g) + t2*vc1.g;
n1 = b1*(1 - vc1.b) + b2*vc1.b;
n2 = b3*(1 - vc1.b) + b4*vc1.b;
nv = n1*(1 - vc1.g) + n2*vc1.g;
break;
case 3965214311: //terrain_cb_w_4lyr_cm_pxm_tnt vt: PNCTTTX_3 //vb_35_beache
case 4186046662: //terrain_cb_w_4lyr_cm_pxm vt: PNCTTTX_3 //cs6_08_struct08
//m = min(m, vc0);
//return float4(m.rgb, m.a*0.5 + 0.5);
//return float4(vc0.rgb, vc0.a*0.5 + 0.5);
//return float4(0, 1, 1, 1);
//m = vc0;
vc1 = m; //needs work!
t1 = c1*(1 - vc1.b) + c2*vc1.b;
t2 = c3*(1 - vc1.b) + c4*vc1.b;
tv = t1*(1 - vc1.g) + t2*vc1.g;
n1 = b1*(1 - vc1.b) + b2*vc1.b;
n2 = b3*(1 - vc1.b) + b4*vc1.b;
nv = n1*(1 - vc1.g) + n2*vc1.g;
break;
}
if (EnableTint == 1)
{
tv.rgb *= input.Tint.rgb;
}
if (RenderMode == 1) //normals
{
tv.rgb = normalize(input.Normal)*0.5+0.5;
}
else if (RenderMode == 2) //tangents
{
tv.rgb = normalize(input.Tangent.xyz)*0.5+0.5;
}
else if (RenderMode == 3) //colours
{
tv.rgb = input.Colour0.rgb;
if (RenderModeIndex == 2) tv.rgb = input.Colour1.rgb;
}
else if (RenderMode == 4) //texcoords
{
tv.rgb = float3(input.Texcoord0, 0);
if (RenderModeIndex == 2) tv.rgb = float3(input.Texcoord1, 0);
if (RenderModeIndex == 3) tv.rgb = float3(input.Texcoord2, 0);
}
else if (RenderMode == 5) //render diffuse maps
{
//nothing to do here yet, diffuse maps rendered by default
}
else if (RenderMode == 6) //render normalmaps
{
tv.rgb = nv.rgb;
}
else if (RenderMode == 7) //render spec maps
{
tv.rgb = 0.5; //nothing to see here yet...
}
else if (RenderMode == 8) //render direct texture
{
tv = c0;
}
//nv = normalize(nv*2-1);
//float4 tang = input.Tangent;
float3 nz = normalize(input.Normal);
//float3 nx = normalize(tang.xyz);
//float3 ny = normalize(cross(nz, nx));
////float3 norm = normalize(nx*nv.x + ny*nv.y + nz*nv.z);
float3 norm = nz;// normalize(input.Normal)
if ((RenderMode == 0) && (EnableNormalMap == 1))
{
norm = NormalMap(nv.xy, bumpiness, input.Normal.xyz, input.Tangent.xyz, input.Bitangent.xyz);
}
float3 spec = float3(0, 0, 1);
tv.a = saturate(tv.a);
PS_OUTPUT output;
output.Diffuse = tv;
output.Normal = float4(saturate(norm * 0.5 + 0.5), tv.a);
output.Specular = float4(spec, tv.a);
output.Irradiance = float4(input.Colour0.rg, 0, tv.a);
return output;
}