Set albedo of shaderMaterial from code

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By TobiLa

Hi,

what I’m trying right now in my mesh node in Godot 3.0.6 stable:

export(Color, RGBA) var albedo setget setAlbedo
var meshNode # this is set correctly in my code based on my tree structure, 
             # not relevant here

func setAlbedo(newAlbedo):
	
	for i in range(meshNode.get_surface_count()):
		var material = meshNode.surface_get_material(i)
		material.set_shader_param("Albedo", newAlbedo)
	albedo = newAlbedo

My shader code is the default shader code when converting a spatial material to shader material:

shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
uniform vec4 albedo : hint_color;
uniform sampler2D texture_albedo : hint_albedo;
uniform float specular;
uniform float metallic;
uniform float roughness : hint_range(0,1);
uniform float point_size : hint_range(0,128);
uniform sampler2D texture_metallic : hint_white;
uniform vec4 metallic_texture_channel;
uniform sampler2D texture_roughness : hint_white;
uniform vec4 roughness_texture_channel;
uniform vec3 uv1_scale;
uniform vec3 uv1_offset;
uniform vec3 uv2_scale;
uniform vec3 uv2_offset;


void vertex() {
	UV=UV*uv1_scale.xy+uv1_offset.xy;
}




void fragment() {
	vec2 base_uv = UV;
	vec4 albedo_tex = texture(texture_albedo,base_uv);
	ALBEDO = albedo.rgb * albedo_tex.rgb;
	float metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel);
	METALLIC = metallic_tex * metallic;
	float roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel);
	ROUGHNESS = roughness_tex * roughness;
	SPECULAR = specular;
}

But it has no effect, weirldy I get no error messages.
Thanks in advance,
Tobi

:bust_in_silhouette: Reply From: TobiLa

Found my stupid mistake:

material.set_shader_param("Albedo", newAlbedo)

should be

material.set_shader_param("albedo", newAlbedo)

This may have changed to “albedo_color” now. It has for Spatial Materials.

Satscape | 2021-09-23 00:21

what will be the source code for godot version 4.x ?