My Custom Light Shader received only a single light

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Robojima

I made simple ramp shader, but this shader received only a single light like image.

Directional Light result disappeared

shader_type spatial;
render_mode blend_mix,depth_draw_opaque, cull_back, ambient_light_disabled;

uniform vec4 albedo_col : hint_color;
uniform sampler2D ramp_img : hint_albedo;

void vertex(){
	UV = UV ;
}

void fragment(){
	vec2 baseUV = UV;
	ALBEDO = albedo_col.rgb;
}

void light(){
	float NdotL = dot(NORMAL, LIGHT);
	float diff = NdotL  * 0.5 + 0.5 ;
	vec3 ramp = texture(ramp_img, vec2(diff)).rgb;
	
	DIFFUSE_LIGHT = ALBEDO * ATTENUATION * ramp ;
}

How should I fix this?

:bust_in_silhouette: Reply From: Antor

Hello!

This maybe is too late and probably you’ve figured out how to solve it, but anyway, if it’s useful to anyone, I have recently figured out how to solve this. If you read with attention the godot documentation, the part of light shaders says:

If you want the lights to add together, add the light contribution to DIFFUSE_LIGHT using +=, rather than overwriting it.

So, you have to sum up every single light, otherwise only the closest light is computed.

In other words, your problem is solved by simply assign the DIFFUSE_LIGHTcomponent on your shader using +=, like this:

DIFFUSE_LIGHT += ALBEDO * ATTENUATION * ramp ;

or also:

DIFFUSE_LIGHT = DIFFUSE_LIGHT + ALBEDO * ATTENUATION * ramp ;

This should work. It worked for me!

Have a nice day!

Thank you so much!
I’d struggled with this problem until now!

Robojima | 2019-11-11 03:42