source: GTP/trunk/App/Demos/Illum/IBRBillboardCloudTrees/OGRE/IBRTreesOGRE/media/oldgeneral/tree_idtexturing_spotlight_fp_ATI_9700.shd @ 1493

Revision 1493, 4.6 KB checked in by igarcia, 18 years ago (diff)
Line 
1float3 cameraDirection;
2float shininess;
3float nearDistance;
4float farDistance;
5float tex_atlas_size;
6float scale_factor;
7float3 lDiffuseColor;
8float3 lSpecularColor;
9float3 lattenuation;
10float4 gambient;
11float Ka;
12float Kd;
13float Ks;
14sampler orderFrontBack: register(s0);
15sampler leaf: register(s1);
16sampler shadowMap: register(s6);
17sampler spotLight: register(s2);
18sampler normalMap: register(s3);
19sampler ob_front_face: register(s4);
20sampler ob_back_face: register(s5);
21float shadowBias = 0.0;
22float backProjectionCut = 0.01;
23float exposure;
24float4x4 worldmatrix;
25
26float4 main_fp(float3 normal: TEXCOORD0, float3 lightVec: TEXCOORD1, float3 viewVec: TEXCOORD2, float4 shadowCrd: TEXCOORD3,
27float4 texCoord: TEXCOORD4, float4 texCoordNormalized: TEXCOORD5) : COLOR
28{
29   float4 leafColor;
30   float4 ocolor;
31
32   float2 coords = ((texCoordNormalized - tex2D(orderFrontBack, texCoord).xy) + tex2D(orderFrontBack, texCoord).zw) * 4.0;   
33   normal = normalize(normal);
34   float4 obsColor;
35   float depth = length(lightVec.xyz);
36   lightVec = normalize(lightVec);
37   viewVec = normalize(viewVec);
38   cameraDirection = normalize(-cameraDirection);
39   
40   if (dot(normal.xyz,cameraDirection.xyz) < 0.0)
41   //if (reg < 0.0)
42   {
43          obsColor = float4(tex2D(ob_front_face,texCoord).xxxw);     
44          //obsColor.xyz = obsColor.xyz / obsColor.w;
45      //if (tex2D(ob_front_face,texCoord).x == tex2D(ob_front_face,texCoord).y)
46      //{
47      //        obsColor = float4(1.0,0.0,0.0,1.0);
48          //}
49          //else
50          //{
51          //    obsColor = float4(0.0,0.0,1.0,1.0);     
52          //}     
53   }
54   else
55   {
56         obsColor = float4(tex2D(ob_front_face,texCoord).yyyw); 
57         //obsColor.xyz = obsColor.xyz / obsColor.w;     
58     //if (tex2D(ob_front_face,texCoord).x == tex2D(ob_front_face,texCoord).y)
59     //{
60         //     obsColor = float4(1.0,1.0,0.0,1.0);
61         //}
62         //else
63         //{
64         //     obsColor = float4(0.0,1.0,1.0,1.0);     
65         //}     
66   }
67     
68   if (dot(normal.xyz,cameraDirection.xyz) < 0.0)
69   //if (reg < 0.0)
70   {
71     normal = -normal;     
72   }
73     
74   float lDiffuseAttenuation = max(dot(lightVec,normal),0.0);
75   float lSpecularAttenuation = pow(max(dot(reflect(-normalize(viewVec),normal),lightVec),0.0),shininess);
76   float4 shadowMapValue = tex2Dproj(shadowMap,shadowCrd).xyzw;
77   float spotLight = tex2Dproj(spotLight,shadowCrd);
78   // If the depth is larger than the stored depth, this fragment
79   // is not the closest to the light, that is we are in shadow.
80   // Otherwise, we're lit. Add a bias to avoid precision issues.
81   float shadow = tex2Dproj(shadowMap, shadowCrd).w - 500 < (depth - 0.0) ? 0.1f : 1.0f;
82   // Cut back-projection, that is, make sure we don't lit
83   // anything behind the light. Theoretically, you should just
84   // cut at w = 0, but in practice you'll have to cut at a
85   // fairly high positive number to avoid precision issue when
86   // coordinates approaches zero.
87   shadow *= (shadowCrd.w > backProjectionCut);
88   //shadow *= spotLight;
89   
90   // Leaf lookup
91   leafColor = (tex2D(orderFrontBack,texCoord).w > 0.0) ? tex2D(leaf,coords + float2(-0.025,0.025)) : 0.0;
92   //leafColor = (tex2D(ob_front_face,texCoord*512).y > 0.0) ? tex2D(leaf,coords + float2(-0.025,0.025)) : 0.0;
93
94   leafColor =  float4(0.0,0.0,0.0,leafColor.w)
95                +  float4(Ka * gambient.xyz * leafColor.xyz,0.0)
96                ////+ float4(Kd * lDiffuseAttenuation * leafColor.xyz * lDiffuseColor,0.0);
97                + float4(Kd * lDiffuseAttenuation * leafColor.xyz * lDiffuseColor,0.0)
98                //+ float4(Ks * lSpecularAttenuation * lSpecularColor,0.0);
99                + float4(Ks * lSpecularAttenuation * leafColor.xyz * lSpecularColor,0.0);
100
101   // LIGHT DIRECTION DEBUG...
102   //if (lightVec.z > 0.5)
103   //{
104   //   leafColor = float4(1.0,0.0,0.0,leafColor.w);
105   //}
106   //else
107   //{
108   //   leafColor = float4(0.0,0.0,1.0,leafColor.w);
109   //}
110   // CAMERA DIRECTION DEBUG...
111   //leafColor = float4(lightVecNormalMapping.xyz,leafColor.w);
112   // AMBIENT DEGUB....
113   //leafColor = float4(Ka * gambient.xyz * leafColor.xyz,leafColor.w);
114   // DIFFUSE COLOUR DEBUG...
115   //leafColor  = float4(lDiffuseColor.xyz,leafColor.w);
116   // DIFFUSE COLOUR DEBUG...
117   //leafColor  = float4(Kd.xxx,leafColor.w);
118   // DIFFUSE
119   //leafColor = float4(Kd * (lDiffuseAttenuation) * leafColor.xyz * lDiffuseColor,leafColor.w);
120   // SPECULAR
121   //leafColor = float4(Ks * (lSpecularAttenuation) * leafColor.xyz * lSpecularColor,leafColor.w);
122   // SHADOW
123   //leafColor = float4(shadow.xxx,leafColor.w);
124   leafColor = float4((1.0 - exp(exposure * obsColor.xyz)),leafColor.w);
125   ocolor = leafColor;
126   return  ocolor;
127}
128
Note: See TracBrowser for help on using the repository browser.