+2 votes

How can I load a shader file using script, just like we do it in the editor?

shader load

in Engine by (40 points)

1 Answer

+7 votes
Best answer

The shader file is a resource so you can load it like any resource.
http://docs.godotengine.org/en/latest/getting_started/step_by_step/resources.html#creating-your-own-resources

Once you have the resource you just assign it like this:

onready var WaterShader = preload("res://Water.shader")

func _ready():
    self.material.shader = WaterShader

Hope this helps

by (1,445 points)
selected by

Thank you that worked

how can you access the material in 3d?

to supplement MysteryGM's answer:

onready var WaterShader = preload("res://Water.shader")

func _ready():
    some_sprite_node.material = ShaderMaterial.new()
    some_sprite_node.material.shader = WaterShader
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.