// Vertex part struct typInput { float4 Position : POSITION; float3 Normal : NORMAL; float2 uv0 : TEXCOORD0; float4 c : COLOR0; }; struct typOutput { float4 Position : POSITION; float4 light : COLOR1; float2 T0 : TEXCOORD0; float2 T1 : TEXCOORD1; float2 T2 : TEXCOORD2; }; typOutput main_vp(typInput inData, uniform float3 gravity, uniform float furHeight, uniform float totalPass, uniform float2 UVScale, uniform float4x4 wvpMat, uniform float4x4 iwpMat, uniform float4x4 wpMat, uniform float4 eyePosition, uniform float3 ambientColor, uniform float4 lightPosition, uniform float4 lightAttenuation, uniform float3 lightDiffuseColor, uniform float3 Ke, uniform float3 Ka, uniform float3 Kd, uniform float3 Ks, uniform float shininess, uniform float multiPassIter){ typOutput outData; float4 normal = mul(wpMat, float4(inData.Normal, 1.0)); // light float4 tmpcolor = inData.c; furHeight = furHeight * ((1.0 / (totalPass + 1)) * (multiPassIter + 1)); float3 vGravity = mul(wpMat, float4(gravity, 0.0)).xyz; //float pp = 3.14 * 0.5 * Layer; // depth paramete //float A = dot(normal, vGravity); //A is the angle between surface normal and gravity vector float k = pow(((1.0 / (totalPass + 1)) * (multiPassIter + 1)), 3); // We use the pow function, so that only the tips of the hairs bend // As layer goes from 0 to 1, so by using pow(..) function is still // goes form 0 to 1, but it increases faster! exponentially float3 P = inData.Position.xyz + (inData.Normal * furHeight); P = P + vGravity*k; float4 znormal = 1 - dot(normal, float4(0,0,1,0)); outData.T0 = inData.uv0 * UVScale; outData.T1 = inData.uv0 * UVScale + znormal.xy * 0.0007; outData.T2 = inData.uv0; lightPosition = mul(iwpMat, lightPosition); eyePosition = mul(iwpMat, eyePosition); float3 N = normalize(inData.Normal); float3 emissive = Ke; float3 ambient = Ka * ambientColor; float3 L = normalize(lightPosition).xyz; float diffuseLight = max(dot(L, N), 0); float3 diffuse = Kd * lightDiffuseColor * diffuseLight; float3 V = normalize(eyePosition).xyz; float3 H = normalize(L + V); float specularLight = pow(max(dot(H, N), 0), shininess); if (diffuseLight <= 0) specularLight = 0; float3 specular = Ks * lightDiffuseColor * specularLight; tmpcolor.xyz = emissive + ambient + specular + diffuse; outData.Position = mul(wvpMat, float4(P, 1.0)); outData.light = tmpcolor; return outData; } //Fragment part struct typOut { float4 fragColor : COLOR; }; struct typIn { float4 Position : POSITION; float4 light : COLOR1; float2 T0 : TEXCOORD0; float2 T1 : TEXCOORD1; float2 T2 : TEXCOORD2; float2 ambient : TEXCOORD3; }; typOut main_fp(typIn inData, uniform float3 vecLightDir, uniform sampler2D noiseTexture : register(s0), uniform sampler2D colorTexture : register(s1), uniform float spacing, uniform float transparency) { typOut outData; float4 furcolr = tex2D(noiseTexture, inData.T0); float4 furcolr_offset = tex2D(noiseTexture, inData.T1); float4 texcolr = tex2D(colorTexture, inData.T2); float4 color = furcolr_offset - furcolr; float4 fcolor = color; fcolor.a = color.a; fcolor = (texcolr * inData.light) + (fcolor * inData.light); fcolor.a = color.a; outData.fragColor = fcolor; return outData; }