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

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