forked from teamnwah/openmw-tes3coop
first reflection test; removed the refraction render (we'll have it for free using MRT and deferred water rendering)
This commit is contained in:
parent
6481cf87fc
commit
fe63f2b2aa
5 changed files with 84 additions and 46 deletions
|
@ -9,7 +9,7 @@ namespace MWRender
|
||||||
Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
||||||
mCamera (camera), mViewport (camera->getViewport()), mSceneManager (camera->getSceneManager()),
|
mCamera (camera), mViewport (camera->getViewport()), mSceneManager (camera->getSceneManager()),
|
||||||
mIsUnderwater(false), mReflectDistance(0), mVisibilityFlags(0), mOldCameraFarClip(0),
|
mIsUnderwater(false), mReflectDistance(0), mVisibilityFlags(0), mOldCameraFarClip(0),
|
||||||
mReflectionTarget(0), mRefractionTarget(0), mActive(1)
|
mReflectionTarget(0), mActive(1)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -28,8 +28,6 @@ Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
||||||
mWater = mSceneManager->createEntity("water");
|
mWater = mSceneManager->createEntity("water");
|
||||||
mWater->setVisibilityFlags(RV_Water);
|
mWater->setVisibilityFlags(RV_Water);
|
||||||
|
|
||||||
mWater->setMaterial(createMaterial());
|
|
||||||
|
|
||||||
mVisibilityFlags = RV_Terrain * Settings::Manager::getBool("reflect terrain", "Water")
|
mVisibilityFlags = RV_Terrain * Settings::Manager::getBool("reflect terrain", "Water")
|
||||||
+ RV_Statics * Settings::Manager::getBool("reflect statics", "Water")
|
+ RV_Statics * Settings::Manager::getBool("reflect statics", "Water")
|
||||||
+ RV_StaticsSmall * Settings::Manager::getBool("reflect small statics", "Water")
|
+ RV_StaticsSmall * Settings::Manager::getBool("reflect small statics", "Water")
|
||||||
|
@ -48,12 +46,10 @@ Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
||||||
|
|
||||||
// Create rendertargets for reflection and refraction
|
// Create rendertargets for reflection and refraction
|
||||||
int rttsize = Settings::Manager::getInt("rtt size", "Water");
|
int rttsize = Settings::Manager::getInt("rtt size", "Water");
|
||||||
for (unsigned int i = 0; i < 2; ++i)
|
|
||||||
{
|
|
||||||
if (i==0 && !Settings::Manager::getBool("reflection", "Water")) continue;
|
|
||||||
if (i==1 && !Settings::Manager::getBool("refraction", "Water")) continue;
|
|
||||||
|
|
||||||
TexturePtr tex = TextureManager::getSingleton().createManual(i == 0 ? "WaterReflection" : "WaterRefraction",
|
if (Settings::Manager::getBool("reflection", "Water"))
|
||||||
|
{
|
||||||
|
TexturePtr tex = TextureManager::getSingleton().createManual("WaterReflection",
|
||||||
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, rttsize, rttsize, 0, PF_R8G8B8, TU_RENDERTARGET);
|
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, rttsize, rttsize, 0, PF_R8G8B8, TU_RENDERTARGET);
|
||||||
|
|
||||||
RenderTarget* rtt = tex->getBuffer()->getRenderTarget();
|
RenderTarget* rtt = tex->getBuffer()->getRenderTarget();
|
||||||
|
@ -61,20 +57,20 @@ Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
||||||
vp->setOverlaysEnabled(false);
|
vp->setOverlaysEnabled(false);
|
||||||
vp->setBackgroundColour(ColourValue(0.8f, 0.9f, 1.0f));
|
vp->setBackgroundColour(ColourValue(0.8f, 0.9f, 1.0f));
|
||||||
vp->setShadowsEnabled(false);
|
vp->setShadowsEnabled(false);
|
||||||
vp->setVisibilityMask( (i == 0) ? mVisibilityFlags : RV_All);
|
vp->setVisibilityMask( mVisibilityFlags );
|
||||||
rtt->addListener(this);
|
rtt->addListener(this);
|
||||||
rtt->setActive(true);
|
rtt->setActive(true);
|
||||||
|
|
||||||
if (i == 0) mReflectionTarget = rtt;
|
mReflectionTarget = rtt;
|
||||||
else mRefractionTarget = rtt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mWater->setMaterial(createMaterial());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Water::setActive(bool active)
|
void Water::setActive(bool active)
|
||||||
{
|
{
|
||||||
mActive = active;
|
mActive = active;
|
||||||
if (mReflectionTarget) mReflectionTarget->setActive(active);
|
if (mReflectionTarget) mReflectionTarget->setActive(active);
|
||||||
if (mRefractionTarget) mRefractionTarget->setActive(active);
|
|
||||||
mWater->setVisible(active);
|
mWater->setVisible(active);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,8 +142,8 @@ void Water::preRenderTargetUpdate(const RenderTargetEvent& evt)
|
||||||
|
|
||||||
if (evt.source == mReflectionTarget)
|
if (evt.source == mReflectionTarget)
|
||||||
{
|
{
|
||||||
mCamera->enableCustomNearClipPlane(mWaterPlane);
|
mCamera->enableCustomNearClipPlane(Plane(Vector3::UNIT_Y, mTop));
|
||||||
mCamera->enableReflection(Plane(Vector3::UNIT_Y, mWaterNode->_getDerivedPosition().y));
|
mCamera->enableReflection(Plane(Vector3::UNIT_Y, mTop));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,33 +162,16 @@ void Water::postRenderTargetUpdate(const RenderTargetEvent& evt)
|
||||||
|
|
||||||
Ogre::MaterialPtr Water::createMaterial()
|
Ogre::MaterialPtr Water::createMaterial()
|
||||||
{
|
{
|
||||||
MaterialPtr mat = MaterialManager::getSingleton().create("Water", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
MaterialPtr mat = MaterialManager::getSingleton().getByName("Water");
|
||||||
mat->removeAllTechniques();
|
|
||||||
|
|
||||||
// shader technique
|
// these have to be set in code
|
||||||
Technique* tech = mat->createTechnique();
|
|
||||||
Pass* pass = tech->createPass();
|
|
||||||
|
|
||||||
|
|
||||||
// fallback technique without shaders
|
|
||||||
// also used for minimap (because it can't have reflecting water)
|
|
||||||
Technique* old = mat->createTechnique();
|
|
||||||
old->setSchemeName("Map");
|
|
||||||
Pass* oldpass = old->createPass();
|
|
||||||
oldpass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
|
|
||||||
oldpass->setDepthWriteEnabled(false);
|
|
||||||
oldpass->setDiffuse(0,0,0,1);
|
|
||||||
oldpass->setSelfIllumination(0.6, 0.7, 1.0);
|
|
||||||
oldpass->setAmbient(0,0,0);
|
|
||||||
TextureUnitState* oldtus = oldpass->createTextureUnitState();
|
|
||||||
std::string textureNames[32];
|
std::string textureNames[32];
|
||||||
for (int i=0; i<32; ++i)
|
for (int i=0; i<32; ++i)
|
||||||
{
|
{
|
||||||
textureNames[i] = "textures\\water\\water" + StringConverter::toString(i, 2, '0') + ".dds";
|
textureNames[i] = "textures\\water\\water" + StringConverter::toString(i, 2, '0') + ".dds";
|
||||||
}
|
}
|
||||||
oldtus->setAnimatedTextureName(textureNames, 32, 2);
|
mat->getTechnique(1)->getPass(0)->getTextureUnitState(0)->setAnimatedTextureName(textureNames, 32, 2);
|
||||||
oldtus->setTextureScale(0.1, 0.1);
|
|
||||||
oldtus->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, 0.7);
|
|
||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ namespace MWRender {
|
||||||
Ogre::MaterialPtr createMaterial();
|
Ogre::MaterialPtr createMaterial();
|
||||||
|
|
||||||
Ogre::RenderTarget* mReflectionTarget;
|
Ogre::RenderTarget* mReflectionTarget;
|
||||||
Ogre::RenderTarget* mRefractionTarget;
|
|
||||||
|
|
||||||
int mVisibilityFlags;
|
int mVisibilityFlags;
|
||||||
int mReflectDistance;
|
int mReflectDistance;
|
||||||
|
|
|
@ -7,3 +7,4 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/perlinvolume.dds "${OpenMW_BINA
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/water.compositor "${OpenMW_BINARY_DIR}/resources/water/water.compositor" COPYONLY)
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/water.compositor "${OpenMW_BINARY_DIR}/resources/water/water.compositor" COPYONLY)
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/water.material "${OpenMW_BINARY_DIR}/resources/water/water.material" COPYONLY)
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/water.material "${OpenMW_BINARY_DIR}/resources/water/water.material" COPYONLY)
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/WaterNormal2.tga "${OpenMW_BINARY_DIR}/resources/water/WaterNormal2.tga" COPYONLY)
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/WaterNormal2.tga "${OpenMW_BINARY_DIR}/resources/water/WaterNormal2.tga" COPYONLY)
|
||||||
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/water/water.cg "${OpenMW_BINARY_DIR}/resources/water/water.cg" COPYONLY)
|
||||||
|
|
|
@ -46,8 +46,6 @@ num lights = 8
|
||||||
|
|
||||||
reflection = false
|
reflection = false
|
||||||
|
|
||||||
refraction = false
|
|
||||||
|
|
||||||
rtt size = 256
|
rtt size = 256
|
||||||
|
|
||||||
# 0 unlimited
|
# 0 unlimited
|
||||||
|
|
|
@ -18,6 +18,67 @@ fragment_program Water/GlassFP cg
|
||||||
profiles ps_2_0 arbfp1
|
profiles ps_2_0 arbfp1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vertex_program Water_VP cg
|
||||||
|
{
|
||||||
|
source water.cg
|
||||||
|
entry_point main_vp
|
||||||
|
profiles vs_2_x arbvp1
|
||||||
|
|
||||||
|
default_params
|
||||||
|
{
|
||||||
|
param_named_auto wvpMat worldviewproj_matrix
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fragment_program Water_FP cg
|
||||||
|
{
|
||||||
|
source water.cg
|
||||||
|
entry_point main_fp
|
||||||
|
profiles ps_2_x arbfp1
|
||||||
|
}
|
||||||
|
|
||||||
|
material Water
|
||||||
|
{
|
||||||
|
technique
|
||||||
|
{
|
||||||
|
pass
|
||||||
|
{
|
||||||
|
scene_blend alpha_blend
|
||||||
|
depth_write off
|
||||||
|
|
||||||
|
vertex_program_ref Water_VP
|
||||||
|
{
|
||||||
|
}
|
||||||
|
fragment_program_ref Water_FP
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
texture_unit reflectionMap
|
||||||
|
{
|
||||||
|
texture WaterReflection
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
technique
|
||||||
|
{
|
||||||
|
scheme Map
|
||||||
|
pass
|
||||||
|
{
|
||||||
|
scene_blend alpha_blend
|
||||||
|
depth_write off
|
||||||
|
diffuse 0 0 0 1
|
||||||
|
emissive 0.6 0.7 1.0
|
||||||
|
ambient 0 0 0
|
||||||
|
texture_unit
|
||||||
|
{
|
||||||
|
// texture names set via code
|
||||||
|
scale 0.1 0.1
|
||||||
|
alpha_op_ex source1 src_manual src_current 0.7
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
material Water/Compositor
|
material Water/Compositor
|
||||||
{
|
{
|
||||||
technique
|
technique
|
||||||
|
|
Loading…
Reference in a new issue