From: <axl...@us...> - 2009-08-10 00:38:46
|
Revision: 467 http://hgengine.svn.sourceforge.net/hgengine/?rev=467&view=rev Author: axlecrusher Date: 2009-08-10 00:38:39 +0000 (Mon, 10 Aug 2009) Log Message: ----------- updates Modified Paths: -------------- Mercury2/src/HGMDLModel.cpp Mercury2/src/Light.cpp Mercury2/src/Light.h Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryFBO.h Mercury2/src/MercuryNode.cpp Modified: Mercury2/src/HGMDLModel.cpp =================================================================== --- Mercury2/src/HGMDLModel.cpp 2009-08-09 01:14:31 UTC (rev 466) +++ Mercury2/src/HGMDLModel.cpp 2009-08-10 00:38:39 UTC (rev 467) @@ -69,6 +69,7 @@ for(uint16_t i = 0; i < m_meshes.size(); ++i) culled = culled && m_meshes[i]->DoCullingTests(n, matrix); } + m_culled = culled; return culled; } Modified: Mercury2/src/Light.cpp =================================================================== --- Mercury2/src/Light.cpp 2009-08-09 01:14:31 UTC (rev 466) +++ Mercury2/src/Light.cpp 2009-08-10 00:38:39 UTC (rev 467) @@ -16,15 +16,20 @@ m_color[0] = m_color[1] = m_color[2] = 1.0f; m_radius = 0.0f; m_fullscreen = false; + m_power = 1.0f; } Light::~Light() { } +void Light::PreRender(const MercuryMatrix& matrix) +{ + SetCulled( m_boundingVolume->DoFrustumTest( matrix ) ); +} + void Light::Render(const MercuryMatrix& matrix) { -// printf("render!\n"); m_worldPosition = FindModelViewMatrix(); m_worldPosition2 = FindGlobalMatrix(); CURRENTRENDERGRAPH->AddDifferedLight( this ); @@ -36,6 +41,9 @@ if ( !node.Attribute("atten").empty() ) StrTo3Float(node.Attribute("atten"), m_atten); + if ( !node.Attribute("power").empty() ) + m_power = StrToFloat(node.Attribute("power"), 1.0); + if ( !node.Attribute("fullscreen").empty() ) m_fullscreen = node.Attribute("fullscreen")=="true"?true:false; @@ -74,7 +82,7 @@ { //300 ensures that RGB of 255 reaches 0 //at 50, 255 is about 5. Close enough for me - const float maxDenom = 50;//300; + const float maxDenom = 50; float a = m_atten[2]; //quadratic float b = m_atten[1]; //linear float c = m_atten[0]; //constant @@ -99,11 +107,16 @@ float s = SQRT((b*b)-(4*a*c)); float x1 = ((-b) - s)/bottom; float x2 = ((-b) + s)/bottom; + x1 = x1>=0?x1:-x1; + x2 = x2>=0?x2:-x2; d = MAX<float>(x1,x2); } + d = m_power * d; m_radius = Clamp<float>(0.0f, 1000.0f, d); + printf("light radius %f\n", m_radius); + SAFE_DELETE( m_boundingVolume ); m_boundingVolume = new BoundingBox(MercuryVertex(0,0,0), MercuryVertex(m_radius,m_radius,m_radius) ); } @@ -143,6 +156,7 @@ sa.value.fFloatV4[0] = m_color[0]; sa.value.fFloatV4[1] = m_color[1]; sa.value.fFloatV4[2] = m_color[2]; + sa.value.fFloatV4[3] = m_power; Shader::SetAttribute("HG_LightColor", sa); if (m_fullscreen) Modified: Mercury2/src/Light.h =================================================================== --- Mercury2/src/Light.h 2009-08-09 01:14:31 UTC (rev 466) +++ Mercury2/src/Light.h 2009-08-10 00:38:39 UTC (rev 467) @@ -16,8 +16,7 @@ /** PreRender should be called before any real openGL render commands. It is used to handles things like frustum culling, and occlusion culling. Currently only occlusion culling test is run here.**/ -// virtual void PreRender(const MercuryNode* node); - + virtual void PreRender(const MercuryMatrix& matrix); virtual void Render(const MercuryMatrix& matrix); // virtual void PostRender(const MercuryNode* node) {}; @@ -35,6 +34,7 @@ float m_atten[3]; float m_color[3]; float m_radius; + float m_power; MercuryMatrix m_worldPosition; MercuryMatrix m_worldPosition2; Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-08-09 01:14:31 UTC (rev 466) +++ Mercury2/src/MercuryAsset.cpp 2009-08-10 00:38:39 UTC (rev 467) @@ -6,7 +6,7 @@ extern bool DOOCCLUSIONCULL; MercuryAsset::MercuryAsset() - :m_isInstanced(false), m_boundingVolume(NULL), m_loadState(NONE) + :m_isInstanced(false), m_boundingVolume(NULL), m_loadState(NONE), m_culled(false) { } @@ -48,6 +48,7 @@ if ( !culled && DOOCCLUSIONCULL) m_boundingVolume->DoOcclusionTest( n->GetOcclusionResult() ); } + m_culled = culled; return culled; } Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-08-09 01:14:31 UTC (rev 466) +++ Mercury2/src/MercuryAsset.h 2009-08-10 00:38:39 UTC (rev 467) @@ -57,6 +57,8 @@ inline void SetExcludeFromCull(bool t) { m_excludeFromCull = t; } inline bool ExcludeFromCull() const { return m_excludeFromCull; } + + inline bool IsCulled() const { return m_culled; } protected: void SetLoadState(LoadState ls); //thread safe LoadState GetLoadState(); //thread safe @@ -64,6 +66,7 @@ bool m_isInstanced; BoundingVolume* m_boundingVolume; MString m_path; + bool m_culled; private: LoadState m_loadState; MSemaphore m_lock; Modified: Mercury2/src/MercuryFBO.h =================================================================== --- Mercury2/src/MercuryFBO.h 2009-08-09 01:14:31 UTC (rev 466) +++ Mercury2/src/MercuryFBO.h 2009-08-10 00:38:39 UTC (rev 467) @@ -34,18 +34,10 @@ uint32_t m_fboID, m_depthBufferID; bool m_initiated, m_useDepth, m_useScreenSize; uint16_t m_width, m_height; -// uint32_t m_textureID[4]; MAutoPtr< Texture > m_textures[4]; uint8_t m_numTextures; ColorByteType m_cbt[4]; - -// static uint32_t m_lastRendered; - -// uint32_t m_lastInStask; - protected: -// AlignedBuffer<float> m_vertexData; -// AlignedBuffer<uint16_t> m_indexData; }; #endif Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-08-09 01:14:31 UTC (rev 466) +++ Mercury2/src/MercuryNode.cpp 2009-08-10 00:38:39 UTC (rev 467) @@ -146,7 +146,10 @@ PreRender( matrix ); //calls on children assets for (MercuryNode* child = FirstChild(); child != NULL; child = NextChild(child)) + { child->RecursivePreRender(); + m_culled = m_culled && child->IsCulled(); + } } void MercuryNode::RecursiveRender() @@ -247,7 +250,10 @@ { list< MercuryAsset* >::iterator i; for (i = m_render.begin(); i != m_render.end(); ++i ) - (*i)->Render(this); + { + if ( !(*i)->IsCulled() ) + (*i)->Render(this); + } } void MercuryNode::PostRender(const MercuryMatrix& matrix) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |