Add linear AO spec constant

This commit is contained in:
2025-11-19 17:03:04 +01:00
parent d3e3090cc5
commit cc4b0aee82
5 changed files with 22 additions and 5 deletions
+5
View File
@@ -24,6 +24,7 @@ pub(crate) struct PreviousDebug {
pub(crate) show_material: bool, pub(crate) show_material: bool,
pub(crate) show_all: bool, pub(crate) show_all: bool,
pub(crate) disable_ao: bool, pub(crate) disable_ao: bool,
pub(crate) use_linear_ao: bool,
} }
#[derive(Debug)] #[derive(Debug)]
@@ -313,6 +314,10 @@ pub(crate) fn gui_up(gui: &mut Gui, state: &mut GState, new_csg_needed: &mut boo
&mut state.debug.disable_ao, &mut state.debug.disable_ao,
"Disable ambient occlusion calculation", "Disable ambient occlusion calculation",
); );
ui.toggle_value(
&mut state.debug.use_linear_ao,
"Use linear falloff for occlusion calculation",
);
}); });
}); });
}); });
+1
View File
@@ -10,6 +10,7 @@ layout(constant_id = 5) const bool SPEC_SHOW_ALBEDO = false;
layout(constant_id = 6) const bool SPEC_SHOW_MATERIAL = false; layout(constant_id = 6) const bool SPEC_SHOW_MATERIAL = false;
layout(constant_id = 7) const bool SPEC_SHOW_ALL = false; layout(constant_id = 7) const bool SPEC_SHOW_ALL = false;
layout(constant_id = 8) const bool SPEC_DISABLE_AO = false; layout(constant_id = 8) const bool SPEC_DISABLE_AO = false;
layout(constant_id = 9) const bool SPEC_USE_LINEAR_AO = false;
//layout(constant_id = 30) const uint SPEC_MAXIMUM_SUBDIVISION = 64; //layout(constant_id = 30) const uint SPEC_MAXIMUM_SUBDIVISION = 64;
const uint SPEC_MAXIMUM_SUBDIVISION = 64; const uint SPEC_MAXIMUM_SUBDIVISION = 64;
+5
View File
@@ -1867,6 +1867,7 @@ fn get_spec_constants(debug: &PreviousDebug) -> HashMap<u32, SpecializationConst
const SPEC_SHOW_MATERIAL: u32 = 6; const SPEC_SHOW_MATERIAL: u32 = 6;
const SPEC_SHOW_ALL: u32 = 7; const SPEC_SHOW_ALL: u32 = 7;
const SPEC_DISABLE_AO: u32 = 8; const SPEC_DISABLE_AO: u32 = 8;
const SPEC_USE_LINEAR_AO: u32 = 9;
const SPEC_MAXIMUM_SUBDISIVION: u32 = 30; const SPEC_MAXIMUM_SUBDISIVION: u32 = 30;
let mut spec_constants = HashMap::with_capacity(6); let mut spec_constants = HashMap::with_capacity(6);
@@ -1900,6 +1901,10 @@ fn get_spec_constants(debug: &PreviousDebug) -> HashMap<u32, SpecializationConst
SPEC_DISABLE_AO, SPEC_DISABLE_AO,
SpecializationConstant::Bool(debug.disable_ao), SpecializationConstant::Bool(debug.disable_ao),
); );
spec_constants.insert(
SPEC_USE_LINEAR_AO,
SpecializationConstant::Bool(debug.use_linear_ao),
);
spec_constants.insert( spec_constants.insert(
SPEC_MAXIMUM_SUBDISIVION, SPEC_MAXIMUM_SUBDISIVION,
SpecializationConstant::U32(MAXIMUM_SUBDIVISION), SpecializationConstant::U32(MAXIMUM_SUBDIVISION),
+7 -1
View File
@@ -100,7 +100,13 @@ float getOcclusion(vec3 p, vec3 n) {
#if AO_ENABLE #if AO_ENABLE
for (uint i = 1; i < AO_MAX_ITER; i++) { for (uint i = 1; i < AO_MAX_ITER; i++) {
hash = pcg4d(hash); hash = pcg4d(hash);
vec3 point = getPointOnSphere(vec2(floatConstruct(hash.x), floatConstruct(hash.y))) * AO_STEP * i; float multiplier;
if (SPEC_USE_LINEAR_AO) {
multiplier = AO_STEP * i;
} else {
multiplier = pow(AO_STEP, (float(i) / AO_MAX_ITER * 2) + 0.5);
}
vec3 point = getPointOnSphere(vec2(floatConstruct(hash.x), floatConstruct(hash.y))) * multiplier;
float dist = dot(point, n); float dist = dot(point, n);
if (dist < 0) { if (dist < 0) {
dist = abs(dist); dist = abs(dist);
+3 -3
View File
@@ -436,9 +436,9 @@ fn create_csg() -> SSATape {
pos[0], pos[0],
pos[1], pos[1],
pos[2], pos[2],
SSAInput::Constant(rand::random_range(0.0..3.0)), SSAInput::Constant(rand::random_range(0.0..1.0)),
SSAInput::Constant(rand::random_range(0.0..3.0)), SSAInput::Constant(rand::random_range(0.0..1.0)),
SSAInput::Constant(rand::random_range(0.0..3.0)), SSAInput::Constant(rand::random_range(0.0..1.0)),
], ],
); );
let sphere = tape.push_instruction( let sphere = tape.push_instruction(