0 votes

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?

asked Jul 12, 2019 in Engine by Robojima (15 points)

1 Answer

+3 votes
Best answer

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!

answered Oct 7, 2019 by Antor (57 points)
selected Nov 11, 2019 by Robojima

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

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.