Changeset 2820 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Timestamp:
- 07/07/08 16:34:07 (16 years ago)
- 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 145 145 bool eightKeyPressed = false; 146 146 147 static Vector3 samples[32]; 148 GLubyte *randomNormals; 147 GLubyte *randomNormals = NULL; 149 148 150 149 PerfTimer frameTimer, algTimer; 151 150 151 152 #define NUM_SAMPLES 8 153 154 static float samples[NUM_SAMPLES * 2]; 155 152 156 153 157 // function forward declarations … … 201 205 void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br); 202 206 207 void GenerateSamples(); 208 209 203 210 GLenum mrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT}; 204 211 … … 222 229 static CGparameter sMaxDepthParamTex; 223 230 224 const static float radius = 1e-3f; 231 static CGparameter sSamplesParam; 232 225 233 226 234 … … 461 469 sNormalsTexParam = cgGetNamedParameter(sCgSSAOProgram, "normals"); 462 470 sNoiseTexParam = cgGetNamedParameter(sCgSSAOProgram, "noiseTexture"); 471 472 sSamplesParam = cgGetNamedParameter(sCgSSAOProgram, "samples"); 473 cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples); 463 474 } 464 475 else … … 1690 1701 void GenerateSamples() 1691 1702 { 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) 1694 1707 { 1695 1708 // 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; 1699 1710 1700 1711 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; 1705 1717 } 1706 1718 } -
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 3 4 // kustls magic sample positions 4 static const float2 samples[SAMPLES] =5 /*static const float2 samples[NUM_SAMPLES] = 5 6 { 6 7 {-0.326212f, -0.405805f}, … … 28 29 {0.32194f, 0.932615f}, 29 30 {0.791559f, 0.597705f} 30 }; 31 };*/ 31 32 32 33 … … 60 61 uniform sampler2D positions, 61 62 uniform sampler2D normals, 62 uniform sampler2D noiseTexture 63 uniform sampler2D noiseTexture, 64 uniform float2 samples[NUM_SAMPLES] 63 65 ) 64 66 { … … 79 81 80 82 //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; 83 85 84 for (int i = 0; i < SAMPLES; i ++) {86 for (int i = 0; i < NUM_SAMPLES; i ++) { 85 87 float2 offset = samples[i]; 86 88 … … 95 97 96 98 // 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; 98 100 99 101 float3 sample_position = tex2D(positions, texcoord).xyz; … … 101 103 float3 vector_to_sample = sample_position - centerPosition.xyz; 102 104 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; 104 106 105 107 // Angle between current normal and direction to sample controls AO intensity. … … 115 117 distance_intensity = max(distance_intensity, 0.0f); 116 118 117 total_ao += cos_angle * sampleIntensity* distance_intensity;119 total_ao += cos_angle * SAMPLE_INTENSITY * distance_intensity; 118 120 } 119 121 … … 122 124 123 125 124 pixel main(fragment IN, 125 uniform sampler2D colors, 126 uniform sampler2D positions, 127 uniform sampler2D normals, 128 uniform sampler2D noiseTexture) 126 float4 shade(fragment IN, 127 uniform sampler2D colors, 128 uniform sampler2D positions, 129 uniform sampler2D normals) 129 130 { 130 pixel OUT;131 132 131 float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 133 132 float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f); … … 152 151 float diffuse = diffuseLight + diffuseLight2; 153 152 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 157 pixel 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; 158 171 //OUT.color = (ambient + diffuse) * color; 159 172
Note: See TracChangeset
for help on using the changeset viewer.