1 | //
|
---|
2 | // Globals
|
---|
3 | //
|
---|
4 |
|
---|
5 | texture Top;
|
---|
6 | texture Slope;
|
---|
7 | texture Bottom;
|
---|
8 | //texture Tex;
|
---|
9 |
|
---|
10 | vector Ambient;
|
---|
11 | vector Sun_Direction;
|
---|
12 |
|
---|
13 | float4x4 g_mWorldViewProjection;
|
---|
14 | float4x4 g_mWorldView;
|
---|
15 |
|
---|
16 | float FarPlaneMinusNearPlane; // Distance of the far plane minus distance of the near plane.
|
---|
17 |
|
---|
18 | //
|
---|
19 | // Sampler
|
---|
20 | //
|
---|
21 |
|
---|
22 | sampler TopTex = sampler_state
|
---|
23 | {
|
---|
24 | Texture = (Top);
|
---|
25 | MinFilter = LINEAR;
|
---|
26 | MagFilter = LINEAR;
|
---|
27 | MipFilter = LINEAR;
|
---|
28 | };
|
---|
29 |
|
---|
30 | sampler SlopeTex = sampler_state
|
---|
31 | {
|
---|
32 | Texture = (Slope);
|
---|
33 | MinFilter = LINEAR;
|
---|
34 | MagFilter = LINEAR;
|
---|
35 | MipFilter = LINEAR;
|
---|
36 | };
|
---|
37 |
|
---|
38 | sampler BottomTex = sampler_state
|
---|
39 | {
|
---|
40 | Texture = (Bottom);
|
---|
41 | MinFilter = LINEAR;
|
---|
42 | MagFilter = LINEAR;
|
---|
43 | MipFilter = LINEAR;
|
---|
44 | };
|
---|
45 |
|
---|
46 | //
|
---|
47 | // Structures
|
---|
48 | //
|
---|
49 |
|
---|
50 | struct VS_OUTPUT
|
---|
51 | {
|
---|
52 | float4 pos : POSITION;
|
---|
53 | float2 coord1 : TEXCOORD0;
|
---|
54 | float3 Normal : TEXCOORD1;
|
---|
55 | vector values : COLOR0;
|
---|
56 |
|
---|
57 | };
|
---|
58 |
|
---|
59 | struct VS_OUTPUT_RAY
|
---|
60 | {
|
---|
61 | float4 pos : POSITION;
|
---|
62 | float2 coord1 : TEXCOORD0;
|
---|
63 | float3 Normal : TEXCOORD1;
|
---|
64 | float3 pos2 : TEXCOORD2;
|
---|
65 | vector values : COLOR0;
|
---|
66 |
|
---|
67 | };
|
---|
68 |
|
---|
69 | struct VS_OUTPUT_DEPTH
|
---|
70 | {
|
---|
71 | float4 HPosition : POSITION;
|
---|
72 | float4 texCoord : TEXCOORD0;
|
---|
73 | };
|
---|
74 |
|
---|
75 | struct PS_OUTPUT
|
---|
76 | {
|
---|
77 | float4 diffuse : COLOR0;
|
---|
78 | };
|
---|
79 |
|
---|
80 | //
|
---|
81 | // VertexShader Main
|
---|
82 | //
|
---|
83 |
|
---|
84 |
|
---|
85 | VS_OUTPUT vs_main(float4 inPos: POSITION, float3 inNormal: NORMAL, float2 inCoord1: TEXCOORD0, vector inValues : COLOR0)
|
---|
86 | {
|
---|
87 | VS_OUTPUT Out;
|
---|
88 |
|
---|
89 | Out.pos = mul(inPos, g_mWorldViewProjection );
|
---|
90 | Out.coord1 = inCoord1;
|
---|
91 | Out.Normal = inNormal;
|
---|
92 | Out.values = inValues;
|
---|
93 | return Out;
|
---|
94 | }
|
---|
95 |
|
---|
96 | VS_OUTPUT_RAY vs_main_ray(float4 inPos: POSITION, float3 inNormal: NORMAL, float2 inCoord1: TEXCOORD0, vector inValues : COLOR0)
|
---|
97 | {
|
---|
98 | VS_OUTPUT_RAY Out;
|
---|
99 |
|
---|
100 | Out.pos = mul(inPos, g_mWorldViewProjection );
|
---|
101 | Out.coord1 = inCoord1;
|
---|
102 | Out.Normal = inNormal;
|
---|
103 | Out.values = inValues;
|
---|
104 | Out.pos2 = mul(inPos, g_mWorldView );
|
---|
105 | return Out;
|
---|
106 | }
|
---|
107 |
|
---|
108 | VS_OUTPUT_DEPTH vs_main_depth(float4 position : POSITION, float4 texCoord1 : TEXCOORD0)
|
---|
109 | {
|
---|
110 | VS_OUTPUT_DEPTH OUT;
|
---|
111 | float4 vertexpos = float4(position.xyz, 1.0);
|
---|
112 | float4 eyespace = mul(vertexpos, g_mWorldViewProjection);
|
---|
113 | OUT.HPosition = eyespace;
|
---|
114 | float tempDepth = saturate(eyespace.z/FarPlaneMinusNearPlane);
|
---|
115 | texCoord1.a = tempDepth;
|
---|
116 | OUT.texCoord = texCoord1;
|
---|
117 | return OUT;
|
---|
118 | }
|
---|
119 |
|
---|
120 | //per pixel lighting function
|
---|
121 | float4 Light_PointDiffuse(vector LightDir, float3 Normal)
|
---|
122 | {
|
---|
123 | // Compute suface/light angle based attenuation defined as dot(N,L)
|
---|
124 | float AngleAttn = clamp(0, 1, dot(Normal, LightDir.xyz) );
|
---|
125 |
|
---|
126 | return AngleAttn;
|
---|
127 | }
|
---|
128 |
|
---|
129 | //
|
---|
130 | // PixelShader Main
|
---|
131 | //
|
---|
132 |
|
---|
133 | PS_OUTPUT ps_main(float2 coord1 : TEXCOORD0, float3 Normal : TEXCOORD1, vector values : COLOR0)
|
---|
134 | {
|
---|
135 | // zero out members of output
|
---|
136 | PS_OUTPUT output = (PS_OUTPUT)0;
|
---|
137 |
|
---|
138 | // sample appropriate textures
|
---|
139 | vector t = tex2D(TopTex, coord1);
|
---|
140 | vector s = tex2D(SlopeTex, coord1);
|
---|
141 | vector b = tex2D(BottomTex, coord1);
|
---|
142 |
|
---|
143 | // combine texel colors
|
---|
144 | vector c = t*values.x + s*values.y + b*values.z;
|
---|
145 |
|
---|
146 | // do per-pixel-lighting
|
---|
147 | output.diffuse = c * Light_PointDiffuse(Sun_Direction,Normal) + 0.1;
|
---|
148 |
|
---|
149 | //return result
|
---|
150 | return output;
|
---|
151 | }
|
---|
152 |
|
---|
153 | PS_OUTPUT ps_main_ray(float2 coord1 : TEXCOORD0, float3 Normal : TEXCOORD1, float3 pos2 : TEXCOORD2, vector values : COLOR0)
|
---|
154 | {
|
---|
155 | // zero out members of output
|
---|
156 | PS_OUTPUT output = (PS_OUTPUT)0;
|
---|
157 |
|
---|
158 | // sample appropriate textures
|
---|
159 | vector t = tex2D(TopTex, coord1);
|
---|
160 | vector s = tex2D(SlopeTex, coord1);
|
---|
161 | vector b = tex2D(BottomTex, coord1);
|
---|
162 |
|
---|
163 | // combine texel colors
|
---|
164 | vector c = t*values.x + s*values.y + b*values.z;
|
---|
165 |
|
---|
166 | // do per-pixel-lighting
|
---|
167 | output.diffuse = c * Light_PointDiffuse(Sun_Direction,Normal) + 0.1;
|
---|
168 |
|
---|
169 | // The distance
|
---|
170 | output.diffuse.a = (float) ( length( pos2.xyz ) );
|
---|
171 |
|
---|
172 | //return result
|
---|
173 | return output;
|
---|
174 | }
|
---|
175 |
|
---|
176 | PS_OUTPUT ps_main_depth(VS_OUTPUT_DEPTH IN)
|
---|
177 | {
|
---|
178 | PS_OUTPUT OUT;
|
---|
179 | float depth = IN.texCoord.a;
|
---|
180 | OUT.diffuse = float4(depth, depth, depth, depth);
|
---|
181 | return OUT;
|
---|
182 | }
|
---|
183 |
|
---|
184 | //
|
---|
185 | // Effect
|
---|
186 | //
|
---|
187 |
|
---|
188 | technique TerrainShader
|
---|
189 | {
|
---|
190 | pass P0
|
---|
191 | {
|
---|
192 | //
|
---|
193 | // Set Misc render states.
|
---|
194 | vertexshader = compile vs_2_0 vs_main();
|
---|
195 | pixelshader = compile ps_2_0 ps_main();
|
---|
196 | fvf = XYZ | Normal | Tex1;
|
---|
197 | Lighting = false;
|
---|
198 | NormalizeNormals = false;
|
---|
199 | SpecularEnable = false;
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 | technique TerrainShaderRay
|
---|
204 | {
|
---|
205 | pass P0
|
---|
206 | {
|
---|
207 | //
|
---|
208 | // Set Misc render states.
|
---|
209 | vertexshader = compile vs_2_0 vs_main_ray();
|
---|
210 | pixelshader = compile ps_2_0 ps_main_ray();
|
---|
211 | fvf = XYZ | Normal | Tex1;
|
---|
212 | Lighting = false;
|
---|
213 | NormalizeNormals = false;
|
---|
214 | SpecularEnable = false;
|
---|
215 | }
|
---|
216 | }
|
---|
217 |
|
---|
218 | technique TerrainShaderDepth
|
---|
219 | {
|
---|
220 | pass P0
|
---|
221 | {
|
---|
222 | //
|
---|
223 | // Set Misc render states.
|
---|
224 | vertexshader = compile vs_2_0 vs_main_depth();
|
---|
225 | pixelshader = compile ps_2_0 ps_main_depth();
|
---|
226 | fvf = XYZ | Normal | Tex1;
|
---|
227 | Lighting = false;
|
---|
228 | NormalizeNormals = false;
|
---|
229 | SpecularEnable = false;
|
---|
230 | }
|
---|
231 | }
|
---|