summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gles3/rasterizer_gles3.cpp7
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.cpp117
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.h8
-rw-r--r--drivers/gles3/rasterizer_storage_gles3.cpp132
-rw-r--r--drivers/gles3/rasterizer_storage_gles3.h11
-rw-r--r--drivers/gles3/shader_gles3.cpp1
-rw-r--r--drivers/gles3/shaders/copy.glsl13
-rw-r--r--drivers/gles3/shaders/cubemap_filter.glsl2
-rw-r--r--drivers/gles3/shaders/effect_blur.glsl3
-rw-r--r--drivers/gles3/shaders/particles.glsl4
-rw-r--r--drivers/gles3/shaders/resolve.glsl3
-rw-r--r--drivers/gles3/shaders/scene.glsl293
-rw-r--r--drivers/gles3/shaders/tonemap.glsl4
13 files changed, 444 insertions, 154 deletions
diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp
index 3daf13c3c3..bb7b85e653 100644
--- a/drivers/gles3/rasterizer_gles3.cpp
+++ b/drivers/gles3/rasterizer_gles3.cpp
@@ -186,6 +186,9 @@ void RasterizerGLES3::initialize() {
GL_DEBUG_SEVERITY_HIGH_ARB,5, "hello");
*/
+
+ const GLubyte *renderer = glGetString(GL_RENDERER);
+ print_line("OpenGL ES 3.0 Renderer: " + String((const char *)renderer));
storage->initialize();
canvas->initialize();
scene->initialize();
@@ -336,6 +339,10 @@ void RasterizerGLES3::blit_render_target_to_screen(RID p_render_target, const Re
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, rt->color);
+ //glBindTexture(GL_TEXTURE_2D, rt->effects.mip_maps[0].color);
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex);
+
canvas->draw_generic_textured_rect(p_screen_rect, Rect2(0, 0, 1, -1));
glBindTexture(GL_TEXTURE_2D, 0);
canvas->canvas_end();
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp
index 5d884fff11..56bd3ca2ef 100644
--- a/drivers/gles3/rasterizer_scene_gles3.cpp
+++ b/drivers/gles3/rasterizer_scene_gles3.cpp
@@ -521,13 +521,7 @@ void RasterizerSceneGLES3::reflection_atlas_set_size(RID p_ref_atlas, int p_size
glBindTexture(GL_TEXTURE_2D, reflection_atlas->color);
int mmsize = reflection_atlas->size;
-
- for (int i = 0; i < 6; i++) {
- glTexImage2D(GL_TEXTURE_2D, i, internal_format, mmsize, mmsize, 0,
- format, type, NULL);
-
- mmsize >>= 1;
- }
+ glTexStorage2DCustom(GL_TEXTURE_2D, 6, internal_format, mmsize, mmsize, format, type);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -537,8 +531,6 @@ void RasterizerSceneGLES3::reflection_atlas_set_size(RID p_ref_atlas, int p_size
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 5);
- mmsize = reflection_atlas->size;
-
for (int i = 0; i < 6; i++) {
glGenFramebuffers(1, &reflection_atlas->fbo[i]);
glBindFramebuffer(GL_FRAMEBUFFER, reflection_atlas->fbo[i]);
@@ -1962,6 +1954,7 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_
state.scene_shader.set_conditional(SceneShaderGLES3::SHADELESS, true);
state.scene_shader.set_conditional(SceneShaderGLES3::USE_FORWARD_LIGHTING, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_VERTEX_LIGHTING, false);
state.scene_shader.set_conditional(SceneShaderGLES3::USE_LIGHT_DIRECTIONAL, false);
state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_DIRECTIONAL_SHADOW, false);
state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM4, false);
@@ -1972,6 +1965,7 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_
state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_13, false);
state.scene_shader.set_conditional(SceneShaderGLES3::USE_GI_PROBES, false);
state.scene_shader.set_conditional(SceneShaderGLES3::USE_RADIANCE_MAP, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_CONTACT_SHADOWS, false);
//state.scene_shader.set_conditional(SceneShaderGLES3::SHADELESS,true);
} else {
@@ -1979,7 +1973,10 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_
state.scene_shader.set_conditional(SceneShaderGLES3::USE_GI_PROBES, e->instance->gi_probe_instances.size() > 0);
state.scene_shader.set_conditional(SceneShaderGLES3::SHADELESS, false);
+
state.scene_shader.set_conditional(SceneShaderGLES3::USE_FORWARD_LIGHTING, !p_directional_add);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_VERTEX_LIGHTING, (e->sort_key & SORT_KEY_VERTEX_LIT_FLAG));
+
state.scene_shader.set_conditional(SceneShaderGLES3::USE_LIGHT_DIRECTIONAL, false);
state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_DIRECTIONAL_SHADOW, false);
state.scene_shader.set_conditional(SceneShaderGLES3::LIGHT_USE_PSSM4, false);
@@ -1988,6 +1985,7 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_
state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_5, shadow_filter_mode == SHADOW_FILTER_PCF5);
state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_13, shadow_filter_mode == SHADOW_FILTER_PCF13);
state.scene_shader.set_conditional(SceneShaderGLES3::USE_RADIANCE_MAP, use_radiance_map);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_CONTACT_SHADOWS, state.used_contact_shadows);
if (p_directional_add || (directional_light && (e->sort_key & SORT_KEY_NO_DIRECTIONAL_FLAG) == 0)) {
state.scene_shader.set_conditional(SceneShaderGLES3::USE_LIGHT_DIRECTIONAL, true);
@@ -2136,6 +2134,8 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_
state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_5, false);
state.scene_shader.set_conditional(SceneShaderGLES3::SHADOW_MODE_PCF_13, false);
state.scene_shader.set_conditional(SceneShaderGLES3::USE_GI_PROBES, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_CONTACT_SHADOWS, false);
+ state.scene_shader.set_conditional(SceneShaderGLES3::USE_VERTEX_LIGHTING, false);
}
void RasterizerSceneGLES3::_add_geometry(RasterizerStorageGLES3::Geometry *p_geometry, InstanceBase *p_instance, RasterizerStorageGLES3::GeometryOwner *p_owner, int p_material, bool p_shadow) {
@@ -2281,6 +2281,11 @@ void RasterizerSceneGLES3::_add_geometry_with_material(RasterizerStorageGLES3::G
e->sort_key |= SORT_KEY_UNSHADED_FLAG;
}
+
+ if (!shadow && (m->shader->spatial.uses_vertex_lighting || storage->config.force_vertex_shading)) {
+
+ e->sort_key |= SORT_KEY_VERTEX_LIT_FLAG;
+ }
}
void RasterizerSceneGLES3::_draw_sky(RasterizerStorageGLES3::Sky *p_sky, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_scale, float p_energy) {
@@ -2912,7 +2917,19 @@ void RasterizerSceneGLES3::_setup_reflections(RID *p_reflection_probe_cull_resul
glBindBufferBase(GL_UNIFORM_BUFFER, 6, state.reflection_array_ubo);
}
-void RasterizerSceneGLES3::_copy_screen() {
+void RasterizerSceneGLES3::_copy_screen(bool p_invalidate_color, bool p_invalidate_depth) {
+
+#ifndef GLES_OVER_GL
+ if (p_invalidate_color) {
+
+ GLenum attachments[2] = {
+ GL_COLOR_ATTACHMENT0,
+ GL_DEPTH_STENCIL_ATTACHMENT
+ };
+
+ glInvalidateFramebuffer(GL_FRAMEBUFFER, p_invalidate_depth ? 2 : 1, attachments);
+ }
+#endif
glBindVertexArray(storage->resources.quadie_array);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
@@ -3080,7 +3097,7 @@ void RasterizerSceneGLES3::_blur_effect_buffer() {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); //previous level, since mipmaps[0] starts one level bigger
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[1].sizes[i].fbo);
- _copy_screen();
+ _copy_screen(true);
state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_HORIZONTAL, false);
//vertical pass
@@ -3091,7 +3108,7 @@ void RasterizerSceneGLES3::_blur_effect_buffer() {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[1].color);
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[i + 1].fbo); //next level, since mipmaps[0] starts one level bigger
- _copy_screen();
+ _copy_screen(true);
state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_VERTICAL, false);
}
}
@@ -3139,7 +3156,7 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.ssao.depth_mipmap_fbos[i]); //copy to front first
glViewport(0, 0, ss[0], ss[1]);
- _copy_screen();
+ _copy_screen(true);
}
ss[0] = storage->frame.current_rt->width;
ss[1] = storage->frame.current_rt->height;
@@ -3191,7 +3208,7 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_
Color white(1, 1, 1, 1);
glClearBufferfv(GL_COLOR, 0, white.components); // specular
- _copy_screen();
+ _copy_screen(true);
//do the batm, i mean blur
@@ -3212,7 +3229,7 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_
if (i == 0) {
glClearBufferfv(GL_COLOR, 0, white.components); // specular
}
- _copy_screen();
+ _copy_screen(true);
}
}
@@ -3229,7 +3246,7 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.ssao.blur_red[0]); //previous level, since mipmaps[0] starts one level bigger
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo); // copy to base level
- _copy_screen();
+ _copy_screen(true);
state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::SSAO_MERGE, false);
} else {
@@ -3278,14 +3295,14 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); //copy to front first
- _copy_screen();
+ _copy_screen(true);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color);
state.sss_shader.set_uniform(SubsurfScatteringShaderGLES3::DIR, Vector2(0, 1));
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo); // copy to base level
- _copy_screen();
+ _copy_screen(true);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); //restore filter
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -3337,7 +3354,7 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[1].sizes[0].fbo);
glViewport(0, 0, ssr_w, ssr_h);
- _copy_screen();
+ _copy_screen(true);
glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height);
}
@@ -3368,7 +3385,7 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ONE); //use additive to accumulate one over the other
- _copy_screen();
+ _copy_screen(true);
glDisable(GL_BLEND); //end additive
@@ -3392,7 +3409,7 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color);
- _copy_screen();
+ _copy_screen(true);
state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::SIMPLE_COPY, false);
}
@@ -3413,13 +3430,16 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
//copy specular to front buffer
//copy diffuse to effect buffer
- glReadBuffer(GL_COLOR_ATTACHMENT0);
- glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo);
- glBlitFramebuffer(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
+ if (storage->frame.current_rt->buffers.active) {
+ //transfer to effect buffer if using buffers, also resolve MSAA
+ glReadBuffer(GL_COLOR_ATTACHMENT0);
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo);
+ glBlitFramebuffer(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
- glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+ }
if (!env || storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
//no environment or transparent render, simply return and convert to SRGB
@@ -3431,7 +3451,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA, !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]);
storage->shaders.copy.bind();
- _copy_screen();
+ _copy_screen(true);
storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB, false);
storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA, false); //compute luminance
@@ -3487,7 +3507,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); //copy to front first
- _copy_screen();
+ _copy_screen(true);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color);
@@ -3574,7 +3594,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->buffers.diffuse);
}
- _copy_screen();
+ _copy_screen(true);
if (composite_from != storage->frame.current_rt->buffers.diffuse) {
@@ -3614,7 +3634,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
glBindFramebuffer(GL_FRAMEBUFFER, exposure_shrink[0].fbo);
glViewport(0, 0, exposure_shrink_size, exposure_shrink_size);
- _copy_screen();
+ _copy_screen(true);
//second step, shrink to 2x2 pixels
state.exposure_shader.set_conditional(ExposureShaderGLES3::EXPOSURE_BEGIN, false);
@@ -3658,7 +3678,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
state.exposure_shader.set_uniform(ExposureShaderGLES3::MAX_LUMINANCE, env->auto_exposure_max);
state.exposure_shader.set_uniform(ExposureShaderGLES3::MIN_LUMINANCE, env->auto_exposure_min);
- _copy_screen();
+ _copy_screen(true);
state.exposure_shader.set_conditional(ExposureShaderGLES3::EXPOSURE_FORCE_SET, false);
state.exposure_shader.set_conditional(ExposureShaderGLES3::EXPOSURE_END, false);
@@ -3729,7 +3749,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); //previous level, since mipmaps[0] starts one level bigger
}
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[1].sizes[i].fbo);
- _copy_screen();
+ _copy_screen(true);
state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_GAUSSIAN_HORIZONTAL, false);
state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_FIRST_PASS, false);
state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GLOW_USE_AUTO_EXPOSURE, false);
@@ -3837,7 +3857,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
state.tonemap_shader.set_uniform(TonemapShaderGLES3::BCS, Vector3(env->adjustments_brightness, env->adjustments_contrast, env->adjustments_saturation));
}
- _copy_screen();
+ _copy_screen(true, true);
//turn off everything used
state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_AUTO_EXPOSURE, false);
@@ -3913,7 +3933,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
state.used_contact_shadows = true;
- if (storage->frame.current_rt && state.debug_draw != VS::VIEWPORT_DEBUG_DRAW_OVERDRAW) { //detect with state.used_contact_shadows too
+ if (!storage->config.no_depth_prepass && storage->frame.current_rt && state.debug_draw != VS::VIEWPORT_DEBUG_DRAW_OVERDRAW) { //detect with state.used_contact_shadows too
//pre z pass
glDisable(GL_BLEND);
@@ -3927,7 +3947,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
glColorMask(0, 0, 0, 0);
glClearDepth(1.0f);
- glClear(GL_DEPTH_BUFFER_BIT);
+ glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
render_list.clear();
_fill_render_list(p_cull_result, p_cull_count, true);
@@ -3953,6 +3973,9 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
fb_cleared = true;
render_pass++;
+ state.using_contact_shadows = true;
+ } else {
+ state.using_contact_shadows = false;
}
_setup_lights(p_light_cull_result, p_light_cull_count, p_cam_transform.affine_inverse(), p_cam_projection, p_shadow_atlas);
@@ -4034,8 +4057,13 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
} else {
- current_fbo = storage->frame.current_rt->buffers.fbo;
- glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
+ if (storage->frame.current_rt->buffers.active) {
+ current_fbo = storage->frame.current_rt->buffers.fbo;
+ } else {
+ current_fbo = storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo;
+ }
+
+ glBindFramebuffer(GL_FRAMEBUFFER, current_fbo);
state.scene_shader.set_conditional(SceneShaderGLES3::USE_MULTIPLE_RENDER_TARGETS, false);
Vector<GLenum> draw_buffers;
@@ -4045,8 +4073,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
}
if (!fb_cleared) {
- glClearDepth(1.0f);
- glClear(GL_DEPTH_BUFFER_BIT);
+ glClearBufferfi(GL_DEPTH_STENCIL, 0, 1.0, 0);
}
Color clear_color(0, 0, 0, 0);
@@ -4111,7 +4138,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
storage->shaders.copy.bind();
- _copy_screen();
+ _copy_screen(true, true);
//turn off everything used
storage->shaders.copy.set_conditional(CopyShaderGLES3::SRGB_TO_LINEAR, false);
@@ -4178,7 +4205,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
_render_mrts(env, p_cam_projection);
} else {
//FIXME: check that this is possible to use
- if (storage->frame.current_rt && state.used_screen_texture) {
+ if (storage->frame.current_rt && storage->frame.current_rt->buffers.active && state.used_screen_texture) {
glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo);
@@ -4192,7 +4219,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
}
}
- if (storage->frame.current_rt && state.used_screen_texture) {
+ if (storage->frame.current_rt && state.used_screen_texture && storage->frame.current_rt->buffers.active) {
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 7);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color);
}
@@ -4273,6 +4300,8 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
+
+ //disable all stuff
}
void RasterizerSceneGLES3::render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count) {
@@ -4297,6 +4326,8 @@ void RasterizerSceneGLES3::render_shadow(RID p_light, RID p_shadow_atlas, int p_
float bias = 0;
float normal_bias = 0;
+ state.using_contact_shadows = false;
+
CameraMatrix light_projection;
Transform light_transform;
diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h
index a03e3dbe3d..f6509e0041 100644
--- a/drivers/gles3/rasterizer_scene_gles3.h
+++ b/drivers/gles3/rasterizer_scene_gles3.h
@@ -187,6 +187,7 @@ public:
bool cull_front;
bool used_sss;
bool used_screen_texture;
+ bool using_contact_shadows;
VS::ViewportDebugDraw debug_draw;
} state;
@@ -645,8 +646,9 @@ public:
#define SORT_KEY_UNSHADED_FLAG (uint64_t(1) << 59)
#define SORT_KEY_NO_DIRECTIONAL_FLAG (uint64_t(1) << 58)
#define SORT_KEY_GI_PROBES_FLAG (uint64_t(1) << 57)
- SORT_KEY_SHADING_SHIFT = 57,
- SORT_KEY_SHADING_MASK = 7,
+#define SORT_KEY_VERTEX_LIT_FLAG (uint64_t(1) << 56)
+ SORT_KEY_SHADING_SHIFT = 56,
+ SORT_KEY_SHADING_MASK = 15,
SORT_KEY_MATERIAL_INDEX_SHIFT = 40,
SORT_KEY_GEOMETRY_INDEX_SHIFT = 20,
SORT_KEY_GEOMETRY_TYPE_SHIFT = 15,
@@ -795,7 +797,7 @@ public:
void _setup_lights(RID *p_light_cull_result, int p_light_cull_count, const Transform &p_camera_inverse_transform, const CameraMatrix &p_camera_projection, RID p_shadow_atlas);
void _setup_reflections(RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, const Transform &p_camera_inverse_transform, const CameraMatrix &p_camera_projection, RID p_reflection_atlas, Environment *p_env);
- void _copy_screen();
+ void _copy_screen(bool p_invalidate_color = false, bool p_invalidate_depth = false);
void _copy_to_front_buffer(Environment *env);
void _copy_texture_to_front_buffer(GLuint p_texture); //used for debug
diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp
index 17e77aed89..263b0cc641 100644
--- a/drivers/gles3/rasterizer_storage_gles3.cpp
+++ b/drivers/gles3/rasterizer_storage_gles3.cpp
@@ -99,6 +99,21 @@
#define _EXT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT 0x8E8E
#define _EXT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT 0x8E8F
+void glTexStorage2DCustom(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type) {
+
+#ifdef GLES_OVER_GL
+
+ for (int i = 0; i < levels; i++) {
+ glTexImage2D(target, i, internalformat, width, height, 0, format, type, NULL);
+ width = MAX(1, (width / 2));
+ height = MAX(1, (height / 2));
+ }
+
+#else
+ glTexStorage2D(target, levels, internalformat, width, height);
+#endif
+}
+
GLuint RasterizerStorageGLES3::system_fbo = 0;
Ref<Image> RasterizerStorageGLES3::_get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool &srgb) {
@@ -1412,18 +1427,10 @@ void RasterizerStorageGLES3::sky_set_texture(RID p_sky, RID p_panorama, int p_ra
GLenum format = GL_RGBA;
GLenum type = use_float ? GL_HALF_FLOAT : GL_UNSIGNED_INT_2_10_10_10_REV;
- while (mm_level) {
-
- glTexImage2D(GL_TEXTURE_2D, lod, internal_format, size, size * 2, 0, format, type, NULL);
- lod++;
- mm_level--;
-
- if (size > 1)
- size >>= 1;
- }
+ glTexStorage2DCustom(GL_TEXTURE_2D, mipmaps, internal_format, size, size * 2.0, format, type);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, lod - 1);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mipmaps - 1);
lod = 0;
mm_level = mipmaps;
@@ -1593,6 +1600,7 @@ void RasterizerStorageGLES3::_update_shader(Shader *p_shader) const {
p_shader->spatial.unshaded = false;
p_shader->spatial.ontop = false;
p_shader->spatial.uses_sss = false;
+ p_shader->spatial.uses_vertex_lighting = false;
p_shader->spatial.uses_screen_texture = false;
p_shader->spatial.uses_vertex = false;
p_shader->spatial.writes_modelview_or_projection = false;
@@ -1614,6 +1622,8 @@ void RasterizerStorageGLES3::_update_shader(Shader *p_shader) const {
shaders.actions_scene.render_mode_flags["unshaded"] = &p_shader->spatial.unshaded;
shaders.actions_scene.render_mode_flags["ontop"] = &p_shader->spatial.ontop;
+ shaders.actions_scene.render_mode_flags["vertex_lighting"] = &p_shader->spatial.uses_vertex_lighting;
+
shaders.actions_scene.usage_flag_pointers["ALPHA"] = &p_shader->spatial.uses_alpha;
shaders.actions_scene.usage_flag_pointers["VERTEX"] = &p_shader->spatial.uses_vertex;
@@ -5818,17 +5828,20 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) {
rt->fbo = 0;
}
- if (rt->buffers.fbo) {
+ if (rt->buffers.active) {
glDeleteFramebuffers(1, &rt->buffers.fbo);
glDeleteRenderbuffers(1, &rt->buffers.depth);
glDeleteRenderbuffers(1, &rt->buffers.diffuse);
- glDeleteRenderbuffers(1, &rt->buffers.specular);
- glDeleteRenderbuffers(1, &rt->buffers.normal_rough);
- glDeleteRenderbuffers(1, &rt->buffers.sss);
- glDeleteFramebuffers(1, &rt->buffers.effect_fbo);
- glDeleteTextures(1, &rt->buffers.effect);
+ if (rt->buffers.effects_active) {
+ glDeleteRenderbuffers(1, &rt->buffers.specular);
+ glDeleteRenderbuffers(1, &rt->buffers.normal_rough);
+ glDeleteRenderbuffers(1, &rt->buffers.sss);
+ glDeleteFramebuffers(1, &rt->buffers.effect_fbo);
+ glDeleteTextures(1, &rt->buffers.effect);
+ }
- rt->buffers.fbo = 0;
+ rt->buffers.effects_active = false;
+ rt->buffers.active = false;
}
if (rt->depth) {
@@ -5866,13 +5879,15 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) {
tex->active = false;
for (int i = 0; i < 2; i++) {
- for (int j = 0; j < rt->effects.mip_maps[i].sizes.size(); j++) {
- glDeleteFramebuffers(1, &rt->effects.mip_maps[i].sizes[j].fbo);
- }
+ if (rt->effects.mip_maps[i].color) {
+ for (int j = 0; j < rt->effects.mip_maps[i].sizes.size(); j++) {
+ glDeleteFramebuffers(1, &rt->effects.mip_maps[i].sizes[j].fbo);
+ }
- glDeleteTextures(1, &rt->effects.mip_maps[i].color);
- rt->effects.mip_maps[i].sizes.clear();
- rt->effects.mip_maps[i].levels = 0;
+ glDeleteTextures(1, &rt->effects.mip_maps[i].color);
+ rt->effects.mip_maps[i].sizes.clear();
+ rt->effects.mip_maps[i].levels = 0;
+ }
}
/*
@@ -5899,10 +5914,20 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) {
if (!hdr || rt->flags[RENDER_TARGET_NO_3D]) {
- color_internal_format = GL_RGBA8;
- color_format = GL_RGBA;
- color_type = GL_UNSIGNED_BYTE;
- image_format = Image::FORMAT_RGBA8;
+ if (rt->flags[RENDER_TARGET_NO_3D_EFFECTS] && !rt->flags[RENDER_TARGET_TRANSPARENT]) {
+ //if this is not used, linear colorspace looks pretty bad
+ //this is the default mode used for mobile
+ color_internal_format = GL_RGB10_A2;
+ color_format = GL_RGBA;
+ color_type = GL_UNSIGNED_INT_2_10_10_10_REV;
+ image_format = Image::FORMAT_RGBA8;
+ } else {
+
+ color_internal_format = GL_RGBA8;
+ color_format = GL_RGBA;
+ color_type = GL_UNSIGNED_BYTE;
+ image_format = Image::FORMAT_RGBA8;
+ }
} else {
color_internal_format = GL_RGBA16F;
color_format = GL_RGBA;
@@ -5967,7 +5992,9 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) {
/* BACK FBO */
- if (!rt->flags[RENDER_TARGET_NO_3D]) {
+ if (!rt->flags[RENDER_TARGET_NO_3D] && (!rt->flags[RENDER_TARGET_NO_3D_EFFECTS] || rt->msaa != VS::VIEWPORT_MSAA_DISABLED)) {
+
+ rt->buffers.active = true;
static const int msaa_value[] = { 0, 2, 4, 8, 16 };
int msaa = msaa_value[rt->msaa];
@@ -5997,6 +6024,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) {
if (!rt->flags[RENDER_TARGET_NO_3D_EFFECTS]) {
+ rt->buffers.effects_active = true;
glGenRenderbuffers(1, &rt->buffers.specular);
glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.specular);
@@ -6140,7 +6168,12 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) {
_render_target_clear(rt);
ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE);
}
+ } else {
+ rt->buffers.effects_active = false;
}
+ } else {
+ rt->buffers.active = false;
+ rt->buffers.effects_active = true;
}
if (!rt->flags[RENDER_TARGET_NO_SAMPLING]) {
@@ -6164,8 +6197,6 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) {
while (true) {
RenderTarget::Effects::MipMaps::Size mm;
-
- glTexImage2D(GL_TEXTURE_2D, level, color_internal_format, w, h, 0, color_format, color_type, NULL);
mm.width = w;
mm.height = h;
rt->effects.mip_maps[i].sizes.push_back(mm);
@@ -6179,8 +6210,13 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) {
level++;
}
+ glTexStorage2DCustom(GL_TEXTURE_2D, level + 1, color_internal_format, rt->width, rt->height, color_format, color_type);
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, level);
+ glDisable(GL_SCISSOR_TEST);
+ glColorMask(1, 1, 1, 1);
+ glDepthMask(GL_TRUE);
for (int j = 0; j < rt->effects.mip_maps[i].sizes.size(); j++) {
@@ -6189,6 +6225,11 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) {
glGenFramebuffers(1, &mm.fbo);
glBindFramebuffer(GL_FRAMEBUFFER, mm.fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->effects.mip_maps[i].color, j);
+ bool used_depth = false;
+ if (j == 0 && i == 0 && rt->buffers.active == false && !rt->flags[RENDER_TARGET_NO_3D]) { //will use this one for rendering 3D
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, rt->depth, 0);
+ used_depth = true;
+ }
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
@@ -6197,7 +6238,12 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) {
}
float zero[4] = { 1, 0, 1, 0 };
+ glViewport(0, 0, rt->effects.mip_maps[i].sizes[j].width, rt->effects.mip_maps[i].sizes[j].height);
+
glClearBufferfv(GL_COLOR, 0, zero);
+ if (used_depth) {
+ glClearBufferfi(GL_DEPTH_STENCIL, 0, 1.0, 0);
+ }
}
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
@@ -6838,7 +6884,6 @@ void RasterizerStorageGLES3::initialize() {
int max_extensions = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &max_extensions);
- print_line("GLES3: max extensions: " + itos(max_extensions));
for (int i = 0; i < max_extensions; i++) {
const GLubyte *s = glGetStringi(GL_EXTENSIONS, i);
if (!s)
@@ -6864,7 +6909,6 @@ void RasterizerStorageGLES3::initialize() {
config.hdr_supported = false;
#endif
- print_line("hdr supported: " + itos(config.hdr_supported));
config.pvrtc_supported = config.extensions.has("GL_IMG_texture_compression_pvrtc");
config.srgb_decode_supported = config.extensions.has("GL_EXT_texture_sRGB_decode");
@@ -6997,6 +7041,8 @@ void RasterizerStorageGLES3::initialize() {
}
shaders.cubemap_filter.init();
+ bool ggx_hq = GLOBAL_GET("rendering/quality/reflections/high_quality_ggx.mobile");
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::LOW_QUALITY, !ggx_hq);
shaders.particles.init();
#ifdef GLES_OVER_GL
@@ -7010,6 +7056,28 @@ void RasterizerStorageGLES3::initialize() {
config.keep_original_textures = false;
config.generate_wireframes = false;
config.use_texture_array_environment = GLOBAL_GET("rendering/quality/reflections/texture_array_reflections");
+
+ config.force_vertex_shading = GLOBAL_GET("rendering/quality/shading/force_vertex_shading");
+
+ GLOBAL_DEF("rendering/quality/depth_prepass/disable", false);
+
+ String renderer = (const char *)glGetString(GL_RENDERER);
+
+ config.no_depth_prepass = !bool(GLOBAL_GET("rendering/quality/depth_prepass/enable"));
+ if (!config.no_depth_prepass) {
+
+ String vendors = GLOBAL_GET("rendering/quality/depth_prepass/disable_for_vendors");
+ Vector<String> vendor_match = vendors.split(",");
+ for (int i = 0; i < vendor_match.size(); i++) {
+ String v = vendor_match[i].strip_edges();
+ if (v == String())
+ continue;
+
+ if (renderer.findn(v) != -1) {
+ config.no_depth_prepass = true;
+ }
+ }
+ }
}
void RasterizerStorageGLES3::finalize() {
diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h
index b24da44afd..7d0f3e5745 100644
--- a/drivers/gles3/rasterizer_storage_gles3.h
+++ b/drivers/gles3/rasterizer_storage_gles3.h
@@ -48,6 +48,8 @@ class RasterizerSceneGLES3;
#define _DECODE_EXT 0x8A49
#define _SKIP_DECODE_EXT 0x8A4A
+void glTexStorage2DCustom(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type);
+
class RasterizerStorageGLES3 : public RasterizerStorage {
public:
RasterizerCanvasGLES3 *canvas;
@@ -91,6 +93,9 @@ public:
Set<String> extensions;
bool keep_original_textures;
+
+ bool no_depth_prepass;
+ bool force_vertex_shading;
} config;
mutable struct Shaders {
@@ -444,6 +449,7 @@ public:
bool uses_sss;
bool uses_screen_texture;
bool writes_modelview_or_projection;
+ bool uses_vertex_lighting;
} spatial;
@@ -1193,6 +1199,9 @@ public:
GLuint depth;
struct Buffers {
+
+ bool active;
+ bool effects_active;
GLuint fbo;
GLuint depth;
GLuint specular;
@@ -1282,6 +1291,8 @@ public:
flags[RENDER_TARGET_NO_3D] = false;
flags[RENDER_TARGET_NO_SAMPLING] = false;
flags[RENDER_TARGET_HDR] = true;
+ buffers.active = false;
+ buffers.effects_active = false;
last_exposure_tick = 0;
}
diff --git a/drivers/gles3/shader_gles3.cpp b/drivers/gles3/shader_gles3.cpp
index 33a7c9a22f..f1077e2d20 100644
--- a/drivers/gles3/shader_gles3.cpp
+++ b/drivers/gles3/shader_gles3.cpp
@@ -208,6 +208,7 @@ ShaderGLES3::Version *ShaderGLES3::get_current_version() {
Vector<const char *> strings;
#ifdef GLES_OVER_GL
strings.push_back("#version 330\n");
+ strings.push_back("#define GLES_OVER_GL\n");
#else
strings.push_back("#version 300 es\n");
#endif
diff --git a/drivers/gles3/shaders/copy.glsl b/drivers/gles3/shaders/copy.glsl
index a7c388815d..d33193ee50 100644
--- a/drivers/gles3/shaders/copy.glsl
+++ b/drivers/gles3/shaders/copy.glsl
@@ -49,6 +49,9 @@ void main() {
#define M_PI 3.14159265359
+#if !defined(USE_GLES_OVER_GL)
+precision mediump float;
+#endif
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
in vec3 cube_interp;
@@ -87,14 +90,6 @@ vec4 texturePanorama(vec3 normal,sampler2D pano ) {
#endif
-float sRGB_gamma_correct(float c){
- float a = 0.055;
- if(c < 0.0031308)
- return 12.92*c;
- else
- return (1.0+a)*pow(c, 1.0/2.4) - a;
-}
-
uniform float stuff;
uniform vec2 pixel_size;
@@ -131,7 +126,7 @@ void main() {
vec4 color = texture( source_cube, normalize(cube_interp) );
#else
- vec4 color = texture( source, uv_interp );
+ vec4 color = textureLod( source, uv_interp,0.0 );
#endif
diff --git a/drivers/gles3/shaders/cubemap_filter.glsl b/drivers/gles3/shaders/cubemap_filter.glsl
index ac4e47a440..485fbb6ee0 100644
--- a/drivers/gles3/shaders/cubemap_filter.glsl
+++ b/drivers/gles3/shaders/cubemap_filter.glsl
@@ -204,7 +204,7 @@ vec4 textureDualParaboloidArray(vec3 normal) {
vec3 norm = normalize(normal);
norm.xy/=1.0+abs(norm.z);
norm.xy=norm.xy * vec2(0.5,0.25) + vec2(0.5,0.25);
- if (norm.z<0) {
+ if (norm.z<0.0) {
norm.y=0.5-norm.y+0.5;
}
return textureLod(source_dual_paraboloid_array, vec3(norm.xy, float(source_array_index) ), 0.0);
diff --git a/drivers/gles3/shaders/effect_blur.glsl b/drivers/gles3/shaders/effect_blur.glsl
index 2550335174..09e522866c 100644
--- a/drivers/gles3/shaders/effect_blur.glsl
+++ b/drivers/gles3/shaders/effect_blur.glsl
@@ -25,6 +25,9 @@ void main() {
[fragment]
+#if !defined(GLES_OVER_GL)
+precision mediump float;
+#endif
in vec2 uv_interp;
uniform sampler2D source_color; //texunit:0
diff --git a/drivers/gles3/shaders/particles.glsl b/drivers/gles3/shaders/particles.glsl
index 6a977a201e..a62c124dfe 100644
--- a/drivers/gles3/shaders/particles.glsl
+++ b/drivers/gles3/shaders/particles.glsl
@@ -178,7 +178,7 @@ VERTEX_SHADER_CODE
#if !defined(DISABLE_FORCE)
- if (true) {
+ if (false) {
vec3 force = vec3(0.0);
for(int i=0;i<attractor_count;i++) {
@@ -187,7 +187,7 @@ VERTEX_SHADER_CODE
float dist = length(rel_vec);
if (attractors[i].radius < dist)
continue;
- if (attractors[i].eat_radius>0 && attractors[i].eat_radius > dist) {
+ if (attractors[i].eat_radius>0.0 && attractors[i].eat_radius > dist) {
out_velocity_active.a=0.0;
}
diff --git a/drivers/gles3/shaders/resolve.glsl b/drivers/gles3/shaders/resolve.glsl
index 181a3c99ec..0b50a9c57b 100644
--- a/drivers/gles3/shaders/resolve.glsl
+++ b/drivers/gles3/shaders/resolve.glsl
@@ -15,6 +15,9 @@ void main() {
[fragment]
+#if !defined(GLES_OVER_GL)
+precision mediump float;
+#endif
in vec2 uv_interp;
uniform sampler2D source_specular; //texunit:0
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index 9d474d3902..acece2e639 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -64,44 +64,45 @@ layout(std140) uniform SceneData { //ubo:0
highp mat4 camera_inverse_matrix;
highp mat4 camera_matrix;
- highp vec4 ambient_light_color;
- highp vec4 bg_color;
+ mediump vec4 ambient_light_color;
+ mediump vec4 bg_color;
- vec4 fog_color_enabled;
- vec4 fog_sun_color_amount;
+ mediump vec4 fog_color_enabled;
+ mediump vec4 fog_sun_color_amount;
- float ambient_energy;
- float bg_energy;
+ mediump float ambient_energy;
+ mediump float bg_energy;
- float z_offset;
- float z_slope_scale;
- float shadow_dual_paraboloid_render_zfar;
- float shadow_dual_paraboloid_render_side;
+ mediump float z_offset;
+ mediump float z_slope_scale;
+ highp float shadow_dual_paraboloid_render_zfar;
+ highp float shadow_dual_paraboloid_render_side;
highp vec2 screen_pixel_size;
- vec2 shadow_atlas_pixel_size;
- vec2 directional_shadow_pixel_size;
+ highp vec2 shadow_atlas_pixel_size;
+ highp vec2 directional_shadow_pixel_size;
- float time;
- float z_far;
- float reflection_multiplier;
- float subsurface_scatter_width;
- float ambient_occlusion_affect_light;
+ highp float time;
+ highp float z_far;
+ mediump float reflection_multiplier;
+ mediump float subsurface_scatter_width;
+ mediump float ambient_occlusion_affect_light;
bool fog_depth_enabled;
- float fog_depth_begin;
- float fog_depth_curve;
+ highp float fog_depth_begin;
+ highp float fog_depth_curve;
bool fog_transmit_enabled;
- float fog_transmit_curve;
+ highp float fog_transmit_curve;
bool fog_height_enabled;
- float fog_height_min;
- float fog_height_max;
- float fog_height_curve;
+ highp float fog_height_min;
+ highp float fog_height_max;
+ highp float fog_height_curve;
};
uniform highp mat4 world_transform;
+
#ifdef USE_LIGHT_DIRECTIONAL
layout(std140) uniform DirectionalLightData { //ubo:3
@@ -121,6 +122,90 @@ layout(std140) uniform DirectionalLightData { //ubo:3
#endif
+#ifdef USE_VERTEX_LIGHTING
+//omni and spot
+
+struct LightData {
+
+ highp vec4 light_pos_inv_radius;
+ mediump vec4 light_direction_attenuation;
+ mediump vec4 light_color_energy;
+ mediump vec4 light_params; //cone attenuation, angle, specular, shadow enabled,
+ mediump vec4 light_clamp;
+ mediump vec4 shadow_color_contact;
+ highp mat4 shadow_matrix;
+
+};
+
+
+layout(std140) uniform OmniLightData { //ubo:4
+
+ LightData omni_lights[MAX_LIGHT_DATA_STRUCTS];
+};
+
+layout(std140) uniform SpotLightData { //ubo:5
+
+ LightData spot_lights[MAX_LIGHT_DATA_STRUCTS];
+};
+
+#ifdef USE_FORWARD_LIGHTING
+
+
+uniform int omni_light_indices[MAX_FORWARD_LIGHTS];
+uniform int omni_light_count;
+
+uniform int spot_light_indices[MAX_FORWARD_LIGHTS];
+uniform int spot_light_count;
+
+#endif
+
+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;
+
+ if (roughness > 0.0) {
+
+ vec3 H = normalize(V + L);
+ float dotNH = max(dot(N,H), 0.0 );
+ float intensity = pow( dotNH, (1.0-roughness) * 256.0);
+ specular += light_color * intensity;
+
+ }
+}
+
+void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal, float roughness,inout vec3 diffuse, inout vec3 specular) {
+
+ vec3 light_rel_vec = omni_lights[idx].light_pos_inv_radius.xyz-vertex;
+ float light_length = length( light_rel_vec );
+ float normalized_distance = light_length*omni_lights[idx].light_pos_inv_radius.w;
+ vec3 light_attenuation = vec3(pow( max(1.0 - normalized_distance, 0.0), omni_lights[idx].light_direction_attenuation.w ));
+
+ light_compute(normal,normalize(light_rel_vec),eye_vec,omni_lights[idx].light_color_energy.rgb * light_attenuation,roughness,diffuse,specular);
+
+}
+
+void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, float roughness, inout vec3 diffuse, inout vec3 specular) {
+
+ vec3 light_rel_vec = spot_lights[idx].light_pos_inv_radius.xyz-vertex;
+ float light_length = length( light_rel_vec );
+ float normalized_distance = light_length*spot_lights[idx].light_pos_inv_radius.w;
+ vec3 light_attenuation = vec3(pow( max(1.0 - normalized_distance, 0.001), spot_lights[idx].light_direction_attenuation.w ));
+ vec3 spot_dir = spot_lights[idx].light_direction_attenuation.xyz;
+ float spot_cutoff=spot_lights[idx].light_params.y;
+ float scos = max(dot(-normalize(light_rel_vec), spot_dir),spot_cutoff);
+ float spot_rim = (1.0 - scos) / (1.0 - spot_cutoff);
+ light_attenuation *= 1.0 - pow( max(spot_rim,0.001), spot_lights[idx].light_params.x);
+
+
+ light_compute(normal,normalize(light_rel_vec),eye_vec,spot_lights[idx].light_color_energy.rgb*light_attenuation,roughness,diffuse,specular);
+}
+
+
+#endif
/* Varyings */
@@ -288,6 +373,8 @@ void main() {
#endif
#endif
+ float roughness=0.0;
+
//defines that make writing custom shaders easier
#define projection_matrix local_projection
#define world_transform world_matrix
@@ -376,6 +463,54 @@ VERTEX_SHADER_CODE
#endif
position_interp=gl_Position;
+
+#ifdef USE_VERTEX_LIGHTING
+
+ diffuse_light_interp=vec4(0.0);
+ specular_light_interp=vec4(0.0);
+
+#ifdef USE_FORWARD_LIGHTING
+
+ for(int i=0;i<omni_light_count;i++) {
+ light_process_omni(omni_light_indices[i],vertex_interp,-normalize( vertex_interp ),normal_interp,roughness,diffuse_light_interp.rgb,specular_light_interp.rgb);
+ }
+
+ for(int i=0;i<spot_light_count;i++) {
+ light_process_spot(spot_light_indices[i],vertex_interp,-normalize( vertex_interp ),normal_interp,roughness,diffuse_light_interp.rgb,specular_light_interp.rgb);
+ }
+#endif
+
+#ifdef USE_LIGHT_DIRECTIONAL
+
+ vec3 directional_diffuse = vec3(0.0);
+ vec3 directional_specular = vec3(0.0);
+ light_compute(normal_interp,-light_direction_attenuation.xyz,-normalize( vertex_interp ),normal_interp,roughness,directional_diffuse,directional_specular);
+
+ float diff_avg = dot(diffuse_light_interp.rgb,vec3(0.33333));
+ float diff_dir_avg = dot(directional_diffuse,vec3(0.33333));
+ if (diff_avg>0.0) {
+ diffuse_light_interp.a=diff_dir_avg/(diff_avg+diff_dir_avg);
+ } else {
+ diffuse_light_interp.a=1.0;
+ }
+
+ diffuse_light_interp.rgb+=directional_diffuse;
+
+ float spec_avg = dot(specular_light_interp.rgb,vec3(0.33333));
+ float spec_dir_avg = dot(directional_specular,vec3(0.33333));
+ if (spec_avg>0.0) {
+ specular_light_interp.a=spec_dir_avg/(spec_avg+spec_dir_avg);
+ } else {
+ specular_light_interp.a=1.0;
+ }
+
+ specular_light_interp.rgb+=directional_specular;
+
+#endif //USE_LIGHT_DIRECTIONAL
+
+
+#endif // USE_VERTEX_LIGHTING
+
}
@@ -455,7 +590,7 @@ vec3 textureDualParaboloid(sampler2DArray p_tex, vec3 p_vec,float p_roughness) {
// we need to lie the derivatives (normg) and assume that DP side is always the same
// to get proper texure filtering
vec2 normg=norm.xy;
- if (norm.z>0) {
+ if (norm.z>0.0) {
norm.y=0.5-norm.y+0.5;
}
@@ -479,7 +614,7 @@ vec3 textureDualParaboloid(sampler2D p_tex, vec3 p_vec,float p_roughness) {
vec3 norm = normalize(p_vec);
norm.xy/=1.0+abs(norm.z);
norm.xy=norm.xy * vec2(0.5,0.25) + vec2(0.5,0.25);
- if (norm.z>0) {
+ if (norm.z>0.0) {
norm.y=0.5-norm.y+0.5;
}
return textureLod(p_tex, norm.xy, p_roughness * RADIANCE_MAX_LOD).xyz;
@@ -511,39 +646,39 @@ layout(std140) uniform SceneData {
highp mat4 camera_inverse_matrix;
highp mat4 camera_matrix;
- highp vec4 ambient_light_color;
- highp vec4 bg_color;
+ mediump vec4 ambient_light_color;
+ mediump vec4 bg_color;
- vec4 fog_color_enabled;
- vec4 fog_sun_color_amount;
+ mediump vec4 fog_color_enabled;
+ mediump vec4 fog_sun_color_amount;
- float ambient_energy;
- float bg_energy;
+ mediump float ambient_energy;
+ mediump float bg_energy;
- float z_offset;
- float z_slope_scale;
- float shadow_dual_paraboloid_render_zfar;
- float shadow_dual_paraboloid_render_side;
+ mediump float z_offset;
+ mediump float z_slope_scale;
+ highp float shadow_dual_paraboloid_render_zfar;
+ highp float shadow_dual_paraboloid_render_side;
highp vec2 screen_pixel_size;
- vec2 shadow_atlas_pixel_size;
- vec2 directional_shadow_pixel_size;
+ highp vec2 shadow_atlas_pixel_size;
+ highp vec2 directional_shadow_pixel_size;
- float time;
- float z_far;
- float reflection_multiplier;
- float subsurface_scatter_width;
- float ambient_occlusion_affect_light;
+ highp float time;
+ highp float z_far;
+ mediump float reflection_multiplier;
+ mediump float subsurface_scatter_width;
+ mediump float ambient_occlusion_affect_light;
bool fog_depth_enabled;
- float fog_depth_begin;
- float fog_depth_curve;
+ highp float fog_depth_begin;
+ highp float fog_depth_curve;
bool fog_transmit_enabled;
- float fog_transmit_curve;
+ highp float fog_transmit_curve;
bool fog_height_enabled;
- float fog_height_min;
- float fog_height_max;
- float fog_height_curve;
+ highp float fog_height_min;
+ highp float fog_height_max;
+ highp float fog_height_curve;
};
//directional light data
@@ -570,6 +705,10 @@ uniform highp sampler2DShadow directional_shadow; //texunit:-4
#endif
+#ifdef USE_VERTEX_LIGHTING
+in vec4 diffuse_light_interp;
+in vec4 specular_light_interp;
+#endif
//omni and spot
struct LightData {
@@ -655,6 +794,8 @@ layout(location=0) out vec4 frag_color;
in highp vec4 position_interp;
uniform highp sampler2D depth_buffer; //texunit:-8
+#ifdef USE_CONTACT_SHADOWS
+
float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) {
if (abs(dir.z)>0.99)
@@ -715,6 +856,8 @@ float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) {
return 1.0;
}
+#endif
+
// GGX Specular
// Source: http://www.filmicworlds.com/images/ggx-opt/optimized-ggx.hlsl
float G1V(float dotNV, float k)
@@ -1010,13 +1153,16 @@ void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 bino
splane.xy = clamp_rect.xy+splane.xy*clamp_rect.zw;
float shadow = sample_shadow(shadow_atlas,shadow_atlas_pixel_size,splane.xy,splane.z,clamp_rect);
+
+#ifdef USE_CONTACT_SHADOWS
+
if (shadow>0.01 && omni_lights[idx].shadow_color_contact.a>0.0) {
float contact_shadow = contact_shadow_compute(vertex,normalize(light_rel_vec),min(light_length,omni_lights[idx].shadow_color_contact.a));
shadow=min(shadow,contact_shadow);
-
}
+#endif
light_attenuation*=mix(omni_lights[idx].shadow_color_contact.rgb,vec3(1.0),shadow);
}
@@ -1043,13 +1189,14 @@ void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 bi
float shadow = sample_shadow(shadow_atlas,shadow_atlas_pixel_size,splane.xy,splane.z,spot_lights[idx].light_clamp);
+#ifdef USE_CONTACT_SHADOWS
if (shadow>0.01 && spot_lights[idx].shadow_color_contact.a>0.0) {
float contact_shadow = contact_shadow_compute(vertex,normalize(light_rel_vec),min(light_length,spot_lights[idx].shadow_color_contact.a));
shadow=min(shadow,contact_shadow);
}
-
+#endif
light_attenuation*=mix(spot_lights[idx].shadow_color_contact.rgb,vec3(1.0),shadow);
}
@@ -1097,7 +1244,7 @@ void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 ta
vec3 norm = normalize(local_ref_vec);
norm.xy/=1.0+abs(norm.z);
norm.xy=norm.xy * vec2(0.5,0.25) + vec2(0.5,0.25);
- if (norm.z>0) {
+ if (norm.z>0.0) {
norm.y=0.5-norm.y+0.5;
}
@@ -1460,9 +1607,18 @@ FRAGMENT_SHADER_CODE
//apply energy conservation
+#ifdef USE_VERTEX_LIGHTING
+
+ vec3 specular_light = specular_light_interp.rgb;
+ vec3 diffuse_light = diffuse_light_interp.rgb;
+#else
+
vec3 specular_light = vec3(0.0,0.0,0.0);
- vec3 ambient_light;
vec3 diffuse_light = vec3(0.0,0.0,0.0);
+
+#endif
+
+ vec3 ambient_light;
vec3 env_reflection_light = vec3(0.0,0.0,0.0);
vec3 eye_vec = -normalize( vertex_interp );
@@ -1515,7 +1671,7 @@ FRAGMENT_SHADER_CODE
specular_blob_intensity*=specular * 2.0;
#endif
-#ifdef USE_LIGHT_DIRECTIONAL
+#if defined(USE_LIGHT_DIRECTIONAL)
vec3 light_attenuation=vec3(1.0);
@@ -1640,13 +1796,14 @@ FRAGMENT_SHADER_CODE
}
#endif
+#ifdef USE_CONTACT_SHADOWS
if (shadow>0.01 && shadow_color_contact.a>0.0) {
float contact_shadow = contact_shadow_compute(vertex,-light_direction_attenuation.xyz,shadow_color_contact.a);
shadow=min(shadow,contact_shadow);
}
-
+#endif
light_attenuation=mix(shadow_color_contact.rgb,vec3(1.0),shadow);
@@ -1654,7 +1811,13 @@ FRAGMENT_SHADER_CODE
#endif //LIGHT_DIRECTIONAL_SHADOW
+#ifdef USE_VERTEX_LIGHTING
+ diffuse_light*=mix(vec3(1.0),light_attenuation,diffuse_light_interp.a);
+ specular_light*=mix(vec3(1.0),light_attenuation,specular_light_interp.a);
+
+#else
light_compute(normal,-light_direction_attenuation.xyz,eye_vec,binormal,tangent,light_color_energy.rgb*light_attenuation,albedo,light_params.z*specular_blob_intensity,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light);
+#endif
#endif //#USE_LIGHT_DIRECTIONAL
@@ -1664,12 +1827,11 @@ FRAGMENT_SHADER_CODE
#endif
-
#ifdef USE_FORWARD_LIGHTING
+
highp vec4 reflection_accum = vec4(0.0,0.0,0.0,0.0);
highp vec4 ambient_accum = vec4(0.0,0.0,0.0,0.0);
-
for(int i=0;i<reflection_count;i++) {
reflection_process(reflection_indices[i],vertex,normal,binormal,tangent,roughness,anisotropy,ambient_light,env_reflection_light,reflection_accum,ambient_accum);
}
@@ -1684,6 +1846,13 @@ FRAGMENT_SHADER_CODE
ambient_light+=ambient_accum.rgb/ambient_accum.a;
}
+
+
+#ifdef USE_VERTEX_LIGHTING
+
+ diffuse_light*=albedo;
+#else
+
for(int i=0;i<omni_light_count;i++) {
light_process_omni(omni_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,specular_blob_intensity,diffuse_light,specular_light);
}
@@ -1692,15 +1861,13 @@ FRAGMENT_SHADER_CODE
light_process_spot(spot_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,specular_blob_intensity,diffuse_light,specular_light);
}
-
+#endif //USE_VERTEX_LIGHTING
#endif
-
-
#ifdef RENDER_DEPTH
//nothing happens, so a tree-ssa optimizer will result in no fragment shader :)
#else
@@ -1713,13 +1880,11 @@ FRAGMENT_SHADER_CODE
#endif
-
-
-
-
//energu conservation
diffuse_light=mix(diffuse_light,vec3(0.0),metallic);
ambient_light=mix(ambient_light,vec3(0.0),metallic);
+
+
{
#if defined(DIFFUSE_TOON)
@@ -1744,7 +1909,7 @@ FRAGMENT_SHADER_CODE
if (fog_color_enabled.a > 0.5) {
- float fog_amount=0;
+ float fog_amount=0.0;
diff --git a/drivers/gles3/shaders/tonemap.glsl b/drivers/gles3/shaders/tonemap.glsl
index 3ce2edf4e9..c6dfc6917d 100644
--- a/drivers/gles3/shaders/tonemap.glsl
+++ b/drivers/gles3/shaders/tonemap.glsl
@@ -18,6 +18,10 @@ void main() {
[fragment]
+#if !defined(GLES_OVER_GL)
+precision mediump float;
+#endif
+
in vec2 uv_interp;