unlittwotexture

This commit is contained in:
Robin Appelman 2023-12-19 19:50:53 +01:00
commit b11b1ae7ec
2 changed files with 102 additions and 0 deletions

View file

@ -1,6 +1,7 @@
mod eyerefract; mod eyerefract;
mod lightmappedgeneric; mod lightmappedgeneric;
mod unlitgeneric; mod unlitgeneric;
mod unlittwotexture;
mod vertexlitgeneric; mod vertexlitgeneric;
mod water; mod water;
mod worldvertextransition; mod worldvertextransition;
@ -9,6 +10,7 @@ pub use eyerefract::EyeRefractMaterial;
pub use lightmappedgeneric::LightMappedGenericMaterial; pub use lightmappedgeneric::LightMappedGenericMaterial;
use serde::{Deserialize, Deserializer, Serialize}; use serde::{Deserialize, Deserializer, Serialize};
pub use unlitgeneric::UnlitGenericMaterial; pub use unlitgeneric::UnlitGenericMaterial;
pub use unlittwotexture::UnlitTwoTextureMaterial;
use vdf_reader::entry::{Entry, Table}; use vdf_reader::entry::{Entry, Table};
use vdf_reader::error::UnknownError; use vdf_reader::error::UnknownError;
use vdf_reader::{from_entry, VdfError}; use vdf_reader::{from_entry, VdfError};
@ -24,6 +26,8 @@ pub enum Material {
VertexLitGeneric(VertexLitGenericMaterial), VertexLitGeneric(VertexLitGenericMaterial),
#[serde(rename = "unlitgeneric")] #[serde(rename = "unlitgeneric")]
UnlitGeneric(UnlitGenericMaterial), UnlitGeneric(UnlitGenericMaterial),
#[serde(rename = "unlittwotexture")]
UnlitTwoTexture(UnlitTwoTextureMaterial),
#[serde(rename = "water")] #[serde(rename = "water")]
Water(WaterMaterial), Water(WaterMaterial),
#[serde(rename = "worldvertextransition")] #[serde(rename = "worldvertextransition")]
@ -52,6 +56,7 @@ impl Material {
Material::LightMappedGeneric(mat) => mat.translucent, Material::LightMappedGeneric(mat) => mat.translucent,
Material::VertexLitGeneric(mat) => mat.translucent, Material::VertexLitGeneric(mat) => mat.translucent,
Material::UnlitGeneric(mat) => mat.translucent, Material::UnlitGeneric(mat) => mat.translucent,
Material::UnlitTwoTexture(mat) => mat.translucent,
Material::WorldVertexTransition(mat) => mat.translucent, Material::WorldVertexTransition(mat) => mat.translucent,
Material::Water(_) => true, Material::Water(_) => true,
_ => false, _ => false,
@ -63,6 +68,7 @@ impl Material {
Material::LightMappedGeneric(mat) => mat.no_cull, Material::LightMappedGeneric(mat) => mat.no_cull,
Material::VertexLitGeneric(mat) => mat.no_cull, Material::VertexLitGeneric(mat) => mat.no_cull,
Material::UnlitGeneric(mat) => mat.no_cull, Material::UnlitGeneric(mat) => mat.no_cull,
Material::UnlitTwoTexture(mat) => mat.no_cull,
Material::WorldVertexTransition(mat) => mat.no_cull, Material::WorldVertexTransition(mat) => mat.no_cull,
Material::Water(_) => true, Material::Water(_) => true,
_ => false, _ => false,
@ -74,6 +80,7 @@ impl Material {
Material::LightMappedGeneric(mat) => mat.alpha_test.then_some(mat.alpha_test_reference), Material::LightMappedGeneric(mat) => mat.alpha_test.then_some(mat.alpha_test_reference),
Material::VertexLitGeneric(mat) => mat.alpha_test.then_some(mat.alpha_test_reference), Material::VertexLitGeneric(mat) => mat.alpha_test.then_some(mat.alpha_test_reference),
Material::UnlitGeneric(mat) => mat.alpha_test.then_some(mat.alpha_test_reference), Material::UnlitGeneric(mat) => mat.alpha_test.then_some(mat.alpha_test_reference),
Material::UnlitTwoTexture(mat) => mat.alpha_test.then_some(mat.alpha_test_reference),
Material::WorldVertexTransition(mat) => { Material::WorldVertexTransition(mat) => {
mat.alpha_test.then_some(mat.alpha_test_reference) mat.alpha_test.then_some(mat.alpha_test_reference)
} }
@ -87,6 +94,7 @@ impl Material {
Material::LightMappedGeneric(mat) => &mat.base_texture, Material::LightMappedGeneric(mat) => &mat.base_texture,
Material::VertexLitGeneric(mat) => &mat.base_texture, Material::VertexLitGeneric(mat) => &mat.base_texture,
Material::UnlitGeneric(mat) => &mat.base_texture, Material::UnlitGeneric(mat) => &mat.base_texture,
Material::UnlitTwoTexture(mat) => &mat.base_texture,
Material::WorldVertexTransition(mat) => &mat.base_texture, Material::WorldVertexTransition(mat) => &mat.base_texture,
Material::Water(mat) => mat.base_texture.as_deref().unwrap_or_default(), Material::Water(mat) => mat.base_texture.as_deref().unwrap_or_default(),
Material::EyeRefract(mat) => &mat.iris, Material::EyeRefract(mat) => &mat.iris,
@ -99,6 +107,7 @@ impl Material {
Material::LightMappedGeneric(mat) => mat.bump_map.as_deref(), Material::LightMappedGeneric(mat) => mat.bump_map.as_deref(),
Material::VertexLitGeneric(mat) => mat.bump_map.as_deref(), Material::VertexLitGeneric(mat) => mat.bump_map.as_deref(),
Material::UnlitGeneric(mat) => mat.bump_map.as_deref(), Material::UnlitGeneric(mat) => mat.bump_map.as_deref(),
Material::UnlitTwoTexture(mat) => mat.bump_map.as_deref(),
Material::WorldVertexTransition(mat) => mat.bump_map.as_deref(), Material::WorldVertexTransition(mat) => mat.bump_map.as_deref(),
Material::Water(mat) => mat.bump_map.as_deref(), Material::Water(mat) => mat.bump_map.as_deref(),
_ => None, _ => None,
@ -109,6 +118,7 @@ impl Material {
match self { match self {
Material::LightMappedGeneric(mat) => mat.surface_prop.as_deref(), Material::LightMappedGeneric(mat) => mat.surface_prop.as_deref(),
Material::UnlitGeneric(mat) => mat.surface_prop.as_deref(), Material::UnlitGeneric(mat) => mat.surface_prop.as_deref(),
Material::UnlitTwoTexture(mat) => mat.surface_prop.as_deref(),
Material::WorldVertexTransition(mat) => mat.surface_prop.as_deref(), Material::WorldVertexTransition(mat) => mat.surface_prop.as_deref(),
_ => None, _ => None,
} }
@ -119,10 +129,22 @@ impl Material {
Material::LightMappedGeneric(mat) => mat.alpha, Material::LightMappedGeneric(mat) => mat.alpha,
Material::VertexLitGeneric(mat) => mat.alpha, Material::VertexLitGeneric(mat) => mat.alpha,
Material::UnlitGeneric(mat) => mat.alpha, Material::UnlitGeneric(mat) => mat.alpha,
Material::UnlitTwoTexture(mat) => mat.alpha,
Material::WorldVertexTransition(mat) => mat.alpha, Material::WorldVertexTransition(mat) => mat.alpha,
_ => 1.0, _ => 1.0,
} }
} }
pub fn ignore_z_test(&self) -> bool {
match self {
Material::LightMappedGeneric(mat) => mat.ignore_z,
Material::VertexLitGeneric(mat) => mat.ignore_z,
Material::UnlitGeneric(mat) => mat.ignore_z,
Material::UnlitTwoTexture(mat) => mat.ignore_z,
Material::WorldVertexTransition(mat) => mat.ignore_z,
_ => false,
}
}
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]

View file

@ -0,0 +1,80 @@
use super::deserialize_path;
use crate::{default_scale, default_scale3, TextureTransform, Vec3};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UnlitTwoTextureMaterial {
/// The first texture in the blend.
#[serde(rename = "$basetexture", deserialize_with = "deserialize_path")]
pub base_texture: String,
/// The second texture to blend to.
#[serde(rename = "$texture2", deserialize_with = "deserialize_path")]
pub texture2: String,
/// Links the surface to a set of physical properties.
#[serde(rename = "$surfaceprop", default)]
pub surface_prop: Option<String>,
/// Transforms the texture before use in the material. This does not affect lightmaps on the surface.
#[serde(rename = "$basetexturetransform", default)]
pub base_texture_transform: TextureTransform,
/// Independently scales the red, green and blue channels of an albedo.
#[serde(rename = "$color", default = "default_scale3")]
pub color: Vec3,
/// Independently scales the red, green and blue channels of an albedo.
#[serde(rename = "$color2", default = "default_scale3")]
pub color2: Vec3,
/// Scales the opacity of an entire material.
#[serde(rename = "$alpha", default = "default_scale")]
pub alpha: f32,
/// Specifies a mask to use to determine binary opacity.
#[serde(rename = "$alphatest", default)]
pub alpha_test: bool,
/// Specifies a mask to use to determine binary opacity.
#[serde(rename = "$alphatestreference", default = "default_scale")]
pub alpha_test_reference: f32,
/// Vector-like edge filtering.
#[serde(rename = "$distancealpha", default)]
pub distance_alpha: bool,
/// Disables backface culling.
#[serde(rename = "$nocull", default)]
pub no_cull: bool,
/// Specifies that the material should be partially see-through.
#[serde(rename = "$translucent", default)]
pub translucent: bool,
/// bumpmap for the first texture.
#[serde(rename = "$bumpmap", default, deserialize_with = "deserialize_path")]
pub bump_map: Option<String>,
/// bumpmap for the second texture.
#[serde(rename = "$bumpmap2", default, deserialize_with = "deserialize_path")]
pub bump_map2: Option<String>,
/// Per-texel color modification via a warp texture.
#[serde(
rename = "$lightwarptexture",
default,
deserialize_with = "deserialize_path"
)]
pub light_wrap_texture: Option<String>,
/// Determines whether the surface is self-illuminated independent of environment lighting.
#[serde(rename = "$selfillum", default)]
pub self_illum: bool,
/// Flags the $bumpmap as being a self-shadowing bumpmap.
#[serde(rename = "$ssbump", default)]
pub ss_bump: bool,
/// Specular reflections.
#[serde(rename = "$envmap", default, deserialize_with = "deserialize_path")]
pub env_map: Option<String>,
/// Diffuse reflections.
#[serde(rename = "$phong", default)]
pub phong: f32,
/// Prevents fog from overdrawing a material.
#[serde(rename = "$nofog", default)]
pub no_fog: bool,
/// Ignore z filtering
#[serde(rename = "$ignorez", default)]
pub ignore_z: bool,
}