Fixed size points vs world scale points.
A quick Godot shader to render mesh points at world scale instead of at a fixed size.
Shader Code Download
shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_schlick_ggx, unshaded;
uniform vec4 albedo : source_color;
uniform sampler2D texture_albedo : source_color, filter_linear_mipmap, repeat_enable;
uniform float point_size : hint_range(0.1, 128.0, 0.1);
uniform float roughness : hint_range(0.0, 1.0);
uniform sampler2D texture_metallic : hint_default_white, filter_linear_mipmap, repeat_enable;
uniform vec4 metallic_texture_channel;
uniform sampler2D texture_roughness : hint_roughness_r, filter_linear_mipmap, repeat_enable;
uniform float specular : hint_range(0.0, 1.0, 0.01);
uniform float metallic : hint_range(0.0, 1.0, 0.01);
uniform vec3 uv1_scale = vec3(1.0, 1.0, 1.0);
uniform vec3 uv1_offset;
void vertex() {
// https://godotforums.org/d/42124-adjust-point-size-in-point-mesh-in-inverse-relation-to-distance-to-camera
// https://godotshaders.com/shader/how-to-get-vertical-camera-fov/
float fov_y = atan(-1.0 / PROJECTION_MATRIX[1][1]) * 2.0;
// https://gamedev.stackexchange.com/a/54492
float vertex_distance_camera_plane = (MODELVIEW_MATRIX * vec4(VERTEX, 1.0)).z * -1.0;
float world_point_size = point_size;
float near_plane_height = VIEWPORT_SIZE.y / (2.0 * tan(0.5 * fov_y));
POINT_SIZE = (near_plane_height * world_point_size) / vertex_distance_camera_plane;
UV = UV * uv1_scale.xy + uv1_offset.xy;
}
void fragment() {
vec2 base_uv = UV;
// Use Point Size: Enabled
vec4 albedo_tex = texture(texture_albedo, POINT_COORD);
// Vertex Color Use as Albedo: Enabled
albedo_tex *= COLOR;
ALBEDO = albedo.rgb * albedo_tex.rgb;
float metallic_tex = dot(texture(texture_metallic, base_uv), metallic_texture_channel);
METALLIC = metallic_tex * metallic;
SPECULAR = specular;
vec4 roughness_texture_channel = vec4(1.0, 0.0, 0.0, 0.0);
float roughness_tex = dot(texture(texture_roughness, base_uv), roughness_texture_channel);
ROUGHNESS = roughness_tex * roughness;
ALPHA *= albedo.a * albedo_tex.a;
ALPHA_SCISSOR_THRESHOLD = 0.8;
}
License: Zero-Clause BSD
