Changeset 2974
- Timestamp:
- 09/25/08 18:37:03 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r2973 r2974 80 80 static CGparameter sColorsTexCombinedSsaoParam; 81 81 static CGparameter sSsaoTexCombinedSsaoParam; 82 static CGparameter sPositionsTexCombinedSsaoParam; 82 83 83 84 … … 403 404 sColorsTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "colors"); 404 405 sSsaoTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "ssaoTex"); 406 sPositionsTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "positions"); 405 407 } 406 408 else … … 551 553 FirstPass(fbo, light); 552 554 553 554 float imageKey, whiteLum, middleGrey; 555 556 ComputeToneParameters(fbo, light, imageKey, whiteLum, middleGrey); 557 558 ToneMap(fbo, light, imageKey, whiteLum, middleGrey); 555 glEnable(GL_TEXTURE_2D); 556 // generate mip map levels for position texture 557 glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture()); 558 glGenerateMipmapEXT(GL_TEXTURE_2D); 559 559 560 560 561 switch (mShadingMethod) … … 573 574 } 574 575 576 float imageKey, whiteLum, middleGrey; 577 578 ComputeToneParameters(fbo, light, imageKey, whiteLum, middleGrey); 579 ToneMap(fbo, light, imageKey, whiteLum, middleGrey); 580 575 581 AntiAliasing(fbo, light); 576 582 … … 613 619 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 614 620 615 if (1) 616 { 617 // generate mip map levels for position texture 618 glBindTexture(GL_TEXTURE_2D, positionsTex); 619 glGenerateMipmapEXT(GL_TEXTURE_2D); 620 } 621 621 // generate mip map levels for position texture 622 glBindTexture(GL_TEXTURE_2D, positionsTex); 623 glGenerateMipmapEXT(GL_TEXTURE_2D); 624 622 625 623 626 // read the second buffer, write to the first buffer … … 748 751 glColor3f(1.0f, 1.0f, 1.0f); 749 752 750 float offs2 = 0.5f;751 752 753 glBegin(GL_QUADS); 753 754 … … 832 833 cgGLSetMatrixParameterfc(sOldModelViewProjMatrixGiParam, (const float *)oldProjViewMatrix.x); 833 834 834 GLuint colorsTex = fbo->GetColorBuffer( 3)->GetTexture();835 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 835 836 GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 836 837 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 837 838 838 if (1) 839 { 840 // generate mip map levels for position texture 841 glBindTexture(GL_TEXTURE_2D, positionsTex); 842 glGenerateMipmapEXT(GL_TEXTURE_2D); 843 844 // generate mip map levels for position texture 845 glBindTexture(GL_TEXTURE_2D, colorsTex); 846 glGenerateMipmapEXT(GL_TEXTURE_2D); 847 } 848 839 // generate mip map levels for position texture 840 glBindTexture(GL_TEXTURE_2D, positionsTex); 841 glGenerateMipmapEXT(GL_TEXTURE_2D); 849 842 850 843 // read the second buffer, write to the first buffer … … 991 984 992 985 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 986 GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 993 987 GLuint ssaoTex = mFbo->GetColorBuffer(mFboIndex)->GetTexture(); 994 988 … … 1009 1003 cgGLEnableTextureParameter(sSsaoTexCombinedSsaoParam); 1010 1004 1005 cgGLSetTextureParameter(sPositionsTexCombinedSsaoParam, positionsTex); 1006 cgGLEnableTextureParameter(sPositionsTexCombinedSsaoParam); 1011 1007 1012 1008 glColor3f(1.0f, 1.0f, 1.0f); … … 1025 1021 cgGLDisableTextureParameter(sColorsTexCombinedSsaoParam); 1026 1022 cgGLDisableTextureParameter(sSsaoTexCombinedSsaoParam); 1027 1023 cgGLDisableTextureParameter(sPositionsTexCombinedSsaoParam); 1024 1028 1025 cgGLDisableProfile(RenderState::sCgFragmentProfile); 1029 1026 … … 1163 1160 ///////////// 1164 1161 1165 GLuint colorsTex = colorBuffer->GetTexture();1162 /*GLuint colorsTex = colorBuffer->GetTexture(); 1166 1163 1167 1164 fbo->Bind(); … … 1186 1183 1187 1184 // the neighbouring texels 1188 float x_offs = 1.0f / mWidth;1189 float y_offs = 1.0f / mHeight;1185 float x_offs = 0;//1.0f / mWidth; 1186 float y_offs = 0;//1.0f / mHeight; 1190 1187 1191 1188 SetVertex(0, 0, x_offs, y_offs); … … 1211 1208 //DownSample(fbo); 1212 1209 } 1213 1210 */ 1214 1211 PrintGLerror("antialiasing"); 1215 1212 } … … 1258 1255 glColor3f(1.0f, 1.0f, 1.0f); 1259 1256 1260 float offs2 = 0.5f;1261 1262 1257 glBegin(GL_QUADS); 1263 1258 1264 1259 // the neighbouring texels 1265 float x_offs = 1.0f / mWidth;1266 float y_offs = 1.0f / mHeight;1260 const float x_offs = 1.0f / mWidth; 1261 const float y_offs = 1.0f / mHeight; 1267 1262 1268 1263 SetVertex(0, 0, x_offs, y_offs); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2968 r2974 618 618 // the diffuse color buffer 619 619 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 620 //fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false);621 620 622 621 // the positions buffer 623 622 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 624 //fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false);625 623 626 624 // the normals buffer … … 1054 1052 1055 1053 // draw to 3 color buffers 1056 glDrawBuffers(3, mrt); 1054 // a color, normal, and positions buffer 1055 glDrawBuffers(4, mrt); 1057 1056 1058 1057 glEnableClientState(GL_NORMAL_ARRAY); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r2970 r2974 38 38 39 39 40 ////////// 41 //-- Tone mapping 42 43 #define MINLOGLUM 10.0f 44 #define MAXLOGLUM 10.0f 40 45 41 46 #endif // __SHADERENV_H -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
r2973 r2974 1 1 #include "../shaderenv.h" 2 2 3 struct v2p3 struct fragment 4 4 { 5 5 float2 c: TEXCOORD0; // center … … 21 21 22 22 23 float4 main( v2pIN,23 float4 main(fragment IN, 24 24 uniform sampler2D colors, 25 25 uniform sampler2D normals -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2968 r2974 48 48 float4 outColor; 49 49 50 if (emmisive > 1.5) outColor = color; 51 //else if (emmisive > 0.95) outColor = color * lightDiffuse; 52 else 53 outColor = (ambient + diffuse) * color; 50 //if (color.w > 1e19f) outColor = color; 51 if (emmisive > 1.5f) outColor = color; 52 else outColor = (ambient + diffuse) * color; 54 53 55 54 return outColor; … … 75 74 76 75 // an ambient color term 77 float amb = norm.w;76 float amb = color.w; 78 77 79 78 float3 normal = normalize(norm.xyz); … … 82 81 83 82 OUT.color = col; 84 //OUT.color = float4(100.0, 1, 1, 0);85 83 OUT.color.w = color.w; 84 85 // write out logaritmic luminance for tone mapping 86 const float3 w = float3(0.299f, 0.587f, 0.114f); 87 88 float lum = dot(OUT.color.rgb, w); 89 float logLum = log(1e-5f + lum); 90 91 float invLogLumRange = 1 / (MAXLOGLUM + MINLOGLUM); 92 float logLumOffset = MINLOGLUM * invLogLumRange; 93 float logLumScaled = logLum * invLogLumRange + logLumOffset; 94 95 OUT.color.w = logLumScaled; 86 96 87 97 return OUT; … … 152 162 153 163 // hack: an emmisive color term 154 float emmisive = norm.w;164 float emmisive = color.w; 155 165 156 166 // diffuse intensity … … 163 173 164 174 // calc diffuse illumination + shadow term 165 if ((emmisive < 0.95f) // hack: prevent shadowing the sky175 if ((emmisive < 1.5f) // hack: prevent shadowing the sky 166 176 && (angle > 1e-3f) // shadow only if diffuse color has some minimum intensity 167 177 ) … … 178 188 } 179 189 180 // global ambient 181 //const float4 ambient = 0.25f; 190 // light ambient term 182 191 const float4 ambient = glstate.light[0].ambient; 183 192 … … 185 194 OUT.color = (emmisive > 1.5f) ? color: (ambient + diffuse) * color; 186 195 187 // also write out depth component 188 OUT.color.w = color.w; 189 196 // write out logaritmic luminance for tone mapping 197 const float3 w = float3(0.299f, 0.587f, 0.114f); 198 199 float lum = dot(OUT.color.rgb, w); 200 float logLum = log(1e-5f + lum); 201 202 OUT.color.w = 100;//logLum; 203 190 204 return OUT; 191 205 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r2964 r2974 227 227 228 228 OUT.illum_col = (col + illum) * ao; 229 //OUT.illum_col = ao;230 231 229 OUT.illum_col.w = col.w; 232 230 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r2965 r2974 75 75 76 76 // save color in first render target 77 // hack: use com ination of emmisive + diffuse (emmisive used as constant ambient term)77 // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term) 78 78 pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor; 79 79 80 80 // save world position in second render target 81 81 pix.pos = IN.worldPos * maxDepth; 82 // save normal in third rt82 // save world space normal in third rt 83 83 pix.norm.xyz = IN.normal; 84 84 85 // hack: squeeze some information about ambient into the texture86 pix.norm.w = glstate.material.emission.x;87 85 // store projection coordinates with positions (used for ssao) 88 pix.pos.w = IN.projPos.w; 86 pix.norm.w = IN.projPos.w; 87 // write the depth 88 pix.pos.w = IN.mypos.z / IN.mypos.w; 89 89 90 90 // account for alpha blending … … 92 92 discard; 93 93 94 // write the depth95 pix.col.w = IN.mypos.z / IN.mypos.w;94 // hack: squeeze some information about ambient into the texture 95 pix.col.w = glstate.material.emission.x; 96 96 97 97 return pix; … … 110 110 pix.norm.xyz = IN.normal; 111 111 112 // store projection coordinates with positions (used for ssao) 113 pix.norm.w = IN.mypos.w; 114 // the projected depth 115 pix.pos.w = IN.mypos.z / IN.mypos.w; 116 112 117 // hack: squeeze some information about the ambient term into the target 113 pix.norm.w = glstate.material.emission.x; 114 pix.pos.w = IN.mypos.w; 115 116 // the projected depth 117 pix.col.w = IN.mypos.z / IN.mypos.w; 118 pix.col.w = glstate.material.emission.x; 118 119 119 120 return pix; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg
r2968 r2974 94 94 OUT.color = float4(hcol, 1.0); 95 95 96 //OUT.color.rgb *= 2e-3f;97 96 //OUT.color.rgb *= 2e-5f; 98 97 … … 112 111 113 112 pix.col = IN.color2; 114 pix.pos = IN.worldPos * 1e20;// * maxDepth;113 pix.pos = 1e20f; 115 114 116 115 pix.norm.xyz = IN.normal; 117 116 118 // hack: squeeze some information about an ambient term into the target 119 pix.norm.w = 2; 120 pix.pos.w = IN.mypos.w; 117 pix.norm.w = IN.mypos.w; 118 pix.pos.w = 1e20f; 121 119 122 // the projected depth 123 pix.col.w = IN.mypos.z / IN.mypos.w; 120 pix.col.w = 2.0f; 124 121 125 122 return pix; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r2964 r2974 40 40 uniform float2 samples[NUM_SAMPLES], 41 41 uniform float3 currentNormal, 42 uniform float4 centerPosition 42 uniform float4 centerPosition, 43 uniform float scaleFactor 43 44 //,uniform float3 currentViewDir 44 45 ) 45 46 { 46 // the w coordinate from the persp. projection47 float w = centerPosition.w;48 49 47 // Check in a circular area around the current position. 50 48 // Shoot vectors to the positions there, and check the angle to these positions. … … 67 65 #endif 68 66 // weight with projected coordinate to reach similar kernel size for near and far 69 float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w;67 float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * scaleFactor; 70 68 71 69 if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) … … 120 118 float4 norm = tex2D(normals, IN.texCoord.xy); 121 119 122 // the ambient term123 const float amb = norm.w;124 125 120 // expand normal 126 121 float3 normal = normalize(norm.xyz); 127 122 128 /// the current view direction 129 //float3 viewDir = normalize(IN.view); 123 // a constant ambient term 124 const float amb = norm.w; 125 // the w coordinate from the persp. projection 126 float w = norm.w; 130 127 131 128 // the current world position … … 133 130 134 131 // the current color 135 const float4 currentCol = tex2D(colors, IN.texCoord.xy); 136 const float currentDepth = currentCol.w; 137 138 const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition);//, viewDir); 132 const float currentDepth = centerPosition.w; 133 134 const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w);//, viewDir); 139 135 140 136 … … 182 178 } 183 179 184 185 //OUT.illum_col.y = ao.y;186 180 OUT.illum_col.z = newWeight; 187 181 OUT.illum_col.w = currentDepth; … … 193 187 pixel combine(fragment IN, 194 188 uniform sampler2D colors, 195 uniform sampler2D ssaoTex) 189 uniform sampler2D ssaoTex, 190 uniform sampler2D positions) 196 191 { 197 192 pixel OUT; 198 193 199 194 float4 col = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)); 195 float depth = tex2Dlod(positions, float4(IN.texCoord.xy, 0, 0)).w; 200 196 float4 ao = tex2D(ssaoTex, IN.texCoord.xy); 201 197 202 198 OUT.illum_col = col * ao.x; 203 //OUT.illum_col = (float4)ao.x;204 205 199 OUT.illum_col.w = ao.w; 206 200 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
r2973 r2974 2 2 3 3 4 struct frag ment4 struct frag 5 5 { 6 6 // normalized screen position 7 float4 pos: WPOS; 8 float4 texCoord: TEXCOORD0; 7 float2 texCoord: TEXCOORD0; 9 8 10 9 float2 lt: TEXCOORD1; // left top … … 21 20 22 21 23 float4 DownSample(frag mentIN,22 float4 DownSample(frag IN, 24 23 uniform sampler2D colors, 25 24 float2 downSampleOffs[16]) : COLOR … … 29 28 for(int i = 0; i < 16; ++ i) 30 29 { 31 average += tex2D(colors, IN.texCoord .xy+ downSampleOffs[i]);30 average += tex2D(colors, IN.texCoord + downSampleOffs[i]); 32 31 } 33 32 … … 38 37 39 38 40 float4 GreyScaleDownSample(fragment IN, 41 uniform sampler2D colors): COLOR 39 float4 GreyScaleDownSample(frag IN, 40 uniform sampler2D colors 41 ): COLOR 42 42 { 43 43 44 44 // Compute the average of the 4 necessary samples 45 float average = 0.0f;46 float maximum = -1e20;45 float average = .0f; 46 float maximum = .0f; 47 47 48 48 // the rgb weights … … 52 52 float4 cols[4]; 53 53 54 cols[0] = tex2D(colors, IN.texCoord.xy + IN.lt.xy); 55 cols[1] = tex2D(colors, IN.texCoord.xy + IN.lb.xy); 56 cols[2] = tex2D(colors, IN.texCoord.xy + IN.rt.xy); 57 cols[3] = tex2D(colors, IN.texCoord.xy + IN.rb.xy); 58 54 cols[0] = tex2D(colors, IN.lt); 55 cols[1] = tex2D(colors, IN.lb); 56 cols[2] = tex2D(colors, IN.rt); 57 cols[3] = tex2D(colors, IN.rb); 59 58 60 59 for (int i = 0; i < 4; ++ i) … … 63 62 64 63 maximum = max(maximum, intensity); 65 average += (0.25f * log(1e-5f + intensity));64 average += log(1e-5f + intensity); 66 65 } 67 66 68 average = exp(average );67 average = exp(average * 0.25f); 69 68 70 return tex2D(colors, IN.texCoord.xy); 69 float4 hcols = cols[0] + cols[1] + cols[2] + cols[3]; 70 71 return hcols * 0.25f; 72 //return float4(average, maximum, 0.0f, cols[0].w); 71 73 72 74 // Output the luminance to the render target 73 return float4(average, maximum, 0.0f, 1.0f);75 //return float4(average, maximum, 0.0f, 1.0f); 74 76 } 75 77 76 78 77 pixel ToneMap(frag mentIN,79 pixel ToneMap(frag IN, 78 80 uniform sampler2D colors, 79 81 uniform float imageKey, … … 82 84 { 83 85 pixel OUT; 84 float4 color = tex2D(colors, IN.texCoord .xy);86 float4 color = tex2D(colors, IN.texCoord); 85 87 86 88 const float pixLum = 0.2125f * color.x + 0.7154f * color.y + 0.0721f * color.z; 87 89 90 // obtain new image key from highest mipmap level 91 float logLumScaled = tex2Dlod(colors, float4(.5f, .5f, 0, 99)).w; 92 93 float logLumRange = MAXLOGLUM + MINLOGLUM; 94 //float logLumOffset = MINLOGLUM * logLumRange; 95 float logLum = logLumScaled * logLumRange - MINLOGLUM; 96 97 float newImageKey = exp(logLum); 98 88 99 // adjust to middle gray 89 const float lum = middleGrey * pixLum / imageKey;100 const float lum = middleGrey * pixLum / newImageKey; 90 101 91 102 // map to range and calc burnout
Note: See TracChangeset
for help on using the changeset viewer.