mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-29 03:36:40 +00:00
Support red-green normal maps
This commit is contained in:
parent
819aace891
commit
58afe1ba23
9 changed files with 42 additions and 5 deletions
|
@ -152,6 +152,7 @@ CSMWorld::Data::Data(ToUTF8::FromType encoding, const Files::PathContainer& data
|
||||||
mResourceSystem
|
mResourceSystem
|
||||||
= std::make_unique<Resource::ResourceSystem>(mVFS.get(), expiryDelay, &mEncoder.getStatelessEncoder());
|
= std::make_unique<Resource::ResourceSystem>(mVFS.get(), expiryDelay, &mEncoder.getStatelessEncoder());
|
||||||
|
|
||||||
|
// FIXME: this is severely out of date (see #7595)
|
||||||
Shader::ShaderManager::DefineMap defines
|
Shader::ShaderManager::DefineMap defines
|
||||||
= mResourceSystem->getSceneManager()->getShaderManager().getGlobalDefines();
|
= mResourceSystem->getSceneManager()->getShaderManager().getGlobalDefines();
|
||||||
Shader::ShaderManager::DefineMap shadowDefines = SceneUtil::ShadowManager::getShadowsDisabledDefines();
|
Shader::ShaderManager::DefineMap shadowDefines = SceneUtil::ShadowManager::getShadowsDisabledDefines();
|
||||||
|
|
|
@ -446,6 +446,7 @@ namespace MWRender
|
||||||
globalDefines["useOVR_multiview"] = "0";
|
globalDefines["useOVR_multiview"] = "0";
|
||||||
globalDefines["numViews"] = "1";
|
globalDefines["numViews"] = "1";
|
||||||
globalDefines["disableNormals"] = "1";
|
globalDefines["disableNormals"] = "1";
|
||||||
|
globalDefines["reconstructNormalZ"] = "0";
|
||||||
|
|
||||||
for (auto itr = lightDefines.begin(); itr != lightDefines.end(); itr++)
|
for (auto itr = lightDefines.begin(); itr != lightDefines.end(); itr++)
|
||||||
globalDefines[itr->first] = itr->second;
|
globalDefines[itr->first] = itr->second;
|
||||||
|
|
|
@ -78,8 +78,7 @@ namespace Resource
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// not bothering with checks for other compression formats right now, we are unlikely to ever use those
|
// not bothering with checks for other compression formats right now
|
||||||
// anyway
|
|
||||||
default:
|
default:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,6 +184,7 @@ namespace Shader
|
||||||
, mAdditiveBlending(false)
|
, mAdditiveBlending(false)
|
||||||
, mDiffuseHeight(false)
|
, mDiffuseHeight(false)
|
||||||
, mNormalHeight(false)
|
, mNormalHeight(false)
|
||||||
|
, mReconstructNormalZ(false)
|
||||||
, mTexStageRequiringTangents(-1)
|
, mTexStageRequiringTangents(-1)
|
||||||
, mSoftParticles(false)
|
, mSoftParticles(false)
|
||||||
, mNode(nullptr)
|
, mNode(nullptr)
|
||||||
|
@ -429,6 +430,7 @@ namespace Shader
|
||||||
normalMapTex->setFilter(osg::Texture::MAG_FILTER, diffuseMap->getFilter(osg::Texture::MAG_FILTER));
|
normalMapTex->setFilter(osg::Texture::MAG_FILTER, diffuseMap->getFilter(osg::Texture::MAG_FILTER));
|
||||||
normalMapTex->setMaxAnisotropy(diffuseMap->getMaxAnisotropy());
|
normalMapTex->setMaxAnisotropy(diffuseMap->getMaxAnisotropy());
|
||||||
normalMapTex->setName("normalMap");
|
normalMapTex->setName("normalMap");
|
||||||
|
normalMap = normalMapTex;
|
||||||
|
|
||||||
int unit = texAttributes.size();
|
int unit = texAttributes.size();
|
||||||
if (!writableStateSet)
|
if (!writableStateSet)
|
||||||
|
@ -440,6 +442,23 @@ namespace Shader
|
||||||
mRequirements.back().mNormalHeight = normalHeight;
|
mRequirements.back().mNormalHeight = normalHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (normalMap != nullptr && normalMap->getImage(0))
|
||||||
|
{
|
||||||
|
// Special handling for red-green normal maps (e.g. BC5 or R8G8).
|
||||||
|
switch (normalMap->getImage(0)->getPixelFormat())
|
||||||
|
{
|
||||||
|
case GL_RG:
|
||||||
|
case GL_RG_INTEGER:
|
||||||
|
case GL_COMPRESSED_RED_GREEN_RGTC2_EXT:
|
||||||
|
case GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT:
|
||||||
|
{
|
||||||
|
mRequirements.back().mReconstructNormalZ = true;
|
||||||
|
mRequirements.back().mNormalHeight = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mAutoUseSpecularMaps && diffuseMap != nullptr && specularMap == nullptr && diffuseMap->getImage(0))
|
if (mAutoUseSpecularMaps && diffuseMap != nullptr && specularMap == nullptr && diffuseMap->getImage(0))
|
||||||
{
|
{
|
||||||
std::string specularMapFileName = diffuseMap->getImage(0)->getFileName();
|
std::string specularMapFileName = diffuseMap->getImage(0)->getFileName();
|
||||||
|
@ -629,6 +648,7 @@ namespace Shader
|
||||||
|
|
||||||
defineMap["diffuseParallax"] = reqs.mDiffuseHeight ? "1" : "0";
|
defineMap["diffuseParallax"] = reqs.mDiffuseHeight ? "1" : "0";
|
||||||
defineMap["parallax"] = reqs.mNormalHeight ? "1" : "0";
|
defineMap["parallax"] = reqs.mNormalHeight ? "1" : "0";
|
||||||
|
defineMap["reconstructNormalZ"] = reqs.mReconstructNormalZ ? "1" : "0";
|
||||||
|
|
||||||
writableStateSet->addUniform(new osg::Uniform("colorMode", reqs.mColorMode));
|
writableStateSet->addUniform(new osg::Uniform("colorMode", reqs.mColorMode));
|
||||||
addedState->addUniform("colorMode");
|
addedState->addUniform("colorMode");
|
||||||
|
|
|
@ -110,6 +110,7 @@ namespace Shader
|
||||||
|
|
||||||
bool mDiffuseHeight; // true if diffuse map has height info in alpha channel
|
bool mDiffuseHeight; // true if diffuse map has height info in alpha channel
|
||||||
bool mNormalHeight; // true if normal map has height info in alpha channel
|
bool mNormalHeight; // true if normal map has height info in alpha channel
|
||||||
|
bool mReconstructNormalZ; // used for red-green normal maps (e.g. BC5)
|
||||||
|
|
||||||
// -1 == no tangents required
|
// -1 == no tangents required
|
||||||
int mTexStageRequiringTangents;
|
int mTexStageRequiringTangents;
|
||||||
|
|
|
@ -77,6 +77,9 @@ void main()
|
||||||
vec3 specularColor = getSpecularColor().xyz;
|
vec3 specularColor = getSpecularColor().xyz;
|
||||||
#if @normalMap
|
#if @normalMap
|
||||||
vec4 normalTex = texture2D(normalMap, normalMapUV);
|
vec4 normalTex = texture2D(normalMap, normalMapUV);
|
||||||
|
#if @reconstructNormalZ
|
||||||
|
normalTex.z = sqrt(1.0 - dot(normalTex.xy, normalTex.xy));
|
||||||
|
#endif
|
||||||
vec3 viewNormal = normalToView(normalTex.xyz * 2.0 - 1.0);
|
vec3 viewNormal = normalToView(normalTex.xyz * 2.0 - 1.0);
|
||||||
specularColor *= normalTex.a;
|
specularColor *= normalTex.a;
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -59,7 +59,11 @@ void main()
|
||||||
gl_FragData[0].a = alphaTest(gl_FragData[0].a, alphaRef);
|
gl_FragData[0].a = alphaTest(gl_FragData[0].a, alphaRef);
|
||||||
|
|
||||||
#if @normalMap
|
#if @normalMap
|
||||||
vec3 viewNormal = normalToView(texture2D(normalMap, normalMapUV).xyz * 2.0 - 1.0);
|
vec4 normalTex = texture2D(normalMap, normalMapUV);
|
||||||
|
#if @reconstructNormalZ
|
||||||
|
normalTex.z = sqrt(1.0 - dot(normalTex.xy, normalTex.xy));
|
||||||
|
#endif
|
||||||
|
vec3 viewNormal = normalToView(normalTex.xyz * 2.0 - 1.0);
|
||||||
#else
|
#else
|
||||||
vec3 viewNormal = normalToView(normalize(passNormal));
|
vec3 viewNormal = normalToView(normalize(passNormal));
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -167,7 +167,11 @@ vec2 screenCoords = gl_FragCoord.xy / screenRes;
|
||||||
gl_FragData[0].a = alphaTest(gl_FragData[0].a, alphaRef);
|
gl_FragData[0].a = alphaTest(gl_FragData[0].a, alphaRef);
|
||||||
|
|
||||||
#if @normalMap
|
#if @normalMap
|
||||||
vec3 viewNormal = normalToView(texture2D(normalMap, normalMapUV + offset).xyz * 2.0 - 1.0);
|
vec4 normalTex = texture2D(normalMap, normalMapUV + offset);
|
||||||
|
#if @reconstructNormalZ
|
||||||
|
normalTex.z = sqrt(1.0 - dot(normalTex.xy, normalTex.xy));
|
||||||
|
#endif
|
||||||
|
vec3 viewNormal = normalToView(normalTex.xyz * 2.0 - 1.0);
|
||||||
#else
|
#else
|
||||||
vec3 viewNormal = normalize(gl_NormalMatrix * passNormal);
|
vec3 viewNormal = normalize(gl_NormalMatrix * passNormal);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -63,7 +63,11 @@ void main()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if @normalMap
|
#if @normalMap
|
||||||
vec3 viewNormal = normalToView(texture2D(normalMap, adjustedUV).xyz * 2.0 - 1.0);
|
vec4 normalTex = texture2D(normalMap, adjustedUV);
|
||||||
|
#if @reconstructNormalZ
|
||||||
|
normalTex.z = sqrt(1.0 - dot(normalTex.xy, normalTex.xy));
|
||||||
|
#endif
|
||||||
|
vec3 viewNormal = normalToView(normalTex.xyz * 2.0 - 1.0);
|
||||||
#else
|
#else
|
||||||
vec3 viewNormal = normalize(gl_NormalMatrix * passNormal);
|
vec3 viewNormal = normalize(gl_NormalMatrix * passNormal);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue