Changeset 2903 for GTP/trunk/App/Demos
- Timestamp:
- 09/04/08 15:00:42 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r2901 r2903 47 47 static CGparameter sOldTexParam; 48 48 static CGparameter sNoiseTexParam; 49 static CGparameter sNoiseMultiplierParam;50 49 static CGparameter sTemporalCoherenceParam; 51 50 … … 65 64 static CGparameter sOldIllumTexGiParam; 66 65 static CGparameter sNoiseTexGiParam; 67 static CGparameter sNoiseMultiplierGiParam;68 66 static CGparameter sTemporalCoherenceGiParam; 69 67 … … 92 90 static CGparameter sSampleWidthParam; 93 91 92 //#define USE_3D_SSAO 94 93 95 94 … … 97 96 98 97 // ssao random spherical samples 98 #ifdef USE_3D_SSAO 99 100 static Sample2 samples3[NUM_SAMPLES]; 101 102 #else 103 99 104 static Sample2 samples2[NUM_SAMPLES]; 100 static Sample2 samples3[NUM_SAMPLES]; 105 106 #endif 101 107 102 108 static int colorBufferIdx = 0; … … 119 125 static void GenerateSamples(int sampling) 120 126 { 121 SphericalSampleGenerator gauss(NUM_SAMPLES, 1.0f); 122 gauss.Generate((float *)samples3); 123 124 /* 127 #ifdef USE_3D_SSAO 128 129 SphericalSampleGenerator sph(NUM_SAMPLES, 1.0f); 130 sph.Generate((float *)samples3); 131 132 #else 125 133 switch (sampling) 126 134 { 127 135 case DeferredRenderer::POISSON: 128 136 { 129 staticPoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f);137 PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f); 130 138 poisson.Generate((float *)samples2); 131 139 } … … 133 141 case DeferredRenderer::GAUSS: 134 142 { 135 // static GaussianSampleGenerator gauss(NUM_SAMPLES, 0.5f);136 // gauss.Generate((float *)samples2);137 138 static SphericalSampleGenerator gauss(NUM_SAMPLES, 0.5f);139 gauss.Generate((float *)samples3);143 //PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f); 144 //poisson.Generate((float *)samples2); 145 146 PseudoRandomGenerator pseudo(NUM_SAMPLES, 1.0f); 147 pseudo.Generate((float *)samples2); 140 148 } 141 149 break; 142 150 default: 151 cout << "should not come here" << endl; 143 152 break; 144 }*/ 153 } 154 #endif 145 155 } 146 156 … … 151 161 float *randomNormals = new float[w * h * 3]; 152 162 153 //SphericalSampleGenerator gauss(w * h, 1.0f);154 //gauss.Generate(randomNormals);155 156 163 static HaltonSequence halton; 157 164 float r[2]; … … 159 166 for (int i = 0; i < w * h * 3; i += 3) 160 167 { 161 // create random samples on a circle162 halton.GetNext(2, r);163 164 168 165 //const float theta = 2.0f * acos(sqrt(1.0f - rx)); 166 // randomNormals[i + 0] = cos(theta);167 //randomNormals[i + 1] = sin(theta);168 //randomNormals[i + 2] = 0;169 #ifdef USE_3D_SSAO 170 //halton.GetNext(2, r); 171 r[0] = RandomValue(0, 1); 172 r[1] = RandomValue(0, 1); 169 173 170 174 const float theta = 2.0f * acos(sqrt(1.0f - r[0])); … … 174 178 randomNormals[i + 1] = sin(theta) * sin(phi); 175 179 randomNormals[i + 2] = cos(theta); 180 #else 181 // create random samples on a circle 182 r[0] = RandomValue(0, 1); 183 //halton.GetNext(1, r); 184 185 const float theta = 2.0f * acos(sqrt(1.0f - r[0])); 186 187 randomNormals[i + 0] = cos(theta); 188 randomNormals[i + 1] = sin(theta); 189 randomNormals[i + 2] = 0; 190 #endif 176 191 } 177 192 … … 274 289 cgCreateProgramFromFile(context, 275 290 CG_SOURCE, 276 //"src/shaders/ssao.cg", 291 #ifdef USE_3D_SSAO 277 292 "src/shaders/ssao3d.cg", 293 294 #else 295 "src/shaders/ssao.cg", 296 #endif 278 297 RenderState::sCgFragmentProfile, 279 298 "main", … … 288 307 sNormalsTexParam = cgGetNamedParameter(sCgSsaoProgram, "normals"); 289 308 sNoiseTexParam = cgGetNamedParameter(sCgSsaoProgram, "noiseTexture"); 290 sNoiseMultiplierParam = cgGetNamedParameter(sCgSsaoProgram, "noiseMultiplier");291 309 292 310 sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "oldModelViewProj"); … … 297 315 sOldTexParam = cgGetNamedParameter(sCgSsaoProgram, "oldTex"); 298 316 299 cgGLSetParameter1f(sNoiseMultiplierParam, RandomValue(1.0f, 3.0f));300 317 sSamplesParam = cgGetNamedParameter(sCgSsaoProgram, "samples"); 301 318 } … … 320 337 sNormalsTexGiParam = cgGetNamedParameter(sCgGiProgram, "normals"); 321 338 sNoiseTexGiParam = cgGetNamedParameter(sCgGiProgram, "noiseTexture"); 322 sNoiseMultiplierGiParam = cgGetNamedParameter(sCgGiProgram, "noiseMultiplier");323 339 324 340 sOldModelViewProjMatrixGiParam = cgGetNamedParameter(sCgGiProgram, "oldModelViewProj"); … … 330 346 sOldSsaoTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldSsaoTex"); 331 347 sOldIllumTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldIllumTex"); 332 333 cgGLSetParameter1f(sNoiseMultiplierGiParam, RandomValue(1.0f, 3.0f));334 348 } 335 349 else … … 500 514 ) 501 515 { 516 #ifdef USE_3D_SSAO 502 517 static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f, 503 518 0.0f, 0.5f, 0.0f, 0.5f, … … 507 522 Matrix4x4 m = projViewMatrix * biasMatrix; 508 523 524 cgGLSetMatrixParameterfc(sModelViewProjMatrixParam, (const float *)m.x); 525 #endif 526 509 527 cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 510 cgGLSetMatrixParameterfc(sModelViewProjMatrixParam, (const float *)m.x);511 528 512 529 GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); … … 558 575 { 559 576 mRegenerateSamples = false; 560 cgGLSetParameter1f(sNoiseMultiplierParam, RandomValue(3.0f, 17.0f));561 577 562 578 // q: should we generate new samples or only rotate the old ones? … … 565 581 GenerateSamples(mSamplingMethod); 566 582 567 //cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples2); 583 #ifdef USE_3D_SSAO 568 584 cgGLSetParameterArray3f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples3); 585 #else 586 cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples2); 587 #endif 569 588 } 570 589 … … 779 798 { 780 799 mRegenerateSamples = false; 781 cgGLSetParameter1f(sNoiseMultiplierGiParam, RandomValue(3.0f, 17.0f));782 800 783 801 // q: should we generate new samples or only rotate the old ones? … … 785 803 // needs longer to converge 786 804 GenerateSamples(mSamplingMethod); 805 806 #ifdef USE_3D_SSAO 807 cgGLSetParameterArray3f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples3); 808 #else 787 809 cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples2); 810 #endif 788 811 } 789 812 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
r2902 r2903 1 #include "SampleGenerator.h" 1 2 #include "common.h" 2 #include "SampleGenerator.h"3 3 4 4 5 5 using namespace std; 6 using namespace CHCDemoEngine; 6 7 7 8 HaltonSequence SphericalSampleGenerator::sHalton; 8 9 HaltonSequence PoissonDiscSampleGenerator::sHalton; 9 HaltonSequence GaussianSampleGenerator::sHalton;10 10 HaltonSequence PseudoRandomGenerator::sHalton; 11 11 … … 32 32 const float f_reduction = 0.9f; 33 33 34 static HaltonSequence halton;34 //static HaltonSequence halton; 35 35 float r[2]; 36 36 37 37 // generates poisson distribution on disc 38 float minDist = 2.0f / sqrt((float)mNumSamples);38 float minDist = 2.0f * mRadius / sqrt((float)mNumSamples); 39 39 40 40 //cout << "minDist before= " << minDist << endl; … … 51 51 ++ totalTries; 52 52 53 halton.GetNext(2, r); 53 r[0] = RandomValue(0, mRadius); 54 r[1] = RandomValue(0, mRadius); 55 //halton.GetNext(2, r); 54 56 55 57 const float rx = r[0] * 2.0f - 1.0f; … … 57 59 58 60 // check if in disk, else exit early 59 if (rx * rx + ry * ry > 1)61 if (rx * rx + ry * ry > mRadius * mRadius) 60 62 continue; 61 63 … … 86 88 } 87 89 } 88 89 //cout << "sample: " << samples[i].x << " " << i << " " << samples[i].y << " r: " << sqrt(samples[i].x * samples[i].x + samples[i].y * samples[i].y) << " tries: " << totalTries << endl;90 }91 92 //cout << "minDist after= " << minDist << endl;93 }94 95 96 97 GaussianSampleGenerator::GaussianSampleGenerator(int numSamples, float radius):98 SampleGenerator(numSamples, radius)99 {}100 101 102 void GaussianSampleGenerator::Generate(float *samples) const103 {104 float r[2];105 106 const float sigma = mRadius;107 108 Sample2 *s = (Sample2 *)samples;109 110 const float p0 = 1.0f / (sigma * sqrt(2.0f * M_PI));111 const float p1 = 1.0f / (sigma * sqrt(2.0f * M_PI));112 113 for (int i = 0; i < mNumSamples; ++ i)114 {115 sHalton.GetNext(2, r);116 117 float exp_x = -(r[0] * r[0]) / (2.0f * sigma * sigma);118 float exp_y = -(r[1] * r[1]) / (2.0f * sigma * sigma);119 120 s[i].x = p0 * pow(M_E, exp_x);121 s[i].y = p1 * pow(M_E, exp_y);122 90 } 123 91 … … 133 101 void PseudoRandomGenerator::Generate(float *samples) const 134 102 { 135 sHalton.GetNext(2 * mNumSamples, samples); 103 Sample2 *s = (Sample2 *)samples; 104 105 int numSamples = 0; 106 107 while (numSamples < mNumSamples) 108 { 109 const float rx = RandomValue(-mRadius, +mRadius); 110 const float ry = RandomValue(-mRadius, +mRadius); 111 112 // check if in disk, else exit early 113 if (rx * rx + ry * ry > mRadius * mRadius) 114 continue; 115 116 s[numSamples].x = rx; 117 s[numSamples].y = ry; 118 119 ++ numSamples; 120 } 136 121 } 137 122 … … 146 131 float r[2]; 147 132 Sample3 *s = (Sample3 *)samples; 148 /*149 // idea: use poisson distribution to generate samples150 133 151 PoissonDiscSampleGenerator poisson(mNumSamples, 1.0f);152 Sample2 *pSamples = new Sample2[mNumSamples];153 poisson.Generate((float *)pSamples);154 */155 134 for (int i = 0; i < mNumSamples; ++ i) 156 135 { 157 sHalton.GetNext(2, r); 136 r[0] = RandomValue(0, 1); 137 r[1] = RandomValue(0, 1); 138 //sHalton.GetNext(2, r); 158 139 //r[0] = pSamples[i].x; r[1] = pSamples[i].y; 159 140 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h
r2902 r2903 75 75 76 76 77 class GaussianSampleGenerator: public SampleGenerator78 {79 public:80 81 GaussianSampleGenerator(int numSamples, float radius);82 83 virtual void Generate(float *samples) const;84 85 protected:86 87 static HaltonSequence sHalton;88 };89 90 91 77 class SphericalSampleGenerator: public SampleGenerator 92 78 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2901 r2903 153 153 154 154 bool useGlobIllum = false; 155 bool useSsao = false;156 155 bool useTemporalCoherence = true; 157 156 … … 173 172 174 173 DeferredRenderer::SAMPLING_METHOD samplingMethod = DeferredRenderer::POISSON; 175 DeferredRenderer::SHADING_METHOD shadingMethod = DeferredRenderer::DEFAULT; 174 175 bool useAdvancedShading = false; 176 176 177 177 bool showShadowMap = false; … … 1027 1027 if (!ssaoShader) ssaoShader = new DeferredRenderer(texWidth, texHeight, camera, myfar / 10.0f); 1028 1028 1029 DeferredRenderer::SHADING_METHOD shadingMethod; 1030 1031 if (useAdvancedShading) 1032 { 1033 if (useGlobIllum) 1034 shadingMethod = DeferredRenderer::GI; 1035 else 1036 shadingMethod = DeferredRenderer::SSAO; 1037 } 1038 else 1039 shadingMethod = DeferredRenderer::DEFAULT; 1040 1041 1029 1042 ssaoShader->SetShadingMethod(shadingMethod); 1030 1043 ssaoShader->SetSamplingMethod(samplingMethod); … … 1158 1171 else 1159 1172 samplingMethod = DeferredRenderer::GAUSS; 1160 1161 1173 break; 1162 1174 case 'Y': … … 1165 1177 break; 1166 1178 case 'g': 1179 case 'G': 1180 useGlobIllum = !useGlobIllum; 1181 break; 1167 1182 case 't': 1168 1183 case 'T': … … 1300 1315 break; 1301 1316 case GLUT_KEY_F8: 1302 //shadingMethod = (DeferredRenderer::SHADING_METHOD)((shadingMethod + 1) % 3); 1303 shadingMethod = (DeferredRenderer::SHADING_METHOD)((shadingMethod + 1) % 2); 1304 1317 1318 useAdvancedShading = !useAdvancedShading; 1319 //shadingMethod = (DeferredRenderer::SHADING_METHOD)((shadingMethod + 1) % 2); 1320 1305 1321 break; 1306 1322 case GLUT_KEY_F9: … … 1735 1751 useMultiQueries, useTightBounds, useRenderQueue); 1736 1752 1737 sprintf(msg[i ++], "render technique: %s, SSAO: %d", renderTypeStr[renderType], use Ssao);1753 sprintf(msg[i ++], "render technique: %s, SSAO: %d", renderTypeStr[renderType], useAdvancedShading); 1738 1754 1739 1755 sprintf(msg[i ++], "triangles per virtual leaf: %5d", trianglesPerVirtualLeaf); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h
r2898 r2903 254 254 255 255 256 /*inline int257 RandomValue(int a, int b)258 {259 int range = abs(a - b);260 return (rand() * range) / RAND_MAX + ((a < b) ? a : b);261 }*/262 263 256 inline Real sqr(Real a) 264 257 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r2901 r2903 11 11 12 12 // for quadradtc falloff 13 //#define SAMPLE_INTENSITY 0.28f13 #define SAMPLE_INTENSITY 0.28f 14 14 //#define SAMPLE_INTENSITY 0.32f 15 #define SAMPLE_INTENSITY 2.4f15 //#define SAMPLE_INTENSITY 2.4f 16 16 17 17 //#define AREA_SIZE 25e-1f -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r2897 r2903 46 46 uniform float3 currentNormal, 47 47 uniform float3 currentViewDir, 48 uniform float noiseMultiplier,49 48 uniform float4 centerPosition 50 49 ) … … 67 66 { 68 67 float2 offset = samples[i]; 69 //float3 offset = float3(samples[i], 0); 70 71 //sample noisetex; r stores costheta, g stores sintheta 72 float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy; 73 //float3 mynoise = float3(tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy, 0); 74 75 // reflect sampling using the noise texture 68 69 #if 1 70 //////////////////// 71 // add random noise: reflect around random normal vector (warning: slow!) 72 float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy).xy; 76 73 float2 offsetTransformed = myreflect(offset, mynoise); 77 74 #else 75 float2 offsetTransformed = offset; 76 #endif 78 77 // weight with projected coordinate to reach similar kernel size for near and far 79 78 float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w; … … 96 95 97 96 // if normal perpenticular to view dir, only half of the samples count 98 //const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 99 //total_color.w -= cos_angle * distance_intensity * view_correction; 100 //total_color.xyz += cos_angle * distance_intensity * view_correction * sample_color * ILLUM_INTENSITY; 101 97 /* 98 const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 99 total_color.w -= cos_angle * distance_intensity * view_correction; 100 total_color.xyz += cos_angle * distance_intensity * view_correction * sample_color * ILLUM_INTENSITY; 101 */ 102 102 total_color.w -= cos_angle * distance_intensity; 103 103 total_color.xyz += cos_angle * distance_intensity * sample_color * ILLUM_INTENSITY; … … 116 116 uniform sampler2D noiseTexture, 117 117 uniform float2 samples[NUM_SAMPLES], 118 uniform float noiseMultiplier,119 118 uniform sampler2D oldSsaoTex, 120 119 uniform sampler2D oldIllumTex, … … 146 145 147 146 float4 new_color = globIllum(IN, colors, positions, noiseTexture, 148 samples, normal, viewDir, noiseMultiplier,centerPosition);147 samples, normal, viewDir, centerPosition); 149 148 150 149 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r2898 r2903 41 41 uniform float3 currentNormal, 42 42 uniform float3 currentViewDir, 43 uniform float noiseMultiplier,44 43 uniform float4 centerPosition 45 44 ) … … 57 56 { 58 57 const float2 offset = samples[i]; 59 //const float3 offset = float3(samples[i], 0);60 58 59 #if 1 61 60 //////////////////// 62 // add random noise: r stores costheta, g stores sintheta 63 64 //const float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f; 65 float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy; 66 //float3 mynoise = float3(tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy,0); 67 61 // add random noise: reflect around random normal vector (warning: slow!) 62 float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy).xy; 68 63 const float2 offsetTransformed = myreflect(offset, mynoise); 69 64 #else 65 const float2 offsetTransformed = offset; 66 #endif 70 67 // weight with projected coordinate to reach similar kernel size for near and far 71 68 float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w; … … 110 107 uniform sampler2D noiseTexture, 111 108 uniform float2 samples[NUM_SAMPLES], 112 uniform float noiseMultiplier,113 109 uniform sampler2D oldTex, 114 110 const uniform float4x4 oldModelViewProj, … … 137 133 const float currentDepth = currentCol.w; 138 134 139 const float ao = ssao(IN, positions, noiseTexture, samples, normal, viewDir, noiseMultiplier,centerPosition);135 const float ao = ssao(IN, positions, noiseTexture, samples, normal, viewDir, centerPosition); 140 136 141 137 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao3d.cg
r2902 r2903 40 40 uniform float3 currentNormal, 41 41 uniform float3 currentViewDir, 42 uniform float noiseMultiplier,43 42 uniform float4 centerPosition, 44 43 const uniform float4x4 modelViewProj, … … 64 63 // add random noise: r stores costheta, g stores sintheta 65 64 66 float3 mynoise = (float3)tex2D(noiseTexture, IN.texCoord.xy); // * noiseMultiplier);67 //const float3 offsetTransformed = myreflect(offset, mynoise) * AREA_SIZE;68 const float3 offsetTransformed = offset * AREA_SIZE;65 float3 mynoise = (float3)tex2D(noiseTexture, IN.texCoord.xy); 66 const float3 offsetTransformed = myreflect(offset, mynoise) * AREA_SIZE; 67 //const float3 offsetTransformed = offset * AREA_SIZE; 69 68 70 69 // compute position … … 116 115 uniform sampler2D noiseTexture, 117 116 uniform float3 samples[NUM_SAMPLES], 118 uniform float noiseMultiplier,119 117 uniform sampler2D oldTex, 120 118 const uniform float4x4 oldModelViewProj, … … 147 145 realPos.w = 1.0f; 148 146 149 const float ao = ssao(IN, positions, noiseTexture, samples, normal, viewDir, noiseMultiplier,centerPosition, mymodelViewProj, realPos);147 const float ao = ssao(IN, positions, noiseTexture, samples, normal, viewDir, centerPosition, mymodelViewProj, realPos); 150 148 //const float ao = ssao(IN, positions, samples, normal, viewDir, centerPosition, mymodelViewProj, realPos); 151 149
Note: See TracChangeset
for help on using the changeset viewer.