Added creators to all textures but mix, need to decide now on a bloody architecture, this repo was in an insane state

This commit is contained in:
Wito Wiala 2026-09-01 22:45:42 +01:00
parent 7c35f9b180
commit aba574219c
6 changed files with 60 additions and 33 deletions

View file

@ -22,7 +22,6 @@ pub struct MarbleTexture {
pub colorspace: Ptr<RGBColorSpace>,
}
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)
}
}

View file

@ -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(

View file

@ -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)

View file

@ -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<FloatTexture>,
pub tex2: Arc<FloatTexture>,
pub amount: Arc<FloatTexture>
pub amount: Arc<FloatTexture>,
}
impl FloatMixTexture {
@ -44,7 +43,7 @@ impl FloatMixTexture {
pub struct FloatDirectionMixTexture {
pub tex1: Arc<FloatTexture>,
pub tex2: Arc<FloatTexture>,
pub dir: Vector3f
pub dir: Vector3f,
}
impl FloatDirectionMixTexture {
@ -71,18 +70,32 @@ impl FloatDirectionMixTexture {
pub struct SpectrumMixTexture {
pub tex1: Arc<SpectrumTexture>,
pub tex2: Arc<SpectrumTexture>,
pub amount: Arc<FloatTexture>
pub amount: Arc<FloatTexture>,
}
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<SpectrumTexture> {
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<SpectrumTexture>,
pub tex2: Arc<SpectrumTexture>,
pub dir: Vector3f
pub dir: Vector3f,
}
impl CreateSpectrumTexture for SpectrumDirectionMixTexture {
@ -104,4 +117,3 @@ impl CreateSpectrumTexture for SpectrumDirectionMixTexture {
todo!()
}
}

View file

@ -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<FloatTexture> {
todo!()
let map = TextureMapping3D::create(&parameters, &render_from_texture, &loc)?;
let tex = WindyTexture::new(map);
Ok(FloatTexture::Windy(tex))
}
}

View file

@ -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<FloatTexture> {
todo!()
let map = TextureMapping3D::create(&parameters, &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))
}
}