1 | float shininess;
|
---|
2 | float nearDistance;
|
---|
3 | float farDistance;
|
---|
4 | float tex_atlas_size;
|
---|
5 | float scale_factor;
|
---|
6 | float3 lDiffuseColor;
|
---|
7 | float3 lSpecularColor;
|
---|
8 | float3 lattenuation;
|
---|
9 | float4 gambient;
|
---|
10 | float Ka;
|
---|
11 | float Kd;
|
---|
12 | float Ks;
|
---|
13 | sampler orderFrontBack: register(s0);
|
---|
14 | sampler leaf: register(s1);
|
---|
15 | sampler shadowMap: register(s6);
|
---|
16 | sampler spotLight: register(s2);
|
---|
17 | sampler normalMap: register(s3);
|
---|
18 | sampler ob_front_face: register(s4);
|
---|
19 | sampler ob_back_face: register(s5);
|
---|
20 | float shadowBias = 0.0;
|
---|
21 | float backProjectionCut = 0.01;
|
---|
22 | float exposure;
|
---|
23 | float4x4 worldmatrix;
|
---|
24 |
|
---|
25 | //float4 main_fp(float2 texCoord: TEXCOORD0, float2 texCoordNormalized: TEXCOORD1) : COLOR
|
---|
26 | //{
|
---|
27 | // // DirectX
|
---|
28 | // return float4((tex2D(orderFrontBack, texCoord).w > 0.0) ? tex2D(leaf,((texCoordNormalized - tex2D(orderFrontBack, texCoord).xy) + float2(0.0,0.0)) * 4.0) : 0.0);
|
---|
29 | //}
|
---|
30 |
|
---|
31 | float4 main_fp(float reg: VFACE, float3 normal: TEXCOORD0, float3 lightVec: TEXCOORD1, float4 halfvec: TEXCOORD2, float4 shadowCrd: TEXCOORD3,
|
---|
32 | //float4 main_fp(float3 normal: TEXCOORD0, float3 lightVec: TEXCOORD1, float4 halfvec: TEXCOORD2, float4 shadowCrd: TEXCOORD3,
|
---|
33 | float4 texCoord: TEXCOORD4, float4 texCoordNormalized: TEXCOORD5,float4 lightVecNormalMapping: TEXCOORD6, float backside: TEXCOORD7) : COLOR
|
---|
34 | {
|
---|
35 | float4 leafColor;
|
---|
36 | float4 ocolor;
|
---|
37 |
|
---|
38 | // The normals are not correct if we change the orientation of the impostor tree
|
---|
39 | //----------------------------------------------------------------------------
|
---|
40 | // Using normalmap, the vertex normal is not used...
|
---|
41 | float2 coords = ((texCoordNormalized - tex2D(orderFrontBack, texCoord).xy) + tex2D(orderFrontBack, texCoord).zw) * 4.0;
|
---|
42 | //normal = tex2D(normalMap,coords);
|
---|
43 | // The values are from 0..255, so I should convert them from [0,255] to [0,1]
|
---|
44 | // and convert from [0,1] to [-1,1]
|
---|
45 | //normal = float3(1.0,1.0,1.0) - normal * 2.0;
|
---|
46 | //normal = mul(worldmatrix,normal);
|
---|
47 | //----------------------------------------------------------------------------
|
---|
48 |
|
---|
49 | normal = normalize(normal);
|
---|
50 | // Front and Back faces lighted, not needed because we
|
---|
51 | // correct the orientation in the vertex program.
|
---|
52 | //normal = (backside == 0.0) ? -normal : normal;
|
---|
53 | normal = (reg > 0.0) ? normal : -normal;
|
---|
54 |
|
---|
55 | //float4 obsColor = (backside == 1.0) ? float4(tex2D(ob_front_face,texCoord).xyz,1.0) : float4(tex2D(ob_back_face,texCoord).xyz,1.0);
|
---|
56 | //float4 obsColor = (backside == 0.0) ? float4(tex2D(ob_front_face,texCoord).xyzw)
|
---|
57 | //float4 obsColor = (backside == 0.0) ? float4(tex2D(ob_front_face,texCoord).xxxw) : float4(tex2D(ob_front_face,texCoord).yyyw);
|
---|
58 | //float4 obsColor = (reg > 0.0) ? float4(tex2D(ob_front_face,texCoord).xxxw) : float4(tex2D(ob_front_face,texCoord).yyyw);
|
---|
59 |
|
---|
60 | // Radial distance
|
---|
61 | float depth = length(lightVec.xyz);
|
---|
62 |
|
---|
63 | // Standard lighting
|
---|
64 | // Using the standard normals in Object-space
|
---|
65 | lightVec = normalize(lightVec);
|
---|
66 |
|
---|
67 | //float lDiffuseAttenuation = saturate(dot(lightVec,normal));
|
---|
68 | //float lSpecularAttenuation = pow(saturate(dot(reflect(-normalize(lightVecNormalMapping),normal),lightVec)),shininess);
|
---|
69 | float lDiffuseAttenuation = max(dot(lightVec,normal),0.0);
|
---|
70 | float lSpecularAttenuation = pow(max(dot(reflect(-normalize(lightVecNormalMapping),normal),lightVec),0.0),shininess);
|
---|
71 |
|
---|
72 |
|
---|
73 |
|
---|
74 | // Using the normal_map in Tangent-space
|
---|
75 | //float lDiffuseAttenuation = clamp(0.0,1.0,dot(normal,lightVecNormalMapping));
|
---|
76 | //float lSpecularAttenuation = pow(clamp(0.0,1.0,dot(normal,halfvec)),shininess);
|
---|
77 |
|
---|
78 | // The depth of the fragment closest to the light
|
---|
79 | float4 shadowMapValue = tex2Dproj(shadowMap, shadowCrd).xyzw;
|
---|
80 |
|
---|
81 | // A spot image of the spotlight
|
---|
82 | float spotLight = tex2Dproj(spotLight, shadowCrd);
|
---|
83 | // If the depth is larger than the stored depth, this fragment
|
---|
84 | // is not the closest to the light, that is we are in shadow.
|
---|
85 | // Otherwise, we're lit. Add a bias to avoid precision issues
|
---|
86 | float shadow;
|
---|
87 | shadow = (depth < shadowMapValue.w + shadowBias);
|
---|
88 |
|
---|
89 | // Cut back-projection, that is, make sure we don't lit
|
---|
90 | // anything behind the light. Theoretically, you should just
|
---|
91 | // cut at w = 0, but in practice you'll have to cut at a
|
---|
92 | // fairly high positive number to avoid precision issue when
|
---|
93 | // coordinates approaches zero.
|
---|
94 | shadow *= (shadowCrd.w > backProjectionCut);
|
---|
95 | // Modulate with spotlight image
|
---|
96 | shadow *= spotLight + 0.8;
|
---|
97 |
|
---|
98 |
|
---|
99 | // Shadow any light contribution except ambient
|
---|
100 | // green test
|
---|
101 | //leafColor.xyz = float3(0.0,0.5,0.2);
|
---|
102 |
|
---|
103 | leafColor = (tex2D(orderFrontBack,texCoord).w > 0.0) ? tex2D(leaf,coords) : 0.0;
|
---|
104 |
|
---|
105 |
|
---|
106 | //shadow = 0.2 - clamp(0.0,0.2,shadow);
|
---|
107 | //leafColor = float4(leafColor.xyz - float3(shadow,shadow,shadow),leafColor.w);
|
---|
108 | //
|
---|
109 | //leafColor = (depth < 2000 && depth > 500) ? float4(1.0,0.0,0.0,leafColor.w) : float4(0.0,1.0,0.0,leafColor.w);
|
---|
110 | //leafColor = (shadowMapValue * 1000.0 < 2000 && shadowMapValue * 1000.0 > 500.0) ? float4(1.0,0.0,0.0,leafColor.w) : float4(0.0,1.0,0.0,leafColor.w);
|
---|
111 | //leafColor = (shadowMapValue * 1000.0 < depth) ? float4(leafColor.xyz * 0.5,leafColor.w) : float4(leafColor.xyz,leafColor.w);
|
---|
112 |
|
---|
113 | //leafColor = float4((Ka*(obsColor.xyz * 0.005)) + (Kd*(lDiffuseAttenuation * leafColor.xyz * lDiffuseColor)) + (Ks * (lSpecularAttenuation * lSpecularColor)) ,leafColor.w);
|
---|
114 | //leafColor = float4((Ka*(gambient.xyz)) + (Kd*(lDiffuseAttenuation * leafColor.xyz * lDiffuseColor)) + (Ks * (lSpecularAttenuation * lSpecularColor)) ,leafColor.w);
|
---|
115 | //leafColor = float4((Ka*(gambient.xyz)) + (Kd*(lDiffuseAttenuation * leafColor.xyz * lDiffuseColor)) + float3(shadow,shadow,shadow)*0.2 + (Ks * (lSpecularAttenuation * lSpecularColor)) ,leafColor.w);
|
---|
116 | //leafColor = float4(obsColor.xyz * 0.005,leafColor.w);
|
---|
117 |
|
---|
118 | // Look the different leaves orientations used...
|
---|
119 | //leafColor = (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 | //leafColor = (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 | //leafColor = (reg > 0.0) ? float4(1.0,0.0,0.0,leafColor.w) : float4(0.0,1.0,0.0,leafColor.w);
|
---|
125 |
|
---|
126 | //leafColor = float4(leafColor.xyz*0.6 + ( leafColor.xyz ) * (shadow),leafColor.w);
|
---|
127 | //leafColor = float4(color.xyz, 1.0) * (float4(intensity,1.0) * float4(aux.rgb / aux.a, 1.0) + shadow * float4(diffuse,0.0));
|
---|
128 |
|
---|
129 | //leafColor = float4(leafColor.xyz,leafColor.w) * float4(gambient.xyz * (1.0 - exp(-exposure * obsColor.xyz)), 1.0) + shadow * float4((Kd*leafColor.xyz*(lDiffuseAttenuation * lDiffuseColor)),0.0) + float4(Ks * (lSpecularAttenuation * lSpecularColor),0.0);
|
---|
130 | //leafColor = float4(leafColor.xyz,leafColor.w) * float4(gambient.xyz, 1.0) + float4((shadow * Kd*leafColor.xyz*(lDiffuseAttenuation * lDiffuseColor)),0.0) + float4(Ks * (lSpecularAttenuation * lSpecularColor),0.0);
|
---|
131 | //leafColor = float4(leafColor.xyz,leafColor.w) * float4(Ka * gambient.xyz, 1.0) + float4((Kd*leafColor.xyz*(lDiffuseColor)),0.0) + float4(Ks * (lSpecularAttenuation * lSpecularColor),0.0);
|
---|
132 |
|
---|
133 |
|
---|
134 | leafColor = float4(0.0,0.0,0.0,leafColor.w)
|
---|
135 | + float4(Ka * gambient.xyz * leafColor.xyz,0.0)
|
---|
136 | ////+ float4(Kd * lDiffuseAttenuation * leafColor.xyz * lDiffuseColor,0.0);
|
---|
137 | + float4(Kd * lDiffuseAttenuation * leafColor.xyz,0.0)
|
---|
138 | //+ float4(Ks * lSpecularAttenuation * lSpecularColor,0.0);
|
---|
139 | + float4(Ks * lSpecularAttenuation * leafColor.xyz,0.0);
|
---|
140 |
|
---|
141 | //leafColor = float4(lDiffuseAttenuation.xxx,leafColor.w);
|
---|
142 | //leafColor.xyz = float4(float4(gambient.xyz * (1.0 - exp(-exposure * obsColor.xyz)), 0.0) + (float4((Kd*(lDiffuseAttenuation * lDiffuseColor)),0.0) + float4(Ks * (lSpecularAttenuation * lSpecularColor),0.0)) * leafColor.xyzw).xyz;
|
---|
143 |
|
---|
144 | //leafColor = float4(leafColor.xyz,leafColor.w) * float4(gambient.xyz + (exp(-exposure * obsColor.xyz)), 1.0) + shadow * float4((Kd*leafColor.xyz*(lDiffuseAttenuation * lDiffuseColor)),0.0) + float4(Ks * (lSpecularAttenuation * lSpecularColor),0.0);
|
---|
145 | //leafColor.xyz = gambient * ( 1.0 - (exp(-exposure * (obsColor.xyz/obsColor.w))) ) + ( 1.0 - (exp(-exposure * (obsColor.xyz/obsColor.w))) ) + leafColor.xyzw * (float4((Kd*(lDiffuseAttenuation * lDiffuseColor * leafColor.xyz)),0.0) + float4(Ks * (lSpecularAttenuation * lSpecularColor),0.0));
|
---|
146 | //if (leafColor.w > 0)
|
---|
147 | //{
|
---|
148 | // leafColor = float4(1.0 - (exp(-exposure * (obsColor.xyz/obsColor.w))),1.0);
|
---|
149 | //}
|
---|
150 | //else
|
---|
151 | //{
|
---|
152 | // leafColor = float4(0.0,1.0,0.0,1.0);
|
---|
153 | //}
|
---|
154 | //leafColor = float4(1.0 - (exp(-exposure * (obsColor.xyz/obsColor.w))),1.0);
|
---|
155 | //leafColor = float4(1.0 - (exp(-exposure * (obsColor.xyz/obsColor.w))),leafColor.w);
|
---|
156 |
|
---|
157 | //leafColor = float4(1.0 - (exp(-exposure * (obsColor.xyz/obsColor.w))),1.0);
|
---|
158 | //leafColor = float4(1.0 - (obsColor.xyz/obsColor.w) * 2.0, leafColor.w);
|
---|
159 | //depth = depth / 4000.0;
|
---|
160 | //depth = -depth;
|
---|
161 | //leafColor = float4(depth.xxx,leafColor.w);
|
---|
162 | //leafColor = float4(shadowMapValue.www,leafColor.w);
|
---|
163 | //leafColor = float4(shadow.xxx,leafColor.w);
|
---|
164 |
|
---|
165 | // This proves that the depth is GREATER than the value of the shadow_map
|
---|
166 | // Without normalizing between the far and near planes distance...
|
---|
167 | //leafColor = float4(float3(1.0,1.0,1.0)-s
|
---|
168 | //leafColor = float4(shadow.xxx,leafColor.w);
|
---|
169 |
|
---|
170 | // Normalizing between far and near planes distance...
|
---|
171 | //leafColor = ((shadowMapValue + shadowBias) > 0.5) ? float4(1.0,0.0,0.0,leafColor.w) : float4(0.0,1.0,0.0,leafColor.w);
|
---|
172 |
|
---|
173 | //leafColor = float4(leafColor.xyz * depth,leafColor.w);
|
---|
174 | //leafColor = float4(leafColor.xyz * depth,leafColor.w);
|
---|
175 | //leafColor = float4(normal,leafColor.w);
|
---|
176 |
|
---|
177 |
|
---|
178 | //leafColor = (tex2D(orderFrontBack,texCoord).w > 0.0) ? tex2D(leaf,coords) : 0.0;
|
---|
179 | // LIGHT DIRECTION DEBUG...
|
---|
180 | //if (lightVec.z > 0.5)
|
---|
181 | //{
|
---|
182 | // leafColor = float4(1.0,0.0,0.0,leafColor.w);
|
---|
183 | //}
|
---|
184 | //else
|
---|
185 | //{
|
---|
186 | // leafColor = float4(0.0,0.0,1.0,leafColor.w);
|
---|
187 | //}
|
---|
188 | // CAMERA DIRECTION DEBUG...
|
---|
189 | //leafColor = float4(lightVecNormalMapping.xyz,leafColor.w);
|
---|
190 | // AMBIENT DEGUB....
|
---|
191 | //leafColor = float4(Ka * gambient.xyz * leafColor.xyz,leafColor.w);
|
---|
192 | ocolor = leafColor;
|
---|
193 | return ocolor;
|
---|
194 | }
|
---|
195 |
|
---|