source: GTP/trunk/App/Demos/Illum/IBRBillboardCloudTrees/OGRE/IBRTreesOGRE/media/general/v_lighting_indirect_texture_mapping.cg.bak @ 1493

Revision 1493, 2.9 KB checked in by igarcia, 18 years ago (diff)
Line 
1// Define inputs from application.
2struct VertexIn
3{
4  float4 position    : POSITION;   // Vertex in object-space
5  float4 normal      : NORMAL;     // Vertex's Normal
6  float2 subTexCoord : TEXCOORD0;  // Vertex's Texture Coordinates
7  float3 color       : COLOR0;
8};
9
10// Define outputs from vertex shader.
11struct Vertex
12{
13  float4 position       : POSITION;     // Vertex position in screen-space
14  float2 texCoord       : TEXCOORD0;    // Vertex texture coordinates
15  float2 subTexCoord    : TEXCOORD1;    // Vertex texture coordinates
16  float3 normal         : TEXCOORD2;    // Normal in eye-space
17  float3 halfVector     : TEXCOORD3;    // Half angle vector in eye space
18  float3 lightVector    : TEXCOORD4;    // Light vector in eye space
19  float4 wposition      : TEXCOORD5;    // Vertex position in world-space
20  float3 color          : COLOR0;
21
22#ifdef SHADOW_MAP
23  float4 lightPosition  : TEXCOORD6;    // Vertex position in light space
24
25#endif
26};
27
28Vertex main(VertexIn p_In,
29            uniform float4x4 p_ModelViewProjection, // Model view projection matrix
30            uniform float4 p_LightPosition,         // Light position in object-space
31            uniform float4x4 p_ModelView,           // Model view matrix
32            uniform float4x4 p_InverseModelView,    // Model view matrix inverted
33            uniform float4x4 p_Model                // Model matrix
34
35            #ifdef SHADOW_MAP
36              , uniform float4x4 p_TextureViewProjection  // Texture view projection matrix
37            #endif
38            )
39{
40    Vertex l_Out;
41
42    // Compute light position in eye-space
43    float4 l_LightPosition4 = mul(p_ModelView, p_LightPosition);
44    float3 l_LightPosition3 = l_LightPosition4.xyz;
45   
46    // Compute vertex position in eye-space
47    float4 l_Position4 = mul(p_ModelView, p_In.position);
48    float3 l_Position3 = l_Position4.xyz / l_Position4.w;
49   
50    // Transform normal from model-space to eye-space.
51    l_Out.normal = normalize(mul(transpose(p_InverseModelView), p_In.normal).xyz);
52   
53    // Light vector.
54    l_Out.lightVector = l_LightPosition3 - (l_Position3 * l_LightPosition4.w);
55   
56    // Half angle vector = light vector + eye vector
57    l_Out.halfVector = l_Out.lightVector + (- l_Position3);
58
59    // Compute vertex position in light space
60    // First object to world space
61    l_Out.wposition = mul(p_Model, float4(0.0, 0.0, 0.0, 1.0));
62
63#ifdef SHADOW_MAP
64    // Then world to light space
65    l_Out.lightPosition = mul(p_Model, p_In.position);
66    l_Out.lightPosition = mul(p_TextureViewProjection, l_Out.lightPosition);   
67#endif
68
69    // Transform vertex position into homogenous screen-space.
70    l_Out.position = mul(p_ModelViewProjection, p_In.position);
71
72    // Pass texture coordinates to fragment shader
73    l_Out.subTexCoord = p_In.subTexCoord;
74    l_Out.texCoord = p_In.color.xy;
75
76    l_Out.color = p_In.color;
77
78    return l_Out;
79}
Note: See TracBrowser for help on using the repository browser.