Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move FXAA over to ProjectSettings and Viewport #1

Merged
merged 1 commit into from
Sep 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions doc/classes/Environment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,6 @@
<member name="fog_transmit_enabled" type="bool" setter="set_fog_transmit_enabled" getter="is_fog_transmit_enabled" default="false">
Enables fog's light transmission effect. If [code]true[/code], light will be more visible in the fog to simulate light scattering as in real life.
</member>
<member name="fxaa_enabled" type="bool" setter="set_fxaa_enabled" getter="is_fxaa_enabled" default="false">
Enables fast approximate antialiasing. FXAA is a popular screen-space antialiasing method, which is fast but will make the image look blurry, especially at lower resolutions. It can still work relatively well at large resolutions such as 1440p and 4K.
</member>
<member name="glow_bicubic_upscale" type="bool" setter="set_glow_bicubic_upscale" getter="is_glow_bicubic_upscale_enabled" default="false">
Smooths out the blockiness created by sampling higher levels, at the cost of performance.
[b]Note:[/b] When using the GLES2 renderer, this is only available if the GPU supports the [code]GL_EXT_gpu_shader4[/code] extension.
Expand Down
3 changes: 3 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,9 @@
Sets the number of MSAA samples to use. MSAA is used to reduce aliasing around the edges of polygons. A higher MSAA value results in smoother edges but can be significantly slower on some hardware.
[b]Note:[/b] MSAA is not available on HTML5 export using the GLES2 backend.
</member>
<member name="rendering/quality/filters/use_fxaa" type="bool" setter="" getter="" default="false">
Enables FXAA in the root Viewport. FXAA is a popular screen-space antialiasing method, which is fast but will make the image look blurry, especially at lower resolutions. It can still work relatively well at large resolutions such as 1440p and 4K.
</member>
<member name="rendering/quality/filters/use_nearest_mipmap_filter" type="bool" setter="" getter="" default="false">
If [code]true[/code], uses nearest-neighbor mipmap filtering when using mipmaps (also called "bilinear filtering"), which will result in visible seams appearing between mipmap stages. This may increase performance in mobile as less memory bandwidth is used. If [code]false[/code], linear mipmap filtering (also called "trilinear filtering") is used.
</member>
Expand Down
3 changes: 3 additions & 0 deletions doc/classes/Viewport.xml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@
<member name="disable_3d" type="bool" setter="set_disable_3d" getter="is_3d_disabled" default="false">
If [code]true[/code], the viewport will disable 3D rendering. For actual disabling use [code]usage[/code].
</member>
<member name="fxaa" type="bool" setter="set_use_fxaa" getter="get_use_fxaa" default="false">
Enables fast approximate antialiasing. FXAA is a popular screen-space antialiasing method, which is fast but will make the image look blurry, especially at lower resolutions. It can still work relatively well at large resolutions such as 1440p and 4K.
</member>
<member name="global_canvas_transform" type="Transform2D" setter="set_global_canvas_transform" getter="get_global_canvas_transform">
The global canvas transform of the viewport. The canvas transform is relative to this.
</member>
Expand Down
22 changes: 11 additions & 11 deletions doc/classes/VisualServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1207,17 +1207,6 @@
Sets the variables to be used with the fog height effect. See [Environment] for more details.
</description>
</method>
<method name="environment_set_fxaa">
<return type="void">
</return>
<argument index="0" name="env" type="RID">
</argument>
<argument index="1" name="enable" type="bool">
</argument>
<description>
Sets the FXAA value of the environment. FXAA is a popular screen-space antialiasing method, which is fast but will make the image look blurry, especially at lower resolutions. It can still work relatively well at large resolutions such as 1440p and 4K. Equivalent to [member Environment.fxaa_enabled].
</description>
</method>
<method name="environment_set_glow">
<return type="void">
</return>
Expand Down Expand Up @@ -4230,6 +4219,17 @@
If [code]true[/code], the viewport uses augmented or virtual reality technologies. See [ARVRInterface].
</description>
</method>
<method name="viewport_set_use_fxaa">
<return type="void">
</return>
<argument index="0" name="viewport" type="RID">
</argument>
<argument index="1" name="fxaa" type="bool">
</argument>
<description>
Enables fast approximate antialiasing for this viewport. FXAA is a popular screen-space antialiasing method, which is fast but will make the image look blurry, especially at lower resolutions. It can still work relatively well at large resolutions such as 1440p and 4K.
</description>
</method>
<method name="viewport_set_vflip">
<return type="void">
</return>
Expand Down
3 changes: 1 addition & 2 deletions drivers/dummy/rasterizer_dummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ class RasterizerSceneDummy : public RasterizerScene {
void environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_far_amount, VS::EnvironmentDOFBlurQuality p_quality) {}
void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale) {}

