From 393530e67174d4771cc668a2dbefcfe0c9a0f601 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 6 Apr 2012 15:05:17 +0200 Subject: [PATCH] more or less fixed the sky for normal viewing angles, still disappears at a certain height though --- apps/openmw/mwrender/sky.cpp | 9 ++++++++- apps/openmw/mwrender/sky.hpp | 23 ++++++++++++----------- apps/openmw/mwrender/water.cpp | 10 ++++++---- apps/openmw/mwrender/water.hpp | 2 +- files/water/water.cg | 5 ++++- 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 43ef31d86..8f719ebaa 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -810,7 +810,9 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather) strength = 1.f; mSunGlare->setVisibility(weather.mGlareView * mGlareFade * strength); - mSun->setVisibility(weather.mGlareView); + + if (strength < 0.4) strength = 0.4; + mSun->setVisibility(weather.mGlareView * strength); mAtmosphereNight->setVisible(weather.mNight && mEnabled); } @@ -923,3 +925,8 @@ void SkyManager::resetSkyPosition() { mRootNode->setPosition(0,0,0); } + +void SkyManager::scaleSky(float scale) +{ + mRootNode->setScale(scale, scale, scale); +} diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index c18b9f484..f6f166b9e 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -170,6 +170,7 @@ namespace MWRender void setSkyPosition(const Ogre::Vector3& position); void resetSkyPosition(); + void scaleSky(float scale); private: bool mCreated; @@ -183,21 +184,21 @@ namespace MWRender BillboardObject* mSunGlare; Moon* mMasser; Moon* mSecunda; - + Ogre::Viewport* mViewport; Ogre::SceneNode* mRootNode; Ogre::SceneManager* mSceneMgr; - + Ogre::SceneNode* mAtmosphereDay; Ogre::SceneNode* mAtmosphereNight; - + Ogre::MaterialPtr mCloudMaterial; Ogre::MaterialPtr mAtmosphereMaterial; - + Ogre::MaterialPtr mStarsMaterials[7]; - + Ogre::HighLevelGpuProgramPtr mCloudFragmentShader; - + // remember some settings so we don't have to apply them again if they didnt change Ogre::String mClouds; Ogre::String mNextClouds; @@ -207,17 +208,17 @@ namespace MWRender float mStarsOpacity; Ogre::ColourValue mCloudColour; Ogre::ColourValue mSkyColour; - + Ogre::Overlay* mThunderOverlay; Ogre::TextureUnitState* mThunderTextureUnit; - + float mRemainingTransitionTime; - + float mGlare; // target float mGlareFade; // actual - + void ModVertexAlpha(Ogre::Entity* ent, unsigned int meshType); - + bool mEnabled; bool mSunEnabled; bool mMasserEnabled; diff --git a/apps/openmw/mwrender/water.cpp b/apps/openmw/mwrender/water.cpp index cbce0d075..544f738e5 100644 --- a/apps/openmw/mwrender/water.cpp +++ b/apps/openmw/mwrender/water.cpp @@ -141,15 +141,16 @@ void Water::preRenderTargetUpdate(const RenderTargetEvent& evt) { mWater->setVisible(false); - mOldCameraFarClip = mCamera->getFarClipDistance(); - if (mReflectDistance != 0) - mCamera->setFarClipDistance(mReflectDistance); + //mOldCameraFarClip = mCamera->getFarClipDistance(); + //if (mReflectDistance != 0) + // mCamera->setFarClipDistance(mReflectDistance); if (evt.source == mReflectionTarget) { Vector3 pos = mCamera->getRealPosition(); pos.y = mTop*2 - pos.y; mSky->setSkyPosition(pos); + mSky->scaleSky(mCamera->getFarClipDistance() / 1000.f); mCamera->enableCustomNearClipPlane(Plane(Vector3::UNIT_Y, mTop)); mCamera->enableReflection(Plane(Vector3::UNIT_Y, mTop)); } @@ -159,11 +160,12 @@ void Water::postRenderTargetUpdate(const RenderTargetEvent& evt) { mWater->setVisible(true); - mCamera->setFarClipDistance(mOldCameraFarClip); + //mCamera->setFarClipDistance(mOldCameraFarClip); if (evt.source == mReflectionTarget) { mSky->resetSkyPosition(); + mSky->scaleSky(1); mCamera->disableReflection(); mCamera->disableCustomNearClipPlane(); } diff --git a/apps/openmw/mwrender/water.hpp b/apps/openmw/mwrender/water.hpp index 964a8c735..264f96fbe 100644 --- a/apps/openmw/mwrender/water.hpp +++ b/apps/openmw/mwrender/water.hpp @@ -11,7 +11,7 @@ namespace MWRender { class SkyManager; /// Water rendering - class Water : Ogre::RenderTargetListener + class Water : public Ogre::RenderTargetListener { static const int CELL_SIZE = 8192; Ogre::Camera *mCamera; diff --git a/files/water/water.cg b/files/water/water.cg index 18ef0a757..613891fa5 100644 --- a/files/water/water.cg +++ b/files/water/water.cg @@ -54,6 +54,9 @@ void main_fp float2 screenCoords = iScreenCoords.xy / iScreenCoords.z; screenCoords.y = (1-saturate(renderTargetFlipping))+renderTargetFlipping*screenCoords.y; + // No need for transparency since we are using a refraction map + oColor.a = 1; + // Sample screen-space depth map and subtract pixel depth to get the real water depth float depth1 = tex2D(depthMap, screenCoords).r * far - iDepth; depth1 = saturate(depth1 / 500.f); @@ -93,7 +96,7 @@ void main_fp oColor.xyz = lerp(refraction.xyz, reflection.xyz, opacity); + // add fog float fogValue = saturate((iDepth - fogParams.y) * fogParams.w); oColor.xyz = lerp(oColor.xyz, fogColour, fogValue); - oColor.a = 1; }