- Timestamp:
- 08/26/08 20:45:40 (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/SsaoShader.cpp
r2869 r2871 87 87 // the diffuse color buffer 88 88 mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 89 mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 89 90 90 91 mOldFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 91 92 // the diffuse color buffer 93 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 92 94 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 93 95 … … 140 142 141 143 142 sCgCombineProgram =144 /*sCgCombineProgram = 143 145 cgCreateProgramFromFile(context, 144 146 CG_SOURCE, … … 158 160 else 159 161 cerr << "combined program failed to load" << endl; 160 162 */ 161 163 162 164 /////////////// … … 257 259 FirstPass(fbo); 258 260 ComputeSsao(fbo, expFactor); 259 Combine(fbo);261 //Combine(fbo); 260 262 AntiAliasing(fbo); 261 263 … … 291 293 // read the second buffer, write to the first buffer 292 294 mNewFbo->Bind(); 293 glDrawBuffers( 1, mymrt);295 glDrawBuffers(2, mymrt); 294 296 295 297 GLuint oldTex = mOldFbo->GetColorBuffer(0)->GetTexture(); … … 443 445 void SsaoShader::AntiAliasing(FrameBufferObject *fbo) 444 446 { 445 GLuint colorsTex = mFbo4->GetColorBuffer(0)->GetTexture();446 //GLuint colorsTex = mNewFbo->GetColorBuffer(0)->GetTexture();447 //GLuint colorsTex = mFbo4->GetColorBuffer(0)->GetTexture(); 448 GLuint colorsTex = mNewFbo->GetColorBuffer(1)->GetTexture(); 447 449 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 448 450 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r2870 r2871 27 27 struct pixel 28 28 { 29 float4 color: COLOR0; 29 float4 illum_col: COLOR0; 30 float4 combined_col: COLOR1; 30 31 }; 31 32 … … 33 34 float2 reflect(float2 pt, float2 n) 34 35 { 35 // distance to plane 36 float d = dot(n, pt); 37 // reflect around plane 38 float2 rpt = pt - d * 2.0f * n; 39 40 return rpt; 41 } 42 43 44 float2 rotate(float2 pt, float2 n) 36 // distance to plane 37 float d = dot(n, pt); 38 // reflect around plane 39 float2 rpt = pt - d * 2.0f * n; 40 return rpt; 41 } 42 43 44 /*float2 rotate(float2 pt, float2 n) 45 45 { 46 46 float2 ptTransformed; … … 49 49 50 50 return ptTransformed; 51 } 51 }*/ 52 52 53 53 … … 121 121 /** Computes ambient occlusion + diffuse reflections 122 122 */ 123 /* 123 124 float4 globIllum(fragment IN, 124 125 uniform sampler2D colors, … … 149 150 150 151 //sample noisetex; r stores costheta, g stores sintheta 151 float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f;152 float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy; 152 153 153 154 // rotation … … 157 158 float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w; 158 159 159 float3 sample_position = tex2D (positions, texcoord).xyz;160 float3 sample_color = tex2D(colors, texcoord).xyz;160 float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, 1)).xyz; 161 float3 sample_color = tex2D(colors, float4(texcoord, 0, 1)).xyz; 161 162 162 163 float3 vector_to_sample = sample_position - centerPosition.xyz; … … 176 177 177 178 total_ao += cos_angle * distance_intensity * view_correction; 178 total_color += cos_angle * distance_intensity * view_correction * sample_color * 0.3f; 179 float scale_factor = 0.3f; 180 total_color += cos_angle * distance_intensity * view_correction * sample_color * scale_factor; 179 181 } 180 182 181 183 return float4(total_color, 1.0f - total_ao); 182 184 } 183 185 */ 184 186 185 187 /** The mrt shader for screen space ambient occlusion … … 200 202 pixel OUT; 201 203 202 float4 norm al= tex2D(normals, IN.texCoord.xy);204 float4 norm = tex2D(normals, IN.texCoord.xy); 203 205 204 206 // the ambient term 205 float amb = normal.w;207 const float amb = norm.w; 206 208 207 209 // expand normal 208 normal = normalize(normal);// * 2.0f - 1.0f);210 float3 normal = normalize(norm.xyz);// * 2.0f - 1.0f); 209 211 /// the current view direction 210 212 float3 viewDir = normalize(IN.view * 2.0f - float3(1.0f)); 211 213 212 214 // the current world position 213 float4 centerPosition = tex2D(positions, IN.texCoord.xy);215 const float4 centerPosition = tex2D(positions, IN.texCoord.xy); 214 216 215 217 // the current color 216 float4 currentCol = tex2D(colors, IN.texCoord.xy); 217 float currentDepth = currentCol.w; 218 219 float ao = ssao(IN, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 220 221 //float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 218 const float4 currentCol = tex2D(colors, IN.texCoord.xy); 219 const float currentDepth = currentCol.w; 220 221 float4 new_col = (float4)ssao(IN, positions, noiseTexture, samples, normal, viewDir, noiseMultiplier, centerPosition); 222 //float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal, viewDir, noiseMultiplier, centerPosition); 222 223 223 // compute temporally smoothed color 224 225 ///////////////// 226 //-- compute temporally smoothed value 227 224 228 float4 realPos = centerPosition * maxDepth; 225 229 realPos.w = 1.0f; … … 227 231 float4 oldPos = mul(oldModelViewProj, realPos); 228 232 229 float newDepth = oldPos.z / oldPos.w;233 const float newDepth = oldPos.z / oldPos.w; 230 234 231 235 float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f; 232 236 float4 oldCol = tex2D(oldTex, tex); 233 237 234 float oldDepth = oldCol.w;235 float depthDif = 1.0f - newDepth / oldDepth;238 const float oldDepth = oldCol.w; 239 const float depthDif = 1.0f - newDepth / oldDepth; 236 240 237 241 if ((tex.x >= 0.0f) && (tex.x < 1.0f) && … … 239 243 (abs(depthDif) < 1e-4f)) 240 244 { 241 OUT. color = float4(ao * expFactor + oldCol * float4(1.0f - expFactor));245 OUT.illum_col = new_col * expFactor + oldCol * float4(1.0f - expFactor); 242 246 } 243 247 else 244 248 { 245 OUT.color = (float4)ao; 246 } 247 248 249 //OUT.color.xyz = viewDir; 250 //OUT.color = attenuated_color; 251 252 OUT.color.w = currentDepth; 249 OUT.illum_col = new_col; 250 } 251 252 253 OUT.combined_col = currentCol * OUT.illum_col; 254 255 OUT.illum_col.w = currentDepth; 253 256 254 257 return OUT; 255 258 } 256 259 257 260 /* 258 261 pixel combined(fragment IN, 259 262 uniform sampler2D colors, … … 265 268 float4 col = tex2D(colors, IN.texCoord.xy); 266 269 float4 ao = tex2D(ssaoTex, IN.texCoord.xy); 267 268 OUT.color = float4(1,0,0,0); 269 OUT. color= col * ao;270 //float4 illum = tex2D(ssaoTex, IN.texCoord.xy); 271 272 OUT.illum_col = col * ao; 270 273 271 274 return OUT; 272 } 275 }*/
Note: See TracChangeset
for help on using the changeset viewer.