Fix "Light Only" mode of CanvasItemMaterial

This commit is contained in:
Danil Alexeev 2023-03-21 12:18:15 +03:00
parent c64afeb017
commit 43b0702a02
No known key found for this signature in database
GPG Key ID: 124453E157DA8DC7
4 changed files with 26 additions and 6 deletions

View File

@ -175,7 +175,7 @@ void RasterizerCanvasGLES3::canvas_render_items(RID p_to_render_target, Item *p_
state.light_uniforms[index].color[i] = l->color[i]; state.light_uniforms[index].color[i] = l->color[i];
} }
state.light_uniforms[index].color[3] = l->energy; //use alpha for energy, so base color can go separate state.light_uniforms[index].color[3] *= l->energy; //use alpha for energy, so base color can go separate
if (state.shadow_fb != 0) { if (state.shadow_fb != 0) {
state.light_uniforms[index].shadow_pixel_size = (1.0 / state.shadow_texture_size) * (1.0 + l->shadow_smooth); state.light_uniforms[index].shadow_pixel_size = (1.0 / state.shadow_texture_size) * (1.0 + l->shadow_smooth);
@ -238,7 +238,7 @@ void RasterizerCanvasGLES3::canvas_render_items(RID p_to_render_target, Item *p_
state.light_uniforms[index].color[i] = l->color[i]; state.light_uniforms[index].color[i] = l->color[i];
} }
state.light_uniforms[index].color[3] = l->energy; //use alpha for energy, so base color can go separate state.light_uniforms[index].color[3] *= l->energy; //use alpha for energy, so base color can go separate
if (state.shadow_fb != 0) { if (state.shadow_fb != 0) {
state.light_uniforms[index].shadow_pixel_size = (1.0 / state.shadow_texture_size) * (1.0 + l->shadow_smooth); state.light_uniforms[index].shadow_pixel_size = (1.0 / state.shadow_texture_size) * (1.0 + l->shadow_smooth);

View File

@ -648,7 +648,7 @@ void main() {
vec4 base_color = color; vec4 base_color = color;
#ifdef MODE_LIGHT_ONLY #ifdef MODE_LIGHT_ONLY
color = vec4(0.0); float light_only_alpha = 0.0;
#elif !defined(MODE_UNSHADED) #elif !defined(MODE_UNSHADED)
color *= canvas_modulation; color *= canvas_modulation;
#endif #endif
@ -691,6 +691,9 @@ void main() {
} }
light_blend_compute(light_base, light_color, color.rgb); light_blend_compute(light_base, light_color, color.rgb);
#ifdef MODE_LIGHT_ONLY
light_only_alpha += light_color.a;
#endif
} }
// Positional Lights // Positional Lights
@ -788,8 +791,15 @@ void main() {
} }
light_blend_compute(light_base, light_color, color.rgb); light_blend_compute(light_base, light_color, color.rgb);
#ifdef MODE_LIGHT_ONLY
light_only_alpha += light_color.a;
#endif
} }
#endif #endif
#ifdef MODE_LIGHT_ONLY
color.a *= light_only_alpha;
#endif
frag_color = color; frag_color = color;
} }

View File

@ -1202,7 +1202,7 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p
state.light_uniforms[index].color[i] = l->color[i]; state.light_uniforms[index].color[i] = l->color[i];
} }
state.light_uniforms[index].color[3] = l->energy; //use alpha for energy, so base color can go separate state.light_uniforms[index].color[3] *= l->energy; //use alpha for energy, so base color can go separate
if (state.shadow_fb.is_valid()) { if (state.shadow_fb.is_valid()) {
state.light_uniforms[index].shadow_pixel_size = (1.0 / state.shadow_texture_size) * (1.0 + l->shadow_smooth); state.light_uniforms[index].shadow_pixel_size = (1.0 / state.shadow_texture_size) * (1.0 + l->shadow_smooth);
@ -1264,7 +1264,7 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p
state.light_uniforms[index].color[i] = l->color[i]; state.light_uniforms[index].color[i] = l->color[i];
} }
state.light_uniforms[index].color[3] = l->energy; //use alpha for energy, so base color can go separate state.light_uniforms[index].color[3] *= l->energy; //use alpha for energy, so base color can go separate
if (state.shadow_fb.is_valid()) { if (state.shadow_fb.is_valid()) {
state.light_uniforms[index].shadow_pixel_size = (1.0 / state.shadow_texture_size) * (1.0 + l->shadow_smooth); state.light_uniforms[index].shadow_pixel_size = (1.0 / state.shadow_texture_size) * (1.0 + l->shadow_smooth);

View File

@ -568,7 +568,7 @@ void main() {
} }
#ifdef MODE_LIGHT_ONLY #ifdef MODE_LIGHT_ONLY
color = vec4(0.0); float light_only_alpha = 0.0;
#elif !defined(MODE_UNSHADED) #elif !defined(MODE_UNSHADED)
color *= canvas_data.canvas_modulation; color *= canvas_data.canvas_modulation;
#endif #endif
@ -611,6 +611,9 @@ void main() {
} }
light_blend_compute(light_base, light_color, color.rgb); light_blend_compute(light_base, light_color, color.rgb);
#ifdef MODE_LIGHT_ONLY
light_only_alpha += light_color.a;
#endif
} }
// Positional Lights // Positional Lights
@ -695,8 +698,15 @@ void main() {
} }
light_blend_compute(light_base, light_color, color.rgb); light_blend_compute(light_base, light_color, color.rgb);
#ifdef MODE_LIGHT_ONLY
light_only_alpha += light_color.a;
#endif
} }
#endif #endif
#ifdef MODE_LIGHT_ONLY
color.a *= light_only_alpha;
#endif
frag_color = color; frag_color = color;
} }