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

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