Reflector Sight (Red Dot)

a reflex sight shader that superimposes a given texture to a given distance to give a parallax effect. This shader also attempts to imitate the refresh rate of a reflex sight which can be toggled with the “flicker” flag.

Shader code
shader_type spatial;
render_mode blend_mix, cull_back, diffuse_burley, specular_schlick_ggx;

uniform sampler2D lens_texture : source_color;
uniform vec4 lens_color : source_color = vec4(0.0, 0.0, 0.0, .2);

uniform sampler2D retical_texture : source_color, repeat_disable;
uniform vec4 retical_color : source_color = vec4(1.0);
uniform float retical_size : hint_range(0.0, 100.0) = 0.0;
uniform bool flicker = false;
uniform float flicker_rate: hint_range(0, 60) = 60.0;
uniform float depth : hint_range(0.0, 100.0) = 10.0;
uniform float offset_x = 0.0;
uniform float offset_y = 0.0;
uniform float emission_strength: hint_range(0, 16) = .2;

varying vec2 offset;
varying vec2 lens_dir;

void vertex() {
	vec3 world_position = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
	vec3 view_dir = CAMERA_POSITION_WORLD - world_position;
	offset = VERTEX.xy - vec2(offset_x, offset_y);
	lens_dir = (inverse(MODEL_MATRIX) * vec4(view_dir, 0.0)).xz;
}

void fragment() {
	vec4 color = texture(lens_texture, UV) * lens_color;
	
	vec2 offset_uv = offset;
	offset_uv -= (lens_dir * depth);
	offset_uv /= (retical_size * depth);
	offset_uv += vec2(0.5);
	
	float retical_a = texture(retical_texture, offset_uv).a;
	float square_wave = max(0.1, sign(sin(TIME * flicker_rate * 2.0 * PI)));
	
	if (flicker) {
		retical_a *= square_wave;
	}

	color.rgb += retical_a * retical_color.rgb * retical_color.a;
	color.a += retical_a * retical_color.a;
	
	ALBEDO = color.rgb;
	ALPHA = color.a;
	EMISSION = retical_color.rgb * retical_a * emission_strength;
}
Tags
ADS, FPS, holographic, Red Dot, Reflector Sight, Scope, Sight
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

Holographic Sight Reticle

pixelated horror vignette dot-matrix downres

Subscribe
Notify of
guest

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Unhinged Dev
1 year ago

amazin

DJ_SIMULATOR
4 months ago

this looks really useful, thanks for the upload!

nattens
nattens
3 months ago

How do i use this ?