How do I fix the colours of my shader so they match the original blender render

Godot Version

4.3

Question

I’m working on my first shader with the script of:

shader_type spatial;

// import the textures
// base colour texture
uniform sampler2D base_colour : source_color;

// shadow colour texture
//uniform sampler2D shadow_colour;
// if no shadow colour texure use base_colour and multiply
//uniform vec3 shadow_colour = texture(base_colour, UV).rgb * vec3(0.0);
uniform vec4 shading_multiplier = vec4(.264, .205, .626, .408);

// R, G, B, and Alpha channels:
uniform sampler2D R_tga : source_color;
uniform sampler2D G_tga : source_color;
uniform sampler2D B_tga : source_color;
uniform sampler2D A_tga : source_color;


void vertex() {
	// Called for every vertex the material is visible on.
	
}

void fragment() {
	// Called for every pixel the material is visible on.
	
	// get base colour and multiply by shadow to create shading colour
	vec4 shadow_colour = texture(base_colour,UV) * shading_multiplier;
	ALBEDO = texture(base_colour,UV).rgb;
}

//void light() {
	// Called for every pixel for every light affecting the material.
	// Uncomment to replace the default light processing function with this one.
//}

While the result is close (unshaded Godot on left, blender render on right):

Its not quite right. All my dark purples now look dark brown, looking at the RGB values their only a little bit off but I need the to be exactly the same otherwise all the original colour contrasts won’t come through. I’ve had a look online and seen the documentation about colour washing but from what I understand my script shouldn’t have that problem now. Any suggestions on what I can do?

Comparing the RGBA values of the skin and brows shows that a simple multiplication cant fix it since the differences are different

blender/godot

Skin: R .97 G 1.0 B .99
brow: R 1.15 G 1.04 B 1.12

could be all sorts of things. event unshaded, adding an environment node and changing the tonemapping will make a difference:
image
also, did you use a similar shader in blender? because the shading multiplier may be different, but even if you used the same multiplier in a blender shader, no two rendering engines will do colour mapping identically.

Also dont forget to check the the actual colour picker you chose the colour from, they have different colour interpolations similar to the tonemap the camera uses, and that changes how the actual RGB values are interpreted

2 Likes

The blender model is only altering the colours where there is shading, the unshaded parts should be the same but arnt.

If the render engines are going to render the colours differently how am I supposed to design my models colours so they are consistent? that’s incredibly annoying.

I’m using a website to pick the colours and it picks by pixel so they should be correct.

how do i find that setting?

You actually have the preview environment off, so it won’t be tonemapped in this scene.

For your world scene will be part of the WorldEnvironment node, shouldn’t affect other scenes though.

The texture should remain the same between the two programs, make sure Godot is importing it as high quality

1 Like

how do I do that? I copied and pasted the image into the Godot files, so I cant see anything going wrong there

double click the image in Godot’s filesystem, then change the import settings (the “Import” tab usually located next to “Scene”). There should be a check box for “High Quality” if it’s been used in 3D.

1 Like

Thanks that got it close enough, there still 1/255 off on the g channel but its good enough

You might even want to switch it to “VRam Uncompressed”, though this can use much more memory per texture. You can be selective with it too.

1 Like

can I ask u a quick question about colour mixing in Godot?

I had a look a the blender documentation and I think the mixing ratio just sort of controls the alpha of the mix colour and over laps it. Do you know how I would be able to do that that in Godot?

Godot uses a pretty raw GLSL shading variant, maybe you want the mix function, I am not sure exactly what you want to do, but this line should mix based on alpha

vec4 t1 = texture(sampler1, UV)
vec4 t2 = texture(sampler2, UV)
ALBEDO = mix(t1.rgb, t2.rgb, t1.a)

to be exact:

uniform sampler2D base_colour : source_color, filter_nearest; //this is my base/lit colourtexture.

uniform vec4 shading_multiplier = vec4(.264, .205, .626, .408) // the RGB are the colour of the mix I used in blender and the Alpha is the mix ratio.

What I think I need to do is somehow overlap the colours so the render shows the shading colour over the base colour, but in such a way that the shading colour is transparent by 0.408. if that makes sense. Ive tried controlling the mix amount but i dont think thats it, multiply numbers smaller than 1 always gives u a smaller number afterall.

mix is probably good for that, it’s really more of a lerp function, so given this line a alpha of 1.0 will only show the texture, and a alpha of 0.0 will only show the shading multiplier colors.

ALBEDO = mix(shading_multiplier.rgb, t1.rgb shading_multiplier.a)
1 Like

Thanks for the info, didnt work but ill keep looking. Appreciate it!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.