Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Normal terrain quality water + fog, adjust blending #3693

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading