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

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