0 votes

I have no experience with shaders but I'm trying to achieve texturing an object based on the direction of the faces. I did something similar in blender but since most of the nodes are either named differently it's hard making any progress

in Engine by (161 points)

did you know that the spatial shader has an option for triplanar texturing?

... or do you want to have different textures for different orientations?

No just the different colours...what's the node and how do I use it tho

1 Answer

0 votes

i assume you want to use visual shaders. But i dont know a lot about the nodes.

But i can give you a glsl shader wich isnt to hard to modify

The base of the code is from here:

shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
uniform float specular;
uniform float metallic;
uniform float roughness : hint_range(0,1);

varying vec3 wNormal;
uniform float _TriplanarBlendSharpness : hint_range(2,20) = 5.0;

uniform vec4 north : hint_color = vec4(1.0,0.0,0.0,1.0);
uniform vec4 west : hint_color = vec4(0.0,1.0,0.0,1.0);
uniform vec4 near : hint_color = vec4(0.0,0.0,1.0,1.0);

uniform vec4 south : hint_color = vec4(1.0,0.5,0.5,1.0);
uniform vec4 east : hint_color = vec4(0.5,1.0,0.5,1.0);
uniform vec4 far : hint_color = vec4(0.5,0.5,1.0,1.0);

void vertex() {
    //calculate the world space normal
    wNormal = normalize((WORLD_MATRIX * vec4(NORMAL,0.0)).xyz);

void fragment() {
    METALLIC = metallic;
    ROUGHNESS = roughness;
    SPECULAR = specular;

    //calculate the blend weight
    vec3 blendWeights  = pow(abs(wNormal),vec3(_TriplanarBlendSharpness));
    blendWeights = blendWeights / (blendWeights.x + blendWeights.y + blendWeights.z);
    //set black becaus we want to add the color on to it
    ALBEDO = vec3(0.0);
    //for the left we multiply by blendweight and the sign
    ALBEDO += clamp(west.rgb * blendWeights.x * sign(wNormal.x),0.0,1.0);
    //for the right we multiply it by the inverted sign
    ALBEDO += clamp(east.rgb * blendWeights.x * sign(wNormal.x*-1.0),0.0,1.0);

    // do so for the other directions
    ALBEDO += clamp(north.rgb * blendWeights.y * sign(wNormal.y),0.0,1.0);
    ALBEDO += clamp(south.rgb * blendWeights.y * sign(wNormal.y*-1.0),0.0,1.0);
    ALBEDO += clamp(near.rgb * blendWeights.z * sign(wNormal.z),0.0,1.0);
    ALBEDO += clamp(far.rgb * blendWeights.z * sign(wNormal.z*-1.0),0.0,1.0);
by (4,010 points)

Thanks for the help

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.