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

Revision 2964, 2.7 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        float3 normal: TEXCOORD2;
33        float4 mypos: TEXCOORD3;
34};
35
36
37struct pixel
38{
39  float4 col: COLOR0;
40  float4 pos: COLOR1;
41  float4 norm: COLOR2;
42};
43
44#pragma position_invariant vtx
45
46vtxout vtx(vtxin IN,
47                   const uniform float4x4 ModelViewProj,
48                   uniform float4x4 ModelView)
49{
50        vtxout OUT;
51
52        OUT.color = IN.color;
53        OUT.texCoord = IN.texCoord;
54
55        //OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position);
56        OUT.worldPos = mul(ModelView, IN.position);
57        // transform the vertex position into eye space
58        OUT.position = mul(glstate.matrix.mvp, IN.position);
59
60        OUT.normal = IN.normal;
61        OUT.mypos = OUT.position;
62
63        return OUT;
64}
65
66
67pixel fragtex(fragin IN,
68                          uniform sampler2D dirtTex,
69                          uniform float maxDepth,
70                          uniform sampler2D tex)
71{
72        pixel pix;
73
74        //float4 dirtTexColor = tex2D(dirtTex, IN.texCoord.xy);
75        float4 texColor = tex2D(tex, IN.texCoord.xy);
76
77        // save color in first render target
78        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
79        //pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor * dirtTexColor;
80        pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor;
81       
82        // save world position in second render target
83        pix.pos = IN.worldPos * maxDepth;
84        // save normal in third rt
85        pix.norm.xyz = IN.normal;
86
87        // hack: squeeze some information about ambient into the texture
88        pix.norm.w = glstate.material.emission.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{
106        pixel pix;
107
108        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
109        pix.col = glstate.material.diffuse + glstate.material.emission;
110        pix.pos = IN.worldPos * maxDepth;
111
112        pix.norm.xyz = IN.normal;
113       
114        // hack: squeeze some information about the ambient term into the target
115        pix.norm.w = glstate.material.emission.x;
116        pix.pos.w = IN.mypos.w;
117       
118        // the projected depth
119        pix.col.w = IN.mypos.z / IN.mypos.w;
120
121        return pix;
122}
Note: See TracBrowser for help on using the repository browser.