Changeset 2820 for GTP


Ignore:
Timestamp:
07/07/08 16:34:07 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
2 edited

Legend:

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

    r2819 r2820  
    145145bool eightKeyPressed = false; 
    146146 
    147 static Vector3 samples[32]; 
    148 GLubyte *randomNormals; 
     147GLubyte *randomNormals = NULL; 
    149148 
    150149PerfTimer frameTimer, algTimer; 
    151          
     150 
     151 
     152#define NUM_SAMPLES 8 
     153 
     154static float samples[NUM_SAMPLES * 2]; 
     155 
    152156 
    153157// function forward declarations 
     
    201205void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br); 
    202206 
     207void GenerateSamples(); 
     208 
     209 
    203210GLenum mrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT}; 
    204211 
     
    222229static CGparameter sMaxDepthParamTex; 
    223230 
    224 const static float radius = 1e-3f; 
     231static CGparameter sSamplesParam;  
     232 
    225233 
    226234 
     
    461469                sNormalsTexParam = cgGetNamedParameter(sCgSSAOProgram, "normals");   
    462470                sNoiseTexParam = cgGetNamedParameter(sCgSSAOProgram, "noiseTexture"); 
     471 
     472                sSamplesParam = cgGetNamedParameter(sCgSSAOProgram, "samples"); 
     473                cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples); 
    463474        } 
    464475        else 
     
    16901701void GenerateSamples() 
    16911702{ 
    1692         // fill an n * n * 2 array with uniformly distributed spherical samples 
    1693         for (int i = 0; i < 32; ++ i) 
     1703        float scale = 1.0f / (float)NUM_SAMPLES; 
     1704 
     1705        // fill an array with uniformly distributed spherical samples 
     1706        for (int i = 0; i < NUM_SAMPLES; ++ i) 
    16941707        { 
    16951708                // create stratified samples over sphere 
    1696                 const float rx = RandomValue(0, 1); 
    1697                 const float ry = RandomValue(0, 1); 
    1698                 //const float l = RandomValue(0, 1); 
     1709                const float rx = ((float)i + RandomValue(0, 1)) * scale; 
    16991710 
    17001711                const float theta = 2.0f * acos(sqrt(1.0f - rx)); 
    1701                 const float phi = 2.0f * M_PI * ry; 
    1702  
    1703                 samples[i] = Vector3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta)); 
    1704                 cout << samples[i] << endl; 
     1712                 
     1713                samples[i + 0] = cos(theta); 
     1714                samples[i + 1] = sin(theta); 
     1715 
     1716                cout << samples[i] << " " << samples[i + 1] << endl; 
    17051717        } 
    17061718} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2819 r2820  
    1 #define SAMPLES 24 
    2  
     1#define NUM_SAMPLES 8 
     2#define SAMPLE_INTENSITY 0.6 
     3#define AREA_SIZE 3e-1f 
    34// kustls magic sample positions 
    4 static const float2 samples[SAMPLES] = 
     5/*static const float2 samples[NUM_SAMPLES] = 
    56{ 
    67  {-0.326212f, -0.405805f}, 
     
    2829  {0.32194f, 0.932615f}, 
    2930  {0.791559f, 0.597705f} 
    30 }; 
     31};*/ 
    3132 
    3233 
     
    6061           uniform sampler2D positions, 
    6162           uniform sampler2D normals, 
    62            uniform sampler2D noiseTexture                                
     63           uniform sampler2D noiseTexture, 
     64           uniform float2 samples[NUM_SAMPLES] 
    6365           ) 
    6466{ 
     
    7981 
    8082  //const float areaSize = 5e-1f; 
    81   const float areaSize = 3e-1f; 
    82   const float sampleIntensity = 0.2f; 
     83  //const float areaSize = 3e-1f; 
     84  //const float sampleIntensity = 0.2f; 
    8385   
    84   for (int i = 0; i < SAMPLES; i ++) { 
     86  for (int i = 0; i < NUM_SAMPLES; i ++) { 
    8587    float2 offset = samples[i]; 
    8688     
     
    9597                 
    9698    // weight with projected coordinate to reach similar kernel size for near and far 
    97     float2 texcoord = IN.texCoord.xy + offsetTransformed * areaSize * w; 
     99    float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w; 
    98100     
    99101    float3 sample_position = tex2D(positions, texcoord).xyz; 
     
    101103    float3 vector_to_sample = sample_position - centerPosition.xyz; 
    102104    float length_to_sample = length(vector_to_sample); 
    103     float3 direction_to_sample = vector_to_sample / (length_to_sample + 1e-9f); 
     105    float3 direction_to_sample = vector_to_sample / length_to_sample; 
    104106     
    105107    // Angle between current normal and direction to sample controls AO intensity. 
     
    115117    distance_intensity = max(distance_intensity, 0.0f); 
    116118     
    117     total_ao += cos_angle * sampleIntensity * distance_intensity; 
     119    total_ao += cos_angle * SAMPLE_INTENSITY * distance_intensity; 
    118120  } 
    119121         
     
    122124 
    123125 
    124 pixel main(fragment IN,  
    125            uniform sampler2D colors, 
    126            uniform sampler2D positions, 
    127            uniform sampler2D normals, 
    128            uniform sampler2D noiseTexture) 
     126float4 shade(fragment IN,  
     127             uniform sampler2D colors, 
     128             uniform sampler2D positions, 
     129             uniform sampler2D normals) 
    129130{ 
    130   pixel OUT; 
    131  
    132131  float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 
    133132  float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f); 
     
    152151  float diffuse = diffuseLight + diffuseLight2; 
    153152 
    154   //float ao = ssao(IN, positions, normals, noiseTexture); 
    155   float ao = 1.0f; 
    156   //OUT.color = ao;  
    157   OUT.color = ao * (ambient + diffuse) * color; 
     153  return (ambient + diffuse) * color; 
     154} 
     155 
     156 
     157pixel main(fragment IN,  
     158           uniform sampler2D colors, 
     159           uniform sampler2D positions, 
     160           uniform sampler2D normals, 
     161           uniform sampler2D noiseTexture, 
     162           uniform float2 samples[NUM_SAMPLES]) 
     163{ 
     164  pixel OUT; 
     165 
     166  float4 col = Shade(IN, positions, normals); 
     167  float ao = ssao(IN, positions, normals, noiseTexture, samples); 
     168  //float ao = 1.0f; 
     169  OUT.color = ao * col;  
     170  //OUT.color = ao * (ambient + diffuse) * color; 
    158171  //OUT.color = (ambient + diffuse) * color; 
    159172       
Note: See TracChangeset for help on using the changeset viewer.