summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gles2/rasterizer_canvas_gles2.cpp382
-rw-r--r--drivers/gles2/rasterizer_canvas_gles2.h4
-rw-r--r--drivers/gles2/rasterizer_gles2.cpp17
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.cpp18
-rw-r--r--drivers/gles3/rasterizer_canvas_gles3.cpp5
-rw-r--r--drivers/gles3/shaders/scene.glsl60
6 files changed, 327 insertions, 159 deletions
diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/gles2/rasterizer_canvas_gles2.cpp
index d54d6e9eee..bbae3d3d22 100644
--- a/drivers/gles2/rasterizer_canvas_gles2.cpp
+++ b/drivers/gles2/rasterizer_canvas_gles2.cpp
@@ -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() {
@@ -456,160 +489,164 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur
glDisableVertexAttribArray(VS::ARRAY_COLOR);
glVertexAttrib4fv(VS::ARRAY_COLOR, r->modulate.components);
-#if 1
- //more compatible
- state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_TEXTURE_RECT, false);
+ // On some widespread Nvidia cards, the normal draw method can produce some
+ // flickering in draw_rect and especially TileMap rendering (tiles randomly flicker).
+ // See GH-9913.
+ // To work it around, we use a simpler draw method which does not flicker, but gives
+ // a non negligible performance hit, so it's opt-in (GH-24466).
+ if (use_nvidia_rect_workaround) {
+ state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_TEXTURE_RECT, false);
- if (state.canvas_shader.bind()) {
- _set_uniforms();
- state.canvas_shader.use_material((void *)p_material);
- }
+ if (state.canvas_shader.bind()) {
+ _set_uniforms();
+ state.canvas_shader.use_material((void *)p_material);
+ }
- Vector2 points[4] = {
- r->rect.position,
- r->rect.position + Vector2(r->rect.size.x, 0.0),
- r->rect.position + r->rect.size,
- r->rect.position + Vector2(0.0, r->rect.size.y),
- };
+ Vector2 points[4] = {
+ r->rect.position,
+ r->rect.position + Vector2(r->rect.size.x, 0.0),
+ r->rect.position + r->rect.size,
+ r->rect.position + Vector2(0.0, r->rect.size.y),
+ };
- if (r->rect.size.x < 0) {
- SWAP(points[0], points[1]);
- SWAP(points[2], points[3]);
- }
- if (r->rect.size.y < 0) {
- SWAP(points[0], points[3]);
- SWAP(points[1], points[2]);
- }
+ if (r->rect.size.x < 0) {
+ SWAP(points[0], points[1]);
+ SWAP(points[2], points[3]);
+ }
+ if (r->rect.size.y < 0) {
+ SWAP(points[0], points[3]);
+ SWAP(points[1], points[2]);
+ }
- RasterizerStorageGLES2::Texture *texture = _bind_canvas_texture(r->texture, r->normal_map);
+ RasterizerStorageGLES2::Texture *texture = _bind_canvas_texture(r->texture, r->normal_map);
- if (texture) {
- Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
+ if (texture) {
+ Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
- Rect2 src_rect = (r->flags & CANVAS_RECT_REGION) ? Rect2(r->source.position * texpixel_size, r->source.size * texpixel_size) : Rect2(0, 0, 1, 1);
+ Rect2 src_rect = (r->flags & CANVAS_RECT_REGION) ? Rect2(r->source.position * texpixel_size, r->source.size * texpixel_size) : Rect2(0, 0, 1, 1);
- Vector2 uvs[4] = {
- src_rect.position,
- src_rect.position + Vector2(src_rect.size.x, 0.0),
- src_rect.position + src_rect.size,
- src_rect.position + Vector2(0.0, src_rect.size.y),
- };
+ Vector2 uvs[4] = {
+ src_rect.position,
+ src_rect.position + Vector2(src_rect.size.x, 0.0),
+ src_rect.position + src_rect.size,
+ src_rect.position + Vector2(0.0, src_rect.size.y),
+ };
- if (r->flags & CANVAS_RECT_TRANSPOSE) {
- SWAP(uvs[1], uvs[3]);
- }
+ if (r->flags & CANVAS_RECT_TRANSPOSE) {
+ SWAP(uvs[1], uvs[3]);
+ }
- if (r->flags & CANVAS_RECT_FLIP_H) {
- SWAP(uvs[0], uvs[1]);
- SWAP(uvs[2], uvs[3]);
- }
- if (r->flags & CANVAS_RECT_FLIP_V) {
- SWAP(uvs[0], uvs[3]);
- SWAP(uvs[1], uvs[2]);
- }
+ if (r->flags & CANVAS_RECT_FLIP_H) {
+ SWAP(uvs[0], uvs[1]);
+ SWAP(uvs[2], uvs[3]);
+ }
+ if (r->flags & CANVAS_RECT_FLIP_V) {
+ SWAP(uvs[0], uvs[3]);
+ SWAP(uvs[1], uvs[2]);
+ }
- state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, texpixel_size);
+ state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, texpixel_size);
- bool untile = false;
+ bool untile = false;
- if (r->flags & CANVAS_RECT_TILE && !(texture->flags & VS::TEXTURE_FLAG_REPEAT)) {
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- untile = true;
- }
+ if (r->flags & CANVAS_RECT_TILE && !(texture->flags & VS::TEXTURE_FLAG_REPEAT)) {
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ untile = true;
+ }
- _draw_gui_primitive(4, points, NULL, uvs);
+ _draw_gui_primitive(4, points, NULL, uvs);
- if (untile) {
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ if (untile) {
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ }
+ } else {
+ state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, Vector2());
+ _draw_gui_primitive(4, points, NULL, NULL);
}
- } else {
- state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, Vector2());
- _draw_gui_primitive(4, points, NULL, NULL);
- }
-#else
- //disabled because it fails on buggy nvidia drivers
- _bind_quad_buffer();
+ } else {
+ // This branch is better for performance, but can produce flicker on Nvidia, see above comment.
+ _bind_quad_buffer();
- state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_TEXTURE_RECT, true);
+ state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_TEXTURE_RECT, true);
- if (state.canvas_shader.bind()) {
- _set_uniforms();
- state.canvas_shader.use_material((void *)p_material);
- }
+ if (state.canvas_shader.bind()) {
+ _set_uniforms();
+ state.canvas_shader.use_material((void *)p_material);
+ }
- RasterizerStorageGLES2::Texture *tex = _bind_canvas_texture(r->texture, r->normal_map);
+ RasterizerStorageGLES2::Texture *tex = _bind_canvas_texture(r->texture, r->normal_map);
- if (!tex) {
- Rect2 dst_rect = Rect2(r->rect.position, r->rect.size);
+ if (!tex) {
+ Rect2 dst_rect = Rect2(r->rect.position, r->rect.size);
- if (dst_rect.size.width < 0) {
- dst_rect.position.x += dst_rect.size.width;
- dst_rect.size.width *= -1;
- }
- if (dst_rect.size.height < 0) {
- dst_rect.position.y += dst_rect.size.height;
- dst_rect.size.height *= -1;
- }
+ if (dst_rect.size.width < 0) {
+ dst_rect.position.x += dst_rect.size.width;
+ dst_rect.size.width *= -1;
+ }
+ if (dst_rect.size.height < 0) {
+ dst_rect.position.y += dst_rect.size.height;
+ dst_rect.size.height *= -1;
+ }
- state.canvas_shader.set_uniform(CanvasShaderGLES2::DST_RECT, Color(dst_rect.position.x, dst_rect.position.y, dst_rect.size.x, dst_rect.size.y));
- state.canvas_shader.set_uniform(CanvasShaderGLES2::SRC_RECT, Color(0, 0, 1, 1));
+ state.canvas_shader.set_uniform(CanvasShaderGLES2::DST_RECT, Color(dst_rect.position.x, dst_rect.position.y, dst_rect.size.x, dst_rect.size.y));
+ state.canvas_shader.set_uniform(CanvasShaderGLES2::SRC_RECT, Color(0, 0, 1, 1));
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
- } else {
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ } else {
- bool untile = false;
+ bool untile = false;
- if (r->flags & CANVAS_RECT_TILE && !(tex->flags & VS::TEXTURE_FLAG_REPEAT)) {
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- untile = true;
- }
+ if (r->flags & CANVAS_RECT_TILE && !(tex->flags & VS::TEXTURE_FLAG_REPEAT)) {
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ untile = true;
+ }
- Size2 texpixel_size(1.0 / tex->width, 1.0 / tex->height);
- Rect2 src_rect = (r->flags & CANVAS_RECT_REGION) ? Rect2(r->source.position * texpixel_size, r->source.size * texpixel_size) : Rect2(0, 0, 1, 1);
+ Size2 texpixel_size(1.0 / tex->width, 1.0 / tex->height);
+ Rect2 src_rect = (r->flags & CANVAS_RECT_REGION) ? Rect2(r->source.position * texpixel_size, r->source.size * texpixel_size) : Rect2(0, 0, 1, 1);
- Rect2 dst_rect = Rect2(r->rect.position, r->rect.size);
+ Rect2 dst_rect = Rect2(r->rect.position, r->rect.size);
- if (dst_rect.size.width < 0) {
- dst_rect.position.x += dst_rect.size.width;
- dst_rect.size.width *= -1;
- }
- if (dst_rect.size.height < 0) {
- dst_rect.position.y += dst_rect.size.height;
- dst_rect.size.height *= -1;
- }
+ if (dst_rect.size.width < 0) {
+ dst_rect.position.x += dst_rect.size.width;
+ dst_rect.size.width *= -1;
+ }
+ if (dst_rect.size.height < 0) {
+ dst_rect.position.y += dst_rect.size.height;
+ dst_rect.size.height *= -1;
+ }
- if (r->flags & CANVAS_RECT_FLIP_H) {
- src_rect.size.x *= -1;
- }
+ if (r->flags & CANVAS_RECT_FLIP_H) {
+ src_rect.size.x *= -1;
+ }
- if (r->flags & CANVAS_RECT_FLIP_V) {
- src_rect.size.y *= -1;
- }
+ if (r->flags & CANVAS_RECT_FLIP_V) {
+ src_rect.size.y *= -1;
+ }
- if (r->flags & CANVAS_RECT_TRANSPOSE) {
- dst_rect.size.x *= -1; // Encoding in the dst_rect.z uniform
- }
+ if (r->flags & CANVAS_RECT_TRANSPOSE) {
+ dst_rect.size.x *= -1; // Encoding in the dst_rect.z uniform
+ }
- state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, texpixel_size);
+ state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, texpixel_size);
- state.canvas_shader.set_uniform(CanvasShaderGLES2::DST_RECT, Color(dst_rect.position.x, dst_rect.position.y, dst_rect.size.x, dst_rect.size.y));
- state.canvas_shader.set_uniform(CanvasShaderGLES2::SRC_RECT, Color(src_rect.position.x, src_rect.position.y, src_rect.size.x, src_rect.size.y));
+ state.canvas_shader.set_uniform(CanvasShaderGLES2::DST_RECT, Color(dst_rect.position.x, dst_rect.position.y, dst_rect.size.x, dst_rect.size.y));
+ state.canvas_shader.set_uniform(CanvasShaderGLES2::SRC_RECT, Color(src_rect.position.x, src_rect.position.y, src_rect.size.x, src_rect.size.y));
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
- if (untile) {
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ if (untile) {
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ }
}
- }
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
-#endif
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ }
} break;
case Item::Command::TYPE_NINEPATCH: {
@@ -1266,6 +1303,14 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons
t = t->get_ptr();
+#ifdef TOOLS_ENABLED
+ if (t->detect_normal && texture_hints[i] == ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL) {
+ t->detect_normal(t->detect_normal_ud);
+ }
+#endif
+ if (t->render_target)
+ t->render_target->used_in_frame = true;
+
if (t->redraw_if_visible) {
VisualServerRaster::redraw_request();
}
@@ -1413,41 +1458,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) {
@@ -1460,6 +1478,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;
@@ -1721,6 +1741,64 @@ void RasterizerCanvasGLES2::draw_lens_distortion_rect(const Rect2 &p_rect, float
}
void RasterizerCanvasGLES2::draw_window_margins(int *black_margin, RID *black_image) {
+
+ Vector2 window_size = OS::get_singleton()->get_window_size();
+ int window_h = window_size.height;
+ int window_w = window_size.width;
+
+ glBindFramebuffer(GL_FRAMEBUFFER, storage->system_fbo);
+ glViewport(0, 0, window_size.width, window_size.height);
+ canvas_begin();
+
+ if (black_image[MARGIN_LEFT].is_valid()) {
+ _bind_canvas_texture(black_image[MARGIN_LEFT], RID());
+ Size2 sz(storage->texture_get_width(black_image[MARGIN_LEFT]), storage->texture_get_height(black_image[MARGIN_LEFT]));
+ draw_generic_textured_rect(Rect2(0, 0, black_margin[MARGIN_LEFT], window_h), Rect2(0, 0, sz.x, sz.y));
+ } else if (black_margin[MARGIN_LEFT]) {
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
+
+ draw_generic_textured_rect(Rect2(0, 0, black_margin[MARGIN_LEFT], window_h), Rect2(0, 0, 1, 1));
+ }
+
+ if (black_image[MARGIN_RIGHT].is_valid()) {
+ _bind_canvas_texture(black_image[MARGIN_RIGHT], RID());
+ Size2 sz(storage->texture_get_width(black_image[MARGIN_RIGHT]), storage->texture_get_height(black_image[MARGIN_RIGHT]));
+ draw_generic_textured_rect(Rect2(window_w - black_margin[MARGIN_RIGHT], 0, black_margin[MARGIN_RIGHT], window_h), Rect2(0, 0, sz.x, sz.y));
+ } else if (black_margin[MARGIN_RIGHT]) {
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
+
+ draw_generic_textured_rect(Rect2(window_w - black_margin[MARGIN_RIGHT], 0, black_margin[MARGIN_RIGHT], window_h), Rect2(0, 0, 1, 1));
+ }
+
+ if (black_image[MARGIN_TOP].is_valid()) {
+ _bind_canvas_texture(black_image[MARGIN_TOP], RID());
+
+ Size2 sz(storage->texture_get_width(black_image[MARGIN_TOP]), storage->texture_get_height(black_image[MARGIN_TOP]));
+ draw_generic_textured_rect(Rect2(0, 0, window_w, black_margin[MARGIN_TOP]), Rect2(0, 0, sz.x, sz.y));
+
+ } else if (black_margin[MARGIN_TOP]) {
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
+
+ draw_generic_textured_rect(Rect2(0, 0, window_w, black_margin[MARGIN_TOP]), Rect2(0, 0, 1, 1));
+ }
+
+ if (black_image[MARGIN_BOTTOM].is_valid()) {
+
+ _bind_canvas_texture(black_image[MARGIN_BOTTOM], RID());
+
+ Size2 sz(storage->texture_get_width(black_image[MARGIN_BOTTOM]), storage->texture_get_height(black_image[MARGIN_BOTTOM]));
+ draw_generic_textured_rect(Rect2(0, window_h - black_margin[MARGIN_BOTTOM], window_w, black_margin[MARGIN_BOTTOM]), Rect2(0, 0, sz.x, sz.y));
+
+ } else if (black_margin[MARGIN_BOTTOM]) {
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
+
+ draw_generic_textured_rect(Rect2(0, window_h - black_margin[MARGIN_BOTTOM], window_w, black_margin[MARGIN_BOTTOM]), Rect2(0, 0, 1, 1));
+ }
}
void RasterizerCanvasGLES2::initialize() {
@@ -1756,8 +1834,8 @@ void RasterizerCanvasGLES2::initialize() {
glBindBuffer(GL_ARRAY_BUFFER, 0);
- uint32_t index_size = GLOBAL_DEF("rendering/limits/buffers/canvas_polygon_index_size_kb", 128);
- ProjectSettings::get_singleton()->set_custom_property_info("rendering/limits/buffers/canvas_polygon_index_size_kb", PropertyInfo(Variant::INT, "rendering/limits/buffers/canvas_polygon_index_size_kb", PROPERTY_HINT_RANGE, "0,256,1,or_greater"));
+ uint32_t index_size = GLOBAL_DEF("rendering/limits/buffers/canvas_polygon_index_buffer_size_kb", 128);
+ ProjectSettings::get_singleton()->set_custom_property_info("rendering/limits/buffers/canvas_polygon_index_buffer_size_kb", PropertyInfo(Variant::INT, "rendering/limits/buffers/canvas_polygon_index_buffer_size_kb", PROPERTY_HINT_RANGE, "0,256,1,or_greater"));
index_size *= 1024; // kb
glGenBuffers(1, &data.polygon_index_buffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer);
@@ -1839,10 +1917,18 @@ 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() {
}
RasterizerCanvasGLES2::RasterizerCanvasGLES2() {
+#ifdef GLES_OVER_GL
+ use_nvidia_rect_workaround = GLOBAL_GET("rendering/quality/2d/gles2_use_nvidia_rect_flicker_workaround");
+#else
+ // Not needed (a priori) on GLES devices
+ use_nvidia_rect_workaround = false;
+#endif
}
diff --git a/drivers/gles2/rasterizer_canvas_gles2.h b/drivers/gles2/rasterizer_canvas_gles2.h
index cf593a8a62..221427198a 100644
--- a/drivers/gles2/rasterizer_canvas_gles2.h
+++ b/drivers/gles2/rasterizer_canvas_gles2.h
@@ -91,6 +91,8 @@ public:
RasterizerStorageGLES2::Texture *current_tex_ptr;
Transform vp;
+ Light *using_light;
+ bool using_shadow;
} state;
@@ -100,6 +102,8 @@ public:
RasterizerStorageGLES2 *storage;
+ bool use_nvidia_rect_workaround;
+
virtual RID light_internal_create();
virtual void light_internal_update(RID p_rid, Light *p_light);
virtual void light_internal_free(RID p_rid);
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp
index f0496fc153..71b826d689 100644
--- a/drivers/gles2/rasterizer_gles2.cpp
+++ b/drivers/gles2/rasterizer_gles2.cpp
@@ -66,8 +66,13 @@
#endif
#endif
-#if !defined(GLES_OVER_GL) && !defined(IPHONE_ENABLED)
-// Used for debugging on mobile, but not iOS as EGL is not available
+#ifndef IPHONE_ENABLED
+// We include EGL below to get debug callback on GLES2 platforms,
+// but EGL is not available on iOS.
+#define CAN_DEBUG
+#endif
+
+#if !defined(GLES_OVER_GL) && defined(CAN_DEBUG)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES2/gl2platform.h>
@@ -80,7 +85,7 @@
#define strcpy strcpy_s
#endif
-#ifndef IPHONE_ENABLED
+#ifdef CAN_DEBUG
static void GLAPIENTRY _gl_debug_print(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const GLvoid *userParam) {
if (type == _EXT_DEBUG_TYPE_OTHER_ARB)
@@ -128,7 +133,7 @@ static void GLAPIENTRY _gl_debug_print(GLenum source, GLenum type, GLuint id, GL
ERR_PRINTS(output);
}
-#endif // IPHONE_ENABLED
+#endif // CAN_DEBUG
typedef void (*DEBUGPROCARB)(GLenum source,
GLenum type,
@@ -222,6 +227,7 @@ void RasterizerGLES2::initialize() {
#endif // GLAD_ENABLED
// For debugging
+#ifdef CAN_DEBUG
#ifdef GLES_OVER_GL
if (OS::get_singleton()->is_stdout_verbose() && GLAD_GL_ARB_debug_output) {
glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_ERROR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, NULL, GL_TRUE);
@@ -237,7 +243,6 @@ void RasterizerGLES2::initialize() {
*/
}
#else
-#ifndef IPHONE_ENABLED
if (OS::get_singleton()->is_stdout_verbose()) {
DebugMessageCallbackARB callback = (DebugMessageCallbackARB)eglGetProcAddress("glDebugMessageCallback");
if (!callback) {
@@ -252,8 +257,8 @@ void RasterizerGLES2::initialize() {
glEnable(_EXT_DEBUG_OUTPUT);
}
}
-#endif // !IPHONE_ENABLED
#endif // GLES_OVER_GL
+#endif // CAN_DEBUG
const GLubyte *renderer = glGetString(GL_RENDERER);
print_line("OpenGL ES 2.0 Renderer: " + String((const char *)renderer));
diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp
index d9f1fe1212..e4783e907b 100644
--- a/drivers/gles2/rasterizer_scene_gles2.cpp
+++ b/drivers/gles2/rasterizer_scene_gles2.cpp
@@ -1245,6 +1245,24 @@ bool RasterizerSceneGLES2::_setup_material(RasterizerStorageGLES2::Material *p_m
t = t->get_ptr();
+ if (t->redraw_if_visible) { //must check before proxy because this is often used with proxies
+ VisualServerRaster::redraw_request();
+ }
+
+#ifdef TOOLS_ENABLED
+ if (t->detect_3d) {
+ t->detect_3d(t->detect_3d_ud);
+ }
+#endif
+
+#ifdef TOOLS_ENABLED
+ if (t->detect_normal && texture_hints[i] == ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL) {
+ t->detect_normal(t->detect_normal_ud);
+ }
+#endif
+ if (t->render_target)
+ t->render_target->used_in_frame = true;
+
glBindTexture(t->target, t->tex_id);
if (i == 0) {
state.current_main_tex = t->tex_id;
diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp
index bc1883b09d..06b84aeab4 100644
--- a/drivers/gles3/rasterizer_canvas_gles3.cpp
+++ b/drivers/gles3/rasterizer_canvas_gles3.cpp
@@ -1144,6 +1144,11 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur
void RasterizerCanvasGLES3::_copy_texscreen(const Rect2 &p_rect) {
+ if (storage->frame.current_rt->effects.mip_maps[0].sizes.size() == 0) {
+ ERR_EXPLAIN("Can't use screen texture copying in a render target configured without copy buffers");
+ ERR_FAIL();
+ }
+
glDisable(GL_BLEND);
state.canvas_texscreen_used = true;
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index df1645db1f..86aac2801a 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -165,18 +165,68 @@ uniform int spot_light_count;
out vec4 diffuse_light_interp;
out vec4 specular_light_interp;
+
void light_compute(vec3 N, vec3 L, vec3 V, vec3 light_color, float roughness, inout vec3 diffuse, inout vec3 specular) {
- float dotNL = max(dot(N, L), 0.0);
- diffuse += dotNL * light_color / M_PI;
+
+ float NdotL = dot(N, L);
+ float cNdotL = max(NdotL, 0.0); // clamped NdotL
+ float NdotV = dot(N, V);
+ float cNdotV = max(NdotV, 0.0);
+
+#if defined(DIFFUSE_OREN_NAYAR)
+ vec3 diffuse_brdf_NL;
+#else
+ float diffuse_brdf_NL; // BRDF times N.L for calculating diffuse radiance
+#endif
+
+#if defined(DIFFUSE_LAMBERT_WRAP)
+ // energy conserving lambert wrap shader
+ diffuse_brdf_NL = max(0.0, (NdotL + roughness) / ((1.0 + roughness) * (1.0 + roughness)));
+
+#elif defined(DIFFUSE_OREN_NAYAR)
+
+ {
+ // see http://mimosa-pudica.net/improved-oren-nayar.html
+ float LdotV = dot(L, V);
+
+ float s = LdotV - NdotL * NdotV;
+ float t = mix(1.0, max(NdotL, NdotV), step(0.0, s));
+
+ float sigma2 = roughness * roughness; // TODO: this needs checking
+ vec3 A = 1.0 + sigma2 * (-0.5 / (sigma2 + 0.33) + 0.17 * diffuse_color / (sigma2 + 0.13));
+ float B = 0.45 * sigma2 / (sigma2 + 0.09);
+
+ diffuse_brdf_NL = cNdotL * (A + vec3(B) * s / t) * (1.0 / M_PI);
+ }
+#else
+ // lambert by default for everything else
+ diffuse_brdf_NL = cNdotL * (1.0 / M_PI);
+#endif
+
+ diffuse += light_color * diffuse_brdf_NL;
if (roughness > 0.0) {
+ // D
+ float specular_brdf_NL = 0.0;
+
+#if !defined(SPECULAR_DISABLED)
+ //normalized blinn always unless disabled
vec3 H = normalize(V + L);
- float dotNH = max(dot(N, H), 0.0);
- float intensity = (roughness >= 1.0 ? 1.0 : pow(dotNH, (1.0 - roughness) * 256.0));
- specular += light_color * intensity;
+ float cNdotH = max(dot(N, H), 0.0);
+ float cVdotH = max(dot(V, H), 0.0);
+ float cLdotH = max(dot(L, H), 0.0);
+ float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
+ float blinn = pow(cNdotH, shininess);
+ blinn *= (shininess + 8.0) * (1.0 / (8.0 * M_PI));
+ specular_brdf_NL = (blinn) / max(4.0 * cNdotV * cNdotL, 0.75);
+#endif
+
+ specular += specular_brdf_NL * light_color * (1.0 / M_PI);
}
+
+
}
void light_process_omni(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, float roughness, inout vec3 diffuse, inout vec3 specular) {