Skip to content

Commit

Permalink
Fix: Normal terrain quality water + fog, adjust blending
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Mar 18, 2024
1 parent 748df17 commit 715d12d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
11 changes: 8 additions & 3 deletions data/base/shaders/vk/water.frag
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ void main()
{
// Calculate linear fog
float fogFactor = (fogEnd - vertexDistance) / (fogEnd - fogStart);
fogFactor = clamp(fogFactor, 0.0, 1.0);

// Return fragment color
fragColor = mix(fragColor, fogColor, fogFactor);
if (fogFactor >= 1.f)
{
discard;
}

fogFactor = 1.0 - clamp(fogFactor, 0.0, 1.0);
fragColor.rgb *= fogFactor; // premultiply by fogFactor as alpha
fragColor.a = fogFactor;
}

FragColor = fragColor;
Expand Down
11 changes: 8 additions & 3 deletions data/base/shaders/water.frag
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ void main()
{
// Calculate linear fog
float fogFactor = (fogEnd - vertexDistance) / (fogEnd - fogStart);
fogFactor = clamp(fogFactor, 0.0, 1.0);

// Return fragment color
fragColor = mix(fragColor, fogColor, fogFactor);
if (fogFactor >= 1.f)
{
discard;
}

fogFactor = 1.0 - clamp(fogFactor, 0.0, 1.0);
fragColor.rgb *= fogFactor; // premultiply by fogFactor as alpha
fragColor.a = fogFactor;
}

FragColor = fragColor;
Expand Down
2 changes: 1 addition & 1 deletion lib/ivis_opengl/gfx_api_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ void gl_pipeline_state_object::bind()

case REND_MULTIPLICATIVE:
glEnable(GL_BLEND);
glBlendFunc(GL_ZERO, GL_SRC_COLOR);
glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
break;

case REND_PREMULTIPLIED:
Expand Down
6 changes: 3 additions & 3 deletions lib/ivis_opengl/gfx_api_vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,9 +1279,9 @@ std::array<vk::PipelineColorBlendAttachmentState, 1> VkPSO::to_vk(const REND_MOD
.setBlendEnable(true)
.setColorBlendOp(vk::BlendOp::eAdd)
.setAlphaBlendOp(vk::BlendOp::eAdd)
.setSrcColorBlendFactor(vk::BlendFactor::eZero)
.setSrcAlphaBlendFactor(vk::BlendFactor::eZero)
.setDstColorBlendFactor(vk::BlendFactor::eSrcColor)
.setSrcColorBlendFactor(vk::BlendFactor::eDstColor)
.setSrcAlphaBlendFactor(vk::BlendFactor::eDstAlpha)
.setDstColorBlendFactor(vk::BlendFactor::eOneMinusSrcAlpha)
.setDstAlphaBlendFactor(vk::BlendFactor::eOneMinusSrcAlpha)
.setColorWriteMask(vk_color_mask)
};
Expand Down

0 comments on commit 715d12d

Please sign in to comment.