- Timestamp:
- 09/19/08 17:40:48 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ObjConverter.cpp
r2957 r2958 112 112 // Material *mat = new Material(RgbaColor(0, 1, 0, 1)); 113 113 Material *mat = new Material(); 114 mat->SetAmbient(RgbaColor(0, 0, 0, 0)); 115 mat->SetDiffuse(RgbaColor(0, 0, 0, 0)); 116 114 117 Geometry *geom = new Geometry(_vertices, _normals, _texcoords, numElements, false); 115 118 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
r2957 r2958 82 82 float sun_theta[2]; 83 83 84 //sun_theta[0] = acos(sunDir.y);85 84 sun_theta[0] = acos(sunDir.z); 86 85 … … 124 123 ABCDE_Y[4] = -0.06696 * mTurbidity + 0.37027; 125 124 126 //F().getRenderDevice().setDefaultDepthStencilMode(FRenderDevice::DEPTHSTENCIL_TEST_NO_OVERWRITE);127 125 128 126 // Move skybox with camera. 129 127 Vector3 position = camera->GetPosition(); 130 128 131 132 129 const float scaleFactor = 100.0f; 133 130 … … 137 134 Matrix4x4 s = ScaleMatrix(scaleFactor, scaleFactor, scaleFactor); 138 135 mSkyDome->GetTransform()->SetMatrix(s * m); 139 140 136 141 137 cgGLSetParameter3f(sLightDirParam, sunDir.x, sunDir.y, sunDir.z); … … 149 145 cgGLSetParameter3f(sEColorParam, ABCDE_x[4], ABCDE_y[4], ABCDE_Y[4]); 150 146 151 /*mEffect->setVariableVector3("LightDirection", D().getScene().getLight().getDirection());152 mEffect->setVariableVector2("ThetaSun", sun_theta);153 mEffect->setVariableVector3("ZenithColor", zenithColor);154 mEffect->setVariableVector3("AColor",FVector3((FFloat)ABCDE_x[0], (FFloat)ABCDE_y[0], (FFloat)ABCDE_Y[0]));155 mEffect->setVariableVector3("BColor",FVector3((FFloat)ABCDE_x[1], (FFloat)ABCDE_y[1], (FFloat)ABCDE_Y[1]));156 mEffect->setVariableVector3("CColor",FVector3((FFloat)ABCDE_x[2], (FFloat)ABCDE_y[2], (FFloat)ABCDE_Y[2]));157 mEffect->setVariableVector3("DColor",FVector3((FFloat)ABCDE_x[3], (FFloat)ABCDE_y[3], (FFloat)ABCDE_Y[3]));158 mEffect->setVariableVector3("EColor",FVector3((FFloat)ABCDE_x[4], (FFloat)ABCDE_y[4], (FFloat)ABCDE_Y[4]));159 */160 161 147 cgGLEnableProfile(RenderState::sCgVertexProfile); 162 148 cgGLBindProgram(sCgSkyProgram); 149 150 163 151 164 152 // Render sky dome. … … 166 154 167 155 // Render additively blended sun disc. 168 RenderSunDisk(); 169 } 170 171 172 void SkyPreetham::RenderSunDisk() 173 { 174 /* 175 F().getRenderDevice().setDefaultBlendingMode(FRenderDevice::BLENDING_ADDITIVE); 156 //RenderSunDisk(sunDir, camera); 157 } 158 159 160 void SkyPreetham::RenderSunDisk(const Vector3 &sunDir, Camera *camera) 161 { 162 // Move skybox with camera. 163 Vector3 position = camera->GetPosition(); 164 165 const float scaleFactor = 100.0f; 166 position.z -= 10 * scaleFactor; 176 167 177 168 // Set world matrix to sun disc position. 178 FMatrix4 sunposition; 179 sunposition.translate(D().getScene().getCamera().getPosition()); 180 sunposition.rotateAroundY(-D().getScene().getLight().getHorizontalOrientation() + 90.0f); 181 sunposition.rotateAroundX(-D().getScene().getLight().getVerticalOrientation()); 182 F().getRenderDevice().getTransform().setWorldMatrix(sunposition); 183 184 FVector3 lightdirection = D().getScene().getLight().getDirection(); 185 FFloat size = 0.5f + (1.0f - lightdirection.y) * 0.5f; 186 187 mSunEffect->setVariableVector3("LightDiffuseColor", D().getScene().getLight().getDiffuseColor()); 188 mSunEffect->setVariableFloat("SunSize", size); 189 mSunEffect->setVariableTexture2D("SunTexture", mSunTexture); 190 191 mSunEffect->activate(); 169 Matrix4x4 sunPos = TranslationMatrix(position); 170 171 Vector3 ndir = -Normalize(sunDir); 172 173 const float pitch = -atan2(ndir.x, ndir.y); 174 const float yaw = atan2(ndir.z, sqrt((ndir.x * ndir.x) + (ndir.y * ndir.y))); 175 176 Matrix4x4 roty = RotationYMatrix(pitch); 177 Matrix4x4 rotx = RotationXMatrix(yaw); 178 179 sunPos *= roty; 180 sunPos *= rotx;; 181 182 //sunposition.rotateAroundY(-D().getScene().getLight().getHorizontalOrientation() + 90.0f); 183 //sunposition.rotateAroundX(-D().getScene().getLight().getVerticalOrientation()); 184 185 glMatrixMode(GL_MODELVIEW); 186 glMultMatrixf((float *)sunPos.x); 187 188 float ambient[] = {1.0f, 1.0f, 1.0f, 1.0f}; 189 190 glMaterialfv(GL_FRONT, GL_AMBIENT, ambient); 191 192 //Float size = 0.5f + (1.0f - lightdirection.y) * 0.5f; 193 194 //mSunEffect->setVariableVector3("LightDiffuseColor", D().getScene().getLight().getDiffuseColor()); 195 //mSunEffect->setVariableFloat("SunSize", size); 196 //mSunEffect->setVariableTexture2D("SunTexture", mSunTexture); 197 198 /*mSunEffect->activate(); 192 199 193 200 mSunQuad->render(); 194 201 195 202 mSunEffect->deactivate(); 196 197 F().getRenderDevice().setDefaultBlendingMode(FRenderDevice::BLENDING_NONE); 198 */203 F().getRenderDevice().setDefaultBlendingMode(FRenderDevice::BLENDING_NONE);*/ 204 205 glPopMatrix(); 199 206 } 200 207 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.h
r2957 r2958 28 28 protected: 29 29 30 void RenderSunDisk( );30 void RenderSunDisk(const CHCDemoEngine::Vector3 &lightDir, CHCDemoEngine::Camera *camera); 31 31 void CreateSunQuad(); 32 32 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2957 r2958 171 171 172 172 173 174 173 /// the used render type for this render pass 175 174 enum RenderMethod … … 274 273 static CGparameter sMaxDepthParamTex; 275 274 static Matrix4x4 oldViewProjMatrix; 275 static CGprogram sCgMrtFragmentSkyDomeProgram = NULL; 276 276 277 277 … … 547 547 cerr << "fragment tex program failed to load" << endl; 548 548 549 RenderState::sCgMrtFragmentProgram =549 sCgMrtFragmentSkyDomeProgram = 550 550 cgCreateProgramFromFile(sCgContext, 551 551 CG_SOURCE, 552 "src/shaders/ mrt.cg",552 "src/shaders/sky_preetham.cg", 553 553 RenderState::sCgFragmentProfile, 554 "frag ",554 "frag_skydome", 555 555 NULL); 556 556 557 if ( RenderState::sCgMrtFragmentProgram != NULL)558 { 559 cgGLLoadProgram( RenderState::sCgMrtFragmentProgram);560 561 sMaxDepthParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "maxDepth");557 if (sCgMrtFragmentSkyDomeProgram != NULL) 558 { 559 cgGLLoadProgram(sCgMrtFragmentSkyDomeProgram); 560 561 /*sMaxDepthParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "maxDepth"); 562 562 Material::sDiffuseParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "diffuse"); 563 563 Material::sAmbientParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "ambient"); 564 564 565 565 cgGLSetParameter1f(sMaxDepthParam, MAX_DEPTH_CONST / farDist); 566 */ 566 567 } 567 568 else 568 cerr << "fragment program failed to load" << endl;569 cerr << "fragment skyprogram failed to load" << endl; 569 570 570 571 PrintGLerror("init"); … … 617 618 void InitGLstate() 618 619 { 619 glClearColor(0. 2f, 0.2f, 0.8f, 1.0f);620 glClearColor(0.3f, 0.3f, 0.4f, 1.0f); 620 621 621 622 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); … … 675 676 ////////////////////////////// 676 677 677 GLfloat lmodel_ambient[] = {0.5f, 0.5f, 0.5f, 1.0f}; 678 //GLfloat lmodel_ambient[] = {0.5f, 0.5f, 0.5f, 1.0f}; 679 GLfloat lmodel_ambient[] = {1.0f, 1.0f, 1.0f, 1.0f}; 678 680 679 681 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); … … 1958 1960 void RenderSky() 1959 1961 { 1962 glEnable(GL_LIGHTING); 1963 cgGLEnableProfile(RenderState::sCgVertexProfile); 1964 1965 if (state.GetRenderPassType() == RenderState::DEFERRED) 1966 { 1967 cgGLEnableProfile(RenderState::sCgFragmentProfile); 1968 cgGLBindProgram(sCgMrtFragmentSkyDomeProgram); 1969 } 1970 1960 1971 SceneEntityContainer::const_iterator sit, sit_end = skyGeometry.end(); 1961 1972 … … 1968 1979 preetham->Compute(-light->GetDirection(), camera, &state); 1969 1980 glEnable(GL_CULL_FACE); 1981 1970 1982 cgGLDisableProfile(RenderState::sCgVertexProfile); 1983 cgGLDisableProfile(RenderState::sCgFragmentProfile); 1971 1984 } 1972 1985 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r2957 r2958 30 30 float4 projPos: WPOS; 31 31 float4 worldPos: TEXCOORD1; // world position 32 33 32 float3 normal: TEXCOORD2; 34 35 33 float4 mypos: TEXCOORD3; 36 34 }; … … 55 53 OUT.texCoord = IN.texCoord; 56 54 55 //OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position); 56 OUT.worldPos = mul(ModelView, IN.position); 57 57 // transform the vertex position into eye space 58 58 OUT.position = mul(glstate.matrix.mvp, IN.position); 59 //OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position);60 OUT.worldPos = mul(ModelView, IN.position);61 59 62 60 OUT.normal = IN.normal; 63 64 61 OUT.mypos = OUT.position; 65 62 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg
r2957 r2958 11 11 float3 color: COLOR; 12 12 float2 texcoord: TEXCOORD0; 13 float3 tangent : TEXCOORD1;14 13 }; 15 14 16 15 17 struct VertexOutput 16 // vtx output 17 struct vtxout 18 18 { 19 float4 position: POSITION; 20 float4 vs_color: COLOR;19 float4 position: POSITION; // eye space 20 float4 texCoord: TEXCOORD0; 21 21 22 float4 color: COLOR0; 23 float4 worldPos: TEXCOORD1; // world position 24 float3 normal: TEXCOORD2; 25 float4 mypos: TEXCOORD3; 22 26 }; 23 27 … … 35 39 36 40 37 VertexOutput default_vs(VertexInput IN, 38 uniform float3 lightDir, 39 uniform float2 thetaSun, 40 uniform float3 zenithColor, 41 uniform float3 aColor, 42 uniform float3 bColor, 43 uniform float3 cColor, 44 uniform float3 dColor, 45 uniform float3 eColor) 41 vtxout default_vs(VertexInput IN, 42 uniform float3 lightDir, 43 uniform float2 thetaSun, 44 uniform float3 zenithColor, 45 uniform float3 aColor, 46 uniform float3 bColor, 47 uniform float3 cColor, 48 uniform float3 dColor, 49 uniform float3 eColor, 50 uniform float4x4 ModelView) 46 51 { 47 VertexOutput OUT; 48 49 //OUT.position = mul(float4(IN.position.xyz, 1.0), WorldViewProjection); 50 //OUT.position = mul(float4(IN.position.xyz, 1.0), glstate.matrix.mvp); 52 vtxout OUT; 53 51 54 OUT.position = mul(glstate.matrix.mvp, IN.position); 52 55 53 56 54 57 const float dotLN = dot(lightDir, IN.normal); 55 58 const float cos2gamma = dotLN * dotLN; 56 59 57 60 const float gamma = acos(dotLN); 58 61 const float theta = dot(float3(0.0, 0.0, 1.0), IN.normal); … … 68 71 XYZ.z = ((1.0f - xyY.x - xyY.y) / xyY.y) * xyY.z; 69 72 70 /*XYZ.x = (xyY.x / xyY.z) * xyY.y;71 XYZ.y = ((1.0 - xyY.x - xyY.z) / xyY.z) * xyY.y;72 XYZ.z = xyY.y;73 */74 //XYZ = float3(1, 1, 0);75 73 const static float3x3 conv_Mat = 76 74 float3x3(3.240479, -1.537150, -0.498535, … … 79 77 80 78 float3 hcol = mul(conv_Mat, XYZ); 79 OUT.color = float4(hcol, 1.0); 81 80 82 /*hcol.x = 3.240479f*XYZ.x -1.537150f*XYZ.y-0.498535f*XYZ.z; 83 hcol.y = -0.969256f*XYZ.x +1.875992f*XYZ.y +0.041556f*XYZ.z; 84 hcol.z = 0.055648f*XYZ.x -0.204043f*XYZ.y +1.057311f*XYZ.z; 85 */ 86 //OUT.vs_color = float4(mul(transpose(conv_Mat), XYZ), 1.0); 87 //OUT.vs_color = float4(mul(XYZ, transpose(conv_Mat)), 1.0); 88 //OUT.vs_color = float4(mul(xyY, conv_Mat), 1.0); 89 OUT.vs_color = float4(hcol, 1.0); 90 //OUT.vs_color = float4(zenithColor, 1.0); 81 OUT.color.rgb *= 5e-5f; 91 82 92 //OUT.vs_color = float4(float3(dotLN), 1.0); 93 //OUT.vs_color.rgb *= 0.0003f; 94 OUT.vs_color.rgb *= 5e-5f; 83 //OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position); 84 OUT.worldPos = mul(ModelView, IN.position); 85 86 OUT.normal = IN.normal; 87 OUT.mypos = OUT.position; 95 88 96 89 return OUT; … … 98 91 99 92 93 pixel frag_skydome(fragin IN, 94 uniform float maxDepth) 95 { 96 pixel pix; 100 97 98 pix.col = IN.color; 99 pix.pos = IN.worldPos;// * maxDepth; 101 100 102 //-------------------------------------------------------------------------------------- 103 // Pixel Shaders 104 //-------------------------------------------------------------------------------------- 101 pix.norm.xyz = IN.normal; 102 103 // hack: squeeze some information about the ambient term into the target 104 pix.norm.w = 0; 105 pix.pos.w = IN.mypos.w; 106 107 // the projected depth 108 pix.col.w = IN.mypos.z / IN.mypos.w; 105 109 106 107 PixelOutput default_ps(VertexOutput IN) 108 { 109 PixelOutput OUT; 110 111 OUT.color = IN.vs_color; 112 113 return OUT; 110 return pix; 114 111 }
Note: See TracChangeset
for help on using the changeset viewer.