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

Revision 2960, 2.5 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  float4 mypos: TEXCOORD3;
20};
21
22
23// fragment input
24struct fragin
25{
26        float4 color: COLOR0; 
27        float4 position: POSITION; // eye space
28        float4 texCoord: TEXCOORD0;   
29
30        float4 projPos: WPOS;
31        float4 worldPos: TEXCOORD1; // world position
32        float3 normal: TEXCOORD2;
33        float4 mypos: TEXCOORD3;
34};
35
36
37struct pixel
38{
39  float4 col: COLOR0;
40  float4 pos: COLOR1;
41  float4 norm: COLOR2;
42};
43
44#pragma position_invariant vtx
45
46vtxout vtx(vtxin IN,
47                   const uniform float4x4 ModelViewProj,
48                   uniform float4x4 ModelView)
49{
50        vtxout OUT;
51
52        OUT.color = IN.color;
53        OUT.texCoord = IN.texCoord;
54
55        //OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position);
56        OUT.worldPos = mul(ModelView, IN.position);
57        // transform the vertex position into eye space
58        OUT.position = mul(glstate.matrix.mvp, IN.position);
59
60        OUT.normal = IN.normal;
61        OUT.mypos = OUT.position;
62
63        return OUT;
64}
65
66
67pixel fragtex(fragin IN,
68                          uniform sampler2D tex,
69                          uniform float maxDepth)
70{
71        pixel pix;
72
73        // save color in first render target
74        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
75        pix.col = (glstate.material.emission + glstate.material.diffuse) * tex2D(tex, IN.texCoord.xy);
76       
77        // save world position in second render target
78        pix.pos = IN.worldPos * maxDepth;
79        // save normal in third rt
80        pix.norm.xyz = IN.normal;
81
82        // hack: squeeze some information about ambient into the texture
83        pix.norm.w = glstate.material.emission.x;
84        // store projection coordinates with positions (used for ssao)
85        pix.pos.w = IN.projPos.w;
86
87        // account for alpha blending
88        if (pix.col.w < 0.5f)
89                discard;
90
91        // write the depth
92        pix.col.w = IN.mypos.z / IN.mypos.w;
93
94        return pix;
95}
96
97
98pixel frag(fragin IN,
99                   uniform float maxDepth)
100{
101        pixel pix;
102
103        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
104        pix.col = glstate.material.diffuse + glstate.material.emission;
105        pix.pos = IN.worldPos * maxDepth;
106
107        pix.norm.xyz = IN.normal;
108       
109        // hack: squeeze some information about the ambient term into the target
110        pix.norm.w = glstate.material.emission.x;
111        pix.pos.w = IN.mypos.w;
112       
113        // the projected depth
114        pix.col.w = IN.mypos.z / IN.mypos.w;
115
116        return pix;
117}
Note: See TracBrowser for help on using the repository browser.