mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-03 21:19:40 +00:00
Add settings
This commit is contained in:
parent
f56a117bde
commit
c3e0398d1c
7 changed files with 107 additions and 66 deletions
|
@ -151,14 +151,7 @@ namespace MWRender
|
||||||
defaultMat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(0.f, 0.f, 0.f, 0.f));
|
defaultMat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(0.f, 0.f, 0.f, 0.f));
|
||||||
stateset->setAttribute(defaultMat);
|
stateset->setAttribute(defaultMat);
|
||||||
|
|
||||||
osg::ref_ptr<osg::Image> fakeShadowMapImage = new osg::Image();
|
SceneUtil::MWShadow::disableShadowsForStateSet(stateset);
|
||||||
fakeShadowMapImage->allocateImage(1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT);
|
|
||||||
*(float*)fakeShadowMapImage->data() = std::numeric_limits<float>::infinity();
|
|
||||||
osg::ref_ptr<osg::Texture> fakeShadowMapTexture = new osg::Texture2D(fakeShadowMapImage);
|
|
||||||
fakeShadowMapTexture->setShadowComparison(true);
|
|
||||||
fakeShadowMapTexture->setShadowCompareFunc(osg::Texture::ShadowCompareFunc::ALWAYS);
|
|
||||||
for (int i = SceneUtil::MWShadow::baseShadowTextureUnit; i < SceneUtil::MWShadow::baseShadowTextureUnit + SceneUtil::MWShadow::numberOfShadowMapsPerLight; ++i)
|
|
||||||
stateset->setTextureAttributeAndModes(i, fakeShadowMapTexture, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED);
|
|
||||||
|
|
||||||
// assign large value to effectively turn off fog
|
// assign large value to effectively turn off fog
|
||||||
// shaders don't respect glDisable(GL_FOG)
|
// shaders don't respect glDisable(GL_FOG)
|
||||||
|
|
|
@ -202,14 +202,7 @@ osg::ref_ptr<osg::Camera> LocalMap::createOrthographicCamera(float x, float y, f
|
||||||
|
|
||||||
lightSource->setStateSetModes(*stateset, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
|
lightSource->setStateSetModes(*stateset, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
|
||||||
|
|
||||||
osg::ref_ptr<osg::Image> fakeShadowMapImage = new osg::Image();
|
SceneUtil::MWShadow::disableShadowsForStateSet(stateset);
|
||||||
fakeShadowMapImage->allocateImage(1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT);
|
|
||||||
*(float*)fakeShadowMapImage->data() = std::numeric_limits<float>::infinity();
|
|
||||||
osg::ref_ptr<osg::Texture> fakeShadowMapTexture = new osg::Texture2D(fakeShadowMapImage);
|
|
||||||
fakeShadowMapTexture->setShadowComparison(true);
|
|
||||||
fakeShadowMapTexture->setShadowCompareFunc(osg::Texture::ShadowCompareFunc::ALWAYS);
|
|
||||||
for (int i = SceneUtil::MWShadow::baseShadowTextureUnit; i < SceneUtil::MWShadow::baseShadowTextureUnit + SceneUtil::MWShadow::numberOfShadowMapsPerLight; ++i)
|
|
||||||
stateset->setTextureAttributeAndModes(i, fakeShadowMapTexture, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED);
|
|
||||||
|
|
||||||
camera->addChild(lightSource);
|
camera->addChild(lightSource);
|
||||||
camera->setStateSet(stateset);
|
camera->setStateSet(stateset);
|
||||||
|
|
|
@ -204,25 +204,14 @@ namespace MWRender
|
||||||
|
|
||||||
osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene (new osgShadow::ShadowedScene);
|
osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene (new osgShadow::ShadowedScene);
|
||||||
|
|
||||||
osgShadow::ShadowSettings* settings = shadowedScene->getShadowSettings();
|
int shadowCastingTraversalMask = Mask_Scene;
|
||||||
settings->setLightNum(0);
|
if (Settings::Manager::getBool("actor shadows", "Shadows"))
|
||||||
settings->setCastsShadowTraversalMask(Mask_Scene|Mask_Actor|Mask_Player|Mask_Terrain);
|
shadowCastingTraversalMask |= Mask_Actor;
|
||||||
settings->setReceivesShadowTraversalMask(~0u);
|
if (Settings::Manager::getBool("player shadows", "Shadows"))
|
||||||
|
shadowCastingTraversalMask |= Mask_Player;
|
||||||
//settings->setShadowMapProjectionHint(osgShadow::ShadowSettings::PERSPECTIVE_SHADOW_MAP);
|
if (Settings::Manager::getBool("terrain shadows", "Shadows"))
|
||||||
settings->setBaseShadowTextureUnit(SceneUtil::MWShadow::baseShadowTextureUnit);
|
shadowCastingTraversalMask |= Mask_Terrain;
|
||||||
settings->setMinimumShadowMapNearFarRatio(0.25);
|
SceneUtil::MWShadow::setupShadowSettings(shadowedScene->getShadowSettings(), shadowCastingTraversalMask);
|
||||||
settings->setNumShadowMapsPerLight(SceneUtil::MWShadow::numberOfShadowMapsPerLight);
|
|
||||||
//settings->setShadowMapProjectionHint(osgShadow::ShadowSettings::ORTHOGRAPHIC_SHADOW_MAP);
|
|
||||||
//settings->setMultipleShadowMapHint(osgShadow::ShadowSettings::PARALLEL_SPLIT); // ignored
|
|
||||||
settings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES);
|
|
||||||
//settings->setDebugDraw(true); // don't turn this on because it makes everything break
|
|
||||||
|
|
||||||
//settings->setPerspectiveShadowMapCutOffAngle(0);
|
|
||||||
//settings->setShaderHint(osgShadow::ShadowSettings::PROVIDE_VERTEX_AND_FRAGMENT_SHADER);
|
|
||||||
|
|
||||||
int mapres = 2048;
|
|
||||||
settings->setTextureSize(osg::Vec2s(mapres,mapres));
|
|
||||||
|
|
||||||
SceneUtil::MWShadow* tech = new SceneUtil::MWShadow();
|
SceneUtil::MWShadow* tech = new SceneUtil::MWShadow();
|
||||||
shadowedScene->setShadowTechnique(tech);
|
shadowedScene->setShadowTechnique(tech);
|
||||||
|
|
|
@ -1124,8 +1124,7 @@ SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneMana
|
||||||
// Assign empty program to specify we don't want shaders
|
// Assign empty program to specify we don't want shaders
|
||||||
// The shaders generated by the SceneManager can't handle everything we need
|
// The shaders generated by the SceneManager can't handle everything we need
|
||||||
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);
|
||||||
for (int i = SceneUtil::MWShadow::baseShadowTextureUnit; i < SceneUtil::MWShadow::baseShadowTextureUnit + SceneUtil::MWShadow::numberOfShadowMapsPerLight; ++i)
|
SceneUtil::MWShadow::disableShadowsForStateSet(skyroot->getOrCreateStateSet());
|
||||||
skyroot->getOrCreateStateSet()->setTextureMode(i, GL_TEXTURE_2D, osg::StateAttribute::PROTECTED | osg::StateAttribute::OFF);
|
|
||||||
|
|
||||||
skyroot->setNodeMask(Mask_Sky);
|
skyroot->setNodeMask(Mask_Sky);
|
||||||
parentNode->addChild(skyroot);
|
parentNode->addChild(skyroot);
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include <osgDB/FileUtils>
|
#include <osgDB/FileUtils>
|
||||||
#include <osgDB/ReadFile>
|
#include <osgDB/ReadFile>
|
||||||
|
|
||||||
|
#include <components/settings/settings.hpp>
|
||||||
|
|
||||||
namespace SceneUtil
|
namespace SceneUtil
|
||||||
{
|
{
|
||||||
using namespace osgShadow;
|
using namespace osgShadow;
|
||||||
|
@ -46,12 +48,52 @@ namespace SceneUtil
|
||||||
" gl_FragColor = vec4( fS + fH * color, 1 ); \n"
|
" gl_FragColor = vec4( fS + fH * color, 1 ); \n"
|
||||||
#else
|
#else
|
||||||
" gl_FragColor = texture2D(texture, gl_TexCoord[0].xy); \n"
|
" gl_FragColor = texture2D(texture, gl_TexCoord[0].xy); \n"
|
||||||
" //gl_FragColor = vec4(1.0, 0.5, 0.5, 1.0); \n"
|
|
||||||
#endif
|
#endif
|
||||||
"} \n";
|
"} \n";
|
||||||
|
|
||||||
|
void MWShadow::setupShadowSettings(osg::ref_ptr<osgShadow::ShadowSettings> settings, int castsShadowMask)
|
||||||
|
{
|
||||||
|
if (!Settings::Manager::getBool("enable shadows", "Shadows"))
|
||||||
|
return;
|
||||||
|
|
||||||
MWShadow::MWShadow() : debugProgram(new osg::Program), debugTextureUnit(0)
|
settings->setLightNum(0);
|
||||||
|
settings->setCastsShadowTraversalMask(castsShadowMask);
|
||||||
|
settings->setReceivesShadowTraversalMask(~0u);
|
||||||
|
|
||||||
|
int numberOfShadowMapsPerLight = Settings::Manager::getInt("number of shadow maps", "Shadows");
|
||||||
|
settings->setNumShadowMapsPerLight(numberOfShadowMapsPerLight);
|
||||||
|
settings->setBaseShadowTextureUnit(8 - numberOfShadowMapsPerLight);
|
||||||
|
|
||||||
|
settings->setMinimumShadowMapNearFarRatio(0.25);
|
||||||
|
if (Settings::Manager::getBool("compute tight scene bounds", "Shadows"))
|
||||||
|
settings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES);
|
||||||
|
|
||||||
|
int mapres = Settings::Manager::getInt("shadow map resolution", "Shadows");
|
||||||
|
settings->setTextureSize(osg::Vec2s(mapres, mapres));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MWShadow::disableShadowsForStateSet(osg::ref_ptr<osg::StateSet> stateset)
|
||||||
|
{
|
||||||
|
int numberOfShadowMapsPerLight = Settings::Manager::getInt("number of shadow maps", "Shadows");
|
||||||
|
int baseShadowTextureUnit = 8 - numberOfShadowMapsPerLight;
|
||||||
|
|
||||||
|
osg::ref_ptr<osg::Image> fakeShadowMapImage = new osg::Image();
|
||||||
|
fakeShadowMapImage->allocateImage(1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT);
|
||||||
|
*(float*)fakeShadowMapImage->data() = std::numeric_limits<float>::infinity();
|
||||||
|
osg::ref_ptr<osg::Texture> fakeShadowMapTexture = new osg::Texture2D(fakeShadowMapImage);
|
||||||
|
fakeShadowMapTexture->setShadowComparison(true);
|
||||||
|
fakeShadowMapTexture->setShadowCompareFunc(osg::Texture::ShadowCompareFunc::ALWAYS);
|
||||||
|
for (int i = baseShadowTextureUnit; i < baseShadowTextureUnit + numberOfShadowMapsPerLight; ++i)
|
||||||
|
stateset->setTextureAttributeAndModes(i, fakeShadowMapTexture, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
MWShadow::MWShadow() : enableShadows(Settings::Manager::getBool("enable shadows", "Shadows")),
|
||||||
|
numberOfShadowMapsPerLight(Settings::Manager::getInt("number of shadow maps", "Shadows")),
|
||||||
|
baseShadowTextureUnit(8 - numberOfShadowMapsPerLight),
|
||||||
|
debugHud(Settings::Manager::getBool("enable debug hud", "Shadows")),
|
||||||
|
debugProgram(new osg::Program), debugTextureUnit(0)
|
||||||
|
{
|
||||||
|
if (debugHud)
|
||||||
{
|
{
|
||||||
osg::ref_ptr<osg::Shader> vertexShader = new osg::Shader(osg::Shader::VERTEX, debugVertexShaderSource);
|
osg::ref_ptr<osg::Shader> vertexShader = new osg::Shader(osg::Shader::VERTEX, debugVertexShaderSource);
|
||||||
debugProgram->addShader(vertexShader);
|
debugProgram->addShader(vertexShader);
|
||||||
|
@ -77,6 +119,7 @@ namespace SceneUtil
|
||||||
stateSet->addUniform(textureUniform.get());
|
stateSet->addUniform(textureUniform.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class VDSMCameraCullCallback : public osg::NodeCallback
|
class VDSMCameraCullCallback : public osg::NodeCallback
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef COMPONENTS_SCENEUTIL_SHADOW_H
|
#ifndef COMPONENTS_SCENEUTIL_SHADOW_H
|
||||||
#define COMPONENTS_SCENEUTIL_SHADOW_H
|
#define COMPONENTS_SCENEUTIL_SHADOW_H
|
||||||
|
|
||||||
|
#include <osgShadow/ShadowSettings>
|
||||||
#include <osgShadow/ViewDependentShadowMap>
|
#include <osgShadow/ViewDependentShadowMap>
|
||||||
|
|
||||||
#include <components/shader/shadermanager.hpp>
|
#include <components/shader/shadermanager.hpp>
|
||||||
|
@ -10,14 +11,12 @@ namespace SceneUtil
|
||||||
class MWShadow : public osgShadow::ViewDependentShadowMap
|
class MWShadow : public osgShadow::ViewDependentShadowMap
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static const int numberOfShadowMapsPerLight = 3;
|
static void setupShadowSettings(osg::ref_ptr<osgShadow::ShadowSettings> settings, int castsShadowMask);
|
||||||
static const bool enableShadows = true;
|
|
||||||
static const bool debugHud = true;
|
static void disableShadowsForStateSet(osg::ref_ptr<osg::StateSet> stateSet);
|
||||||
|
|
||||||
MWShadow();
|
MWShadow();
|
||||||
|
|
||||||
const static int baseShadowTextureUnit = 8 - numberOfShadowMapsPerLight;
|
|
||||||
|
|
||||||
virtual void cull(osgUtil::CullVisitor& cv);
|
virtual void cull(osgUtil::CullVisitor& cv);
|
||||||
|
|
||||||
virtual Shader::ShaderManager::DefineMap getShadowDefines();
|
virtual Shader::ShaderManager::DefineMap getShadowDefines();
|
||||||
|
@ -31,6 +30,12 @@ namespace SceneUtil
|
||||||
osg::ref_ptr<osg::Program> debugProgram;
|
osg::ref_ptr<osg::Program> debugProgram;
|
||||||
|
|
||||||
std::vector<osg::ref_ptr<osg::Node>> debugGeometry;
|
std::vector<osg::ref_ptr<osg::Node>> debugGeometry;
|
||||||
|
|
||||||
|
const int numberOfShadowMapsPerLight;
|
||||||
|
const bool enableShadows;
|
||||||
|
const bool debugHud;
|
||||||
|
|
||||||
|
const int baseShadowTextureUnit;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -466,3 +466,22 @@ companion x = 0.25
|
||||||
companion y = 0.0
|
companion y = 0.0
|
||||||
companion w = 0.75
|
companion w = 0.75
|
||||||
companion h = 0.375
|
companion h = 0.375
|
||||||
|
|
||||||
|
[Shadows]
|
||||||
|
# Enable or disable shadows.
|
||||||
|
enable shadows = false
|
||||||
|
# How many shadow maps to use - more of these means each shadow map texel covers less area, producing better looking shadows, but may decrease performance.
|
||||||
|
number of shadow maps = 1
|
||||||
|
# Enable the debug hud to see what the shadow map(s) contain.
|
||||||
|
enable debug hud = false
|
||||||
|
# Attempt to better use the shadow map by making them cover a smaller area. Especially helpful when looking downwards with a high viewing distance. The performance impact of this may be very large.
|
||||||
|
compute tight scene bounds = false
|
||||||
|
# How large to make the shadow map(s). Higher values increase GPU load, but can produce better-looking results. Power-of-two values may turn out to be faster on some GPU/driver combinations.
|
||||||
|
shadow map resolution = 1024
|
||||||
|
# Allow actors to cast shadows. Potentially decreases performance.
|
||||||
|
actor shadows = false
|
||||||
|
# Allow the player to cast shadows. Potentially decreases performance.
|
||||||
|
player shadows = false
|
||||||
|
# Allow terrain to cast shadows. Potentially decreases performance.
|
||||||
|
terrain shadows = false
|
||||||
|
# Note: Right now, there is no setting allowing toggling of shadows for statics
|
Loading…
Reference in a new issue