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

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