Ok. I make it. Helicopter position - the position (x,y,z).
WindRange - distance on tree to helicopter when air is turn tree.
float4x4 WorldViewProj : WorldViewProjection;
float4x4 mWorldView: WorldView;
float4x4 matWorldIT : WorldIT;
float4x4 matWorld : World;
matrix ViewInv : ViewInverse;
float gsc_Ambient=100;
float3 HelicopPos : HelicopPos ;
float3 eyePosition : CameraPosition;
float4 lightPosition = {500.0, 500.0, -500.0, 0.0001}; // w component contains reciprocal of light range
float4 ambientColour = {1, 1, 1, 1.0}; // ambient light
float4 lightColour = {0.95, 0.95, 0.95, 1.0}; // red positional light
float specularLevel = 1.0;
float specularExponent = 10.0;
float fadeStart = 500;
float fadeFull = 1000;
// -------------------------------------------------------------
// Parameters
// -------------------------------------------------------------
float randomOffset = 0.1;
float randomSpeedModifier = 1;
float yDimension = 35.0f;
float2 windDirection = float2(2, 0);
float windSpeed = 15.5f;
float HelicopWindSpeed = 15.5f;
float SimpleWindSpeed = 5.5f;
float Timer : Time < string UIWidget="None"; >;
float WindRange=50; //distance from helicopter
float4 fogColor={0.5f,0.5f,0.6f,1.0f};
float FogRange=100.0f;
float CamRange=20000.0f;
float AlphaClip = 0x000000cf; // The default value used internally by DBPro in transparency mode 4 / 6
texture DiffuseMap < string Name = ""; >;
// Samplers
sampler DiffuseSampler = sampler_state {
texture = < DiffuseMap >;
AddressU = Wrap;
AddressV = Wrap;
MagFilter = Linear;
MinFilter = Linear;
MipFilter = None; // Disable mip mapping for leaf textures, or they will appear very bad at a distance
};
struct vs_in {
float4 pos : POSITION0;
float2 texcoord : TEXCOORD0;
float3 normal : normal;
};
struct vs_out {
float4 pos : POSITION0;
float2 texcoord : TEXCOORD0;
float fog : FOG;
float3 lightDirection : texcoord1;
float3 viewDirection : texcoord2;
float3 normal : texcoord3;
float viewZ : texcoord4;
};
vs_out FoliageVS(vs_in IN) {
vs_out OUT;
//================================Distance from helicopter
float4 Po = float4(IN.pos.xyz,1);
float3 oPosition = mul(Po,matWorld );
float dist = distance(oPosition,HelicopPos);
//==============================
//float dist = distance(OUT.pos, HelicopPos);
randomSpeedModifier=3;
if (dist<WindRange) {
randomSpeedModifier=10;
}
//================================Swing
OUT.pos = mul(IN.pos, WorldViewProj);
OUT.texcoord = IN.texcoord;
float heightFactor = pow(IN.pos.y / yDimension, 2);
float sine = sin(Timer * randomSpeedModifier + randomOffset) * windSpeed * (-(randomSpeedModifier - 1) + 1);
OUT.pos.xz += sine * heightFactor * windDirection;
//=========Light====================================
float3 wPos = mul(IN.pos, matWorld).xyz;
OUT.lightDirection = (wPos - lightPosition.xyz) * lightPosition.w;
OUT.viewDirection = wPos - eyePosition;
OUT.normal = mul(IN.normal, (float3x3) matWorld);
OUT.viewZ = mul(IN.pos, mWorldView).z;
//===================================================
// float3 WPos=mul(In.pos,World);
//===================FOG==================================
// float3 WPos=mul(IN.pos,matWorld);
float3 ViewPos=ViewInv[3].xyz-wPos;
OUT.fog=1-saturate(dot(ViewPos/FogRange,ViewPos/FogRange));
return OUT;
}
float4 FoliagePS(vs_out IN) : COLOR {
// diffuse lighting only
float4 baseColour = tex2D(DiffuseSampler, IN.texcoord);
float3 normal = normalize(IN.normal);
float3 lightDirection = normalize(IN.lightDirection);
float diffuse = saturate(dot(normal, -lightDirection));
float attenuation = saturate(1.0 - length(IN.lightDirection));
//Out.colour = baseColour * (ambientColour + diffuse * attenuation * lightColour);
//return Out;
return baseColour * (ambientColour + diffuse * attenuation * lightColour);
//return tex2D(DiffuseSampler, IN.texcoord);
}
/********************************
* Techniques *
********************************/
technique AlphaClipping {
pass p0 {
// We want to enable alpha blending and set it so that the current fragment gets blended with the current value of its pixel
// such that the current colour is present in direct correspondence to its alpha value and the previous (pre-blended) colour
// is present in the mix to the "remaining" alpha after the current fragment's alpha is deducted from maximum alpha.
// This would probably correspond to DBPro's transparency mode 1.
AlphaBlendEnable = true;
SrcBlend = SrcAlpha;
DestBlend = InvSrcAlpha;
// Now if the alpha value of the current fragment is less than the value of the «AlphaClip» constant, we will completely
// disregard blending the current fragment in with the underlying pixel. This maps to what DBPro's transparency modes 4 and 6
// do, in which case the AlphaClip value is hardcoded to 0xcf / 0xff.
AlphaTestEnable = true;
AlphaRef = 0x000000cf;
AlphaFunc = Greater;
FOGCOLOR=(fogColor);
FOGENABLE=TRUE;
VertexShader = compile vs_2_0 FoliageVS();
PixelShader = compile ps_2_0 FoliagePS();
}
}
zzz!