- Timestamp:
- 09/03/08 22:40:35 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r2898 r2900 807 807 > 808 808 </File> 809 <File 810 RelativePath=".\src\shaders\ssao2.cg" 811 > 812 </File> 809 813 </Filter> 810 814 <File -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r2899 r2900 42 42 43 43 static CGparameter sOldModelViewProjMatrixParam; 44 static CGparameter sModelViewProjMatrixParam; 44 45 static CGparameter sMaxDepthParam; 45 46 static CGparameter sSamplesParam; … … 96 97 97 98 // ssao random spherical samples 98 static Sample2 samples[NUM_SAMPLES]; 99 static Sample2 samples2[NUM_SAMPLES]; 100 static Sample2 samples3[NUM_SAMPLES]; 99 101 100 102 static int colorBufferIdx = 0; … … 117 119 static void GenerateSamples(int sampling) 118 120 { 121 static SphericalSampleGenerator gauss(NUM_SAMPLES, 0.5f); 122 gauss.Generate((float *)samples3); 123 /* 119 124 switch (sampling) 120 125 { … … 122 127 { 123 128 static PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f); 124 poisson.Generate(( Sample2 *)samples);129 poisson.Generate((float *)samples2); 125 130 } 126 131 break; … … 128 133 { 129 134 //static GaussianSampleGenerator gauss(NUM_SAMPLES, 0.5f); 130 //gauss.Generate(( Sample2 *)samples);135 //gauss.Generate((float *)samples2); 131 136 132 137 static SphericalSampleGenerator gauss(NUM_SAMPLES, 0.5f); 133 gauss.Generate(( Sample2 *)samples);138 gauss.Generate((float *)samples3); 134 139 } 135 140 break; 136 141 default: 137 142 break; 138 } 143 }*/ 139 144 } 140 145 … … 145 150 float *randomNormals = new float[w * h * 3]; 146 151 152 static HaltonSequence halton; 153 float r[2]; 154 147 155 for (int i = 0; i < w * h * 3; i += 3) 148 156 { 149 157 // create random samples on a circle 150 const float rx = RandomValue(0, 1); 158 halton.GetNext(2, r); 159 160 /* 151 161 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 152 162 153 //randomNormals[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f);154 //randomNormals[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f);155 163 randomNormals[i + 0] = cos(theta); 156 164 randomNormals[i + 1] = sin(theta); 157 randomNormals[i + 2] = 0; 165 randomNormals[i + 2] = 0;*/ 166 167 const float theta = 2.0f * acos(sqrt(1.0f - r[0])); 168 const float phi = 2.0f * M_PI * r[1]; 169 170 randomNormals[i + 0] = sin(theta) * cos(phi); 171 randomNormals[i + 1] = sin(theta) * sin(phi); 172 randomNormals[i + 2] = cos(theta); 158 173 } 159 174 … … 197 212 //-- the flip-flop fbos 198 213 199 /*mNewFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);200 201 mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);202 mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);203 204 205 ///////////////////////206 207 mOldFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);208 209 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);210 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);*/211 212 214 mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 213 215 … … 269 271 cgCreateProgramFromFile(context, 270 272 CG_SOURCE, 271 "src/shaders/ssao.cg", 273 //"src/shaders/ssao.cg", 274 "src/shaders/ssao2.cg", 272 275 RenderState::sCgFragmentProfile, 273 276 "main", … … 285 288 286 289 sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "oldModelViewProj"); 290 sModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "mymodelViewProj"); 287 291 sMaxDepthParam = cgGetNamedParameter(sCgSsaoProgram, "maxDepth"); 288 292 sTemporalCoherenceParam = cgGetNamedParameter(sCgSsaoProgram, "temporalCoherence"); … … 416 420 void DeferredRenderer::Render(FrameBufferObject *fbo, 417 421 const Matrix4x4 &oldProjViewMatrix, 422 const Matrix4x4 &projViewMatrix, 418 423 float expFactor, 419 424 ShadowMap *shadowMap) … … 457 462 { 458 463 case SSAO: 459 ComputeSsao(fbo, expFactor, oldProjViewMatrix );464 ComputeSsao(fbo, expFactor, oldProjViewMatrix, projViewMatrix); 460 465 CombineSsao(fbo); 461 466 break; … … 487 492 488 493 void DeferredRenderer::ComputeSsao(FrameBufferObject *fbo, 489 float expFactor, 490 const Matrix4x4 &oldProjViewMatrix 491 ) 492 { 494 float expFactor, 495 const Matrix4x4 &oldProjViewMatrix, 496 const Matrix4x4 &projViewMatrix 497 ) 498 { 499 static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f, 500 0.0f, 0.5f, 0.0f, 0.5f, 501 0.0f, 0.0f, 0.5f, 0.5f, 502 0.0f, 0.0f, 0.0f, 1.0f); //bias from [-1, 1] to [0, 1] 503 504 Matrix4x4 m = projViewMatrix * biasMatrix; 505 493 506 cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 507 cgGLSetMatrixParameterfc(sModelViewProjMatrixParam, (const float *)m.x); 494 508 495 509 GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); … … 547 561 // needs longer to converge 548 562 GenerateSamples(mSamplingMethod); 549 cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples); 563 564 //cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples2); 565 cgGLSetParameterArray3f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples3); 550 566 } 551 567 … … 772 788 // needs longer to converge 773 789 GenerateSamples(mSamplingMethod); 774 cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples );790 cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples2); 775 791 } 776 792 … … 865 881 { 866 882 GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); 867 //GLuint ssaoTex = mNewFbo->GetColorBuffer(0)->GetTexture();868 883 GLuint ssaoTex = mFbo->GetColorBuffer(mFboIndex)->GetTexture(); 869 884 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r2897 r2900 38 38 a smoothing factor for temporal coherence 39 39 */ 40 void Render(FrameBufferObject *fbo, const Matrix4x4 &oldProjViewMatrix, float expFactor, ShadowMap *shadowMap = NULL); 40 void Render(FrameBufferObject *fbo, 41 const Matrix4x4 &oldProjViewMatrix, 42 const Matrix4x4 &projViewMatrix, 43 float expFactor, 44 ShadowMap *shadowMap = NULL); 41 45 42 46 /** Initialises the deferred shader and loads the required shaders: … … 58 62 protected: 59 63 60 void ComputeSsao(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix );64 void ComputeSsao(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix, const Matrix4x4 &projViewMatrix); 61 65 62 66 void ComputeGlobIllum(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
r2899 r2900 17 17 18 18 19 void PoissonDiscSampleGenerator::Generate( Sample2*samples) const19 void PoissonDiscSampleGenerator::Generate(float *samples) const 20 20 { 21 21 // this is a hacky poisson sampling generator which does random dart-throwing … … 35 35 36 36 //cout << "minDist before= " << minDist << endl; 37 Sample2 *s = (Sample2 *)samples; 37 38 38 39 for (int i = 0; i < mNumSamples; ++ i) … … 61 62 { 62 63 const float dist = 63 sqrt((s amples[j].x - rx) * (samples[j].x - rx) +64 (s amples[j].y - ry) * (samples[j].y - ry));64 sqrt((s[j].x - rx) * (s[j].x - rx) + 65 (s[j].y - ry) * (s[j].y - ry)); 65 66 66 67 if (dist < minDist) … … 70 71 if (sampleValid) 71 72 { 72 s amples[i].x = rx;73 s amples[i].y = ry;73 s[i].x = rx; 74 s[i].y = ry; 74 75 break; 75 76 } … … 95 96 96 97 97 void GaussianSampleGenerator::Generate( Sample2*samples) const98 void GaussianSampleGenerator::Generate(float *samples) const 98 99 { 99 100 static HaltonSequence halton; … … 101 102 102 103 const float sigma = mRadius; 104 105 Sample2 *s = (Sample2 *)samples; 103 106 104 107 const float p0 = 1.0f / (sigma * sqrt(2.0f * M_PI)); … … 112 115 float exp_y = -(r[1] * r[1]) / (2.0f * sigma * sigma); 113 116 114 s amples[i].x = p0 * pow(M_E, exp_x);115 s amples[i].y = p1 * pow(M_E, exp_y);117 s[i].x = p0 * pow(M_E, exp_x); 118 s[i].y = p1 * pow(M_E, exp_y); 116 119 } 117 120 … … 125 128 126 129 127 128 129 void SphericalSampleGenerator::Generate(Sample2 *samples) const 130 void SphericalSampleGenerator::Generate(float *samples) const 130 131 { 131 132 static HaltonSequence halton; 132 133 float r[2]; 134 135 Sample3 *s = (Sample3 *)samples; 133 136 134 137 for (int i = 0; i < mNumSamples; ++ i) … … 137 140 138 141 // create stratified samples over sphere 139 const float rx = r[0];140 const float ry =r[1];142 const float theta = 2.0f * acos(sqrt(1.0f - r[0])); 143 const float phi = 2.0f * M_PI * r[1]; 141 144 142 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 143 const float phi = 2.0f * M_PI * ry; 144 145 float x = sin(theta) * cos(phi); 146 float y = sin(theta) * sin(phi); 147 float z = cos(theta); 148 149 // project to disc 150 samples[i].x = x / z; 151 samples[i].y = y / z; 145 s[i].x = sin(theta) * cos(phi); 146 s[i].y = sin(theta) * sin(phi); 147 s[i].z = cos(theta); 152 148 } 153 149 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h
r2899 r2900 16 16 17 17 18 struct Sample3 19 { 20 Sample3() {} 21 Sample3(float _x, float _y, float _z): x(_x), y(_y), z(_z) {} 22 23 float x; 24 float y; 25 float z; 26 }; 27 28 /** Class generating random samples on a disc or a sphere, respectively. 29 */ 18 30 class SampleGenerator 19 31 { … … 22 34 SampleGenerator(int numSamples, float radius); 23 35 24 virtual void Generate( Sample2*samples) const = 0;36 virtual void Generate(float *samples) const = 0; 25 37 26 38 protected: … … 39 51 PoissonDiscSampleGenerator(int numSamples, float radius); 40 52 41 virtual void Generate( Sample2*samples) const;53 virtual void Generate(float *samples) const; 42 54 }; 43 55 … … 49 61 GaussianSampleGenerator(int numSamples, float radius); 50 62 51 virtual void Generate( Sample2*samples) const;63 virtual void Generate(float *samples) const; 52 64 }; 53 65 … … 59 71 SphericalSampleGenerator(int numSamples, float radius); 60 72 61 virtual void Generate( Sample2*samples) const;73 virtual void Generate(float *samples) const; 62 74 }; 63 75 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2899 r2900 1032 1032 1033 1033 ShadowMap *sm = showShadowMap ? shadowMap : NULL; 1034 ssaoShader->Render(fbo, oldViewProjMatrix, ssaoExpFactor, sm);1034 ssaoShader->Render(fbo, oldViewProjMatrix, matProjectionView, ssaoExpFactor, sm); 1035 1035 } 1036 1036 … … 1300 1300 break; 1301 1301 case GLUT_KEY_F8: 1302 shadingMethod = (DeferredRenderer::SHADING_METHOD)((shadingMethod + 1) % 3); 1302 //shadingMethod = (DeferredRenderer::SHADING_METHOD)((shadingMethod + 1) % 3); 1303 shadingMethod = (DeferredRenderer::SHADING_METHOD)((shadingMethod + 1) % 2); 1303 1304 1304 1305 break; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r2899 r2900 7 7 // rule of thumb: approx 1 / NUM_SAMPLES 8 8 //#define SAMPLE_INTENSITY 0.14f 9 #define SAMPLE_INTENSITY 0.28f10 //#define SAMPLE_INTENSITY 1.0f9 //#define SAMPLE_INTENSITY 0.28f 10 #define SAMPLE_INTENSITY 0.32f 11 11 12 //#define AREA_SIZE 20e-1f 13 #define AREA_SIZE 5e-1f 12 //#define AREA_SIZE 18e-1f 13 #define AREA_SIZE 8e-1f 14 //#define AREA_SIZE 5e-1f 14 15 15 16 #define VIEW_CORRECTION_SCALE 0.0f
Note: See TracChangeset
for help on using the changeset viewer.