Skip to content

Commit

Permalink
feat: 4d shader defines
Browse files Browse the repository at this point in the history
  • Loading branch information
mosure committed Jan 25, 2024
1 parent 1b59f70 commit 5dcac36
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/material/spherical_harmonics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const fn num_sh_coefficients(degree: usize) -> usize {


#[cfg(feature = "web")]
const SH_DEGREE: usize = 0;
pub const SH_DEGREE: usize = 0;

#[cfg(not(feature = "web"))]
const SH_DEGREE: usize = 3;
pub const SH_DEGREE: usize = 3;

pub const SH_CHANNELS: usize = 3;
pub const SH_COEFF_COUNT_PER_CHANNEL: usize = num_sh_coefficients(SH_DEGREE);
Expand Down
5 changes: 4 additions & 1 deletion src/material/spherindrical_harmonics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ use serde::{
use half::f16;

use crate::material::spherical_harmonics::{

SH_DEGREE,
};


const SH_4D_DEGREE_TIME: usize = 0;


#[cfg(feature = "f16")]
#[derive(
Clone,
Expand Down
10 changes: 5 additions & 5 deletions src/material/spherindrical_harmonics.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ fn spherindrical_harmonics_lookup(

color += shc[ 0] * vec3<f32>(sh[0], sh[1], sh[2]);

#if SH_DEG > 0
#if SH_DEGREE > 0
color += shc[ 1] * vec3<f32>(sh[ 3], sh[ 4], sh[ 5]) * ray_direction.y;
color += shc[ 2] * vec3<f32>(sh[ 6], sh[ 7], sh[ 8]) * ray_direction.z;
color += shc[ 3] * vec3<f32>(sh[ 9], sh[10], sh[11]) * ray_direction.x;
#endif

#if SH_DEG > 1
#if SH_DEGREE > 1
color += shc[ 4] * vec3<f32>(sh[12], sh[13], sh[14]) * ray_direction.x * ray_direction.y;
color += shc[ 5] * vec3<f32>(sh[15], sh[16], sh[17]) * ray_direction.y * ray_direction.z;
color += shc[ 6] * vec3<f32>(sh[18], sh[19], sh[20]) * (2.0 * rds.z - rds.x - rds.y);
color += shc[ 7] * vec3<f32>(sh[21], sh[22], sh[23]) * ray_direction.x * ray_direction.z;
color += shc[ 8] * vec3<f32>(sh[24], sh[25], sh[26]) * (rds.x - rds.y);
#endif

#if SH_DEG > 2
#if SH_DEGREE > 2
color += shc[ 9] * vec3<f32>(sh[27], sh[28], sh[29]) * ray_direction.y * (3.0 * rds.x - rds.y);
color += shc[10] * vec3<f32>(sh[30], sh[31], sh[32]) * ray_direction.x * ray_direction.y * ray_direction.z;
color += shc[11] * vec3<f32>(sh[33], sh[34], sh[35]) * ray_direction.y * (4.0 * rds.z - rds.x - rds.y);
Expand All @@ -42,11 +42,11 @@ fn spherindrical_harmonics_lookup(
#endif

// TODO: add SH_DEG and SH_DEG_T shader defines
#if SH_DEG_T > 0
#if SH_DEGREE_TIME > 0

#endif

#if SH_DEG_T > 1
#if SH_DEGREE_TIME > 1

#endif

Expand Down
2 changes: 1 addition & 1 deletion src/render/gaussian.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fn compute_cov2d(
let rotation = get_rotation(index);
let scale = get_scale(index);

#ifdef GAUSSIAN_4d
#ifdef GAUSSIAN_4D
let rotation_r = get_rotation_r(index);

let decomposed = compute_cov3d_conditional(
Expand Down
9 changes: 9 additions & 0 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ use crate::{
material::spherical_harmonics::{
HALF_SH_COEFF_COUNT,
SH_COEFF_COUNT,
SH_DEGREE,
SH_VEC4_PLANES,
},
morph::MorphPlugin,
Expand Down Expand Up @@ -304,6 +305,7 @@ fn queue_gaussians(

let key = GaussianCloudPipelineKey {
aabb: settings.aabb,
gaussian_4d: false, // TODO: determine GaussianCloud(3d) or SpaceTimeGaussianCloud(4d) - better queue system abstraction
visualize_bounding_box: settings.visualize_bounding_box,
visualize_depth: settings.visualize_depth,
draw_mode: settings.draw_mode,
Expand Down Expand Up @@ -492,6 +494,8 @@ pub fn shader_defs(
let defines = ShaderDefines::default();
let mut shader_defs = vec![
ShaderDefVal::UInt("SH_COEFF_COUNT".into(), SH_COEFF_COUNT as u32),
ShaderDefVal::UInt("SH_DEGREE".into(), SH_DEGREE as u32),
ShaderDefVal::UInt("SH_DEGREE_TIME".into(), SH_DEGREE as u32),
ShaderDefVal::UInt("HALF_SH_COEFF_COUNT".into(), HALF_SH_COEFF_COUNT as u32),
ShaderDefVal::UInt("SH_VEC4_PLANES".into(), SH_VEC4_PLANES as u32),
ShaderDefVal::UInt("RADIX_BASE".into(), defines.radix_base),
Expand Down Expand Up @@ -525,6 +529,10 @@ pub fn shader_defs(
shader_defs.push("VISUALIZE_DEPTH".into());
}

if key.gaussian_4d {
shader_defs.push("GAUSSIAN_4D".into());
}

#[cfg(feature = "packed")]
shader_defs.push("PACKED".into());

Expand Down Expand Up @@ -573,6 +581,7 @@ pub fn shader_defs(
#[derive(PartialEq, Eq, Hash, Clone, Copy, Default)]
pub struct GaussianCloudPipelineKey {
pub aabb: bool,
pub gaussian_4d: bool,
pub visualize_bounding_box: bool,
pub visualize_depth: bool,
pub draw_mode: GaussianCloudDrawMode,
Expand Down

0 comments on commit 5dcac36

Please sign in to comment.