summaryrefslogtreecommitdiff
path: root/drivers/gles3
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-06-15 21:28:05 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-06-16 08:30:21 -0300
commit29cfc365aa270601d2308bcc4b84ffb55f7241b7 (patch)
tree40fb769b3be6735cc6f833ace1a75dd694b6ba6d /drivers/gles3
parent3fadbe2172359e2012cd461626e6dcc829d896e9 (diff)
Fixes to SSR, WIP.
Diffstat (limited to 'drivers/gles3')
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.cpp14
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.h12
-rw-r--r--drivers/gles3/shaders/screen_space_reflection.glsl41
3 files changed, 15 insertions, 52 deletions
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp
index 432666fffa..af0dd1e4da 100644
--- a/drivers/gles3/rasterizer_scene_gles3.cpp
+++ b/drivers/gles3/rasterizer_scene_gles3.cpp
@@ -887,17 +887,16 @@ void RasterizerSceneGLES3::environment_set_glow(RID p_env, bool p_enable, int p_
void RasterizerSceneGLES3::environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture) {
}
-void RasterizerSceneGLES3::environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_accel, float p_fade, float p_depth_tolerance, bool p_smooth, bool p_roughness) {
+void RasterizerSceneGLES3::environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance, bool p_roughness) {
Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
env->ssr_enabled = p_enable;
env->ssr_max_steps = p_max_steps;
- env->ssr_accel = p_accel;
- env->ssr_fade = p_fade;
+ env->ssr_fade_in = p_fade_in;
+ env->ssr_fade_out = p_fade_out;
env->ssr_depth_tolerance = p_depth_tolerance;
- env->ssr_smooth = p_smooth;
env->ssr_roughness = p_roughness;
}
@@ -3253,8 +3252,7 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_
//perform SSR
- state.ssr_shader.set_conditional(ScreenSpaceReflectionShaderGLES3::SMOOTH_ACCEL, env->ssr_accel > 0 && env->ssr_smooth);
- state.ssr_shader.set_conditional(ScreenSpaceReflectionShaderGLES3::REFLECT_ROUGHNESS, env->ssr_accel > 0 && env->ssr_roughness);
+ state.ssr_shader.set_conditional(ScreenSpaceReflectionShaderGLES3::REFLECT_ROUGHNESS, env->ssr_roughness);
state.ssr_shader.bind();
@@ -3270,9 +3268,9 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_
//state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::FRAME_INDEX,int(render_pass));
state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::FILTER_MIPMAP_LEVELS, float(storage->frame.current_rt->effects.mip_maps[0].sizes.size()));
state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::NUM_STEPS, env->ssr_max_steps);
- state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::ACCELERATION, env->ssr_accel);
state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::DEPTH_TOLERANCE, env->ssr_depth_tolerance);
- state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::DISTANCE_FADE, env->ssr_fade);
+ state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::DISTANCE_FADE, env->ssr_fade_in);
+ state.ssr_shader.set_uniform(ScreenSpaceReflectionShaderGLES3::CURVE_FADE_IN, env->ssr_fade_out);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color);
diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h
index c4e6de058c..842cb53171 100644
--- a/drivers/gles3/rasterizer_scene_gles3.h
+++ b/drivers/gles3/rasterizer_scene_gles3.h
@@ -360,10 +360,9 @@ public:
bool ssr_enabled;
int ssr_max_steps;
- float ssr_accel;
- float ssr_fade;
+ float ssr_fade_in;
+ float ssr_fade_out;
float ssr_depth_tolerance;
- bool ssr_smooth;
bool ssr_roughness;
bool ssao_enabled;
@@ -439,10 +438,9 @@ public:
ssr_enabled = false;
ssr_max_steps = 64;
- ssr_accel = 0.04;
- ssr_fade = 2.0;
+ ssr_fade_in = 2.0;
+ ssr_fade_out = 2.0;
ssr_depth_tolerance = 0.2;
- ssr_smooth = true;
ssr_roughness = true;
ssao_enabled = false;
@@ -527,7 +525,7 @@ public:
virtual void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_treshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_treshold, float p_hdr_bleed_scale, bool p_bicubic_upscale);
virtual void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture);
- virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_accel, float p_fade, float p_depth_tolerance, bool p_smooth, bool p_roughness);
+ virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance, bool p_roughness);
virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_radius2, float p_intensity2, float p_intensity, float p_bias, float p_light_affect, const Color &p_color, bool p_blur);
virtual void environment_set_tonemap(RID p_env, VS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale);
diff --git a/drivers/gles3/shaders/screen_space_reflection.glsl b/drivers/gles3/shaders/screen_space_reflection.glsl
index 8eec71ecb6..3a2083e4ca 100644
--- a/drivers/gles3/shaders/screen_space_reflection.glsl
+++ b/drivers/gles3/shaders/screen_space_reflection.glsl
@@ -38,7 +38,8 @@ uniform mat4 projection;
uniform int num_steps;
uniform float depth_tolerance;
uniform float distance_fade;
-uniform float acceleration;
+uniform float curve_fade_in;
+
layout(location = 0) out vec4 frag_color;
@@ -148,8 +149,6 @@ void main() {
bool found=false;
- //if acceleration > 0, distance between pixels gets larger each step. This allows covering a larger area
- float accel=1.0+acceleration;
float steps_taken=0.0;
for(int i=0;i<num_steps;i++) {
@@ -177,9 +176,6 @@ void main() {
steps_taken+=1.0;
prev_pos=pos;
- z_advance*=accel;
- w_advance*=accel;
- line_advance*=accel;
}
@@ -207,39 +203,10 @@ void main() {
vec2 final_pos;
float grad;
+ grad=steps_taken/float(num_steps);
+ final_pos=pos;
-#ifdef SMOOTH_ACCEL
- //if the distance between point and prev point is >1, then take some samples in the middle for smoothing out the image
- vec2 blend_dir = pos - prev_pos;
- float steps = min(8.0,length(blend_dir));
- if (steps>2.0) {
- vec2 blend_step = blend_dir/steps;
- float blend_z = (z_to-z_from)/steps;
- vec2 new_pos;
- float subgrad=0.0;
- for(float i=0.0;i<steps;i++) {
-
- new_pos = (prev_pos+blend_step*i);
- float z = z_from+blend_z*i;
-
- depth = texture(source_depth, new_pos*pixel_size).r * 2.0 - 1.0;
- depth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - depth * (camera_z_far - camera_z_near));
- depth=-depth;
-
- subgrad=i/steps;
- if (depth>z)
- break;
- }
-
- final_pos = new_pos;
- grad=(steps_taken+subgrad)/float(num_steps);
- } else {
-#endif
- grad=steps_taken/float(num_steps);
- final_pos=pos;
-#ifdef SMOOTH_ACCEL
- }
#endif