void environment_set_fxaa(RID p_env, bool p_enable) {}

void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture) {}

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) {}
Expand Down Expand Up @@ -708,6 +706,7 @@ class RasterizerStorageDummy : public RasterizerStorage {
bool render_target_was_used(RID p_render_target) { return false; }
void render_target_clear_used(RID p_render_target) {}
void render_target_set_msaa(RID p_render_target, VS::ViewportMSAA p_msaa) {}
void render_target_set_use_fxaa(RID p_render_target, bool p_fxaa) {}

/* CANVAS SHADOW */

Expand Down
174 changes: 84 additions & 90 deletions drivers/gles2/rasterizer_scene_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,14 +774,6 @@ void RasterizerSceneGLES2::environment_set_dof_blur_near(RID p_env, bool p_enabl
env->dof_blur_near_quality = p_quality;
}

void RasterizerSceneGLES2::environment_set_fxaa(RID p_env, bool p_enable) {

Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);

env->fxaa_enabled = p_enable;
}

void RasterizerSceneGLES2::environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale) {

Environment *env = environment_owner.getornull(p_env);
Expand Down Expand Up @@ -2738,8 +2730,9 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p
use_post_process = use_post_process && storage->frame.current_rt->mip_maps_allocated;

if (env) {
use_post_process = use_post_process && (env->adjustments_enabled || env->glow_enabled || env->dof_blur_far_enabled || env->dof_blur_near_enabled || env->fxaa_enabled);
use_post_process = use_post_process && (env->adjustments_enabled || env->glow_enabled || env->dof_blur_far_enabled || env->dof_blur_near_enabled);
}
use_post_process = use_post_process || storage->frame.current_rt->use_fxaa;

GLuint next_buffer;

Expand Down Expand Up @@ -2798,7 +2791,7 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p

// DOF Blur

if (env->dof_blur_far_enabled) {
if (env && env->dof_blur_far_enabled) {

int vp_h = storage->frame.current_rt->height;
int vp_w = storage->frame.current_rt->width;
Expand Down Expand Up @@ -2855,7 +2848,7 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p
state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::USE_ORTHOGONAL_PROJECTION, false);
}

if (env->dof_blur_near_enabled) {
if (env && env->dof_blur_near_enabled) {

//convert texture to RGBA format if not already
if (!storage->frame.current_rt->used_dof_blur_near) {
Expand Down Expand Up @@ -2940,7 +2933,7 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p
storage->frame.current_rt->used_dof_blur_near = true;
}

if (env->dof_blur_near_enabled || env->dof_blur_far_enabled) {
if (env && (env->dof_blur_near_enabled || env->dof_blur_far_enabled)) {
//these needed to disable filtering, reenamble
glActiveTexture(GL_TEXTURE0);
if (storage->frame.current_rt->mip_maps[0].color) {
Expand All @@ -2961,7 +2954,7 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p
int max_glow_level = -1;
int glow_mask = 0;

if (env->glow_enabled) {
if (env && env->glow_enabled) {

for (int i = 0; i < VS::MAX_GLOW_LEVELS; i++) {
if (env->glow_levels & (1 << i)) {
Expand Down Expand Up @@ -3048,82 +3041,84 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p
} else {
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].sizes[0].color);
}
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_FXAA, storage->frame.current_rt->use_fxaa);
if (env) {

state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_FXAA, env->fxaa_enabled);
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_FILTER_BICUBIC, env->glow_bicubic_upscale);
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_FILTER_BICUBIC, env->glow_bicubic_upscale);

if (max_glow_level >= 0) {
if (storage->frame.current_rt->mip_maps[0].color) {
for (int i = 0; i < (max_glow_level + 1); i++) {
if (max_glow_level >= 0) {
if (storage->frame.current_rt->mip_maps[0].color) {
for (int i = 0; i < (max_glow_level + 1); i++) {

if (glow_mask & (1 << i)) {
if (i == 0) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL1, true);
}
if (i == 1) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL2, true);
}
if (i == 2) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL3, true);
}
if (i == 3) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL4, true);
}
if (i == 4) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL5, true);
}
if (i == 5) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL6, true);
}
if (i == 6) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL7, true);
if (glow_mask & (1 << i)) {
if (i == 0) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL1, true);
}
if (i == 1) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL2, true);
}
if (i == 2) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL3, true);
}
if (i == 3) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL4, true);
}
if (i == 4) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL5, true);
}
if (i == 5) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL6, true);
}
if (i == 6) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL7, true);
}
}
}
}
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].color);
} else {
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].color);
} else {

state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_MULTI_TEXTURE_GLOW, true);
int active_glow_level = 0;
for (int i = 0; i < (max_glow_level + 1); i++) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_MULTI_TEXTURE_GLOW, true);
int active_glow_level = 0;
for (int i = 0; i < (max_glow_level + 1); i++) {

if (glow_mask & (1 << i)) {
active_glow_level++;
glActiveTexture(GL_TEXTURE0 + active_glow_level);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].sizes[i + 1].color);
if (active_glow_level == 1) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL1, true);
}
if (active_glow_level == 2) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL2, true);
}
if (active_glow_level == 3) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL3, true);
}
if (active_glow_level == 4) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL4, true);
}
if (active_glow_level == 5) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL5, true);
}
if (active_glow_level == 6) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL6, true);
}
if (active_glow_level == 7) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL7, true);
if (glow_mask & (1 << i)) {
active_glow_level++;
glActiveTexture(GL_TEXTURE0 + active_glow_level);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].sizes[i + 1].color);
if (active_glow_level == 1) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL1, true);
}
if (active_glow_level == 2) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL2, true);
}
if (active_glow_level == 3) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL3, true);
}
if (active_glow_level == 4) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL4, true);
}
if (active_glow_level == 5) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL5, true);
}
if (active_glow_level == 6) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL6, true);
}
if (active_glow_level == 7) {
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL7, true);
}
}
}
}
}

