- Edited
Hello wonderful Godot community! I have been trying to make a terrain for my game made the mesh separated into chunks, Wrote a little LOD script and so on. But came across a problem when I was writing a shader for my terrain. I'm using the splat map method and mixing different sets of textures, preferably I want to mix Albedo, Normal and Roughness. But have a problem doing that with Roughness maps.
Here's the code example to make things more clear:
shader_type spatial; render_mode cull_disabled; uniform sampler2D splatmap; uniform sampler2D tex_base; uniform sampler2D tex_r; uniform sampler2D tex_g; uniform sampler2D tex_b; uniform sampler2D tex_a; uniform sampler2D norm_base; uniform sampler2D norm_r; uniform sampler2D norm_g; uniform sampler2D norm_b; uniform sampler2D norm_a; uniform sampler2D rough_base; uniform sampler2D rough_r; uniform sampler2D rough_g; uniform sampler2D rough_b; uniform sampler2D rough_a; uniform float base_res = 5; uniform float r_res = 5; uniform float g_res = 5; uniform float b_res = 5; uniform float a_res = 5; void fragment() { vec3 base_col; vec3 r_col; vec3 g_col; vec3 b_col; vec3 a_col; vec3 base_norm; vec3 r_norm; vec3 g_norm; vec3 b_norm; vec3 a_norm; vec3 base_rough; vec3 r_rough; vec3 g_rough; vec3 b_rough; vec3 a_rough; vec4 texs=texture(splatmap,UV); float rval = texs.r; float gval = texs.g; float bval = texs.b; float aval = 1.0-texs.a; float baseval = max(0.0,1.0-(rval+gval+bval+aval)); base_col = texture(tex_base,UV*base_res).rgb * baseval; r_col = texture(tex_r,UV*r_res).rgb * rval; g_col = texture(tex_g,UV*g_res).rgb * gval; b_col = texture(tex_b,UV*b_res).rgb * bval; a_col = texture(tex_a,UV*a_res).rgb * aval; ALBEDO = base_col + r_col + g_col + b_col + a_col; base_norm = texture(norm_base,UV*base_res).rgb * baseval; r_norm = texture(norm_r,UV*r_res).rgb * rval; g_norm = texture(norm_g,UV*g_res).rgb * gval; b_norm = texture(norm_b,UV*b_res).rgb * bval; a_norm = texture(norm_a,UV*a_res).rgb * aval; NORMALMAP = base_norm + r_norm + g_norm + b_norm + a_norm; base_rough = texture(rough_base,UV*base_res).rgb * baseval; r_rough = texture(rough_r,UV*r_res).rgb * rval; g_rough = texture(rough_g,UV*g_res).rgb * gval; b_rough = texture(rough_b,UV*b_res).rgb * bval; a_rough = texture(rough_a,UV*a_res).rgb * aval; ROUGHNESS = base_rough + r_rough + g_rough + b_rough + a_rough; }
naturally upon running the code I get an error:
:81 - Invalid arguments to operator '=' :float and vec3
Is there a way to mix roughness maps or I can only use a float value in the code? Which will basically assign the same value for every different texture set and will kill the whole point of using splat maps in a way... If someone has an answer to this please let me know...
If I remove the roughness part and only retain a line something like ROUGHNESS = 0.5 it will run perfectly, but it's a float value for all the texture which kills the whole look to be honest.