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

Revision 1546, 2.5 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
23Vertex main(VertexIn p_In,
24            uniform float4x4 p_ModelViewProjection, // Model view projection matrix
25            uniform float4 p_LightPosition,         // Light position in object-space
26            uniform float4x4 p_ModelView,           // Model view matrix
27            uniform float4x4 p_InverseModelView,    // Model view matrix inverted
28            uniform float4x4 p_Model                // Model matrix
29            )
30{
31    Vertex l_Out;
32
33    // Compute light position in eye-space
34    float4 l_LightPosition4 = mul(p_ModelView, p_LightPosition);
35    float3 l_LightPosition3 = l_LightPosition4.xyz;
36   
37    // Compute vertex position in eye-space
38    float4 l_Position4 = mul(p_ModelView, p_In.position);
39    float3 l_Position3 = l_Position4.xyz / l_Position4.w;
40   
41    // Transform normal from model-space to eye-space.
42    l_Out.normal = mul(p_Model, p_In.normal);
43    l_Out.normal = normalize(mul(transpose(p_InverseModelView), float4(l_Out.normal,1.0)).xyz);
44   
45    // Light vector.
46    l_Out.lightVector = l_LightPosition3 - (l_Position3 * l_LightPosition4.w);
47   
48    // Half angle vector = light vector + eye vector
49    l_Out.halfVector = l_Out.lightVector + (- l_Position3);
50
51    // Compute vertex position in light space
52    // First object to world space
53    l_Out.wposition = mul(p_Model, float4(0.0, 0.0, 0.0, 1.0));
54
55    // Transform vertex position into homogenous screen-space.
56    l_Out.position = mul(p_ModelViewProjection, p_In.position);
57
58    // Pass texture coordinates to fragment shader
59    l_Out.subTexCoord = p_In.subTexCoord;
60    l_Out.texCoord = p_In.color.xy;
61
62    l_Out.color = p_In.color;
63
64    return l_Out;
65}
Note: See TracBrowser for help on using the repository browser.