- Timestamp:
- 10/31/08 15:08:25 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3081 r3084 237 237 mIllumFboIndex(0) 238 238 { 239 // create noise texture for ssao240 CreateNoiseTex2D(w, h);241 242 243 239 /////////// 244 240 //-- the flip-flop fbos … … 258 254 259 255 mFBOs.push_back(mDownSampleFbo); 256 257 // create noise texture for ssao 258 CreateNoiseTex2D(mDownSampleFbo->GetWidth(), mDownSampleFbo->GetHeight()); 260 259 261 260 InitCg(); … … 298 297 sCgSsaoProgram->AddParameter("normals", i ++); 299 298 sCgSsaoProgram->AddParameter("oldTex", i ++); 300 sCgSsaoProgram->AddParameter("noise ", i ++);299 sCgSsaoProgram->AddParameter("noiseTex", i ++); 301 300 sCgSsaoProgram->AddParameter("eyePos", i ++); 302 301 sCgSsaoProgram->AddParameter("temporalCoherence", i ++); … … 312 311 sCgGiProgram->AddParameter("colors", i ++); 313 312 sCgGiProgram->AddParameter("normals", i ++); 314 sCgGiProgram->AddParameter("noise ", i ++);313 sCgGiProgram->AddParameter("noiseTex", i ++); 315 314 sCgGiProgram->AddParameter("oldSsaoTex", i ++); 316 315 sCgGiProgram->AddParameter("oldIllumTex", i ++); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3083 r3084 42 42 #define MAX_LOD_LEVEL 10 43 43 44 #define MIN_DEPTH_DIFF 1e-5f 44 #define MIN_DEPTH_DIFF 1e-6f 45 #define PRECISION_SCALE 1e-3f 46 45 47 // burnout 46 48 #define WHITE_LUMINANCE 3e4f … … 53 55 #define NUM_SSAO_FILTERSAMPLES 100 54 56 55 #define PRECISION_SCALE 1e-3f56 57 57 58 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r3034 r3084 89 89 #if 1 90 90 //////////////////// 91 // add random noise : reflect around random normal vector (warning: slow!)91 // add random noiseTex: reflect around random normal vector (warning: slow!) 92 92 float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy).xy; 93 93 float2 offsetTransformed = myreflect(offset, mynoise); … … 151 151 uniform sampler2D colors, 152 152 uniform sampler2D normals, 153 uniform sampler2D noise ,153 uniform sampler2D noiseTex, 154 154 uniform float2 samples[NUM_SAMPLES], 155 155 uniform sampler2D oldSsaoTex, … … 187 187 currentPos /= currentPos.w; 188 188 189 const float currentDepth = currentPos.z * 1e-3f;189 const float currentDepth = currentPos.z * PRECISION_SCALE; 190 190 191 191 /////////// 192 192 //-- compute color bleeding + ao 193 193 194 GiStruct gi = globIllum(IN, colors, noise , samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(IN.view));194 GiStruct gi = globIllum(IN, colors, noiseTex, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(IN.view)); 195 195 196 196 … … 204 204 205 205 // the current depth projected into the old frame 206 const float projDepth = projPos.z * 1e-3f;206 const float projDepth = projPos.z * PRECISION_SCALE; 207 207 208 208 // fit from unit cube into 0 .. 1 … … 223 223 //const float oldNumSamples = oldSsao.y; 224 224 225 if ( //(temporalCoherence > 0.0f) &&225 if ((temporalCoherence > 1e-6f) && 226 226 (tex.x >= 0.0f) && (tex.x < 1.0f) && 227 227 (tex.y >= 0.0f) && (tex.y < 1.0f) && -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r3046 r3084 61 61 } 62 62 63 #pragma position_invariant fragtex 63 64 64 65 pixel fragtex(fragin IN, … … 90 91 91 92 93 #pragma position_invariant frag 94 92 95 pixel frag(fragin IN, uniform float4x4 viewMatrix) 93 96 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3083 r3084 54 54 float3 bl, float3 br, float3 tl, float3 tr) 55 55 { 56 texcoord.x += 1.0f / 1024.0f; texcoord.y += 1.0f / 768.0f;57 58 //const float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, 0)).w;59 56 const float eyeSpaceDepth = tex2D(colors, texcoord).w; 60 57 float3 viewVec = Interpol(texcoord, bl, br, tl, tr); … … 77 74 uniform float2 samples[NUM_SAMPLES], 78 75 uniform sampler2D colors, 79 uniform sampler2D noiseTex ture,76 uniform sampler2D noiseTex, 80 77 uniform float scaleFactor, 81 78 uniform float3 bl, … … 83 80 uniform float3 tl, 84 81 uniform float3 tr, 85 float2 texcoord0 82 float2 texcoord0, 83 float3 eyePos 86 84 ) 87 85 { … … 92 90 93 91 // reproject into old frame and calculate projected depth 94 float4 backProjPos = mul(oldModelViewProj, worldPos); 92 const float3 dummyPos = ReconstructSamplePos(colors, texcoord0, bl, br, tl, tr) + eyePos; 93 float4 backProjPos = mul(oldModelViewProj, float4(dummyPos, 1.0f)); 94 //float4 backProjPos = mul(oldModelViewProj, worldPos); 95 95 96 backProjPos /= backProjPos.w; 96 97 … … 106 107 107 108 //const float oldNumSamples = oldCol.y; 108 const float oldWeight = clamp(oldCol.y, 0, temporalCoherence);109 const float oldWeight = clamp(oldCol.y, .0f, temporalCoherence); 109 110 float newWeight; 110 111 … … 115 116 const float2 offset = samples[i]; 116 117 117 //////////////////// 118 // add random noise: reflect around random normal vector (warning: slow!) 119 120 float2 mynoise = tex2D(noiseTexture, texcoord0).xy; 118 float2 mynoise = tex2D(noiseTex, texcoord0).xy; 121 119 const float2 offsetTransformed = myreflect(offset, mynoise); 122 120 123 const float2 texCoord = texcoord0 + offsetTransformed * scaleFactor;124 const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr) ;121 const float2 texCoord = texcoord0;// + offsetTransformed * scaleFactor; 122 const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr) + eyePos; 125 123 126 124 // reproject into old frame and calculate projected depth … … 136 134 137 135 if (abs(dDiff) > 1e-5f) isValid = false; 138 //if (oldSample.y < oldWeight) isValid = false;139 136 } 140 137 … … 142 139 //const float newNumSamples = ao.y; 143 140 144 if ((temporalCoherence > 0)141 if ((temporalCoherence > 1e-6f) 145 142 && (tex.x >= 0.0f) && (tex.x < 1.0f) 146 143 && (tex.y >= 0.0f) && (tex.y < 1.0f) 147 //&& (abs(depthDif) <MIN_DEPTH_DIFF)144 && (abs(depthDif) <= MIN_DEPTH_DIFF) 148 145 // if visibility changed in the surrounding area we have to recompute 149 146 //&& (oldNumSamples > 0.8f * newNumSamples) … … 161 158 newWeight = .0f; 162 159 } 163 160 161 //isValid = 0.0f; 162 //illum_col.y = isValid / 16.0f; 164 163 illum_col.y = newWeight; 165 164 illum_col.z = currentDepth; … … 173 172 float2 ssao(fragment IN, 174 173 uniform sampler2D colors, 175 uniform sampler2D noiseTex ture,174 uniform sampler2D noiseTex, 176 175 uniform float2 samples[NUM_SAMPLES], 177 176 uniform float3 currentNormal, … … 189 188 // Summing up these angles gives an estimation of the occlusion at the current position. 190 189 191 float total_ao = 0.0;192 float numSamples = 0;190 float total_ao = .0f; 191 float numSamples = .0f; 193 192 194 193 … … 199 198 #if 1 200 199 //////////////////// 201 // add random noise: reflect around random normal vector (warning:slow!)202 203 float2 mynoise = tex2D(noiseTex ture, IN.texCoord).xy;200 //-- add random noise: reflect around random normal vector (rather slow!) 201 202 float2 mynoise = tex2D(noiseTex, IN.texCoord).xy; 204 203 const float2 offsetTransformed = myreflect(offset, mynoise); 205 204 #else … … 250 249 uniform sampler2D colors, 251 250 uniform sampler2D normals, 252 uniform sampler2D noise ,251 uniform sampler2D noiseTex, 253 252 uniform float2 samples[NUM_SAMPLES], 254 253 uniform sampler2D oldTex, … … 280 279 float4 projPos = mul(modelViewProj, worldPos); 281 280 282 const float w = SAMPLE_RADIUS / projPos.w; 283 projPos /= projPos.w; 281 float w = 1.0f / projPos.w; 282 projPos *= w; 283 w *= SAMPLE_RADIUS; 284 284 285 285 const float currentDepth = projPos.z * PRECISION_SCALE; 286 286 287 const float2 ao = ssao(IN, colors, noise , samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir));287 const float2 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir)); 288 288 289 289 … … 292 292 293 293 OUT.illum_col = temporalSmoothing(projPos, worldPos, currentDepth, oldTex, oldModelViewProj, temporalCoherence, ao, 294 samples, colors, noise , w, bl, br, tl, tr, IN.texCoord);294 samples, colors, noiseTex, w, bl, br, tl, tr, IN.texCoord, eyePos); 295 295 296 296 return OUT; … … 336 336 //OUT.illum_col = col * ao.x; 337 337 OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 338 //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0); 338 339 OUT.illum_col.w = col.w; 339 340
Note: See TracChangeset
for help on using the changeset viewer.