From 9f2f503d3747533b6ea223829b998b1f0bd93c51 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 28 Oct 2015 18:59:35 +0100 Subject: [PATCH] Water: pass the near and far planes --- apps/openmw/mwrender/renderingmanager.cpp | 3 +++ files/shaders/water_fragment.glsl | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index b9132dc8c..dcf4406bb 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -198,6 +198,9 @@ namespace MWRender mFieldOfView = Settings::Manager::getFloat("field of view", "General"); updateProjectionMatrix(); mStateUpdater->setFogEnd(mViewDistance); + + mRootNode->getOrCreateStateSet()->addUniform(new osg::Uniform("near", mNearClip)); + mRootNode->getOrCreateStateSet()->addUniform(new osg::Uniform("far", mViewDistance)); } RenderingManager::~RenderingManager() diff --git a/files/shaders/water_fragment.glsl b/files/shaders/water_fragment.glsl index 5860120ab..994d74964 100644 --- a/files/shaders/water_fragment.glsl +++ b/files/shaders/water_fragment.glsl @@ -68,6 +68,9 @@ uniform sampler2D normalMap; uniform float osg_SimulationTime; +uniform float near; +uniform float far; + void main(void) { // FIXME @@ -160,10 +163,8 @@ void main(void) #if REFRACTION float refractionDepth = texture2D(refractionDepthMap, screenCoords-(normal.xy*REFR_BUMP)).x; // make linear - float zNear = 5; // FIXME - float zFar = 6666; // FIXME float z_n = 2.0 * refractionDepth - 1.0; - refractionDepth = 2.0 * zNear * zFar / (zFar + zNear - z_n * (zFar - zNear)); + refractionDepth = 2.0 * near * far / (far + near - z_n * (far - near)); float waterDepth = refractionDepth - depthPassthrough;