- Timestamp:
- 10/03/08 14:35:07 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r2989 r2999 38 38 { 39 39 float4 col: COLOR0; 40 float4 pos: COLOR1; 40 //float4 pos: COLOR1; 41 float2 pos: COLOR1; 41 42 float4 norm: COLOR2; 42 43 }; … … 65 66 66 67 68 // bilinear interpolation 69 inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 70 { 71 float3 x1 = lerp(bl, tl, w.y); 72 float3 x2 = lerp(br, tr, w.y); 73 float3 v = lerp(x1, x2, w.x); 74 75 return v; 76 } 77 78 67 79 pixel fragtex(fragin IN, 68 80 uniform sampler2D dirtTex, 69 81 uniform float maxDepth, 70 82 uniform sampler2D tex, 71 uniform float3 currentPos) 83 uniform float3 eyePos, 84 uniform float3 bl, 85 uniform float3 br, 86 uniform float3 tl, 87 uniform float3 tr) 72 88 { 89 float4 texColor = tex2D(tex, IN.texCoord.xy); 90 91 // account for alpha blending 92 if (texColor.w < 0.5f) discard; 93 73 94 pixel pix; 74 75 float4 texColor = tex2D(tex, IN.texCoord.xy);76 95 77 96 // save color in first render target 78 97 // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term) 79 98 pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor; 80 99 81 100 // save world position in second render target 82 pix.pos = IN.worldPos * maxDepth;101 //pix.pos = IN.worldPos * maxDepth; 83 102 // save world space normal in third rt 84 103 pix.norm.xyz = IN.normal; … … 86 105 // store projection coordinates with positions (used for ssao) 87 106 pix.norm.w = IN.projPos.w; 88 // write the depth89 pix.pos.w = IN.mypos.z / IN.mypos.w;90 107 91 // account for alpha blending 92 if (pix.col.w < 0.5f) 93 discard; 108 const float4 projPos = IN.mypos / IN.mypos.w; 109 // store the projected depth 110 pix.pos.y = projPos.z; 111 112 float2 screenCoord = projPos.xy * 0.5f + 0.5f; 113 const float magView = length(Interpol(screenCoord, bl, br, tl, tr)); 94 114 95 115 // hack: squeeze some information about ambient into the texture 96 116 //pix.col.w = glstate.material.emission.x; 97 pix.col.w = length(currentPos - IN.worldPos) * maxDepth; 117 118 // eye linear depth 119 pix.col.w = (length(eyePos - IN.worldPos.xyz) * maxDepth) / magView; 120 pix.pos.x = pix.col.x; 98 121 99 122 return pix; … … 101 124 102 125 103 pixel frag(fragin IN, uniform float maxDepth, uniform float3 currentPos) 126 pixel frag(fragin IN, 127 uniform float maxDepth, 128 uniform float3 eyePos, 129 uniform float3 bl, 130 uniform float3 br, 131 uniform float3 tl, 132 uniform float3 tr) 104 133 { 105 134 pixel pix; … … 107 136 // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term) 108 137 pix.col = glstate.material.diffuse + glstate.material.emission; 109 pix.pos = IN.worldPos * maxDepth;138 //pix.pos = IN.worldPos * maxDepth; 110 139 111 140 pix.norm.xyz = IN.normal; … … 113 142 // store projection coordinates with positions (used for ssao) 114 143 pix.norm.w = IN.mypos.w; 115 // the projected depth 116 pix.pos.w = IN.mypos.z / IN.mypos.w; 117 144 145 const float4 projPos = IN.mypos / IN.mypos.w; 146 // store the projected depth 147 pix.pos.y = projPos.z; 148 149 float2 screenCoord = projPos.xy * 0.5f + 0.5f; 150 const float magView = length(Interpol(screenCoord, bl, br, tl, tr)); 151 118 152 // hack: squeeze some information about the ambient term into the target 119 153 //pix.col.w = glstate.material.emission.x; 120 pix.col.w = length(currentPos - IN.worldPos) * maxDepth; 154 pix.col.w = (length(eyePos - IN.worldPos.xyz) * maxDepth) / magView; 155 pix.pos.x = pix.col.x; 121 156 122 157 return pix;
Note: See TracChangeset
for help on using the changeset viewer.