Changeset 2835 for GTP/trunk/App
- Timestamp:
- 07/14/08 17:20:08 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2834 r2835 241 241 void InitFBO(); 242 242 243 void GenerateSamples();244 245 243 void CreateNoiseTex2D(); 246 244 … … 273 271 static CGparameter sOldModelViewProjMatrixParam; 274 272 static CGparameter sMaxDepthParam; 273 static CGparameter sMaxDepthParamSsao; 275 274 static CGparameter sMaxDepthParamTex; 276 275 … … 443 442 // create noise texture for ssao 444 443 CreateNoiseTex2D(); 445 446 444 // init render traverser 447 445 ResetTraverser(); … … 561 559 sNoiseMultiplierParam = cgGetNamedParameter(sCgSsaoProgram, "noiseMultiplier"); 562 560 sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "oldModelViewProj"); 563 564 cgGLDisableTextureParameter(sNoiseTexParamSsao); 561 sMaxDepthParamSsao = cgGetNamedParameter(sCgSsaoProgram, "maxDepth"); 562 563 cgGLSetParameter1f(sMaxDepthParamSsao, myfar / 10.0f); 565 564 566 565 sSamplesParamSsao = cgGetNamedParameter(sCgSsaoProgram, "samples"); 567 566 sOldTexParamSsao = cgGetNamedParameter(sCgSsaoProgram, "oldTex"); 568 567 569 GenerateSamples(); 570 cgGLSetParameterArray2f(sSamplesParamSsao, 0, NUM_SAMPLES, (const float *)samples); 568 GenerateSamples(); cgGLSetParameterArray2f(sSamplesParamSsao, 0, NUM_SAMPLES, (const float *)samples); 571 569 } 572 570 else … … 649 647 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer); 650 648 651 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA 16F_ARB, texWidth, texHeight);649 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight); 652 650 int samples = 8; 653 651 //glEnable(GL_MULTISAMPLE_ARB); … … 658 656 glBindTexture(GL_TEXTURE_2D, colorsTex); 659 657 660 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA 16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);661 glGenerateMipmapEXT(GL_TEXTURE_2D);658 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 659 //glGenerateMipmapEXT(GL_TEXTURE_2D); 662 660 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex, 0); 663 661 664 662 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 665 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR _MIPMAP_LINEAR);663 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 666 664 667 665 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); … … 744 742 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer1); 745 743 746 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA 16F_ARB, texWidth, texHeight);744 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight); 747 745 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer1); 748 746 … … 750 748 glBindTexture(GL_TEXTURE_2D, colorsTex1); 751 749 752 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA 16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);753 glGenerateMipmapEXT(GL_TEXTURE_2D);750 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 751 //glGenerateMipmapEXT(GL_TEXTURE_2D); 754 752 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex1, 0); 755 753 756 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);757 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);754 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 755 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 758 756 759 757 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 760 758 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 761 759 760 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 761 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 762 762 763 PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); 763 764 … … 776 777 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer2); 777 778 778 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA 16F_ARB, texWidth, texHeight);779 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight); 779 780 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer2); 780 781 … … 782 783 glBindTexture(GL_TEXTURE_2D, colorsTex2); 783 784 784 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA 16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);785 glGenerateMipmapEXT(GL_TEXTURE_2D);785 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 786 //glGenerateMipmapEXT(GL_TEXTURE_2D); 786 787 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex2, 0); 787 788 789 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 790 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 791 792 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 793 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 788 794 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 789 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR _MIPMAP_LINEAR);795 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 790 796 791 797 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); … … 2319 2325 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 2320 2326 2321 //glTexImage2D(GL_RGBA, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, randomNormals);2322 gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texWidth, texHeight, GL_RGB, GL_UNSIGNED_BYTE, randomNormals);2327 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texWidth, texHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals); 2328 //gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texWidth, texHeight, GL_RGB, GL_UNSIGNED_BYTE, randomNormals); 2323 2329 2324 2330 glBindTexture(GL_TEXTURE_2D, 0); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2834 r2835 7 7 //#define SAMPLE_INTENSITY 0.125f 8 8 // rule of thumb: approx 1 / NUM_SAMPLES 9 #define SAMPLE_INTENSITY 0. 2//0.0625f9 #define SAMPLE_INTENSITY 0.16 //0.0625f 10 10 11 11 #define AREA_SIZE 5e-1f … … 76 76 77 77 //sample noisetex; r stores costheta, g stores sintheta 78 float2 noise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f;78 float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f; 79 79 80 80 // rotation 81 81 //float2 offsetTransformed = offset; 82 float2 offsetTransformed = rotate(offset, noise);82 float2 offsetTransformed = rotate(offset, mynoise); 83 83 //float2 offsetTransformed = reflect(offset, noise); 84 84 … … 95 95 float cos_angle = dot(direction_to_sample, currentNormal); 96 96 cos_angle = max(cos_angle, 0.0f); 97 // take quadratic influence to sharpen contrast98 //cos_angle *= cos_angle;99 97 100 98 // distance between current position and sample position controls AO intensity. 101 //const float maxdist = 2e-1f;102 //const float maxdist = 5e-1f;103 99 const float distanceScale = 1e-6f; 104 100 … … 107 103 108 104 // if normal perpenticular to view dir, only half of the samples count 109 float view_correction = (2.0f - dot(currentViewDir, currentNormal)); 110 view_correction *= view_correction; 105 float view_correction = 1.0f + 0.5f * (1.0f - dot(currentViewDir, currentNormal)); 111 106 112 107 total_ao += cos_angle * distance_intensity * view_correction; … … 144 139 145 140 //sample noisetex; r stores costheta, g stores sintheta 146 float2 noise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f;141 float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f; 147 142 148 143 // rotation 149 float2 offsetTransformed = rotate(offset, noise);144 float2 offsetTransformed = rotate(offset, mynoise); 150 145 151 146 // weight with projected coordinate to reach similar kernel size for near and far … … 171 166 // if normal perpenticular to view dir, only half of the samples count 172 167 float view_correction = 1.0f + 0.5f * (1.0f - dot(currentViewDir, currentNormal)); 173 //view_correction *= view_correction;174 168 175 169 total_ao += cos_angle * distance_intensity * view_correction; … … 218 212 uniform float noiseMultiplier, 219 213 uniform sampler2D oldTex, 220 const uniform float4x4 oldModelViewProj 214 const uniform float4x4 oldModelViewProj, 215 uniform float maxDepth 221 216 ) 222 217 { … … 236 231 237 232 //float ao = ssao(IN, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 238 float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 233 float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 239 234 float ao = new_col.w; 240 235 … … 244 239 //OUT.color = ao; 245 240 //OUT.color = ao * col; 246 float4 dummy = centerPosition / 0.000487676f;241 float4 dummy = centerPosition * maxDepth; 247 242 dummy.w = 1.0f; 248 243 float4 oldPos = mul(oldModelViewProj, dummy); … … 250 245 float newDepth = oldPos.z / oldPos.w; 251 246 252 const float x = 0. 05f;247 const float x = 0.1f; 253 248 254 249 float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f; … … 257 252 float oldDepth = col1.w; 258 253 259 if ((tex.x >= 0 ) && (tex.x <= 1) && (tex.y >= 0) && (tex.y <= 1) && (abs(newDepth - oldDepth) < 5e-4f))254 if ((tex.x >= 0.0f) && (tex.x < 1.0f) && (tex.y >= 0.0f) && (tex.y < 1.0f) && (abs(newDepth - oldDepth) < 9e-4f)) 260 255 OUT.color = attenuated_color * x + col1 * float4(1.0f - x); 261 else OUT.color = attenuated_color;// * x + col1 * float4(1.0f - x); 256 else 257 OUT.color = attenuated_color; 262 258 263 259 //OUT.color = float4(centerPosition.w); … … 292 288 float4 col1 = tex2D(oldTex, IN.texCoord.xy); 293 289 294 const float x = 0. 1f;290 const float x = 0.01f; 295 291 OUT.color = col * x + col1 * float4(1.0f - x); 296 292
Note: See TracChangeset
for help on using the changeset viewer.