Skip to content

Commit 7fc2367

Browse files
committed
Added ability for SSAO to affect AO textures too
1 parent 2dc738c commit 7fc2367

13 files changed

+77
-31
lines changed

core/command_queue_mt.h

+17-7
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@
5454
#define _COMMA_10 ,
5555
#define _COMMA_11 ,
5656
#define _COMMA_12 ,
57+
#define _COMMA_13 ,
5758

5859
// 1-based comma separated list of ITEMs
5960
#define COMMA_SEP_LIST(ITEM, LENGTH) _COMMA_SEP_LIST_##LENGTH(ITEM)
61+
#define _COMMA_SEP_LIST_13(ITEM) \
62+
_COMMA_SEP_LIST_12(ITEM) \
63+
, ITEM(13)
6064
#define _COMMA_SEP_LIST_12(ITEM) \
6165
_COMMA_SEP_LIST_11(ITEM) \
6266
, ITEM(12)
@@ -97,6 +101,9 @@
97101

98102
// 1-based semicolon separated list of ITEMs
99103
#define SEMIC_SEP_LIST(ITEM, LENGTH) _SEMIC_SEP_LIST_##LENGTH(ITEM)
104+
#define _SEMIC_SEP_LIST_13(ITEM) \
105+
_SEMIC_SEP_LIST_12(ITEM); \
106+
ITEM(13)
100107
#define _SEMIC_SEP_LIST_12(ITEM) \
101108
_SEMIC_SEP_LIST_11(ITEM); \
102109
ITEM(12)
@@ -137,6 +144,9 @@
137144

138145
// 1-based space separated list of ITEMs
139146
#define SPACE_SEP_LIST(ITEM, LENGTH) _SPACE_SEP_LIST_##LENGTH(ITEM)
147+
#define _SPACE_SEP_LIST_13(ITEM) \
148+
_SPACE_SEP_LIST_12(ITEM) \
149+
ITEM(13)
140150
#define _SPACE_SEP_LIST_12(ITEM) \
141151
_SPACE_SEP_LIST_11(ITEM) \
142152
ITEM(12)
@@ -262,7 +272,7 @@
262272
ss->sem->wait(); \
263273
}
264274

265-
#define MAX_CMD_PARAMS 12
275+
#define MAX_CMD_PARAMS 13
266276

267277
class CommandQueueMT {
268278

@@ -290,15 +300,15 @@ class CommandQueueMT {
290300
};
291301

292302
DECL_CMD(0)
293-
SPACE_SEP_LIST(DECL_CMD, 12)
303+
SPACE_SEP_LIST(DECL_CMD, 13)
294304

295305
/* comands that return */
296306
DECL_CMD_RET(0)
297-
SPACE_SEP_LIST(DECL_CMD_RET, 12)
307+
SPACE_SEP_LIST(DECL_CMD_RET, 13)
298308

299309
/* commands that don't return but sync */
300310
DECL_CMD_SYNC(0)
301-
SPACE_SEP_LIST(DECL_CMD_SYNC, 12)
311+
SPACE_SEP_LIST(DECL_CMD_SYNC, 13)
302312

303313
/***** BASE *******/
304314

@@ -432,15 +442,15 @@ class CommandQueueMT {
432442
public:
433443
/* NORMAL PUSH COMMANDS */
434444
DECL_PUSH(0)
435-
SPACE_SEP_LIST(DECL_PUSH, 12)
445+
SPACE_SEP_LIST(DECL_PUSH, 13)
436446

437447
/* PUSH AND RET COMMANDS */
438448
DECL_PUSH_AND_RET(0)
439-
SPACE_SEP_LIST(DECL_PUSH_AND_RET, 12)
449+
SPACE_SEP_LIST(DECL_PUSH_AND_RET, 13)
440450

441451
/* PUSH AND RET SYNC COMMANDS*/
442452
DECL_PUSH_AND_SYNC(0)
443-
SPACE_SEP_LIST(DECL_PUSH_AND_SYNC, 12)
453+
SPACE_SEP_LIST(DECL_PUSH_AND_SYNC, 13)
444454

445455
void wait_and_flush_one() {
446456
ERR_FAIL_COND(!sync);

drivers/gles2/rasterizer_scene_gles2.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void RasterizerSceneGLES2::environment_set_fog(RID p_env, bool p_enable, float p
144144
void RasterizerSceneGLES2::environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_in, float p_fade_out, float p_depth_tolerance, bool p_roughness) {
145145
}
146146

147-
void RasterizerSceneGLES2::environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, const Color &p_color, VS::EnvironmentSSAOQuality p_quality, VisualServer::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) {
147+
void RasterizerSceneGLES2::environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect,float p_ao_channel_affect, const Color &p_color, VS::EnvironmentSSAOQuality p_quality, VisualServer::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) {
148148
}
149149

150150
void RasterizerSceneGLES2::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) {

drivers/gles2/rasterizer_scene_gles2.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class RasterizerSceneGLES2 : public RasterizerScene {
212212
virtual void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture);
213213

214214
virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_in, float p_fade_out, float p_depth_tolerance, bool p_roughness);
215-
virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, const Color &p_color, VS::EnvironmentSSAOQuality p_quality, VS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness);
215+
virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect,float p_ao_channel_affect, const Color &p_color, VS::EnvironmentSSAOQuality p_quality, VS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness);
216216

217217
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);
218218

drivers/gles3/rasterizer_scene_gles3.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ void RasterizerSceneGLES3::environment_set_ssr(RID p_env, bool p_enable, int p_m
896896
env->ssr_roughness = p_roughness;
897897
}
898898

