1 |
|
---|
2 | //float4 main_fp(float2 texCoord: TEXCOORD0, float2 texCoordNormalized: TEXCOORD1) : COLOR
|
---|
3 | //{
|
---|
4 | // // DirectX
|
---|
5 | // return float4((tex2D(orderFrontBack, texCoord).w > 0.0) ? tex2D(leaf,((texCoordNormalized - tex2D(orderFrontBack, texCoord).xy) + float2(0.0,0.0)) * 4.0) : 0.0);
|
---|
6 | //}
|
---|
7 |
|
---|
8 | /*
|
---|
9 | normal = normalize(normal);
|
---|
10 | // Radial distance
|
---|
11 | float depth = length(lightVec);
|
---|
12 | // Normalizes light vector
|
---|
13 | lightVec /= depth;
|
---|
14 |
|
---|
15 | // Standard lighting
|
---|
16 | float odiffuse = saturate(dot(lightVec, normal));
|
---|
17 | float ospecular = pow(saturate(dot(reflect(-normalize(viewVec), normal), lightVec)), 16);
|
---|
18 |
|
---|
19 | // The depth of the fragment closest to the light
|
---|
20 | float shadowMap = tex2Dproj(shadowMap, shadowCrd);
|
---|
21 | // A spot image of the spotlight
|
---|
22 | float spotLight = tex2Dproj(spotLight, shadowCrd);
|
---|
23 | // If the depth is larger than the stored depth, this fragment
|
---|
24 | // is not the closest to the light, that is we are in shadow.
|
---|
25 | // Otherwise, we're lit. Add a bias to avoid precision issues
|
---|
26 | float shadow;
|
---|
27 | shadow = (depth < shadowMap + shadowBias);
|
---|
28 |
|
---|
29 | // Cut back-projection, that is, make sure we don't lit
|
---|
30 | // anything behind the light. Theoretically, you should just
|
---|
31 | // cut at w = 0, but in practice you'll have to cut at a
|
---|
32 | // fairly high positive number to avoid precision issue when
|
---|
33 | // coordinates approaches zero.
|
---|
34 | shadow *= (shadowCrd.w > backProjectionCut);
|
---|
35 | // Modulate with spotlight image
|
---|
36 | shadow *= spotLight;
|
---|
37 |
|
---|
38 | // Shadow any light contribution except ambient
|
---|
39 | //float4 tempcolor = (tex2D(orderFrontBack, texCoord).w > 0.0) ? tex2D(leaf,((texCoordNormalized - tex2D(orderFrontBack, texCoord).xy) + float2(0.0,0.0)) * 4.0) : 0.0;
|
---|
40 | tempcolor = (tex2D(orderFrontBack, texCoord).x >= 0.0) ? tex2D(leaf,((texCoordNormalized - tex2D(orderFrontBack, texCoord).xy) + tex2D(orderFrontBack, texCoord).zw) * 4.0) : 0.0;
|
---|
41 | // green test
|
---|
42 | //tempcolor.xyz = float3(0.0,0.5,0.2);
|
---|
43 | // Look the different leaves orientations used...
|
---|
44 | //float4 tempcolor = (tex2D(orderFrontBack, texCoord).x >= 0.0) ? float4(tex2D(orderFrontBack, texCoord).zw,1.0,1.0) : 0.0;
|
---|
45 |
|
---|
46 | tempcolor = float4(lattenuation * (Ka*(gambient.xyz)) + (Kd*(odiffuse * tempcolor.xyz * ldiffuse)) + (Ks * (ospecular * lspecular)),tempcolor.w * 0.5);
|
---|
47 | //return float4((tex2D(orderFrontBack, texCoord).w > 0.0) ? tex2D(leaf,((texCoordNormalized - tex2D(orderFrontBack, texCoord).xy) + float2(0.0,0.0)) * 4.0) : 0.0);
|
---|
48 |
|
---|
49 | //else
|
---|
50 | //{
|
---|
51 | // tempcolor = float4(0.0,1.0,0.0,1.0);
|
---|
52 | //}
|
---|
53 | */
|
---|
54 |
|
---|
55 | float4x4 worldmatrix;
|
---|
56 | float tex_atlas_size;
|
---|
57 | float scale_factor;
|
---|
58 | float3 ldiffuse;
|
---|
59 | float3 lspecular;
|
---|
60 | float3 lattenuation;
|
---|
61 | float4 gambient;
|
---|
62 | float Ka;
|
---|
63 | float Kd;
|
---|
64 | float Ks;
|
---|
65 | sampler orderFrontBack: register(s0);
|
---|
66 | sampler leaf: register(s1);
|
---|
67 | sampler shadowMap: register(s2);
|
---|
68 | sampler spotLight: register(s3);
|
---|
69 |
|
---|
70 | float shadowBias = 45.57;
|
---|
71 | float backProjectionCut = 0.0;
|
---|
72 | 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
|
---|
73 | {
|
---|
74 | float4 tempcolor;
|
---|
75 | float4 ocolor;
|
---|
76 |
|
---|
77 | normal = normalize(normal);
|
---|
78 | // Front and Back faces lighted
|
---|
79 | normal = (reg > 0.0) ? normal : -normal;
|
---|
80 |
|
---|
81 | // Radial distance
|
---|
82 | float depth = length(lightVec);
|
---|
83 | // Normalizes light vector
|
---|
84 | lightVec /= depth;
|
---|
85 |
|
---|
86 | // Standard lighting
|
---|
87 | float odiffuse = saturate(dot(lightVec, normal));
|
---|
88 | float ospecular = pow(saturate(dot(reflect(-normalize(viewVec), normal), lightVec)), 16);
|
---|
89 |
|
---|
90 | // The depth of the fragment closest to the light
|
---|
91 | float shadowMap = tex2Dproj(shadowMap, shadowCrd);
|
---|
92 | // A spot image of the spotlight
|
---|
93 | float spotLight = tex2Dproj(spotLight, shadowCrd);
|
---|
94 | // If the depth is larger than the stored depth, this fragment
|
---|
95 | // is not the closest to the light, that is we are in shadow.
|
---|
96 | // Otherwise, we're lit. Add a bias to avoid precision issues
|
---|
97 | float shadow;
|
---|
98 | shadow = (depth < shadowMap + shadowBias);
|
---|
99 |
|
---|
100 | // Cut back-projection, that is, make sure we don't lit
|
---|
101 | // anything behind the light. Theoretically, you should just
|
---|
102 | // cut at w = 0, but in practice you'll have to cut at a
|
---|
103 | // fairly high positive number to avoid precision issue when
|
---|
104 | // coordinates approaches zero.
|
---|
105 | shadow *= (shadowCrd.w > backProjectionCut);
|
---|
106 | // Modulate with spotlight image
|
---|
107 | //shadow *= spotLight;
|
---|
108 |
|
---|
109 | // Shadow any light contribution except ambient
|
---|
110 | tempcolor = (tex2D(orderFrontBack, texCoord).x >= 0.0) ? tex2D(leaf,((texCoordNormalized - tex2D(orderFrontBack, texCoord).xy) + tex2D(orderFrontBack, texCoord).zw) * 4.0) : 0.0;
|
---|
111 |
|
---|
112 |
|
---|
113 | // green test
|
---|
114 | //tempcolor.xyz = float3(0.0,0.5,0.2);
|
---|
115 |
|
---|
116 | tempcolor = float4((Ka*(gambient.xyz)) + (Kd*(odiffuse * tempcolor.xyz * ldiffuse)) + (Ks * (ospecular * lspecular)),tempcolor.w);
|
---|
117 |
|
---|
118 | // Look the different leaves orientations used...
|
---|
119 | //tempcolor = (tex2D(orderFrontBack, texCoord).x >= 0.0) ? float4(tex2D(orderFrontBack, texCoord).zw,1.0,1.0) : 0.0;
|
---|
120 | // Check the AATexQuads of the leaves...
|
---|
121 | //tempcolor = (tex2D(orderFrontBack, texCoord).x >= 0.0) ? float4(tex2D(orderFrontBack, texCoord).xy,1.0,1.0) : 0.0;
|
---|
122 |
|
---|
123 | // Shows each side the front and the back side...
|
---|
124 | //tempcolor = (reg > 0.0) ? float4(1.0,0.0,0.0,tempcolor.w) : float4(0.0,1.0,0.0,tempcolor.w);
|
---|
125 |
|
---|
126 | ocolor = tempcolor;
|
---|
127 | return ocolor;
|
---|
128 | }
|
---|
129 |
|
---|