0 votes

I'm new to shader writing in Godot and ma finding that the shaders I've written appear very overlit and washed out compared to the default shaders Godot applies to meshes imported from Blender.

The purpose of this custom shader is to use vertex colors to blend between two different albedo textures. There is a base texture to be used wherever the vertex color is black and a second texture is overlaid wherever the vertex color is red. I've created this mesh in Blender and have imported it into a Godot scene. However, when it is drawn, the textures appear much lighter than they should be. I've tried playing with the specular, roughness and metallic settings, but they do not help.

Any idea how I could fix the lighting here?

(If someone could post the code for a shader that just draws a plain spatial mesh with a single texture, I think that would be a good reference point for demonstrating what a basic shader should look like - the water shader in the docs is not terribly helpful since it illustrates a very unusual case).

shader_type spatial;
render_mode cull_disabled;

uniform sampler2D baseAlbedo;
uniform sampler2D redAlbedo;

void fragment() 
    vec3 base = texture(baseAlbedo, UV).rgb;
    vec3 red = texture(redAlbedo, UV).rgb;

    ALBEDO = COLOR.r * red.rgb + (1.0 - COLOR.r) * base.rgb;
    ROUGHNESS = 1.0;
    SPECULAR = 0.0;
    METALLIC = 0.0;


in Engine by (122 points)

2 Answers

0 votes
Best answer

Looks like I had to add hint_albedo to my sampler declaration. No idea why this acts the way it does, but my shader textures are lit correctly now.

uniform sampler2D baseAlbedo : hint_albedo;
uniform sampler2D redAlbedo : hint_albedo;
by (122 points)

This hint probably tells Godot to convert the texture to the sRGB color space upon import (and treat it as such). Godot expects all albedo textures to be sRGB in 3D.

0 votes

You can convert Godot's default materials into shader script, that should help you ;)

by (283 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 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.