Changeset 3009
- Timestamp:
- 10/06/08 17:39:30 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3008 r3009 72 72 static CGparameter sMaxDepthParam; 73 73 static CGparameter sEyePosParam; 74 static CGparameter sEyePosShadowParam; 74 75 static CGparameter sSamplesParam; 75 76 static CGparameter sOldTexParam; … … 295 296 296 297 mDownSampleFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 297 //mDownSampleFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);298 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);299 298 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 300 299 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 300 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 301 301 } 302 302 … … 509 509 sLightDirShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "lightDir"); 510 510 511 sEyePosShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "eyePos"); 512 511 513 PoissonDiscSampleGenerator2 poisson(NUM_PCF_TABS, 1.0f); 512 514 poisson.Generate((float *)pcfSamples); … … 641 643 { 642 644 case SSAO: 645 // downsample fbo buffers for colors, normals 643 646 DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0); 644 647 DownSample(fbo, 1, mDownSampleFbo, 1); … … 649 652 break; 650 653 case GI: 654 // downsample fbo buffers for colors, normals 651 655 DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0); 652 DownSample(fbo, 2, mDownSampleFbo, 2); 656 DownSample(fbo, 1, mDownSampleFbo, 1); 657 653 658 ComputeGlobIllum(fbo, tempCohFactor, projViewMatrix, oldProjViewMatrix); 654 659 CombineIllum(fbo); … … 708 713 709 714 //GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 710 //GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture();711 //GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();715 //GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 716 //GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture(); 712 717 713 718 GLuint colorsTex = mDownSampleFbo->GetColorBuffer(0)->GetTexture(); 714 GLuint positionsTex = mDownSampleFbo->GetColorBuffer(1)->GetTexture(); 715 GLuint normalsTex = mDownSampleFbo->GetColorBuffer(2)->GetTexture(); 719 GLuint normalsTex = mDownSampleFbo->GetColorBuffer(1)->GetTexture(); 720 GLuint positionsTex = mDownSampleFbo->GetColorBuffer(2)->GetTexture(); 721 716 722 GLuint oldTex = mFbo->GetColorBuffer(2 - mFboIndex)->GetTexture(); 717 723 … … 868 874 { 869 875 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 870 GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture();871 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();876 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 877 GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture(); 872 878 873 879 fbo->Bind(); … … 923 929 //GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 924 930 GLuint colorsTex = mDownSampleFbo->GetColorBuffer(0)->GetTexture(); 925 GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture();926 GLuint normalsTex = mDownSampleFbo->GetColorBuffer(2)->GetTexture();931 GLuint normalsTex = mDownSampleFbo->GetColorBuffer(1)->GetTexture(); 932 GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture(); 927 933 928 934 glPushAttrib(GL_VIEWPORT_BIT); … … 992 998 993 999 1000 // note: slightly larger texture could hide ambient occlusion error on border but costs resolution 1001 const float offs = 0.5f; 1002 994 1003 glBegin(GL_QUADS); 995 1004 996 // note: slightly larger texture hides ambient occlusion error on border but costs resolution 997 //const float new_offs = 0.55f; 998 const float new_offs = 0.5f; 999 1000 glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-new_offs, -new_offs, -0.5f); 1001 glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex3f( new_offs, -new_offs, -0.5f); 1002 glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex3f( new_offs, new_offs, -0.5f); 1003 glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-new_offs, new_offs, -0.5f); 1005 glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-offs, -offs, -0.5f); 1006 glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex3f( offs, -offs, -0.5f); 1007 glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex3f( offs, offs, -0.5f); 1008 glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-offs, offs, -0.5f); 1004 1009 1005 1010 glEnd(); … … 1071 1076 1072 1077 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 1073 GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 1078 GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture(); 1079 1074 1080 GLuint ssaoTex = mFbo->GetColorBuffer(mFboIndex)->GetTexture(); 1075 1081 … … 1114 1120 1115 1121 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 1116 1117 GLuint positionsTex = fbo->GetColorBuffer( 1)->GetTexture();1118 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 1122 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 1123 GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture(); 1124 1119 1125 GLuint shadowTex = shadowMap->GetDepthTexture(); 1120 1126 … … 1153 1159 cgGLSetParameter3f(sLightDirShadowParam, lightDir.x, lightDir.y, lightDir.z); 1154 1160 1155 1156 glColor3f(1.0f, 1.0f, 1.0f); 1161 Vector3 tl, tr, bl, br; 1162 ComputeViewVectors(tl, tr, bl, br); 1163 1164 const Vector3 pos = mCamera->GetPosition() / mScaleFactor; 1165 cgGLSetParameter3f(sEyePosShadowParam, pos.x, pos.y, pos.z); 1166 1167 // note: slightly larger texture could hide ambient occlusion error on border but costs resolution 1168 const float offs = 0.5f; 1157 1169 1158 1170 glBegin(GL_QUADS); 1159 1171 1160 float offs2 = 0.5f; 1161 1162 glTexCoord2f(0, 0); glVertex3f(-offs2, -offs2, -0.5f); 1163 glTexCoord2f(1, 0); glVertex3f( offs2, -offs2, -0.5f); 1164 glTexCoord2f(1, 1); glVertex3f( offs2, offs2, -0.5f); 1165 glTexCoord2f(0, 1); glVertex3f(-offs2, offs2, -0.5f); 1172 glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-offs, -offs, -0.5f); 1173 glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex3f( offs, -offs, -0.5f); 1174 glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex3f( offs, offs, -0.5f); 1175 glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-offs, offs, -0.5f); 1166 1176 1167 1177 glEnd(); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3005 r3009 663 663 // the diffuse color buffer 664 664 fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 665 // the normals buffer 666 fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 665 667 // the positions buffer 666 668 //fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 667 fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 668 // the normals buffer 669 fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 669 fbo->AddColorBuffer(ColorBufferObject::RGB_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 670 670 // another color buffer 671 671 fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); … … 1005 1005 { 1006 1006 DeferredRenderer::colorBufferIdx = 0; 1007 glDrawBuffers( 3, mrt);1007 glDrawBuffers(2, mrt); 1008 1008 } 1009 1009 else 1010 1010 { 1011 1011 DeferredRenderer::colorBufferIdx = 3; 1012 glDrawBuffers( 3, mrt2);1012 glDrawBuffers(2, mrt2); 1013 1013 } 1014 1014 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r2991 r3009 49 49 #define MAX_LOD_LEVEL 99 50 50 51 #define MIN_DEPTH_DIFF 1e-5f 51 52 52 53 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3005 r3009 6 6 // normalized screen position 7 7 float4 pos: WPOS; 8 float 4texCoord: TEXCOORD0;9 float3 view: COLOR0;8 float2 texCoord: TEXCOORD0; 9 float3 view: TEXCOORD1; 10 10 }; 11 11 … … 32 32 float4 shade(fragment IN, 33 33 uniform float4 color, 34 uniform float4 position,35 34 uniform float3 normal, 36 35 uniform float emmisive, … … 49 48 50 49 // hack: prevent shading the sky 51 if ( position.z> 1e19f) outColor = color;50 if (color.w > 1e19f) outColor = color; 52 51 //if (emmisive > 1.5f) outColor = color; 53 52 else outColor = (ambient + diffuse) * color; … … 70 69 pixel OUT; 71 70 72 float4 norm = tex2D(normals, IN.texCoord .xy);73 float4 color = tex2Dlod(colors, float4(IN.texCoord .xy, 0, 0));74 float4 position = tex2D(positions, IN.texCoord.xy);71 float4 norm = tex2D(normals, IN.texCoord); 72 float4 color = tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 73 75 74 76 75 // an ambient color term 77 76 float amb = color.w; 78 77 float3 normal = normalize(norm.xyz); 79 float4 col = shade(IN, color, position,normal, amb, lightDir);78 float4 col = shade(IN, color, normal, amb, lightDir); 80 79 81 80 OUT.color = col; 82 83 #if 184 85 81 OUT.color.w = color.w; 86 87 #else88 89 ////////////90 //-- write out logaritmic luminance for tone mapping91 92 // the old loglum is stored in the hightest mipmap-level93 float oldLogLum = tex2Dlod(colors, float4(IN.texCoord.xy, 0, MAX_LOD_LEVEL)).w;94 95 const float3 w = float3(0.299f, 0.587f, 0.114f);96 97 float lum = dot(OUT.color.rgb, w);98 float logLum = log(1e-5f + lum);99 100 float logLumOffset = MINLOGLUM * INV_LOGLUM_RANGE;101 float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset;102 103 if (oldLogLum > 0)104 OUT.color.w = lerp(oldLogLum, logLumScaled, 0.1f);105 else106 OUT.color.w = logLumScaled;107 108 #endif109 82 110 83 return OUT; … … 134 107 //-- add random noise: reflect around random normal vector (warning: slow!) 135 108 136 float2 mynoise = tex2D(noiseTexture, IN.texCoord .xy).xy;109 float2 mynoise = tex2D(noiseTexture, IN.texCoord).xy; 137 110 const float2 offsetTransformed = myreflect(offset, mynoise); 138 111 #else … … 150 123 151 124 return total_d; 125 } 126 127 inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 128 { 129 float3 x1 = lerp(bl, tl, w.y); 130 float3 x2 = lerp(br, tr, w.y); 131 float3 v = lerp(x1, x2, w.x); 132 133 return v; 152 134 } 153 135 … … 163 145 uniform sampler2D noiseTexture, 164 146 uniform float2 samples[NUM_PCF_TABS], 165 uniform float3 lightDir 166 //, uniform sampler2D oldColors 147 uniform float3 lightDir, 148 uniform float3 eyePos, 149 uniform float3 bl, 150 uniform float3 br, 151 uniform float3 tl, 152 uniform float3 tr 167 153 ) 168 154 { … … 170 156 171 157 float4 norm = tex2D(normals, IN.texCoord.xy); 172 float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0));173 float4 position = tex2D(positions, IN.texCoord.xy);174 175 158 const float3 normal = normalize(norm.xyz); 176 177 // hack: an emmisive color term 178 float emmisive = color.w; 179 159 160 float4 color = tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 161 162 /// reconstruct position from the eye space depth 163 float3 viewDir = IN.view; 164 const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 165 166 float4 position; 167 position.xyz = eyePos - viewDir * eyeDepth; 168 169 180 170 // diffuse intensity 181 171 const float angle = saturate(dot(normal, lightDir)); … … 186 176 float4 diffuse = lightDiffuse * angle; 187 177 178 // hack: prevent shadowing the sky 179 const bool useShading = (color.w < 1e19f); 180 188 181 // calc diffuse illumination + shadow term 189 //if ((emmisive < 1.5f) // hack: prevent shadowing the sky 190 if ((position.z < 1e19f) 191 && (angle > 1e-3f) // shadow only if diffuse color has some minimum intensity 182 if (useShading && 183 (angle > 1e-3f) // shadow only if diffuse color has some minimum intensity 192 184 ) 193 185 { … … 205 197 // light ambient term 206 198 const float4 ambient = glstate.light[0].ambient; 207 208 // base lighting 209 //OUT.color = (emmisive > 1.5f) ? color: (ambient + diffuse) * color; 210 OUT.color = (position.z > 1e19f) ? color: (ambient + diffuse) * color; 211 212 213 //////////// 214 //-- write out logaritmic luminance for tone mapping 215 216 #if 1 199 // compute shading 200 OUT.color = useShading ? (ambient + diffuse) * color : color; 201 217 202 OUT.color.w = color.w; 218 #else 219 220 float oldLogLum = tex2Dlod(colors, float4(IN.texCoord.xy, 0, MAX_LOD_LEVEL)).w; 221 222 const float3 w = float3(0.299f, 0.587f, 0.114f); 223 224 float lum = dot(OUT.color.rgb, w); 225 float logLum = log(1e-5f + lum); 226 227 float logLumOffset = MINLOGLUM * INV_LOGLUM_RANGE; 228 float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 229 230 if (oldLogLum > 0) 231 OUT.color.w = lerp(oldLogLum, logLumScaled, 0.1f); 232 else 233 OUT.color.w = logLumScaled; 234 #endif 203 235 204 return OUT; 236 205 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r3006 r3009 11 11 float4 pos: WPOS; 12 12 float4 texCoord: TEXCOORD0; 13 float3 view: COLOR0;13 float3 view: TEXCOORD1; 14 14 }; 15 15 … … 177 177 //-- reconstruct position from the eye space depth 178 178 179 float3 viewDir = I nterpol(IN.texCoord.xy, bl, br, tl, tr);//IN.view;179 float3 viewDir = IN.view; 180 180 const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)).w; 181 181 … … 234 234 (tex.x >= 0.0f) && (tex.x < 1.0f) && 235 235 (tex.y >= 0.0f) && (tex.y < 1.0f) && 236 (abs(depthDif) < 1e-3f)236 (abs(depthDif) < MIN_DEPTH_DIFF) 237 237 // check if something changed in the surrounding area 238 238 //&& (oldNumSamples > 0.2 * gi.ao.y) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r3005 r3009 38 38 { 39 39 float4 col: COLOR0; 40 //float4 pos: COLOR1; 41 float3 pos: COLOR1; 42 float4 norm: COLOR2; 40 float4 norm: COLOR1; 41 float3 pos: COLOR2; 43 42 }; 44 43 … … 113 112 pix.col.w = length(eyePos - IN.worldPos.xyz) * maxDepth / magView; 114 113 115 #if 1114 #if 0 116 115 // save world position in second render target 117 116 pix.pos = IN.worldPos.xyz * maxDepth; … … 145 144 //pix.col.w = glstate.material.emission.x; 146 145 147 // compute eye linear depth 146 // compute eye linear depth and scale with lenght to avoid sqr root in pixel shader 148 147 float2 screenCoord = projPos.xy * 0.5f + 0.5f; 149 148 const float magView = length(Interpol(screenCoord, bl, br, tl, tr)); 150 149 pix.col.w = length(eyePos - IN.worldPos.xyz) * maxDepth / magView; 151 150 152 #if 1151 #if 0 153 152 pix.pos = IN.worldPos.xyz * maxDepth; 154 153 #endif -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg
r3005 r3009 30 30 struct pixel 31 31 { 32 33 float3 pos: COLOR1;34 float4 norm: COLOR2;32 float4 col: COLOR0; 33 float4 norm: COLOR1; 34 float3 pos: COLOR2; 35 35 }; 36 36 … … 112 112 113 113 pix.col = IN.color2; 114 pix.col.w = 2.0f;114 pix.col.w = 1e20f; 115 115 116 116 pix.norm.xyz = IN.normal; 117 117 pix.norm.w = IN.mypos.w; 118 118 119 pix.pos = 1e20f;119 //pix.pos = 1e20f; 120 120 121 121 return pix; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3006 r3009 230 230 (tex.x >= 0.0f) && (tex.x < 1.0f) && 231 231 (tex.y >= 0.0f) && (tex.y < 1.0f) && 232 (abs(depthDif) < 1e-4f)232 (abs(depthDif) < MIN_DEPTH_DIFF) 233 233 // if visibility changed in the surrounding area we have to recompute 234 234 //&& (oldNumSamples > 0.8f * newNumSamples)
Note: See TracChangeset
for help on using the changeset viewer.