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

Revision 2834, 2.1 KB checked in by mattausch, 16 years ago (diff)

research version: implemented temporal smoothing and color bleeding

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  // hack: squeeze some information about ambient into the texture
81  pix.norm.w = ambient.x;
82  // hack: store projection coordinate for scaling ssao
83  pix.pos.w = IN.projPos.w;
84  pix.col.w = IN.mypos.z / IN.mypos.w;
85
86  return pix;
87}
88
89
90pixel frag(fragin IN,
91           uniform float maxDepth,
92           uniform float4 ambient,
93           uniform float4 diffuse)
94{
95  pixel pix;
96     
97  pix.col = diffuse;
98  pix.pos = IN.worldPos * maxDepth;
99  pix.norm.xyz = IN.normal * 0.5f + float3(0.5f);
100  // hack: squeeze some information about ambient into the texture
101  pix.norm.w = ambient.x;
102  pix.pos.w = IN.mypos.w; //IN.projPos.w;
103  pix.col.w = IN.mypos.z / IN.mypos.w;
104
105  return pix;
106}
Note: See TracBrowser for help on using the repository browser.