Fix visible square behind sun by switching celestial to additive blending

Alpha blending caused faint quad edges to be visible against the sky
gradient. Additive blending correctly adds glow light without the
outline artifact. Edge fade starts earlier and discard threshold raised.
This commit is contained in:
Kelsi 2026-02-23 07:40:51 -08:00
parent 59f487c941
commit 83d7f26f33
3 changed files with 7 additions and 6 deletions

View file

@ -37,8 +37,8 @@ void main() {
// Combine disc and glow // Combine disc and glow
float alpha = max(disc, glow) * push.intensity; float alpha = max(disc, glow) * push.intensity;
// Fade to zero at quad edges to prevent visible box // Fade to zero well before quad edges
float edgeFade = 1.0 - smoothstep(0.4, 0.5, dist); float edgeFade = 1.0 - smoothstep(0.35, 0.48, dist);
alpha *= edgeFade; alpha *= edgeFade;
vec3 color = push.celestialColor.rgb; vec3 color = push.celestialColor.rgb;
@ -56,6 +56,7 @@ void main() {
float phaseShadow = smoothstep(-0.1, 0.1, phaseX); float phaseShadow = smoothstep(-0.1, 0.1, phaseX);
alpha *= mix(phaseShadow, 1.0, step(0.5, push.intensity)); alpha *= mix(phaseShadow, 1.0, step(0.5, push.intensity));
if (alpha < 0.001) discard; if (alpha < 0.003) discard;
outColor = vec4(color, alpha); // Pre-multiply for additive blending: RGB is the light contribution
outColor = vec4(color * alpha, alpha);
} }

Binary file not shown.

View file

@ -85,7 +85,7 @@ bool Celestial::initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout)
.setTopology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST) .setTopology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
.setRasterization(VK_POLYGON_MODE_FILL, VK_CULL_MODE_NONE) .setRasterization(VK_POLYGON_MODE_FILL, VK_CULL_MODE_NONE)
.setDepthTest(true, false, VK_COMPARE_OP_LESS_OR_EQUAL) // test on, write off (sky layer) .setDepthTest(true, false, VK_COMPARE_OP_LESS_OR_EQUAL) // test on, write off (sky layer)
.setColorBlendAttachment(PipelineBuilder::blendAlpha()) .setColorBlendAttachment(PipelineBuilder::blendAdditive())
.setMultisample(vkCtx_->getMsaaSamples()) .setMultisample(vkCtx_->getMsaaSamples())
.setLayout(pipelineLayout_) .setLayout(pipelineLayout_)
.setRenderPass(vkCtx_->getImGuiRenderPass()) .setRenderPass(vkCtx_->getImGuiRenderPass())
@ -157,7 +157,7 @@ void Celestial::recreatePipelines() {
.setTopology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST) .setTopology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
.setRasterization(VK_POLYGON_MODE_FILL, VK_CULL_MODE_NONE) .setRasterization(VK_POLYGON_MODE_FILL, VK_CULL_MODE_NONE)
.setDepthTest(true, false, VK_COMPARE_OP_LESS_OR_EQUAL) .setDepthTest(true, false, VK_COMPARE_OP_LESS_OR_EQUAL)
.setColorBlendAttachment(PipelineBuilder::blendAlpha()) .setColorBlendAttachment(PipelineBuilder::blendAdditive())
.setMultisample(vkCtx_->getMsaaSamples()) .setMultisample(vkCtx_->getMsaaSamples())
.setLayout(pipelineLayout_) .setLayout(pipelineLayout_)
.setRenderPass(vkCtx_->getImGuiRenderPass()) .setRenderPass(vkCtx_->getImGuiRenderPass())