Skip to main content

The "vngen_set_shader_sampler" Function


vngen_set_shader_sampler(id, type, [name], uniform, source);
idreal/stringThe ID of the specific entity to modify
typeinteger/macroSets which type of entity to modify
[name]stringOptional: Sets the character name to check, if entity is an attachment
uniformstringSets the shader uniform to modify, as a string
sourcesprite/stringSets the sprite or surface to assign to the shader uniform (string required for surface)


When writing a shader, it can be useful to pass information from GML to the shader. Normally, shader variables are completely separate from GML and can't be modified externally, however it is possible to pass in variables called uniforms which are then referenced in shaders, allowing GML and shaders to communicate.

VNgen uses its own implementation of shaders on a per-entity basis. With this script, it is possible to assign a sprite or surface to a shader uniform defined within the shader itself. While it might seem strange, surfaces must be input as a string, not the associated variable itself, as this is the only way to differentiate between whether the intended source is a sprite or not.


Surfaces passed into shaders as samplers must be created and drawn to before vngen_object_draw is run.

Note that VNgen automatically passes in 5 default input values for handling fade transitions, global time, mouse and view coordinates, and the parent entity dimensions. These values are read-only and cannot be modified, but are very useful for designing shaders themselves.

They are:

uniform float in_Amount; //Transition percentage (0-1)
uniform float in_Time; //Seconds active
uniform vec2 in_Mouse; //X/Y
uniform vec2 in_Offset; //View X/Y
uniform vec2 in_Resolution; //Width/Height

Note the names and functions of these uniform values when supplying uniform names to be modified.


vngen_set_shader_sampler("bg", vngen_type_scene, "my_sampler", my_sprite);
vngen_set_shader_sampler("bg", vngen_type_scene, "my_sampler", "my_surf");