diff options
Diffstat (limited to 'drivers/gles3')
-rw-r--r-- | drivers/gles3/rasterizer_canvas_gles3.cpp | 139 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_canvas_gles3.h | 5 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_gles3.cpp | 1 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.cpp | 6 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.h | 2 | ||||
-rw-r--r-- | drivers/gles3/shader_compiler_gles3.cpp | 4 | ||||
-rw-r--r-- | drivers/gles3/shader_gles3.cpp | 33 | ||||
-rw-r--r-- | drivers/gles3/shaders/canvas.glsl | 15 | ||||
-rw-r--r-- | drivers/gles3/shaders/copy.glsl | 13 | ||||
-rw-r--r-- | drivers/gles3/shaders/effect_blur.glsl | 12 | ||||
-rw-r--r-- | drivers/gles3/shaders/particles.glsl | 7 | ||||
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 7 |
12 files changed, 182 insertions, 62 deletions
diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index c71bf22965..8c3569bec0 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -28,10 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "rasterizer_canvas_gles3.h" -#include "servers/visual/visual_server_raster.h" - #include "global_config.h" #include "os/os.h" +#include "rasterizer_scene_gles3.h" +#include "servers/visual/visual_server_raster.h" #ifndef GLES_OVER_GL #define glClearDepth glClearDepthf #endif @@ -172,6 +172,11 @@ void RasterizerCanvasGLES3::canvas_begin() { state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, Color(1, 1, 1, 1)); state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, Transform2D()); state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, Transform2D()); + if (storage->frame.current_rt) { + state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height)); + } else { + state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0, 1.0)); + } //state.canvas_shader.set_uniform(CanvasShaderGLES3::PROJECTION_MATRIX,state.vp); //state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,Transform()); @@ -282,7 +287,11 @@ void RasterizerCanvasGLES3::_set_texture_rect_mode(bool p_enable, bool p_ninepat state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, state.canvas_item_modulate); state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform); state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, state.extra_matrix); - + if (storage->frame.current_rt) { + state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height)); + } else { + state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0, 1.0)); + } state.using_texture_rect = p_enable; state.using_ninepatch = p_ninepatch; } @@ -822,6 +831,78 @@ void RasterizerGLES2::_canvas_item_setup_shader_params(ShaderMaterial *material, #endif +void RasterizerCanvasGLES3::_copy_texscreen(const Rect2 &p_rect) { + + state.canvas_texscreen_used = true; + //blur diffuse into effect mipmaps using separatable convolution + //storage->shaders.copy.set_conditional(CopyShaderGLES3::GAUSSIAN_HORIZONTAL,true); + + Vector2 wh(storage->frame.current_rt->width, storage->frame.current_rt->height); + + Color blur_section(p_rect.position.x / wh.x, p_rect.position.y / wh.y, p_rect.size.x / wh.x, p_rect.size.y / wh.y); + + if (p_rect != Rect2()) { + + scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::USE_BLUR_SECTION, true); + storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_COPY_SECTION, true); + } + + glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color); + + storage->shaders.copy.bind(); + storage->shaders.copy.set_uniform(CopyShaderGLES3::COPY_SECTION, blur_section); + + scene_render->_copy_screen(); + + for (int i = 0; i < storage->frame.current_rt->effects.mip_maps[1].sizes.size(); i++) { + + int vp_w = storage->frame.current_rt->effects.mip_maps[1].sizes[i].width; + int vp_h = storage->frame.current_rt->effects.mip_maps[1].sizes[i].height; + glViewport(0, 0, vp_w, vp_h); + //horizontal pass + scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_HORIZONTAL, true); + scene_render->state.effect_blur_shader.bind(); + scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h)); + scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(i)); + scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::BLUR_SECTION, blur_section); + 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); + + scene_render->_copy_screen(); + + scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_HORIZONTAL, false); + + //vertical pass + scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_VERTICAL, true); + scene_render->state.effect_blur_shader.bind(); + scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h)); + scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(i)); + scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::BLUR_SECTION, blur_section); + 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 + + scene_render->_copy_screen(); + + scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_VERTICAL, false); + } + + scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::USE_BLUR_SECTION, false); + storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_COPY_SECTION, false); + + glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); //back to front + glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height); + state.canvas_shader.bind(); //back to canvas + + if (state.using_texture_rect) { + state.using_texture_rect = false; + _set_texture_rect_mode(state.using_texture_rect, state.using_ninepatch); + } +} + void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light) { Item *current_clip = NULL; @@ -875,44 +956,17 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, cons glDisable(GL_SCISSOR_TEST); } } -#if 0 - if (ci->copy_back_buffer && framebuffer.active && framebuffer.scale==1) { - Rect2 rect; - int x,y; + if (ci->copy_back_buffer) { if (ci->copy_back_buffer->full) { - x = viewport.x; - y = window_size.height-(viewport.height+viewport.y); - } else { - x = viewport.x+ci->copy_back_buffer->screen_rect.pos.x; - y = window_size.height-(viewport.y+ci->copy_back_buffer->screen_rect.pos.y+ci->copy_back_buffer->screen_rect.size.y); - } - glActiveTexture(GL_TEXTURE0+max_texture_units-1); - glBindTexture(GL_TEXTURE_2D,framebuffer.sample_color); - -#ifdef GLEW_ENABLED - if (current_rt) { - glReadBuffer(GL_COLOR_ATTACHMENT0); - } else { - glReadBuffer(GL_BACK); - } -#endif - if (current_rt) { - glCopyTexSubImage2D(GL_TEXTURE_2D,0,viewport.x,viewport.y,viewport.x,viewport.y,viewport.width,viewport.height); - //window_size.height-(viewport.height+viewport.y) + _copy_texscreen(Rect2()); } else { - glCopyTexSubImage2D(GL_TEXTURE_2D,0,x,y,x,y,viewport.width,viewport.height); + _copy_texscreen(ci->copy_back_buffer->rect); } - - canvas_texscreen_used=true; - glActiveTexture(GL_TEXTURE0); - } -#endif - //begin rect Item *material_owner = ci->material_owner ? ci->material_owner : ci; @@ -934,6 +988,11 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, cons if (shader_ptr && shader_ptr != shader_cache) { + if (shader_ptr->canvas_item.uses_screen_texture && !state.canvas_texscreen_used) { + //copy if not copied before + _copy_texscreen(Rect2()); + } + state.canvas_shader.set_custom_shader(shader_ptr->custom_code_id); state.canvas_shader.bind(); @@ -1046,7 +1105,11 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, cons state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, state.canvas_item_modulate); state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform); state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, state.extra_matrix); - + if (storage->frame.current_rt) { + state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height)); + } else { + state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0, 1.0)); + } if (unshaded || (state.canvas_item_modulate.a > 0.001 && (!shader_cache || shader_cache->canvas_item.light_mode != RasterizerStorageGLES3::Shader::CanvasItem::LIGHT_MODE_LIGHT_ONLY) && !ci->light_masked)) _canvas_item_render_commands(ci, current_clip, reclip); @@ -1376,6 +1439,12 @@ void RasterizerCanvasGLES3::reset_canvas() { glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + //use for reading from screen + if (storage->frame.current_rt) { + glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 3); + glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); + } + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex); @@ -1543,7 +1612,7 @@ void RasterizerCanvasGLES3::initialize() { glBindBuffer(GL_UNIFORM_BUFFER, 0); state.canvas_shader.init(); - state.canvas_shader.set_base_material_tex_index(1); + state.canvas_shader.set_base_material_tex_index(2); state.canvas_shadow_shader.init(); state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_RGBA_SHADOWS, storage->config.use_rgba_2d_shadows); diff --git a/drivers/gles3/rasterizer_canvas_gles3.h b/drivers/gles3/rasterizer_canvas_gles3.h index 5859820364..ee018e15ea 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.h +++ b/drivers/gles3/rasterizer_canvas_gles3.h @@ -34,6 +34,8 @@ #include "servers/visual/rasterizer.h" #include "shaders/canvas_shadow.glsl.gen.h" +class RasterizerSceneGLES3; + class RasterizerCanvasGLES3 : public RasterizerCanvas { public: struct CanvasItemUBO { @@ -42,6 +44,8 @@ public: float time; }; + RasterizerSceneGLES3 *scene_render; + struct Data { GLuint canvas_quad_vertices; @@ -118,6 +122,7 @@ public: _FORCE_INLINE_ void _draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs); _FORCE_INLINE_ void _draw_polygon(const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor); _FORCE_INLINE_ void _canvas_item_render_commands(Item *p_item, Item *current_clip, bool &reclip); + _FORCE_INLINE_ void _copy_texscreen(const Rect2 &p_rect); virtual void canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light); virtual void canvas_debug_viewport_shadows(Light *p_lights_with_shadow); diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index 53df7e9c3d..0cfa8a7d6e 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -412,6 +412,7 @@ RasterizerGLES3::RasterizerGLES3() { canvas = memnew(RasterizerCanvasGLES3); scene = memnew(RasterizerSceneGLES3); canvas->storage = storage; + canvas->scene_render = scene; storage->canvas = canvas; scene->storage = storage; storage->scene = scene; diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 24a57b772b..b1dc32e1c0 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -1445,6 +1445,8 @@ void RasterizerStorageGLES3::_update_shader(Shader *p_shader) const { p_shader->canvas_item.light_mode = Shader::CanvasItem::LIGHT_MODE_NORMAL; p_shader->canvas_item.blend_mode = Shader::CanvasItem::BLEND_MODE_MIX; + p_shader->canvas_item.uses_screen_texture = false; + p_shader->canvas_item.uses_screen_uv = false; shaders.actions_canvas.render_mode_values["blend_add"] = Pair<int *, int>(&p_shader->canvas_item.blend_mode, Shader::CanvasItem::BLEND_MODE_ADD); shaders.actions_canvas.render_mode_values["blend_mix"] = Pair<int *, int>(&p_shader->canvas_item.blend_mode, Shader::CanvasItem::BLEND_MODE_MIX); @@ -1455,6 +1457,10 @@ void RasterizerStorageGLES3::_update_shader(Shader *p_shader) const { shaders.actions_canvas.render_mode_values["unshaded"] = Pair<int *, int>(&p_shader->canvas_item.light_mode, Shader::CanvasItem::LIGHT_MODE_UNSHADED); shaders.actions_canvas.render_mode_values["light_only"] = Pair<int *, int>(&p_shader->canvas_item.light_mode, Shader::CanvasItem::LIGHT_MODE_LIGHT_ONLY); + shaders.actions_canvas.usage_flag_pointers["SCREEN_UV"] = &p_shader->canvas_item.uses_screen_uv; + shaders.actions_canvas.usage_flag_pointers["SCREEN_PIXEL_SIZE"] = &p_shader->canvas_item.uses_screen_uv; + shaders.actions_canvas.usage_flag_pointers["SCREEN_TEXTURE"] = &p_shader->canvas_item.uses_screen_texture; + actions = &shaders.actions_canvas; actions->uniforms = &p_shader->uniforms; diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index 2ef47fe2cb..3f8055d613 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -401,6 +401,8 @@ public: }; int light_mode; + bool uses_screen_texture; + bool uses_screen_uv; } canvas_item; diff --git a/drivers/gles3/shader_compiler_gles3.cpp b/drivers/gles3/shader_compiler_gles3.cpp index 41421a3e2f..6c568714f8 100644 --- a/drivers/gles3/shader_compiler_gles3.cpp +++ b/drivers/gles3/shader_compiler_gles3.cpp @@ -680,7 +680,8 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() { actions[VS::SHADER_CANVAS_ITEM].renames["TEXTURE_PIXEL_SIZE"] = "color_texpixel_size"; actions[VS::SHADER_CANVAS_ITEM].renames["SCREEN_UV"] = "screen_uv"; actions[VS::SHADER_CANVAS_ITEM].renames["SCREEN_TEXTURE"] = "screen_texture"; - actions[VS::SHADER_CANVAS_ITEM].renames["POSITION"] = "(gl_FragCoord.xy)"; + actions[VS::SHADER_CANVAS_ITEM].renames["SCREEN_PIXEL_SIZE"] = "screen_pixel_size"; + actions[VS::SHADER_CANVAS_ITEM].renames["FRAGCOORD"] = "gl_FragCoord"; actions[VS::SHADER_CANVAS_ITEM].renames["POINT_COORD"] = "gl_PointCoord"; actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_VEC"] = "light_vec"; @@ -694,6 +695,7 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() { actions[VS::SHADER_CANVAS_ITEM].usage_defines["COLOR"] = "#define COLOR_USED\n"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_TEXTURE"] = "#define SCREEN_TEXTURE_USED\n"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_UV"] = "#define SCREEN_UV_USED\n"; + actions[VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_PIXEL_SIZE"] = "@SCREEN_UV"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMAL"] = "#define NORMAL_USED\n"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMALMAP"] = "#define NORMALMAP_USED\n"; actions[VS::SHADER_CANVAS_ITEM].usage_defines["SHADOW_COLOR"] = "#define SHADOW_COLOR_USED\n"; diff --git a/drivers/gles3/shader_gles3.cpp b/drivers/gles3/shader_gles3.cpp index e08ef0ad12..c821acadf5 100644 --- a/drivers/gles3/shader_gles3.cpp +++ b/drivers/gles3/shader_gles3.cpp @@ -289,16 +289,17 @@ ShaderGLES3::Version *ShaderGLES3::get_current_version() { #endif strings.push_back(vertex_code0.get_data()); + if (cc) { - code_globals = cc->vertex_globals.ascii(); - strings.push_back(code_globals.get_data()); + material_string = cc->uniforms.ascii(); + strings.push_back(material_string.get_data()); } strings.push_back(vertex_code1.get_data()); if (cc) { - material_string = cc->uniforms.ascii(); - strings.push_back(material_string.get_data()); + code_globals = cc->vertex_globals.ascii(); + strings.push_back(code_globals.get_data()); } strings.push_back(vertex_code2.get_data()); @@ -387,15 +388,15 @@ ShaderGLES3::Version *ShaderGLES3::get_current_version() { strings.push_back(fragment_code0.get_data()); if (cc) { - code_globals = cc->fragment_globals.ascii(); - strings.push_back(code_globals.get_data()); + material_string = cc->uniforms.ascii(); + strings.push_back(material_string.get_data()); } strings.push_back(fragment_code1.get_data()); if (cc) { - material_string = cc->uniforms.ascii(); - strings.push_back(material_string.get_data()); + code_globals = cc->fragment_globals.ascii(); + strings.push_back(code_globals.get_data()); } strings.push_back(fragment_code2.get_data()); @@ -617,21 +618,21 @@ void ShaderGLES3::setup(const char **p_conditional_defines, int p_conditional_co String material_tag = "\nMATERIAL_UNIFORMS"; String code_tag = "\nVERTEX_SHADER_CODE"; String code = vertex_code; - int cpos = code.find(globals_tag); + int cpos = code.find(material_tag); if (cpos == -1) { vertex_code0 = code.ascii(); } else { vertex_code0 = code.substr(0, cpos).ascii(); - code = code.substr(cpos + globals_tag.length(), code.length()); + code = code.substr(cpos + material_tag.length(), code.length()); - cpos = code.find(material_tag); + cpos = code.find(globals_tag); if (cpos == -1) { vertex_code1 = code.ascii(); } else { vertex_code1 = code.substr(0, cpos).ascii(); - String code2 = code.substr(cpos + material_tag.length(), code.length()); + String code2 = code.substr(cpos + globals_tag.length(), code.length()); cpos = code2.find(code_tag); if (cpos == -1) { @@ -651,14 +652,14 @@ void ShaderGLES3::setup(const char **p_conditional_defines, int p_conditional_co String code_tag = "\nFRAGMENT_SHADER_CODE"; String light_code_tag = "\nLIGHT_SHADER_CODE"; String code = fragment_code; - int cpos = code.find(globals_tag); + int cpos = code.find(material_tag); if (cpos == -1) { fragment_code0 = code.ascii(); } else { fragment_code0 = code.substr(0, cpos).ascii(); //print_line("CODE0:\n"+String(fragment_code0.get_data())); - code = code.substr(cpos + globals_tag.length(), code.length()); - cpos = code.find(material_tag); + code = code.substr(cpos + material_tag.length(), code.length()); + cpos = code.find(globals_tag); if (cpos == -1) { fragment_code1 = code.ascii(); @@ -667,7 +668,7 @@ void ShaderGLES3::setup(const char **p_conditional_defines, int p_conditional_co fragment_code1 = code.substr(0, cpos).ascii(); //print_line("CODE1:\n"+String(fragment_code1.get_data())); - String code2 = code.substr(cpos + material_tag.length(), code.length()); + String code2 = code.substr(cpos + globals_tag.length(), code.length()); cpos = code2.find(light_code_tag); if (cpos == -1) { diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index e97ce62daa..31bae66278 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -90,7 +90,6 @@ uniform int h_frames; uniform int v_frames; #endif -VERTEX_SHADER_GLOBALS #if defined(USE_MATERIAL) @@ -102,6 +101,8 @@ MATERIAL_UNIFORMS #endif +VERTEX_SHADER_GLOBALS + void main() { vec4 vertex_color = color_attrib; @@ -211,6 +212,11 @@ uniform sampler2D screen_texture; // texunit:-3 #endif +#if defined(SCREEN_UV_USED) + +uniform vec2 screen_pixel_size; +#endif + layout(std140) uniform CanvasItemData { highp mat4 projection_matrix; @@ -256,7 +262,7 @@ const bool at_light_pass = false; uniform mediump vec4 final_modulate; -FRAGMENT_SHADER_GLOBALS + layout(location=0) out mediump vec4 frag_color; @@ -272,6 +278,7 @@ MATERIAL_UNIFORMS #endif +FRAGMENT_SHADER_GLOBALS void light_compute(inout vec3 light,vec3 light_vec,float light_height,vec4 light_color,vec2 light_uv,vec4 shadow,vec3 normal,vec2 uv,vec2 screen_uv,vec4 color) { @@ -410,8 +417,8 @@ void main() { -#if defined(ENABLE_SCREEN_UV) - vec2 screen_uv = gl_FragCoord.xy*screen_uv_mult; +#if defined(SCREEN_UV_USED) + vec2 screen_uv = gl_FragCoord.xy*screen_pixel_size; #endif diff --git a/drivers/gles3/shaders/copy.glsl b/drivers/gles3/shaders/copy.glsl index b0fb525e20..a7c388815d 100644 --- a/drivers/gles3/shaders/copy.glsl +++ b/drivers/gles3/shaders/copy.glsl @@ -17,6 +17,12 @@ out vec2 uv_interp; out vec2 uv2_interp; +#ifdef USE_COPY_SECTION + +uniform vec4 copy_section; + +#endif + void main() { #if defined(USE_CUBEMAP) || defined(USE_PANORAMA) @@ -30,6 +36,13 @@ void main() { #endif uv2_interp = uv2_in; gl_Position = vertex_attrib; + +#ifdef USE_COPY_SECTION + + uv_interp = copy_section.xy + uv_interp * copy_section.zw; + gl_Position.xy = (copy_section.xy + (gl_Position.xy * 0.5 + 0.5) * copy_section.zw) * 2.0 - 1.0; +#endif + } [fragment] diff --git a/drivers/gles3/shaders/effect_blur.glsl b/drivers/gles3/shaders/effect_blur.glsl index 89afa12f60..8ca8e21f11 100644 --- a/drivers/gles3/shaders/effect_blur.glsl +++ b/drivers/gles3/shaders/effect_blur.glsl @@ -6,11 +6,21 @@ layout(location=4) in vec2 uv_in; out vec2 uv_interp; +#ifdef USE_BLUR_SECTION + +uniform vec4 blur_section; + +#endif void main() { - uv_interp = uv_in; + uv_interp = uv_in; gl_Position = vertex_attrib; +#ifdef USE_BLUR_SECTION + + uv_interp = blur_section.xy + uv_interp * blur_section.zw; + gl_Position.xy = (blur_section.xy + (gl_Position.xy * 0.5 + 0.5) * blur_section.zw) * 2.0 - 1.0; +#endif } [fragment] diff --git a/drivers/gles3/shaders/particles.glsl b/drivers/gles3/shaders/particles.glsl index ec2577538c..6a977a201e 100644 --- a/drivers/gles3/shaders/particles.glsl +++ b/drivers/gles3/shaders/particles.glsl @@ -47,7 +47,6 @@ out highp vec4 out_xform_1; //tfb: out highp vec4 out_xform_2; //tfb: out highp vec4 out_xform_3; //tfb: -VERTEX_SHADER_GLOBALS #if defined(USE_MATERIAL) @@ -59,6 +58,9 @@ MATERIAL_UNIFORMS #endif + +VERTEX_SHADER_GLOBALS + uint hash(uint x) { x = ((x >> uint(16)) ^ x) * uint(0x45d9f3b); @@ -233,7 +235,6 @@ VERTEX_SHADER_CODE //any code here is never executed, stuff is filled just so it works -FRAGMENT_SHADER_GLOBALS #if defined(USE_MATERIAL) @@ -245,6 +246,8 @@ MATERIAL_UNIFORMS #endif +FRAGMENT_SHADER_GLOBALS + void main() { { diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index a047e693cb..40a295bc83 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -146,7 +146,7 @@ out vec3 binormal_interp; #endif -VERTEX_SHADER_GLOBALS + #if defined(USE_MATERIAL) @@ -159,6 +159,8 @@ MATERIAL_UNIFORMS #endif +VERTEX_SHADER_GLOBALS + #ifdef RENDER_DEPTH_DUAL_PARABOLOID out highp float dp_clip; @@ -418,8 +420,6 @@ layout(std140) uniform Radiance { //ubo:2 /* Material Uniforms */ -FRAGMENT_SHADER_GLOBALS - #if defined(USE_MATERIAL) @@ -431,6 +431,7 @@ MATERIAL_UNIFORMS #endif +FRAGMENT_SHADER_GLOBALS layout(std140) uniform SceneData { |