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

Revision 2866, 2.3 KB checked in by mattausch, 16 years ago (diff)

bug: downsampling of positions does not work

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        // save world position in second rt
80        pix.pos = IN.worldPos * maxDepth;
81        // save normal in third rt
82        pix.norm.xyz = IN.normal * 0.5f + 0.5f;
83
84        // hack: squeeze some information about ambient into the texture
85        pix.norm.w = ambient.x;
86        // store projection coordinates with positions (used for ssao)
87        pix.pos.w = IN.projPos.w;
88
89        // account for alpha blending
90        if (pix.col.w < 0.5f)
91                discard;
92
93        // write the depth
94        pix.col.w = IN.mypos.z / IN.mypos.w;
95
96        return pix;
97}
98
99
100pixel frag(fragin IN,
101           uniform float maxDepth,
102           uniform float4 ambient,
103           uniform float4 diffuse)
104{
105        pixel pix;
106
107        pix.col = diffuse;
108        pix.pos = IN.worldPos * maxDepth;
109        pix.norm.xyz = IN.normal * 0.5f + float3(0.5f);
110        // hack: squeeze some information about ambient into the texture
111        pix.norm.w = ambient.x;
112        pix.pos.w = IN.mypos.w;
113        pix.col.w = IN.mypos.z / IN.mypos.w;
114
115        return pix;
116}
Note: See TracBrowser for help on using the repository browser.