From 30cb4326fe0f5f0a8dbcbb8f4b474226c833d793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Mon, 8 Mar 2021 17:19:06 +0100 Subject: EEVEE: Ambient Occlusion: Add sample parameter support for the AO node The actual sample count is rounded up to a multiple of 4 because we sample 4 horizons directions. Changing this setting forces the shader to recompile (because using a GPU_constant). --- .../shaders/material/gpu_shader_material_ambient_occlusion.glsl | 3 ++- .../blender/nodes/shader/nodes/node_shader_ambient_occlusion.c | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_ambient_occlusion.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_ambient_occlusion.glsl index 0231aeca04b..edf2c93c9a0 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_ambient_occlusion.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_ambient_occlusion.glsl @@ -3,12 +3,13 @@ void node_ambient_occlusion(vec4 color, float dist, vec3 normal, const float inverted, + const float sample_count, out vec4 result_color, out float result_ao) { vec3 bent_normal; vec4 rand = texelfetch_noise_tex(gl_FragCoord.xy); - OcclusionData data = occlusion_search(viewPosition, maxzBuffer, dist, inverted, 8.0); + OcclusionData data = occlusion_search(viewPosition, maxzBuffer, dist, inverted, sample_count); vec3 V = cameraVec(worldPosition); vec3 N = normalize(normal); diff --git a/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c b/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c index 36971d4e799..abe80ebcefb 100644 --- a/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c +++ b/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c @@ -47,8 +47,15 @@ static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); float inverted = node->custom2 ? 1.0f : 0.0f; + float f_samples = divide_ceil_u(node->custom1, 4); - return GPU_stack_link(mat, node, "node_ambient_occlusion", in, out, GPU_constant(&inverted)); + return GPU_stack_link(mat, + node, + "node_ambient_occlusion", + in, + out, + GPU_constant(&inverted), + GPU_constant(&f_samples)); } static void node_shader_init_ambient_occlusion(bNodeTree *UNUSED(ntree), bNode *node) -- cgit v1.2.3