Terrain editing brush indicator

#1

Hello! I’m currently working on a terrain editing tool, and i’d like to show a highlighted circle on the terrain at the location of the terrain brush, and i’m sooo close, but i can’t seem to figure out how to make it work like it should. Currently it looks like this

Here’s my fragment shader code:

#version 400 core

const vec4 brushColor = vec4(1.0, 0.0, 0.0, 1.0);

in vec2 v_TextureCoords;
in vec4 v_Position;

uniform sampler2D u_Texture;
uniform vec3 u_BrushPosition;
uniform float u_BrushRadius;

out vec4 out_Color;

void main()
{
  vec4 finalColor = texture(u_Texture, v_TextureCoords);
  vec3 toBrushVector = u_BrushPosition - v_Position.xyz;
  float distance = length(toBrushVector) / u_BrushRadius;

  out_Color = finalColor * (brushColor / distance);
}

v_Position is just the terrains “world” position (model matrix * vertex positions.
The problem is that while the radius around the brush is indeed red, all other colors are darkened, which obviously isn’t what i want.

Any help is appreciated!

1 Like
#2

So use something other than multiplication. E.g.

  out_Color = finalColor + (brushColor / distance);

or

  out_Color = mix(brushColor, finalColor, smoothstep(radius, radius+border, distance));

or whatever.

#3

That worked, I’m a bit new to GLSL, but thanks