Changeset 3227


Ignore:
Timestamp:
12/22/08 10:56:58 (15 years ago)
Author:
mattausch
Message:

worked on sampling / convergence

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env

    r3226 r3227  
    4141#camDirection=1 0 0 
    4242 
    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 
     43camPosition=468.025 267.591 182.478 
     44camDirection=0.937282 0.348573 -0 
    5145 
    5246#lightDirection=-0.8f 1.0f -0.7f 
     
    5751## window options 
    5852 
    59 winWidth=800 
    60 winHeight=600 
     53#winWidth=800 
     54#winHeight=600 
    6155 
    62 #winWidth=1024 
    63 #winHeight=768 
    64 #winWidth=512 
    65 #winHeight=384 
     56winWidth=1024 
     57winHeight=768 
    6658 
    6759useFullScreen=0 
     
    9890ssaoUseFullResolution=1 
    9991# ssao kernel radius 
    100 ssaoKernelRadius=8e-1f 
     92#ssaoKernelRadius=8e-1f 
     93ssaoKernelRadius=4e-1f 
    10194# ssao sample intensity 
    102 ssaoSampleIntensity=0.1f 
     95#ssaoSampleIntensity=0.2f 
     96ssaoSampleIntensity=1.0f 
    10397# ssao temporal coherence factor 
    10498tempCohFactor=1000.0f 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3222 r3227  
    198198        case DeferredRenderer::SAMPLING_POISSON: 
    199199                { 
    200                         PoissonDiscSampleGenerator2 poisson(NUM_SAMPLES, 1.0f); 
     200                        static PoissonDiscSampleGenerator2D poisson(NUM_SAMPLES, 1.0f); 
    201201                        poisson.Generate((float *)samples2); 
    202202                } 
     
    204204        case DeferredRenderer::SAMPLING_QUADRATIC: 
    205205                { 
    206                         QuadraticDiscSampleGenerator2 g(NUM_SAMPLES, 1.0f); 
     206                        static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f); 
    207207                        g.Generate((float *)samples2); 
    208208                } 
     
    210210        default: // SAMPLING_DEFAULT 
    211211                { 
    212                         RandomSampleGenerator2 g(NUM_SAMPLES, 1.0f); 
     212                        static RandomSampleGenerator2D g(NUM_SAMPLES, 1.0f); 
    213213                        g.Generate((float *)samples2); 
    214214                } 
     
    220220{ 
    221221        //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) 
    228225        { 
    229226                // 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 
    239235 
    240236        glEnable(GL_TEXTURE_2D); 
     
    242238        glBindTexture(GL_TEXTURE_2D, noiseTex2D); 
    243239                 
    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); 
    246245        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
    247246        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
    248247 
    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); 
    250249 
    251250        glBindTexture(GL_TEXTURE_2D, 0); 
     
    257256 
    258257        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 circle 
    273                 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"); 
    297258} 
    298259 
     
    385346        // for performance reasons we use a smaller texture and repeat it over the screen 
    386347        CreateNoiseTex2D(mIllumFbo->GetWidth() / 4, mIllumFbo->GetWidth() / 4); 
     348        //CreateNoiseTex2D(mIllumFbo->GetWidth(), mIllumFbo->GetWidth()); 
    387349         
    388350        mProjViewMatrix = IdentityMatrix(); 
     
    526488 
    527489        float filterWeights[NUM_PCF_TABS]; 
    528         PoissonDiscSampleGenerator2 poisson2(NUM_PCF_TABS, 1.0f); 
     490        PoissonDiscSampleGenerator2D poisson2(NUM_PCF_TABS, 1.0f); 
    529491        poisson2.Generate((float *)pcfSamples); 
    530492 
     
    625587        const float filterWidth = 1.0f; 
    626588 
    627         PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f); 
     589        PoissonDiscSampleGenerator2D poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f); 
    628590        poisson.Generate((float *)ssaoFilterOffsets); 
    629591 
     
    777739        sCgSsaoProgram->SetTexture(i ++, attribsTex); 
    778740        sCgSsaoProgram->SetValue1f(i ++, mKernelRadius); 
    779         sCgSsaoProgram->SetValue1f(i ++, mSampleIntensity); 
     741        sCgSsaoProgram->SetValue1f(i ++, mSampleIntensity * mKernelRadius); 
    780742 
    781743 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Halton.cpp

    r2839 r3227  
    33 
    44 
    5 float Halton2::_invBases[2]; 
    65 
    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); 
     6void Halton::TestHalton(int n, int dim) 
     7{ 
     8        Halton h(dim); 
    159 
    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) 
    3311        { 
    34                 GetNext(dim, p); 
     12                std::cout << "halton " << i << " of dim " << dim << " = " << h.GetNext() << std::endl; 
    3513        } 
    36  
    37         sPregeneratedDim = dim; 
    38         sPregeneratedNumber = number; 
    3914} 
    4015 
    4116 
    42 void HaltonSequence::GetNext(const int dimensions, float *p) 
     17void Halton::TestPrime() 
    4318{ 
    44         for (int i = 0; i < dimensions; ++ i) 
    45                 p[i] = (float)GetNumber(i + 1); 
     19        int dim = 2; 
    4620 
    47         GenerateNext(); 
     21        for (int i = 1; i < 10; ++ i) 
     22        { 
     23                std::cout << "prime for dim " << i << " " << Halton::FindPrime(i) << std::endl; 
     24        } 
    4825} 
     26 
     27 
     28Halton::Halton(int dim): mIndex(0) 
     29{ 
     30        mBase = FindPrime(dim); 
     31} 
     32 
     33 
     34float 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 
     56bool 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 
     73int 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 
     99void 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 
     117HaltonSequence::HaltonSequence(int dim) 
     118{ 
     119        for (int i = 0; i < dim; ++ i) 
     120        { 
     121                mHaltons.push_back(Halton(i + 1)); 
     122        } 
     123} 
     124 
     125 
     126void 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  
    33 
    44#include <iostream> 
     5#include <vector> 
     6 
     7class Halton  
     8{ 
     9public: 
     10 
     11        static void TestHalton(int n, int dim); 
     12 
     13        static void TestPrime(); 
    514 
    615 
    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); 
    3017 
    3118 
    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(); 
    7420 
    7521 
    76 template<int T> struct Halton  
     22protected: 
     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 
     36class HaltonSequence 
    7737{ 
    78         static float _invBases[T]; 
    79         float _prev[T]; 
    80  
    8138public: 
    8239 
    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); 
    8841 
    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); 
    10043 
    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); 
    14545 
    14646 
    147    
    148 struct HaltonSequence  
    149 { 
    150 public: 
    151         int index; 
     47protected: 
    15248 
    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; 
    23050}; 
    23151 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp

    r3221 r3227  
    66using namespace CHCDemoEngine; 
    77 
    8 HaltonSequence SphericalSampleGenerator3::sHalton; 
    9 HaltonSequence PoissonDiscSampleGenerator2::sHalton; 
    10 HaltonSequence RandomSampleGenerator2::sHalton; 
    11 HaltonSequence QuadraticDiscSampleGenerator2::sHalton; 
     8HaltonSequence PoissonDiscSampleGenerator2D::sHalton(2); 
     9HaltonSequence RandomSampleGenerator2D::sHalton(2); 
     10HaltonSequence QuadraticDiscSampleGenerator2D::sHalton(2); 
    1211 
    1312 
     
    1716 
    1817 
    19 PoissonDiscSampleGenerator2::PoissonDiscSampleGenerator2(int numSamples, float radius): 
    20 SampleGenerator(numSamples, radius) 
    21 {} 
    22  
    23  
    24 void PoissonDiscSampleGenerator2::Generate(float *samples) const 
     18PoissonDiscSampleGenerator2D::PoissonDiscSampleGenerator2D(int numSamples, float radius): 
     19SampleGenerator(numSamples, radius) 
     20{} 
     21 
     22 
     23void PoissonDiscSampleGenerator2D::Generate(float *samples) const 
    2524{ 
    2625        // this is a hacky poisson sampling generator which does random dart-throwing on a disc. 
     
    3231        const float f_reduction = 0.9f; 
    3332 
    34         //static HaltonSequence halton; 
     33 
    3534        float r[2]; 
    3635 
     
    5958 
    6059                        // 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); 
    6461 
    6562                        // scale to -1 .. 1 
     
    7269                        if ((rx * rx + ry * ry > mRadius * mRadius)  
    7370                                // also avoid case that sample exactly in center                         
    74                                 || (distanceSquared <= 1e-3f) 
     71                                //|| (distanceSquared <= 1e-3f) 
    7572                                ) 
    7673                                continue; 
     
    108105 
    109106 
    110 RandomSampleGenerator2::RandomSampleGenerator2(int numSamples, float radius): 
    111 SampleGenerator(numSamples, radius) 
    112 {} 
    113  
    114  
    115 void RandomSampleGenerator2::Generate(float *samples) const 
     107RandomSampleGenerator2D::RandomSampleGenerator2D(int numSamples, float radius): 
     108SampleGenerator(numSamples, radius) 
     109{} 
     110 
     111 
     112void RandomSampleGenerator2D::Generate(float *samples) const 
    116113{ 
    117114        Sample2 *s = (Sample2 *)samples; 
     
    123120        while (numSamples < mNumSamples) 
    124121        { 
    125                 //r[0] = RandomValue(-mRadius, mRadius); 
    126                 //r[1] = RandomValue(-mRadius, mRadius); 
    127                 sHalton.GetNext(2, r); 
     122                sHalton.GetNext(r); 
    128123                 
    129124                const float rx = r[0] * 2.0f - 1.0f; 
     
    142137 
    143138 
    144 SphericalSampleGenerator3::SphericalSampleGenerator3(int numSamples, float radius): 
    145 SampleGenerator(numSamples, radius) 
    146 {} 
    147  
    148  
    149 void SphericalSampleGenerator3::Generate(float *samples) const 
     139SphericalSampleGenerator3D::SphericalSampleGenerator3D(int numSamples, float radius): 
     140SampleGenerator(numSamples, radius) 
     141{} 
     142 
     143 
     144void SphericalSampleGenerator3D::Generate(float *samples) const 
    150145{ 
    151146        float r[2]; 
     
    156151                r[0] = RandomValue(0, 1); 
    157152                r[1] = RandomValue(0, 1); 
    158  
    159                 //sHalton.GetNext(2, r); 
    160153 
    161154                // create stratified samples over sphere 
     
    170163 
    171164 
    172 QuadraticDiscSampleGenerator2::QuadraticDiscSampleGenerator2(int numSamples, float radius): 
    173 SampleGenerator(numSamples, radius) 
    174 {} 
    175  
    176  
    177 void QuadraticDiscSampleGenerator2::Generate(float *samples) const 
     165QuadraticDiscSampleGenerator2D::QuadraticDiscSampleGenerator2D(int numSamples, float radius): 
     166SampleGenerator(numSamples, radius) 
     167{} 
     168 
     169 
     170void QuadraticDiscSampleGenerator2D::Generate(float *samples) const 
    178171{ 
    179172#if 0 
     
    183176        for (int i = 0; i < mNumSamples; ++ i) 
    184177        { 
    185                 //r[0] = samples[i * 2]; 
    186                 //r[1] = samples[i * 2 + 1]; 
    187                 sHalton.GetNext(2, r); 
     178                sHalton.GetNext(r); 
    188179 
    189180                // create samples over disc: the sample density 
     
    194185#else 
    195186 
    196         PoissonDiscSampleGenerator2 poisson(mNumSamples, 1.0f); 
     187        static PoissonDiscSampleGenerator2D poisson(mNumSamples, 1.0f); 
    197188        poisson.Generate(samples); 
    198189 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h

    r2930 r3227  
    4747 
    4848 
    49 class RandomSampleGenerator2: public SampleGenerator 
     49class RandomSampleGenerator2D: public SampleGenerator 
    5050{ 
    5151public: 
    5252         
    53         RandomSampleGenerator2(int numSamples, float radius); 
     53        RandomSampleGenerator2D(int numSamples, float radius); 
    5454 
    5555        virtual void Generate(float *samples) const; 
     
    6565        according to some d related to the number of samples. 
    6666*/ 
    67 class PoissonDiscSampleGenerator2: public SampleGenerator 
     67class PoissonDiscSampleGenerator2D: public SampleGenerator 
    6868{ 
    6969public: 
    7070         
    71         PoissonDiscSampleGenerator2(int numSamples, float radius); 
     71        PoissonDiscSampleGenerator2D(int numSamples, float radius); 
    7272 
    7373        virtual void Generate(float *samples) const; 
     
    8383        with the distance 
    8484*/ 
    85 class QuadraticDiscSampleGenerator2: public SampleGenerator 
     85class QuadraticDiscSampleGenerator2D: public SampleGenerator 
    8686{ 
    8787public: 
    8888         
    89         QuadraticDiscSampleGenerator2(int numSamples, float radius); 
     89        QuadraticDiscSampleGenerator2D(int numSamples, float radius); 
    9090 
    9191        virtual void Generate(float *samples) const; 
     
    9999/** This class generates random spherical samples. 
    100100*/ 
    101 class SphericalSampleGenerator3: public SampleGenerator 
     101class SphericalSampleGenerator3D: public SampleGenerator 
    102102{ 
    103103public: 
    104104         
    105         SphericalSampleGenerator3(int numSamples, float radius); 
     105        SphericalSampleGenerator3D(int numSamples, float radius); 
    106106 
    107107        virtual void Generate(float *samples) const; 
    108  
    109 protected: 
    110  
    111         static HaltonSequence sHalton; 
    112108}; 
    113109 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3226 r3227  
    5858#include "WalkThroughRecorder.h" 
    5959#include "StatsWriter.h" 
     60#include "Halton.h" 
    6061 
    6162 
     
    645646 
    646647        // this function assign the render queue bucket ids of the materials in beforehand 
    647         // => probably a little less overhead for new parts of the scene that are not yet assigned 
     648        // => probably less overhead for new parts of the scene that are not yet assigned 
    648649        PrepareRenderQueue(); 
    649650        /// forward rendering is the default 
     
    651652        // frame time is restarted every frame 
    652653        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(); 
    653662 
    654663        // the rendering loop 
     
    14051414                break; 
    14061415        case '7': 
    1407                 ssaoTempCohFactor *= 0.5f; 
     1416                ssaoTempCohFactor *= 1.0f / 1.2f; 
    14081417                cout << "new temporal coherence factor: " << ssaoTempCohFactor << endl; 
    14091418                break; 
    14101419        case '8': 
    1411                 ssaoTempCohFactor *= 2.0f; 
     1420                ssaoTempCohFactor *= 1.2f; 
    14121421                cout << "new temporal coherence factor: " << ssaoTempCohFactor << endl; 
    14131422                break; 
     
    14171426                break; 
    14181427        case '0': 
    1419                 ssaoKernelRadius *= 1.2f; 
     1428                ssaoKernelRadius *= 1.0f / 0.8f; 
    14201429                cout << "new ssao kernel radius: " << ssaoKernelRadius << endl; 
    14211430                break; 
     
    14251434                break; 
    14261435        case 'N': 
    1427                 ssaoSampleIntensity *= 1.1f; 
     1436                ssaoSampleIntensity *= 1.0f / 0.9f; 
    14281437                cout << "new ssao sample intensity: " << ssaoSampleIntensity << endl; 
    14291438                break; 
     
    14331442                break; 
    14341443        case 'O': 
    1435                 ssaoFilterRadius *= 1.1f; 
     1444                ssaoFilterRadius *= 1.0f / 0.9f; 
    14361445                cout << "new ssao filter radius: " << ssaoFilterRadius << endl; 
    14371446                break; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3226 r3227  
    2121 
    2222#define SSAO_CONVERGENCE_THRESHOLD 700.0f 
     23//#define SSAO_CONVERGENCE_THRESHOLD 1500.0f 
    2324 
    2425 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/common.h

    r3213 r3227  
    4545        return rpt; 
    4646} 
     47 
     48 
     49 
     50 
     51inline 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  
    229229 
    230230        // 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; 
    232233 
    233234 
     
    275276                pixelValid = pixelNotValid; 
    276277        } 
    277         else if ( 
     278        else if (!((oldEyeSpaceDepth > 1e10f) || (projectedEyeSpaceDepth > 1e10f)) && 
    278279                // check if changed from dynamic to not dynamic object 
    279                 (oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 
     280                ((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 
    280281                // 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)))) 
    282285        {        
    283286                pixelValid = pixelCouldBeValid;  
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3226 r3227  
    11#include "../shaderenv.h" 
    2  
     2#include "common.h" 
    33 
    44//////////////////// 
     
    2828} 
    2929 
    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 plane 
    40         float d = dot(n, pt); 
    41         // reflect around plane 
    42         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 } 
    5630 
    5731 
     
    225199        total_ao /= numSamples; 
    226200 
    227 #if 0 
     201#if 1 
    228202        // if surface normal perpenticular to view dir, approx. half of the samples will not count 
    229203        // => compensate for this (on the other hand, projected sampling area could be larger!) 
    230204        const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * max(dot(viewDir, normal), 0.0f); 
    231         total_ao *= viewCorrection; 
     205        total_ao += cosAngle * aoContrib * viewCorrection; 
    232206 
    233207#endif 
    234208 
    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); 
    237210} 
    238211 
     
    261234                        float newWeight, 
    262235                        float sampleIntensity, 
    263                         bool isMovingObject, 
    264                         sampler2D normalTex 
     236                        bool isMovingObject 
    265237                        ) 
    266238{ 
     
    273245                const float2 offset = samples[i]; 
    274246 
    275 #if 1 
     247                float2 offsetTransformed; 
     248 
    276249                //////////////////// 
    277250                //-- add random noise: reflect around random normal vector  
    278                 //-- (slows down the computation for some reason!) 
     251                //-- (affects performance for some reason!) 
    279252 
    280253                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                 
    285258                // weight with projected coordinate to reach similar kernel size for near and far 
    286259                const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor; 
     
    290263                 
    291264 
    292                 // the normal of the current sample 
    293                 //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  
    297265                //////////////// 
    298266                //-- compute contribution of sample using the direction and angle 
     
    300268                float3 dirSample = samplePos - centerPosition; 
    301269 
    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); 
    304273 
    305274                dirSample /= lengthToSample; // normalize 
    306275 
    307276                // 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; 
    310281                //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 
    311282 
    312                 //total_ao += cosAngle2 * cosAngle * aoContrib; 
    313                 total_ao += cosAngle * aoContrib; 
     283                total_ao += max(cosAngle, 0) * aoContrib; 
    314284 
    315285                ++ numSamples; 
     
    324294                // to have any influence in the current or last frame 
    325295                const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 
    326                 validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid); 
    327  
    328 #if 1//#ifdef U//USE_GTX 
     296                validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid * step(-0.1f, cosAngle)); 
     297 
     298#ifdef USE_GTX 
    329299                // we can bail out early and use a minimal #samples) 
    330300                // if some conditions are met as long as the hardware supports it 
     
    351321 
    352322        return float3(total_ao, validSamples, numSamples); 
    353         //return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples); 
    354323} 
    355324 
     
    426395        if (eyeSpaceDepth < 1e10f) 
    427396        { 
    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); 
    429398                //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity); 
    430399        } 
     
    460429        } 
    461430 
     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 
    462438        // the new weight for the next frame 
    463439        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); 
    471440 
    472441        OUT.illum_col.y = combinedWeight; 
Note: See TracChangeset for help on using the changeset viewer.