- Timestamp:
- 11/18/08 17:26:34 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3136 r3137 58 58 static ShaderProgram *sCgDownSampleProgram = NULL; 59 59 static ShaderProgram *sCgSmoothSsaoProgram = NULL; 60 static ShaderProgram *sCgScaleDepthProgram = NULL; 60 61 61 62 … … 370 371 sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", "antiAliasing"); 371 372 sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", "toneMap"); 372 sCgDownSampleProgram = sm->CreateFragmentProgram("tonemap", "DownSample", "downSample"); 373 sCgDownSampleProgram = sm->CreateFragmentProgram("deferred", "Output", "Output"); 374 sCgScaleDepthProgram = sm->CreateFragmentProgram("deferred", "ScaleDepth", "ScaleDepth"); 373 375 sCgLogLumProgram = sm->CreateFragmentProgram("tonemap", "CalcAvgLogLum", "avgLogLum"); 374 376 sCgSmoothSsaoProgram = sm->CreateFragmentProgram("combineSsao", "smoothSsao", "smoothSsao"); … … 425 427 ///////////////////// 426 428 427 string downSampleParams[] = {"colors", "downSampleOffs"}; 428 sCgDownSampleProgram->AddParameters(downSampleParams, 0, 2); 429 string downSampleParams[] = {"colors"}; 430 sCgDownSampleProgram->AddParameters(downSampleParams, 0, 1); 431 432 ///////////////////// 433 434 string scaleDepthParams[] = {"colors"}; 435 sCgScaleDepthProgram->AddParameters(scaleDepthParams, 0, 1); 429 436 430 437 //////////// … … 505 512 { 506 513 // downsample fbo buffers 507 DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0); // colors 508 DownSample(fbo, 1, mDownSampleFbo, 1); // normals 509 DownSample(fbo, 2, mDownSampleFbo, 2); // offsets 514 // colors 515 DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0, sCgScaleDepthProgram); 516 DownSample(fbo, 1, mDownSampleFbo, 1, sCgDownSampleProgram); // normals 517 DownSample(fbo, 2, mDownSampleFbo, 2, sCgDownSampleProgram); // offsets 510 518 } 511 519 … … 952 960 int bufferIdx, 953 961 FrameBufferObject *downSampleFbo, 954 int downSampleBufferIdx) 955 { 956 ColorBufferObject *colorBuffer = fbo->GetColorBuffer(bufferIdx); 957 GLuint colorsTex = colorBuffer->GetTexture(); 962 int downSampleBufferIdx, 963 ShaderProgram *program) 964 { 965 ColorBufferObject *buffer = fbo->GetColorBuffer(bufferIdx); 966 GLuint tex = buffer->GetTexture(); 958 967 959 968 glPushAttrib(GL_VIEWPORT_BIT); 960 969 glViewport(0, 0, downSampleFbo->GetWidth(), downSampleFbo->GetHeight()); 961 970 962 sCgDownSampleProgram->SetTexture(0, colorsTex); 963 964 const float filterWidth = 1.0f; 965 float downSampleOffsets[NUM_DOWNSAMPLES * 2]; 966 //ComputeSampleOffsets(downSampleOffsets, fbo->GetWidth(), fbo->GetHeight(), filterWidth, NUM_DOWNSAMPLES); 967 968 sCgDownSampleProgram->SetArray2f(1, (float *)downSampleOffsets, NUM_DOWNSAMPLES); 969 970 mDownSampleFbo->Bind(); 971 downSampleFbo->Bind(); 972 973 program->SetTexture(0, tex); 971 974 glDrawBuffers(1, mrt + downSampleBufferIdx); 972 975 973 DrawQuad( sCgDownSampleProgram);976 DrawQuad(program); 974 977 975 978 glPopAttrib(); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3135 r3137 88 88 resolution of fbo. 89 89 */ 90 void DownSample(FrameBufferObject *fbo, int bufferIdx, 91 FrameBufferObject *downSampleFbo, int downSampleBufferIdx); 90 void DownSample(FrameBufferObject *fbo, 91 int bufferIdx, 92 FrameBufferObject *downSampleFbo, 93 int downSampleBufferIdx, 94 ShaderProgram *program); 92 95 93 96 void DrawQuad(ShaderProgram *p); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
r3136 r3137 23 23 { 24 24 // center normal 25 const float3 centerNormal = normalize(tex2Dlod(normals, float4(IN.texCoords, 0, 0)).xyz);25 const float3 centerNormal = tex2Dlod(normals, float4(IN.texCoords, 0, 0)).xyz; 26 26 // center color 27 27 const float4 centerColor = tex2Dlod(colors, float4(IN.texCoords, 0, 0)); … … 37 37 float4 nd; 38 38 39 nd.x = dot(centerNormal, normalize(tex2Dlod(normals, float4(lt, 0, 0)).xyz));40 nd.y = dot(centerNormal, normalize(tex2Dlod(normals, float4(rb, 0, 0)).xyz));41 nd.z = dot(centerNormal, normalize(tex2Dlod(normals, float4(rt, 0, 0)).xyz));42 nd.w = dot(centerNormal, normalize(tex2Dlod(normals, float4(lb, 0, 0)).xyz));39 nd.x = dot(centerNormal, tex2Dlod(normals, float4(lt, 0, 0)).xyz); 40 nd.y = dot(centerNormal, tex2Dlod(normals, float4(rb, 0, 0)).xyz); 41 nd.z = dot(centerNormal, tex2Dlod(normals, float4(rt, 0, 0)).xyz); 42 nd.w = dot(centerNormal, tex2Dlod(normals, float4(lb, 0, 0)).xyz); 43 43 44 44 nd -= float4(barrier.x); … … 65 65 for (int i = 0; i < 4; ++ i) 66 66 { 67 dd = float4(depthVals[i * 2] + depthVals[i * 2 + 1]);67 dd[i] = float4(depthVals[i * 2] + depthVals[i * 2 + 1]); 68 68 } 69 69 … … 72 72 dd = step(dd, float4(0.0f)); 73 73 74 const float de = saturate(dot(dd, weights.y)); 74 //const float de = saturate(dot(dd, weights.y)); 75 const float de = weights.y * dd.x + dd.y + dd.z + dd.w; 75 76 76 77 … … 91 92 92 93 //float4 col = (s0 + s1 + s2 + s3 + centerColor) * 0.2f; 93 //float4 col = (s0 + s1 + s2 + s3) * 0.25f;94 float4 col = float4(ne.x, ne.x, ne.x, 0);94 float4 col = (s0 + s1 + s2 + s3) * 0.25f; 95 //float4 col = float4(ne.x, ne.x, ne.x, 0); 95 96 //float4 col = float4(de.x, de.x, de.x, 0); 96 97 //float4 col = float4(w, w, w, 0); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3135 r3137 66 66 float DiscontinuityFilter(float2 texCoord, 67 67 float4 ao, 68 float4 color, 68 69 uniform sampler2D ssaoTex, 69 70 uniform sampler2D normalsTex, 71 uniform sampler2D colorsTex, 70 72 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 71 73 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], … … 82 84 const float3 centerPos = ReconstructSamplePos(ssaoTex, texCoord, bl, br, tl, tr); 83 85 #else 86 //const float eyeSpaceDepth = color.w; 84 87 const float eyeSpaceDepth = ao.w; 85 88 #endif 86 89 87 const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 90 const float3 centerNormal = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 91 //const float3 centerNormal = tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz; 88 92 89 93 float4 aoSample; … … 95 99 float normalFactor; 96 100 float convergenceFactor; 101 float sampleDepth; 97 102 98 103 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 99 104 { 100 105 sampleTexCoord = float4(texCoord + filterOffs[i] * scale, 0, 0); 106 107 101 108 aoSample = tex2Dlod(ssaoTex, sampleTexCoord); 102 109 sampleNorm = normalize(tex2Dlod(normalsTex, sampleTexCoord).xyz); 110 //sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 103 111 104 112 #ifdef USE_POSITION … … 106 114 depthFactor = max(step(1.0f - 5e-1f, 1.0f - length(samplePos - centerPos)), 1e-3f); 107 115 #else // use depth 108 depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 116 //sampleDepth = tex2Dlod(colorsTex, sampleTexCoord).w; 117 sampleDepth = aoSample.w; 118 depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / sampleDepth)), 1e-3f); 109 119 #endif 110 normalFactor = max(step(0.6f, dot(sampleNorm, norm)), 1e-3f);120 normalFactor = max(step(0.6f, dot(sampleNorm, centerNormal)), 1e-3f); 111 121 convergenceFactor = min(100.0f, aoSample.y) * 0.01f;//max(step(18.5f, aoSample.y), 1e-3f); 112 122 … … 176 186 //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor / (adaptFactor + ao.y), 0); 177 187 178 if (ao.y < 50.5f) ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, ao.z, bl, br, tl, tr);188 if (ao.y < 50.5f) ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, ao.z, bl, br, tl, tr); 179 189 //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1, 0); 180 190 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3136 r3137 72 72 73 73 OUT.color = col; 74 //OUT.color.xyz = normal * 0.5f + 0.5f;75 74 // store scaled view vector so wie don't have to normalize for e.g., ssao 76 75 OUT.color.w = color.w;// / length(IN.view); … … 196 195 OUT.color = useShading ? (ambient + diffuse) * color : color; 197 196 // store scaled view vector from now on so wie don't have to normalize later (e.g., for ssao) 198 OUT.color.w = color.w / lenView;197 //OUT.color.w = color.w / lenView; 199 198 200 199 return OUT; … … 294 293 float4 Output(fragment IN, uniform sampler2D colors): COLOR 295 294 { 295 return tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 296 } 297 298 299 float4 ScaleDepth(fragment IN, 300 uniform sampler2D colors): COLOR 301 { 302 float4 color = tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 303 // store scaled view vector so wie don't have to normalize for e.g., ssao 304 color.w /= length(IN.view); 305 306 return color; 307 } 308 309 310 float4 DownSample(fragment IN, 311 uniform sampler2D colors, 312 uniform float2 downSampleOffs[NUM_DOWNSAMPLES]): COLOR 313 { 296 314 // let bilinear filtering do its work 297 return tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 298 } 315 float4 color = tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 316 return color; 317 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3133 r3137 118 118 reprojected color / depth values as well as a boolean that 119 119 */ 120 inline float 3temporalSmoothing(float4 worldPos,120 inline float2 temporalSmoothing(float4 worldPos, 121 121 float eyeSpaceDepth, 122 122 float2 texcoord0, … … 167 167 const float invLen = 1.0f / length(viewVec); 168 168 const float projectedEyeSpaceDepth = invLen * length(translatedPos); 169 //const float projectedEyeSpaceDepth = length(translatedPos); 169 170 170 171 const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth); … … 238 239 //newWeight -= step(512.0f, newWeight) * 256.0f; 239 240 240 return float 3(oldPixel.x, newWeight, eyeSpaceDepth);241 return float2(oldPixel.x, newWeight); 241 242 } 242 243 … … 385 386 //-- compute temporal reprojection 386 387 387 float 3temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos,388 float2 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos, 388 389 oldTex, oldModelViewProj, temporalCoherence, 389 390 colors, … … 401 402 //const float newWeight = clamp(temporalVals.y, 1.0f, temporalCoherence); 402 403 const float newWeight = temporalVals.y; 404 403 405 //float2 noiseOffs = float2((temporalVals.y - 1)/ 139.0f, .0f); 404 406 float2 noiseOffs = float2(.0f); … … 418 420 419 421 OUT.illum_col.x = (ao.x + oldSsao * (newWeight - 1.0f)) / newWeight; 420 OUT.illum_col.y = temporalVals.y;422 OUT.illum_col.y = newWeight; 421 423 OUT.illum_col.z = invw; 422 OUT.illum_col.w = temporalVals.z;424 OUT.illum_col.w = eyeSpaceDepth; 423 425 424 426 return OUT; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
r3132 r3137 18 18 float4 col: COLOR0; 19 19 }; 20 21 22 23 float4 DownSample(frag IN,24 uniform sampler2D colors,25 uniform float2 downSampleOffs[NUM_DOWNSAMPLES]): COLOR26 {27 // let bilinear filtering do its work28 return tex2Dlod(colors, float4(IN.texCoord, 0, 0));29 /*30 float4 average = .0f;31 for (int i = 0; i < NUM_DOWNSAMPLES; ++ i)32 {33 average += tex2Dlod(colors, float4(IN.texCoord + downSampleOffs[i], 0, 0));34 }35 average *= 1.0f / (float)NUM_DOWNSAMPLES;36 37 return average;*/38 }39 20 40 21 … … 154 135 float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 155 136 156 const float expFactor = 0.1f;137 const float expFactor = 1e-2f; 157 138 // exponential smoothing of tone mapping over time 158 139 if (oldLogLum > 1e-3f) // check if loglum from last frame too small (=> tm too bright)
Note: See TracChangeset
for help on using the changeset viewer.