source: GTP/trunk/App/Games/Jungle_Rumble/src/shaders/terrain.fx @ 1378

Revision 1378, 5.0 KB checked in by giegl, 18 years ago (diff)

GTPD - Jungle Rumble - integrate into GTP SVN structure

Line 
1//
2// Globals
3//
4
5texture Top;
6texture Slope;
7texture Bottom;
8//texture Tex;
9
10vector Ambient;
11vector Sun_Direction;
12
13float4x4 g_mWorldViewProjection;
14float4x4 g_mWorldView;
15
16float FarPlaneMinusNearPlane; // Distance of the far plane minus distance of the near plane.
17
18//
19// Sampler
20//
21
22sampler TopTex = sampler_state
23{
24        Texture   = (Top);
25    MinFilter = LINEAR;
26    MagFilter = LINEAR;
27    MipFilter = LINEAR;
28};
29
30sampler SlopeTex = sampler_state
31{
32        Texture   = (Slope);
33    MinFilter = LINEAR;
34    MagFilter = LINEAR;
35    MipFilter = LINEAR;
36};
37
38sampler BottomTex = sampler_state
39{
40        Texture   = (Bottom);
41    MinFilter = LINEAR;
42    MagFilter = LINEAR;
43    MipFilter = LINEAR;
44};
45
46//
47// Structures
48//
49
50struct VS_OUTPUT
51{
52    float4 pos : POSITION;
53    float2 coord1 : TEXCOORD0;
54    float3 Normal : TEXCOORD1;
55    vector values : COLOR0;
56       
57};
58
59struct 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
69struct VS_OUTPUT_DEPTH
70{
71    float4 HPosition : POSITION;
72    float4 texCoord     : TEXCOORD0;
73};
74
75struct PS_OUTPUT
76{
77    float4 diffuse : COLOR0;
78};
79
80//
81// VertexShader Main
82//
83
84
85VS_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
96VS_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
108VS_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
121float4 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
133PS_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
153PS_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
176PS_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
188technique 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
203technique 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
218technique 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}
Note: See TracBrowser for help on using the repository browser.