Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions citro3d/src/fog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
//! Fog/Gas unit configuration.
/// Fog modes.
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[doc(alias = "GPU_FOGMODE")]
pub enum FogMode {
/// Fog/Gas unit disabled.
#[doc(alias = "GPU_NO_FOG")]
NoFog = ctru_sys::GPU_NO_FOG,

/// Fog/Gas unit configured in Fog mode.
#[doc(alias = "GPU_FOG")]
Fog = ctru_sys::GPU_FOG,

/// Fog/Gas unit configured in Gas mode.
#[doc(alias = "GPU_GAS")]
Gas = ctru_sys::GPU_GAS,
}

impl TryFrom<u8> for FogMode {
type Error = String;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
ctru_sys::GPU_NO_FOG => Ok(FogMode::NoFog),
ctru_sys::GPU_FOG => Ok(FogMode::Fog),
ctru_sys::GPU_GAS => Ok(FogMode::Gas),
_ => Err("invalid value for FogMode".to_string()),
}
}
}

/// Gas shading density source values.
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[doc(alias = "GPU_GASMODE")]
pub enum GasMode {
/// Plain density.
#[doc(alias = "GPU_PLAIN_DENSITY")]
PlainDensity = ctru_sys::GPU_PLAIN_DENSITY,

/// Depth density.
#[doc(alias = "GPU_DEPTH_DENSITY")]
DepthDensity = ctru_sys::GPU_DEPTH_DENSITY,
}

impl TryFrom<u8> for GasMode {
type Error = String;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
ctru_sys::GPU_PLAIN_DENSITY => Ok(GasMode::PlainDensity),
ctru_sys::GPU_DEPTH_DENSITY => Ok(GasMode::DepthDensity),
_ => Err("invalid value for GasMode".to_string()),
}
}
}

/// Gas color LUT inputs.
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[doc(alias = "GPU_GASLUTINPUT")]
pub enum GasLutInput {
/// Gas density used as input.
#[doc(alias = "GPU_GAS_DENSITY")]
Density = ctru_sys::GPU_GAS_DENSITY,

/// Light factor used as input.
#[doc(alias = "GPU_GAS_LIGHT_FACTOR")]
LightFactor = ctru_sys::GPU_GAS_LIGHT_FACTOR,
}

impl TryFrom<u8> for GasLutInput {
type Error = String;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
ctru_sys::GPU_GAS_DENSITY => Ok(GasLutInput::Density),
ctru_sys::GPU_GAS_LIGHT_FACTOR => Ok(GasLutInput::LightFactor),
_ => Err("invalid value for GasLutInput".to_string()),
}
}
}

/// Gas depth functions.
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[doc(alias = "GPU_GASDEPTHFUNC")]
pub enum GasDepthFunction {
/// Never pass (0).
#[doc(alias = "GPU_GAS_NEVER")]
Never = ctru_sys::GPU_GAS_NEVER,

/// Always pass (1).
#[doc(alias = "GPU_GAS_ALWAYS")]
Always = ctru_sys::GPU_GAS_ALWAYS,

/// Pass if greater than (1-X).
#[doc(alias = "GPU_GAS_GREATER")]
Greater = ctru_sys::GPU_GAS_GREATER,

/// Pass if less than (X).
#[doc(alias = "GPU_GAS_LESS")]
Less = ctru_sys::GPU_GAS_LESS,
}

impl TryFrom<u8> for GasDepthFunction {
type Error = String;

fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
ctru_sys::GPU_GAS_NEVER => Ok(GasDepthFunction::Never),
ctru_sys::GPU_GAS_ALWAYS => Ok(GasDepthFunction::Always),
ctru_sys::GPU_GAS_GREATER => Ok(GasDepthFunction::Greater),
ctru_sys::GPU_GAS_LESS => Ok(GasDepthFunction::Less),
_ => Err("invalid value for GasDepthFunction".to_string()),
}
}
}
2 changes: 2 additions & 0 deletions citro3d/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ pub mod attrib;
pub mod buffer;
pub mod color;
pub mod error;
pub mod fog;
pub mod light;
pub mod math;
pub mod render;
pub mod shader;
pub mod texenv;
pub mod texture;
pub mod uniform;

use std::cell::{OnceCell, RefMut};
Expand Down
122 changes: 121 additions & 1 deletion citro3d/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ impl Light {
}
}

/// Sets the spotlight direction of the light (relatively to the light's source [position](set_position)).
/// Sets the spotlight direction of the light (relatively to the light's source [position](Light::set_position)).
#[doc(alias = "C3D_LightSpotDir")]
pub fn set_spotlight_direction(self: Pin<&mut Self>, direction: FVec3) {
unsafe {
Expand Down Expand Up @@ -636,6 +636,21 @@ pub enum LutInput {
ViewHalf = ctru_sys::GPU_LUTINPUT_VH,
}

impl TryFrom<u8> for LutInput {
type Error = String;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
ctru_sys::GPU_LUTINPUT_NH => Ok(Self::NormalHalf),
ctru_sys::GPU_LUTINPUT_VH => Ok(Self::ViewHalf),
ctru_sys::GPU_LUTINPUT_NV => Ok(Self::NormalView),
ctru_sys::GPU_LUTINPUT_LN => Ok(Self::LightNormal),
ctru_sys::GPU_LUTINPUT_SP => Ok(Self::LightSpotLight),
ctru_sys::GPU_LUTINPUT_CP => Ok(Self::CosPhi),
_ => Err("invalid value for LutInput".to_string()),
}
}
}

/// Identifier/index for the various LUTs associated to a [`LightEnv`].
///
/// # Notes
Expand Down Expand Up @@ -664,6 +679,23 @@ pub enum LutId {
DistanceAttenuation = ctru_sys::GPU_LUT_DA,
}

impl TryFrom<u8> for LutId {
type Error = String;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
ctru_sys::GPU_LUT_D0 => Ok(Self::D0),
ctru_sys::GPU_LUT_D1 => Ok(Self::D1),
ctru_sys::GPU_LUT_SP => Ok(Self::Spotlight),
ctru_sys::GPU_LUT_FR => Ok(Self::Fresnel),
ctru_sys::GPU_LUT_RB => Ok(Self::ReflectBlue),
ctru_sys::GPU_LUT_RG => Ok(Self::ReflectGreen),
ctru_sys::GPU_LUT_RR => Ok(Self::ReflectRed),
ctru_sys::GPU_LUT_DA => Ok(Self::DistanceAttenuation),
_ => Err("invalid value for LutId".to_string()),
}
}
}

#[doc(alias = "GPU_FRESNELSEL")]
#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Debug)]
#[repr(u8)]
Expand All @@ -678,6 +710,94 @@ pub enum FresnelSelector {
Both = ctru_sys::GPU_PRI_SEC_ALPHA_FRESNEL,
}

impl TryFrom<u8> for FresnelSelector {
type Error = String;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
ctru_sys::GPU_NO_FRESNEL => Ok(Self::None),
ctru_sys::GPU_PRI_ALPHA_FRESNEL => Ok(Self::PrimaryAlpha),
ctru_sys::GPU_SEC_ALPHA_FRESNEL => Ok(Self::SecondaryAlpha),
ctru_sys::GPU_PRI_SEC_ALPHA_FRESNEL => Ok(Self::Both),
_ => Err("invalid value for FresnelSelector".to_string()),
}
}
}

/// LUT scaling factors.
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[doc(alias = "GPU_LIGHTLUTSCALER")]
pub enum LutScale {
/// 1x scale.
#[doc(alias = "GPU_LUTSCALER_1x")]
OneX = ctru_sys::GPU_LUTSCALER_1x,

/// 2x scale.
#[doc(alias = "GPU_LUTSCALER_2x")]
TwoX = ctru_sys::GPU_LUTSCALER_2x,

/// 4x scale.
#[doc(alias = "GPU_LUTSCALER_4x")]
FourX = ctru_sys::GPU_LUTSCALER_4x,

/// 8x scale.
#[doc(alias = "GPU_LUTSCALER_8x")]
EightX = ctru_sys::GPU_LUTSCALER_8x,

/// 0.25x scale.
#[doc(alias = "GPU_LUTSCALER_0_25x")]
QuarterX = ctru_sys::GPU_LUTSCALER_0_25x,

/// 0.5x scale.
#[doc(alias = "GPU_LUTSCALER_0_5x")]
HalfX = ctru_sys::GPU_LUTSCALER_0_5x,
}

impl TryFrom<u8> for LutScale {
type Error = String;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
ctru_sys::GPU_LUTSCALER_1x => Ok(Self::OneX),
ctru_sys::GPU_LUTSCALER_2x => Ok(Self::TwoX),
ctru_sys::GPU_LUTSCALER_4x => Ok(Self::FourX),
ctru_sys::GPU_LUTSCALER_8x => Ok(Self::EightX),
ctru_sys::GPU_LUTSCALER_0_25x => Ok(Self::QuarterX),
ctru_sys::GPU_LUTSCALER_0_5x => Ok(Self::HalfX),
_ => Err("invalid value for LutScale".to_string()),
}
}
}

/// Bump map modes.
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[doc(alias = "GPU_BUMPMODE")]
pub enum BumpMappingMode {
/// Disabled.
#[doc(alias = "GPU_BUMP_NOT_USED")]
NotUsed = ctru_sys::GPU_BUMP_NOT_USED,

/// Bump as bump mapping.
#[doc(alias = "GPU_BUMP_AS_BUMP")]
AsBump = ctru_sys::GPU_BUMP_AS_BUMP,

/// Bump as tangent/normal mapping.
#[doc(alias = "GPU_BUMP_AS_TANG")]
AsTangent = ctru_sys::GPU_BUMP_AS_TANG,
}

impl TryFrom<u8> for BumpMappingMode {
type Error = String;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
ctru_sys::GPU_BUMP_NOT_USED => Ok(BumpMappingMode::NotUsed),
ctru_sys::GPU_BUMP_AS_BUMP => Ok(BumpMappingMode::AsBump),
ctru_sys::GPU_BUMP_AS_TANG => Ok(BumpMappingMode::AsTangent),
_ => Err("invalid value for BumpMappingMode".to_string()),
}
}
}

#[cfg(test)]
mod tests {
use super::Lut;
Expand Down
1 change: 1 addition & 0 deletions citro3d/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use ctru_sys::{GPU_COLORBUF, GPU_DEPTHBUF};

use crate::{Error, RenderQueue, Result};

pub mod effect;
mod transfer;

/// A render target for `citro3d`. Frame data will be written to this target
Expand Down
Loading
Loading