summaryrefslogtreecommitdiff
path: root/drivers/gles2
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gles2')
-rw-r--r--drivers/gles2/rasterizer_gles2.cpp4
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.cpp67
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.h8
-rw-r--r--drivers/gles2/rasterizer_storage_gles2.cpp69
-rw-r--r--drivers/gles2/rasterizer_storage_gles2.h65
-rw-r--r--drivers/gles2/shader_compiler_gles2.cpp23
-rw-r--r--drivers/gles2/shader_gles2.cpp16
-rw-r--r--drivers/gles2/shaders/scene.glsl76
8 files changed, 182 insertions, 146 deletions
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp
index 175587b1bb..f49dbfeabb 100644
--- a/drivers/gles2/rasterizer_gles2.cpp
+++ b/drivers/gles2/rasterizer_gles2.cpp
@@ -58,11 +58,13 @@
#define _EXT_DEBUG_SEVERITY_LOW_ARB 0x9148
#define _EXT_DEBUG_OUTPUT 0x92E0
-#if (defined WINDOWS_ENABLED) && !(defined UWP_ENABLED)
+#ifndef GLAPIENTRY
+#if defined(WINDOWS_ENABLED) && !defined(UWP_ENABLED)
#define GLAPIENTRY APIENTRY
#else
#define GLAPIENTRY
#endif
+#endif
#if !defined(GLES_OVER_GL) && !defined(IPHONE_ENABLED)
// Used for debugging on mobile, but not iOS as EGL is not available
diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp
index c4b6c607a2..25d7df8ebc 100644
--- a/drivers/gles2/rasterizer_scene_gles2.cpp
+++ b/drivers/gles2/rasterizer_scene_gles2.cpp
@@ -605,7 +605,6 @@ bool RasterizerSceneGLES2::reflection_probe_instance_postprocess_step(RID p_inst
size >>= 1;
int mipmaps = 6;
- int mm_level = mipmaps - 1;
storage->shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES2::USE_SOURCE_PANORAMA, false);
storage->shaders.cubemap_filter.bind();
@@ -628,8 +627,6 @@ bool RasterizerSceneGLES2::reflection_probe_instance_postprocess_step(RID p_inst
size >>= 1;
- mm_level--;
-
lod++;
}
@@ -711,7 +708,7 @@ void RasterizerSceneGLES2::environment_set_dof_blur_near(RID p_env, bool p_enabl
ERR_FAIL_COND(!env);
}
-void RasterizerSceneGLES2::environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, bool p_bicubic_upscale) {
+void RasterizerSceneGLES2::environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale) {
Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
}
@@ -752,13 +749,14 @@ void RasterizerSceneGLES2::environment_set_fog(RID p_env, bool p_enable, const C
env->fog_sun_amount = p_sun_amount;
}
-void RasterizerSceneGLES2::environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_curve, bool p_transmit, float p_transmit_curve) {
+void RasterizerSceneGLES2::environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_end, float p_depth_curve, bool p_transmit, float p_transmit_curve) {
Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
env->fog_depth_enabled = p_enable;
env->fog_depth_begin = p_depth_begin;
+ env->fog_depth_end = p_depth_end;
env->fog_depth_curve = p_depth_curve;
env->fog_transmit_enabled = p_transmit;
env->fog_transmit_curve = p_transmit_curve;
@@ -1209,6 +1207,8 @@ bool RasterizerSceneGLES2::_setup_material(RasterizerStorageGLES2::Material *p_m
state.scene_shader.set_uniform(SceneShaderGLES2::SKELETON_TEXTURE_SIZE, p_skeleton_tex_size);
+ state.current_main_tex = 0;
+
for (int i = 0; i < tc; i++) {
glActiveTexture(GL_TEXTURE0 + i);
@@ -1239,6 +1239,9 @@ bool RasterizerSceneGLES2::_setup_material(RasterizerStorageGLES2::Material *p_m
t = t->get_ptr();
glBindTexture(t->target, t->tex_id);
+ if (i == 0) {
+ state.current_main_tex = t->tex_id;
+ }
}
state.scene_shader.use_material((void *)p_material);
@@ -2014,6 +2017,8 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas);
+ Vector2 viewport_size = state.viewport_size;
+
Vector2 screen_pixel_size = state.screen_pixel_size;
bool use_radiance_map = false;
@@ -2054,7 +2059,11 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
if (p_env && !p_shadow && p_env->fog_enabled && (p_env->fog_depth_enabled || p_env->fog_height_enabled)) {
state.scene_shader.set_conditional(SceneShaderGLES2::FOG_DEPTH_ENABLED, p_env->fog_depth_enabled);
state.scene_shader.set_conditional(SceneShaderGLES2::FOG_HEIGHT_ENABLED, p_env->fog_height_enabled);
- fog_max_distance = p_projection.get_z_far();
+ if (p_env->fog_depth_end > 0) {
+ fog_max_distance = p_env->fog_depth_end;
+ } else {
+ fog_max_distance = p_projection.get_z_far();
+ }
using_fog = true;
}
@@ -2328,8 +2337,9 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
state.scene_shader.set_uniform(SceneShaderGLES2::TIME, storage->frame.time[0]);
+ state.scene_shader.set_uniform(SceneShaderGLES2::VIEWPORT_SIZE, viewport_size);
+
state.scene_shader.set_uniform(SceneShaderGLES2::SCREEN_PIXEL_SIZE, screen_pixel_size);
- state.scene_shader.set_uniform(SceneShaderGLES2::NORMAL_MULT, 1.0); // TODO mirror?
}
if (rebind_light && light) {
@@ -2488,6 +2498,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
Environment *env = NULL;
int viewport_width, viewport_height;
+ bool probe_interior = false;
if (p_reflection_probe.is_valid()) {
ReflectionProbeInstance *probe = reflection_probe_instance_owner.getornull(p_reflection_probe);
@@ -2499,21 +2510,26 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
}
current_fb = probe->fbo[p_reflection_probe_pass];
- state.screen_pixel_size.x = 1.0 / probe->probe_ptr->resolution;
- state.screen_pixel_size.y = 1.0 / probe->probe_ptr->resolution;
viewport_width = probe->probe_ptr->resolution;
viewport_height = probe->probe_ptr->resolution;
+ probe_interior = probe->probe_ptr->interior;
+
} else {
state.render_no_shadows = false;
current_fb = storage->frame.current_rt->fbo;
env = environment_owner.getornull(p_environment);
- state.screen_pixel_size.x = 1.0 / storage->frame.current_rt->width;
- state.screen_pixel_size.y = 1.0 / storage->frame.current_rt->height;
+
viewport_width = storage->frame.current_rt->width;
viewport_height = storage->frame.current_rt->height;
}
+
+ state.viewport_size.x = viewport_width;
+ state.viewport_size.y = viewport_height;
+ state.screen_pixel_size.x = 1.0 / viewport_width;
+ state.screen_pixel_size.y = 1.0 / viewport_height;
+
//push back the directional lights
if (p_light_cull_count) {
@@ -2578,9 +2594,30 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ // clear color
+
+ Color clear_color(0, 0, 0, 0);
- storage->frame.clear_request = false;
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
+ clear_color = Color(0, 0, 0, 0);
+ storage->frame.clear_request = false;
+ } else if (!env || env->bg_mode == VS::ENV_BG_CLEAR_COLOR || env->bg_mode == VS::ENV_BG_SKY) {
+ if (storage->frame.clear_request) {
+ clear_color = storage->frame.clear_request_color.to_linear();
+ storage->frame.clear_request = false;
+ }
+ } else if (env->bg_mode == VS::ENV_BG_CANVAS || env->bg_mode == VS::ENV_BG_COLOR || env->bg_mode == VS::ENV_BG_COLOR_SKY) {
+ clear_color = env->bg_color.to_linear();
+ storage->frame.clear_request = false;
+ } else {
+ storage->frame.clear_request = false;
+ }
+
+ if (!env || env->bg_mode != VS::ENV_BG_KEEP) {
+ glClearColor(clear_color.r, clear_color.g, clear_color.b, clear_color.a);
+ }
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
@@ -2615,6 +2652,10 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
}
}
+ if (probe_interior) {
+ env_radiance_tex = 0; //do not use radiance texture on interiors
+ }
+
// render opaque things first
render_list.sort_by_key(false);
_render_render_list(render_list.elements, render_list.element_count, p_cam_transform, p_cam_projection, p_shadow_atlas, env, env_radiance_tex, 0.0, 0.0, false, false, false);
diff --git a/drivers/gles2/rasterizer_scene_gles2.h b/drivers/gles2/rasterizer_scene_gles2.h
index 33ac99366d..3c7d331cb8 100644
--- a/drivers/gles2/rasterizer_scene_gles2.h
+++ b/drivers/gles2/rasterizer_scene_gles2.h
@@ -211,6 +211,8 @@ public:
bool render_no_shadows;
+ Vector2 viewport_size;
+
Vector2 screen_pixel_size;
} state;
@@ -360,6 +362,7 @@ public:
bool fog_depth_enabled;
float fog_depth_begin;
+ float fog_depth_end;
float fog_depth_curve;
bool fog_transmit_enabled;
float fog_transmit_curve;
@@ -385,6 +388,7 @@ public:
fog_depth_enabled = true;
fog_depth_begin = 10;
+ fog_depth_end = 0;
fog_depth_curve = 1;
fog_transmit_enabled = true;
@@ -411,7 +415,7 @@ public:
virtual void environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, VS::EnvironmentDOFBlurQuality p_quality);
virtual void environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, VS::EnvironmentDOFBlurQuality p_quality);
- virtual void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, bool p_bicubic_upscale);
+ virtual void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale);
virtual void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture);
virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_in, float p_fade_out, float p_depth_tolerance, bool p_roughness);
@@ -422,7 +426,7 @@ public:
virtual void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp);
virtual void environment_set_fog(RID p_env, bool p_enable, const Color &p_color, const Color &p_sun_color, float p_sun_amount);
- virtual void environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_curve, bool p_transmit, float p_transmit_curve);
+ virtual void environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_end, float p_depth_curve, bool p_transmit, float p_transmit_curve);
virtual void environment_set_fog_height(RID p_env, bool p_enable, float p_min_height, float p_max_height, float p_height_curve);
virtual bool is_environment(RID p_env);
diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp
index c4c5093540..3beb8eac33 100644
--- a/drivers/gles2/rasterizer_storage_gles2.cpp
+++ b/drivers/gles2/rasterizer_storage_gles2.cpp
@@ -1125,6 +1125,10 @@ void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const {
p_shader->uniforms.clear();
+ if (p_shader->code == String()) {
+ return; //just invalid, but no error
+ }
+
ShaderCompilerGLES2::GeneratedCode gen_code;
ShaderCompilerGLES2::IdentifierActions *actions = NULL;
@@ -1493,8 +1497,9 @@ Variant RasterizerStorageGLES2::material_get_param_default(RID p_material, const
if (material->shader) {
if (material->shader->uniforms.has(p_param)) {
- Vector<ShaderLanguage::ConstantNode::Value> default_value = material->shader->uniforms[p_param].default_value;
- return ShaderLanguage::constant_value_to_variant(default_value, material->shader->uniforms[p_param].type);
+ ShaderLanguage::ShaderNode::Uniform uniform = material->shader->uniforms[p_param];
+ Vector<ShaderLanguage::ConstantNode::Value> default_value = uniform.default_value;
+ return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.hint);
}
}
return Variant();
@@ -1602,7 +1607,7 @@ void RasterizerStorageGLES2::_update_material(Material *p_material) {
if (p_material->shader && p_material->shader->mode == VS::SHADER_SPATIAL) {
if (p_material->shader->spatial.blend_mode == Shader::Spatial::BLEND_MODE_MIX &&
- (!p_material->shader->spatial.uses_alpha || (p_material->shader->spatial.uses_alpha && p_material->shader->spatial.depth_draw_mode == Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS))) {
+ (!p_material->shader->spatial.uses_alpha || p_material->shader->spatial.depth_draw_mode == Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS)) {
can_cast_shadow = true;
}
@@ -1623,7 +1628,7 @@ void RasterizerStorageGLES2::_update_material(Material *p_material) {
}
for (Map<RasterizerScene::InstanceBase *, int>::Element *E = p_material->instance_owners.front(); E; E = E->next()) {
- E->key()->base_material_changed();
+ E->key()->base_changed(false, true);
}
}
}
@@ -2010,7 +2015,7 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS:
}
mesh->surfaces.push_back(surface);
- mesh->instance_change_notify();
+ mesh->instance_change_notify(true, false);
info.vertex_mem += surface->total_data_size;
}
@@ -2080,7 +2085,7 @@ void RasterizerStorageGLES2::mesh_surface_set_material(RID p_mesh, int p_surface
_material_add_geometry(mesh->surfaces[p_surface]->material, mesh->surfaces[p_surface]);
}
- mesh->instance_material_change_notify();
+ mesh->instance_change_notify(false, true);
}
RID RasterizerStorageGLES2::mesh_surface_get_material(RID p_mesh, int p_surface) const {
@@ -2188,13 +2193,11 @@ void RasterizerStorageGLES2::mesh_remove_surface(RID p_mesh, int p_surface) {
info.vertex_mem -= surface->total_data_size;
- mesh->instance_material_change_notify();
-
memdelete(surface);
mesh->surfaces.remove(p_surface);
- mesh->instance_change_notify();
+ mesh->instance_change_notify(true, true);
}
int RasterizerStorageGLES2::mesh_get_surface_count(RID p_mesh) const {
@@ -2768,7 +2771,7 @@ void RasterizerStorageGLES2::update_dirty_multimeshes() {
multimesh->dirty_aabb = false;
multimesh->dirty_data = false;
- multimesh->instance_change_notify();
+ multimesh->instance_change_notify(true, false);
multimesh_update_list.remove(multimesh_update_list.first());
}
@@ -2873,7 +2876,7 @@ void RasterizerStorageGLES2::immediate_end(RID p_immediate) {
ERR_FAIL_COND(!im->building);
im->building = false;
- im->instance_change_notify();
+ im->instance_change_notify(true, false);
}
void RasterizerStorageGLES2::immediate_clear(RID p_immediate) {
@@ -2882,7 +2885,7 @@ void RasterizerStorageGLES2::immediate_clear(RID p_immediate) {
ERR_FAIL_COND(im->building);
im->chunks.clear();
- im->instance_change_notify();
+ im->instance_change_notify(true, false);
}
AABB RasterizerStorageGLES2::immediate_get_aabb(RID p_immediate) const {
@@ -2896,7 +2899,7 @@ void RasterizerStorageGLES2::immediate_set_material(RID p_immediate, RID p_mater
ERR_FAIL_COND(!im);
im->material = p_material;
- im->instance_material_change_notify();
+ im->instance_change_notify(false, true);
}
RID RasterizerStorageGLES2::immediate_get_material(RID p_immediate) const {
@@ -3107,7 +3110,7 @@ void RasterizerStorageGLES2::update_dirty_skeletons() {
}
for (Set<RasterizerScene::InstanceBase *>::Element *E = skeleton->instances.front(); E; E = E->next()) {
- E->get()->base_changed();
+ E->get()->base_changed(true, false);
}
skeleton_update_list.remove(skeleton_update_list.first());
@@ -3172,7 +3175,7 @@ void RasterizerStorageGLES2::light_set_param(RID p_light, VS::LightParam p_param
case VS::LIGHT_PARAM_SHADOW_NORMAL_BIAS:
case VS::LIGHT_PARAM_SHADOW_BIAS: {
light->version++;
- light->instance_change_notify();
+ light->instance_change_notify(true, false);
} break;
default: {}
}
@@ -3187,7 +3190,7 @@ void RasterizerStorageGLES2::light_set_shadow(RID p_light, bool p_enabled) {
light->shadow = p_enabled;
light->version++;
- light->instance_change_notify();
+ light->instance_change_notify(true, false);
}
void RasterizerStorageGLES2::light_set_shadow_color(RID p_light, const Color &p_color) {
@@ -3218,7 +3221,7 @@ void RasterizerStorageGLES2::light_set_cull_mask(RID p_light, uint32_t p_mask) {
light->cull_mask = p_mask;
light->version++;
- light->instance_change_notify();
+ light->instance_change_notify(true, false);
}
void RasterizerStorageGLES2::light_set_reverse_cull_face_mode(RID p_light, bool p_enabled) {
@@ -3228,7 +3231,7 @@ void RasterizerStorageGLES2::light_set_reverse_cull_face_mode(RID p_light, bool
light->reverse_cull = p_enabled;
light->version++;
- light->instance_change_notify();
+ light->instance_change_notify(true, false);
}
void RasterizerStorageGLES2::light_omni_set_shadow_mode(RID p_light, VS::LightOmniShadowMode p_mode) {
@@ -3238,7 +3241,7 @@ void RasterizerStorageGLES2::light_omni_set_shadow_mode(RID p_light, VS::LightOm
light->omni_shadow_mode = p_mode;
light->version++;
- light->instance_change_notify();
+ light->instance_change_notify(true, false);
}
VS::LightOmniShadowMode RasterizerStorageGLES2::light_omni_get_shadow_mode(RID p_light) {
@@ -3255,7 +3258,7 @@ void RasterizerStorageGLES2::light_omni_set_shadow_detail(RID p_light, VS::Light
light->omni_shadow_detail = p_detail;
light->version++;
- light->instance_change_notify();
+ light->instance_change_notify(true, false);
}
void RasterizerStorageGLES2::light_directional_set_shadow_mode(RID p_light, VS::LightDirectionalShadowMode p_mode) {
@@ -3265,7 +3268,7 @@ void RasterizerStorageGLES2::light_directional_set_shadow_mode(RID p_light, VS::
light->directional_shadow_mode = p_mode;
light->version++;
- light->instance_change_notify();
+ light->instance_change_notify(true, false);
}
void RasterizerStorageGLES2::light_directional_set_blend_splits(RID p_light, bool p_enable) {
@@ -3275,7 +3278,7 @@ void RasterizerStorageGLES2::light_directional_set_blend_splits(RID p_light, boo
light->directional_blend_splits = p_enable;
light->version++;
- light->instance_change_notify();
+ light->instance_change_notify(true, false);
}
bool RasterizerStorageGLES2::light_directional_get_blend_splits(RID p_light) const {
@@ -3394,7 +3397,7 @@ void RasterizerStorageGLES2::reflection_probe_set_update_mode(RID p_probe, VS::R
ERR_FAIL_COND(!reflection_probe);
reflection_probe->update_mode = p_mode;
- reflection_probe->instance_change_notify();
+ reflection_probe->instance_change_notify(true, false);
}
void RasterizerStorageGLES2::reflection_probe_set_intensity(RID p_probe, float p_intensity) {
@@ -3435,7 +3438,7 @@ void RasterizerStorageGLES2::reflection_probe_set_max_distance(RID p_probe, floa
ERR_FAIL_COND(!reflection_probe);
reflection_probe->max_distance = p_distance;
- reflection_probe->instance_change_notify();
+ reflection_probe->instance_change_notify(true, false);
}
void RasterizerStorageGLES2::reflection_probe_set_extents(RID p_probe, const Vector3 &p_extents) {
@@ -3443,7 +3446,7 @@ void RasterizerStorageGLES2::reflection_probe_set_extents(RID p_probe, const Vec
ERR_FAIL_COND(!reflection_probe);
reflection_probe->extents = p_extents;
- reflection_probe->instance_change_notify();
+ reflection_probe->instance_change_notify(true, false);
}
void RasterizerStorageGLES2::reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset) {
@@ -3451,7 +3454,7 @@ void RasterizerStorageGLES2::reflection_probe_set_origin_offset(RID p_probe, con
ERR_FAIL_COND(!reflection_probe);
reflection_probe->origin_offset = p_offset;
- reflection_probe->instance_change_notify();
+ reflection_probe->instance_change_notify(true, false);
}
void RasterizerStorageGLES2::reflection_probe_set_as_interior(RID p_probe, bool p_enable) {
@@ -3475,7 +3478,7 @@ void RasterizerStorageGLES2::reflection_probe_set_enable_shadows(RID p_probe, bo
ERR_FAIL_COND(!reflection_probe);
reflection_probe->enable_shadows = p_enable;
- reflection_probe->instance_change_notify();
+ reflection_probe->instance_change_notify(true, false);
}
void RasterizerStorageGLES2::reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers) {
@@ -3483,7 +3486,7 @@ void RasterizerStorageGLES2::reflection_probe_set_cull_mask(RID p_probe, uint32_
ERR_FAIL_COND(!reflection_probe);
reflection_probe->cull_mask = p_layers;
- reflection_probe->instance_change_notify();
+ reflection_probe->instance_change_notify(true, false);
}
void RasterizerStorageGLES2::reflection_probe_set_resolution(RID p_probe, int p_resolution) {
@@ -3667,7 +3670,7 @@ void RasterizerStorageGLES2::lightmap_capture_set_bounds(RID p_capture, const AA
LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture);
ERR_FAIL_COND(!capture);
capture->bounds = p_bounds;
- capture->instance_change_notify();
+ capture->instance_change_notify(true, false);
}
AABB RasterizerStorageGLES2::lightmap_capture_get_bounds(RID p_capture) const {
@@ -3688,7 +3691,7 @@ void RasterizerStorageGLES2::lightmap_capture_set_octree(RID p_capture, const Po
PoolVector<uint8_t>::Read r = p_octree.read();
copymem(w.ptr(), r.ptr(), p_octree.size());
}
- capture->instance_change_notify();
+ capture->instance_change_notify(true, false);
}
PoolVector<uint8_t> RasterizerStorageGLES2::lightmap_capture_get_octree(RID p_capture) const {
@@ -3839,6 +3842,10 @@ RID RasterizerStorageGLES2::particles_get_draw_pass_mesh(RID p_particles, int p_
void RasterizerStorageGLES2::update_particles() {
}
+bool RasterizerStorageGLES2::particles_is_inactive(RID p_particles) const {
+ return true;
+}
+
////////
void RasterizerStorageGLES2::instance_add_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance) {
@@ -4458,6 +4465,7 @@ void RasterizerStorageGLES2::initialize() {
}
}
+ config.keep_original_textures = false;
config.shrink_textures_x2 = false;
config.float_texture_supported = config.extensions.has("GL_ARB_texture_float") || config.extensions.has("GL_OES_texture_float");
@@ -4605,6 +4613,7 @@ void RasterizerStorageGLES2::initialize() {
#endif
config.force_vertex_shading = GLOBAL_GET("rendering/quality/shading/force_vertex_shading");
+ config.use_fast_texture_filter = GLOBAL_GET("rendering/quality/filters/use_nearest_mipmap_filter");
}
void RasterizerStorageGLES2::finalize() {
diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h
index c928f753b1..5bdc65a0b5 100644
--- a/drivers/gles2/rasterizer_storage_gles2.h
+++ b/drivers/gles2/rasterizer_storage_gles2.h
@@ -60,20 +60,12 @@ public:
bool shrink_textures_x2;
bool use_fast_texture_filter;
- // bool use_anisotropic_filter;
-
- bool hdr_supported;
-
- bool use_rgba_2d_shadows;
-
- // float anisotropic_level;
int max_texture_image_units;
int max_texture_size;
- bool generate_wireframes;
-
- bool use_texture_array_environment;
+ // TODO implement wireframe in GLES2
+ // bool generate_wireframes;
Set<String> extensions;
@@ -83,7 +75,6 @@ public:
bool keep_original_textures;
- bool no_depth_prepass;
bool force_vertex_shading;
} config;
@@ -159,20 +150,12 @@ public:
struct Instantiable : public RID_Data {
SelfList<RasterizerScene::InstanceBase>::List instance_list;
- _FORCE_INLINE_ void instance_change_notify() {
- SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first();
-
- while (instances) {
- instances->self()->base_changed();
- instances = instances->next();
- }
- }
+ _FORCE_INLINE_ void instance_change_notify(bool p_aabb, bool p_materials) {
- _FORCE_INLINE_ void instance_material_change_notify() {
SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first();
-
while (instances) {
- instances->self()->base_material_changed();
+
+ instances->self()->base_changed(p_aabb, p_materials);
instances = instances->next();
}
}
@@ -272,31 +255,28 @@ public:
void *detect_normal_ud;
Texture() {
- flags = 0;
- width = 0;
- height = 0;
alloc_width = 0;
alloc_height = 0;
- format = Image::FORMAT_L8;
-
target = 0;
- data_size = 0;
- total_data_size = 0;
+ stored_cube_sides = 0;
ignore_mipmaps = false;
-
- compressed = false;
-
- active = false;
-
+ render_target = NULL;
+ flags = width = height = 0;
tex_id = 0;
-
- stored_cube_sides = 0;
-
+ data_size = 0;
+ format = Image::FORMAT_L8;
+ active = false;
+ compressed = false;
+ total_data_size = 0;
+ mipmaps = 0;
+ detect_3d = NULL;
+ detect_3d_ud = NULL;
+ detect_srgb = NULL;
+ detect_srgb_ud = NULL;
+ detect_normal = NULL;
+ detect_normal_ud = NULL;
proxy = NULL;
-
- render_target = NULL;
-
redraw_if_visible = false;
}
@@ -429,6 +409,7 @@ public:
int light_mode;
*/
+
bool uses_screen_texture;
bool uses_screen_uv;
bool uses_time;
@@ -672,7 +653,7 @@ public:
SelfList<MultiMesh> *mm = multimeshes.first();
while (mm) {
- mm->self()->instance_material_change_notify();
+ mm->self()->instance_change_notify(false, true);
mm = mm->next();
}
}
@@ -1109,6 +1090,8 @@ public:
virtual int particles_get_draw_passes(RID p_particles) const;
virtual RID particles_get_draw_pass_mesh(RID p_particles, int p_pass) const;
+ virtual bool particles_is_inactive(RID p_particles) const;
+
/* INSTANCE */
virtual void instance_add_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance);
diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp
index 082c520480..45b0d695a3 100644
--- a/drivers/gles2/shader_compiler_gles2.cpp
+++ b/drivers/gles2/shader_compiler_gles2.cpp
@@ -80,19 +80,17 @@ static String _opstr(SL::Operator p_op) {
static String _mkid(const String &p_id) {
- StringBuffer<> id;
- id += "m_";
- id += p_id;
-
- return id.as_string();
+ String id = "m_" + p_id;
+ return id.replace("__", "_dus_"); //doubleunderscore is reserverd in glsl
}
static String f2sp0(float p_float) {
- if (int(p_float) == p_float)
- return itos(p_float) + ".0";
- else
- return rtoss(p_float);
+ String num = rtoss(p_float);
+ if (num.find(".") == -1 && num.find("e") == -1) {
+ num += ".0";
+ }
+ return num;
}
static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value> &p_values) {
@@ -364,6 +362,7 @@ String ShaderCompilerGLES2::_dump_node_code(SL::Node *p_node, int p_level, Gener
for (int i = 0; i < snode->functions.size(); i++) {
SL::FunctionNode *fnode = snode->functions[i].function;
+ current_func_name = fnode->name;
function_code[fnode->name] = _dump_node_code(fnode->body, 1, r_gen_code, p_actions, p_default_actions, p_assigning);
}
@@ -815,8 +814,8 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
/** SPATIAL SHADER **/
actions[VS::SHADER_SPATIAL].renames["WORLD_MATRIX"] = "world_transform";
- actions[VS::SHADER_SPATIAL].renames["INV_CAMERA_MATRIX"] = "camera_matrix";
- actions[VS::SHADER_SPATIAL].renames["CAMERA_MATRIX"] = "camera_inverse_matrix";
+ actions[VS::SHADER_SPATIAL].renames["INV_CAMERA_MATRIX"] = "camera_inverse_matrix";
+ actions[VS::SHADER_SPATIAL].renames["CAMERA_MATRIX"] = "camera_matrix";
actions[VS::SHADER_SPATIAL].renames["PROJECTION_MATRIX"] = "projection_matrix";
actions[VS::SHADER_SPATIAL].renames["INV_PROJECTION_MATRIX"] = "projection_inverse_matrix";
actions[VS::SHADER_SPATIAL].renames["MODELVIEW_MATRIX"] = "modelview";
@@ -932,7 +931,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
actions[VS::SHADER_PARTICLES].renames["COLOR"] = "out_color";
actions[VS::SHADER_PARTICLES].renames["VELOCITY"] = "out_velocity_active.xyz";
actions[VS::SHADER_PARTICLES].renames["MASS"] = "mass";
- actions[VS::SHADER_PARTICLES].renames["ACTIVE"] = "active";
+ actions[VS::SHADER_PARTICLES].renames["ACTIVE"] = "shader_active";
actions[VS::SHADER_PARTICLES].renames["RESTART"] = "restart";
actions[VS::SHADER_PARTICLES].renames["CUSTOM"] = "out_custom";
actions[VS::SHADER_PARTICLES].renames["TRANSFORM"] = "xform";
diff --git a/drivers/gles2/shader_gles2.cpp b/drivers/gles2/shader_gles2.cpp
index 628a57c06d..84bd413abb 100644
--- a/drivers/gles2/shader_gles2.cpp
+++ b/drivers/gles2/shader_gles2.cpp
@@ -99,7 +99,7 @@ void ShaderGLES2::bind_uniforms() {
const Map<uint32_t, CameraMatrix>::Element *C = uniform_cameras.front();
while (C) {
- int idx = E->key();
+ int idx = C->key();
int location = version->uniform_location[idx];
if (location < 0) {
@@ -196,6 +196,12 @@ static void _display_error_with_code(const String &p_error, const Vector<const c
ERR_PRINTS(p_error);
}
+static String _mkid(const String &p_id) {
+
+ String id = "m_" + p_id;
+ return id.replace("__", "_dus_"); //doubleunderscore is reserverd in glsl
+}
+
ShaderGLES2::Version *ShaderGLES2::get_current_version() {
Version *_v = version_map.getptr(conditional_version);
@@ -492,15 +498,15 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() {
if (cc) {
// uniforms
for (int i = 0; i < cc->custom_uniforms.size(); i++) {
- StringName native_uniform_name = "m_" + cc->custom_uniforms[i];
- GLint location = glGetUniformLocation(v.id, ((String)native_uniform_name).ascii().get_data());
+ String native_uniform_name = _mkid(cc->custom_uniforms[i]);
+ GLint location = glGetUniformLocation(v.id, (native_uniform_name).ascii().get_data());
v.custom_uniform_locations[cc->custom_uniforms[i]] = location;
}
// textures
for (int i = 0; i < cc->texture_uniforms.size(); i++) {
- StringName native_uniform_name = "m_" + cc->texture_uniforms[i];
- GLint location = glGetUniformLocation(v.id, ((String)native_uniform_name).ascii().get_data());
+ String native_uniform_name = _mkid(cc->texture_uniforms[i]);
+ GLint location = glGetUniformLocation(v.id, (native_uniform_name).ascii().get_data());
v.custom_uniform_locations[cc->texture_uniforms[i]] = location;
}
}
diff --git a/drivers/gles2/shaders/scene.glsl b/drivers/gles2/shaders/scene.glsl
index 83f33fb67b..30dc55cc4c 100644
--- a/drivers/gles2/shaders/scene.glsl
+++ b/drivers/gles2/shaders/scene.glsl
@@ -84,7 +84,7 @@ uniform highp mat4 world_transform;
uniform highp float time;
-uniform float normal_mult;
+uniform highp vec2 viewport_size;
#ifdef RENDER_DEPTH
uniform float light_bias;
@@ -247,7 +247,7 @@ void light_compute(
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) / (8.0 * 3.141592654);
+ blinn *= (shininess + 8.0) * (1.0 / (8.0 * M_PI));
specular_brdf_NL = (blinn) / max(4.0 * cNdotV * cNdotL, 0.75);
#endif
@@ -330,11 +330,10 @@ void main() {
#endif
- vec3 normal = normal_attrib * normal_mult;
+ vec3 normal = normal_attrib;
#if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP)
vec3 tangent = tangent_attrib.xyz;
- tangent *= normal_mult;
float binormalf = tangent_attrib.a;
vec3 binormal = normalize(cross(normal, tangent) * binormalf);
#endif
@@ -626,7 +625,7 @@ VERTEX_SHADER_CODE
float fog_z = smoothstep(fog_depth_begin, fog_max_distance, length(vertex));
- fog_amount = pow(fog_z, fog_depth_curve);
+ fog_amount = pow(fog_z, fog_depth_curve) * fog_color_base.a;
}
#endif
@@ -680,6 +679,8 @@ uniform highp mat4 world_transform;
uniform highp float time;
+uniform highp vec2 viewport_size;
+
#if defined(SCREEN_UV_USED)
uniform vec2 screen_pixel_size;
#endif
@@ -1012,9 +1013,7 @@ float G_GGX_2cos(float cos_theta_m, float alpha) {
// This approximates G_GGX_2cos(cos_theta_l, alpha) * G_GGX_2cos(cos_theta_v, alpha)
// See Filament docs, Specular G section.
float V_GGX(float cos_theta_l, float cos_theta_v, float alpha) {
- float v = cos_theta_l * (cos_theta_v * (1.0 - alpha) + alpha);
- float l = cos_theta_v * (cos_theta_l * (1.0 - alpha) + alpha);
- return 0.5 / (v + l);
+ return 0.5 / mix(2.0 * cos_theta_l * cos_theta_v, cos_theta_l + cos_theta_v, alpha);
}
float D_GGX(float cos_theta_m, float alpha) {
@@ -1124,7 +1123,19 @@ LIGHT_SHADER_CODE
float NdotL = dot(N, L);
float cNdotL = max(NdotL, 0.0); // clamped NdotL
float NdotV = dot(N, V);
- float cNdotV = max(NdotV, 0.0);
+ float cNdotV = max(abs(NdotV), 1e-6);
+
+#if defined(DIFFUSE_BURLEY) || defined(SPECULAR_BLINN) || defined(SPECULAR_SCHLICK_GGX) || defined(LIGHT_USE_CLEARCOAT)
+ vec3 H = normalize(V + L);
+#endif
+
+#if defined(SPECULAR_BLINN) || defined(SPECULAR_SCHLICK_GGX) || defined(LIGHT_USE_CLEARCOAT)
+ float cNdotH = max(dot(N, H), 0.0);
+#endif
+
+#if defined(DIFFUSE_BURLEY) || defined(SPECULAR_SCHLICK_GGX) || defined(LIGHT_USE_CLEARCOAT)
+ float cLdotH = max(dot(L, H), 0.0);
+#endif
if (metallic < 1.0) {
#if defined(DIFFUSE_OREN_NAYAR)
@@ -1160,13 +1171,9 @@ LIGHT_SHADER_CODE
#elif defined(DIFFUSE_BURLEY)
{
-
- vec3 H = normalize(V + L);
- float cLdotH = max(0.0, dot(L, H));
-
- float FD90 = 0.5 + 2.0 * cLdotH * cLdotH * roughness;
- float FdV = 1.0 + (FD90 - 1.0) * SchlickFresnel(cNdotV);
- float FdL = 1.0 + (FD90 - 1.0) * SchlickFresnel(cNdotL);
+ float FD90_minus_1 = 2.0 * cLdotH * cLdotH * roughness - 0.5;
+ float FdV = 1.0 + FD90_minus_1 * SchlickFresnel(cNdotV);
+ float FdL = 1.0 + FD90_minus_1 * SchlickFresnel(cNdotL);
diffuse_brdf_NL = (1.0 / M_PI) * FdV * FdL * cNdotL;
/*
float energyBias = mix(roughness, 0.0, 0.5);
@@ -1209,13 +1216,9 @@ LIGHT_SHADER_CODE
#if defined(SPECULAR_BLINN)
//normalized blinn
- vec3 H = normalize(V + L);
- 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) / (8.0 * 3.141592654);
+ blinn *= (shininess + 8.0) * (1.0 / (8.0 * M_PI));
specular_brdf_NL = (blinn) / max(4.0 * cNdotV * cNdotL, 0.75);
#elif defined(SPECULAR_PHONG)
@@ -1224,7 +1227,7 @@ LIGHT_SHADER_CODE
float cRdotV = max(0.0, dot(R, V));
float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
float phong = pow(cRdotV, shininess);
- phong *= (shininess + 8.0) / (8.0 * 3.141592654);
+ phong *= (shininess + 8.0) * (1.0 / (8.0 * M_PI));
specular_brdf_NL = (phong) / max(4.0 * cNdotV * cNdotL, 0.75);
#elif defined(SPECULAR_TOON)
@@ -1240,11 +1243,6 @@ LIGHT_SHADER_CODE
#elif defined(SPECULAR_SCHLICK_GGX)
// shlick+ggx as default
- vec3 H = normalize(V + L);
-
- float cNdotH = max(dot(N, H), 0.0);
- float cLdotH = max(dot(L, H), 0.0);
-
#if defined(LIGHT_USE_ANISOTROPY)
float alpha = roughness * roughness;
float aspect = sqrt(1.0 - anisotropy * 0.9);
@@ -1275,24 +1273,18 @@ LIGHT_SHADER_CODE
specular_light += specular_brdf_NL * light_color * specular_blob_intensity * attenuation;
#if defined(LIGHT_USE_CLEARCOAT)
- if (clearcoat_gloss > 0.0) {
-#if !defined(SPECULAR_SCHLICK_GGX) && !defined(SPECULAR_BLINN)
- vec3 H = normalize(V + L);
-#endif
+
#if !defined(SPECULAR_SCHLICK_GGX)
- float cNdotH = max(dot(N, H), 0.0);
- float cLdotH = max(dot(L, H), 0.0);
- float cLdotH5 = SchlickFresnel(cLdotH);
+ float cLdotH5 = SchlickFresnel(cLdotH);
#endif
- float Dr = GTR1(cNdotH, mix(.1, .001, clearcoat_gloss));
- float Fr = mix(.04, 1.0, cLdotH5);
- //float Gr = G_GGX_2cos(cNdotL, .25) * G_GGX_2cos(cNdotV, .25);
- float Gr = V_GGX(cNdotL, cNdotV, 0.25);
+ float Dr = GTR1(cNdotH, mix(.1, .001, clearcoat_gloss));
+ float Fr = mix(.04, 1.0, cLdotH5);
+ //float Gr = G_GGX_2cos(cNdotL, .25) * G_GGX_2cos(cNdotV, .25);
+ float Gr = V_GGX(cNdotL, cNdotV, 0.25);
- float clearcoat_specular_brdf_NL = 0.25 * clearcoat * Gr * Fr * Dr * cNdotL;
+ float clearcoat_specular_brdf_NL = 0.25 * clearcoat * Gr * Fr * Dr * cNdotL;
- specular_light += clearcoat_specular_brdf_NL * light_color * specular_blob_intensity * attenuation;
- }
+ specular_light += clearcoat_specular_brdf_NL * light_color * specular_blob_intensity * attenuation;
#endif
}
@@ -2037,7 +2029,7 @@ FRAGMENT_SHADER_CODE
float fog_z = smoothstep(fog_depth_begin, fog_max_distance, length(vertex));
- fog_amount = pow(fog_z, fog_depth_curve);
+ fog_amount = pow(fog_z, fog_depth_curve) * fog_color_base.a;
if (fog_transmit_enabled) {
vec3 total_light = gl_FragColor.rgb;