mirror of
https://github.com/TES3MP/TES3MP.git
synced 2025-09-27 06:55:54 -04:00
Add an option to apply lighting to environment maps
This commit is contained in:
parent
29e6c6baae
commit
6999f1fd28
@ -81,6 +81,7 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, bool fsStrict, const Files::Pat
|
|||||||
Shader::ShaderManager::DefineMap shadowDefines = SceneUtil::ShadowManager::getShadowsDisabledDefines();
|
Shader::ShaderManager::DefineMap shadowDefines = SceneUtil::ShadowManager::getShadowsDisabledDefines();
|
||||||
defines["forcePPL"] = "0";
|
defines["forcePPL"] = "0";
|
||||||
defines["clamp"] = "1";
|
defines["clamp"] = "1";
|
||||||
|
defines["preLightEnv"] = "0";
|
||||||
for (const auto& define : shadowDefines)
|
for (const auto& define : shadowDefines)
|
||||||
defines[define.first] = define.second;
|
defines[define.first] = define.second;
|
||||||
mResourceSystem->getSceneManager()->getShaderManager().setGlobalDefines(defines);
|
mResourceSystem->getSceneManager()->getShaderManager().setGlobalDefines(defines);
|
||||||
|
@ -253,6 +253,7 @@ namespace MWRender
|
|||||||
|
|
||||||
globalDefines["forcePPL"] = Settings::Manager::getBool("force per pixel lighting", "Shaders") ? "1" : "0";
|
globalDefines["forcePPL"] = Settings::Manager::getBool("force per pixel lighting", "Shaders") ? "1" : "0";
|
||||||
globalDefines["clamp"] = Settings::Manager::getBool("clamp lighting", "Shaders") ? "1" : "0";
|
globalDefines["clamp"] = Settings::Manager::getBool("clamp lighting", "Shaders") ? "1" : "0";
|
||||||
|
globalDefines["preLightEnv"] = Settings::Manager::getBool("apply lighting to environment maps", "Shaders") ? "1" : "0";
|
||||||
|
|
||||||
// It is unnecessary to stop/start the viewer as no frames are being rendered yet.
|
// It is unnecessary to stop/start the viewer as no frames are being rendered yet.
|
||||||
mResourceSystem->getSceneManager()->getShaderManager().setGlobalDefines(globalDefines);
|
mResourceSystem->getSceneManager()->getShaderManager().setGlobalDefines(globalDefines);
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include <components/sceneutil/skeleton.hpp>
|
#include <components/sceneutil/skeleton.hpp>
|
||||||
#include <components/sceneutil/riggeometry.hpp>
|
#include <components/sceneutil/riggeometry.hpp>
|
||||||
#include <components/sceneutil/morphgeometry.hpp>
|
#include <components/sceneutil/morphgeometry.hpp>
|
||||||
|
#include <components/settings/settings.hpp>
|
||||||
|
|
||||||
#include "particle.hpp"
|
#include "particle.hpp"
|
||||||
#include "userdata.hpp"
|
#include "userdata.hpp"
|
||||||
@ -427,12 +428,29 @@ namespace NifOsg
|
|||||||
texture2d->setWrap(osg::Texture::WRAP_S, wrapS ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE);
|
texture2d->setWrap(osg::Texture::WRAP_S, wrapS ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE);
|
||||||
texture2d->setWrap(osg::Texture::WRAP_T, wrapT ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE);
|
texture2d->setWrap(osg::Texture::WRAP_T, wrapT ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE);
|
||||||
|
|
||||||
|
static const bool preLightEnv = Settings::Manager::getBool("apply lighting to environment maps", "Shaders");
|
||||||
osg::ref_ptr<osg::TexEnvCombine> texEnv = new osg::TexEnvCombine;
|
osg::ref_ptr<osg::TexEnvCombine> texEnv = new osg::TexEnvCombine;
|
||||||
|
if (!preLightEnv)
|
||||||
|
{
|
||||||
texEnv->setCombine_Alpha(osg::TexEnvCombine::REPLACE);
|
texEnv->setCombine_Alpha(osg::TexEnvCombine::REPLACE);
|
||||||
texEnv->setSource0_Alpha(osg::TexEnvCombine::PREVIOUS);
|
texEnv->setSource0_Alpha(osg::TexEnvCombine::PREVIOUS);
|
||||||
texEnv->setCombine_RGB(osg::TexEnvCombine::ADD);
|
texEnv->setCombine_RGB(osg::TexEnvCombine::ADD);
|
||||||
texEnv->setSource0_RGB(osg::TexEnvCombine::PREVIOUS);
|
texEnv->setSource0_RGB(osg::TexEnvCombine::PREVIOUS);
|
||||||
texEnv->setSource1_RGB(osg::TexEnvCombine::TEXTURE);
|
texEnv->setSource1_RGB(osg::TexEnvCombine::TEXTURE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
texEnv->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE);
|
||||||
|
texEnv->setSource0_RGB(osg::TexEnvCombine::TEXTURE);
|
||||||
|
texEnv->setOperand0_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||||
|
texEnv->setSource1_RGB(osg::TexEnvCombine::PREVIOUS);
|
||||||
|
texEnv->setOperand1_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||||
|
texEnv->setSource2_RGB(osg::TexEnvCombine::TEXTURE);
|
||||||
|
texEnv->setOperand2_RGB(osg::TexEnvCombine::SRC_ALPHA);
|
||||||
|
texEnv->setCombine_Alpha(osg::TexEnvCombine::REPLACE);
|
||||||
|
texEnv->setSource0_Alpha(osg::TexEnvCombine::PREVIOUS);
|
||||||
|
texEnv->setOperand0_Alpha(osg::TexEnvCombine::SRC_ALPHA);
|
||||||
|
}
|
||||||
|
|
||||||
int texUnit = 3; // FIXME
|
int texUnit = 3; // FIXME
|
||||||
|
|
||||||
|
@ -124,3 +124,14 @@ terrain specular map pattern
|
|||||||
:Default: _diffusespec
|
:Default: _diffusespec
|
||||||
|
|
||||||
The filename pattern to probe for when detecting terrain specular maps (see 'auto use terrain specular maps')
|
The filename pattern to probe for when detecting terrain specular maps (see 'auto use terrain specular maps')
|
||||||
|
|
||||||
|
apply lighting to environment maps
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
:Type: boolean
|
||||||
|
:Range: True/False
|
||||||
|
:Default: False
|
||||||
|
|
||||||
|
Normally environment map reflections aren't affected by lighting, which makes environment-mapped (and thus bump-mapped objects) glow in the dark.
|
||||||
|
Morrowind Code Patch includes an option to remedy that by doing environment-mapping before applying lighting, this is the equivalent of that option.
|
||||||
|
This also affects fixed function pipeline rendering.
|
||||||
|
@ -75,13 +75,18 @@ Morrowind bump-mapping
|
|||||||
**Conversion difficulty:**
|
**Conversion difficulty:**
|
||||||
*Varies. Sometimes quick and easy, sometimes time-consuming and hard.*
|
*Varies. Sometimes quick and easy, sometimes time-consuming and hard.*
|
||||||
|
|
||||||
You might have bumped (pun intended) on a few bump-mapped texture packs for Morrowind that require the
|
You might have bumped (pun intended) on a few bump-mapped texture packs for Morrowind that require
|
||||||
Morrowind Code Patch (MCP). OpenMW does support the legacy bump-maps,
|
Morrowind Code Patch (MCP). OpenMW supports them, and like MCP can optionally apply lighting after environment maps
|
||||||
but bump-mapped models may look brighter than intended if they were designed with Morrowind Code Patch in mind
|
are processed which makes bump-mapped models look a bit better,
|
||||||
because MCP can optionally apply lighting after environment maps are processed which makes bump-mapped models look a bit better,
|
can make use of the gloss map channel in the bump map and can apply bump-mapping to skinned models.
|
||||||
and can make use of the gloss map channel in the bump map. It also makes skinned mesh bump-mapping possible.
|
Add this to settings.cfg_-file:
|
||||||
We chose not to replicate the difference in environment map handling, but gloss map channel as well as skinned mesh bump-mapping are supported.
|
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
[Shaders]
|
||||||
|
apply lighting to environment maps = true
|
||||||
|
|
||||||
|
But sometimes you may want them to look a bit better than in vanilla.
|
||||||
Technically you aren't supposed to convert bump maps because they shouldn't be normal maps that are supported by OpenMW as well,
|
Technically you aren't supposed to convert bump maps because they shouldn't be normal maps that are supported by OpenMW as well,
|
||||||
but artists may use actual normal maps as bump maps either because they look better in vanilla... or because they're lazy.
|
but artists may use actual normal maps as bump maps either because they look better in vanilla... or because they're lazy.
|
||||||
In this case you can benefit from OpenMW's normal-mapping support by using these bump maps the way normal maps are used.
|
In this case you can benefit from OpenMW's normal-mapping support by using these bump maps the way normal maps are used.
|
||||||
@ -203,7 +208,7 @@ Since we want the glory of normal-mapping in our OpenMW setup, we will go with t
|
|||||||
|
|
||||||
#. Start by downloading Apel's `Various Things - Sacks`_ from Nexus.
|
#. Start by downloading Apel's `Various Things - Sacks`_ from Nexus.
|
||||||
#. Once downloaded, install it the way you'd normally install your mods (**Pro tip**: Install using OpenMW's `Multiple data folders`_ function!).
|
#. Once downloaded, install it the way you'd normally install your mods (**Pro tip**: Install using OpenMW's `Multiple data folders`_ function!).
|
||||||
#. Now, if you ran the mod right away, your sacks may look... wetter than expected. This is because the mod assumes you have the MCP feature which makes the sacks less shiny enabled. Which you can't have enabled.
|
#. Now, if you ran the mod right away, your sacks may look... wetter than expected. This is because the mod assumes you have the MCP feature which makes the sacks less shiny enabled. You can have its equivalent enabled to make the sacks look like in Morrowind with MCP, or you may proceed on the tutorial.
|
||||||
#. We need to fix this by removing some tags in the model files. You need to download NifSkope_ for this, which, again, only have binaries available for Windows.
|
#. We need to fix this by removing some tags in the model files. You need to download NifSkope_ for this, which, again, only have binaries available for Windows.
|
||||||
#. Go the place where you installed the mod and go to ``./Meshes/o/`` to find the model files.
|
#. Go the place where you installed the mod and go to ``./Meshes/o/`` to find the model files.
|
||||||
- If you installed the mod like I suggested, finding the files will be easy as a pie, but if you installed it by dropping everything into your main Morrowind Data Files folder, then you'll have to scroll a lot to find them. Check the mod's zip file for the file names of the models if this is the case. The same thing applies to when fixing the textures.
|
- If you installed the mod like I suggested, finding the files will be easy as a pie, but if you installed it by dropping everything into your main Morrowind Data Files folder, then you'll have to scroll a lot to find them. Check the mod's zip file for the file names of the models if this is the case. The same thing applies to when fixing the textures.
|
||||||
|
@ -346,6 +346,10 @@ specular map pattern = _spec
|
|||||||
# The filename pattern to probe for when detecting terrain specular maps (see 'auto use terrain specular maps')
|
# The filename pattern to probe for when detecting terrain specular maps (see 'auto use terrain specular maps')
|
||||||
terrain specular map pattern = _diffusespec
|
terrain specular map pattern = _diffusespec
|
||||||
|
|
||||||
|
# Apply lighting to environment map reflections on the rendered objects like in Morrowind Code Patch.
|
||||||
|
# Also affects fixed function pipeline.
|
||||||
|
apply lighting to environment maps = false
|
||||||
|
|
||||||
[Input]
|
[Input]
|
||||||
|
|
||||||
# Capture control of the cursor prevent movement outside the window.
|
# Capture control of the cursor prevent movement outside the window.
|
||||||
|
@ -119,6 +119,31 @@ void main()
|
|||||||
#if @decalMap
|
#if @decalMap
|
||||||
vec4 decalTex = texture2D(decalMap, decalMapUV);
|
vec4 decalTex = texture2D(decalMap, decalMapUV);
|
||||||
gl_FragData[0].xyz = mix(gl_FragData[0].xyz, decalTex.xyz, decalTex.a);
|
gl_FragData[0].xyz = mix(gl_FragData[0].xyz, decalTex.xyz, decalTex.a);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if @envMap
|
||||||
|
|
||||||
|
vec2 envTexCoordGen = envMapUV;
|
||||||
|
float envLuma = 1.0;
|
||||||
|
|
||||||
|
#if @normalMap
|
||||||
|
// if using normal map + env map, take advantage of per-pixel normals for envTexCoordGen
|
||||||
|
vec3 viewVec = normalize(passViewPos.xyz);
|
||||||
|
vec3 r = reflect( viewVec, viewNormal );
|
||||||
|
float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );
|
||||||
|
envTexCoordGen = vec2(r.x/m + 0.5, r.y/m + 0.5);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if @bumpMap
|
||||||
|
vec4 bumpTex = texture2D(bumpMap, bumpMapUV);
|
||||||
|
envTexCoordGen += bumpTex.rg * bumpMapMatrix;
|
||||||
|
envLuma = clamp(bumpTex.b * envMapLumaBias.x + envMapLumaBias.y, 0.0, 1.0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if @preLightEnv
|
||||||
|
gl_FragData[0].xyz += texture2D(envMap, envTexCoordGen).xyz * envMapColor.xyz * envLuma;
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float shadowing = unshadowedLightRatio(depth);
|
float shadowing = unshadowedLightRatio(depth);
|
||||||
@ -135,30 +160,14 @@ void main()
|
|||||||
gl_FragData[0] *= doLighting(passViewPos, normalize(viewNormal), passColor, shadowing);
|
gl_FragData[0] *= doLighting(passViewPos, normalize(viewNormal), passColor, shadowing);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if @envMap && !@preLightEnv
|
||||||
|
gl_FragData[0].xyz += texture2D(envMap, envTexCoordGen).xyz * envMapColor.xyz * envLuma;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if @emissiveMap
|
#if @emissiveMap
|
||||||
gl_FragData[0].xyz += texture2D(emissiveMap, emissiveMapUV).xyz;
|
gl_FragData[0].xyz += texture2D(emissiveMap, emissiveMapUV).xyz;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if @envMap
|
|
||||||
vec2 texCoordGen = envMapUV;
|
|
||||||
float envLuma = 1.0;
|
|
||||||
|
|
||||||
#if @normalMap
|
|
||||||
// if using normal map + env map, take advantage of per-pixel normals for texCoordGen
|
|
||||||
vec3 viewVec = normalize(passViewPos.xyz);
|
|
||||||
vec3 r = reflect( viewVec, viewNormal );
|
|
||||||
float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );
|
|
||||||
texCoordGen = vec2(r.x/m + 0.5, r.y/m + 0.5);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if @bumpMap
|
|
||||||
vec4 bumpTex = texture2D(bumpMap, bumpMapUV);
|
|
||||||
texCoordGen += bumpTex.rg * bumpMapMatrix;
|
|
||||||
envLuma = clamp(bumpTex.b * envMapLumaBias.x + envMapLumaBias.y, 0.0, 1.0);
|
|
||||||
#endif
|
|
||||||
gl_FragData[0].xyz += texture2D(envMap, texCoordGen).xyz * envMapColor.xyz * envLuma;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if @specularMap
|
#if @specularMap
|
||||||
vec4 specTex = texture2D(specularMap, specularMapUV);
|
vec4 specTex = texture2D(specularMap, specularMapUV);
|
||||||
float shininess = specTex.a * 255;
|
float shininess = specTex.a * 255;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user