diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-06-03 21:13:03 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-06-03 21:14:05 -0300 |
commit | 8126a0cb12f8b65076a45859d1ae2cb73f43b08c (patch) | |
tree | 97c61b5fb4ba43579e58e623367121d6ce8998a4 /drivers | |
parent | 69bec86028f87307e549d7a2f49bbb7e2b1f3771 (diff) |
subsurface scattering is fixed and working again
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.cpp | 16 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.cpp | 12 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.h | 2 | ||||
-rw-r--r-- | drivers/gles3/shader_compiler_gles3.cpp | 2 | ||||
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 10 | ||||
-rw-r--r-- | drivers/gles3/shaders/subsurf_scattering.glsl | 4 |
6 files changed, 27 insertions, 19 deletions
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 9037f68dad..6e8feda2f0 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -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) { @@ -3766,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); diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index a3f1873eae..3d144bc643 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -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 7771405bb0..e478c289bf 100644 --- a/drivers/gles3/shader_compiler_gles3.cpp +++ b/drivers/gles3/shader_compiler_gles3.cpp @@ -757,7 +757,7 @@ 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"; diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index f35e04c5e4..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 @@ -1271,7 +1271,7 @@ void main() { bool discard_=false; #endif -#if defined (ENABLE_SSS_MOTION) +#if defined (ENABLE_SSS) float sss_strength=0.0; #endif @@ -1616,8 +1616,8 @@ FRAGMENT_SHADER_CODE 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/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: |