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

Revision 2851, 2.2 KB checked in by mattausch, 16 years ago (diff)

using sample_to_coverage instead of alpha

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