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)
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,
[2964]68                          uniform sampler2D dirtTex,
69                          uniform float maxDepth,
70                          uniform sampler2D tex)
[2810]71{
[2865]72        pixel pix;
[2836]73
[2964]74        //float4 dirtTexColor = tex2D(dirtTex, IN.texCoord.xy);
75        float4 texColor = tex2D(tex, IN.texCoord.xy);
76
[2866]77        // save color in first render target
[2960]78        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
[2964]79        //pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor * dirtTexColor;
80        pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor;
[2867]81       
[2951]82        // save world position in second render target
[2865]83        pix.pos = IN.worldPos * maxDepth;
[2866]84        // save normal in third rt
[2867]85        pix.norm.xyz = IN.normal;
[2836]86
[2865]87        // hack: squeeze some information about ambient into the texture
[2960]88        pix.norm.w = glstate.material.emission.x;
[2866]89        // store projection coordinates with positions (used for ssao)
[2865]90        pix.pos.w = IN.projPos.w;
[2836]91
[2865]92        // account for alpha blending
93        if (pix.col.w < 0.5f)
94                discard;
[2810]95
[2865]96        // write the depth
97        pix.col.w = IN.mypos.z / IN.mypos.w;
98
99        return pix;
[2810]100}
[2819]101
102
[2822]103pixel frag(fragin IN,
[2960]104                   uniform float maxDepth)
[2819]105{
[2865]106        pixel pix;
[2819]107
[2960]108        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
109        pix.col = glstate.material.diffuse + glstate.material.emission;
[2865]110        pix.pos = IN.worldPos * maxDepth;
[2873]111
[2867]112        pix.norm.xyz = IN.normal;
[2873]113       
[2867]114        // hack: squeeze some information about the ambient term into the target
[2960]115        pix.norm.w = glstate.material.emission.x;
[2865]116        pix.pos.w = IN.mypos.w;
[2873]117       
118        // the projected depth
[2865]119        pix.col.w = IN.mypos.z / IN.mypos.w;
120
121        return pix;
[2928]122}
Note: See TracBrowser for help on using the repository browser.