From aba574219c6157fbe841ea2e298fc1aff7bac1fb Mon Sep 17 00:00:00 2001 From: Wito Wiala Date: Tue, 1 Sep 2026 22:45:42 +0100 Subject: [PATCH] Added creators to all textures but mix, need to decide now on a bloody architecture, this repo was in an insane state --- shared/src/textures/marble.rs | 3 +-- shared/src/textures/windy.rs | 3 +++ shared/src/textures/wrinkled.rs | 7 ++++++ src/textures/mix.rs | 40 +++++++++++++++++++++------------ src/textures/windy.rs | 17 +++++++------- src/textures/wrinkled.rs | 23 +++++++++++-------- 6 files changed, 60 insertions(+), 33 deletions(-) diff --git a/shared/src/textures/marble.rs b/shared/src/textures/marble.rs index 87b878b..f5a2685 100644 --- a/shared/src/textures/marble.rs +++ b/shared/src/textures/marble.rs @@ -22,7 +22,6 @@ pub struct MarbleTexture { pub colorspace: Ptr, } - impl MarbleTexture { pub fn evaluate( &self, @@ -61,6 +60,6 @@ impl MarbleTexture { let (rgb_vec, _) = evaluate_cubic_bezier(&colors[first_idx..first_idx + 4], t_segment); let rgb = RGB::new(rgb_vec.x() * 1.5, rgb_vec.y() * 1.5, rgb_vec.z() * 1.5); - RGBAlbedoSpectrum::new(&*self.colorspace, rgb).sample(lambda) + RGBAlbedoSpectrum::new(&self.colorspace, rgb).sample(lambda) } } diff --git a/shared/src/textures/windy.rs b/shared/src/textures/windy.rs index 246fee0..542bf21 100644 --- a/shared/src/textures/windy.rs +++ b/shared/src/textures/windy.rs @@ -10,6 +10,9 @@ pub struct WindyTexture { } impl WindyTexture { + pub fn new(mapping: TextureMapping3D) -> Self { + Self { mapping } + } pub fn evaluate(&self, ctx: &TextureEvalContext) -> Float { let c = self.mapping.map(ctx); let wind_strength = fbm( diff --git a/shared/src/textures/wrinkled.rs b/shared/src/textures/wrinkled.rs index 97b642b..c951fef 100644 --- a/shared/src/textures/wrinkled.rs +++ b/shared/src/textures/wrinkled.rs @@ -11,6 +11,13 @@ pub struct WrinkledTexture { } impl WrinkledTexture { + pub fn new(mapping: TextureMapping3D, octaves: u32, omega: Float) -> Self { + Self { + mapping, + octaves, + omega, + } + } pub fn evaluate(&self, ctx: &TextureEvalContext) -> Float { let c = self.mapping.map(ctx); turbulence(c.p, c.dpdx, c.dpdy, self.omega, self.octaves) diff --git a/src/textures/mix.rs b/src/textures/mix.rs index 05ac31d..41f747c 100644 --- a/src/textures/mix.rs +++ b/src/textures/mix.rs @@ -1,20 +1,19 @@ -use crate::core::texture::{ - CreateSpectrumTexture, FloatTexture, SpectrumTexture }; -use crate::utils::{FileLoc, TextureParameterDictionary}; use crate::Arena; +use crate::core::texture::{CreateSpectrumTexture, FloatTexture, SpectrumTexture}; +use crate::utils::{FileLoc, TextureParameterDictionary}; use anyhow::Result; +use shared::Float; use shared::core::geometry::{Vector3f, VectorLike}; use shared::core::texture::{SpectrumType, TextureEvalContext}; use shared::spectra::{SampledSpectrum, SampledWavelengths}; use shared::utils::Transform; -use shared::Float; use std::sync::Arc; #[derive(Clone, Debug)] pub struct FloatMixTexture { pub tex1: Arc, pub tex2: Arc, - pub amount: Arc + pub amount: Arc, } impl FloatMixTexture { @@ -44,7 +43,7 @@ impl FloatMixTexture { pub struct FloatDirectionMixTexture { pub tex1: Arc, pub tex2: Arc, - pub dir: Vector3f + pub dir: Vector3f, } impl FloatDirectionMixTexture { @@ -71,18 +70,32 @@ impl FloatDirectionMixTexture { pub struct SpectrumMixTexture { pub tex1: Arc, pub tex2: Arc, - pub amount: Arc + pub amount: Arc, } impl CreateSpectrumTexture for SpectrumMixTexture { fn create( _render_from_texture: Transform, - _parameters: TextureParameterDictionary, - _spectrum_type: SpectrumType, - _loc: FileLoc, - _arena: &Arena, + parameters: TextureParameterDictionary, + spectrum_type: SpectrumType, + loc: FileLoc, + arena: &Arena, ) -> Result { - todo!() + let zero = Spectrum::Constant(ConstantSpectrum::new(0.)); + let one = Spectrum::Constant(ConstantSpectrum::new(1.)); + + let tex = |name: &str, def: Spectrum| { + parameters + .get_spectrum_texture(name, Some(def), spectrum_type) + .expect("default supplied") + }; + + let tex = SpectrumMixTexture::new( + tex("tex1", zero), + tex("tex2", one), + parameters.get_float_texture("amount", 0.5)?, + ); + Ok(SpectrumTexture::Mix(tex)) } } @@ -90,7 +103,7 @@ impl CreateSpectrumTexture for SpectrumMixTexture { pub struct SpectrumDirectionMixTexture { pub tex1: Arc, pub tex2: Arc, - pub dir: Vector3f + pub dir: Vector3f, } impl CreateSpectrumTexture for SpectrumDirectionMixTexture { @@ -104,4 +117,3 @@ impl CreateSpectrumTexture for SpectrumDirectionMixTexture { todo!() } } - diff --git a/src/textures/windy.rs b/src/textures/windy.rs index 7f9c728..8d300b2 100644 --- a/src/textures/windy.rs +++ b/src/textures/windy.rs @@ -1,20 +1,21 @@ use crate::Arena; use anyhow::Result; -use shared::{textures::WindyTexture, utils::Transform}; +use shared::{core::texture::TextureMapping3D, textures::WindyTexture, utils::Transform}; use crate::{ - core::texture::{CreateFloatTexture, FloatTexture }, - utils::{FileLoc, TextureParameterDictionary} + core::texture::{CreateFloatTexture, CreateTextureMapping, FloatTexture}, + utils::{FileLoc, TextureParameterDictionary}, }; impl CreateFloatTexture for WindyTexture { fn create( - _render_from_texture: Transform, - _parameters: TextureParameterDictionary, - _loc: FileLoc, + render_from_texture: Transform, + parameters: TextureParameterDictionary, + loc: FileLoc, _arena: &Arena, ) -> Result { - todo!() + let map = TextureMapping3D::create(¶meters, &render_from_texture, &loc)?; + let tex = WindyTexture::new(map); + Ok(FloatTexture::Windy(tex)) } } - diff --git a/src/textures/wrinkled.rs b/src/textures/wrinkled.rs index e68a152..6c73768 100644 --- a/src/textures/wrinkled.rs +++ b/src/textures/wrinkled.rs @@ -1,20 +1,25 @@ use crate::Arena; use anyhow::Result; -use shared::{textures::WrinkledTexture, utils::Transform}; +use shared::{core::texture::TextureMapping3D, textures::WrinkledTexture, utils::Transform}; use crate::{ - core::texture::{CreateFloatTexture, FloatTexture }, - utils::{FileLoc, TextureParameterDictionary} + core::texture::{CreateFloatTexture, CreateTextureMapping, FloatTexture}, + utils::{FileLoc, TextureParameterDictionary}, }; impl CreateFloatTexture for WrinkledTexture { fn create( - _render_from_texture: Transform, - _parameters: TextureParameterDictionary, - _loc: FileLoc, - _arena: &Arena, + render_from_texture: Transform, + parameters: TextureParameterDictionary, + loc: FileLoc, + arena: &Arena, ) -> Result { - todo!() + let map = TextureMapping3D::create(¶meters, &render_from_texture, &loc)?; + let tex = WrinkledTexture::new( + map, + parameters.get_one_int("octaves", 8)?.try_into().unwrap(), + parameters.get_one_float("roughness", 0.5)?, + ); + Ok(FloatTexture::Wrinkled(tex)) } } -