Revision: 2634
http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2634&view=rev
Author: ulteq
Date: 2012-05-23 16:28:00 +0000 (Wed, 23 May 2012)
Log Message:
-----------
-Bugfix: fixes the reflections of Ogre materials (environment map) - thanks for
the help Miura
~modified nicemetal shader in materials.zip
+new Setting "EnvmapUpdateRate" minimum = default = 1; maximum = 6. Specifies
how many cube faces are updated per frame.
Modified Paths:
--------------
trunk/bin/resources/materials.zip
trunk/source/main/gameplay/RoRFrameListener.cpp
trunk/source/main/gfx/envmap.cpp
trunk/source/main/gfx/envmap.h
Modified: trunk/bin/resources/materials.zip
===================================================================
(Binary files differ)
Modified: trunk/source/main/gameplay/RoRFrameListener.cpp
===================================================================
--- trunk/source/main/gameplay/RoRFrameListener.cpp 2012-05-22 22:22:53 UTC
(rev 2633)
+++ trunk/source/main/gameplay/RoRFrameListener.cpp 2012-05-23 16:28:00 UTC
(rev 2634)
@@ -4381,7 +4381,7 @@
//environment map
if (!BSETTING("Envmapdisable", false))
{
- envmap = new Envmap(mSceneMgr, mWindow, mCamera,
BSETTING("Envmap", false));
+ envmap = new Envmap(mSceneMgr, mWindow, mCamera,
BSETTING("Envmap", false), ISETTING("EnvmapUpdateRate", 1));
}
//dashboard
@@ -5056,12 +5056,6 @@
#endif // 0
collisions->finishLoadingTerrain();
-
- //okay, taking a picture of the scene for the envmap
- //SAY CHEESE!
- //no, not yet, Caelum is not ready!
- //if (envmap) envmap->update(Vector3(terrainxsize/2.0,
hfinder->getHeightAt(terrainxsize/2.0, terrainzsize/2.0)+50.0,
terrainzsize/2.0));
-
}
void RoRFrameListener::initTrucks(bool loadmanual, Ogre::String selected,
Ogre::String selectedExtension, std::vector<Ogre::String> *truckconfig, bool
enterTruck, Skin *skin)
@@ -5486,12 +5480,6 @@
if (curr_truck)
{
envmap->update(curr_truck->getPosition(), curr_truck);
-#ifdef USE_CAELUM
- if (SkyManager::singletonExists())
- {
-
SkyManager::getSingleton().notifyCameraChanged(mCamera);
- }
-#endif // USE_CAELUM
} else
{
envmap->update(Vector3(terrainxsize / 2.0f,
hfinder->getHeightAt(terrainxsize / 2.0f, terrainzsize / 2.0f ) + 50.0f,
terrainzsize / 2.0f));
Modified: trunk/source/main/gfx/envmap.cpp
===================================================================
--- trunk/source/main/gfx/envmap.cpp 2012-05-22 22:22:53 UTC (rev 2633)
+++ trunk/source/main/gfx/envmap.cpp 2012-05-23 16:28:00 UTC (rev 2634)
@@ -26,11 +26,13 @@
using namespace Ogre;
-Envmap::Envmap(SceneManager *scm, RenderWindow *rw, Camera *cam, bool dynamic)
:
+Envmap::Envmap(Ogre::SceneManager *scm, Ogre::RenderWindow *rw, Ogre::Camera
*cam, bool dynamic, int updateRate /* = 1 */) :
mDebugSceneNode(0)
+ , mInitiated(false)
, mIsDynamic(dynamic)
- , mInitiated(false)
+ , mMainCamera(cam)
, mRound(0)
+ , updateRate(updateRate)
{
TexturePtr texture =
TextureManager::getSingleton().createManual("EnvironmentTexture",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
TEX_TYPE_CUBE_MAP, 256, 256, 0,
@@ -39,12 +41,12 @@
for (int face=0; face < NUM_FACES; face++)
{
mRenderTargets[face] =
texture->getBuffer(face)->getRenderTarget();
-
mCameras[face] = scm->createCamera("EnvironmentCamera-" +
TOSTRING(face));
mCameras[face]->setAspectRatio(1.0);
mCameras[face]->setProjectionType(PT_PERSPECTIVE);
+ mCameras[face]->setFixedYawAxis(false);
mCameras[face]->setFOVy(Degree(90));
- mCameras[face]->setNearClipDistance(0.1); //why this does not
work, I wonder.
+ mCameras[face]->setNearClipDistance(0.1f);
mCameras[face]->setFarClipDistance(cam->getFarClipDistance());
Viewport *v = mRenderTargets[face]->addViewport(mCameras[face]);
@@ -56,28 +58,29 @@
switch (face)
{
case 0:
- mCameras[face]->setDirection(-1, 0, 0); // <-- should
be +X
+ mCameras[face]->setDirection(+Vector3::UNIT_X);
break;
case 1:
- mCameras[face]->setDirection(1, 0, 0); // <-- should
be -X
+ mCameras[face]->setDirection(-Vector3::UNIT_X);
break;
case 2:
- mCameras[face]->setDirection(0, 0, 1);
- mCameras[face]->pitch(Degree(90));
+ mCameras[face]->setDirection(+Vector3::UNIT_Y);
break;
case 3:
- mCameras[face]->setDirection(0, 0, 1);
- mCameras[face]->pitch(Degree(-90));
+ mCameras[face]->setDirection(-Vector3::UNIT_Y);
break;
case 4:
- mCameras[face]->setDirection(0, 0, 1);
+ mCameras[face]->setDirection(-Vector3::UNIT_Z);
break;
case 5:
- mCameras[face]->setDirection(0, 0, -1);
+ mCameras[face]->setDirection(+Vector3::UNIT_Z);
break;
}
}
-
+
+ updateRate = std::max(0, updateRate);
+ updateRate = std::min(updateRate, 6);
+
if (BSETTING("EnvMapDebug", false))
{
// create fancy mesh for debugging the envmap
@@ -85,7 +88,7 @@
if (overlay)
{
Vector3 position = Vector3::ZERO;
- Vector3 scale = Vector3(1,1,1);
+ float scale = 1.0f;
MeshPtr mesh =
MeshManager::getSingletonPtr()->createManual("cubeMapDebug",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
// create sub mesh
@@ -117,7 +120,7 @@
// Vertex data
static const float vertexData[] = {
- // Position Texture coordinates // Index
+ // Position Texture coordinates // Index
0.0, 2.0, -1.0, 1.0, 1.0, // 0
0.0, 1.0, -1.0, -1.0, 1.0, // 1
1.0, 2.0, -1.0, 1.0, -1.0, // 2
@@ -136,11 +139,11 @@
// Fill vertex buffer
float *pData =
static_cast<float*>(vertexBuffer->lock(HardwareBuffer::HBL_DISCARD));
- for (size_t vertex = 0, i = 0; vertex <
mesh->sharedVertexData->vertexCount; ++vertex)
+ for (size_t vertex=0, i=0; vertex <
mesh->sharedVertexData->vertexCount; vertex++)
{
// Position
- *pData++ = position.x + scale.x * vertexData[i++];
- *pData++ = position.y + scale.y * vertexData[i++];
+ *pData++ = position.x + scale * vertexData[i++];
+ *pData++ = position.y + scale * vertexData[i++];
*pData++ = 0.0;
// Texture coordinates
@@ -161,7 +164,7 @@
// Index data
static const uint16 indexData[] = {
- // Indices // Face
+ // Indices // Face
0, 1, 2, // 0
2, 1, 3, // 1
2, 3, 4, // 2
@@ -201,18 +204,22 @@
overlay->show();
// example update
- forceUpdate(Vector3::ZERO);
+ init(Vector3::ZERO);
}
}
}
-void Envmap::update(Ogre::Vector3 center, Beam *beam/* =0 */)
+void Envmap::update(Ogre::Vector3 center, Beam *beam /* = 0 */)
{
- if (!mIsDynamic)
+ if (!mIsDynamic || !beam)
{
- if (mInitiated) return;
- else forceUpdate(center);
+ if (!mInitiated)
+ {
+ init(center);
+ }
+ return;
}
+
for (int i=0; i < NUM_FACES; i++)
{
mCameras[i]->setPosition(center);
@@ -227,26 +234,34 @@
beam->setMeshVisibility(false);
}
- // caelum needs to know that we changed the cameras
+ for (int i=0; i < updateRate; i++)
+ {
+ // caelum needs to know that we changed the cameras
+ #ifdef USE_CAELUM
+ if (SkyManager::singletonExists())
+ {
+
SkyManager::getSingleton().notifyCameraChanged(mCameras[mRound]);
+ }
+ #endif // USE_CAELUM
+ mRenderTargets[mRound]->update();
+ mRound = (mRound + 1) % NUM_FACES;
+ }
#ifdef USE_CAELUM
if (SkyManager::singletonExists())
{
-
SkyManager::getSingleton().notifyCameraChanged(mCameras[mRound]);
+ SkyManager::getSingleton().notifyCameraChanged(mMainCamera);
}
#endif // USE_CAELUM
- mRenderTargets[mRound]->update();
if (toggleMeshes)
{
beam->setMeshVisibility(true);
}
-
- mRound = (mRound + 1) % NUM_FACES;
}
-void Envmap::forceUpdate(Vector3 center)
+void Envmap::init(Vector3 center)
{
- if (mInitiated) return;
+ if (mIsDynamic) return;
// capture all images at once
for (int i=0; i < NUM_FACES; i++)
Modified: trunk/source/main/gfx/envmap.h
===================================================================
--- trunk/source/main/gfx/envmap.h 2012-05-22 22:22:53 UTC (rev 2633)
+++ trunk/source/main/gfx/envmap.h 2012-05-23 16:28:00 UTC (rev 2634)
@@ -26,24 +26,26 @@
{
public:
- Envmap(Ogre::SceneManager *scm, Ogre::RenderWindow *rw, Ogre::Camera
*cam, bool dynamic);
+ Envmap(Ogre::SceneManager *scm, Ogre::RenderWindow *rw, Ogre::Camera
*cam, bool dynamic, int updateRate = 1);
void prepareShutdown() {};
- void update(Ogre::Vector3 center, Beam *beam=0);
+ void update(Ogre::Vector3 center, Beam *beam = 0);
private:
- void forceUpdate(Ogre::Vector3 center);
+ void init(Ogre::Vector3 center);
static const unsigned int NUM_FACES = 6;
Ogre::Camera *mCameras[NUM_FACES];
+ Ogre::Camera *mMainCamera;
Ogre::RenderTarget *mRenderTargets[NUM_FACES];
Ogre::SceneNode *mDebugSceneNode;
bool mInitiated;
bool mIsDynamic;
int mRound;
+ int updateRate;
};
#endif // __Environment_Map_H_
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel