@spacecloud said:

@DJM said: - a triplanar 3 layer blend shader that blends textures based on red green and blue vertex colors(this is for my terrain meshes) each layer should support a color, roughness and normal map

thats just awesome! works perfectly, tnx! dont know how i can thank u. how long did it take u to write the shader? u want something in return?

what does the Orm parameter do? ive applied a packed map with AO in red, roughness in blue and metallic in green channel but it looks too shiny maybe im packing the channels wrong

You have blue and green swapped.

I also forgot to make AO and tinting do anything, so I updated it to fix that and also made it use better default values.

@DJM said: dont know how i can thank u. how long did it take u to write the shader?

I wrote most of it 2 months ago :)

@DJM said: u want something in return?

no.

@spacecloud said:

no.

ok, tnx anyway, exactly what i needed

a month later

@spacecloud the triplanar shader is broken in alpha 9 could i make a similar shader with the visual shader editor? i havent tried that feature yet

I updated the download with one that works with alpha 9.

You probably could, but i can't help with that.

@spacecloud tnx!

a month later

@spacecloud im getting this warning when using your triplanar shader
'(UNUSED_VARYING):The varying 'power_normal' is declared but never used.'

shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_schlick_ggx;
uniform float blend_sharpness = 1.0;
uniform float normal_scale = 1.0;

uniform vec3 texture1_scale = vec3(1.0);

uniform sampler2D texture1_albedo : source_color,filter_linear_mipmap,repeat_enable;
uniform sampler2D texture1_normal : hint_normal,filter_linear_mipmap,repeat_enable;
uniform sampler2D texture1_roughness : hint_roughness_gray,filter_linear_mipmap,repeat_enable;


uniform vec3 texture2_scale = vec3(1.0);

uniform sampler2D texture2_albedo : source_color,filter_linear_mipmap,repeat_enable;
uniform sampler2D texture2_normal : hint_roughness_normal,filter_linear_mipmap,repeat_enable;
uniform sampler2D texture2_roughness : hint_roughness_gray,filter_linear_mipmap,repeat_enable;


uniform vec3 texture3_scale = vec3(1.0);

uniform sampler2D texture3_albedo : source_color,filter_linear_mipmap,repeat_enable;
uniform sampler2D texture3_normal : hint_roughness_normal,filter_linear_mipmap,repeat_enable;
uniform sampler2D texture3_roughness : hint_roughness_gray,filter_linear_mipmap,repeat_enable;

varying vec3 power_normal;
varying vec3 triplanar_pos;
void vertex() {
	TANGENT = vec3(0.0,0.0,-1.0) * abs(NORMAL.x);
	TANGENT += vec3(1.0,0.0,0.0) * abs(NORMAL.y);
	TANGENT += vec3(1.0,0.0,0.0) * abs(NORMAL.z);
	TANGENT = normalize(TANGENT);
	BINORMAL = vec3(0.0,1.0,0.0) * abs(NORMAL.x);
	BINORMAL += vec3(0.0,0.0,-1.0) * abs(NORMAL.y);
	BINORMAL += vec3(0.0,1.0,0.0) * abs(NORMAL.z);
	BINORMAL = normalize(BINORMAL);
	power_normal = pow(abs(NORMAL),vec3(blend_sharpness));
	triplanar_pos = VERTEX;
	power_normal /= dot(power_normal,vec3(1.0));
	triplanar_pos *= vec3(1.0,-1.0, 1.0);
}
vec3 triplanar_texture(sampler2D p_sampler, vec3 p_triplanar_pos) {
	vec3 samp = vec3(0.0);
	samp += texture(p_sampler,p_triplanar_pos.xy).xyz * power_normal.z;
	samp += texture(p_sampler,p_triplanar_pos.xz).xyz * power_normal.y;
	samp += texture(p_sampler,p_triplanar_pos.zy * vec2(-1.0,1.0)).xyz * power_normal.x;
	return samp;
}

vec3 blend(vec3 texture1, vec3 texture2, vec3 texture3, vec4 color){
	return ((texture1 * color.r) + (texture2 * color.b) + (texture3 * color.g)).rgb;
}
void fragment() {
	vec3 albedo_texture = blend(triplanar_texture(texture1_albedo, triplanar_pos * texture1_scale), triplanar_texture(texture2_albedo, triplanar_pos * texture2_scale) , triplanar_texture(texture3_albedo, triplanar_pos * texture3_scale), COLOR);
	ALBEDO = albedo_texture.rgb;
	vec3 orm_texture = blend(triplanar_texture(texture1_roughness, triplanar_pos * texture1_scale), triplanar_texture(texture2_roughness, triplanar_pos * texture2_scale), triplanar_texture(texture3_roughness, triplanar_pos * texture3_scale), COLOR);
	AO = 1.0;
	ROUGHNESS = orm_texture.r;
	METALLIC = 0.0;
	NORMAL_MAP = blend(triplanar_texture(texture1_normal, triplanar_pos * texture1_scale), triplanar_texture(texture2_normal, triplanar_pos * texture2_scale), triplanar_texture(texture3_normal, triplanar_pos * texture3_scale), COLOR);
	NORMAL_MAP_DEPTH = normal_scale;
}

Honestly, that's an ignorable warning but I'd make sure you have no typos in your code that might cause it.

edit: it might be because you are reading it's components not the whole varying, i.e. the linter warning you is just a bit too dumb to deal with it. Ignorable warning.

  • DJM replied to this.

    That warning seems like a bug. The varying is clearly being written and read from. You might want to make an issue about it on Github.

    • DJM replied to this.

      spacecloud yes it is. weird.

      Megalomaniak yeah its not really an error and doesnt show strange results, ill ignore it.

      cybereality id rather make a bug report for my 'fake wind' shader i wrote.

      shader_type spatial;
      render_mode blend_mix, depth_prepass_alpha, cull_disabled, diffuse_burley, specular_schlick_ggx;
      uniform float alphatreshold;
      uniform float strenght : hint_range(0.0, 1.0, 0.05);
      uniform float speed : hint_range(0.0, 1.0, 0.1);
      
      uniform sampler2D colortex : source_color,filter_linear_mipmap,repeat_disable;
      uniform sampler2D normaltex :  hint_roughness_normal,filter_linear_mipmap,repeat_disable;
      uniform sampler2D roughnesstex : hint_roughness_gray,filter_linear_mipmap,repeat_disable;
      
      
      
      void vertex() {
      	
      	
      	
      	VERTEX.x += sin(TIME * speed + VERTEX.x + VERTEX.z ) * strenght * COLOR.g;
      	VERTEX.y += sin(TIME * speed + VERTEX.y + VERTEX.x ) * strenght * COLOR.g;
      	VERTEX.z += sin(TIME * speed + VERTEX.z + VERTEX.y ) * strenght * COLOR.g;
      
      }
      
      void fragment() {
      	// Place fragment code here.
      	ALPHA = texture(colortex,UV).a;
      	ALPHA_SCISSOR_THRESHOLD = alphatreshold;
      	ALBEDO= texture(colortex,UV).rgb;
      	NORMAL_MAP = texture(normaltex,UV).rgb;
      	SPECULAR = 0.5;
      	ROUGHNESS = texture(roughnesstex,UV).r;
      	
      }

      if i use this shader the editor becomes extremely slow. it also doesnt give the correct results. but it also might be my shader code is wrong

      spacecloud how do i add an overall 'detail normal map' and a a black and white multiply 'detail color' to the complete triplanar material with its own scale?

      Pre PBS the black and white detail map would just get multiplied over the diffuse, nowadays you might do that in albedo, but I'd recommend to multiply or multiply-add it to the roughness instead. If you feel the effect is too weak then maybe consider also albedo.

      Mixing normals is a bit more delicate and don't forget to normalize the result at the end. You might find some glsl examples via google, for an example on shadertoy.com

      i did it!!!
      @Megalomaniak tnx for your shadertoy suggestion!
      heres the shader if anybody is interested, u will need a mesh with painted vertex colors red green and blue
      , works in godot4 , dont know if it will work in godot3

      shader_type spatial;
      render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_schlick_ggx;
      uniform float blend_sharpness = 1.0;
      uniform float normal_scale = 1.0;
      
      uniform vec3 texture1_scale = vec3(1.0);
      
      uniform sampler2D texture1_albedo : source_color,filter_linear_mipmap,repeat_enable;
      uniform sampler2D texture1_normal : hint_normal,filter_linear_mipmap,repeat_enable;
      uniform sampler2D texture1_roughness : hint_roughness_gray,filter_linear_mipmap,repeat_enable;
      
      
      uniform vec3 texture2_scale = vec3(1.0);
      
      uniform sampler2D texture2_albedo : source_color,filter_linear_mipmap,repeat_enable;
      uniform sampler2D texture2_normal : hint_roughness_normal,filter_linear_mipmap,repeat_enable;
      uniform sampler2D texture2_roughness : hint_roughness_gray,filter_linear_mipmap,repeat_enable;
      
      
      uniform vec3 texture3_scale = vec3(1.0);
      
      uniform sampler2D texture3_albedo : source_color,filter_linear_mipmap,repeat_enable;
      uniform sampler2D texture3_normal : hint_roughness_normal,filter_linear_mipmap,repeat_enable;
      uniform sampler2D texture3_roughness : hint_roughness_gray,filter_linear_mipmap,repeat_enable;
      
      uniform sampler2D detailtexture : hint_roughness_gray,filter_linear_mipmap,repeat_enable;
      uniform sampler2D detailroughness : hint_roughness_gray,filter_linear_mipmap,repeat_enable;
      uniform sampler2D detailnormal : hint_roughness_normal,filter_linear_mipmap,repeat_enable;
      
      uniform vec3 detail_scale = vec3(1.0);
      varying vec3 power_normal;
      varying vec3 triplanar_pos;
      void vertex() {
      	TANGENT = vec3(0.0,0.0,-1.0) * abs(NORMAL.x);
      	TANGENT += vec3(1.0,0.0,0.0) * abs(NORMAL.y);
      	TANGENT += vec3(1.0,0.0,0.0) * abs(NORMAL.z);
      	TANGENT = normalize(TANGENT);
      	BINORMAL = vec3(0.0,1.0,0.0) * abs(NORMAL.x);
      	BINORMAL += vec3(0.0,0.0,-1.0) * abs(NORMAL.y);
      	BINORMAL += vec3(0.0,1.0,0.0) * abs(NORMAL.z);
      	BINORMAL = normalize(BINORMAL);
      	power_normal = pow(abs(NORMAL),vec3(blend_sharpness));
      	triplanar_pos = VERTEX;
      	power_normal /= dot(power_normal,vec3(1.0));
      	triplanar_pos *= vec3(1.0,-1.0, 1.0);
      }
      vec3 triplanar_texture(sampler2D p_sampler, vec3 p_triplanar_pos) {
      	vec3 samp = vec3(0.0);
      	samp += texture(p_sampler,p_triplanar_pos.xy).xyz * power_normal.z;
      	samp += texture(p_sampler,p_triplanar_pos.xz).xyz * power_normal.y;
      	samp += texture(p_sampler,p_triplanar_pos.zy * vec2(-1.0,1.0)).xyz * power_normal.x;
      	return samp;
      }
      
      vec3 blend(vec3 texture1, vec3 texture2, vec3 texture3, vec4 color){
      	return ((texture1 * color.r) + (texture2 * color.b) + (texture3 * color.g)).rgb;
      }
      vec3 normalblend(vec3 n1, vec3 n2)
      {
      	n1 += vec3(0, 0, 1);
      	n2 *= vec3(-1, -1, 1);
      	
          return normalize(n1*dot(n1, n2)/n1.z - n2);
      }
      void fragment() {
      	vec3 albedo_texture = (blend(triplanar_texture(texture1_albedo, triplanar_pos * texture1_scale), triplanar_texture(texture2_albedo, triplanar_pos * texture2_scale) , triplanar_texture(texture3_albedo, triplanar_pos * texture3_scale), COLOR)) * triplanar_texture(detailtexture, triplanar_pos * detail_scale);
      	ALBEDO = albedo_texture.rgb;
      	vec3 orm_texture = (blend(triplanar_texture(texture1_roughness, triplanar_pos * texture1_scale), triplanar_texture(texture2_roughness, triplanar_pos * texture2_scale), triplanar_texture(texture3_roughness, triplanar_pos * texture3_scale), COLOR))* triplanar_texture(detailroughness, triplanar_pos * detail_scale);
      	AO = 1.0;
      	ROUGHNESS = orm_texture.r;
      	METALLIC = 0.0;
      	NORMAL_MAP = normalblend(blend(triplanar_texture(texture1_normal, triplanar_pos * texture1_scale), triplanar_texture(texture2_normal, triplanar_pos * texture2_scale), triplanar_texture(texture3_normal, triplanar_pos * texture3_scale), COLOR),triplanar_texture(detailnormal, triplanar_pos * detail_scale));
      	NORMAL_MAP_DEPTH = normal_scale;
      }

        nope i was wrong, the base triplanar normal seems to be inverted on some places

        Megalomaniak
        to difficult for me to really understand the normal blending. i simply messed around with an example on shadertoy.
        strange thing is that it works correctly on specific axises and others dont.

        did some tests, my normal blend code is correct i think, somehow the triplanar sampling gets messed up