899-
void RasterizerSceneGLES3::environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, const Color &p_color, VS::EnvironmentSSAOQuality p_quality, VisualServer::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) {
899+
void RasterizerSceneGLES3::environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, float p_ao_channel_affect, const Color &p_color, VS::EnvironmentSSAOQuality p_quality, VisualServer::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) {
900900

901901
Environment *env = environment_owner.getornull(p_env);
902902
ERR_FAIL_COND(!env);
@@ -908,6 +908,7 @@ void RasterizerSceneGLES3::environment_set_ssao(RID p_env, bool p_enable, float
908908
env->ssao_intensity2 = p_intensity2;
909909
env->ssao_bias = p_bias;
910910
env->ssao_light_affect = p_light_affect;
911+
env->ssao_ao_channel_affect = p_ao_channel_affect;
911912
env->ssao_color = p_color;
912913
env->ssao_filter = p_blur;
913914
env->ssao_quality = p_quality;
@@ -2507,6 +2508,7 @@ void RasterizerSceneGLES3::_setup_environment(Environment *env, const CameraMatr
25072508

25082509
state.env_radiance_data.ambient_contribution = env->ambient_sky_contribution;
25092510
state.ubo_data.ambient_occlusion_affect_light = env->ssao_light_affect;
2511+
state.ubo_data.ambient_occlusion_affect_ssao = env->ssao_ao_channel_affect;
25102512

25112513
//fog
25122514

drivers/gles3/rasterizer_scene_gles3.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class RasterizerSceneGLES3 : public RasterizerScene {
140140
float reflection_multiplier;
141141
float subsurface_scatter_width;
142142
float ambient_occlusion_affect_light;
143+
float ambient_occlusion_affect_ssao;
143144

144145
uint32_t fog_depth_enabled;
145146
float fog_depth_begin;
@@ -151,6 +152,7 @@ class RasterizerSceneGLES3 : public RasterizerScene {
151152
float fog_height_max;
152153
float fog_height_curve;
153154
// make sure this struct is padded to be a multiple of 16 bytes for webgl
155+
float pad[3];
154156

155157
} ubo_data;
156158

@@ -385,6 +387,7 @@ class RasterizerSceneGLES3 : public RasterizerScene {
385387
float ssao_radius2;
386388
float ssao_bias;
387389
float ssao_light_affect;
390+
float ssao_ao_channel_affect;
388391
Color ssao_color;
389392
VS::EnvironmentSSAOQuality ssao_quality;
390393
float ssao_bilateral_sharpness;
@@ -465,6 +468,7 @@ class RasterizerSceneGLES3 : public RasterizerScene {
465468
ssao_radius2 = 0.0;
466469
ssao_bias = 0.01;
467470
ssao_light_affect = 0;
471+
ssao_ao_channel_affect = 0;
468472
ssao_filter = VS::ENV_SSAO_BLUR_3x3;
469473
ssao_quality = VS::ENV_SSAO_QUALITY_LOW;
470474
ssao_bilateral_sharpness = 4;
@@ -543,7 +547,7 @@ class RasterizerSceneGLES3 : public RasterizerScene {
543547
virtual void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture);
544548

545549
virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_in, float p_fade_out, float p_depth_tolerance, bool p_roughness);
546-
virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, const Color &p_color, VS::EnvironmentSSAOQuality p_quality, VS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness);
550+
virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, float p_ao_channel_affect, const Color &p_color, VS::EnvironmentSSAOQuality p_quality, VS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness);
547551

548552
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);
549553

drivers/gles3/shaders/scene.glsl

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ layout(std140) uniform SceneData { //ubo:0
9090
mediump float reflection_multiplier;
9191
mediump float subsurface_scatter_width;
9292
mediump float ambient_occlusion_affect_light;
93+
mediump float ambient_occlusion_affect_ao_channel;
9394

9495
bool fog_depth_enabled;
9596
highp float fog_depth_begin;
@@ -670,6 +671,7 @@ layout(std140) uniform SceneData {
670671
mediump float reflection_multiplier;
671672
mediump float subsurface_scatter_width;
672673
mediump float ambient_occlusion_affect_light;
674+
mediump float ambient_occlusion_affect_ao_channel;
673675

674676
bool fog_depth_enabled;
675677
highp float fog_depth_begin;
@@ -2128,18 +2130,16 @@ FRAGMENT_SHADER_CODE
21282130

21292131
#else
21302132

2131-
#if defined(ENABLE_AO)
2132-
2133-
float ambient_scale=0.0; // AO is supplied by material
2134-
#else
21352133
//approximate ambient scale for SSAO, since we will lack full ambient
21362134
float max_emission=max(emission.r,max(emission.g,emission.b));
21372135
float max_ambient=max(ambient_light.r,max(ambient_light.g,ambient_light.b));
21382136
float max_diffuse=max(diffuse_light.r,max(diffuse_light.g,diffuse_light.b));
21392137
float total_ambient = max_ambient+max_diffuse+max_emission;
21402138
float ambient_scale = (total_ambient>0.0) ? (max_ambient+ambient_occlusion_affect_light*max_diffuse)/total_ambient : 0.0;
2141-
#endif //ENABLE_AO
21422139

2140+
#if defined(ENABLE_AO)
2141+
ambient_scale=mix(0.0,ambient_scale,ambient_occlusion_affect_ao_channel);
2142+
#endif
21432143
diffuse_buffer=vec4(emission+diffuse_light+ambient_light,ambient_scale);
21442144
specular_buffer=vec4(specular_light,metallic);
21452145

0 commit comments

Comments
 (0)