- Timestamp:
- 09/11/08 14:52:51 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r2928 r2930 138 138 switch (sampling) 139 139 { 140 case DeferredRenderer:: POISSON:140 case DeferredRenderer::SAMPLING_POISSON: 141 141 { 142 PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f);142 PoissonDiscSampleGenerator2 poisson(NUM_SAMPLES, 1.0f); 143 143 poisson.Generate((float *)samples2); 144 144 } 145 145 break; 146 case DeferredRenderer:: GAUSS:146 case DeferredRenderer::SAMPLING_QUADRATIC: 147 147 { 148 //PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f); 149 //poisson.Generate((float *)samples2); 150 151 PseudoRandomGenerator pseudo(NUM_SAMPLES, 1.0f); 152 pseudo.Generate((float *)samples2); 148 QuadraticDiscSampleGenerator2 g(NUM_SAMPLES, 1.0f); 149 g.Generate((float *)samples2); 153 150 } 154 151 break; 155 default: 156 cout << "should not come here" << endl; 157 break; 152 default: // SAMPLING_DEFAULT 153 154 RandomSampleGenerator2 g(NUM_SAMPLES, 1.0f); 155 g.Generate((float *)samples2); 158 156 } 159 157 #endif … … 225 223 mUseTemporalCoherence(true), 226 224 mRegenerateSamples(true), 227 mSamplingMethod( POISSON),225 mSamplingMethod(SAMPLING_POISSON), 228 226 mShadingMethod(DEFAULT), 229 227 mFboIndex(0) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r2928 r2930 53 53 void SetUseTemporalCoherence(bool temporal); 54 54 55 enum SAMPLING_METHOD { POISSON, GAUSS};55 enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT}; 56 56 enum SHADING_METHOD {DEFAULT, SSAO, GI}; 57 57 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
r2903 r2930 6 6 using namespace CHCDemoEngine; 7 7 8 HaltonSequence SphericalSampleGenerator::sHalton; 9 HaltonSequence PoissonDiscSampleGenerator::sHalton; 10 HaltonSequence PseudoRandomGenerator::sHalton; 8 HaltonSequence SphericalSampleGenerator3::sHalton; 9 HaltonSequence PoissonDiscSampleGenerator2::sHalton; 10 HaltonSequence RandomSampleGenerator2::sHalton; 11 HaltonSequence QuadraticDiscSampleGenerator2::sHalton; 11 12 12 13 … … 16 17 17 18 18 PoissonDiscSampleGenerator ::PoissonDiscSampleGenerator(int numSamples, float radius):19 PoissonDiscSampleGenerator2::PoissonDiscSampleGenerator2(int numSamples, float radius): 19 20 SampleGenerator(numSamples, radius) 20 21 {} 21 22 22 23 23 void PoissonDiscSampleGenerator ::Generate(float *samples) const24 void PoissonDiscSampleGenerator2::Generate(float *samples) const 24 25 { 25 // this is a hacky poisson sampling generator which does random dart-throwing 26 // until it is not able to place any dart for a number of tries27 // in this case, the required min distance is reduced26 // this is a hacky poisson sampling generator which does random dart-throwing on a disc. 27 // as a savety criterium, the min distance requirement is relaxed if we are not 28 // able to place any dart for a number of tries 28 29 // the solution is a possion sampling with respect to the adjusted min distance 29 30 // better solutions have been proposed, i.e., using hierarchical sampling 30 31 31 const float maxTries = 1000; 32 32 const float f_reduction = 0.9f; … … 36 36 37 37 // generates poisson distribution on disc 38 float minDist = 2.0f * mRadius / sqrt((float)mNumSamples); 38 // start with some threshold. best case: all samples lie on the circumference 39 //const float minDist = 2.0f * mRadius / sqrt((float)mNumSamples); 40 const float eps = 0.2f; 41 const float minDist = 2.0f * mRadius * M_PI * (1.0f - eps) / (float)mNumSamples; 42 float sqrMinDist = minDist * minDist; 39 43 40 44 //cout << "minDist before= " << minDist << endl; 41 45 Sample2 *s = (Sample2 *)samples; 42 46 47 int totalTries = 0; 48 49 // check if on disc 43 50 for (int i = 0; i < mNumSamples; ++ i) 44 51 { 45 int tries = 0 , totalTries = 0;52 int tries = 0; 46 53 47 54 // repeat until valid sample was found … … 51 58 ++ totalTries; 52 59 53 r[0] = RandomValue(0, mRadius); 54 r[1] = RandomValue(0, mRadius); 55 //halton.GetNext(2, r); 60 // note: should use halton, but seems somewhat broken 61 //r[0] = RandomValue(.0f, mRadius); 62 //r[1] = RandomValue(.0f, mRadius); 63 sHalton.GetNext(2, r); 56 64 65 // scale to -1 .. 1 57 66 const float rx = r[0] * 2.0f - 1.0f; 58 67 const float ry = r[1] * 2.0f - 1.0f; … … 68 77 { 69 78 const float dist = 70 sqrt((s[j].x - rx) * (s[j].x - rx) +71 (s[j].y - ry) * (s[j].y - ry));79 (s[j].x - rx) * (s[j].x - rx) + 80 (s[j].y - ry) * (s[j].y - ry); 72 81 73 if (dist < minDist)82 if (dist < sqrMinDist) 74 83 sampleValid = false; 75 84 } … … 84 93 if (tries > maxTries) 85 94 { 86 minDist *= f_reduction;95 sqrMinDist *= f_reduction; 87 96 tries = 0; 88 97 } … … 90 99 } 91 100 92 //cout << "minDist after= " << minDist<< endl;101 //cout << "minDist after= " << sqrt(sqrMinDist) << " #tries: " << totalTries << endl; 93 102 } 94 103 95 104 96 PseudoRandomGenerator::PseudoRandomGenerator(int numSamples, float radius):105 RandomSampleGenerator2::RandomSampleGenerator2(int numSamples, float radius): 97 106 SampleGenerator(numSamples, radius) 98 107 {} 99 108 100 109 101 void PseudoRandomGenerator::Generate(float *samples) const110 void RandomSampleGenerator2::Generate(float *samples) const 102 111 { 103 112 Sample2 *s = (Sample2 *)samples; … … 105 114 int numSamples = 0; 106 115 116 float r[2]; 117 107 118 while (numSamples < mNumSamples) 108 119 { 109 const float rx = RandomValue(-mRadius, +mRadius); 110 const float ry = RandomValue(-mRadius, +mRadius); 120 //r[0] = RandomValue(-mRadius, mRadius); 121 //r[1] = RandomValue(-mRadius, mRadius); 122 sHalton.GetNext(2, r); 123 124 const float rx = r[0] * 2.0f - 1.0f; 125 const float ry = r[1] * 2.0f - 1.0f; 111 126 112 127 // check if in disk, else exit early … … 122 137 123 138 124 SphericalSampleGenerator ::SphericalSampleGenerator(int numSamples, float radius):139 SphericalSampleGenerator3::SphericalSampleGenerator3(int numSamples, float radius): 125 140 SampleGenerator(numSamples, radius) 126 141 {} 127 142 128 143 129 void SphericalSampleGenerator ::Generate(float *samples) const144 void SphericalSampleGenerator3::Generate(float *samples) const 130 145 { 131 146 float r[2]; … … 136 151 r[0] = RandomValue(0, 1); 137 152 r[1] = RandomValue(0, 1); 153 138 154 //sHalton.GetNext(2, r); 139 //r[0] = pSamples[i].x; r[1] = pSamples[i].y;140 155 141 156 // create stratified samples over sphere … … 147 162 s[i].z = mRadius * cos(theta); 148 163 } 164 } 149 165 150 //delete [] pSamples; 166 167 QuadraticDiscSampleGenerator2::QuadraticDiscSampleGenerator2(int numSamples, float radius): 168 SampleGenerator(numSamples, radius) 169 {} 170 171 172 void QuadraticDiscSampleGenerator2::Generate(float *samples) const 173 { 174 float r[2]; 175 Sample2 *s = (Sample2 *)samples; 176 177 for (int i = 0; i < mNumSamples; ++ i) 178 { 179 //r[0] = samples[i * 2]; 180 //r[1] = samples[i * 2 + 1]; 181 sHalton.GetNext(2, r); 182 183 // create samples over disc: the sample density 184 // decreases quadratically with the distance to the origin 185 s[i].x = mRadius * r[1] * sin(2.0f * M_PI * r[0]); 186 s[i].y = mRadius * r[1] * cos(2.0f * M_PI * r[0]); 187 188 //s[i].x = mRadius * r[1] * r[1] * sin(2.0f * M_PI * r[0]); 189 //s[i].y = mRadius * r[1] * r[1] * cos(2.0f * M_PI * r[0]); 190 } 151 191 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h
r2911 r2930 47 47 48 48 49 class PseudoRandomGenerator: public SampleGenerator49 class RandomSampleGenerator2: public SampleGenerator 50 50 { 51 51 public: 52 52 53 PseudoRandomGenerator(int numSamples, float radius);53 RandomSampleGenerator2(int numSamples, float radius); 54 54 55 55 virtual void Generate(float *samples) const; … … 65 65 according to some d related to the number of samples. 66 66 */ 67 class PoissonDiscSampleGenerator : public SampleGenerator67 class PoissonDiscSampleGenerator2: public SampleGenerator 68 68 { 69 69 public: 70 70 71 PoissonDiscSampleGenerator (int numSamples, float radius);71 PoissonDiscSampleGenerator2(int numSamples, float radius); 72 72 73 73 virtual void Generate(float *samples) const; … … 78 78 }; 79 79 80 /** This class generates random spherical samples. 80 81 /** This class generates random samples on a disc 82 that have the property that their density decreases quadratically 83 with the distance 81 84 */ 82 class SphericalSampleGenerator: public SampleGenerator85 class QuadraticDiscSampleGenerator2: public SampleGenerator 83 86 { 84 87 public: 85 88 86 SphericalSampleGenerator(int numSamples, float radius); 89 QuadraticDiscSampleGenerator2(int numSamples, float radius); 90 91 virtual void Generate(float *samples) const; 92 93 protected: 94 95 static HaltonSequence sHalton; 96 }; 97 98 99 /** This class generates random spherical samples. 100 */ 101 class SphericalSampleGenerator3: public SampleGenerator 102 { 103 public: 104 105 SphericalSampleGenerator3(int numSamples, float radius); 87 106 88 107 virtual void Generate(float *samples) const; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2929 r2930 171 171 bool useLODs = true; 172 172 173 DeferredRenderer::SAMPLING_METHOD samplingMethod = DeferredRenderer:: POISSON;173 DeferredRenderer::SAMPLING_METHOD samplingMethod = DeferredRenderer::SAMPLING_POISSON; 174 174 175 175 bool useAdvancedShading = false; … … 1180 1180 case 'P': 1181 1181 case 'p': 1182 if (samplingMethod == DeferredRenderer::GAUSS) 1183 samplingMethod = DeferredRenderer::POISSON; 1184 else 1185 samplingMethod = DeferredRenderer::GAUSS; 1182 samplingMethod = DeferredRenderer::SAMPLING_METHOD((samplingMethod + 1) % 3); 1183 cout << "ssao sampling method: " << samplingMethod << endl; 1186 1184 break; 1187 1185 case 'Y': -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r2905 r2930 10 10 //#define SAMPLE_INTENSITY 40.0f 11 11 12 // for quadradtc falloff 13 //#define SAMPLE_INTENSITY 0.28f 12 // for quadratic falloff 14 13 #define SAMPLE_INTENSITY 0.32f 15 //#define SAMPLE_INTENSITY 2.4f 14 //#define SAMPLE_INTENSITY 0.85f 15 //#define SAMPLE_INTENSITY 5.0f 16 16 17 //#define AREA_SIZE 15e-1f 17 18 //#define AREA_SIZE 25e-1f 18 //#define AREA_SIZE 6e-1f19 19 #define AREA_SIZE 8e-1f 20 //#define AREA_SIZE 5e-1f21 20 22 21 #define VIEW_CORRECTION_SCALE 0.0f 23 22 //#define VIEW_CORRECTION_SCALE 0.1f 24 23 25 //#define DISTANCE_SCALE 5e-7f24 //#define DISTANCE_SCALE 1e-4f 26 25 #define DISTANCE_SCALE 1e-6f 27 //#define DISTANCE_SCALE 0.0f26 //#define DISTANCE_SCALE 1e-8f 28 27 29 28 #define ILLUM_INTENSITY 5e-1f;
Note: See TracChangeset
for help on using the changeset viewer.