mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Merge branch 'normal_fix' into 'master'
Fix pass normals (#7146, #7145) See merge request OpenMW/openmw!2635
This commit is contained in:
commit
761aef61ae
@ -313,8 +313,9 @@ namespace MWRender
|
|||||||
class DepthClearCallback : public osgUtil::RenderBin::DrawCallback
|
class DepthClearCallback : public osgUtil::RenderBin::DrawCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DepthClearCallback()
|
DepthClearCallback(Resource::ResourceSystem* resourceSystem)
|
||||||
{
|
{
|
||||||
|
mPassNormals = resourceSystem->getSceneManager()->getSupportsNormalsRT();
|
||||||
mDepth = new SceneUtil::AutoDepth;
|
mDepth = new SceneUtil::AutoDepth;
|
||||||
mDepth->setWriteMask(true);
|
mDepth->setWriteMask(true);
|
||||||
|
|
||||||
@ -337,7 +338,11 @@ namespace MWRender
|
|||||||
if (postProcessor && postProcessor->getFbo(PostProcessor::FBO_FirstPerson, frameId))
|
if (postProcessor && postProcessor->getFbo(PostProcessor::FBO_FirstPerson, frameId))
|
||||||
{
|
{
|
||||||
postProcessor->getFbo(PostProcessor::FBO_FirstPerson, frameId)->apply(*state);
|
postProcessor->getFbo(PostProcessor::FBO_FirstPerson, frameId)->apply(*state);
|
||||||
|
if (mPassNormals)
|
||||||
|
{
|
||||||
|
state->get<osg::GLExtensions>()->glColorMaski(1, true, true, true, true);
|
||||||
|
state->haveAppliedAttribute(osg::StateAttribute::COLORMASK);
|
||||||
|
}
|
||||||
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
// color accumulation pass
|
// color accumulation pass
|
||||||
bin->drawImplementation(renderInfo, previous);
|
bin->drawImplementation(renderInfo, previous);
|
||||||
@ -368,6 +373,7 @@ namespace MWRender
|
|||||||
state->checkGLErrors("after DepthClearCallback::drawImplementation");
|
state->checkGLErrors("after DepthClearCallback::drawImplementation");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool mPassNormals;
|
||||||
osg::ref_ptr<osg::Depth> mDepth;
|
osg::ref_ptr<osg::Depth> mDepth;
|
||||||
osg::ref_ptr<osg::StateSet> mStateSet;
|
osg::ref_ptr<osg::StateSet> mStateSet;
|
||||||
};
|
};
|
||||||
@ -416,7 +422,7 @@ namespace MWRender
|
|||||||
if (!prototypeAdded)
|
if (!prototypeAdded)
|
||||||
{
|
{
|
||||||
osg::ref_ptr<osgUtil::RenderBin> depthClearBin(new osgUtil::RenderBin);
|
osg::ref_ptr<osgUtil::RenderBin> depthClearBin(new osgUtil::RenderBin);
|
||||||
depthClearBin->setDrawCallback(new DepthClearCallback);
|
depthClearBin->setDrawCallback(new DepthClearCallback(mResourceSystem));
|
||||||
osgUtil::RenderBin::addRenderBinPrototype("DepthClear", depthClearBin);
|
osgUtil::RenderBin::addRenderBinPrototype("DepthClear", depthClearBin);
|
||||||
prototypeAdded = true;
|
prototypeAdded = true;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ fragment main {
|
|||||||
omw_FragColor = vec4(vec3(omw_GetLinearDepth(omw_TexCoord) / omw.far * uDepthFactor), 1.0);
|
omw_FragColor = vec4(vec3(omw_GetLinearDepth(omw_TexCoord) / omw.far * uDepthFactor), 1.0);
|
||||||
#if OMW_NORMALS
|
#if OMW_NORMALS
|
||||||
if (uDisplayNormals && (!uDisplayDepth || omw_TexCoord.x < 0.5))
|
if (uDisplayNormals && (!uDisplayDepth || omw_TexCoord.x < 0.5))
|
||||||
omw_FragColor.rgb = omw_GetNormals(omw_TexCoord);
|
omw_FragColor.rgb = omw_GetNormals(omw_TexCoord) * 0.5 + 0.5;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,19 +45,19 @@ varying vec3 passNormal;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 worldNormal = normalize(passNormal);
|
vec3 normal = normalize(passNormal);
|
||||||
|
|
||||||
#if @normalMap
|
#if @normalMap
|
||||||
vec4 normalTex = texture2D(normalMap, normalMapUV);
|
vec4 normalTex = texture2D(normalMap, normalMapUV);
|
||||||
|
|
||||||
vec3 normalizedNormal = worldNormal;
|
vec3 normalizedNormal = normal;
|
||||||
vec3 normalizedTangent = normalize(passTangent.xyz);
|
vec3 normalizedTangent = normalize(passTangent.xyz);
|
||||||
vec3 binormal = cross(normalizedTangent, normalizedNormal) * passTangent.w;
|
vec3 binormal = cross(normalizedTangent, normalizedNormal) * passTangent.w;
|
||||||
mat3 tbnTranspose = mat3(normalizedTangent, binormal, normalizedNormal);
|
mat3 tbnTranspose = mat3(normalizedTangent, binormal, normalizedNormal);
|
||||||
|
|
||||||
worldNormal = normalize(tbnTranspose * (normalTex.xyz * 2.0 - 1.0));
|
normal = normalize(tbnTranspose * (normalTex.xyz * 2.0 - 1.0));
|
||||||
vec3 viewNormal = gl_NormalMatrix * worldNormal;
|
|
||||||
#endif
|
#endif
|
||||||
|
vec3 viewNormal = normalize(gl_NormalMatrix * normal);
|
||||||
|
|
||||||
#if @diffuseMap
|
#if @diffuseMap
|
||||||
gl_FragData[0] = texture2D(diffuseMap, diffuseMapUV);
|
gl_FragData[0] = texture2D(diffuseMap, diffuseMapUV);
|
||||||
@ -77,7 +77,7 @@ void main()
|
|||||||
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
||||||
#else
|
#else
|
||||||
vec3 diffuseLight, ambientLight;
|
vec3 diffuseLight, ambientLight;
|
||||||
doLighting(passViewPos, normalize(viewNormal), shadowing, diffuseLight, ambientLight);
|
doLighting(passViewPos, viewNormal, shadowing, diffuseLight, ambientLight);
|
||||||
lighting = diffuseLight + ambientLight;
|
lighting = diffuseLight + ambientLight;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ void main()
|
|||||||
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth);
|
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth);
|
||||||
|
|
||||||
#if !@disableNormals
|
#if !@disableNormals
|
||||||
gl_FragData[1].xyz = worldNormal * 0.5 + 0.5;
|
gl_FragData[1].xyz = viewNormal * 0.5 + 0.5;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
applyShadowDebugOverlay();
|
applyShadowDebugOverlay();
|
||||||
|
@ -46,7 +46,7 @@ uniform float specStrength;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 worldNormal = normalize(passNormal);
|
vec3 normal = normalize(passNormal);
|
||||||
|
|
||||||
#if @diffuseMap
|
#if @diffuseMap
|
||||||
gl_FragData[0] = texture2D(diffuseMap, diffuseMapUV);
|
gl_FragData[0] = texture2D(diffuseMap, diffuseMapUV);
|
||||||
@ -62,20 +62,18 @@ void main()
|
|||||||
#if @normalMap
|
#if @normalMap
|
||||||
vec4 normalTex = texture2D(normalMap, normalMapUV);
|
vec4 normalTex = texture2D(normalMap, normalMapUV);
|
||||||
|
|
||||||
vec3 normalizedNormal = worldNormal;
|
vec3 normalizedNormal = normal;
|
||||||
vec3 normalizedTangent = normalize(passTangent.xyz);
|
vec3 normalizedTangent = normalize(passTangent.xyz);
|
||||||
vec3 binormal = cross(normalizedTangent, normalizedNormal) * passTangent.w;
|
vec3 binormal = cross(normalizedTangent, normalizedNormal) * passTangent.w;
|
||||||
mat3 tbnTranspose = mat3(normalizedTangent, binormal, normalizedNormal);
|
mat3 tbnTranspose = mat3(normalizedTangent, binormal, normalizedNormal);
|
||||||
|
|
||||||
worldNormal = normalize(tbnTranspose * (normalTex.xyz * 2.0 - 1.0));
|
normal = normalize(tbnTranspose * (normalTex.xyz * 2.0 - 1.0));
|
||||||
vec3 viewNormal = gl_NormalMatrix * worldNormal;
|
|
||||||
#else
|
|
||||||
vec3 viewNormal = gl_NormalMatrix * worldNormal;
|
|
||||||
#endif
|
#endif
|
||||||
|
vec3 viewNormal = normalize(gl_NormalMatrix * normal);
|
||||||
|
|
||||||
float shadowing = unshadowedLightRatio(linearDepth);
|
float shadowing = unshadowedLightRatio(linearDepth);
|
||||||
vec3 diffuseLight, ambientLight;
|
vec3 diffuseLight, ambientLight;
|
||||||
doLighting(passViewPos, normalize(viewNormal), shadowing, diffuseLight, ambientLight);
|
doLighting(passViewPos, viewNormal, shadowing, diffuseLight, ambientLight);
|
||||||
vec3 emission = getEmissionColor().xyz * emissiveMult;
|
vec3 emission = getEmissionColor().xyz * emissiveMult;
|
||||||
#if @emissiveMap
|
#if @emissiveMap
|
||||||
emission *= texture2D(emissiveMap, emissiveMapUV).xyz;
|
emission *= texture2D(emissiveMap, emissiveMapUV).xyz;
|
||||||
@ -93,7 +91,7 @@ void main()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (matSpec != vec3(0.0))
|
if (matSpec != vec3(0.0))
|
||||||
gl_FragData[0].xyz += getSpecular(normalize(viewNormal), normalize(passViewPos.xyz), shininess, matSpec) * shadowing;
|
gl_FragData[0].xyz += getSpecular(viewNormal, normalize(passViewPos.xyz), shininess, matSpec) * shadowing;
|
||||||
|
|
||||||
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth);
|
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth);
|
||||||
|
|
||||||
@ -103,7 +101,7 @@ void main()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(FORCE_OPAQUE) && !@disableNormals
|
#if !defined(FORCE_OPAQUE) && !@disableNormals
|
||||||
gl_FragData[1].xyz = worldNormal * 0.5 + 0.5;
|
gl_FragData[1].xyz = viewNormal * 0.5 + 0.5;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
applyShadowDebugOverlay();
|
applyShadowDebugOverlay();
|
||||||
|
@ -120,23 +120,18 @@ void main()
|
|||||||
vec2 adjustedDiffuseUV = diffuseMapUV;
|
vec2 adjustedDiffuseUV = diffuseMapUV;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vec3 worldNormal = normalize(passNormal);
|
vec3 normal = normalize(passNormal);
|
||||||
vec3 viewVec = normalize(passViewPos.xyz);
|
vec3 viewVec = normalize(passViewPos.xyz);
|
||||||
|
|
||||||
#if @normalMap
|
#if @normalMap
|
||||||
vec4 normalTex = texture2D(normalMap, normalMapUV);
|
vec4 normalTex = texture2D(normalMap, normalMapUV);
|
||||||
|
|
||||||
vec3 normalizedNormal = worldNormal;
|
vec3 normalizedNormal = normal;
|
||||||
vec3 normalizedTangent = normalize(passTangent.xyz);
|
vec3 normalizedTangent = normalize(passTangent.xyz);
|
||||||
vec3 binormal = cross(normalizedTangent, normalizedNormal) * passTangent.w;
|
vec3 binormal = cross(normalizedTangent, normalizedNormal) * passTangent.w;
|
||||||
mat3 tbnTranspose = mat3(normalizedTangent, binormal, normalizedNormal);
|
mat3 tbnTranspose = mat3(normalizedTangent, binormal, normalizedNormal);
|
||||||
|
|
||||||
worldNormal = normalize(tbnTranspose * (normalTex.xyz * 2.0 - 1.0));
|
normal = normalize(tbnTranspose * (normalTex.xyz * 2.0 - 1.0));
|
||||||
vec3 viewNormal = gl_NormalMatrix * worldNormal;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (!@normalMap && (@parallax || @forcePPL || @softParticles))
|
|
||||||
vec3 viewNormal = gl_NormalMatrix * worldNormal;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if @parallax
|
#if @parallax
|
||||||
@ -152,12 +147,13 @@ void main()
|
|||||||
// fetch a new normal using updated coordinates
|
// fetch a new normal using updated coordinates
|
||||||
normalTex = texture2D(normalMap, adjustedDiffuseUV);
|
normalTex = texture2D(normalMap, adjustedDiffuseUV);
|
||||||
|
|
||||||
worldNormal = normalize(tbnTranspose * (normalTex.xyz * 2.0 - 1.0));
|
normal = normalize(tbnTranspose * (normalTex.xyz * 2.0 - 1.0));
|
||||||
viewNormal = gl_NormalMatrix * worldNormal;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
vec3 viewNormal = normalize(gl_NormalMatrix * normal);
|
||||||
|
|
||||||
#if @diffuseMap
|
#if @diffuseMap
|
||||||
gl_FragData[0] = texture2D(diffuseMap, adjustedDiffuseUV);
|
gl_FragData[0] = texture2D(diffuseMap, adjustedDiffuseUV);
|
||||||
gl_FragData[0].a *= coveragePreservingAlphaScale(diffuseMap, adjustedDiffuseUV);
|
gl_FragData[0].a *= coveragePreservingAlphaScale(diffuseMap, adjustedDiffuseUV);
|
||||||
@ -220,7 +216,7 @@ void main()
|
|||||||
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
||||||
#else
|
#else
|
||||||
vec3 diffuseLight, ambientLight;
|
vec3 diffuseLight, ambientLight;
|
||||||
doLighting(passViewPos, normalize(viewNormal), shadowing, diffuseLight, ambientLight);
|
doLighting(passViewPos, viewNormal, shadowing, diffuseLight, ambientLight);
|
||||||
vec3 emission = getEmissionColor().xyz * emissiveMult;
|
vec3 emission = getEmissionColor().xyz * emissiveMult;
|
||||||
lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + emission;
|
lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + emission;
|
||||||
#endif
|
#endif
|
||||||
@ -249,10 +245,7 @@ void main()
|
|||||||
matSpec *= specStrength;
|
matSpec *= specStrength;
|
||||||
if (matSpec != vec3(0.0))
|
if (matSpec != vec3(0.0))
|
||||||
{
|
{
|
||||||
#if (!@normalMap && !@parallax && !@forcePPL)
|
gl_FragData[0].xyz += getSpecular(viewNormal, viewVec, shininess, matSpec) * shadowing;
|
||||||
vec3 viewNormal = gl_NormalMatrix * worldNormal;
|
|
||||||
#endif
|
|
||||||
gl_FragData[0].xyz += getSpecular(normalize(viewNormal), viewVec, shininess, matSpec) * shadowing;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gl_FragData[0] = applyFogAtPos(gl_FragData[0], passViewPos);
|
gl_FragData[0] = applyFogAtPos(gl_FragData[0], passViewPos);
|
||||||
@ -267,7 +260,7 @@ void main()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(FORCE_OPAQUE) && !@disableNormals
|
#if !defined(FORCE_OPAQUE) && !@disableNormals
|
||||||
gl_FragData[1].xyz = worldNormal * 0.5 + 0.5;
|
gl_FragData[1].xyz = viewNormal * 0.5 + 0.5;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
applyShadowDebugOverlay();
|
applyShadowDebugOverlay();
|
||||||
|
@ -44,24 +44,18 @@ void main()
|
|||||||
{
|
{
|
||||||
vec2 adjustedUV = (gl_TextureMatrix[0] * vec4(uv, 0.0, 1.0)).xy;
|
vec2 adjustedUV = (gl_TextureMatrix[0] * vec4(uv, 0.0, 1.0)).xy;
|
||||||
|
|
||||||
vec3 worldNormal = normalize(passNormal);
|
vec3 normal = normalize(passNormal);
|
||||||
|
|
||||||
#if @normalMap
|
#if @normalMap
|
||||||
vec4 normalTex = texture2D(normalMap, adjustedUV);
|
vec4 normalTex = texture2D(normalMap, adjustedUV);
|
||||||
|
|
||||||
vec3 normalizedNormal = worldNormal;
|
vec3 normalizedNormal = normal;
|
||||||
vec3 tangent = vec3(1.0, 0.0, 0.0);
|
vec3 tangent = vec3(1.0, 0.0, 0.0);
|
||||||
vec3 binormal = normalize(cross(tangent, normalizedNormal));
|
vec3 binormal = normalize(cross(tangent, normalizedNormal));
|
||||||
tangent = normalize(cross(normalizedNormal, binormal)); // note, now we need to re-cross to derive tangent again because it wasn't orthonormal
|
tangent = normalize(cross(normalizedNormal, binormal)); // note, now we need to re-cross to derive tangent again because it wasn't orthonormal
|
||||||
mat3 tbnTranspose = mat3(tangent, binormal, normalizedNormal);
|
mat3 tbnTranspose = mat3(tangent, binormal, normalizedNormal);
|
||||||
|
|
||||||
worldNormal = tbnTranspose * (normalTex.xyz * 2.0 - 1.0);
|
normal = tbnTranspose * (normalTex.xyz * 2.0 - 1.0);
|
||||||
vec3 viewNormal = normalize(gl_NormalMatrix * worldNormal);
|
|
||||||
normalize(worldNormal);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (!@normalMap && (@parallax || @forcePPL))
|
|
||||||
vec3 viewNormal = gl_NormalMatrix * worldNormal;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if @parallax
|
#if @parallax
|
||||||
@ -73,11 +67,11 @@ void main()
|
|||||||
// update normal using new coordinates
|
// update normal using new coordinates
|
||||||
normalTex = texture2D(normalMap, adjustedUV);
|
normalTex = texture2D(normalMap, adjustedUV);
|
||||||
|
|
||||||
worldNormal = tbnTranspose * (normalTex.xyz * 2.0 - 1.0);
|
normal = tbnTranspose * (normalTex.xyz * 2.0 - 1.0);
|
||||||
viewNormal = normalize(gl_NormalMatrix * worldNormal);
|
|
||||||
normalize(worldNormal);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
vec3 viewNormal = normalize(gl_NormalMatrix * normal);
|
||||||
|
|
||||||
vec4 diffuseTex = texture2D(diffuseMap, adjustedUV);
|
vec4 diffuseTex = texture2D(diffuseMap, adjustedUV);
|
||||||
gl_FragData[0] = vec4(diffuseTex.xyz, 1.0);
|
gl_FragData[0] = vec4(diffuseTex.xyz, 1.0);
|
||||||
|
|
||||||
@ -95,7 +89,7 @@ void main()
|
|||||||
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
||||||
#else
|
#else
|
||||||
vec3 diffuseLight, ambientLight;
|
vec3 diffuseLight, ambientLight;
|
||||||
doLighting(passViewPos, normalize(viewNormal), shadowing, diffuseLight, ambientLight);
|
doLighting(passViewPos, viewNormal, shadowing, diffuseLight, ambientLight);
|
||||||
lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + getEmissionColor().xyz;
|
lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + getEmissionColor().xyz;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -113,16 +107,13 @@ void main()
|
|||||||
|
|
||||||
if (matSpec != vec3(0.0))
|
if (matSpec != vec3(0.0))
|
||||||
{
|
{
|
||||||
#if (!@normalMap && !@parallax && !@forcePPL)
|
gl_FragData[0].xyz += getSpecular(viewNormal, normalize(passViewPos), shininess, matSpec) * shadowing;
|
||||||
vec3 viewNormal = gl_NormalMatrix * worldNormal;
|
|
||||||
#endif
|
|
||||||
gl_FragData[0].xyz += getSpecular(normalize(viewNormal), normalize(passViewPos), shininess, matSpec) * shadowing;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth);
|
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth);
|
||||||
|
|
||||||
#if !@disableNormals && @writeNormals
|
#if !@disableNormals && @writeNormals
|
||||||
gl_FragData[1].xyz = worldNormal.xyz * 0.5 + 0.5;
|
gl_FragData[1].xyz = viewNormal * 0.5 + 0.5;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
applyShadowDebugOverlay();
|
applyShadowDebugOverlay();
|
||||||
|
@ -360,7 +360,7 @@ void main(void)
|
|||||||
gl_FragData[0] = applyFogAtDist(gl_FragData[0], radialDepth, linearDepth);
|
gl_FragData[0] = applyFogAtDist(gl_FragData[0], radialDepth, linearDepth);
|
||||||
|
|
||||||
#if !@disableNormals
|
#if !@disableNormals
|
||||||
gl_FragData[1].rgb = normal * 0.5 + 0.5;
|
gl_FragData[1].rgb = normalize(gl_NormalMatrix * normal) * 0.5 + 0.5;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
applyShadowDebugOverlay();
|
applyShadowDebugOverlay();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user