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

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