plasma-prp 0.1.0

Read, write, inspect, and manipulate Plasma engine PRP files used by Myst Online: Uru Live
Documentation
//! hsGMatState — material rendering state flags.
//!
//! Five uint32 flag words controlling blend mode, clamping, shading, z-buffer, and misc.
//!
//! C++ ref: hsGMatState.h, hsGMatState.inl

use std::io::Read;

use anyhow::Result;

use crate::resource::prp::PlasmaRead;

/// Material rendering state — 5 flag words.
#[derive(Debug, Clone, Copy, Default)]
pub struct MatState {
    pub blend_flags: u32,
    pub clamp_flags: u32,
    pub shade_flags: u32,
    pub z_flags: u32,
    pub misc_flags: u32,
}

impl MatState {
    pub fn read(reader: &mut impl Read) -> Result<Self> {
        Ok(Self {
            blend_flags: reader.read_u32()?,
            clamp_flags: reader.read_u32()?,
            shade_flags: reader.read_u32()?,
            z_flags: reader.read_u32()?,
            misc_flags: reader.read_u32()?,
        })
    }
}

// Blend flags
#[allow(dead_code)]
pub mod blend {
    pub const TEST: u32 = 0x1;
    pub const ALPHA: u32 = 0x2;
    pub const MULT: u32 = 0x4;
    pub const ADD: u32 = 0x8;
    pub const ADD_COLOR_TIMES_ALPHA: u32 = 0x10;
    pub const ANTI_ALIAS: u32 = 0x20;
    pub const DETAIL: u32 = 0x40;
    pub const NO_COLOR: u32 = 0x80;
    pub const MADD: u32 = 0x100;
    pub const DOT3: u32 = 0x200;
    pub const ADD_SIGNED: u32 = 0x400;
    pub const ADD_SIGNED_2X: u32 = 0x800;
    pub const MASK: u32 = 0xFFE;
    pub const INVERT_ALPHA: u32 = 0x1000;
    pub const INVERT_COLOR: u32 = 0x2000;
    pub const ALPHA_MULT: u32 = 0x4000;
    pub const ALPHA_ADD: u32 = 0x8000;
    pub const NO_VTX_ALPHA: u32 = 0x10000;
    pub const NO_TEX_COLOR: u32 = 0x20000;
    pub const NO_TEX_ALPHA: u32 = 0x40000;
    pub const INVERT_VTX_ALPHA: u32 = 0x80000;
    pub const ALPHA_ALWAYS: u32 = 0x100000;
    pub const INVERT_FINAL_COLOR: u32 = 0x200000;
    pub const INVERT_FINAL_ALPHA: u32 = 0x400000;
    pub const ENV_BUMP_NEXT: u32 = 0x800000;
    pub const SUBTRACT: u32 = 0x1000000;
    pub const REV_SUBTRACT: u32 = 0x2000000;
    pub const ALPHA_TEST_HIGH: u32 = 0x4000000;
    pub const ALPHA_PREMULTIPLIED: u32 = 0x8000000;
}

// Clamp flags
#[allow(dead_code)]
pub mod clamp {
    pub const TEXTURE_U: u32 = 0x1;
    pub const TEXTURE_V: u32 = 0x2;
    pub const TEXTURE: u32 = 0x3;
}

// Shade flags
#[allow(dead_code)]
pub mod shade {
    pub const SOFT_SHADOW: u32 = 0x1;
    pub const NO_PROJECTORS: u32 = 0x2;
    pub const ENVIRON_MAP: u32 = 0x4;
    pub const VERTEX_SHADE: u32 = 0x20;
    pub const NO_SHADE: u32 = 0x40;
    pub const SPECULAR: u32 = 0x80;
    pub const WHITE: u32 = 0x200;
    pub const SPECULAR_ALPHA: u32 = 0x400;
    pub const SPECULAR_COLOR: u32 = 0x800;
    pub const SPECULAR_HIGHLIGHT: u32 = 0x1000;
    pub const VERT_COL_SHADE: u32 = 0x2000;
    pub const INHERIT: u32 = 0x4000;
    pub const IGNORE_VTX_ILLUM: u32 = 0x8000;
    pub const EMISSIVE: u32 = 0x10000;
    pub const REALLY_NO_FOG: u32 = 0x20000;
}

// Z flags
#[allow(dead_code)]
pub mod z_flags {
    pub const INC_LAYER: u32 = 0x1;
    pub const CLEAR_Z: u32 = 0x4;
    pub const NO_Z_READ: u32 = 0x8;
    pub const NO_Z_WRITE: u32 = 0x10;
    pub const Z_MASK: u32 = 0x1C;
    pub const LOD_BIAS: u32 = 0x20;
}

// Misc flags
#[allow(dead_code)]
pub mod misc {
    pub const WIRE_FRAME: u32 = 0x1;
    pub const DRAW_MESH_OUTLINES: u32 = 0x2;
    pub const TWO_SIDED: u32 = 0x4;
    pub const DRAW_AS_SPLATS: u32 = 0x8;
    pub const ADJUST_PLANE: u32 = 0x10;
    pub const ADJUST_CYLINDER: u32 = 0x20;
    pub const ADJUST_SPHERE: u32 = 0x40;
    pub const ADJUST: u32 = 0x70;
    pub const TROUBLED_LONER: u32 = 0x80;
    pub const BIND_SKIP: u32 = 0x100;
    pub const BIND_MASK: u32 = 0x200;
    pub const BIND_NEXT: u32 = 0x400;
    pub const LIGHT_MAP: u32 = 0x800;
    pub const USE_REFLECTION_XFM: u32 = 0x1000;
    pub const PERSP_PROJECTION: u32 = 0x2000;
    pub const ORTHO_PROJECTION: u32 = 0x4000;
    pub const PROJECTION: u32 = 0x6000;
    pub const RESTART_PASS_HERE: u32 = 0x8000;
    pub const BUMP_LAYER: u32 = 0x10000;
    pub const BUMP_DU: u32 = 0x20000;
    pub const BUMP_DV: u32 = 0x40000;
    pub const BUMP_DW: u32 = 0x80000;
    pub const BUMP_CHANS: u32 = 0xE0000;
    pub const NO_SHADOW_ALPHA: u32 = 0x100000;
    pub const USE_REFRACTION_XFM: u32 = 0x200000;
    pub const CAM2_SCREEN: u32 = 0x400000;
}