Shader

Shader Uniform Cheatsheet

Auto-inherited uniforms from the model's original material — no manual set_param needed

When a shader is applied to a model via shader:apply_to_material(...), Vital automatically reads the model surface's original BaseMaterial3D and feeds matching values into your shader uniforms. Name your uniforms to match the table below and they are populated for free. Any value you set manually via shader:set_param / shader:set_param_texture takes priority over the auto-bind.


Spatial

Textures

Uniform name (case-insensitive, partial match)Source slot
albedo_texture, diffuse_texture, basecolor_texture, base_color_textureAlbedo / Base Color
normal_textureNormal Map
rough_texture, roughness_textureRoughness
metal_texture, metallic_textureMetallic
emission_textureEmission
occlusion_texture, ao_texture, ambient_textureAmbient Occlusion

Any sampler2D uniform whose name contains one of the keywords above (e.g. my_albedo_tex) gets the matching texture automatically.

Scalars & Vectors

Uniform name (exact)TypeSource value
roughnessfloatBaseMaterial3D.roughness
metallicfloatBaseMaterial3D.metallic
specularfloatBaseMaterial3D.specular
normal_scalefloatBaseMaterial3D.normal_scale
emission_energyfloatBaseMaterial3D.emission_energy_multiplier
alpha_scissor_thresholdfloatBaseMaterial3D.alpha_scissor_threshold
uv1_scalevec3BaseMaterial3D.uv1_scale
uv1_offsetvec3BaseMaterial3D.uv1_offset

Colors

Declare as vec4, vec3, or Color — Vital coerces automatically.

Uniform name (exact)Source value
albedo_color, albedoBaseMaterial3D.albedo
emission, emission_colorBaseMaterial3D.emission

Channel Masks (ORM / packed textures)

Returns a vec4 dot-product mask for the channel Godot reads for each property. Useful with glTF ORM textures (ao=R, roughness=G, metallic=B).

Uniform name (exact)TypeExample value (green channel)
roughness_channelvec4vec4(0,1,0,0)
metallic_channelvec4vec4(0,0,1,0)
ao_channelvec4vec4(1,0,0,0)

Usage in shader:

uniform sampler2D orm_texture;
uniform vec4 roughness_channel;

void fragment() {
    float rough = dot(texture(orm_texture, UV), roughness_channel);
    ROUGHNESS = rough;
}

Canvas Item

Canvas Item shaders use a different pipeline — no BaseMaterial3D is involved. No uniforms are auto-inherited. Use shader:set_param / shader:set_param_texture to feed all values.


Priority

shader:set_param / shader:set_param_texture   ← always wins
        ↓ (only if above not set)
auto-bind from original surface material
        ↓ (only if no original material or no match)
uniform default value declared in GLSL

Example

Spatial shader using auto-inherited uniforms
local shader = core.shader.create_from_raw([[
    uniform sampler2D albedo_texture  : source_color, hint_default_white;
    uniform vec4      albedo_color    : source_color = vec4(1.0);
    uniform float     roughness       = 0.5;
    uniform float     metallic        = 0.0;
    uniform vec3      uv1_scale       = vec3(1.0);
    uniform vec3      uv1_offset      = vec3(0.0);

    void fragment() {
        vec2 uv   = UV * uv1_scale.xy + uv1_offset.xy;
        vec4 tex  = texture(albedo_texture, uv) * albedo_color;
        ALBEDO    = tex.rgb;
        ROUGHNESS = roughness;
        METALLIC  = metallic;
    }
]], core.shader.shader_mode.SPATIAL)

-- albedo_texture, roughness, metallic, uv1_scale, uv1_offset
-- are all pulled from the model's original material automatically.
shader:apply_to_material(my_model, "*", "*")

On this page