HeightShader.fx
上传用户:henghua
上传日期:2007-11-14
资源大小:7655k
文件大小:2k
- float scale;
- float4 trailCorner00, trailCorner10, trailCorner01, trailCorner11;
- struct VS_INPUT
- {
- float3 Pos : POSITION;
- float2 tc : TEXCOORD0;
- };
- struct VS_OUTPUT
- {
- float4 Pos : POSITION;
- float2 tc0 : TEXCOORD0;
- float2 tc1 : TEXCOORD1;
- float2 tc2 : TEXCOORD2;
- };
- texture noise0;
- texture noise1;
- texture trailHeight;
- sampler noise0Sampler = sampler_state
- {
- texture = <noise0>;
- AddressU = WRAP;
- AddressV = WRAP;
- MIPFILTER = LINEAR;
- MINFILTER = LINEAR;
- MAGFILTER = LINEAR;
- };
- sampler noise1Sampler = sampler_state
- {
- texture = <noise1>;
- AddressU = WRAP;
- AddressV = WRAP;
- MIPFILTER = LINEAR;
- MINFILTER = LINEAR;
- MAGFILTER = LINEAR;
- };
- sampler trailSampler = sampler_state
- {
- texture = <trailHeight>;
- AddressU = WRAP;
- AddressV = WRAP;
- MIPFILTER = LINEAR;
- MINFILTER = LINEAR;
- MAGFILTER = LINEAR;
- };
- VS_OUTPUT VShader(VS_INPUT i)
- {
- VS_OUTPUT o;
- o.Pos = float4( i.tc.x*2-1,1-i.tc.y*2, 0, 1 );
- o.tc0 = scale*i.Pos.xz*0.01;
- o.tc1 = scale*i.Pos.xz*0.1;
- o.tc2 = i.Pos.xz;
- return o;
- }
- float4 PShader(VS_OUTPUT i) : COLOR
- {
- float2 trail_tc;
- float a = 0.0f;
- if(i.tc2.x>trailCorner00.x && i.tc2.y>trailCorner00.z && i.tc2.x<trailCorner11.x && i.tc2.y<trailCorner11.z)
- {
- trail_tc = (i.tc2 - trailCorner00.xz)/(trailCorner11.xz - trailCorner00.xz);
- a = 1.0f;
-
- }
- //return ((tex2D(noise0Sampler, i.tc0) + tex2D(noise1Sampler, i.tc1)) - 0.5f) * (1.0f-a);//*tex2D(trailSampler, trail_tc)
- return a*(tex2D(trailSampler, trail_tc.yx)-0.5f)*0.4 + ((tex2D(noise0Sampler, i.tc0) + tex2D(noise1Sampler, i.tc1)) - 0.5f);
- }
- technique T0
- {
- pass P0
- {
- vertexshader = compile vs_2_0 VShader();
- pixelshader = compile ps_2_0 PShader();
- }
- }