EEVEE Next: Optional surfel backface culling

Allow disabling surfels backfaces from contributing to volume probes.

Pull Request: https://projects.blender.org/blender/blender/pulls/113362
This commit is contained in:
Miguel Pozo 2023-10-09 17:02:14 +02:00
parent 311a3d5695
commit f54205cfdd
9 changed files with 32 additions and 9 deletions

View file

@ -256,7 +256,12 @@ class EEVEE_NEXT_MATERIAL_PT_settings(MaterialButtonsPanel, Panel):
mat = context.material
layout.prop(mat, "use_backface_culling")
col = layout.column(heading="Cull Backfaces")
col.prop(mat, "use_backface_culling", text="Camera")
col.prop(mat, "use_backface_culling_probe", text="Probe Capture")
layout.separator()
layout.prop(mat, "blend_method")
layout.prop(mat, "shadow_method")
@ -265,7 +270,7 @@ class EEVEE_NEXT_MATERIAL_PT_settings(MaterialButtonsPanel, Panel):
row.prop(mat, "alpha_threshold")
if mat.blend_method not in {'OPAQUE', 'CLIP', 'HASHED'}:
layout.prop(mat, "show_transparent_back")
col.prop(mat, "show_transparent_back", text="Transparency")
layout.prop(mat, "use_screen_refraction")
layout.prop(mat, "pass_index")

View file

@ -1081,9 +1081,13 @@ void CapturePipeline::sync()
inst_.bind_uniform_data(&surface_ps_);
}
PassMain::Sub *CapturePipeline::surface_material_add(GPUMaterial *gpumat)
PassMain::Sub *CapturePipeline::surface_material_add(::Material *blender_mat, GPUMaterial *gpumat)
{
return &surface_ps_.sub(GPU_material_get_name(gpumat));
PassMain::Sub &sub_pass = surface_ps_.sub(GPU_material_get_name(gpumat));
GPUPass *gpupass = GPU_material_get_pass(gpumat);
sub_pass.shader_set(GPU_pass_shader_get(gpupass));
sub_pass.push_constant("double_sided", !(blender_mat->blend_flag & MA_BL_CULL_BACKFACE_PROBE));
return &sub_pass;
}
void CapturePipeline::render(View &view)

View file

@ -371,7 +371,7 @@ class CapturePipeline {
public:
CapturePipeline(Instance &inst) : inst_(inst){};
PassMain::Sub *surface_material_add(GPUMaterial *gpumat);
PassMain::Sub *surface_material_add(::Material *blender_mat, GPUMaterial *gpumat);
void sync();
void render(View &view);
@ -567,7 +567,7 @@ class PipelineModule {
case MAT_PIPE_SHADOW:
return shadow.surface_material_add(gpumat);
case MAT_PIPE_CAPTURE:
return capture.surface_material_add(gpumat);
return capture.surface_material_add(blender_mat, gpumat);
case MAT_PIPE_PLANAR_PREPASS:
BLI_assert_unreachable();
return nullptr;

View file

@ -1036,6 +1036,11 @@ struct Surfel {
packed_float3 albedo_back;
/** Cluster this surfel is assigned to. */
int cluster_id;
/** True if the light can bounce or be emitted by the surfel back face. */
bool1 double_sided;
int _pad0;
int _pad1;
int _pad2;
/** Surface radiance: Emission + Direct Lighting. */
SurfelRadiance radiance_direct;
/** Surface radiance: Indirect Lighting. Double buffered to avoid race conditions. */

View file

@ -53,7 +53,7 @@ void irradiance_capture_surfel(Surfel surfel, vec3 P, inout SphericalHarmonicL1
void validity_capture_surfel(Surfel surfel, vec3 P, inout float validity)
{
vec3 L = safe_normalize(surfel.position - P);
bool facing = dot(-L, surfel.normal) > 0.0;
bool facing = surfel.double_sided || dot(-L, surfel.normal) > 0.0;
validity += float(facing);
}

View file

@ -53,9 +53,10 @@ void main()
surfel_buf[surfel_id].radiance_direct.front.rgb = g_emission;
surfel_buf[surfel_id].radiance_direct.front.a = 0.0;
/* TODO(fclem): 2nd surface evaluation. */
surfel_buf[surfel_id].albedo_back = albedo;
surfel_buf[surfel_id].radiance_direct.back.rgb = g_emission;
surfel_buf[surfel_id].albedo_back = double_sided ? albedo : vec3(0);
surfel_buf[surfel_id].radiance_direct.back.rgb = double_sided ? g_emission : vec3(0);
surfel_buf[surfel_id].radiance_direct.back.a = 0.0;
surfel_buf[surfel_id].double_sided = double_sided;
if (!capture_info_buf.capture_emission) {
surfel_buf[surfel_id].radiance_direct.front.rgb = vec3(0.0);

View file

@ -182,6 +182,7 @@ GPU_SHADER_CREATE_INFO(eevee_surf_capture)
.define("MAT_CAPTURE")
.storage_buf(SURFEL_BUF_SLOT, Qualifier::WRITE, "Surfel", "surfel_buf[]")
.storage_buf(CAPTURE_BUF_SLOT, Qualifier::READ_WRITE, "CaptureInfoData", "capture_info_buf")
.push_constant(Type::BOOL, "double_sided")
.fragment_source("eevee_surf_capture_frag.glsl")
.additional_info("eevee_global_ubo", "eevee_utility_texture");

View file

@ -342,6 +342,7 @@ enum {
MA_BL_SS_REFRACTION = (1 << 1),
MA_BL_CULL_BACKFACE = (1 << 2),
MA_BL_TRANSLUCENCY = (1 << 3),
MA_BL_CULL_BACKFACE_PROBE = (1 << 4),
};
/** #Material::blend_shadow */

View file

@ -858,6 +858,12 @@ void RNA_def_material(BlenderRNA *brna)
prop, "Backface Culling", "Use back face culling to hide the back side of faces");
RNA_def_property_update(prop, 0, "rna_Material_draw_update");
prop = RNA_def_property(srna, "use_backface_culling_probe", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "blend_flag", MA_BL_CULL_BACKFACE_PROBE);
RNA_def_property_ui_text(
prop, "Probe Capture Backface Culling", "Use back faces for probe captures");
RNA_def_property_update(prop, 0, "rna_Material_draw_update");
prop = RNA_def_property(srna, "use_screen_refraction", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "blend_flag", MA_BL_SS_REFRACTION);
RNA_def_property_ui_text(