simple static shader optimized for lowpoly game

It is just a simple shader, I frequently use, it is low power demanding, and lightweight. That’s all.

Shader code
shader_type spatial;

// Shading model and render settings
render_mode blend_mix, unshaded, cull_disabled, diffuse_burley, depth_prepass_alpha;

// Base material properties
uniform vec4 albedo : source_color;
uniform sampler2D texture_albedo : source_color, filter_linear_mipmap, repeat_enable;

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);

// Normal mapping
uniform sampler2D texture_normal : hint_normal, filter_linear_mipmap, repeat_enable;
uniform float normal_scale : hint_range(0.0, 2.0) = 1.0;

// Distance fade settings
uniform bool enable_fade = false; // Toggle for enabling/disabling fade effect
uniform float fade_start_distance : hint_range(0.0, 200.0) = 50.0; // Distance at which fading starts
uniform float fade_length : hint_range(1.0, 50.0) = 20.0; // Distance over which fading occurs

void fragment() {
    vec2 base_uv = UV;

    // Sample textures
    vec4 albedo_tex = texture(texture_albedo, base_uv);
    float metallic_tex = dot(texture(texture_metallic, base_uv), metallic_texture_channel);
    float roughness_tex = texture(texture_roughness, base_uv).r;

    // Compute base material properties
    ALBEDO = albedo.rgb * albedo_tex.rgb;
    METALLIC = metallic_tex * metallic;
    SPECULAR = specular;
    ROUGHNESS = roughness_tex * roughness;

    // Normal mapping
    vec3 normal_map = texture(texture_normal, base_uv).rgb * 2.0 - 1.0;
    normal_map.xy *= normal_scale;
    NORMAL_MAP = normal_map;

    // Compute fade effect only if enabled
    float fade = 1.0; // Default fully visible
    if (enable_fade) {
        float dist = length(VERTEX);
        fade = clamp(1.0 - (dist - fade_start_distance) / fade_length, 0.0, 1.0);
    }

    // Apply fading to alpha
    ALPHA = albedo.a * albedo_tex.a * fade;
}
Tags
simple shader.
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from buddhanomad

Godot 4 Shader: Dual-Channel Overlay Effect for Dynamic Texturing

vertex paint controlled simple 3D wind sway shader

godot4 5 layer splatmap shader for terrain or something..

Related shaders

CRT Shader for 3D game

3D simple animated flag shader

vertex paint controlled simple 3D wind sway shader

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments