- Timestamp:
- 07/09/09 10:21:25 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3372 r3375 39 39 float4 outColor; 40 40 41 #if 041 #if 1 42 42 // hack: prevent to shade the sky 43 43 if (color.w > DEPTH_THRESHOLD) … … 47 47 else 48 48 { 49 if (useAO > .5f) 50 outColor = (ambient * ao + diffuse) * color; 51 else 52 outColor = (ambient + diffuse) * color; 49 outColor = (useAO > .5f) ? (ambient * ao + diffuse) * color : (ambient + diffuse) * color; 53 50 } 54 51 #else 52 // just output ambient occlusion 55 53 outColor = ao; 56 54 #endif … … 81 79 82 80 OUT.color = col; 81 83 82 // store scaled view vector so wie don't have to normalize for later 84 //OUT.color.w = color.w / length(IN.view); 83 if (0) OUT.color.w = color.w / length(IN.view); 84 85 85 OUT.color.w = color.w; 86 86 … … 150 150 uniform float3 br, 151 151 uniform float3 tl, 152 uniform float3 tr 152 uniform float3 tr, 153 uniform sampler2D aoTex, 154 uniform float useAO 153 155 ) 154 156 { 155 157 pixel OUT; 158 159 float4 ao = 1;//(useAO > .5f) ? tex2Dlod(aoTex, float4(IN.texCoord, 0, 0)) : 1.0f; 156 160 157 161 const float3 normal = tex2D(normals, IN.texCoord.xy); … … 192 196 const float4 ambient = glstate.light[0].ambient; 193 197 // compute shading 194 OUT.color = useShading ? (ambient + diffuse) * color : color; 198 OUT.color = useShading ? (ambient * ao + diffuse) * color : color * ao; 199 195 200 // store scaled view vector from now on so wie don't have to normalize later (e.g., for ssao) 196 //OUT.color.w = color.w / lenView; 201 if (0) OUT.color.w = color.w / lenView; 202 197 203 OUT.color.w = color.w; 198 204 … … 216 222 return color; 217 223 } 218 219 220 /** This shader computes the reprojection and checks221 if the reprojected pixel from last frame is still222 valid in the current frame223 */224 /*inline float2 ComputeInfo(sampler2D oldTex,225 float4 color,226 float3 difVec,227 float2 texCoord,228 float3 viewDir,229 float3 oldEyePos,230 float4x4 modelViewProj,231 float4x4 oldModelViewProj,232 float3 oldbl,233 float3 oldbr,234 float3 oldtl,235 float3 oldtr,236 sampler2D myTex237 )238 {239 // reconstruct position from the eye space depth240 const float eyeSpaceDepth = color.w;241 const float4 worldPos = float4(-viewDir * eyeSpaceDepth, 1.0f);242 243 // compute position from old frame for dynamic objects + translational portion244 const float3 translatedPos = -oldEyePos + worldPos.xyz + difVec;245 246 247 /////////////////248 //-- reproject into old frame and calculate texture position of sample in old frame249 250 // note: the old model view matrix only holds the view orientation part251 float4 backProjPos = mul(oldModelViewProj, float4(translatedPos, 1.0f));252 backProjPos /= backProjPos.w;253 254 // fit from unit cube into 0 .. 1255 const float2 oldTexCoords = backProjPos.xy * .5f + .5f;256 257 // retrieve the sample from the last frame258 const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f));259 const float oldDiff = tex2Dlod(myTex, float4(oldTexCoords, .0f, .0f)).x;260 261 // calculate eye space position of sample in old frame262 const float oldEyeSpaceDepth = oldPixel.w;263 264 // vector from eye pos to old sample265 const float3 oldViewDir = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr);266 const float invLen = 1.0f / length(oldViewDir);267 268 269 // check if the pixel was outside of the frame buffer270 if ((oldTexCoords.x <= .0f) || (oldTexCoords.x >= 1.0f) ||271 (oldTexCoords.y <= .0f) || (oldTexCoords.y >= 1.0f)272 )273 {274 isPixelValid = pixelIsNotValid;275 }276 else if (// check if changed from dynamic to not dynamic object277 (278 // (oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) ||279 (280 (oldEyeSpaceDepth < DEPTH_THRESHOLD) && (projectedEyeSpaceDepth < DEPTH_THRESHOLD) &&281 //(oldDynamic || newDynamic) && // check if we have a dynamic object282 (depthDif > 5e-2f)))//MIN_DEPTH_DIFF)))283 ) // and there is a depth discontinuity284 {285 isPixelValid = pixelCouldBeValid;286 }287 else288 {289 isPixelValid = pixelIsValid;290 }291 292 //isPixelValid = depthDif;293 294 return float3(isPixelValid, abs(oldEyeSpaceDepth - projectedEyeSpaceDepth));295 }296 */297 224 298 225 … … 365 292 const float3 normal = normalize(tex2Dlod(normalsTex, float4(IN.texCoord, 0, 0)).xyz); 366 293 367 // do reprojection and filter out the pixels that are not save368 /* const float2 pValid = PixelValid(oldTex,369 color,370 difVec.xyz,371 IN.texCoord,372 IN.view,373 oldEyePos,374 modelViewProj,375 oldModelViewProj,376 oldbl, oldbr, oldtl, oldtr,377 myTex378 );379 380 pix.color = color;381 pix.color.xy = pValid.xy;382 pix.color.z = color.w;383 */384 294 const float3 translatedPos = 385 295 ComputeTranslatedPos(color, difVec.xyz, IN.view, oldEyePos, oldModelViewProj);
Note: See TracChangeset
for help on using the changeset viewer.