diff options
Diffstat (limited to 'drivers/gles3')
-rw-r--r-- | drivers/gles3/rasterizer_canvas_gles3.cpp | 58 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_gles3.cpp | 6 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.cpp | 40 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.cpp | 16 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.h | 2 | ||||
-rw-r--r-- | drivers/gles3/shader_compiler_gles3.cpp | 11 | ||||
-rw-r--r-- | drivers/gles3/shader_gles3.cpp | 16 | ||||
-rw-r--r-- | drivers/gles3/shaders/canvas.glsl | 18 | ||||
-rw-r--r-- | drivers/gles3/shaders/particles.glsl | 4 | ||||
-rw-r--r-- | drivers/gles3/shaders/resolve.glsl | 2 | ||||
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 81 | ||||
-rw-r--r-- | drivers/gles3/shaders/ssao_blur.glsl | 2 | ||||
-rw-r--r-- | drivers/gles3/shaders/subsurf_scattering.glsl | 4 |
13 files changed, 168 insertions, 92 deletions
diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index 4f6d68de43..1121a07347 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -473,7 +473,7 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur } Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height); - Rect2 src_rect = (rect->flags & CANVAS_RECT_REGION) ? Rect2(rect->source.pos * texpixel_size, rect->source.size * texpixel_size) : Rect2(0, 0, 1, 1); + Rect2 src_rect = (rect->flags & CANVAS_RECT_REGION) ? Rect2(rect->source.position * texpixel_size, rect->source.size * texpixel_size) : Rect2(0, 0, 1, 1); if (rect->flags & CANVAS_RECT_FLIP_H) { src_rect.size.x *= -1; @@ -489,8 +489,8 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size); - glVertexAttrib4f(1, rect->rect.pos.x, rect->rect.pos.y, rect->rect.size.x, rect->rect.size.y); - glVertexAttrib4f(2, src_rect.pos.x, src_rect.pos.y, src_rect.size.x, src_rect.size.y); + glVertexAttrib4f(1, rect->rect.position.x, rect->rect.position.y, rect->rect.size.x, rect->rect.size.y); + glVertexAttrib4f(2, src_rect.position.x, src_rect.position.y, src_rect.size.x, src_rect.size.y); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); if (untile) { @@ -500,7 +500,7 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur } else { - glVertexAttrib4f(1, rect->rect.pos.x, rect->rect.pos.y, rect->rect.size.x, rect->rect.size.y); + glVertexAttrib4f(1, rect->rect.position.x, rect->rect.position.y, rect->rect.size.x, rect->rect.size.y); glVertexAttrib4f(2, 0, 0, 1, 1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } @@ -521,7 +521,7 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur if (!texture) { - glVertexAttrib4f(1, np->rect.pos.x, np->rect.pos.y, np->rect.size.x, np->rect.size.y); + glVertexAttrib4f(1, np->rect.position.x, np->rect.position.y, np->rect.size.x, np->rect.size.y); glVertexAttrib4f(2, 0, 0, 1, 1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); continue; @@ -535,50 +535,50 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur #define SRCRECT(m_x, m_y, m_w, m_h) glVertexAttrib4f(2, (m_x)*texpixel_size.x, (m_y)*texpixel_size.y, (m_w)*texpixel_size.x, (m_h)*texpixel_size.y) //top left - DSTRECT(np->rect.pos.x, np->rect.pos.y, np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]); - SRCRECT(np->source.pos.x, np->source.pos.y, np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]); + DSTRECT(np->rect.position.x, np->rect.position.y, np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]); + SRCRECT(np->source.position.x, np->source.position.y, np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //top right - DSTRECT(np->rect.pos.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.pos.y, np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); - SRCRECT(np->source.pos.x + np->source.size.width - np->margin[MARGIN_RIGHT], np->source.pos.y, np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); + DSTRECT(np->rect.position.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.position.y, np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); + SRCRECT(np->source.position.x + np->source.size.width - np->margin[MARGIN_RIGHT], np->source.position.y, np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //bottom right - DSTRECT(np->rect.pos.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.pos.y + np->rect.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]); - SRCRECT(np->source.pos.x + np->source.size.width - np->margin[MARGIN_RIGHT], np->source.pos.y + np->source.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]); + DSTRECT(np->rect.position.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.position.y + np->rect.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]); + SRCRECT(np->source.position.x + np->source.size.width - np->margin[MARGIN_RIGHT], np->source.position.y + np->source.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //bottom left - DSTRECT(np->rect.pos.x, np->rect.pos.y + np->rect.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_LEFT], np->margin[MARGIN_BOTTOM]); - SRCRECT(np->source.pos.x, np->source.pos.y + np->source.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_LEFT], np->margin[MARGIN_BOTTOM]); + DSTRECT(np->rect.position.x, np->rect.position.y + np->rect.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_LEFT], np->margin[MARGIN_BOTTOM]); + SRCRECT(np->source.position.x, np->source.position.y + np->source.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_LEFT], np->margin[MARGIN_BOTTOM]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //top - DSTRECT(np->rect.pos.x + np->margin[MARGIN_LEFT], np->rect.pos.y, np->rect.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); - SRCRECT(np->source.pos.x + np->margin[MARGIN_LEFT], np->source.pos.y, np->source.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); + DSTRECT(np->rect.position.x + np->margin[MARGIN_LEFT], np->rect.position.y, np->rect.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); + SRCRECT(np->source.position.x + np->margin[MARGIN_LEFT], np->source.position.y, np->source.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //bottom - DSTRECT(np->rect.pos.x + np->margin[MARGIN_LEFT], np->rect.pos.y + np->rect.size.height - np->margin[MARGIN_BOTTOM], np->rect.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); - SRCRECT(np->source.pos.x + np->margin[MARGIN_LEFT], np->source.pos.y + np->source.size.height - np->margin[MARGIN_BOTTOM], np->source.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]); + DSTRECT(np->rect.position.x + np->margin[MARGIN_LEFT], np->rect.position.y + np->rect.size.height - np->margin[MARGIN_BOTTOM], np->rect.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); + SRCRECT(np->source.position.x + np->margin[MARGIN_LEFT], np->source.position.y + np->source.size.height - np->margin[MARGIN_BOTTOM], np->source.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //left - DSTRECT(np->rect.pos.x, np->rect.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_LEFT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); - SRCRECT(np->source.pos.x, np->source.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_LEFT], np->source.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); + DSTRECT(np->rect.position.x, np->rect.position.y + np->margin[MARGIN_TOP], np->margin[MARGIN_LEFT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); + SRCRECT(np->source.position.x, np->source.position.y + np->margin[MARGIN_TOP], np->margin[MARGIN_LEFT], np->source.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //right - DSTRECT(np->rect.pos.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); - SRCRECT(np->source.pos.x + np->source.size.width - np->margin[MARGIN_RIGHT], np->source.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], np->source.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); + DSTRECT(np->rect.position.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.position.y + np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); + SRCRECT(np->source.position.x + np->source.size.width - np->margin[MARGIN_RIGHT], np->source.position.y + np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], np->source.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); if (np->draw_center) { //center - DSTRECT(np->rect.pos.x + np->margin[MARGIN_LEFT], np->rect.pos.y + np->margin[MARGIN_TOP], np->rect.size.x - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); - SRCRECT(np->source.pos.x + np->margin[MARGIN_LEFT], np->source.pos.y + np->margin[MARGIN_TOP], np->source.size.x - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->source.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); + DSTRECT(np->rect.position.x + np->margin[MARGIN_LEFT], np->rect.position.y + np->margin[MARGIN_TOP], np->rect.size.x - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); + SRCRECT(np->source.position.x + np->margin[MARGIN_LEFT], np->source.position.y + np->margin[MARGIN_TOP], np->source.size.x - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->source.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } @@ -670,8 +670,8 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur //glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)), //current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height); - int x = current_clip->final_clip_rect.pos.x; - int y = storage->frame.current_rt->height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.y); + int x = current_clip->final_clip_rect.position.x; + int y = storage->frame.current_rt->height - (current_clip->final_clip_rect.position.y + current_clip->final_clip_rect.size.y); int w = current_clip->final_clip_rect.size.x; int h = current_clip->final_clip_rect.size.y; @@ -787,7 +787,7 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, cons if (current_clip) { glEnable(GL_SCISSOR_TEST); - glScissor(current_clip->final_clip_rect.pos.x, (rt_size.height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.height)), current_clip->final_clip_rect.size.width, current_clip->final_clip_rect.size.height); + glScissor(current_clip->final_clip_rect.position.x, (rt_size.height - (current_clip->final_clip_rect.position.y + current_clip->final_clip_rect.size.height)), current_clip->final_clip_rect.size.width, current_clip->final_clip_rect.size.height); } else { @@ -1108,7 +1108,7 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, cons if (reclip) { glEnable(GL_SCISSOR_TEST); - glScissor(current_clip->final_clip_rect.pos.x, (rt_size.height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.height)), current_clip->final_clip_rect.size.width, current_clip->final_clip_rect.size.height); + glScissor(current_clip->final_clip_rect.position.x, (rt_size.height - (current_clip->final_clip_rect.position.y + current_clip->final_clip_rect.size.height)), current_clip->final_clip_rect.size.width, current_clip->final_clip_rect.size.height); } p_item_list = p_item_list->next; @@ -1340,8 +1340,8 @@ void RasterizerCanvasGLES3::reset_canvas() { void RasterizerCanvasGLES3::draw_generic_textured_rect(const Rect2 &p_rect, const Rect2 &p_src) { - glVertexAttrib4f(1, p_rect.pos.x, p_rect.pos.y, p_rect.size.x, p_rect.size.y); - glVertexAttrib4f(2, p_src.pos.x, p_src.pos.y, p_src.size.x, p_src.size.y); + glVertexAttrib4f(1, p_rect.position.x, p_rect.position.y, p_rect.size.x, p_rect.size.y); + glVertexAttrib4f(2, p_src.position.x, p_src.position.y, p_src.size.x, p_src.size.y); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index aa4150cbe4..2262580d9a 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -301,18 +301,18 @@ void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_c //scale horizontally screenrect.size.y = window_h; screenrect.size.x = imgrect.size.x * window_h / imgrect.size.y; - screenrect.pos.x = (window_w - screenrect.size.x) / 2; + screenrect.position.x = (window_w - screenrect.size.x) / 2; } else { //scale vertically screenrect.size.x = window_w; screenrect.size.y = imgrect.size.y * window_w / imgrect.size.x; - screenrect.pos.y = (window_h - screenrect.size.y) / 2; + screenrect.position.y = (window_h - screenrect.size.y) / 2; } } else { screenrect = imgrect; - screenrect.pos += ((Size2(window_w, window_h) - screenrect.size) / 2.0).floor(); + screenrect.position += ((Size2(window_w, window_h) - screenrect.size) / 2.0).floor(); } RasterizerStorageGLES3::Texture *t = storage->texture_owner.get(texture); diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 7138363796..2b0f78e10f 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -2343,8 +2343,8 @@ void RasterizerSceneGLES3::_setup_directional_light(int p_index, const Transform for (int j = 0; j < shadow_count; j++) { - uint32_t x = li->directional_rect.pos.x; - uint32_t y = li->directional_rect.pos.y; + uint32_t x = li->directional_rect.position.x; + uint32_t y = li->directional_rect.position.y; uint32_t width = li->directional_rect.size.x; uint32_t height = li->directional_rect.size.y; @@ -2389,8 +2389,8 @@ void RasterizerSceneGLES3::_setup_directional_light(int p_index, const Transform store_camera(shadow_mtx, &ubo_data.shadow_matrix1[16 * j]); - ubo_data.light_clamp[0] = atlas_rect.pos.x; - ubo_data.light_clamp[1] = atlas_rect.pos.y; + ubo_data.light_clamp[0] = atlas_rect.position.x; + ubo_data.light_clamp[1] = atlas_rect.position.y; ubo_data.light_clamp[2] = atlas_rect.size.x; ubo_data.light_clamp[3] = atlas_rect.size.y; } @@ -2579,8 +2579,8 @@ void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result, int p_light_c Rect2 rect(float(x) / atlas_size, float(y) / atlas_size, float(width) / atlas_size, float(height) / atlas_size); ubo_data.light_params[3] = 1.0; //means it has shadow - ubo_data.light_clamp[0] = rect.pos.x; - ubo_data.light_clamp[1] = rect.pos.y; + ubo_data.light_clamp[0] = rect.position.x; + ubo_data.light_clamp[1] = rect.position.y; ubo_data.light_clamp[2] = rect.size.x; ubo_data.light_clamp[3] = rect.size.y; @@ -3028,8 +3028,8 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_ //copy normal and roughness to effect buffer glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo); glReadBuffer(GL_COLOR_ATTACHMENT3); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->buffers.effect_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_DRAW_FRAMEBUFFER, storage->frame.current_rt->effects.ssao.blur_fbo[0]); + 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_LINEAR); state.sss_shader.set_conditional(SubsurfScatteringShaderGLES3::USE_11_SAMPLES, subsurface_scatter_quality == SSS_QUALITY_LOW); state.sss_shader.set_conditional(SubsurfScatteringShaderGLES3::USE_17_SAMPLES, subsurface_scatter_quality == SSS_QUALITY_MEDIUM); @@ -3045,8 +3045,11 @@ 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); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //disable filter (fixes bugs on AMD) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->buffers.effect); + glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.ssao.blur_red[0]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE); @@ -3056,10 +3059,15 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_ _copy_screen(); 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(); + + 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); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); } if (env->ssr_enabled) { @@ -3151,6 +3159,8 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_ //copy reflection over diffuse, resolving SSR if needed state.resolve_shader.set_conditional(ResolveShaderGLES3::USE_SSR, env->ssr_enabled); state.resolve_shader.bind(); + state.resolve_shader.set_uniform(ResolveShaderGLES3::PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height)); + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color); if (env->ssr_enabled) { @@ -3764,7 +3774,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const } else { - use_mrt = state.used_sss || (env && (env->ssao_enabled || env->ssr_enabled)); //only enable MRT rendering if any of these is enabled + use_mrt = env && (state.used_sss || env->ssao_enabled || env->ssr_enabled); //only enable MRT rendering if any of these is enabled glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height); @@ -4157,15 +4167,15 @@ void RasterizerSceneGLES3::render_shadow(RID p_light, RID p_shadow_atlas, int p_ } else if (directional_shadow.light_count == 2) { light_instance->directional_rect = Rect2(0, 0, directional_shadow.size, directional_shadow.size / 2); if (light_instance->light_directional_index == 1) { - light_instance->directional_rect.pos.x += light_instance->directional_rect.size.x; + light_instance->directional_rect.position.x += light_instance->directional_rect.size.x; } } else { //3 and 4 light_instance->directional_rect = Rect2(0, 0, directional_shadow.size / 2, directional_shadow.size / 2); if (light_instance->light_directional_index & 1) { - light_instance->directional_rect.pos.x += light_instance->directional_rect.size.x; + light_instance->directional_rect.position.x += light_instance->directional_rect.size.x; } if (light_instance->light_directional_index / 2) { - light_instance->directional_rect.pos.y += light_instance->directional_rect.size.y; + light_instance->directional_rect.position.y += light_instance->directional_rect.size.y; } } } @@ -4173,8 +4183,8 @@ void RasterizerSceneGLES3::render_shadow(RID p_light, RID p_shadow_atlas, int p_ light_projection = light_instance->shadow_transform[p_pass].camera; light_transform = light_instance->shadow_transform[p_pass].transform; - x = light_instance->directional_rect.pos.x; - y = light_instance->directional_rect.pos.y; + x = light_instance->directional_rect.position.x; + y = light_instance->directional_rect.position.y; width = light_instance->directional_rect.size.x; height = light_instance->directional_rect.size.y; diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index a3f1873eae..7ac82a9eca 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -1961,8 +1961,8 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy } else if (value.get_type() == Variant::RECT2) { Rect2 v = value; - gui[0] = v.pos.x; - gui[1] = v.pos.y; + gui[0] = v.position.x; + gui[1] = v.position.y; gui[2] = v.size.x; gui[3] = v.size.y; } else if (value.get_type() == Variant::QUAT) { @@ -5452,7 +5452,7 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { glDeleteRenderbuffers(1, &rt->buffers.diffuse); glDeleteRenderbuffers(1, &rt->buffers.specular); glDeleteRenderbuffers(1, &rt->buffers.normal_rough); - glDeleteRenderbuffers(1, &rt->buffers.motion_sss); + glDeleteRenderbuffers(1, &rt->buffers.sss); glDeleteFramebuffers(1, &rt->buffers.effect_fbo); glDeleteTextures(1, &rt->buffers.effect); @@ -5641,15 +5641,15 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) { glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, rt->buffers.normal_rough); - glGenRenderbuffers(1, &rt->buffers.motion_sss); - glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.motion_sss); + glGenRenderbuffers(1, &rt->buffers.sss); + glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.sss); if (msaa == 0) - glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, rt->width, rt->height); + glRenderbufferStorage(GL_RENDERBUFFER, GL_R8, rt->width, rt->height); else - glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_RGBA8, rt->width, rt->height); + glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_R8, rt->width, rt->height); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_RENDERBUFFER, rt->buffers.motion_sss); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_RENDERBUFFER, rt->buffers.sss); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index 7e107cfdf4..1572d4358e 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -1128,7 +1128,7 @@ public: GLuint specular; GLuint diffuse; GLuint normal_rough; - GLuint motion_sss; + GLuint sss; GLuint effect_fbo; GLuint effect; diff --git a/drivers/gles3/shader_compiler_gles3.cpp b/drivers/gles3/shader_compiler_gles3.cpp index 147357bcd0..5ad2ae7362 100644 --- a/drivers/gles3/shader_compiler_gles3.cpp +++ b/drivers/gles3/shader_compiler_gles3.cpp @@ -574,6 +574,7 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener code += _dump_node_code(onode->arguments[2], p_level, r_gen_code, p_actions, p_default_actions); } break; + default: { code = "(" + _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions) + _opstr(onode->op) + _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions) + ")"; @@ -593,6 +594,10 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener code += _mktab(p_level) + "else\n"; code += _dump_node_code(cfnode->blocks[1], p_level + 1, r_gen_code, p_actions, p_default_actions); } + } else if (cfnode->flow_op == SL::FLOW_OP_WHILE) { + + code += _mktab(p_level) + "while (" + _dump_node_code(cfnode->expressions[0], p_level, r_gen_code, p_actions, p_default_actions) + ")\n"; + code += _dump_node_code(cfnode->blocks[0], p_level + 1, r_gen_code, p_actions, p_default_actions); } else if (cfnode->flow_op == SL::FLOW_OP_RETURN) { @@ -757,12 +762,16 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() { actions[VS::SHADER_SPATIAL].usage_defines["COLOR"] = "#define ENABLE_COLOR_INTERP\n"; actions[VS::SHADER_SPATIAL].usage_defines["INSTANCE_CUSTOM"] = "#define ENABLE_INSTANCE_CUSTOM\n"; - actions[VS::SHADER_SPATIAL].usage_defines["SSS_STRENGTH"] = "#define ENABLE_SSS_MOTION\n"; + actions[VS::SHADER_SPATIAL].usage_defines["SSS_STRENGTH"] = "#define ENABLE_SSS\n"; actions[VS::SHADER_SPATIAL].renames["SSS_STRENGTH"] = "sss_strength"; actions[VS::SHADER_SPATIAL].render_mode_defines["skip_default_transform"] = "#define SKIP_TRANSFORM_USED\n"; + actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_burley"] = "#define DIFFUSE_BURLEY\n"; + actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_oren_nayar"] = "#define DIFFUSE_OREN_NAYAR\n"; + actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_half_lambert"] = "#define DIFFUSE_HALF_LAMBERT\n"; + /* PARTICLES SHADER */ actions[VS::SHADER_PARTICLES].renames["COLOR"] = "out_color"; diff --git a/drivers/gles3/shader_gles3.cpp b/drivers/gles3/shader_gles3.cpp index bebc006032..8c6d15c3b7 100644 --- a/drivers/gles3/shader_gles3.cpp +++ b/drivers/gles3/shader_gles3.cpp @@ -100,14 +100,14 @@ void ShaderGLES3::bind_uniforms() { }; uniforms_dirty = false; -}; +} GLint ShaderGLES3::get_uniform_location(int p_idx) const { ERR_FAIL_COND_V(!version, -1); return version->uniform_location[p_idx]; -}; +} bool ShaderGLES3::bind() { @@ -399,14 +399,14 @@ ShaderGLES3::Version *ShaderGLES3::get_current_version() { strings.push_back(fragment_code2.get_data()); if (cc) { - code_string = cc->fragment.ascii(); + code_string = cc->light.ascii(); strings.push_back(code_string.get_data()); } strings.push_back(fragment_code3.get_data()); if (cc) { - code_string2 = cc->light.ascii(); + code_string2 = cc->fragment.ascii(); strings.push_back(code_string2.get_data()); } @@ -666,7 +666,7 @@ void ShaderGLES3::setup(const char **p_conditional_defines, int p_conditional_co //print_line("CODE1:\n"+String(fragment_code1.get_data())); String code2 = code.substr(cpos + material_tag.length(), code.length()); - cpos = code2.find(code_tag); + cpos = code2.find(light_code_tag); if (cpos == -1) { fragment_code2 = code2.ascii(); @@ -675,16 +675,16 @@ void ShaderGLES3::setup(const char **p_conditional_defines, int p_conditional_co fragment_code2 = code2.substr(0, cpos).ascii(); //print_line("CODE2:\n"+String(fragment_code2.get_data())); - String code3 = code2.substr(cpos + code_tag.length(), code2.length()); + String code3 = code2.substr(cpos + light_code_tag.length(), code2.length()); - cpos = code3.find(light_code_tag); + cpos = code3.find(code_tag); if (cpos == -1) { fragment_code3 = code3.ascii(); } else { fragment_code3 = code3.substr(0, cpos).ascii(); //print_line("CODE3:\n"+String(fragment_code3.get_data())); - fragment_code4 = code3.substr(cpos + light_code_tag.length(), code3.length()).ascii(); + fragment_code4 = code3.substr(cpos + code_tag.length(), code3.length()).ascii(); //print_line("CODE4:\n"+String(fragment_code4.get_data())); } } diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index e6c72da8f1..017009015e 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -211,6 +211,18 @@ MATERIAL_UNIFORMS #endif + +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) { + +#if defined(USE_LIGHT_SHADER_CODE) + +LIGHT_SHADER_CODE + +#endif + +} + + void main() { vec4 color = color_interp; @@ -285,11 +297,7 @@ FRAGMENT_SHADER_CODE #if defined(USE_LIGHT_SHADER_CODE) //light is written by the light shader - { - vec4 light_out=light*color; -LIGHT_SHADER_CODE - color=light_out; - } + light_compute(light,light_vec,light_height,light_color,light_uv,shadow,normal,uv,screen_uv,color); #else diff --git a/drivers/gles3/shaders/particles.glsl b/drivers/gles3/shaders/particles.glsl index fa12dd7408..5d8a532f87 100644 --- a/drivers/gles3/shaders/particles.glsl +++ b/drivers/gles3/shaders/particles.glsl @@ -244,6 +244,10 @@ MATERIAL_UNIFORMS void main() { { +LIGHT_SHADER_CODE + } + + { FRAGMENT_SHADER_CODE } } diff --git a/drivers/gles3/shaders/resolve.glsl b/drivers/gles3/shaders/resolve.glsl index 6acc712299..181a3c99ec 100644 --- a/drivers/gles3/shaders/resolve.glsl +++ b/drivers/gles3/shaders/resolve.glsl @@ -20,7 +20,7 @@ in vec2 uv_interp; uniform sampler2D source_specular; //texunit:0 uniform sampler2D source_ssr; //texunit:1 -uniform float stuff; +uniform vec2 pixel_size; in vec2 uv2_interp; diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 81166e84ff..29a7135eed 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -523,8 +523,8 @@ uniform int reflection_count; layout(location=0) out vec4 diffuse_buffer; layout(location=1) out vec4 specular_buffer; layout(location=2) out vec4 normal_mr_buffer; -#if defined (ENABLE_SSS_MOTION) -layout(location=3) out vec4 motion_ssr_buffer; +#if defined(ENABLE_SSS) +layout(location=3) out float sss_buffer; #endif #else @@ -623,15 +623,66 @@ float GTR1(float NdotH, float a) void light_compute(vec3 N, vec3 L,vec3 V,vec3 B, vec3 T,vec3 light_color,vec3 diffuse_color, float specular_blob_intensity, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,inout vec3 diffuse, inout vec3 specular) { +#if defined(USE_LIGHT_SHADER_CODE) +//light is written by the light shader + + +LIGHT_SHADER_CODE + + +#else + float dotNL = max(dot(N,L), 0.0 ); - float dotNV = max(dot(N,V), 0.0 ); +#if defined(DIFFUSE_HALF_LAMBERT) + + float hl = dot(N,L) * 0.5 + 0.5; + diffuse += hl * light_color * diffuse_color; + +#elif defined(DIFFUSE_OREN_NAYAR) + + { + float LdotV = dot(L, V); + float NdotL = dot(L, N); + float NdotV = dot(N, V); + + float s = LdotV - NdotL * NdotV; + float t = mix(1.0, max(NdotL, NdotV), step(0.0, s)); + + float sigma2 = roughness * roughness; + vec3 A = 1.0 + sigma2 * (diffuse_color / (sigma2 + 0.13) + 0.5 / (sigma2 + 0.33)); + float B = 0.45 * sigma2 / (sigma2 + 0.09); + + diffuse += diffuse_color * max(0.0, NdotL) * (A + vec3(B) * s / t) / M_PI; + } + +#elif defined(DIFFUSE_BURLEY) + + { + float NdotL = dot(L, N); + float NdotV = dot(N, V); + float VdotH = dot(N, normalize(L+V)); + float energyBias = mix(roughness, 0.0, 0.5); + float energyFactor = mix(roughness, 1.0, 1.0 / 1.51); + float fd90 = energyBias + 2.0 * VdotH * VdotH * roughness; + float f0 = 1.0; + float lightScatter = f0 + (fd90 - f0) * pow(1.0 - NdotL, 5.0); + float viewScatter = f0 + (fd90 - f0) * pow(1.0 - NdotV, 5.0); + + diffuse+= light_color * diffuse_color * lightScatter * viewScatter * energyFactor; + } +#else + //lambert + diffuse += dotNL * light_color * diffuse_color; +#endif + + + float dotNV = max(dot(N,V), 0.0 ); #if defined(LIGHT_USE_RIM) float rim_light = pow(1.0-dotNV,(1.0-roughness)*16.0); diffuse += rim_light * rim * mix(vec3(1.0),diffuse_color,rim_tint) * light_color; #endif - diffuse += dotNL * light_color * diffuse_color; if (roughness > 0.0) { @@ -685,6 +736,7 @@ void light_compute(vec3 N, vec3 L,vec3 V,vec3 B, vec3 T,vec3 light_color,vec3 di } +#endif //defined(USE_LIGHT_SHADER_CODE) } @@ -968,7 +1020,7 @@ void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 ta #ifdef USE_GI_PROBES -uniform mediump sampler3D gi_probe1; //texunit:-11 +uniform mediump sampler3D gi_probe1; //texunit:-10 uniform highp mat4 gi_probe_xform1; uniform highp vec3 gi_probe_bounds1; uniform highp vec3 gi_probe_cell_size1; @@ -976,7 +1028,7 @@ uniform highp float gi_probe_multiplier1; uniform highp float gi_probe_bias1; uniform bool gi_probe_blend_ambient1; -uniform mediump sampler3D gi_probe2; //texunit:-10 +uniform mediump sampler3D gi_probe2; //texunit:-11 uniform highp mat4 gi_probe_xform2; uniform highp vec3 gi_probe_bounds2; uniform highp vec3 gi_probe_cell_size2; @@ -1219,7 +1271,7 @@ void main() { bool discard_=false; #endif -#if defined (ENABLE_SSS_MOTION) +#if defined (ENABLE_SSS) float sss_strength=0.0; #endif @@ -1293,7 +1345,7 @@ FRAGMENT_SHADER_CODE { //read radiance from dual paraboloid vec3 ref_vec = reflect(-eye_vec,normal); //2.0 * ndotv * normal - view; // reflect(v, n); - ref_vec=normalize((radiance_inverse_xform * vec4(ref_vec,0.0)).xyz); + ref_vec=normalize((radiance_inverse_xform * vec4(ref_vec,0.0)).xyz); vec3 radiance = textureDualParabolod(radiance_map,ref_vec,lod) * bg_energy; specular_light = radiance; @@ -1507,14 +1559,7 @@ FRAGMENT_SHADER_CODE -#if defined(USE_LIGHT_SHADER_CODE) -//light is written by the light shader -{ -LIGHT_SHADER_CODE - -} -#endif #ifdef RENDER_DEPTH //nothing happens, so a tree-ssa optimizer will result in no fragment shader :) @@ -1566,13 +1611,13 @@ LIGHT_SHADER_CODE #endif //ENABLE_AO diffuse_buffer=vec4(emission+diffuse_light+ambient_light,ambient_scale); - specular_buffer=vec4(specular_light,max(specular.r,max(specular.g,specular.b))); + specular_buffer=vec4(specular_light,metallic); normal_mr_buffer=vec4(normalize(normal)*0.5+0.5,roughness); -#if defined (ENABLE_SSS_MOTION) - motion_ssr_buffer = vec4(vec3(0.0),sss_strength); +#if defined (ENABLE_SSS) + sss_buffer = sss_strength; #endif #else diff --git a/drivers/gles3/shaders/ssao_blur.glsl b/drivers/gles3/shaders/ssao_blur.glsl index ff852487c0..ce4154f50c 100644 --- a/drivers/gles3/shaders/ssao_blur.glsl +++ b/drivers/gles3/shaders/ssao_blur.glsl @@ -24,7 +24,7 @@ layout(location = 0) out float visibility; // Tunable Parameters: /** Increase to make depth edges crisper. Decrease to reduce flicker. */ -#define EDGE_SHARPNESS (1.0) +#define EDGE_SHARPNESS (4.0) /** Step in 2-pixel intervals since we already blurred against neighbors in the first AO pass. This constant can be increased while R decreases to improve diff --git a/drivers/gles3/shaders/subsurf_scattering.glsl b/drivers/gles3/shaders/subsurf_scattering.glsl index eb329dbaed..569be6c5fe 100644 --- a/drivers/gles3/shaders/subsurf_scattering.glsl +++ b/drivers/gles3/shaders/subsurf_scattering.glsl @@ -107,14 +107,14 @@ uniform vec2 dir; in vec2 uv_interp; uniform sampler2D source_diffuse; //texunit:0 -uniform sampler2D source_motion_ss; //texunit:1 +uniform sampler2D source_sss; //texunit:1 uniform sampler2D source_depth; //texunit:2 layout(location = 0) out vec4 frag_color; void main() { - float strength = texture(source_motion_ss,uv_interp).a; + float strength = texture(source_sss,uv_interp).r; strength*=strength; //stored as sqrt // Fetch color of current pixel: |