state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SCREEN, env->glow_blend_mode == VS::GLOW_BLEND_MODE_SCREEN);
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SOFTLIGHT, env->glow_blend_mode == VS::GLOW_BLEND_MODE_SOFTLIGHT);
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_REPLACE, env->glow_blend_mode == VS::GLOW_BLEND_MODE_REPLACE);
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SCREEN, env->glow_blend_mode == VS::GLOW_BLEND_MODE_SCREEN);
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SOFTLIGHT, env->glow_blend_mode == VS::GLOW_BLEND_MODE_SOFTLIGHT);
state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_REPLACE, env->glow_blend_mode == VS::GLOW_BLEND_MODE_REPLACE);
}
}

//Adjustments
if (env->adjustments_enabled) {
if (env && env->adjustments_enabled) {

state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_BCS, true);
RasterizerStorageGLES2::Texture *tex = storage->texture_owner.getornull(env->color_correction);
Expand All @@ -3135,26 +3130,25 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p
}

state.tonemap_shader.bind();
if (env) {
if (max_glow_level >= 0) {

if (max_glow_level >= 0) {

state.tonemap_shader.set_uniform(TonemapShaderGLES2::GLOW_INTENSITY, env->glow_intensity);
int ss[2] = {
storage->frame.current_rt->width,
storage->frame.current_rt->height,
};
glUniform2iv(state.tonemap_shader.get_uniform(TonemapShaderGLES2::GLOW_TEXTURE_SIZE), 1, ss);
}
state.tonemap_shader.set_uniform(TonemapShaderGLES2::GLOW_INTENSITY, env->glow_intensity);
int ss[2] = {
storage->frame.current_rt->width,
storage->frame.current_rt->height,
};
glUniform2iv(state.tonemap_shader.get_uniform(TonemapShaderGLES2::GLOW_TEXTURE_SIZE), 1, ss);
}

if (env->adjustments_enabled) {
if (env->adjustments_enabled) {

state.tonemap_shader.set_uniform(TonemapShaderGLES2::BCS, Vector3(env->adjustments_brightness, env->adjustments_contrast, env->adjustments_saturation));
state.tonemap_shader.set_uniform(TonemapShaderGLES2::BCS, Vector3(env->adjustments_brightness, env->adjustments_contrast, env->adjustments_saturation));
}
}

if (env->fxaa_enabled) {
state.tonemap_shader.set_uniform(
TonemapShaderGLES2::PIXEL_SIZE,
Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height));
if (storage->frame.current_rt->use_fxaa) {
state.tonemap_shader.set_uniform(TonemapShaderGLES2::PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height));
}

