|
@@ -861,6 +861,7 @@ void RasterizerSceneGLES3::environment_set_dof_blur_near(RID p_env, bool p_enabl
|
|
env->dof_blur_near_amount = p_amount;
|
|
env->dof_blur_near_amount = p_amount;
|
|
env->dof_blur_near_quality = p_quality;
|
|
env->dof_blur_near_quality = p_quality;
|
|
}
|
|
}
|
|
|
|
+
|
|
void RasterizerSceneGLES3::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 RasterizerSceneGLES3::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);
|
|
Environment *env = environment_owner.getornull(p_env);
|
|
@@ -3626,7 +3627,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
|
}
|
|
}
|
|
|
|
|
|
- if (!env || storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT] || storage->frame.current_rt->width < 4 || storage->frame.current_rt->height < 4) { //no post process on small render targets
|
|
|
|
|
|
+ if ((!env || storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT] || storage->frame.current_rt->width < 4 || storage->frame.current_rt->height < 4) && !storage->frame.current_rt->use_fxaa) { //no post process on small render targets
|
|
//no environment or transparent render, simply return and convert to SRGB
|
|
//no environment or transparent render, simply return and convert to SRGB
|
|
if (storage->frame.current_rt->external.fbo != 0) {
|
|
if (storage->frame.current_rt->external.fbo != 0) {
|
|
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->external.fbo);
|
|
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->external.fbo);
|
|
@@ -3651,14 +3652,14 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
|
|
|
|
|
|
//order of operation
|
|
//order of operation
|
|
//1) DOF Blur (first blur, then copy to buffer applying the blur)
|
|
//1) DOF Blur (first blur, then copy to buffer applying the blur)
|
|
- //2) Motion Blur
|
|
|
|
- //3) Bloom
|
|
|
|
|
|
+ //2) FXAA
|
|
|
|
+ //3) Bloom (Glow)
|
|
//4) Tonemap
|
|
//4) Tonemap
|
|
//5) Adjustments
|
|
//5) Adjustments
|
|
|
|
|
|
GLuint composite_from = storage->frame.current_rt->effects.mip_maps[0].color;
|
|
GLuint composite_from = storage->frame.current_rt->effects.mip_maps[0].color;
|
|
|
|
|
|
- if (env->dof_blur_far_enabled) {
|
|
|
|
|
|
+ if (env && env->dof_blur_far_enabled) {
|
|
|
|
|
|
//blur diffuse into effect mipmaps using separatable convolution
|
|
//blur diffuse into effect mipmaps using separatable convolution
|
|
//storage->shaders.copy.set_conditional(CopyShaderGLES3::GAUSSIAN_HORIZONTAL,true);
|
|
//storage->shaders.copy.set_conditional(CopyShaderGLES3::GAUSSIAN_HORIZONTAL,true);
|
|
@@ -3714,7 +3715,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
|
|
composite_from = storage->frame.current_rt->effects.mip_maps[0].color;
|
|
composite_from = storage->frame.current_rt->effects.mip_maps[0].color;
|
|
}
|
|
}
|
|
|
|
|
|
- if (env->dof_blur_near_enabled) {
|
|
|
|
|
|
+ if (env && env->dof_blur_near_enabled) {
|
|
|
|
|
|
//blur diffuse into effect mipmaps using separatable convolution
|
|
//blur diffuse into effect mipmaps using separatable convolution
|
|
//storage->shaders.copy.set_conditional(CopyShaderGLES3::GAUSSIAN_HORIZONTAL,true);
|
|
//storage->shaders.copy.set_conditional(CopyShaderGLES3::GAUSSIAN_HORIZONTAL,true);
|
|
@@ -3803,7 +3804,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
|
|
composite_from = storage->frame.current_rt->effects.mip_maps[0].color;
|
|
composite_from = storage->frame.current_rt->effects.mip_maps[0].color;
|
|
}
|
|
}
|
|
|
|
|
|
- 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
|
|
//these needed to disable filtering, reenamble
|
|
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);
|
|
@@ -3813,7 +3814,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
}
|
|
}
|
|
|
|
|
|
- if (env->auto_exposure) {
|
|
|
|
|
|
+ if (env && env->auto_exposure) {
|
|
|
|
|
|
//compute auto exposure
|
|
//compute auto exposure
|
|
//first step, copy from image to luminance buffer
|
|
//first step, copy from image to luminance buffer
|
|
@@ -3897,7 +3898,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
|
|
int max_glow_level = -1;
|
|
int max_glow_level = -1;
|
|
int glow_mask = 0;
|
|
int glow_mask = 0;
|
|
|
|
|
|
- if (env->glow_enabled) {
|
|
|
|
|
|
+ if (env && env->glow_enabled) {
|
|
|
|
|
|
for (int i = 0; i < VS::MAX_GLOW_LEVELS; i++) {
|
|
for (int i = 0; i < VS::MAX_GLOW_LEVELS; i++) {
|
|
if (env->glow_levels & (1 << i)) {
|
|
if (env->glow_levels & (1 << i)) {
|
|
@@ -3983,16 +3984,18 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
glActiveTexture(GL_TEXTURE0);
|
|
glBindTexture(GL_TEXTURE_2D, composite_from);
|
|
glBindTexture(GL_TEXTURE_2D, composite_from);
|
|
|
|
+ if (env) {
|
|
|
|
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_FILMIC_TONEMAPPER, env->tone_mapper == VS::ENV_TONE_MAPPER_FILMIC);
|
|
|
|
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_ACES_TONEMAPPER, env->tone_mapper == VS::ENV_TONE_MAPPER_ACES);
|
|
|
|
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_REINHARD_TONEMAPPER, env->tone_mapper == VS::ENV_TONE_MAPPER_REINHARD);
|
|
|
|
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_AUTO_EXPOSURE, env->auto_exposure);
|
|
|
|
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_FILTER_BICUBIC, env->glow_bicubic_upscale);
|
|
|
|
+ }
|
|
|
|
|
|
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_FILMIC_TONEMAPPER, env->tone_mapper == VS::ENV_TONE_MAPPER_FILMIC);
|
|
|
|
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_ACES_TONEMAPPER, env->tone_mapper == VS::ENV_TONE_MAPPER_ACES);
|
|
|
|
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_REINHARD_TONEMAPPER, env->tone_mapper == VS::ENV_TONE_MAPPER_REINHARD);
|
|
|
|
state.tonemap_shader.set_conditional(TonemapShaderGLES3::KEEP_3D_LINEAR, storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_KEEP_3D_LINEAR]);
|
|
state.tonemap_shader.set_conditional(TonemapShaderGLES3::KEEP_3D_LINEAR, storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_KEEP_3D_LINEAR]);
|
|
|
|
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_FXAA, storage->frame.current_rt->use_fxaa);
|
|
|
|
|
|
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_AUTO_EXPOSURE, env->auto_exposure);
|
|
|
|
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_FILTER_BICUBIC, env->glow_bicubic_upscale);
|
|
|
|
-
|
|
|
|
- if (max_glow_level >= 0) {
|
|
|
|
|
|
+ if (env && max_glow_level >= 0) {
|
|
|
|
|
|
for (int i = 0; i < (max_glow_level + 1); i++) {
|
|
for (int i = 0; i < (max_glow_level + 1); i++) {
|
|
|
|
|
|
@@ -4028,7 +4031,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
- if (env->adjustments_enabled) {
|
|
|
|
|
|
+ if (env && env->adjustments_enabled) {
|
|
|
|
|
|
state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_BCS, true);
|
|
state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_BCS, true);
|
|
RasterizerStorageGLES3::Texture *tex = storage->texture_owner.getornull(env->color_correction);
|
|
RasterizerStorageGLES3::Texture *tex = storage->texture_owner.getornull(env->color_correction);
|
|
@@ -4042,34 +4045,44 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
|
|
state.tonemap_shader.set_conditional(TonemapShaderGLES3::V_FLIP, storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]);
|
|
state.tonemap_shader.set_conditional(TonemapShaderGLES3::V_FLIP, storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]);
|
|
state.tonemap_shader.bind();
|
|
state.tonemap_shader.bind();
|
|
|
|
|
|
- state.tonemap_shader.set_uniform(TonemapShaderGLES3::EXPOSURE, env->tone_mapper_exposure);
|
|
|
|
- state.tonemap_shader.set_uniform(TonemapShaderGLES3::WHITE, env->tone_mapper_exposure_white);
|
|
|
|
|
|
+ if (env) {
|
|
|
|
+ state.tonemap_shader.set_uniform(TonemapShaderGLES3::EXPOSURE, env->tone_mapper_exposure);
|
|
|
|
+ state.tonemap_shader.set_uniform(TonemapShaderGLES3::WHITE, env->tone_mapper_exposure_white);
|
|
|
|
|
|
- if (max_glow_level >= 0) {
|
|
|
|
|
|
+ if (max_glow_level >= 0) {
|
|
|
|
|
|
- state.tonemap_shader.set_uniform(TonemapShaderGLES3::GLOW_INTENSITY, env->glow_intensity);
|
|
|
|
- int ss[2] = {
|
|
|
|
- storage->frame.current_rt->width,
|
|
|
|
- storage->frame.current_rt->height,
|
|
|
|
- };
|
|
|
|
- glUniform2iv(state.tonemap_shader.get_uniform(TonemapShaderGLES3::GLOW_TEXTURE_SIZE), 1, ss);
|
|
|
|
- }
|
|
|
|
|
|
+ state.tonemap_shader.set_uniform(TonemapShaderGLES3::GLOW_INTENSITY, env->glow_intensity);
|
|
|
|
+ int ss[2] = {
|
|
|
|
+ storage->frame.current_rt->width,
|
|
|
|
+ storage->frame.current_rt->height,
|
|
|
|
+ };
|
|
|
|
+ glUniform2iv(state.tonemap_shader.get_uniform(TonemapShaderGLES3::GLOW_TEXTURE_SIZE), 1, ss);
|
|
|
|
+ }
|
|
|
|
|
|
- if (env->auto_exposure) {
|
|
|
|
|
|
+ if (env->auto_exposure) {
|
|
|
|
|
|
- glActiveTexture(GL_TEXTURE1);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->exposure.color);
|
|
|
|
- state.tonemap_shader.set_uniform(TonemapShaderGLES3::AUTO_EXPOSURE_GREY, env->auto_exposure_grey);
|
|
|
|
- }
|
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE1);
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->exposure.color);
|
|
|
|
+ state.tonemap_shader.set_uniform(TonemapShaderGLES3::AUTO_EXPOSURE_GREY, env->auto_exposure_grey);
|
|
|
|
+ }
|
|
|
|
|
|
- if (env->adjustments_enabled) {
|
|
|
|
|
|
+ if (env->adjustments_enabled) {
|
|
|
|
+
|
|
|
|
+ state.tonemap_shader.set_uniform(TonemapShaderGLES3::BCS, Vector3(env->adjustments_brightness, env->adjustments_contrast, env->adjustments_saturation));
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // No environment, so no exposure.
|
|
|
|
+ state.tonemap_shader.set_uniform(TonemapShaderGLES3::EXPOSURE, 1.0);
|
|
|
|
+ }
|
|
|
|
|
|
- state.tonemap_shader.set_uniform(TonemapShaderGLES3::BCS, Vector3(env->adjustments_brightness, env->adjustments_contrast, env->adjustments_saturation));
|
|
|
|
|
|
+ if (storage->frame.current_rt->use_fxaa) {
|
|
|
|
+ state.tonemap_shader.set_uniform(TonemapShaderGLES3::PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height));
|
|
}
|
|
}
|
|
|
|
|
|
_copy_screen(true, true);
|
|
_copy_screen(true, true);
|
|
|
|
|
|
//turn off everything used
|
|
//turn off everything used
|
|
|
|
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_FXAA, false);
|
|
state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_AUTO_EXPOSURE, false);
|
|
state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_AUTO_EXPOSURE, false);
|
|
state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_FILMIC_TONEMAPPER, false);
|
|
state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_FILMIC_TONEMAPPER, false);
|
|
state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_ACES_TONEMAPPER, false);
|
|
state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_ACES_TONEMAPPER, false);
|