Is it possible to MAKE a shader in script?

Godot Version

4.X

Question

Is it possible to MAKE a shader using script only (i.e. not from a shader file)??

For example say I have the shader code as a string variable.

How do I let godot know this variable is shader script so I can load it as a canvas shader on to my sprite without explicitly making a shader file?

Is this even possible?

Yes

var shader_material := ShaderMaterial.new()
shader_material.shader.code = """shader_type canvas_item;
render_mode skip_vertex_transform;

void vertex() {

    VERTEX = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy;
}
"""

material_override = shader_material

Thanks!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.