source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg @ 3018

Revision 3018, 2.8 KB checked in by mattausch, 16 years ago (diff)
Line 
1// input
2struct vtxin
3{
4  float4 position: POSITION;
5  float3 normal: NORMAL;
6  float4 color: COLOR0;
7  float4 texCoord: TEXCOORD0;
8};
9
10// vtx output
11struct vtxout
12{
13  float4 position: POSITION; // eye space
14  float4 texCoord: TEXCOORD0;   
15
16  float4 color: COLOR0; 
17  float4 worldPos: TEXCOORD1; // world position
18  float3 normal: TEXCOORD2;
19};
20
21
22// fragment input
23struct fragin
24{
25        float4 color: COLOR0; 
26        float4 position: POSITION; // eye space
27        float4 texCoord: TEXCOORD0;   
28
29        float4 winPos: WPOS;
30        float4 worldPos: TEXCOORD1; // world position
31        float3 normal: TEXCOORD2;
32};
33
34
35struct pixel
36{
37        float4 col: COLOR0;
38        float3 norm: COLOR1;
39        float3 pos: COLOR2;
40};
41
42#pragma position_invariant vtx
43
44vtxout vtx(vtxin IN,
45                   const uniform float4x4 ModelViewProj,
46                   uniform float4x4 ModelView)
47{
48        vtxout OUT;
49
50        OUT.color = IN.color;
51        OUT.texCoord = IN.texCoord;
52
53        //OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position);
54        OUT.worldPos = mul(ModelView, IN.position);
55        // transform the vertex position into eye space
56        OUT.position = mul(glstate.matrix.mvp, IN.position);
57
58        OUT.normal = IN.normal;
59
60        return OUT;
61}
62
63
64// bilinear interpolation
65inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr)
66{
67        float3 x1 = lerp(bl, tl, w.y);
68        float3 x2 = lerp(br, tr, w.y);
69        float3 v = lerp(x1, x2, w.x);
70
71        return v;
72}
73
74//#pragma position_invariant fragtex
75
76pixel fragtex(fragin IN,
77                          uniform sampler2D dirtTex,
78                          uniform sampler2D tex,
79                          uniform float3 eyePos,
80                          uniform float3 bl,
81                          uniform float3 br,
82                          uniform float3 tl,
83                          uniform float3 tr
84                          )
85{
86        float4 texColor = tex2D(tex, IN.texCoord.xy);
87
88        // account for alpha blending
89        if (texColor.w < 0.5f) discard;
90
91        pixel pix;
92
93        // save color in first render target
94        // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term)
95        pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor;
96        // save world space normal in rt
97        pix.norm = IN.normal;
98
99        // hack: squeeze some information about ambient into the texture
100        //pix.col.w = glstate.material.emission.x;
101
102        // compute eye linear depth
103        pix.col.w = length(eyePos - IN.worldPos.xyz);
104
105        return pix;
106}
107
108
109pixel frag(fragin IN,
110                   uniform float3 eyePos,
111                   uniform float3 bl,
112                   uniform float3 br,
113                   uniform float3 tl,
114                   uniform float3 tr)
115{
116        pixel pix;
117
118        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
119        pix.col = glstate.material.diffuse + glstate.material.emission;
120
121        pix.norm = IN.normal;
122
123        // hack: squeeze some information about the ambient term into the target
124        //pix.col.w = glstate.material.emission.x;
125        pix.col.w = length(eyePos - IN.worldPos.xyz);
126
127        return pix;
128}
Note: See TracBrowser for help on using the repository browser.