Skip to content

Commit

Permalink
Fix "Light Only" mode of CanvasItemMaterial
Browse files Browse the repository at this point in the history
  • Loading branch information
dalexeev committed May 13, 2023
1 parent c64afeb commit 43b0702
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
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;
}

0 comments on commit 43b0702

Please sign in to comment.