forked from mirror/openmw-tes3mp
Experimental: Directional shading on local map, separated out refraction render, no longer uses screen depth
parent
a461b282c1
commit
15e51b76de
@ -0,0 +1,62 @@
|
||||
#include "refraction.hpp"
|
||||
|
||||
#include <OgreCamera.h>
|
||||
#include <OgreTextureManager.h>
|
||||
#include <OgreSceneManager.h>
|
||||
#include <OgreHardwarePixelBuffer.h>
|
||||
#include <OgreRenderTarget.h>
|
||||
#include <OgreViewport.h>
|
||||
|
||||
#include "renderconst.hpp"
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
|
||||
Refraction::Refraction(Ogre::Camera *parentCamera)
|
||||
: mParentCamera(parentCamera)
|
||||
{
|
||||
mCamera = mParentCamera->getSceneManager()->createCamera("RefractionCamera");
|
||||
|
||||
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual("WaterRefraction",
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);
|
||||
|
||||
mRenderTarget = texture->getBuffer()->getRenderTarget();
|
||||
Ogre::Viewport* vp = mRenderTarget->addViewport(mCamera);
|
||||
vp->setOverlaysEnabled(false);
|
||||
vp->setShadowsEnabled(false);
|
||||
vp->setVisibilityMask(RV_Actors + RV_Misc + RV_Statics + RV_StaticsSmall + RV_Terrain);
|
||||
mRenderTarget->setAutoUpdated(true);
|
||||
mRenderTarget->addListener(this);
|
||||
}
|
||||
|
||||
Refraction::~Refraction()
|
||||
{
|
||||
Ogre::TextureManager::getSingleton().remove("WaterRefraction");
|
||||
mParentCamera->getSceneManager()->destroyCamera(mCamera);
|
||||
mRenderTarget->removeListener(this);
|
||||
}
|
||||
|
||||
void Refraction::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
|
||||
{
|
||||
mParentCamera->getParentSceneNode ()->needUpdate ();
|
||||
mCamera->setOrientation(mParentCamera->getDerivedOrientation());
|
||||
mCamera->setPosition(mParentCamera->getDerivedPosition());
|
||||
mCamera->setNearClipDistance(mParentCamera->getNearClipDistance());
|
||||
mCamera->setFarClipDistance(mParentCamera->getFarClipDistance());
|
||||
mCamera->setAspectRatio(mParentCamera->getAspectRatio());
|
||||
mCamera->setFOVy(mParentCamera->getFOVy());
|
||||
|
||||
mCamera->enableCustomNearClipPlane(mNearClipPlane);
|
||||
}
|
||||
|
||||
void Refraction::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Refraction::setWaterPlane(Ogre::Plane plane)
|
||||
{
|
||||
mNearClipPlane = Ogre::Plane(-plane.normal, - (plane.d + 5) );
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
#ifndef MWRENDER_REFRACTION_H
|
||||
#define MWRENDER_REFRACTION_H
|
||||
|
||||
#include <OgrePlane.h>
|
||||
#include <OgreRenderTargetListener.h>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class Camera;
|
||||
class RenderTarget;
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
|
||||
class Refraction : public Ogre::RenderTargetListener
|
||||
{
|
||||
|
||||
public:
|
||||
Refraction(Ogre::Camera* parentCamera);
|
||||
~Refraction();
|
||||
|
||||
void setWaterPlane (Ogre::Plane plane);
|
||||
void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
|
||||
void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
|
||||
|
||||
private:
|
||||
Ogre::Camera* mParentCamera;
|
||||
Ogre::Camera* mCamera;
|
||||
Ogre::RenderTarget* mRenderTarget;
|
||||
Ogre::Plane mNearClipPlane;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue