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

Revision 3168, 3.5 KB checked in by mattausch, 16 years ago (diff)

removed bug (second aa output), normsl normalization now during mrt output

RevLine 
[3004]1// input
2struct vtxin
3{
4  float4 position: POSITION;
[3045]5  float4 normal: NORMAL;
[3004]6  float4 color: COLOR0;
7  float4 texCoord: TEXCOORD0;
8};
9
[3041]10
[3004]11// vtx output
12struct vtxout
13{
[3041]14        float4 position: POSITION;
15        float4 texCoord: TEXCOORD0;   
[3004]16
[3041]17        float4 color: COLOR0; 
[3117]18         // eye position
19        float4 eyePos: TEXCOORD1;
[3045]20        float4 normal: TEXCOORD2;
[3113]21        float4 worldPos: TEXCOORD3;
22        float4 oldWorldPos: TEXCOORD4;
[3004]23};
24
25
26// fragment input
27struct fragin
28{
29        float4 color: COLOR0; 
30        float4 texCoord: TEXCOORD0;   
31
[3017]32        float4 winPos: WPOS;
[3117]33        // eye position
34        float4 eyePos: TEXCOORD1;
[3045]35        float4 normal: TEXCOORD2;
[3113]36        float4 worldPos: TEXCOORD3;
37        float4 oldWorldPos: TEXCOORD4;
[3004]38};
39
40
41struct pixel
42{
[3005]43        float4 col: COLOR0;
[3017]44        float3 norm: COLOR1;
[3113]45        float3 offsVec: COLOR2;
[3004]46};
47
[3034]48
[3092]49#pragma position_invariant vtx
[3004]50
[3113]51vtxout vtx(vtxin IN,
52                   uniform float4x4 viewMatrix,
53                   uniform float4x4 modelMatrix,
54                   uniform float4x4 oldModelMatrix)
[3004]55{
56        vtxout OUT;
57
58        OUT.color = IN.color;
59        OUT.texCoord = IN.texCoord;
60
61        // transform the vertex position into eye space
[3034]62        OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position);
63        // transform the vertex position into post projection space
[3004]64        OUT.position = mul(glstate.matrix.mvp, IN.position);
[3113]65        // transform the old vertex position into world space
66        OUT.worldPos = mul(modelMatrix, IN.position);
67        // transform the old vertex position into world space
68        OUT.oldWorldPos = mul(oldModelMatrix, IN.position);
[3118]69        // the normal has to be correctly transformed with the inverse transpose
70        OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal);
[3136]71        //OUT.normal = IN.normal;
[3118]72
[3004]73        return OUT;
74}
75
76
77pixel fragtex(fragin IN,
[3126]78                          uniform sampler2D tex: TEXUNIT0,
[3045]79                          uniform float4x4 viewMatrix
[3004]80                          )
81{
82        float4 texColor = tex2D(tex, IN.texCoord.xy);
83
84        // account for alpha blending
85        if (texColor.w < 0.5f) discard;
86
87        pixel pix;
88
89        // save color in first render target
90        // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term)
91        pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor;
[3045]92        // save world space normal in rt => transform back into world space by
93        // multiplying with inverse view. since transforming normal with T means to
[3113]94        // multiply with the inverse transpose of T, we multiple with
95        // Transp(Inv(Inv(view))) = Transp(view)
[3168]96        pix.norm = normalize(mul(transpose(viewMatrix), IN.normal).xyz);
[3136]97        //pix.norm = IN.normal.xyz;
[3041]98        // compute eye linear depth
99        pix.col.w = length(IN.eyePos.xyz);
[3113]100
[3110]101        // the scene entity id
[3113]102        //pix.id = glstate.fog.color.xyz;
103        // the offset to the world pos from old frame
104        pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.xyz;
[3004]105
106        return pix;
107}
108
109
[3046]110pixel frag(fragin IN, uniform float4x4 viewMatrix)
[3004]111{
112        pixel pix;
113        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
114        pix.col = glstate.material.diffuse + glstate.material.emission;
[3045]115        // save world space normal in rt => transform back into world space by
116        // multiplying with inverse view. since transforming normal with T means to
117        // multiply with the inverse transpose of T, we multiple with Transp(Inv(Inv(view))) = Transp(view)
[3168]118        pix.norm = normalize(mul(transpose(viewMatrix), IN.normal).xyz);
[3136]119        //pix.norm = IN.normal.xyz;
[3041]120        // eye space depth
[3034]121        pix.col.w = length(IN.eyePos.xyz);
[3110]122        // the scene entity id
[3113]123        //pix.id = glstate.fog.color.xyz;
124        // the offset to the world pos from old frame
125        pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.xyz;
126
[3004]127        return pix;
[2928]128}
Note: See TracBrowser for help on using the repository browser.