Was not properly re-setting light uniforms, fixes #24976
This commit is contained in:
parent
577659cb1b
commit
b3dc02b5df
2 changed files with 41 additions and 29 deletions
|
@ -73,6 +73,39 @@ void RasterizerCanvasGLES2::_set_uniforms() {
|
|||
state.canvas_shader.set_uniform(CanvasShaderGLES2::SKELETON_TRANSFORM_INVERSE, state.skeleton_transform_inverse);
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::SKELETON_TEXTURE_SIZE, state.skeleton_texture_size);
|
||||
}
|
||||
|
||||
if (state.using_light) {
|
||||
|
||||
Light *light = state.using_light;
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_MATRIX, light->light_shader_xform);
|
||||
Transform2D basis_inverse = light->light_shader_xform.affine_inverse().orthonormalized();
|
||||
basis_inverse[2] = Vector2();
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_MATRIX_INVERSE, basis_inverse);
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_LOCAL_MATRIX, light->xform_cache.affine_inverse());
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_COLOR, light->color * light->energy);
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_POS, light->light_shader_pos);
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_HEIGHT, light->height);
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_OUTSIDE_ALPHA, light->mode == VS::CANVAS_LIGHT_MODE_MASK ? 1.0 : 0.0);
|
||||
|
||||
if (state.using_shadow) {
|
||||
RasterizerStorageGLES2::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(light->shadow_buffer);
|
||||
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 5);
|
||||
glBindTexture(GL_TEXTURE_2D, cls->distance);
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_MATRIX, light->shadow_matrix_cache);
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_SHADOW_COLOR, light->shadow_color);
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOWPIXEL_SIZE, (1.0 / light->shadow_buffer_size) * (1.0 + light->shadow_smooth));
|
||||
if (light->radius_cache == 0) {
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_GRADIENT, 0.0);
|
||||
} else {
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_GRADIENT, light->shadow_gradient_length / (light->radius_cache * 1.1));
|
||||
}
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_DISTANCE_MULT, light->radius_cache * 1.1);
|
||||
|
||||
/*canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_MATRIX,light->shadow_matrix_cache);
|
||||
canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_ESM_MULTIPLIER,light->shadow_esm_mult);
|
||||
canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_SHADOW_COLOR,light->shadow_color);*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RasterizerCanvasGLES2::canvas_begin() {
|
||||
|
@ -1414,41 +1447,14 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons
|
|||
}
|
||||
|
||||
bool light_rebind = state.canvas_shader.bind();
|
||||
state.using_light = light;
|
||||
state.using_shadow = has_shadow;
|
||||
|
||||
if (light_rebind) {
|
||||
|
||||
_set_uniforms();
|
||||
}
|
||||
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_MATRIX, light->light_shader_xform);
|
||||
Transform2D basis_inverse = light->light_shader_xform.affine_inverse().orthonormalized();
|
||||
basis_inverse[2] = Vector2();
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_MATRIX_INVERSE, basis_inverse);
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_LOCAL_MATRIX, light->xform_cache.affine_inverse());
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_COLOR, light->color * light->energy);
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_POS, light->light_shader_pos);
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_HEIGHT, light->height);
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_OUTSIDE_ALPHA, light->mode == VS::CANVAS_LIGHT_MODE_MASK ? 1.0 : 0.0);
|
||||
|
||||
if (has_shadow) {
|
||||
RasterizerStorageGLES2::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(light->shadow_buffer);
|
||||
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 5);
|
||||
glBindTexture(GL_TEXTURE_2D, cls->distance);
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_MATRIX, light->shadow_matrix_cache);
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_SHADOW_COLOR, light->shadow_color);
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOWPIXEL_SIZE, (1.0 / light->shadow_buffer_size) * (1.0 + light->shadow_smooth));
|
||||
if (light->radius_cache == 0) {
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_GRADIENT, 0.0);
|
||||
} else {
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_GRADIENT, light->shadow_gradient_length / (light->radius_cache * 1.1));
|
||||
}
|
||||
state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_DISTANCE_MULT, light->radius_cache * 1.1);
|
||||
|
||||
/*canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_MATRIX,light->shadow_matrix_cache);
|
||||
canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_ESM_MULTIPLIER,light->shadow_esm_mult);
|
||||
canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_SHADOW_COLOR,light->shadow_color);*/
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 4);
|
||||
RasterizerStorageGLES2::Texture *t = storage->texture_owner.getornull(light->texture);
|
||||
if (!t) {
|
||||
|
@ -1461,6 +1467,8 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons
|
|||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
_canvas_item_render_commands(p_item_list, NULL, reclip, material_ptr); //redraw using light
|
||||
|
||||
state.using_light = NULL;
|
||||
}
|
||||
|
||||
light = light->next_ptr;
|
||||
|
@ -1840,6 +1848,8 @@ void RasterizerCanvasGLES2::initialize() {
|
|||
state.lens_shader.init();
|
||||
|
||||
state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP, GLOBAL_DEF("rendering/quality/2d/use_pixel_snap", false));
|
||||
|
||||
state.using_light = NULL;
|
||||
}
|
||||
|
||||
void RasterizerCanvasGLES2::finalize() {
|
||||
|
|
|
@ -91,6 +91,8 @@ public:
|
|||
RasterizerStorageGLES2::Texture *current_tex_ptr;
|
||||
|
||||
Transform vp;
|
||||
Light *using_light;
|
||||
bool using_shadow;
|
||||
|
||||
} state;
|
||||
|
||||
|
|
Loading…
Reference in a new issue