Fix moon blending (#6439)

This commit is contained in:
Alexei Kotov
2026-03-20 00:40:44 +03:00
parent 663ae0fd77
commit 68adb8dbec
2 changed files with 21 additions and 2 deletions
+2
View File
@@ -348,6 +348,8 @@ namespace MWRender
stateset->addUniform(new osg::Uniform("atmosphereFade", osg::Vec4f{}));
stateset->addUniform(new osg::Uniform("diffuseMap", 0));
stateset->addUniform(new osg::Uniform("maskMap", 1));
stateset->setAttributeAndModes(new osg::BlendFunc(osg::BlendFunc::ONE, osg::BlendFunc::ONE_MINUS_SRC_ALPHA),
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
stateset->setAttributeAndModes(
createUnlitMaterial(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
}
+19 -2
View File
@@ -39,8 +39,25 @@ void paintMoon(inout vec4 color)
vec4 phase = texture2D(diffuseMap, diffuseMapUV);
vec4 mask = texture2D(maskMap, diffuseMapUV);
vec4 blendedLayer = phase * moonBlend;
color = vec4(blendedLayer.xyz + atmosphereFade.xyz, atmosphereFade.a * mask.a);
// Morrowind does this in two passes
// First pass: moon shadow, normal blending (src alpha, 1 - src alpha)
// dst.rgb = mask.rgb * mask.a + dst.rgb * (1 - mask.a)
// Second pass: moon phase, additive blending (src alpha, 1)
// dst.rgb += phase.rgb * phase.a
// The same is doable in a single pass through premultiplied alpha blending
// color.rgb = mask.rgb * mask.a + phase.rgb * phase.a
// color.a = mask.a
// dst.rgb = color.rgb + dst.rgb * (1 - color.a)
vec3 maskTinted = mask.rgb * atmosphereFade.rgb;
float maskAlpha = mask.a * atmosphereFade.a;
vec3 phaseTinted = phase.rgb * moonBlend.rgb;
float phaseAlpha = phase.a * atmosphereFade.a;
color.rgb = maskTinted * maskAlpha + phaseTinted * phaseAlpha;
color.a = maskAlpha;
}
void paintSun(inout vec4 color)