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

Revision 1493, 3.0 KB checked in by igarcia, 18 years ago (diff)
Line 
1struct VS_OUTPUT {
2   float4 Pos:       POSITION;
3   float3 normal:    TEXCOORD0;
4   float4 lightVec : TEXCOORD1;
5   float3 halfvec: TEXCOORD2;
6   float4 shadowCrd: TEXCOORD3;
7   float2 texCoord:  TEXCOORD4;
8   float2 texCoordNormalized: TEXCOORD5;
9   float4 lightVecNM: TEXCOORD6;
10   float backside: TEXCOORD7;
11};
12
13float distanceScale;
14float4 lattenuation;
15float4 lightPosition;
16float4 lightDirection;
17float4 cameraPosition;
18float4 cameraDirection;
19float4x4 worldviewproj;
20float4x4 worldmatrix;
21float4x4 proj_matrix;
22float time_0_X;
23
24VS_OUTPUT main_vp(
25      float4 position : POSITION,
26      float3 normal : NORMAL,
27      float2 texCoord : TEXCOORD0,
28      float2 texCoordNormalized : TEXCOORD1,
29      float3 inTangent : TEXCOORD2,
30      float3 inBinormal : BINORMAL
31      )
32{
33
34        VS_OUTPUT Out;
35
36        Out.Pos = mul(worldviewproj, position);
37
38        //------------------------------------------------------------
39        // World-space lighting
40        //------------------------------------------------------------
41        // world_pos,lightPosition,
42        float4 world_pos = mul(worldmatrix,position);
43
44        Out.backside = 0.0;
45        normal = mul(worldmatrix,normal);
46       
47        if (dot(normal,cameraDirection) < 0.0)
48        {
49                //normal.xyz = -normal.xyz;
50                Out.backside = 1.0;
51        }
52
53
54        Out.normal = normal;
55        Out.lightVec = lightPosition - world_pos;  // Used for shadow mapping
56        //Out.lightVec = -lightDirection;
57        float dist = length(Out.lightVec.xyz);
58        Out.lightVecNM.xyz = -Out.lightVec.xyz / dist; // For shadow mapping we were using distanceScale
59        Out.lightVecNM.w = clamp(0.0,1.0,1.0 / (lattenuation.x + lattenuation.y * dist + lattenuation.z * dist * dist) );
60
61        // Debugging purpose...
62        normal = mul(worldmatrix,normal);
63        inTangent = mul(worldmatrix,inTangent);
64        inBinormal = mul(worldmatrix,inBinormal);
65
66        float3x3 tangentSpace;
67        // In Ogre3D the TAG BINORMAL and TANGENT are not used...
68        tangentSpace[0] = inTangent;
69        tangentSpace[1] = cross(inTangent,normal.xyz);
70        tangentSpace[2] = normal.xyz;
71
72        float4 oviewVec = normalize(cameraPosition - world_pos);
73       
74        // Converted to Tangent-space
75        Out.halfvec = mul(tangentSpace,normalize(Out.lightVecNM.xyz+oviewVec.xyz));
76        //Out.lightVecNM = float4(mul(tangentSpace,Out.lightVecNM.xyz),Out.lightVecNM.w);
77        Out.lightVecNM = oviewVec;
78
79        Out.texCoord = texCoord;
80        Out.texCoordNormalized = texCoordNormalized;
81
82        //------------------------------------------------------------
83        // Light-space coordinates
84        //------------------------------------------------------------
85        float4 sPos = mul(proj_matrix, position);
86        //float4 sPos = mul(position,proj_matrix);
87        //sPos.z += 10;
88        //Out.shadowCrd.x = 0.5 * (sPos.z + sPos.x);
89        //Out.shadowCrd.y = 0.5 * (sPos.z - sPos.y);
90        //Out.shadowCrd.z = 0;
91        //Out.shadowCrd.w = sPos.z;
92       
93        Out.shadowCrd = sPos;
94       
95        //Out.shadowCrd.x = sPos.x;
96        //Out.shadowCrd.y = 1.0 - sPos.y;
97        //Out.shadowCrd.z = 0.0;
98        //Out.shadowCrd.w = sPos.z;
99
100        //Out.shadowCrd.x = sPos.x;
101        //Out.shadowCrd.y = 1.0 - sPos.y;
102        //Out.shadowCrd.z = 0.0;
103        //Out.shadowCrd.w = sPos.z;
104
105        return Out;
106}
Note: See TracBrowser for help on using the repository browser.