subsurface scattering is fixed and working again
This commit is contained in:
parent
69bec86028
commit
8126a0cb12
@ -3028,8 +3028,8 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_
|
|||||||
//copy normal and roughness to effect buffer
|
//copy normal and roughness to effect buffer
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
|
||||||
glReadBuffer(GL_COLOR_ATTACHMENT3);
|
glReadBuffer(GL_COLOR_ATTACHMENT3);
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->buffers.effect_fbo);
|
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_NEAREST);
|
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_11_SAMPLES, subsurface_scatter_quality == SSS_QUALITY_LOW);
|
||||||
state.sss_shader.set_conditional(SubsurfScatteringShaderGLES3::USE_17_SAMPLES, subsurface_scatter_quality == SSS_QUALITY_MEDIUM);
|
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);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color);
|
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);
|
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);
|
glActiveTexture(GL_TEXTURE2);
|
||||||
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth);
|
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
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();
|
_copy_screen();
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color);
|
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color);
|
||||||
state.sss_shader.set_uniform(SubsurfScatteringShaderGLES3::DIR, Vector2(0, 1));
|
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
|
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo); // copy to base level
|
||||||
_copy_screen();
|
_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) {
|
if (env->ssr_enabled) {
|
||||||
@ -3766,7 +3774,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
|
|||||||
|
|
||||||
} else {
|
} 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);
|
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.diffuse);
|
||||||
glDeleteRenderbuffers(1, &rt->buffers.specular);
|
glDeleteRenderbuffers(1, &rt->buffers.specular);
|
||||||
glDeleteRenderbuffers(1, &rt->buffers.normal_rough);
|
glDeleteRenderbuffers(1, &rt->buffers.normal_rough);
|
||||||
glDeleteRenderbuffers(1, &rt->buffers.motion_sss);
|
glDeleteRenderbuffers(1, &rt->buffers.sss);
|
||||||
glDeleteFramebuffers(1, &rt->buffers.effect_fbo);
|
glDeleteFramebuffers(1, &rt->buffers.effect_fbo);
|
||||||
glDeleteTextures(1, &rt->buffers.effect);
|
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);
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, rt->buffers.normal_rough);
|
||||||
|
|
||||||
glGenRenderbuffers(1, &rt->buffers.motion_sss);
|
glGenRenderbuffers(1, &rt->buffers.sss);
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.motion_sss);
|
glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.sss);
|
||||||
|
|
||||||
if (msaa == 0)
|
if (msaa == 0)
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, rt->width, rt->height);
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_R8, rt->width, rt->height);
|
||||||
else
|
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);
|
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
|
||||||
|
@ -1128,7 +1128,7 @@ public:
|
|||||||
GLuint specular;
|
GLuint specular;
|
||||||
GLuint diffuse;
|
GLuint diffuse;
|
||||||
GLuint normal_rough;
|
GLuint normal_rough;
|
||||||
GLuint motion_sss;
|
GLuint sss;
|
||||||
|
|
||||||
GLuint effect_fbo;
|
GLuint effect_fbo;
|
||||||
GLuint effect;
|
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["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["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].renames["SSS_STRENGTH"] = "sss_strength";
|
||||||
|
|
||||||
|
@ -523,8 +523,8 @@ uniform int reflection_count;
|
|||||||
layout(location=0) out vec4 diffuse_buffer;
|
layout(location=0) out vec4 diffuse_buffer;
|
||||||
layout(location=1) out vec4 specular_buffer;
|
layout(location=1) out vec4 specular_buffer;
|
||||||
layout(location=2) out vec4 normal_mr_buffer;
|
layout(location=2) out vec4 normal_mr_buffer;
|
||||||
#if defined (ENABLE_SSS_MOTION)
|
#if defined(ENABLE_SSS)
|
||||||
layout(location=3) out vec4 motion_ssr_buffer;
|
layout(location=3) out float sss_buffer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -1271,7 +1271,7 @@ void main() {
|
|||||||
bool discard_=false;
|
bool discard_=false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (ENABLE_SSS_MOTION)
|
#if defined (ENABLE_SSS)
|
||||||
float sss_strength=0.0;
|
float sss_strength=0.0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1616,8 +1616,8 @@ FRAGMENT_SHADER_CODE
|
|||||||
|
|
||||||
normal_mr_buffer=vec4(normalize(normal)*0.5+0.5,roughness);
|
normal_mr_buffer=vec4(normalize(normal)*0.5+0.5,roughness);
|
||||||
|
|
||||||
#if defined (ENABLE_SSS_MOTION)
|
#if defined (ENABLE_SSS)
|
||||||
motion_ssr_buffer = vec4(vec3(0.0),sss_strength);
|
sss_buffer = sss_strength;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -107,14 +107,14 @@ uniform vec2 dir;
|
|||||||
in vec2 uv_interp;
|
in vec2 uv_interp;
|
||||||
|
|
||||||
uniform sampler2D source_diffuse; //texunit:0
|
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
|
uniform sampler2D source_depth; //texunit:2
|
||||||
|
|
||||||
layout(location = 0) out vec4 frag_color;
|
layout(location = 0) out vec4 frag_color;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
float strength = texture(source_motion_ss,uv_interp).a;
|
float strength = texture(source_sss,uv_interp).r;
|
||||||
strength*=strength; //stored as sqrt
|
strength*=strength; //stored as sqrt
|
||||||
|
|
||||||
// Fetch color of current pixel:
|
// Fetch color of current pixel:
|
||||||
|
Loading…
Reference in New Issue
Block a user