Changeset 3329 for GTP


Ignore:
Timestamp:
02/26/09 18:39:04 (15 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp

    r3323 r3329  
    218218void QuadraticDiscSampleGenerator2D::Generate(float *samples) const 
    219219{ 
    220 #if 0 
    221         float r[2]; 
    222         Sample2 *s = (Sample2 *)samples; 
    223  
    224         for (int i = 0; i < mNumSamples; ++ i) 
    225         { 
    226                 mHalton->GetNext(r); 
    227  
    228                 // create samples over disc: the sample density 
    229                 // decreases quadratically with the distance to the origin 
    230                 s[i].x = mRadius * r[1] * sin(2.0f * M_PI * r[0]); 
    231                 s[i].y = mRadius * r[1] * cos(2.0f * M_PI * r[0]); 
    232         } 
    233 #else 
    234  
    235         //PoissonDiscSampleGenerator2D::Generate(samples); 
    236         RandomSampleGenerator2D::Generate(samples); 
    237  
    238         Sample2 *s = (Sample2 *)samples; 
    239  
    240         // multiply with lenght to get quadratic dependence on the distance 
    241         for (int i = 0; i < mNumSamples; ++ i) 
    242         { 
    243                 Sample2 &spl = s[i]; 
    244  
    245                 float len = sqrt(spl.x * spl.x + spl.y * spl.y); 
    246                 spl.x *= len * mRadius; 
    247                 spl.y *= len * mRadius; 
    248         } 
    249 #endif 
    250 } 
     220        Sample2 *s = (Sample2 *)samples; 
     221 
     222        int numSamples = 0; 
     223        float x[2]; 
     224 
     225        static float total1 = 0; 
     226        static float total2 = 0; 
     227        static int totalSamples = 0; 
     228 
     229        for (int i = 0; i < mNumSamples; ++ i) 
     230        { 
     231                //x[0] = RandomValue(0, 1); x[1] = RandomValue(0, 1); 
     232                mHalton->GetNext(x); 
     233                 
     234                const float a = 2.0f * M_PI * x[0]; 
     235                const float r = sqrt(x[1]); 
     236                //const float rad = mRadius * r * r * r * r; 
     237                const float rad = mRadius * r;// * r; 
     238 
     239                s[i].x = rad * cos(a); 
     240                s[i].y = rad * sin(a); 
     241        } 
     242} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3328 r3329  
    99//#define NUM_SAMPLES 16 
    1010//#define NUM_SAMPLES 24 
    11 #define NUM_SAMPLES 48 
     11#define NUM_SAMPLES 24 
    1212 
    1313//#define MIN_SAMPLES 48 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3328 r3329  
    203203                float2 offset; 
    204204 
    205                 const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy; 
    206                 //const float2 ssaoOffset = samples[i]; 
     205                const float2 ssaoOffset =  
     206                        tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy; 
    207207 
    208208                //////////////////// 
     
    234234                float3 dirSample = samplePos - centerPosition; 
    235235 
    236                 //const float minDist = 9e-1f; 
    237                 const float minDist = 1e-2f; 
    238  
    239                 //const float sqrLen = max(SqrLen(dirSample), minDist); 
    240                 //const float lengthToSample = sqrt(sqrLen); 
    241                 const float lengthToSample =  max(length(dirSample), minDist); 
    242  
    243                 dirSample /= lengthToSample; // normalize 
     236                const float minDist = 1e-6f; 
     237                const float scaleFactor = 1e-3f; 
     238 
     239                const float lengthToSample = length(dirSample); 
     240                const float sampleWeight = 1.0f / (lengthToSample + scaleFactor); 
     241 
     242                dirSample /= max(lengthToSample, minDist); // normalize 
     243 
    244244 
    245245                // angle between current normal and direction to sample controls AO intensity. 
    246                 float cosAngle = dot(dirSample, normal); 
     246                const float cosAngle = dot(dirSample, normal); 
    247247 
    248248                // the normal of the current sample 
    249                 //const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz); 
    250                 const float3 sampleNormal = tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz; 
    251  
     249                const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz); 
     250                 
    252251                // angle between current normal and direction to sample controls AO intensity. 
    253                 float cosAngle2 = .5f + dot(sampleNormal, -normal) * 0.5f; 
    254                 //float cosAngle2 = dot(-dirSample, sampleNormal); 
     252                const float cosAngle2 = dot(-dirSample, sampleNormal); 
    255253                 
    256                 //const float aoContrib = sampleIntensity / sqrLen; 
    257                 const float aoContrib = sampleIntensity / lengthToSample; 
     254                dirSample *= minDist; 
     255                const float aoContrib = sampleIntensity * sampleWeight; 
    258256 
    259257                //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 
     
    277275 
    278276                const float partlyResetThres = 1.0f; 
     277 
    279278                if (pixelValid <= partlyResetThres) 
    280279                        validSamples = max(validSamples, pixelValid * (1.0f - tooFarAway) * step(-0.1f, cosAngle)); 
     
    326325                        sampler2D colors, 
    327326                        sampler2D noiseTex, 
    328                         float2 samples[NUM_SAMPLES], 
     327                        sampler2D samples, 
    329328                        float3 normal, 
    330329                        float3 centerPosition, 
     
    337336                        float convergence, 
    338337                        float sampleIntensity, 
    339                         bool isMovingObject 
     338                        bool isMovingObject, 
     339                        float oldIdx 
    340340                        ) 
    341341{ 
     
    348348                float2 offset; 
    349349 
     350                const float2 ssaoOffset =  
     351                        tex2Dlod(samples, float4((0.5f + i + oldIdx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy; 
     352 
    350353                //////////////////// 
    351354                //-- add random noise: reflect around random normal vector  
     
    356359                        float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 
    357360                        //offset = myreflect(samples[i], mynoise); 
    358                         offset = myrotate(samples[i], mynoise.x); 
     361                        //offset = myrotate(samples[i], mynoise.x); 
     362                        offset = myrotate(ssaoOffset, mynoise.x); 
    359363                } 
    360364                else 
    361365                { 
    362                         offset = samples[i]; 
    363                 } 
    364                  
     366                        offset = ssaoOffset; 
     367                } 
     368 
     369 
    365370                // weight with projected coordinate to reach similar kernel size for near and far 
    366371                const float2 texcoord = IN.texCoord.xy + offset * scaleFactor; 
     
    375380                float3 dirSample = samplePos - centerPosition; 
    376381 
    377                 //const float minDist = 9e-1f; 
    378                 const float minDist = 1e-2f; 
    379  
    380                 //const float sqrLen = max(SqrLen(dirSample), minDist); 
    381                 //const float lengthToSample = sqrt(sqrLen); 
    382                 const float lengthToSample =  max(length(dirSample), minDist); 
    383  
    384                 dirSample /= lengthToSample; // normalize 
     382                const float minDist = 1e-6f; 
     383                const float scaleFactor = 1e-3f; 
     384 
     385                const float lengthToSample = length(dirSample); 
     386                const float sampleWeight = 1.0f / (lengthToSample + scaleFactor); 
     387 
     388                dirSample /= max(length(dirSample), minDist); // normalize 
    385389 
    386390                // angle between current normal and direction to sample controls AO intensity. 
    387                 float cosAngle = dot(dirSample, normal); 
     391                const float cosAngle = dot(dirSample, normal); 
    388392 
    389393                //const float aoContrib = sampleIntensity / sqrLen; 
    390                 const float aoContrib = sampleIntensity / lengthToSample; 
     394                const float aoContrib = sampleIntensity * sampleWeight; 
    391395                //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 
    392396 
    393                 total_ao += max(cosAngle, 0) * aoContrib; 
     397                total_ao += max(cosAngle, .0f) * aoContrib; 
    394398 
    395399                ++ numSamples; 
     
    427431                        // (=> there was no discontinuity recently) 
    428432                        //else if (isMovingObject && (convergence > SSAO_CONVERGENCE_THRESHOLD)) break; 
    429                         //else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break; 
     433                        else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break; 
    430434                } 
    431435#endif 
     
    513517         
    514518        float oldWeight = temporalVals.y; 
    515         float oldIdx = temporalVals.z; 
    516  
     519        float oldIdx = temporalCoherence > 1 ? temporalVals.z : 0; 
     520         
    517521        float3 ao; 
    518522 
     
    520524        if (eyeSpaceDepth < DEPTH_THRESHOLD) 
    521525        { 
    522                 if (0) 
    523                 { 
    524                         ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 
     526                if (1) 
     527                { 
     528                        ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz,  
     529                                      scaleFactor, bl, br, tl, tr, normalize(viewDir), 
     530                                          oldWeight, sampleIntensity, isMovingObject, oldIdx); 
    525531                } 
    526532                else 
    527533                { 
    528534                        ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor,  
    529                                    bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity,  
    530                                            isMovingObject, normals, oldIdx); 
     535                                  bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity,  
     536                                          isMovingObject, normals, oldIdx); 
    531537                } 
    532538        } 
Note: See TracChangeset for help on using the changeset viewer.