storage->_copy_screen();
Expand Down
5 changes: 0 additions & 5 deletions drivers/gles2/rasterizer_scene_gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,6 @@ class RasterizerSceneGLES2 : public RasterizerScene {

int canvas_max_layer;

bool fxaa_enabled;

bool glow_enabled;
int glow_levels;
float glow_intensity;
Expand Down Expand Up @@ -420,7 +418,6 @@ class RasterizerSceneGLES2 : public RasterizerScene {
ambient_energy(1.0),
ambient_sky_contribution(0.0),
canvas_max_layer(0),
fxaa_enabled(false),
glow_enabled(false),
glow_levels((1 << 2) | (1 << 4)),
glow_intensity(0.8),
Expand Down Expand Up @@ -479,8 +476,6 @@ class RasterizerSceneGLES2 : public RasterizerScene {
virtual void environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, VS::EnvironmentDOFBlurQuality p_quality);
virtual void environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, VS::EnvironmentDOFBlurQuality p_quality);

virtual void environment_set_fxaa(RID p_env, bool p_enable);

virtual void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, 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);

Expand Down
7 changes: 7 additions & 0 deletions drivers/gles2/rasterizer_storage_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5362,6 +5362,13 @@ void RasterizerStorageGLES2::render_target_set_msaa(RID p_render_target, VS::Vie
_render_target_allocate(rt);
}

void RasterizerStorageGLES2::render_target_set_use_fxaa(RID p_render_target, bool p_fxaa) {
RenderTarget *rt = render_target_owner.getornull(p_render_target);
ERR_FAIL_COND(!rt);

rt->use_fxaa = p_fxaa;
}

/* CANVAS SHADOW */

RID RasterizerStorageGLES2::canvas_light_shadow_buffer_create(int p_width) {
Expand Down
4 changes: 4 additions & 0 deletions drivers/gles2/rasterizer_storage_gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,8 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
bool used_in_frame;
VS::ViewportMSAA msaa;

bool use_fxaa;

RID texture;

bool used_dof_blur_near;
Expand All @@ -1239,6 +1241,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
height(0),
used_in_frame(false),
msaa(VS::VIEWPORT_MSAA_DISABLED),
use_fxaa(false),
used_dof_blur_near(false),
mip_maps_allocated(false) {
for (int i = 0; i < RENDER_TARGET_FLAG_MAX; ++i) {
Expand All @@ -1263,6 +1266,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
virtual bool render_target_was_used(RID p_render_target);
virtual void render_target_clear_used(RID p_render_target);
virtual void render_target_set_msaa(RID p_render_target, VS::ViewportMSAA p_msaa);
virtual void render_target_set_use_fxaa(RID p_render_target, bool p_fxaa);

/* CANVAS SHADOW */

Expand Down
Loading