subsurface scattering is fixed and working again
This commit is contained in:
parent
69bec86028
commit
8126a0cb12
6 changed files with 27 additions and 19 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1128,7 +1128,7 @@ public:
|
|||
GLuint specular;
|
||||
GLuint diffuse;
|
||||
GLuint normal_rough;
|
||||
GLuint motion_sss;
|
||||
GLuint sss;
|
||||
|
||||
GLuint effect_fbo;
|
||||
GLuint effect;
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue