- Timestamp:
- 09/16/08 16:03:01 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
r2945 r2952 11 11 camPosition=483.398f 242.364f 186.078f 12 12 camDirection=1 0 0 13 lightDir=-0.8f 1.0f -0.7f 13 14 useFullScreen=0 14 15 useLODs=1 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r2946 r2952 8 8 #include "Halton.h" 9 9 #include "ShadowMapping.h" 10 #include "Light.h" 10 11 11 12 … … 91 92 static CGparameter sNoiseTexShadowParam; 92 93 static CGparameter sSamplesShadowParam; 94 95 static CGparameter sLightDirParam; 96 static CGparameter sLightDirShadowParam; 93 97 94 98 … … 245 249 if (sCgAntiAliasingProgram) cgDestroyProgram(sCgAntiAliasingProgram); 246 250 247 //DEL_PTR(mNewFbo);248 //DEL_PTR(mOldFbo);249 251 DEL_PTR(mFbo); 250 252 … … 277 279 sColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "colors"); 278 280 sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "normals"); 281 sLightDirParam = cgGetNamedParameter(sCgDeferredProgram, "lightDir"); 279 282 } 280 283 else … … 427 430 sNoiseTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "noiseTexture"); 428 431 sSamplesShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "samples"); 432 sLightDirShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "lightDir"); 429 433 430 434 PoissonDiscSampleGenerator2 poisson(16, 1.0f); … … 444 448 const Matrix4x4 &projViewMatrix, 445 449 float tempCohFactor, 450 DirectionalLight *light, 446 451 ShadowMap *shadowMap) 447 452 { … … 477 482 478 483 if (shadowMap) 479 FirstPassShadow(fbo, shadowMap);484 FirstPassShadow(fbo, light, shadowMap); 480 485 else 481 FirstPass(fbo );486 FirstPass(fbo, light); 482 487 483 488 switch (mShadingMethod) … … 691 696 692 697 693 void DeferredRenderer::FirstPass(FrameBufferObject *fbo )698 void DeferredRenderer::FirstPass(FrameBufferObject *fbo, DirectionalLight *light) 694 699 { 695 700 GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); … … 717 722 cgGLEnableTextureParameter(sNormalsTexDeferredParam); 718 723 724 Vector3 lightDir = -light->GetDirection(); 725 cgGLSetParameter3f(sLightDirParam, lightDir.x, lightDir.y, lightDir.z); 726 719 727 glColor3f(1.0f, 1.0f, 1.0f); 720 728 … … 952 960 953 961 954 void DeferredRenderer::FirstPassShadow(FrameBufferObject *fbo, ShadowMap *shadowMap) 962 void DeferredRenderer::FirstPassShadow(FrameBufferObject *fbo, 963 DirectionalLight *light, 964 ShadowMap *shadowMap) 955 965 { 956 966 GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); … … 995 1005 cgGLEnableTextureParameter(sNoiseTexShadowParam); 996 1006 1007 Vector3 lightDir = -light->GetDirection(); 1008 cgGLSetParameter3f(sLightDirShadowParam, lightDir.x, lightDir.y, lightDir.z); 1009 997 1010 998 1011 glColor3f(1.0f, 1.0f, 1.0f); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r2944 r2952 1 #ifndef _D eferredRenderer_H__2 #define _D eferredRenderer_H__1 #ifndef _DEFERREDRENDERER_H__ 2 #define _DEFERREDRENDERER_H__ 3 3 4 4 #include "common.h" … … 17 17 class Matrix4x4; 18 18 class ShadowMap; 19 class DirectionalLight; 19 20 20 21 … … 29 30 30 31 The parameter scaleFactor must be reciprocal value of the 31 scale factor used for creating the positionstexture. It is used recover the32 scale factor used for creating the world space position texture. It is used recover the 32 33 exact scene size that was scaled in order to improve floating point precision. 33 34 */ … … 42 43 const Matrix4x4 &projViewMatrix, 43 44 float tempCohFactor, 45 DirectionalLight *light, 44 46 ShadowMap *shadowMap = NULL); 45 47 … … 69 71 void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix); 70 72 71 void FirstPass(FrameBufferObject *fbo );73 void FirstPass(FrameBufferObject *fbo, DirectionalLight *light); 72 74 73 void FirstPassShadow(FrameBufferObject *fbo, ShadowMap *shadowMap);75 void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap); 74 76 75 77 void CombineSsao(FrameBufferObject *fbo); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Light.h
r2891 r2952 12 12 /** Class representing a directional light source 13 13 */ 14 class Light14 class DirectionalLight 15 15 { 16 16 public: 17 17 18 Light(const Vector3 &dir, const RgbaColor &col): mDirection(dir), mColor(col) {}18 DirectionalLight(const Vector3 &dir, const RgbaColor &col): mColor(col) { mDirection = Normalize(dir); } 19 19 20 20 Vector3 GetDirection() const { return mDirection; } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2951 r2952 137 137 138 138 139 ShadowMap::ShadowMap( Light *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam):139 ShadowMap::ShadowMap(DirectionalLight *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam): 140 140 mSceneBox(sceneBox), mSize(size), mCamera(cam), mLight(light) 141 141 { … … 456 456 const Vector3 projViewDir = GetProjViewDir(lightView * lightProj, frustumPoints); 457 457 458 //do Light Space Perspective shadow mapping458 //do DirectionalLight Space Perspective shadow mapping 459 459 //rotate the lightspace so that the projected light view always points upwards 460 460 //calculate a frame matrix that uses the projViewDir[lightspace] as up vector -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
r2947 r2952 19 19 class Vector3; 20 20 class Camera; 21 class Light;21 class DirectionalLight; 22 22 23 23 /** This class implements a the computation of single shadow map … … 30 30 The shadow map has resolution size * size. 31 31 */ 32 ShadowMap( Light *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam);32 ShadowMap(DirectionalLight *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam); 33 33 34 34 ~ShadowMap(); … … 115 115 Matrix4x4 mTextureMatrix; 116 116 /// the used light 117 Light *mLight;117 DirectionalLight *mLight; 118 118 /// the scene camera 119 119 Camera *mCamera; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp
r2951 r2952 8 8 9 9 CGparameter Transform3::sModelMatrixParam; 10 10 11 11 12 Transform3::Transform3(Matrix4x4 *trafo): mMatrix(trafo) … … 23 24 { 24 25 if (!mMatrix) return; 25 26 26 27 if (state->GetRenderType() == RenderState::DEFERRED) 27 28 { 28 29 cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mMatrix->x); 29 30 } 30 // else 31 // { 32 glPushMatrix(); 33 glMultMatrixf((float *)mMatrix->x); 34 // } 31 32 glPushMatrix(); 33 glMultMatrixf((float *)mMatrix->x); 35 34 } 36 35 … … 45 44 cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)identity.x); 46 45 } 47 // else 48 // { 49 glPopMatrix(); 50 // } 46 47 glPopMatrix(); 51 48 } 52 49 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h
r2840 r2952 3 3 4 4 #include "glInterface.h" 5 #include "common.h" 5 6 #include <Cg/cg.h> 6 7 #include <Cg/cgGL.h> 7 #include "common.h" 8 8 9 9 10 namespace CHCDemoEngine … … 37 38 static CGparameter sModelMatrixParam; 38 39 39 40 40 protected: 41 41 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2951 r2952 184 184 185 185 ShadowMap *shadowMap = NULL; 186 Light *light = NULL;186 DirectionalLight *light = NULL; 187 187 DeferredRenderer *ssaoShader = NULL; 188 188 189 189 190 … … 242 243 static CGprogram sCgMrtVertexProgram = NULL; 243 244 244 static CGparameter sModelViewProjMatrixParam;245 245 static CGparameter sMaxDepthParam; 246 246 static CGparameter sMaxDepthParamTex; 247 248 247 static Matrix4x4 oldViewProjMatrix; 249 248 … … 284 283 Vector3 camPos(.0f, .0f, .0f); 285 284 Vector3 camDir(.0f, 1.0f, .0f); 285 Vector3 lightDir(-0.8f, 1.0f, -0.7f); 286 286 287 287 cout << "=== reading environment file ===" << endl << endl; … … 308 308 env.GetVectorParam(string("camPosition"), camPos); 309 309 env.GetVectorParam(string("camDirection"), camDir); 310 env.GetVectorParam(string("lightDirection"), lightDir); 310 311 311 312 env.GetBoolParam(string("useLODs"), useLODs); … … 345 346 346 347 visCamera = new Camera(winWidth, winHeight, fov); 347 348 348 visCamera->SetNear(0.0f); 349 349 visCamera->Yaw(.5 * M_PI); 350 351 // create a new light 352 light = new DirectionalLight(lightDir, RgbaColor(1, 1, 1, 1)); 353 350 354 351 355 renderQueue = new RenderQueue(&state, camera); … … 449 453 sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 450 454 451 //Vector3 lightDir = Normalize(Vector3(0.2, -0.8, -1));452 Vector3 lightDir = Normalize(-Vector3(0.8f, -1.0f, 0.7f));453 454 light = new Light(lightDir, RgbaColor(1, 1, 1, 1));455 456 457 455 // frame time is restarted every frame 458 456 frameTimer.Start(); … … 495 493 cgGLLoadProgram(sCgMrtVertexProgram); 496 494 497 Transform3::sModelMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelMatrix");498 sModelViewProjMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelViewProj");495 //sInvViewProjParam = cgGetNamedParameter(sCgMrtVertexProgram, "InvViewProj"); 496 Transform3::sModelMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelView"); 499 497 } 500 498 … … 757 755 glLightfv(GL_LIGHT0, GL_SPECULAR, specular); 758 756 759 GLfloat position[] = {0.8f, -1.0f, 0.7f, 0.0f}; 757 Vector3 lightDir = -light->GetDirection(); 758 GLfloat position[] = {lightDir.x, lightDir.y, lightDir.z, 0.0f}; 760 759 glLightfv(GL_LIGHT0, GL_POSITION, position); 761 760 … … 802 801 glMatrixMode(GL_PROJECTION); 803 802 glLoadIdentity(); 804 805 803 gluPerspective(fov, winAspectRatio, nearDist, farDist); 806 804 … … 823 821 if ((renderType == RenderState::DEFERRED) || (renderType == RenderState::DEPTH_PASS_DEFERRED)) 824 822 { 825 // set modelview matrix for shaders 826 cgGLSetStateMatrixParameter(sModelViewProjMatrixParam, 827 CG_GL_MODELVIEW_PROJECTION_MATRIX, 828 CG_GL_MATRIX_IDENTITY); 829 830 static Matrix4x4 identity = IdentityMatrix(); 831 cgGLSetMatrixParameterfc(Transform3::sModelMatrixParam, (const float *)identity.x); 832 } 823 cgGLSetMatrixParameterfc(Transform3::sModelMatrixParam, (const float *)IdentityMatrix().x); 824 } 833 825 } 834 826 … … 1012 1004 1013 1005 // set up lights 1014 GLfloat position[] = {0.8f, -1.0f, 0.7f, 0.0f}; 1015 glLightfv(GL_LIGHT0, GL_POSITION, position); 1016 1017 #if 0 1018 GLfloat position1[] = {-0.5f, 0.5f, 0.4f, 0.0f}; 1019 glLightfv(GL_LIGHT1, GL_POSITION, position1); 1020 #endif 1006 Vector3 lightDir = -light->GetDirection(); 1007 GLfloat lightPos[] = {lightDir.x, lightDir.y, lightDir.z, 0.0f}; 1008 glLightfv(GL_LIGHT0, GL_POSITION, lightPos); 1009 1010 // second light 1011 //GLfloat lightPos1[] = {-0.5f, 0.5f, 0.4f, 0.0f}; 1012 //glLightfv(GL_LIGHT1, GL_POSITION, lightPos1); 1013 1021 1014 1022 1015 if (renderLightView) … … 1090 1083 1091 1084 ShadowMap *sm = showShadowMap ? shadowMap : NULL; 1092 ssaoShader->Render(fbo, oldViewProjMatrix, matProjectionView, ssaoTempCohFactor, sm);1085 ssaoShader->Render(fbo, oldViewProjMatrix, matProjectionView, ssaoTempCohFactor, light, sm); 1093 1086 } 1094 1087 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2945 r2952 33 33 uniform float4 position, 34 34 uniform float3 normal, 35 uniform float amb) 36 { 37 const float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 38 const float3 light = normalize(lightDir.xyz); 39 const float diffuseLight = saturate(dot(normal, light)); 35 uniform float amb, 36 float3 lightDir) 37 { 38 const float diffuseLight = saturate(dot(normal, lightDir)); 40 39 41 40 /* … … 60 59 uniform sampler2D colors, 61 60 uniform sampler2D positions, 62 uniform sampler2D normals 61 uniform sampler2D normals, 62 uniform float3 lightDir 63 63 ) 64 64 { … … 74 74 float3 normal = normalize(norm.xyz); 75 75 76 float4 col = shade(IN, color, position, normal, amb );76 float4 col = shade(IN, color, position, normal, amb, lightDir); 77 77 78 78 //OUT.color = float4(1.0f); … … 88 88 uniform float w, 89 89 uniform float2 lightSpacePos, 90 float depth,90 uniform float depth, 91 91 uniform float2 samples[NUM_SAMPLES], 92 92 uniform sampler2D noiseTexture … … 132 132 uniform float4x4 shadowMatrix, 133 133 uniform float maxDepth, 134 uniform float sampleWidth 134 uniform float sampleWidth, 135 uniform float3 lightDir 135 136 ) 136 137 { … … 219 220 uniform float sampleWidth, 220 221 uniform sampler2D noiseTexture, 221 uniform float2 samples[NUM_SAMPLES] 222 uniform float2 samples[NUM_SAMPLES], 223 uniform float3 lightDir 222 224 ) 223 225 { … … 229 231 230 232 const float3 normal = normalize(norm.xyz); 231 const float3 lightDir = normalize(float3(0.8f, -1.0f, 0.7f)); 232 233 233 234 // hack: an emmisive color term 234 235 float emmisive = norm.w; … … 240 241 // calc diffuse illumination + shadow term 241 242 if ((emmisive < 0.95f) // hack: prevent shadowing the sky 242 && (angle > 1e-3f) 243 && (angle > 1e-3f) // shadow only if diffuse color has some minimum intensity 243 244 ) 244 245 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r2951 r2952 48 48 vtxout vtx(vtxin IN, 49 49 const uniform float4x4 ModelViewProj, 50 uniform float4x4 Model Matrix)50 uniform float4x4 ModelView) 51 51 { 52 vtxout OUT; 53 54 // transform the vertex position into eye space 55 OUT.color = IN.color; 52 vtxout OUT; 56 53 57 OUT.texCoord = IN.texCoord; 58 OUT.worldPos = mul(ModelMatrix, IN.position);54 // transform the vertex position into eye space 55 OUT.color = IN.color; 59 56 60 // transform the vertex position into eye space 61 //OUT.position = mul(ModelViewProj, OUT.worldPos); 62 OUT.position = mul(glstate.matrix.mvp, IN.position); 57 OUT.texCoord = IN.texCoord; 63 58 64 OUT.normal = IN.normal; 59 // transform the vertex position into eye space 60 OUT.position = mul(glstate.matrix.mvp, IN.position); 61 //OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position); 62 OUT.worldPos = mul(ModelView, IN.position); 65 63 66 OUT.mypos = OUT.position;64 OUT.normal = IN.normal; 67 65 68 return OUT; 66 OUT.mypos = OUT.position; 67 68 return OUT; 69 69 } 70 70
Note: See TracChangeset
for help on using the changeset viewer.