Changeset 3227 for GTP/trunk/App
- Timestamp:
- 12/22/08 10:56:58 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
r3226 r3227 41 41 #camDirection=1 0 0 42 42 43 #camPosition=468.025 267.591 182.478 44 #camDirection=0.937282 0.348573 -0 45 46 #camPosition=470.548 265.479 181.578 47 #camDirection=-0.0383892 0.999263 -0 48 49 camPosition=470.541 267.286 181.978 50 camDirection=-0.100954 0.993856 -0.045363 43 camPosition=468.025 267.591 182.478 44 camDirection=0.937282 0.348573 -0 51 45 52 46 #lightDirection=-0.8f 1.0f -0.7f … … 57 51 ## window options 58 52 59 winWidth=80060 winHeight=60053 #winWidth=800 54 #winHeight=600 61 55 62 #winWidth=1024 63 #winHeight=768 64 #winWidth=512 65 #winHeight=384 56 winWidth=1024 57 winHeight=768 66 58 67 59 useFullScreen=0 … … 98 90 ssaoUseFullResolution=1 99 91 # ssao kernel radius 100 ssaoKernelRadius=8e-1f 92 #ssaoKernelRadius=8e-1f 93 ssaoKernelRadius=4e-1f 101 94 # ssao sample intensity 102 ssaoSampleIntensity=0.1f 95 #ssaoSampleIntensity=0.2f 96 ssaoSampleIntensity=1.0f 103 97 # ssao temporal coherence factor 104 98 tempCohFactor=1000.0f -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3222 r3227 198 198 case DeferredRenderer::SAMPLING_POISSON: 199 199 { 200 PoissonDiscSampleGenerator2poisson(NUM_SAMPLES, 1.0f);200 static PoissonDiscSampleGenerator2D poisson(NUM_SAMPLES, 1.0f); 201 201 poisson.Generate((float *)samples2); 202 202 } … … 204 204 case DeferredRenderer::SAMPLING_QUADRATIC: 205 205 { 206 QuadraticDiscSampleGenerator2g(NUM_SAMPLES, 1.0f);206 static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f); 207 207 g.Generate((float *)samples2); 208 208 } … … 210 210 default: // SAMPLING_DEFAULT 211 211 { 212 RandomSampleGenerator2g(NUM_SAMPLES, 1.0f);212 static RandomSampleGenerator2D g(NUM_SAMPLES, 1.0f); 213 213 g.Generate((float *)samples2); 214 214 } … … 220 220 { 221 221 //GLubyte *randomNormals = new GLubyte[mWidth * mHeight * 3]; 222 float *randomNormals = new float[w * h * 3]; 223 224 static HaltonSequence halton; 225 float r[2]; 226 227 for (int i = 0; i < w * h * 3; i += 3) 222 Vector3 *randomNormals = new Vector3[w * h]; 223 224 for (int i = 0; i < w * h; ++ i) 228 225 { 229 226 // create random samples on a circle 230 r[0] = RandomValue(0, 1); 231 //halton.GetNext(1, r); 232 233 const float theta = 2.0f * acos(sqrt(1.0f - r[0])); 234 235 randomNormals[i + 0] = cos(theta); 236 randomNormals[i + 1] = sin(theta); 237 randomNormals[i + 2] = 0; 238 } 227 const float r = RandomValue(0, 1); 228 229 const float theta = 2.0f * acos(sqrt(1.0f - r)); 230 //randomNormals[i] = Vector3(cos(theta), sin(theta), 0); 231 randomNormals[i] = Vector3(RandomValue(-M_PI, M_PI), 0, 0); 232 //Normalize(randomNormals[i]); 233 } 234 239 235 240 236 glEnable(GL_TEXTURE_2D); … … 242 238 glBindTexture(GL_TEXTURE_2D, noiseTex2D); 243 239 244 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 245 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 240 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 241 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 242 243 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 244 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 246 245 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 247 246 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 248 247 249 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, w, h, 0, GL_RGB, GL_FLOAT, randomNormals);248 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, w, h, 0, GL_RGB, GL_FLOAT, (float *)randomNormals); 250 249 251 250 glBindTexture(GL_TEXTURE_2D, 0); … … 257 256 258 257 PrintGLerror("noisetexture"); 259 }260 261 262 static void CreateNoiseTex1D(int w)263 {264 float *randomValues = new float[w * 3];265 266 static HaltonSequence halton;267 268 randomValues[0] = randomValues[1] = randomValues[2] = 0;269 270 for (int i = 3; i < w * 3; i += 3)271 {272 // create random samples on a circle273 randomValues[i + 0] = 20.0f * RandomValue(0, 1) / 512.0f;274 randomValues[i + 1] = 20.0f * RandomValue(0, 1) / 384.0f;275 randomValues[i + 2] = 0;276 }277 278 glEnable(GL_TEXTURE_2D);279 glGenTextures(1, &noiseTex1D);280 glBindTexture(GL_TEXTURE_2D, noiseTex1D);281 282 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);283 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);284 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);285 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);286 287 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, w, 1, 0, GL_RGB, GL_FLOAT, randomValues);288 289 glBindTexture(GL_TEXTURE_2D, 0);290 glDisable(GL_TEXTURE_2D);291 292 delete [] randomValues;293 294 cout << "created noise texture 1D" << endl;295 296 PrintGLerror("noisetexture 1D");297 258 } 298 259 … … 385 346 // for performance reasons we use a smaller texture and repeat it over the screen 386 347 CreateNoiseTex2D(mIllumFbo->GetWidth() / 4, mIllumFbo->GetWidth() / 4); 348 //CreateNoiseTex2D(mIllumFbo->GetWidth(), mIllumFbo->GetWidth()); 387 349 388 350 mProjViewMatrix = IdentityMatrix(); … … 526 488 527 489 float filterWeights[NUM_PCF_TABS]; 528 PoissonDiscSampleGenerator2 poisson2(NUM_PCF_TABS, 1.0f);490 PoissonDiscSampleGenerator2D poisson2(NUM_PCF_TABS, 1.0f); 529 491 poisson2.Generate((float *)pcfSamples); 530 492 … … 625 587 const float filterWidth = 1.0f; 626 588 627 PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f);589 PoissonDiscSampleGenerator2D poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f); 628 590 poisson.Generate((float *)ssaoFilterOffsets); 629 591 … … 777 739 sCgSsaoProgram->SetTexture(i ++, attribsTex); 778 740 sCgSsaoProgram->SetValue1f(i ++, mKernelRadius); 779 sCgSsaoProgram->SetValue1f(i ++, mSampleIntensity );741 sCgSsaoProgram->SetValue1f(i ++, mSampleIntensity * mKernelRadius); 780 742 781 743 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Halton.cpp
r2839 r3227 3 3 4 4 5 float Halton2::_invBases[2];6 5 7 template<int T> float Halton<T>::_invBases[T]; 8 9 Halton<1> dummmyHalton1(true); 10 Halton<2> dummmyHalton2(true); 11 Halton<3> dummmyHalton3(true); 12 Halton<4> dummmyHalton4(true); 13 Halton<5> dummmyHalton5(true); 14 Halton<6> dummmyHalton6(true); 6 void Halton::TestHalton(int n, int dim) 7 { 8 Halton h(dim); 15 9 16 17 int HaltonSequence::sPregeneratedDim = 0; 18 int HaltonSequence::sPregeneratedNumber = 0; 19 float *HaltonSequence::sPregeneratedValues = NULL; 20 21 22 // special construtor for pregenerating static halton sequences 23 HaltonSequence::HaltonSequence(const int dim, const int number) 24 { 25 26 sPregeneratedDim = 0; 27 sPregeneratedNumber = 0; 28 sPregeneratedValues = new float[number*dim]; 29 30 float *p = sPregeneratedValues; 31 32 for (int i=0; i < number; i++, p+=dim) 10 for (int i = 1; i <= n; ++ i) 33 11 { 34 GetNext(dim, p);12 std::cout << "halton " << i << " of dim " << dim << " = " << h.GetNext() << std::endl; 35 13 } 36 37 sPregeneratedDim = dim;38 sPregeneratedNumber = number;39 14 } 40 15 41 16 42 void Halton Sequence::GetNext(const int dimensions, float *p)17 void Halton::TestPrime() 43 18 { 44 for (int i = 0; i < dimensions; ++ i) 45 p[i] = (float)GetNumber(i + 1); 19 int dim = 2; 46 20 47 GenerateNext(); 21 for (int i = 1; i < 10; ++ i) 22 { 23 std::cout << "prime for dim " << i << " " << Halton::FindPrime(i) << std::endl; 24 } 48 25 } 26 27 28 Halton::Halton(int dim): mIndex(0) 29 { 30 mBase = FindPrime(dim); 31 } 32 33 34 float Halton::GetNext() 35 { 36 ++ mIndex; 37 38 float result = .0f; 39 float fraction = 1.0f / (float)mBase; 40 int idx = mIndex; 41 42 while (idx > 0) 43 { 44 int digit = idx % mBase; 45 result += fraction * (float)digit; 46 47 idx = (idx - digit) / mBase; 48 fraction /= (float)mBase; 49 } 50 51 mIndex %= 100000000; 52 return result; 53 } 54 55 56 bool Halton::IsPrime(int n) 57 { 58 bool isPrime = true; 59 60 for (int i = 2; i < n; ++ i) 61 { 62 if (n % i == 0) 63 { 64 isPrime = false; 65 break; 66 } 67 } 68 69 return isPrime; 70 } 71 72 73 int Halton::FindPrime(int idx) 74 { 75 if (idx < 1) 76 { 77 std::cerr << "error: cannot find " << idx << "th prime" << std::endl; 78 return 0; 79 } 80 81 // only even prime number 82 if (idx == 1) return 2; 83 84 int number = 3; 85 int primeFound = 1; 86 87 while (1) 88 { 89 if (IsPrime(number)) ++ primeFound; 90 if (primeFound == idx) break; 91 92 number += 2; 93 } 94 95 return number; 96 } 97 98 99 void HaltonSequence::TestHalton(int n, int dim) 100 { 101 HaltonSequence h(dim); 102 float *haltons = new float[dim]; 103 104 for (int i = 1; i <= n; ++ i) 105 { 106 h.GetNext(haltons); 107 std::cout << "halton " << i << " of dim " << dim << " = "; 108 109 for (int j = 0; j < dim; ++ j) 110 std::cout << haltons[j] << " "; 111 112 std::cout << std::endl; 113 } 114 } 115 116 117 HaltonSequence::HaltonSequence(int dim) 118 { 119 for (int i = 0; i < dim; ++ i) 120 { 121 mHaltons.push_back(Halton(i + 1)); 122 } 123 } 124 125 126 void HaltonSequence::GetNext(float *numbers) 127 { 128 for (size_t i = 0; i < mHaltons.size(); ++ i) 129 { 130 numbers[i] = mHaltons[i].GetNext(); 131 } 132 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Halton.h
r3129 r3227 3 3 4 4 #include <iostream> 5 #include <vector> 6 7 class Halton 8 { 9 public: 10 11 static void TestHalton(int n, int dim); 12 13 static void TestPrime(); 5 14 6 15 7 /** Assert whether the argument is a prime number. 8 @param number the number to be checked 9 */ 10 inline bool IsPrime(const int number) 11 { 12 bool isIt = true; 13 14 for(int i = 2; i < number; ++ i) 15 { 16 if(number % i == 0) 17 { 18 isIt = false; 19 break; 20 } 21 } 22 23 if(number == 2) 24 { 25 isIt = false; 26 } 27 28 return isIt; 29 } 16 Halton(int dim); 30 17 31 18 32 /** 33 Find the nth prime number. 34 @param index the ordinal position in the sequence 35 */ 36 inline int FindPrime(const int index) 37 { 38 39 const int primes[] = {-1, 1, 3, 5, 7, 11, 13}; 40 if (index <= 6) 41 return primes[index]; 42 43 int prime = 1; 44 int found = 1; 45 while(found != index) { 46 prime += 2; 47 if(IsPrime(prime) == true) { 48 found++; 49 } 50 } 51 return prime; 52 } 53 54 55 inline float halton(float baseRec, float prev) 56 { 57 float r = 1.0f - prev; 58 59 if (baseRec < r) 60 return prev + baseRec; 61 62 float h = baseRec; 63 64 float hh; 65 66 do 67 { 68 hh = h; 69 h *= baseRec; 70 } while (h > r); 71 72 return prev + hh + h - 1.0f; 73 } 19 float GetNext(); 74 20 75 21 76 template<int T> struct Halton 22 protected: 23 24 static bool IsPrime(int n); 25 26 static int FindPrime(int idx); 27 28 29 //////////////////// 30 31 unsigned int mIndex; 32 int mBase; 33 }; 34 35 36 class HaltonSequence 77 37 { 78 static float _invBases[T];79 float _prev[T];80 81 38 public: 82 39 83 void Reset() 84 { 85 for (int i=0; i < T; i++) 86 _prev[i] = 0; 87 } 40 static void TestHalton(int n, int dim); 88 41 89 Halton(const bool initializeBases) 90 { 91 for (int i=0; i < T; i++) 92 { 93 int base = FindPrime(i+1); 94 95 if (base == 1) 96 base++; 97 _invBases[i] = 1.0f/base; 98 } 99 } 42 HaltonSequence(int dim); 100 43 101 Halton() 102 { 103 Reset(); 104 } 105 106 void GetNext(float *a) 107 { 108 for (int i=0; i < T; i++) 109 { 110 a[i] = halton(_invBases[i], _prev[i]); 111 _prev[i] = a[i]; 112 } 113 } 114 115 }; 116 117 struct Halton2 118 { 119 static float _invBases[2]; 120 float _prev[2]; 121 122 public: 123 124 void Reset() 125 { 126 _prev[0] =_prev[1] = 0; 127 } 128 129 Halton2() 130 { 131 _invBases[0] = 1.0f / 2; 132 _invBases[1] = 1.0f / 3; 133 Reset(); 134 } 135 136 void GetNext(float &a, float &b) 137 { 138 a = halton(_invBases[0], _prev[0]); 139 b = halton(_invBases[1], _prev[1]); 140 141 _prev[0] = a; 142 _prev[1] = b; 143 } 144 }; 44 void GetNext(float *numbers); 145 45 146 46 147 148 struct HaltonSequence 149 { 150 public: 151 int index; 47 protected: 152 48 153 static int sPregeneratedDim; 154 static int sPregeneratedNumber; 155 static float *sPregeneratedValues; 156 157 // special construtor for pregenerating static halton sequences 158 HaltonSequence(int dim, int number); 159 160 HaltonSequence(): index(1) 161 { 162 float dummy[2]; 163 for (int i = 0; i < 20; ++ i) GetNext(2, dummy); 164 } 165 166 void Reset() { index = 1; } 167 168 void GetNext(int dimensions, float *p); 169 170 void GenerateNext() { ++ index; } 171 172 double GetNumber(const int dimension) 173 { 174 int base = FindPrime(dimension); 175 if (base == 1) 176 { 177 base++; // The first dimension uses base 2. 178 } 179 180 int _p1 = base; 181 float _ip1 = 1.0f / base; 182 float p, u=0.0f; 183 int kk, a; 184 185 // the first coordinate 186 for (p = _ip1, kk = index ; kk ; p *= _ip1, kk /= _p1) 187 if ((a = kk % _p1)) 188 u += a * p; 189 190 return u; 191 } 192 193 /** 194 Returns the nth number in the sequence, taken from a specified dimension. 195 @param index the ordinal position in the sequence 196 @param dimension the dimension 197 */ 198 double GetNumberOld(int dimension) 199 { 200 int base = FindPrime(dimension); 201 if(base == 1) 202 { 203 ++ base; //The first dimension uses base 2. 204 } 205 206 double remainder; 207 double output = 0.0; 208 double fraction = 1.0 / (double)base; 209 int N1 = 0; 210 int copyOfIndex = index; 211 212 if ((base >= 2) && (index >= 1)) 213 { 214 while (copyOfIndex > 0) 215 { 216 N1 = (copyOfIndex / base); 217 remainder = copyOfIndex % base; 218 output += fraction * remainder; 219 copyOfIndex = (int)(copyOfIndex / base); 220 fraction /= (double)base; 221 } 222 return output; 223 } 224 else 225 { 226 std::cerr << "Error generating Halton sequence." << std::endl; 227 exit(1); 228 } 229 } 49 std::vector<Halton> mHaltons; 230 50 }; 231 51 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
r3221 r3227 6 6 using namespace CHCDemoEngine; 7 7 8 HaltonSequence SphericalSampleGenerator3::sHalton; 9 HaltonSequence PoissonDiscSampleGenerator2::sHalton; 10 HaltonSequence RandomSampleGenerator2::sHalton; 11 HaltonSequence QuadraticDiscSampleGenerator2::sHalton; 8 HaltonSequence PoissonDiscSampleGenerator2D::sHalton(2); 9 HaltonSequence RandomSampleGenerator2D::sHalton(2); 10 HaltonSequence QuadraticDiscSampleGenerator2D::sHalton(2); 12 11 13 12 … … 17 16 18 17 19 PoissonDiscSampleGenerator2 ::PoissonDiscSampleGenerator2(int numSamples, float radius):20 SampleGenerator(numSamples, radius) 21 {} 22 23 24 void PoissonDiscSampleGenerator2 ::Generate(float *samples) const18 PoissonDiscSampleGenerator2D::PoissonDiscSampleGenerator2D(int numSamples, float radius): 19 SampleGenerator(numSamples, radius) 20 {} 21 22 23 void PoissonDiscSampleGenerator2D::Generate(float *samples) const 25 24 { 26 25 // this is a hacky poisson sampling generator which does random dart-throwing on a disc. … … 32 31 const float f_reduction = 0.9f; 33 32 34 //static HaltonSequence halton; 33 35 34 float r[2]; 36 35 … … 59 58 60 59 // 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); 60 sHalton.GetNext(r); 64 61 65 62 // scale to -1 .. 1 … … 72 69 if ((rx * rx + ry * ry > mRadius * mRadius) 73 70 // also avoid case that sample exactly in center 74 || (distanceSquared <= 1e-3f)71 //|| (distanceSquared <= 1e-3f) 75 72 ) 76 73 continue; … … 108 105 109 106 110 RandomSampleGenerator2 ::RandomSampleGenerator2(int numSamples, float radius):111 SampleGenerator(numSamples, radius) 112 {} 113 114 115 void RandomSampleGenerator2 ::Generate(float *samples) const107 RandomSampleGenerator2D::RandomSampleGenerator2D(int numSamples, float radius): 108 SampleGenerator(numSamples, radius) 109 {} 110 111 112 void RandomSampleGenerator2D::Generate(float *samples) const 116 113 { 117 114 Sample2 *s = (Sample2 *)samples; … … 123 120 while (numSamples < mNumSamples) 124 121 { 125 //r[0] = RandomValue(-mRadius, mRadius); 126 //r[1] = RandomValue(-mRadius, mRadius); 127 sHalton.GetNext(2, r); 122 sHalton.GetNext(r); 128 123 129 124 const float rx = r[0] * 2.0f - 1.0f; … … 142 137 143 138 144 SphericalSampleGenerator3 ::SphericalSampleGenerator3(int numSamples, float radius):145 SampleGenerator(numSamples, radius) 146 {} 147 148 149 void SphericalSampleGenerator3 ::Generate(float *samples) const139 SphericalSampleGenerator3D::SphericalSampleGenerator3D(int numSamples, float radius): 140 SampleGenerator(numSamples, radius) 141 {} 142 143 144 void SphericalSampleGenerator3D::Generate(float *samples) const 150 145 { 151 146 float r[2]; … … 156 151 r[0] = RandomValue(0, 1); 157 152 r[1] = RandomValue(0, 1); 158 159 //sHalton.GetNext(2, r);160 153 161 154 // create stratified samples over sphere … … 170 163 171 164 172 QuadraticDiscSampleGenerator2 ::QuadraticDiscSampleGenerator2(int numSamples, float radius):173 SampleGenerator(numSamples, radius) 174 {} 175 176 177 void QuadraticDiscSampleGenerator2 ::Generate(float *samples) const165 QuadraticDiscSampleGenerator2D::QuadraticDiscSampleGenerator2D(int numSamples, float radius): 166 SampleGenerator(numSamples, radius) 167 {} 168 169 170 void QuadraticDiscSampleGenerator2D::Generate(float *samples) const 178 171 { 179 172 #if 0 … … 183 176 for (int i = 0; i < mNumSamples; ++ i) 184 177 { 185 //r[0] = samples[i * 2]; 186 //r[1] = samples[i * 2 + 1]; 187 sHalton.GetNext(2, r); 178 sHalton.GetNext(r); 188 179 189 180 // create samples over disc: the sample density … … 194 185 #else 195 186 196 PoissonDiscSampleGenerator2poisson(mNumSamples, 1.0f);187 static PoissonDiscSampleGenerator2D poisson(mNumSamples, 1.0f); 197 188 poisson.Generate(samples); 198 189 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h
r2930 r3227 47 47 48 48 49 class RandomSampleGenerator2 : public SampleGenerator49 class RandomSampleGenerator2D: public SampleGenerator 50 50 { 51 51 public: 52 52 53 RandomSampleGenerator2 (int numSamples, float radius);53 RandomSampleGenerator2D(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 PoissonDiscSampleGenerator2 : public SampleGenerator67 class PoissonDiscSampleGenerator2D: public SampleGenerator 68 68 { 69 69 public: 70 70 71 PoissonDiscSampleGenerator2 (int numSamples, float radius);71 PoissonDiscSampleGenerator2D(int numSamples, float radius); 72 72 73 73 virtual void Generate(float *samples) const; … … 83 83 with the distance 84 84 */ 85 class QuadraticDiscSampleGenerator2 : public SampleGenerator85 class QuadraticDiscSampleGenerator2D: public SampleGenerator 86 86 { 87 87 public: 88 88 89 QuadraticDiscSampleGenerator2 (int numSamples, float radius);89 QuadraticDiscSampleGenerator2D(int numSamples, float radius); 90 90 91 91 virtual void Generate(float *samples) const; … … 99 99 /** This class generates random spherical samples. 100 100 */ 101 class SphericalSampleGenerator3 : public SampleGenerator101 class SphericalSampleGenerator3D: public SampleGenerator 102 102 { 103 103 public: 104 104 105 SphericalSampleGenerator3 (int numSamples, float radius);105 SphericalSampleGenerator3D(int numSamples, float radius); 106 106 107 107 virtual void Generate(float *samples) const; 108 109 protected:110 111 static HaltonSequence sHalton;112 108 }; 113 109 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3226 r3227 58 58 #include "WalkThroughRecorder.h" 59 59 #include "StatsWriter.h" 60 #include "Halton.h" 60 61 61 62 … … 645 646 646 647 // this function assign the render queue bucket ids of the materials in beforehand 647 // => probably a littleless overhead for new parts of the scene that are not yet assigned648 // => probably less overhead for new parts of the scene that are not yet assigned 648 649 PrepareRenderQueue(); 649 650 /// forward rendering is the default … … 651 652 // frame time is restarted every frame 652 653 frameTimer.Start(); 654 655 Halton::TestHalton(7, 1); 656 Halton::TestHalton(7, 2); 657 658 HaltonSequence::TestHalton(15, 2); 659 HaltonSequence::TestHalton(15, 1); 660 661 Halton::TestPrime(); 653 662 654 663 // the rendering loop … … 1405 1414 break; 1406 1415 case '7': 1407 ssaoTempCohFactor *= 0.5f;1416 ssaoTempCohFactor *= 1.0f / 1.2f; 1408 1417 cout << "new temporal coherence factor: " << ssaoTempCohFactor << endl; 1409 1418 break; 1410 1419 case '8': 1411 ssaoTempCohFactor *= 2.0f;1420 ssaoTempCohFactor *= 1.2f; 1412 1421 cout << "new temporal coherence factor: " << ssaoTempCohFactor << endl; 1413 1422 break; … … 1417 1426 break; 1418 1427 case '0': 1419 ssaoKernelRadius *= 1. 2f;1428 ssaoKernelRadius *= 1.0f / 0.8f; 1420 1429 cout << "new ssao kernel radius: " << ssaoKernelRadius << endl; 1421 1430 break; … … 1425 1434 break; 1426 1435 case 'N': 1427 ssaoSampleIntensity *= 1. 1f;1436 ssaoSampleIntensity *= 1.0f / 0.9f; 1428 1437 cout << "new ssao sample intensity: " << ssaoSampleIntensity << endl; 1429 1438 break; … … 1433 1442 break; 1434 1443 case 'O': 1435 ssaoFilterRadius *= 1. 1f;1444 ssaoFilterRadius *= 1.0f / 0.9f; 1436 1445 cout << "new ssao filter radius: " << ssaoFilterRadius << endl; 1437 1446 break; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3226 r3227 21 21 22 22 #define SSAO_CONVERGENCE_THRESHOLD 700.0f 23 //#define SSAO_CONVERGENCE_THRESHOLD 1500.0f 23 24 24 25 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/common.h
r3213 r3227 45 45 return rpt; 46 46 } 47 48 49 50 51 inline float2 myrotate(float2 pt, float angle) 52 { 53 float2 rpt; 54 55 rpt.x = pt.x * cos(angle) - pt.y * sin(angle); 56 rpt.y = pt.y * cos(angle) + pt.x * sin(angle); 57 58 //normalize(rpt); 59 return rpt; 60 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3226 r3227 229 229 230 230 // compute position from old frame for dynamic objects + translational portion 231 const float3 translatedPos = difVec - oldEyePos + worldPos.xyz; 231 //const float3 translatedPos = difVec - oldEyePos + worldPos.xyz; 232 const float3 translatedPos = - oldEyePos + worldPos.xyz; 232 233 233 234 … … 275 276 pixelValid = pixelNotValid; 276 277 } 277 else if ( 278 else if (!((oldEyeSpaceDepth > 1e10f) || (projectedEyeSpaceDepth > 1e10f)) && 278 279 // check if changed from dynamic to not dynamic object 279 ( oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) ||280 ((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 280 281 // check if we have a dynamic object and is a depth discontinuity 281 ((oldDynamic || newDynamic) && (depthDif <= MIN_DEPTH_DIFF))) 282 ( 283 //(oldDynamic || newDynamic) && 284 (depthDif > MIN_DEPTH_DIFF)))) 282 285 { 283 286 pixelValid = pixelCouldBeValid; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3226 r3227 1 1 #include "../shaderenv.h" 2 2 #include "common.h" 3 3 4 4 //////////////////// … … 28 28 } 29 29 30 31 inline float SqrLen(float3 v)32 {33 return v.x * v.x + v.y * v.y + v.z * v.z;34 }35 36 37 inline float2 myreflect(float2 pt, float2 n)38 {39 // distance to plane40 float d = dot(n, pt);41 // reflect around plane42 float2 rpt = pt - d * 2.0f * n;43 44 return rpt;45 }46 47 48 inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr)49 {50 float3 x1 = lerp(bl, tl, w.y);51 float3 x2 = lerp(br, tr, w.y);52 float3 v = lerp(x1, x2, w.x);53 54 return v;55 }56 30 57 31 … … 225 199 total_ao /= numSamples; 226 200 227 #if 0201 #if 1 228 202 // if surface normal perpenticular to view dir, approx. half of the samples will not count 229 203 // => compensate for this (on the other hand, projected sampling area could be larger!) 230 204 const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * max(dot(viewDir, normal), 0.0f); 231 total_ao *=viewCorrection;205 total_ao += cosAngle * aoContrib * viewCorrection; 232 206 233 207 #endif 234 208 235 //return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples); 236 return float3(total_ao, validSamples, numSamples); 209 return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples); 237 210 } 238 211 … … 261 234 float newWeight, 262 235 float sampleIntensity, 263 bool isMovingObject, 264 sampler2D normalTex 236 bool isMovingObject 265 237 ) 266 238 { … … 273 245 const float2 offset = samples[i]; 274 246 275 #if 1 247 float2 offsetTransformed; 248 276 249 //////////////////// 277 250 //-- add random noise: reflect around random normal vector 278 //-- ( slows down the computationfor some reason!)251 //-- (affects performance for some reason!) 279 252 280 253 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 281 const float2 offsetTransformed = myreflect(offset, mynoise);282 #else 283 const float2 offsetTransformed = offset;284 #endif 254 //float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord, 0, 0)).xy; 255 //offsetTransformed = myreflect(offset, mynoise); 256 offsetTransformed = myrotate(offset, mynoise.x); 257 285 258 // weight with projected coordinate to reach similar kernel size for near and far 286 259 const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor; … … 290 263 291 264 292 // the normal of the current sample293 //const float3 sampleNormal = tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz;294 // angle between current normal and direction to sample controls AO intensity.295 //float cosAngle2 = .5f + dot(sampleNormal, -normal) * 0.5f;296 297 265 //////////////// 298 266 //-- compute contribution of sample using the direction and angle … … 300 268 float3 dirSample = samplePos - centerPosition; 301 269 302 const float sqrLen = max(SqrLen(dirSample), 1e-2f); 303 const float lengthToSample = sqrt(sqrLen); 270 //const float sqrLen = max(SqrLen(dirSample), 1e-2f); 271 //const float lengthToSample = sqrt(sqrLen); 272 const float lengthToSample = max(length(dirSample), 1e-2f); 304 273 305 274 dirSample /= lengthToSample; // normalize 306 275 307 276 // angle between current normal and direction to sample controls AO intensity. 308 const float cosAngle = max(dot(dirSample, normal), .0f); 309 const float aoContrib = sampleIntensity / sqrLen; 277 float cosAngle = dot(dirSample, normal); 278 279 //const float aoContrib = sampleIntensity / sqrLen; 280 const float aoContrib = sampleIntensity / lengthToSample; 310 281 //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 311 282 312 //total_ao += cosAngle2 * cosAngle * aoContrib; 313 total_ao += cosAngle * aoContrib; 283 total_ao += max(cosAngle, 0) * aoContrib; 314 284 315 285 ++ numSamples; … … 324 294 // to have any influence in the current or last frame 325 295 const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 326 validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid );327 328 #if 1//#ifdef U//USE_GTX296 validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid * step(-0.1f, cosAngle)); 297 298 #ifdef USE_GTX 329 299 // we can bail out early and use a minimal #samples) 330 300 // if some conditions are met as long as the hardware supports it … … 351 321 352 322 return float3(total_ao, validSamples, numSamples); 353 //return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples);354 323 } 355 324 … … 426 395 if (eyeSpaceDepth < 1e10f) 427 396 { 428 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject , normals);397 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 429 398 //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity); 430 399 } … … 460 429 } 461 430 431 ////////// 432 //-- blend ao between old and new samples (and avoid division by zero) 433 434 OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight);// / (newWeight + oldWeight);//max(1e-6f, newWeight + oldWeight); 435 436 OUT.illum_col.x /= (newWeight + oldWeight); 437 462 438 // the new weight for the next frame 463 439 const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence); 464 465 466 //////////467 //-- blend ao between old and new samples (and avoid division by zero)468 469 //OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / max(1e-6f, newWeight + oldWeight);470 OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / (newWeight + oldWeight);471 440 472 441 OUT.illum_col.y = combinedWeight;
Note: See TracChangeset
for help on using the changeset viewer.