Watergit push!
This commit is contained in:
@@ -22,6 +22,16 @@ WaterModule::WaterModule(flecs::world &ecs)
|
||||
float delta = eng.delta;
|
||||
if (!water.mWaterEnt || !water.mWaterNode) {
|
||||
std::cout << "Water setup\n";
|
||||
water.mDepthMaterial =
|
||||
Ogre::MaterialManager::getSingleton()
|
||||
.getByName("Water/Depth");
|
||||
OgreAssert(water.mDepthMaterial,
|
||||
"Water Depth material not found.");
|
||||
water.mDepthMaterial->load();
|
||||
water.mDepthTech =
|
||||
water.mDepthMaterial->getBestTechnique();
|
||||
OgreAssert(water.mDepthTech,
|
||||
"Bad material technique");
|
||||
water.mAbove = false;
|
||||
water.mInRefTexUpdate = false;
|
||||
water.mRenderTargetListener.mSurface = &water;
|
||||
@@ -31,19 +41,16 @@ WaterModule::WaterModule(flecs::world &ecs)
|
||||
Ogre::Plane(Ogre::Vector3::UNIT_Y, 0);
|
||||
water.mReflectionPlane = Ogre::Plane(
|
||||
Ogre::Vector3(0.0, 1.0, 0.0),
|
||||
0.0f /* water height */);
|
||||
0.5f /* water height */);
|
||||
float h = 0.0f;
|
||||
water.mReflectionClipPlaneAbove = Ogre::Plane(
|
||||
Ogre::Vector3(0.0, 1.0, 0.0),
|
||||
0.0f /* water height */ - 2.0f);
|
||||
Ogre::Vector3(0.0, 1.0, 0.0), -h);
|
||||
water.mReflectionClipPlaneBelow = Ogre::Plane(
|
||||
Ogre::Vector3(0.0, -1.0, 0.0),
|
||||
-(0.0f /* water height */ + 2.0));
|
||||
Ogre::Vector3(0.0, -1.0, 0.0), h);
|
||||
water.mRefractionClipPlaneAbove = Ogre::Plane(
|
||||
Ogre::Vector3(0.0, -1.0, 0.0),
|
||||
-(0.0f /* water height */ + 2.0));
|
||||
Ogre::Vector3(0.0, -1.0, 0.0), h);
|
||||
water.mRefractionClipPlaneBelow = Ogre::Plane(
|
||||
Ogre::Vector3(0.0, 1.0, 0.0),
|
||||
0.0f /* water height */ - 2.0);
|
||||
Ogre::Vector3(0.0, 1.0, 0.0), -h);
|
||||
#if 0
|
||||
if (Ogre::TextureManager::getSingleton()
|
||||
.resourceExists(renderTargetName))
|
||||
@@ -58,6 +65,58 @@ WaterModule::WaterModule(flecs::world &ecs)
|
||||
Ogre::TEX_TYPE_2D, 512, 512, 0,
|
||||
Ogre::PF_R8G8B8A8,
|
||||
Ogre::TU_RENDERTARGET);
|
||||
Ogre::MaterialPtr debug_mat =
|
||||
Ogre::MaterialManager::getSingleton()
|
||||
.getByName("Water/Debug",
|
||||
"Water");
|
||||
if (!debug_mat) {
|
||||
debug_mat =
|
||||
Ogre::MaterialManager::getSingleton()
|
||||
.create("Water/Debug",
|
||||
"Water");
|
||||
Ogre::Technique *tech =
|
||||
debug_mat->getTechnique(0);
|
||||
Ogre::Pass *pass = tech->getPass(0);
|
||||
pass->setLightingEnabled(false);
|
||||
pass->setAmbient(
|
||||
Ogre::ColourValue(1, 1, 1, 1));
|
||||
pass->setDiffuse(Ogre::ColourValue(
|
||||
0.0f, 0.2f, 0.5f, 1.0f));
|
||||
pass->setDepthCheckEnabled(false);
|
||||
pass->setDepthWriteEnabled(false);
|
||||
pass->setAlphaRejectFunction(
|
||||
Ogre::CMPF_ALWAYS_PASS);
|
||||
pass->setCullingMode(Ogre::CULL_NONE);
|
||||
pass->setManualCullingMode(
|
||||
Ogre::MANUAL_CULL_NONE);
|
||||
Ogre::TextureUnitState *texture_unit =
|
||||
pass->createTextureUnitState();
|
||||
texture_unit->setTextureName(
|
||||
"ReflectionRefractionTexture");
|
||||
Ogre::Sampler::UVWAddressingMode uvw;
|
||||
uvw.u = Ogre::TextureUnitState::TAM_MIRROR;
|
||||
uvw.v = Ogre::TextureUnitState::TAM_MIRROR;
|
||||
uvw.w = Ogre::TextureUnitState::TAM_MIRROR;
|
||||
texture_unit->setTextureAddressingMode(
|
||||
uvw);
|
||||
texture_unit->setTextureFiltering(
|
||||
Ogre::FT_MIN, Ogre::FO_LINEAR);
|
||||
texture_unit->setTextureFiltering(
|
||||
Ogre::FT_MAG, Ogre::FO_LINEAR);
|
||||
texture_unit->setTextureFiltering(
|
||||
Ogre::FT_MIP, Ogre::FO_LINEAR);
|
||||
}
|
||||
// create a frosted screen in front of the camera, using our dynamic texture to "thaw" certain areas
|
||||
Ogre::Entity *ent = eng.mScnMgr->createEntity(
|
||||
"WaterDebugPlane",
|
||||
Ogre::SceneManager::PT_PLANE);
|
||||
ent->setMaterialName("Water/Debug", "Water");
|
||||
ent->setVisibilityFlags(WATER_MASK);
|
||||
Ogre::SceneNode *node =
|
||||
camera.mCameraNode
|
||||
->createChildSceneNode();
|
||||
node->setPosition(-150, 60, -400);
|
||||
node->attachObject(ent);
|
||||
|
||||
water.mReflectionTexture =
|
||||
reflectionTexture->getBuffer()
|
||||
@@ -163,6 +222,18 @@ WaterModule::WaterModule(flecs::world &ecs)
|
||||
Ogre::FT_MAG, Ogre::FO_LINEAR);
|
||||
texture_unit->setTextureFiltering(
|
||||
Ogre::FT_MIP, Ogre::FO_LINEAR);
|
||||
Ogre::TextureUnitState *texture_unit2 =
|
||||
pass->createTextureUnitState();
|
||||
texture_unit2->setTextureName(
|
||||
"waves2.png");
|
||||
texture_unit2->setTextureAddressingMode(
|
||||
uvw);
|
||||
texture_unit2->setTextureFiltering(
|
||||
Ogre::FT_MIN, Ogre::FO_LINEAR);
|
||||
texture_unit2->setTextureFiltering(
|
||||
Ogre::FT_MAG, Ogre::FO_LINEAR);
|
||||
texture_unit2->setTextureFiltering(
|
||||
Ogre::FT_MIP, Ogre::FO_NONE);
|
||||
#if 0
|
||||
bool success =
|
||||
Ogre::RTShader::ShaderGenerator::getSingletonPtr()
|
||||
@@ -220,8 +291,19 @@ WaterModule::WaterModule(flecs::world &ecs)
|
||||
water.mReflectionCamera =
|
||||
eng.mScnMgr->createCamera(
|
||||
"ReflectionCamera");
|
||||
camera.mCamera->getParentSceneNode()
|
||||
->attachObject(water.mReflectionCamera);
|
||||
water.mReflectionDepthCamera =
|
||||
eng.mScnMgr->createCamera(
|
||||
"ReflectionDepthCamera");
|
||||
water.mReflectionCameraNode =
|
||||
camera.mCamera->getParentSceneNode()
|
||||
->createChildSceneNode(
|
||||
"ReflectionCameraNode");
|
||||
water.mReflectionCameraNode->setPosition(
|
||||
Ogre::Vector3(0, 1.0f, 0));
|
||||
water.mReflectionCameraNode->attachObject(
|
||||
water.mReflectionCamera);
|
||||
water.mReflectionCameraNode->attachObject(
|
||||
water.mReflectionDepthCamera);
|
||||
water.mReflectionCamera->setAspectRatio(
|
||||
camera.mCamera->getAspectRatio());
|
||||
water.mReflectionCamera->setNearClipDistance(
|
||||
@@ -234,23 +316,62 @@ WaterModule::WaterModule(flecs::world &ecs)
|
||||
water.mReflectionCamera->enableReflection(
|
||||
water.mReflectionPlane);
|
||||
|
||||
water.mReflectionDepthCamera->setAspectRatio(
|
||||
camera.mCamera->getAspectRatio());
|
||||
water.mReflectionDepthCamera->setNearClipDistance(
|
||||
camera.mCamera->getNearClipDistance());
|
||||
water.mReflectionDepthCamera->setFarClipDistance(
|
||||
camera.mCamera->getFarClipDistance());
|
||||
water.mReflectionDepthCamera
|
||||
->enableCustomNearClipPlane(
|
||||
water.mReflectionClipPlaneAbove);
|
||||
water.mReflectionDepthCamera->enableReflection(
|
||||
water.mReflectionPlane);
|
||||
|
||||
Ogre::Viewport *reflectionViewport =
|
||||
water.mReflectionTexture->addViewport(
|
||||
water.mReflectionCamera, 0, 0,
|
||||
0, 0.5f, 1.0f);
|
||||
0, 0.5f, 0.5f);
|
||||
reflectionViewport->setClearEveryFrame(true);
|
||||
reflectionViewport->setBackgroundColour(
|
||||
Ogre::ColourValue(0.0, 0.0, 1.0, 1.0));
|
||||
reflectionViewport->setOverlaysEnabled(false);
|
||||
reflectionViewport->setSkiesEnabled(true);
|
||||
reflectionViewport->setAutoUpdated(false);
|
||||
reflectionViewport->setVisibilityMask(
|
||||
~WATER_MASK);
|
||||
water.mViewports[0] = reflectionViewport;
|
||||
|
||||
Ogre::Viewport *reflectionDepthViewport =
|
||||
water.mReflectionTexture->addViewport(
|
||||
water.mReflectionDepthCamera, 2,
|
||||
0, 0.5f, 0.5f, 0.5f);
|
||||
reflectionDepthViewport->setClearEveryFrame(
|
||||
true);
|
||||
reflectionDepthViewport->setBackgroundColour(
|
||||
Ogre::ColourValue(0.0, 0.0, 0.0, 0.0));
|
||||
reflectionDepthViewport->setOverlaysEnabled(
|
||||
false);
|
||||
reflectionDepthViewport->setSkiesEnabled(true);
|
||||
reflectionDepthViewport->setAutoUpdated(false);
|
||||
reflectionDepthViewport->setVisibilityMask(
|
||||
~WATER_MASK);
|
||||
water.mViewports[2] = reflectionDepthViewport;
|
||||
|
||||
water.mRefractionCamera =
|
||||
eng.mScnMgr->createCamera(
|
||||
"RefractionCamera");
|
||||
camera.mCamera->getParentSceneNode()
|
||||
->attachObject(water.mRefractionCamera);
|
||||
water.mRefractionDepthCamera =
|
||||
eng.mScnMgr->createCamera(
|
||||
"RefractionDepthCamera");
|
||||
water.mRefractionCameraNode =
|
||||
camera.mCamera->getParentSceneNode()
|
||||
->createChildSceneNode(
|
||||
"RefractionCameraNode");
|
||||
water.mRefractionCameraNode->attachObject(
|
||||
water.mRefractionCamera);
|
||||
water.mRefractionCameraNode->attachObject(
|
||||
water.mRefractionDepthCamera);
|
||||
water.mRefractionCamera->setAspectRatio(
|
||||
camera.mCamera->getAspectRatio());
|
||||
water.mRefractionCamera->setNearClipDistance(
|
||||
@@ -261,17 +382,50 @@ WaterModule::WaterModule(flecs::world &ecs)
|
||||
->enableCustomNearClipPlane(
|
||||
water.mRefractionClipPlaneAbove);
|
||||
|
||||
water.mRefractionDepthCamera->setAspectRatio(
|
||||
camera.mCamera->getAspectRatio());
|
||||
water.mRefractionDepthCamera->setNearClipDistance(
|
||||
camera.mCamera->getNearClipDistance());
|
||||
water.mRefractionDepthCamera->setFarClipDistance(
|
||||
camera.mCamera->getFarClipDistance());
|
||||
water.mRefractionDepthCamera
|
||||
->enableCustomNearClipPlane(
|
||||
water.mRefractionClipPlaneAbove);
|
||||
|
||||
Ogre::Viewport *refractionViewport =
|
||||
water.mReflectionTexture->addViewport(
|
||||
water.mRefractionCamera, 1, 0.5,
|
||||
0, 0.5f, 1.0f);
|
||||
0, 0.5f, 0.5f);
|
||||
refractionViewport->setClearEveryFrame(true);
|
||||
refractionViewport->setBackgroundColour(
|
||||
Ogre::ColourValue(0.0, 0.5, 1.0, 1.0));
|
||||
refractionViewport->setOverlaysEnabled(false);
|
||||
refractionViewport->setSkiesEnabled(false);
|
||||
refractionViewport->setAutoUpdated(false);
|
||||
refractionViewport->setVisibilityMask(
|
||||
~WATER_MASK);
|
||||
water.mViewports[1] = refractionViewport;
|
||||
|
||||
Ogre::Viewport *refractionDepthViewport =
|
||||
water.mReflectionTexture->addViewport(
|
||||
water.mRefractionDepthCamera, 3,
|
||||
0.5, 0.5, 0.5f, 0.5f);
|
||||
refractionDepthViewport->setClearEveryFrame(
|
||||
true);
|
||||
refractionDepthViewport->setBackgroundColour(
|
||||
Ogre::ColourValue(0.0, 0.0, 0.0, 0.0));
|
||||
refractionDepthViewport->setOverlaysEnabled(
|
||||
false);
|
||||
refractionDepthViewport->setSkiesEnabled(false);
|
||||
refractionDepthViewport->setAutoUpdated(false);
|
||||
refractionDepthViewport->setVisibilityMask(
|
||||
~WATER_MASK);
|
||||
water.mViewports[3] = refractionDepthViewport;
|
||||
|
||||
water.mRenderTargetListener.mInDepth = false;
|
||||
eng.mScnMgr->getRenderQueue()
|
||||
->setRenderableListener(
|
||||
&water.mRenderTargetListener);
|
||||
std::cout << "Water setup done\n";
|
||||
}
|
||||
Ogre::Vector3 mCameraPos =
|
||||
@@ -290,6 +444,10 @@ WaterModule::WaterModule(flecs::world &ecs)
|
||||
water.mWaterEnt->setVisible(false);
|
||||
water.mViewports[0]->update();
|
||||
water.mViewports[1]->update();
|
||||
water.mRenderTargetListener.mInDepth = true;
|
||||
water.mViewports[2]->update();
|
||||
water.mViewports[3]->update();
|
||||
water.mRenderTargetListener.mInDepth = false;
|
||||
water.mWaterEnt->setVisible(true);
|
||||
});
|
||||
ecs.system<const EngineData, const WaterSurface, WaterBody>(
|
||||
@@ -465,4 +623,12 @@ void WaterSurface::RenderTextureListener::postRenderTargetUpdate(
|
||||
mSurface->mWaterEnt->setVisible(true);
|
||||
mSurface->mInRefTexUpdate = false;
|
||||
}
|
||||
bool WaterSurface::RenderTextureListener::renderableQueued(
|
||||
Ogre::Renderable *rend, Ogre::uint8 groupID, ushort priority,
|
||||
Ogre::Technique **ppTech, Ogre::RenderQueue *pQueue)
|
||||
{
|
||||
if (mInDepth)
|
||||
*ppTech = mSurface->mDepthTech;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user