- Timestamp:
- 10/13/08 10:13:27 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3027 r3028 142 142 143 143 glEnd(); 144 145 p->Release();146 144 } 147 145 … … 550 548 glEnd(); 551 549 552 sCgAntiAliasingProgram->Release();553 554 550 PrintGLerror("antialiasing"); 555 551 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
r2965 r3028 59 59 state->SetState(mTexture != NULL, mAlphaTestEnabled, mCullFaceEnabled); 60 60 61 if (state->GetRenderPassType() == RenderState::DEFERRED) 62 { 63 if (mTexture) 64 { 65 cgGLSetTextureParameter(RenderState::sTexParam, mTexture->GetId()); 66 cgGLEnableTextureParameter(RenderState::sTexParam); 67 } 68 else 69 { 70 cgGLDisableTextureParameter(RenderState::sTexParam); 71 } 72 } 73 else 74 { 75 if (mTexture) 76 mTexture->Bind(); 77 else 78 glBindTexture(GL_TEXTURE_2D, 0); 79 } 61 state->SetTexture(mTexture); 80 62 81 63 glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
r2965 r3028 2 2 #include "Geometry.h" 3 3 #include "Material.h" 4 #include "ShaderProgram.h" 5 #include "Texture.h" 4 6 5 7 using namespace std; … … 11 13 CGprofile RenderState::sCgVertexProfile; 12 14 13 CGprogramRenderState::sCgMrtFragmentProgram = NULL;14 CGprogramRenderState::sCgMrtFragmentTexProgram = NULL;15 CGparameterRenderState::sTexParam;15 ShaderProgram *RenderState::sCgMrtFragmentProgram = NULL; 16 ShaderProgram *RenderState::sCgMrtFragmentTexProgram = NULL; 17 int RenderState::sTexParam; 16 18 17 19 … … 123 125 124 126 if (mRenderType == DEFERRED) 125 cgGLBindProgram(sCgMrtFragmentProgram); 126 127 glDisable(GL_TEXTURE_2D); 127 sCgMrtFragmentProgram->Bind(); 128 else 129 glDisable(GL_TEXTURE_2D); 130 128 131 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 129 132 } … … 136 139 137 140 if (mRenderType == DEFERRED) 138 cgGLBindProgram(sCgMrtFragmentTexProgram); 139 140 glEnable(GL_TEXTURE_2D); 141 sCgMrtFragmentTexProgram->Bind(); 142 else 143 glEnable(GL_TEXTURE_2D); 144 141 145 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 142 146 } … … 190 194 191 195 192 } 196 void RenderState::SetTexture(Texture *tex) 197 { 198 if (tex) 199 { 200 if (GetRenderPassType() == RenderState::DEFERRED) 201 { 202 RenderState::sCgMrtFragmentProgram->SetTexture("tex", tex->GetId()); 203 } 204 else 205 { 206 tex->Bind(); 207 } 208 } 209 else 210 { 211 if (!GetRenderPassType() == RenderState::DEFERRED) 212 glBindTexture(GL_TEXTURE_2D, 0); 213 } 214 } 215 216 217 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
r2965 r3028 11 11 namespace CHCDemoEngine 12 12 { 13 14 class ShaderProgram; 15 class Texture; 13 16 14 17 /** The current render state. … … 70 73 */ 71 74 void LockCullFaceEnabled(bool lockCull); 75 /** Set a new texture. 76 */ 77 void SetTexture(Texture *tex); 72 78 73 79 … … 78 84 static CGprofile sCgVertexProfile; 79 85 80 static CGprogramsCgMrtFragmentProgram;81 static CGprogramsCgMrtFragmentTexProgram;86 static ShaderProgram *sCgMrtFragmentProgram; 87 static ShaderProgram *sCgMrtFragmentTexProgram; 82 88 83 static CGparameter sTexParam; 89 static int sTexParam; 90 84 91 85 92 protected: -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
r3025 r3028 45 45 void SetArray2f(const std::string &name, float *vals, int numElements); 46 46 void SetArray3f(const std::string &name, float *vals, int numElements); 47 /** Sets the matrix parameter. 48 */ 49 void SetMatrix(const std::string &name, const Matrix4x4 &mat); 50 /** Sets the texture parameter. 51 */ 52 void SetTexture(const std::string &name, unsigned int tex); 53 /** Enable / disable a texture parameter. 54 */ 55 void EnableTexture(const std::string &name); 47 56 48 void SetMatrix(const std::string &name, const Matrix4x4 &mat); 49 50 void SetTexture(const std::string &name, unsigned int tex); 51 52 void Release(); 53 57 void DisableTexture(const std::string &name); 58 /** Binds the program. 59 */ 54 60 void Bind(); 55 61 /** Returns true if this program is valid. 62 */ 56 63 inline bool IsValid() { return mProgram != NULL; } 57 64 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h
r2961 r3028 51 51 static CGparameter sModelMatrixParam; 52 52 53 53 54 protected: 54 55 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3026 r3028 281 281 282 282 static CGcontext sCgContext = NULL; 283 static CGprogram sCgMrtVertexProgram = NULL; 283 284 ShaderProgram *sCgMrtVertexProgram = NULL; 284 285 285 286 static CGparameter sEyePosParamTex; … … 554 555 cgGLSetOptimalOptions(RenderState::sCgVertexProfile); 555 556 557 cgGLSetManageTextureParameters(sCgContext, true); 558 556 559 sCgMrtVertexProgram = 557 cgCreateProgramFromFile(sCgContext, 558 CG_SOURCE, 559 "src/shaders/mrt.cg", 560 RenderState::sCgVertexProfile, 561 "vtx", 562 NULL); 563 564 if (sCgMrtVertexProgram != NULL) 565 { 566 cgGLLoadProgram(sCgMrtVertexProgram); 567 568 //sInvViewProjParam = cgGetNamedParameter(sCgMrtVertexProgram, "InvViewProj"); 569 Transform3::sModelMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelView"); 570 } 560 new ShaderProgram(sCgContext, "src/shaders/mrt.cg", RenderState::sCgFragmentProfile, "vtx"); 561 562 if (!sCgMrtVertexProgram->IsValid()) 563 cerr << "fragment program failed to load" << endl; 571 564 572 565 RenderState::sCgMrtFragmentTexProgram = 573 cgCreateProgramFromFile(sCgContext, 574 CG_SOURCE, 575 "src/shaders/mrt.cg", 576 RenderState::sCgFragmentProfile, 577 "fragtex", 578 NULL); 579 580 if (RenderState::sCgMrtFragmentTexProgram != NULL) 581 { 582 cgGLLoadProgram(RenderState::sCgMrtFragmentTexProgram); 583 584 sEyePosParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "eyePos"); 585 RenderState::sTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "tex"); 586 } 587 else 588 cerr << "fragment tex program failed to load" << endl; 566 new ShaderProgram(sCgContext, "src/shaders/mrt.cg", RenderState::sCgFragmentProfile, "fragtex"); 567 568 if (!RenderState::sCgMrtFragmentTexProgram->IsValid()) 569 cerr << "fragment program failed to load" << endl; 589 570 590 571 RenderState::sCgMrtFragmentProgram = 591 cgCreateProgramFromFile(sCgContext, 592 CG_SOURCE, 593 "src/shaders/mrt.cg", 594 RenderState::sCgFragmentProfile, 595 "frag", 596 NULL); 597 598 if (RenderState::sCgMrtFragmentProgram != NULL) 599 { 600 cgGLLoadProgram(RenderState::sCgMrtFragmentProgram); 601 602 sEyePosParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "eyePos"); 603 } 604 else 572 new ShaderProgram(sCgContext, "src/shaders/mrt.cg", RenderState::sCgFragmentProfile, "frag"); 573 574 if (!RenderState::sCgMrtFragmentProgram->IsValid()) 605 575 cerr << "fragment program failed to load" << endl; 606 576 … … 938 908 939 909 cgGLEnableProfile(RenderState::sCgVertexProfile); 940 cgGLBindProgram(sCgMrtVertexProgram);910 sCgMrtVertexProgram->Bind(); 941 911 942 912 cgGLEnableProfile(RenderState::sCgFragmentProfile); 943 cgGLBindProgram(RenderState::sCgMrtFragmentProgram);913 RenderState::sCgMrtFragmentProgram->Bind(); 944 914 945 915 const Vector3 pos = camera->GetPosition(); … … 1779 1749 DEL_PTR(shadowMap); 1780 1750 DEL_PTR(shadowTraverser); 1781 1782 if (sCgMrtVertexProgram) 1783 cgDestroyProgram(sCgMrtVertexProgram); 1784 1785 if (RenderState::sCgMrtFragmentProgram) 1786 cgDestroyProgram(RenderState::sCgMrtFragmentProgram); 1787 1788 if (RenderState::sCgMrtFragmentTexProgram) 1789 cgDestroyProgram(RenderState::sCgMrtFragmentTexProgram); 1751 DEL_PTR(RenderState::sCgMrtFragmentProgram); 1752 DEL_PTR(RenderState::sCgMrtFragmentTexProgram); 1753 DEL_PTR(sCgMrtVertexProgram); 1790 1754 1791 1755 DeferredRenderer::ReleaseCG(); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3026 r3028 172 172 currentPos /= currentPos.w; 173 173 174 const float currentDepth = currentPos.z * 1e-3f; 174 const float precisionScale = 1e-3f; 175 const float currentDepth = currentPos.z * precisionScale; 175 176 176 177 const float2 ao = ssao(IN, colors, noise, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir)); … … 188 189 189 190 // the current depth projected into the old frame 190 const float projDepth = projPos.z * 1e-3f;191 const float projDepth = projPos.z * precisionScale; 191 192 192 193 // fit from unit cube into 0 .. 1 … … 202 203 203 204 //const float oldNumSamples = oldCol.y; 204 const float oldWeight = 50;//clamp(oldCol.y, 0, temporalCoherence);205 const float oldWeight = clamp(oldCol.y, 0, temporalCoherence); 205 206 206 207 float newWeight;
Note: See TracChangeset
for help on using the changeset viewer.