Skip to content

Instantly share code, notes, and snippets.

@TheBigRoomXXL
Created June 17, 2024 15:11
Show Gist options
  • Save TheBigRoomXXL/5ae4b414aaf6e36779ded2c73f8cafb1 to your computer and use it in GitHub Desktop.
Save TheBigRoomXXL/5ae4b414aaf6e36779ded2c73f8cafb1 to your computer and use it in GitHub Desktop.
// language=GLSL
const VERTEX_SHADER_SOURCE = /*glsl*/ `
attribute vec4 a_id;
attribute vec4 a_color;
attribute vec2 a_position;
attribute float a_size;
attribute float a_angle;
attribute vec4 a_texture;
attribute float a_texture_index;
uniform mat3 u_matrix;
uniform float u_sizeRatio;
uniform float u_correctionRatio;
varying vec4 v_color;
varying vec2 v_diffVector;
varying float v_radius;
varying vec4 v_texture;
varying float v_texture_index;
const float bias = 255.0 / 254.0;
const float marginRatio = 1.05;
void main() {
float size = a_size * u_correctionRatio / u_sizeRatio * 4.0;
vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle));
vec2 position = a_position + diffVector * marginRatio;
gl_Position = vec4(
(u_matrix * vec3(position, 1)).xy,
0,
1
);
v_diffVector = diffVector;
v_radius = size / 2.0 / marginRatio;
#ifdef PICKING_MODE
// For picking mode, we use the ID as the color:
v_color = a_id;
#else
// For normal mode, we use the color:
v_color = a_color;
// Pass the texture coordinates:
v_texture = a_texture;
v_texture_index = a_texture_index;
#endif
v_color.a *= bias;
}
`;
export default VERTEX_SHADER_SOURCE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment