1 | float4x4 worldmatrix;
|
---|
2 | float scale_factor;
|
---|
3 | float3 ldiffuse;
|
---|
4 | float3 lspecular;
|
---|
5 | float3 lattenuation;
|
---|
6 | float4 gambient;
|
---|
7 | float Ka;
|
---|
8 | float Kd;
|
---|
9 | float Ks;
|
---|
10 | sampler leaf: register(s0);
|
---|
11 | sampler shadowMap: register(s1);
|
---|
12 | sampler spotLight: register(s2);
|
---|
13 | sampler normalMap: register(s3);
|
---|
14 |
|
---|
15 | float shadowBias = 45.57;
|
---|
16 | float backProjectionCut = 0.0;
|
---|
17 | float4 main_fp(float reg: VFACE, float3 normal: TEXCOORD0, float3 lightVec: TEXCOORD1, float3 viewVec: TEXCOORD2, float4 shadowCrd: TEXCOORD3, float4 texCoord: TEXCOORD4, float4 texCoordNormalized: TEXCOORD5) : COLOR
|
---|
18 | {
|
---|
19 | float4 tempcolor;
|
---|
20 | float4 ocolor;
|
---|
21 |
|
---|
22 | // The normals are not correct if we change the orientation of the impostor tree
|
---|
23 | //----------------------------------------------------------------------------
|
---|
24 | // Using normalmap
|
---|
25 | //normal = tex2D(normalMap,texCoord);
|
---|
26 | // If we have random orientations and not only
|
---|
27 | // the original normal_map tree orientation
|
---|
28 | //normal = mul(worldmatrix,normal);
|
---|
29 | // The values are from 0..255, so I should convert them from [0,255] to [0,1]
|
---|
30 | // and convert from [0,1] to [-1,1]
|
---|
31 | //normal = float3(1.0,1.0,1.0) - normalize(normal) * 2.0;
|
---|
32 | //----------------------------------------------------------------------------
|
---|
33 |
|
---|
34 | // Front and Back faces lighted
|
---|
35 | normal = (reg > 0.0) ? normal : -normal;
|
---|
36 |
|
---|
37 | // Radial distance
|
---|
38 | float depth = length(lightVec);
|
---|
39 | // Normalizes light vector
|
---|
40 | lightVec /= depth;
|
---|
41 |
|
---|
42 | // Standard lighting
|
---|
43 | float odiffuse = saturate(dot(lightVec, normal));
|
---|
44 | float ospecular = pow(saturate(dot(reflect(-normalize(viewVec), normal), lightVec)), 16);
|
---|
45 |
|
---|
46 | // The depth of the fragment closest to the light
|
---|
47 | float shadowMap = tex2Dproj(shadowMap, shadowCrd);
|
---|
48 | // A spot image of the spotlight
|
---|
49 | float spotLight = tex2Dproj(spotLight, shadowCrd);
|
---|
50 | // If the depth is larger than the stored depth, this fragment
|
---|
51 | // is not the closest to the light, that is we are in shadow.
|
---|
52 | // Otherwise, we're lit. Add a bias to avoid precision issues
|
---|
53 | float shadow;
|
---|
54 | shadow = (depth < shadowMap + shadowBias);
|
---|
55 |
|
---|
56 | // Cut back-projection, that is, make sure we don't lit
|
---|
57 | // anything behind the light. Theoretically, you should just
|
---|
58 | // cut at w = 0, but in practice you'll have to cut at a
|
---|
59 | // fairly high positive number to avoid precision issue when
|
---|
60 | // coordinates approaches zero.
|
---|
61 | shadow *= (shadowCrd.w > backProjectionCut);
|
---|
62 | // Modulate with spotlight image
|
---|
63 | shadow *= spotLight;
|
---|
64 |
|
---|
65 | // Shadow any light contribution except ambient
|
---|
66 | tempcolor = tex2D(leaf,texCoord);
|
---|
67 | tempcolor = float4((Ka*(gambient.xyz)) + (Kd*(odiffuse * tempcolor.xyz * ldiffuse)) + (Ks * (ospecular * lspecular)),tempcolor.w);
|
---|
68 |
|
---|
69 | // Shows each side the front and the back side...
|
---|
70 | //tempcolor = (reg > 0.0) ? float4(1.0,0.0,0.0,tempcolor.w) : float4(0.0,1.0,0.0,tempcolor.w);
|
---|
71 |
|
---|
72 | // No lighting test...
|
---|
73 | //tempcolor = tex2D(leaf,texCoord);
|
---|
74 | ocolor = tempcolor;
|
---|
75 | return ocolor;
|
---|
76 | }
|
---|