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

Revision 3034, 2.2 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 eyePos: TEXCOORD1; // eye position
18  float3 normal: TEXCOORD2;
19};
20
21
22// fragment input
23struct fragin
24{
25        float4 color: COLOR0; 
26        //float4 position: POSITION;
27        float4 texCoord: TEXCOORD0;   
28
29        float4 winPos: WPOS;
30        float4 eyePos: TEXCOORD1; // eye position
31        float3 normal: TEXCOORD2;
32};
33
34
35struct pixel
36{
37        float4 col: COLOR0;
38        float3 norm: COLOR1;
39        float3 pos: COLOR2;
40};
41
42
43#pragma position_invariant vtx
44
45vtxout vtx(vtxin IN)
46{
47        vtxout OUT;
48
49        OUT.color = IN.color;
50        OUT.texCoord = IN.texCoord;
51
52        // transform the vertex position into eye space
53        OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position);
54        // transform the vertex position into post projection space
55        OUT.position = mul(glstate.matrix.mvp, IN.position);
56
57        OUT.normal = IN.normal;
58
59        return OUT;
60}
61
62//#pragma position_invariant fragtex
63
64pixel fragtex(fragin IN,
65                          uniform sampler2D tex
66                          )
67{
68        float4 texColor = tex2D(tex, IN.texCoord.xy);
69
70        // account for alpha blending
71        if (texColor.w < 0.5f) discard;
72
73        pixel pix;
74
75        // save color in first render target
76        // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term)
77        pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor;
78        // save world space normal in rt
79        pix.norm = IN.normal;
80
81        // hack: squeeze some information about ambient into the texture
82        //pix.col.w = glstate.material.emission.x;
83
84        // compute eye linear depth
85        pix.col.w = length(IN.eyePos.xyz);
86
87        return pix;
88}
89
90
91pixel frag(fragin IN)
92{
93        pixel pix;
94
95        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
96        pix.col = glstate.material.diffuse + glstate.material.emission;
97
98        pix.norm = IN.normal;
99
100        pix.col.w = length(IN.eyePos.xyz);
101
102        // hack: squeeze some information about the ambient term into the target
103        //pix.col.w = glstate.material.emission.x;
104
105        return pix;
106}
Note: See TracBrowser for help on using the repository browser.