Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Light Only" mode of CanvasItemMaterial #75181

Merged
merged 1 commit into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions drivers/gles3/rasterizer_canvas_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[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) {
state.light_uniforms[index].shadow_pixel_size = (1.0 / state.shadow_texture_size) * (1.0 + l->shadow_smooth);
Expand Down Expand Up @@ -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[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) {
state.light_uniforms[index].shadow_pixel_size = (1.0 / state.shadow_texture_size) * (1.0 + l->shadow_smooth);
Expand Down
12 changes: 11 additions & 1 deletion drivers/gles3/shaders/canvas.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ void main() {
vec4 base_color = color;

#ifdef MODE_LIGHT_ONLY
color = vec4(0.0);
float light_only_alpha = 0.0;
#elif !defined(MODE_UNSHADED)
color *= canvas_modulation;
#endif
Expand Down Expand Up @@ -691,6 +691,9 @@ void main() {
}

light_blend_compute(light_base, light_color, color.rgb);
#ifdef MODE_LIGHT_ONLY
light_only_alpha += light_color.a;
#endif
}

// Positional Lights
Expand Down Expand Up @@ -788,8 +791,15 @@ void main() {
}

light_blend_compute(light_base, light_color, color.rgb);
#ifdef MODE_LIGHT_ONLY
light_only_alpha += light_color.a;
#endif
}
#endif

#ifdef MODE_LIGHT_ONLY
color.a *= light_only_alpha;
#endif

frag_color = color;
}
4 changes: 2 additions & 2 deletions servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[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()) {
state.light_uniforms[index].shadow_pixel_size = (1.0 / state.shadow_texture_size) * (1.0 + l->shadow_smooth);
Expand Down Expand Up @@ -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[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()) {
state.light_uniforms[index].shadow_pixel_size = (1.0 / state.shadow_texture_size) * (1.0 + l->shadow_smooth);
Expand Down
12 changes: 11 additions & 1 deletion servers/rendering/renderer_rd/shaders/canvas.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ void main() {
}

#ifdef MODE_LIGHT_ONLY
color = vec4(0.0);
float light_only_alpha = 0.0;
#elif !defined(MODE_UNSHADED)
color *= canvas_data.canvas_modulation;
#endif
Expand Down Expand Up @@ -611,6 +611,9 @@ void main() {
}

light_blend_compute(light_base, light_color, color.rgb);
#ifdef MODE_LIGHT_ONLY
light_only_alpha += light_color.a;
#endif
}

// Positional Lights
Expand Down Expand Up @@ -695,8 +698,15 @@ void main() {
}

light_blend_compute(light_base, light_color, color.rgb);
#ifdef MODE_LIGHT_ONLY
light_only_alpha += light_color.a;
#endif
}
#endif

#ifdef MODE_LIGHT_ONLY
color.a *= light_only_alpha;
#endif

frag_color = color;
}