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

Revision 3045, 2.7 KB checked in by mattausch, 16 years ago (diff)
Line 
1// input
2struct vtxin
3{
4  float4 position: POSITION;
5  float4 normal: NORMAL;
6  float4 color: COLOR0;
7  float4 texCoord: TEXCOORD0;
8};
9
10
11// vtx output
12struct vtxout
13{
14        float4 position: POSITION;
15        float4 texCoord: TEXCOORD0;   
16
17        float4 color: COLOR0; 
18        float4 eyePos: TEXCOORD1; // eye position
19        float4 normal: TEXCOORD2;
20};
21
22
23// fragment input
24struct fragin
25{
26        float4 color: COLOR0; 
27        //float4 position: POSITION;
28        float4 texCoord: TEXCOORD0;   
29
30        float4 winPos: WPOS;
31        float4 eyePos: TEXCOORD1; // eye position
32        float4 normal: TEXCOORD2;
33};
34
35
36struct pixel
37{
38        float4 col: COLOR0;
39        float3 norm: COLOR1;
40        float3 pos: COLOR2;
41};
42
43
44#pragma position_invariant vtx
45
46vtxout vtx(vtxin IN)
47{
48        vtxout OUT;
49
50        OUT.color = IN.color;
51        OUT.texCoord = IN.texCoord;
52
53        // transform the vertex position into eye space
54        OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position);
55        // transform the vertex position into post projection space
56        OUT.position = mul(glstate.matrix.mvp, IN.position);
57
58        OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal);
59
60        return OUT;
61}
62
63
64pixel fragtex(fragin IN,
65                          uniform sampler2D tex,
66                          uniform float4x4 viewMatrix
67                          )
68{
69        float4 texColor = tex2D(tex, IN.texCoord.xy);
70
71        // account for alpha blending
72        if (texColor.w < 0.5f) discard;
73
74        pixel pix;
75
76        // save color in first render target
77        // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term)
78        pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor;
79        // save world space normal in rt => transform back into world space by
80        // multiplying with inverse view. since transforming normal with T means to
81        // multiply with the inverse transpose of T, we multiple with Transp(Inv(Inv(view))) = Transp(view)
82        pix.norm = mul(transpose(viewMatrix), IN.normal);
83        // compute eye linear depth
84        pix.col.w = length(IN.eyePos.xyz);
85        // hack: squeeze some information about ambient into the texture
86        //pix.col.w = glstate.material.emission.x;
87
88        return pix;
89}
90
91
92pixel frag(fragin IN,  uniform float4x4 viewMatrix)
93{
94        pixel pix;
95        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
96        pix.col = glstate.material.diffuse + glstate.material.emission;
97        // save world space normal in rt => transform back into world space by
98        // multiplying with inverse view. since transforming normal with T means to
99        // multiply with the inverse transpose of T, we multiple with Transp(Inv(Inv(view))) = Transp(view)
100        pix.norm = mul(transpose(viewMatrix), IN.normal);
101        // eye space depth
102        pix.col.w = length(IN.eyePos.xyz);
103        // hack: squeeze some information about the ambient term into the target
104        //pix.col.w = glstate.material.emission.x;
105
106        return pix;
107}
Note: See TracBrowser for help on using the repository browser.