+1 vote

I have a Object.TSCN containing a MeshInstance with a ShaderMaterial attached. The GDScript for the Object.TSCN looks like this:

extends Node

export(float) var a 0.0
export(float) var b = 0.0

func _ready():
    x.set_shader_param('a', a)
    x.set_shader_param('b', b)

The ShaderMaterial looks like this:

shader_type spatial;
render_mode blend_mix;

uniform float a : hint_range(0,1) = 0.5;
uniform float b : hint_range(0,1) = 0.5;

void fragment() {
    ALBEDO = vec3(0, 0, 0);
    ALBEDO += vec3(1.0 * a, 0.0, 0.0);
    ALBEDO += vec3(0.0, 1.0 * b, 0.0);
    ROUGHNESS = 1.0;
    SPECULAR = 0.0;

When I now use the editor to add two instances of Object.TSCN to my MainScene.TSCN and set the values of the first instance to a=0, b=1 and of the second to a=1,b=0 both ShaderMaterial will have their a=1 and b=0.

What do I need to do so two instances of the same TSCN can have independent shader parameters?

Godot version v3.2.3.flathub.stable
in Engine by (17 points)

1 Answer

+1 vote

Open Material in Editor and set "Resource/Local To Scene" to "On".
From documentation:
If true, the resource will be made unique in each instance of its local scene. It can thus be modified in a scene instance without impacting other instances of that same scene.

by (1,646 points)
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 Frequently asked questions and 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 [email protected] with your username.