- Timestamp:
- 08/26/08 18:09:03 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r2868 r2869 799 799 > 800 800 </File> 801 <File802 RelativePath=".\src\shaders\temporal.cg"803 >804 </File>805 801 </Filter> 806 802 <File -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp
r2868 r2869 21 21 static CGprogram sCgDeferredProgram2 = NULL; 22 22 static CGprogram sCgAntiAliasingProgram = NULL; 23 static CGprogram sCgCombineProgram = NULL; 24 25 static CGparameter sColorsTexCombineParam; 26 static CGparameter sSsaoTexCombineParam; 23 27 24 28 static CGparameter sColorsTexDeferredParam; … … 91 95 // the diffuse color buffer 92 96 mFbo3->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 93 97 98 mFbo4 = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 99 // the diffuse color buffer 100 mFbo4->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 94 101 95 102 // create noise texture for ssao … … 131 138 else 132 139 cerr << "deferred program failed to load" << endl; 140 141 142 sCgCombineProgram = 143 cgCreateProgramFromFile(context, 144 CG_SOURCE, 145 "src/shaders/ssao.cg", 146 RenderState::sCgFragmentProfile, 147 "combined", 148 NULL); 149 150 if (sCgCombineProgram != NULL) 151 { 152 cgGLLoadProgram(sCgCombineProgram); 153 154 // we need size of texture for scaling 155 sColorsTexCombineParam = cgGetNamedParameter(sCgCombineProgram, "colors"); 156 sSsaoTexCombineParam = cgGetNamedParameter(sCgCombineProgram, "ssaoTex"); 157 } 158 else 159 cerr << "combined program failed to load" << endl; 133 160 134 161 … … 230 257 FirstPass(fbo); 231 258 ComputeSsao(fbo, expFactor); 259 Combine(fbo); 232 260 AntiAliasing(fbo); 233 261 … … 415 443 void SsaoShader::AntiAliasing(FrameBufferObject *fbo) 416 444 { 417 GLuint colorsTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 445 GLuint colorsTex = mFbo4->GetColorBuffer(0)->GetTexture(); 446 //GLuint colorsTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 418 447 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 419 448 … … 503 532 } 504 533 534 535 void SsaoShader::Combine(FrameBufferObject *fbo) 536 { 537 GLuint colorsTex = mFbo3->GetColorBuffer(0)->GetTexture(); 538 GLuint ssaoTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 539 540 mFbo4->Bind(); 541 //mNewFbo->Bind(); 542 543 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 544 545 glDrawBuffers(1, mymrt); 546 547 cgGLEnableProfile(RenderState::sCgFragmentProfile); 548 549 cgGLBindProgram(sCgCombineProgram); 550 551 cgGLSetTextureParameter(sColorsTexCombineParam, colorsTex); 552 cgGLEnableTextureParameter(sColorsTexCombineParam); 553 554 cgGLSetTextureParameter(sSsaoTexCombineParam, ssaoTex); 555 cgGLEnableTextureParameter(sSsaoTexCombineParam); 556 557 glColor3f(1.0f, 1.0f, 1.0f); 558 559 const float offs = 0.5f; 560 561 glBegin(GL_QUADS); 562 563 glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f); 564 glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f); 565 glTexCoord2f(1, 1); glVertex3f( offs, offs, -0.5f); 566 glTexCoord2f(0, 1); glVertex3f(-offs, offs, -0.5f); 567 568 glEnd(); 569 570 cgGLDisableTextureParameter(sColorsTexCombineParam); 571 cgGLDisableTextureParameter(sSsaoTexCombineParam); 572 573 cgGLDisableProfile(RenderState::sCgFragmentProfile); 574 575 FrameBufferObject::Release(); 576 577 PrintGLerror("deferred shading"); 578 } 579 580 505 581 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h
r2868 r2869 53 53 54 54 void AntiAliasing(FrameBufferObject *fbo); 55 void Combine(FrameBufferObject *fbo); 55 56 56 57 void CreateNoiseTex2D(); … … 71 72 FrameBufferObject *mNewFbo; 72 73 FrameBufferObject *mFbo3; 74 FrameBufferObject *mFbo4; 73 75 }; 74 76 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r2868 r2869 181 181 return float4(total_color, 1.0f - total_ao); 182 182 } 183 184 185 float ComputeSmoothedColor(float4 centerPosition, 186 uniform sampler2D oldTex, 187 uniform float maxDepth, 188 uniform float expFactor, 189 const uniform float4x4 oldModelViewProj, 190 float4 currentCol 191 ) 192 { 193 float4 realPos = centerPosition * maxDepth; 194 realPos.w = 1.0f; 195 196 float4 oldPos = mul(oldModelViewProj, realPos); 197 198 float newDepth = oldPos.z / oldPos.w; 199 200 float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f; 201 float4 oldCol = tex2D(oldTex, tex); 202 203 float oldDepth = oldCol.w; 204 float depthDif = 1.0f - newDepth / oldDepth; 205 206 float4 col; 207 208 if ((tex.x >= 0.0f) && (tex.x < 1.0f) && 209 (tex.y >= 0.0f) && (tex.y < 1.0f) && 210 (abs(depthDif) < 1e-4f)) 211 { 212 col = currentCol * expFactor + oldCol * float4(1.0f - expFactor); 213 } 214 else 215 { 216 col = currentCol; 217 } 218 219 return col; 220 } 183 221 184 222 … … 217 255 218 256 float ao = ssao(IN, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 219 float4 attenuated_color = ao * col;257 //float4 attenuated_color = ao * col; 220 258 //float4 attenuated_color = ao; 221 259 … … 223 261 //float4 attenuated_color = ao * col + new_col; 224 262 225 const float x = expFactor; 226 227 float4 dummy = centerPosition * maxDepth; 228 dummy.w = 1.0f; 229 230 float4 oldPos = mul(oldModelViewProj, dummy); 231 232 float newDepth = oldPos.z / oldPos.w; 233 234 float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f; 235 float4 col1 = tex2D(oldTex, tex); 236 237 float oldDepth = col1.w; 238 float depthDif = 1.0f - newDepth / oldDepth; 239 240 if ((tex.x >= 0.0f) && (tex.x < 1.0f) && 241 (tex.y >= 0.0f) && (tex.y < 1.0f) && 242 (abs(depthDif) < 1e-4f)) 243 { 244 OUT.color = attenuated_color * expFactor + col1 * float4(1.0f - expFactor); 245 } 246 else 247 { 248 OUT.color = attenuated_color; 249 } 263 // compute temporally smoothed color 264 OUT.color = ComputeSmoothedColor(centerPosition, oldTex, maxDepth, expFactor, oldModelViewProj, float4(ao)); 250 265 251 266 //OUT.color.xyz = viewDir; … … 256 271 return OUT; 257 272 } 273 274 275 pixel combined(fragment IN, 276 uniform sampler2D colors, 277 uniform sampler2D ssaoTex 278 ) 279 { 280 pixel OUT; 281 282 float4 col = tex2D(colors, IN.texCoord.xy); 283 float4 ao = tex2D(ssaoTex, IN.texCoord.xy); 284 285 OUT.color = float4(1,0,0,0); 286 OUT.color = col * ao; 287 288 return OUT; 289 }
Note: See TracChangeset
for help on using the changeset viewer.