//==================================================== // By EVOLVED // www.evolved-software.com //==================================================== //-------------- // un-tweaks //-------------- matrix ViewProj:ViewProjection; matrix ViewInv:ViewInverse; matrix World:World; //-------------- // tweaks //-------------- float WindTime; float3 LightDir={-0.384,-0.573,-0.723}; float3 LightColor={1.0f,1.0f,0.7f}; float3 Ambient={0.5f,0.5f,0.5f}; float WindPower=0.025f; float LeafWindSpeed=3; float LeafWindPower=0.3333f; float AvgSize=100.0f; float LeafSize=1.0f; float ColorIntensity=1; float Shade=0.75; float FogRange=18000.0f; float4 FogColor = {0.5, 0.5, 0.5, 1.0}; // ***** original code left out this line ***** //-------------- // Textures //-------------- texture BaseTX ; sampler Base = sampler_state { texture = ; ADDRESSU=CLAMP; ADDRESSV=CLAMP; ADDRESSW=CLAMP; }; //-------------- // structs //-------------- struct In_Diffuse { float4 Ipos:POSITION; float2 Iuv:TEXCOORD0; float3 Icolor:COLOR0; float3 Inormal:NORMAL; }; struct Out_Diffuse { float4 Opos:POSITION; float2 Ouv:TEXCOORD0; float3 Ocolor:TEXCOORD1; float3 Onormal:TEXCOORD2; float3 ONorViewPos:TEXCOORD3; float3 ViewPos:TEXCOORD4; float Fog:FOG; }; //-------------- // vertex shader //-------------- Out_Diffuse VS_Diffuse(In_Diffuse IN) { Out_Diffuse OUT; float3 WindAnimate=sin((IN.Ipos.xyz/AvgSize)+WindTime)*WindPower; WindAnimate.y=WindAnimate.y*0.1f; WindAnimate *=IN.Ipos.y/AvgSize; float3 LeafAnimate=cos((IN.Ipos.xyz/LeafSize)+(WindTime*LeafWindSpeed))*LeafWindPower; LeafAnimate *=1-IN.Iuv.y; float4 TempPos=mul(float4(IN.Ipos.xyz+WindAnimate+LeafAnimate,1),World); OUT.Opos=mul(TempPos,ViewProj); OUT.Ouv=IN.Iuv; OUT.Ocolor=IN.Icolor*(Shade+(1-IN.Iuv.y)*(1-Shade)); float3 ViewPos = (TempPos - ViewInv[3]).xyz; // ***** original code left out this line ***** OUT.ONorViewPos=normalize(TempPos-ViewInv[3].xyz); OUT.Onormal=normalize(mul(IN.Inormal,World)-OUT.ONorViewPos); OUT.ViewPos=-ViewPos; OUT.Fog=1-saturate(dot(ViewPos/FogRange,ViewPos/FogRange)); return OUT; } //-------------- // pixel shader //-------------- float4 PS_Diffuse(Out_Diffuse IN) : COLOR { float4 Texture=tex2D(Base,IN.Ouv); clip(Texture.w-0.25f); float Scatter=pow(saturate(dot(IN.ONorViewPos,-LightDir)),4)*saturate(Texture.w-0.333f)*0.333f; float Light=saturate(dot(-LightDir,IN.Onormal))+Scatter; return float4((Texture.xyz*IN.Ocolor*ColorIntensity)*((saturate(Light)*LightColor)+Ambient),1); } //-------------- // techniques //-------------- technique Diffuse { pass p0 { vertexShader = compile vs_2_0 VS_Diffuse(); pixelShader = compile ps_2_0 PS_Diffuse(); FOGCOLOR=(FogColor); FOGENABLE=TRUE; } }