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

Revision 2951, 2.4 KB checked in by mattausch, 16 years ago (diff)

strted to implement animation

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};
37
38
39struct pixel
40{
41  float4 col: COLOR0;
42  float4 pos: COLOR1;
43  float4 norm: COLOR2;
44};
45
46#pragma position_invariant vtx
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   OUT.position = mul(glstate.matrix.mvp, IN.position);
63
64   OUT.normal = IN.normal;
65
66   OUT.mypos = OUT.position;
67
68   return OUT;
69}
70
71
72pixel fragtex(fragin IN,
73                          uniform sampler2D tex,
74                          uniform float maxDepth,
75                          uniform float4 ambient,
76                          uniform float4 diffuse)
77{
78        pixel pix;
79
80        // save color in first render target
81        pix.col = (ambient + diffuse) * tex2D(tex, IN.texCoord.xy);
82       
83        // save world position in second render target
84        pix.pos = IN.worldPos * maxDepth;
85        // save normal in third rt
86        pix.norm.xyz = IN.normal;
87
88        // hack: squeeze some information about ambient into the texture
89        pix.norm.w = ambient.x;
90        // store projection coordinates with positions (used for ssao)
91        pix.pos.w = IN.projPos.w;
92
93        // account for alpha blending
94        if (pix.col.w < 0.5f)
95                discard;
96
97        // write the depth
98        pix.col.w = IN.mypos.z / IN.mypos.w;
99
100        return pix;
101}
102
103
104pixel frag(fragin IN,
105                   uniform float maxDepth,
106                   uniform float4 ambient,
107                   uniform float4 diffuse
108                   )
109{
110        pixel pix;
111
112        pix.col = diffuse;
113        pix.pos = IN.worldPos * maxDepth;
114
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.