mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-22 12:39:59 +00:00
Merge branch 'fog_alpha' into 'master'
Several fixes related to sky blending See merge request OpenMW/openmw!2046
This commit is contained in:
commit
066575821b
@ -232,6 +232,7 @@ namespace
|
|||||||
camera->setReferenceFrame(osg::Camera::RELATIVE_RF);
|
camera->setReferenceFrame(osg::Camera::RELATIVE_RF);
|
||||||
camera->setName("SkyCamera");
|
camera->setName("SkyCamera");
|
||||||
camera->setNodeMask(MWRender::Mask_RenderToTexture);
|
camera->setNodeMask(MWRender::Mask_RenderToTexture);
|
||||||
|
camera->setCullMask(MWRender::Mask_Sky);
|
||||||
camera->addChild(mEarlyRenderBinRoot);
|
camera->addChild(mEarlyRenderBinRoot);
|
||||||
SceneUtil::ShadowManager::disableShadowsForStateSet(camera->getOrCreateStateSet());
|
SceneUtil::ShadowManager::disableShadowsForStateSet(camera->getOrCreateStateSet());
|
||||||
}
|
}
|
||||||
@ -283,25 +284,26 @@ namespace MWRender
|
|||||||
if (!mSceneManager->getForceShaders())
|
if (!mSceneManager->getForceShaders())
|
||||||
skyroot->getOrCreateStateSet()->setAttributeAndModes(new osg::Program(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::PROTECTED|osg::StateAttribute::ON);
|
skyroot->getOrCreateStateSet()->setAttributeAndModes(new osg::Program(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::PROTECTED|osg::StateAttribute::ON);
|
||||||
SceneUtil::ShadowManager::disableShadowsForStateSet(skyroot->getOrCreateStateSet());
|
SceneUtil::ShadowManager::disableShadowsForStateSet(skyroot->getOrCreateStateSet());
|
||||||
|
|
||||||
skyroot->setNodeMask(Mask_Sky);
|
|
||||||
parentNode->addChild(skyroot);
|
parentNode->addChild(skyroot);
|
||||||
|
|
||||||
mRootNode = skyroot;
|
|
||||||
|
|
||||||
mEarlyRenderBinRoot = new osg::Group;
|
mEarlyRenderBinRoot = new osg::Group;
|
||||||
// render before the world is rendered
|
// render before the world is rendered
|
||||||
mEarlyRenderBinRoot->getOrCreateStateSet()->setRenderBinDetails(RenderBin_Sky, "RenderBin");
|
mEarlyRenderBinRoot->getOrCreateStateSet()->setRenderBinDetails(RenderBin_Sky, "RenderBin");
|
||||||
// Prevent unwanted clipping by water reflection camera's clipping plane
|
// Prevent unwanted clipping by water reflection camera's clipping plane
|
||||||
mEarlyRenderBinRoot->getOrCreateStateSet()->setMode(GL_CLIP_PLANE0, osg::StateAttribute::OFF);
|
mEarlyRenderBinRoot->getOrCreateStateSet()->setMode(GL_CLIP_PLANE0, osg::StateAttribute::OFF);
|
||||||
mRootNode->addChild(mEarlyRenderBinRoot);
|
|
||||||
|
|
||||||
if (enableSkyRTT)
|
if (enableSkyRTT)
|
||||||
{
|
{
|
||||||
mSkyRTT = new SkyRTT(Settings::Manager::getVector2("sky rtt resolution", "Fog"), mEarlyRenderBinRoot);
|
mSkyRTT = new SkyRTT(Settings::Manager::getVector2("sky rtt resolution", "Fog"), mEarlyRenderBinRoot);
|
||||||
mRootNode->addChild(mSkyRTT);
|
skyroot->addChild(mSkyRTT);
|
||||||
|
mRootNode = new osg::Group;
|
||||||
|
skyroot->addChild(mRootNode);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
mRootNode = skyroot;
|
||||||
|
|
||||||
|
mRootNode->setNodeMask(Mask_Sky);
|
||||||
|
mRootNode->addChild(mEarlyRenderBinRoot);
|
||||||
mUnderwaterSwitch = new UnderwaterSwitchCallback(skyroot);
|
mUnderwaterSwitch = new UnderwaterSwitchCallback(skyroot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include <osg/AlphaFunc>
|
#include <osg/AlphaFunc>
|
||||||
|
#include <osg/BlendFunc>
|
||||||
#include <osg/Geometry>
|
#include <osg/Geometry>
|
||||||
#include <osg/GLExtensions>
|
#include <osg/GLExtensions>
|
||||||
#include <osg/Material>
|
#include <osg/Material>
|
||||||
@ -195,6 +196,8 @@ namespace Shader
|
|||||||
, mAlphaFunc(GL_ALWAYS)
|
, mAlphaFunc(GL_ALWAYS)
|
||||||
, mAlphaRef(1.0)
|
, mAlphaRef(1.0)
|
||||||
, mAlphaBlend(false)
|
, mAlphaBlend(false)
|
||||||
|
, mBlendFuncOverridden(false)
|
||||||
|
, mAdditiveBlending(false)
|
||||||
, mNormalHeight(false)
|
, mNormalHeight(false)
|
||||||
, mTexStageRequiringTangents(-1)
|
, mTexStageRequiringTangents(-1)
|
||||||
, mSoftParticles(false)
|
, mSoftParticles(false)
|
||||||
@ -517,6 +520,18 @@ namespace Shader
|
|||||||
mRequirements.back().mAlphaRef = alpha->getReferenceValue();
|
mRequirements.back().mAlphaRef = alpha->getReferenceValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (it->first.first == osg::StateAttribute::BLENDFUNC)
|
||||||
|
{
|
||||||
|
if (!mRequirements.back().mBlendFuncOverridden || it->second.second & osg::StateAttribute::PROTECTED)
|
||||||
|
{
|
||||||
|
if (it->second.second & osg::StateAttribute::OVERRIDE)
|
||||||
|
mRequirements.back().mBlendFuncOverridden = true;
|
||||||
|
|
||||||
|
const osg::BlendFunc* blend = static_cast<const osg::BlendFunc*>(it->second.first.get());
|
||||||
|
mRequirements.back().mAdditiveBlending =
|
||||||
|
blend->getSource() == osg::BlendFunc::SRC_ALPHA && blend->getDestination() == osg::BlendFunc::ONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -604,6 +619,8 @@ namespace Shader
|
|||||||
|
|
||||||
defineMap["alphaFunc"] = std::to_string(reqs.mAlphaFunc);
|
defineMap["alphaFunc"] = std::to_string(reqs.mAlphaFunc);
|
||||||
|
|
||||||
|
defineMap["additiveBlending"] = reqs.mAdditiveBlending ? "1" : "0";
|
||||||
|
|
||||||
osg::ref_ptr<osg::StateSet> removedState;
|
osg::ref_ptr<osg::StateSet> removedState;
|
||||||
if ((removedState = getRemovedState(*writableStateSet)) && !mAllowedToModifyStateSets)
|
if ((removedState = getRemovedState(*writableStateSet)) && !mAllowedToModifyStateSets)
|
||||||
removedState = new osg::StateSet(*removedState, osg::CopyOp::SHALLOW_COPY);
|
removedState = new osg::StateSet(*removedState, osg::CopyOp::SHALLOW_COPY);
|
||||||
|
@ -102,6 +102,9 @@ namespace Shader
|
|||||||
float mAlphaRef;
|
float mAlphaRef;
|
||||||
bool mAlphaBlend;
|
bool mAlphaBlend;
|
||||||
|
|
||||||
|
bool mBlendFuncOverridden;
|
||||||
|
bool mAdditiveBlending;
|
||||||
|
|
||||||
bool mNormalHeight; // true if normal map has height info in alpha channel
|
bool mNormalHeight; // true if normal map has height info in alpha channel
|
||||||
|
|
||||||
// -1 == no tangents required
|
// -1 == no tangents required
|
||||||
|
@ -17,12 +17,21 @@ vec4 applyFogAtDist(vec4 color, float euclideanDist, float linearDist)
|
|||||||
#else
|
#else
|
||||||
float fogValue = clamp((dist - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0);
|
float fogValue = clamp((dist - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ADDITIVE_BLENDING
|
||||||
|
color.xyz *= 1 - fogValue;
|
||||||
|
#else
|
||||||
color.xyz = mix(color.xyz, gl_Fog.color.xyz, fogValue);
|
color.xyz = mix(color.xyz, gl_Fog.color.xyz, fogValue);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if @skyBlending && !@useOVR_multiview
|
#if @skyBlending && !@useOVR_multiview
|
||||||
float fadeValue = clamp((far - dist) / (far - skyBlendingStart), 0.0, 1.0);
|
float fadeValue = clamp((far - dist) / (far - skyBlendingStart), 0.0, 1.0);
|
||||||
|
fadeValue *= fadeValue;
|
||||||
|
#ifdef ADDITIVE_BLENDING
|
||||||
|
color.xyz *= fadeValue;
|
||||||
|
#else
|
||||||
vec3 skyColor = texture2D(sky, gl_FragCoord.xy / screenRes).xyz;
|
vec3 skyColor = texture2D(sky, gl_FragCoord.xy / screenRes).xyz;
|
||||||
color.xyz = mix(skyColor, color.xyz, fadeValue * fadeValue);
|
color.xyz = mix(skyColor, color.xyz, fadeValue);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
|
@ -77,6 +77,10 @@ uniform float specStrength;
|
|||||||
varying vec3 passViewPos;
|
varying vec3 passViewPos;
|
||||||
varying vec3 passNormal;
|
varying vec3 passNormal;
|
||||||
|
|
||||||
|
#if @additiveBlending
|
||||||
|
#define ADDITIVE_BLENDING
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "vertexcolors.glsl"
|
#include "vertexcolors.glsl"
|
||||||
#include "shadows_fragment.glsl"
|
#include "shadows_fragment.glsl"
|
||||||
#include "lighting.glsl"
|
#include "lighting.glsl"
|
||||||
@ -188,7 +192,7 @@ void main()
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float shadowing = unshadowedLightRatio(passViewPos.z);
|
float shadowing = unshadowedLightRatio(-passViewPos.z);
|
||||||
vec3 lighting;
|
vec3 lighting;
|
||||||
#if !PER_PIXEL_LIGHTING
|
#if !PER_PIXEL_LIGHTING
|
||||||
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user