adspartan: Fix cursor plane not visible underwater by rendering it before the water and making it write to the depth buffer, add checker board pattern to be able to see the water under it still

95092f992b
This commit is contained in:
T1ti
2024-09-01 05:09:58 +02:00
parent 6211c578eb
commit 934a0a4000
4 changed files with 77 additions and 56 deletions

View File

@@ -921,6 +921,65 @@ void WorldRender::draw (glm::mat4x4 const& model_view
gl.enable(GL_BLEND);
gl.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// render before the water and enable depth right
// so it's visible under water
// the checker board pattern is used to see the water under it
if (angled_mode || use_ref_pos)
{
ZoneScopedN("World::draw() : Draw angles");
// OpenGL::Scoped::bool_setter<GL_CULL_FACE, GL_FALSE> cull;
OpenGL::Scoped::depth_mask_setter<GL_TRUE> const depth_mask;
math::degrees orient = math::degrees(orientation);
math::degrees incl = math::degrees(angle);
glm::vec4 color = cursor_color;
// color.w = 0.5f;
color.w = 0.75f;
float radius = 1.2f * brush_radius;
if (angled_mode && terrainMode == editing_mode::flatten_blur)
{
if (angle > 49.0f) // 0.855 radian
{
color.x = 1.f;
color.y = 0.f;
color.z = 0.f;
}
}
if (angled_mode && !use_ref_pos)
{
glm::vec3 pos = cursor_pos;
pos.y += 0.1f; // to avoid z-fighting with the ground
_square_render.draw(mvp, pos, radius, incl, orient, color);
}
else if (use_ref_pos)
{
if (angled_mode)
{
glm::vec3 pos = cursor_pos;
pos.y = misc::angledHeight(ref_pos, pos, incl, orient);
pos.y += 0.1f;
_square_render.draw(mvp, pos, radius, incl, orient, color);
// display the plane when the cursor is far from ref_point
if (misc::dist(pos.x, pos.z, ref_pos.x, ref_pos.z) > 10.f + radius)
{
glm::vec3 ref = ref_pos;
ref.y += 0.1f;
_square_render.draw(mvp, ref, 10.f, incl, orient, color);
}
}
else
{
glm::vec3 pos = cursor_pos;
pos.y = ref_pos.y + 0.1f;
_square_render.draw(mvp, pos, radius, math::degrees(0.f), math::degrees(0.f), color);
}
}
}
if (draw_water)
{
ZoneScopedN("World::draw() : Draw water");
@@ -959,62 +1018,6 @@ void WorldRender::draw (glm::mat4x4 const& model_view
gl.bindVertexArray(0);
}
if (angled_mode || use_ref_pos)
{
ZoneScopedN("World::draw() : Draw angles");
OpenGL::Scoped::bool_setter<GL_CULL_FACE, GL_FALSE> cull;
OpenGL::Scoped::depth_mask_setter<GL_FALSE> const depth_mask;
math::degrees orient = math::degrees(orientation);
math::degrees incl = math::degrees(angle);
glm::vec4 color = cursor_color;
// always half transparent regardless or the cursor transparency
color.w = 0.5f;
float radius = 1.2f * brush_radius;
if (angled_mode && terrainMode == editing_mode::flatten_blur)
{
if (angle > 49.0f) // 0.855 radian
{
color.x = 1.f;
color.y = 0.f;
color.z = 0.f;
}
}
if (angled_mode && !use_ref_pos)
{
glm::vec3 pos = cursor_pos;
pos.y += 0.1f; // to avoid z-fighting with the ground
_square_render.draw(mvp, pos, radius, incl, orient, color);
}
else if (use_ref_pos)
{
if (angled_mode)
{
glm::vec3 pos = cursor_pos;
pos.y = misc::angledHeight(ref_pos, pos, incl, orient);
pos.y += 0.1f;
_square_render.draw(mvp, pos, radius, incl, orient, color);
// display the plane when the cursor is far from ref_point
if (misc::dist(pos.x, pos.z, ref_pos.x, ref_pos.z) > 10.f + radius)
{
glm::vec3 ref = ref_pos;
ref.y += 0.1f;
_square_render.draw(mvp, ref, 10.f, incl, orient, color);
}
}
else
{
glm::vec3 pos = cursor_pos;
pos.y = ref_pos.y + 0.1f;
_square_render.draw(mvp, pos, radius, math::degrees(0.f), math::degrees(0.f), color);
}
}
}
gl.enable(GL_BLEND);
// draw last because of the transparency

View File

@@ -6,5 +6,9 @@ out vec4 out_color;
void main()
{
if(gl_FragCoord.x < 0.5)
{
discard;
}
out_color = color;
}

View File

@@ -2,9 +2,19 @@
uniform vec4 color;
in vec3 f_pos;
out vec4 out_color;
void main()
{
bool discard_x = mod((f_pos.x + 1.) * 5., 2.) < 1.;
bool discard_y = mod((f_pos.z + 1.) * 5., 2.) < 1.;
// discard in a checker board pattern
if(discard_x != discard_y)
{
discard;
}
out_color = color;
}

View File

@@ -2,6 +2,8 @@
in vec4 position;
out vec3 f_pos;
uniform mat4 model_view_projection;
uniform vec3 origin;
uniform float radius;
@@ -21,4 +23,6 @@ void main()
pos.xyz += origin;
gl_Position = model_view_projection * pos;
f_pos = position.xyz;
}