Continuing work on Texture creation
This commit is contained in:
parent
87afe4168d
commit
2e9526ce18
10 changed files with 112 additions and 50 deletions
|
|
@ -1,15 +1,16 @@
|
|||
use crate::textures::*;
|
||||
use crate::utils::{MIPMap, MIPMapFilterOptions, TextureParameterDictionary};
|
||||
use crate::{Arena, FileLoc};
|
||||
use anyhow::{anyhow, Result};
|
||||
use anyhow::{Result, anyhow};
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use shared::Float;
|
||||
use shared::core::color::ColorEncoding;
|
||||
use shared::core::geometry::Vector3f;
|
||||
use shared::core::image::WrapMode;
|
||||
use shared::core::texture::SpectrumType;
|
||||
use shared::core::texture::{
|
||||
CylindricalMapping, PlanarMapping, SphericalMapping, TextureEvalContext, TextureMapping2D,
|
||||
UVMapping,
|
||||
CylindricalMapping, PlanarMapping, PointTransformMapping, SphericalMapping,
|
||||
TextureEvalContext, TextureMapping2D, TextureMapping3D, UVMapping,
|
||||
};
|
||||
use shared::spectra::{SampledSpectrum, SampledWavelengths};
|
||||
use shared::textures::{
|
||||
|
|
@ -18,7 +19,6 @@ use shared::textures::{
|
|||
SpectrumConstantTexture, SpectrumDotsTexture, WindyTexture, WrinkledTexture,
|
||||
};
|
||||
use shared::utils::Transform;
|
||||
use shared::Float;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex, OnceLock};
|
||||
|
||||
|
|
@ -38,7 +38,6 @@ pub enum FloatTexture {
|
|||
Bilerp(FloatBilerpTexture),
|
||||
}
|
||||
|
||||
|
||||
impl Default for FloatTexture {
|
||||
fn default() -> Self {
|
||||
FloatTexture::Constant(FloatConstantTexture::new(1.0))
|
||||
|
|
@ -102,6 +101,7 @@ pub trait CreateSpectrumTexture {
|
|||
parameters: TextureParameterDictionary,
|
||||
spectrum_type: SpectrumType,
|
||||
loc: FileLoc,
|
||||
arena: &Arena,
|
||||
) -> Result<SpectrumTexture>;
|
||||
}
|
||||
|
||||
|
|
@ -112,29 +112,29 @@ impl SpectrumTexture {
|
|||
params: TextureParameterDictionary,
|
||||
spectrum_type: SpectrumType,
|
||||
loc: FileLoc,
|
||||
_arena: &Arena,
|
||||
arena: &Arena,
|
||||
) -> Result<Self> {
|
||||
match name {
|
||||
"constant" => {
|
||||
SpectrumConstantTexture::create(render_from_texture, params, spectrum_type, loc)
|
||||
SpectrumConstantTexture::create(render_from_texture, params, spectrum_type, loc, arena)
|
||||
}
|
||||
"scale" => {
|
||||
SpectrumScaledTexture::create(render_from_texture, params, spectrum_type, loc)
|
||||
SpectrumScaledTexture::create(render_from_texture, params, spectrum_type, loc, arena)
|
||||
}
|
||||
"mix" => SpectrumMixTexture::create(render_from_texture, params, spectrum_type, loc),
|
||||
"mix" => SpectrumMixTexture::create(render_from_texture, params, spectrum_type, loc, arena),
|
||||
"directionmix" => {
|
||||
SpectrumDirectionMixTexture::create(render_from_texture, params, spectrum_type, loc)
|
||||
SpectrumDirectionMixTexture::create(render_from_texture, params, spectrum_type, loc, arena)
|
||||
}
|
||||
"bilerp" => {
|
||||
SpectrumBilerpTexture::create(render_from_texture, params, spectrum_type, loc)
|
||||
SpectrumBilerpTexture::create(render_from_texture, params, spectrum_type, loc, arena)
|
||||
}
|
||||
"imagemap" => {
|
||||
SpectrumImageTexture::create(render_from_texture, params, spectrum_type, loc)
|
||||
SpectrumImageTexture::create(render_from_texture, params, spectrum_type, loc, arena)
|
||||
}
|
||||
"checkerboard" => {
|
||||
SpectrumCheckerboardTexture::create(render_from_texture, params, spectrum_type, loc)
|
||||
SpectrumCheckerboardTexture::create(render_from_texture, params, spectrum_type, loc, arena)
|
||||
}
|
||||
"dots" => SpectrumDotsTexture::create(render_from_texture, params, spectrum_type, loc),
|
||||
"dots" => SpectrumDotsTexture::create(render_from_texture, params, spectrum_type, loc, arena),
|
||||
_ => Err(anyhow!(
|
||||
"Spectrum texture type '{}' unknown at {}",
|
||||
name,
|
||||
|
|
@ -197,6 +197,21 @@ impl CreateTextureMapping for TextureMapping2D {
|
|||
}
|
||||
}
|
||||
|
||||
impl CreateTextureMapping for TextureMapping3D {
|
||||
fn create(
|
||||
params: &TextureParameterDictionary,
|
||||
render_from_texture: &Transform,
|
||||
loc: &FileLoc,
|
||||
) -> Result<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let mapping = PointTransformMapping::new(render_from_texture.inverse());
|
||||
Ok(TextureMapping3D::PointTransform(mapping))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub static TEXTURE_CACHE: OnceLock<Mutex<HashMap<TexInfo, Arc<MIPMap>>>> = OnceLock::new();
|
||||
|
||||
pub fn get_texture_cache() -> &'static Mutex<HashMap<TexInfo, Arc<MIPMap>>> {
|
||||
|
|
|
|||
|
|
@ -1,39 +1,64 @@
|
|||
use crate::Arena;
|
||||
use crate::core::texture::{
|
||||
CreateFloatTexture, CreateSpectrumTexture, SpectrumTexture
|
||||
};
|
||||
CreateFloatTexture, CreateSpectrumTexture, CreateTextureMapping, FloatTexture, SpectrumTexture,
|
||||
};
|
||||
use crate::utils::{FileLoc, TextureParameterDictionary};
|
||||
use anyhow::Result;
|
||||
use shared::core::texture::{SpectrumType, TextureEvalContext};
|
||||
use shared::{
|
||||
spectra::{SampledSpectrum, SampledWavelengths},
|
||||
textures::{FloatBilerpTexture, SpectrumBilerpTexture},
|
||||
utils::Transform
|
||||
};
|
||||
|
||||
use crate::{
|
||||
core::texture::FloatTexture,
|
||||
utils::{FileLoc, TextureParameterDictionary}
|
||||
};
|
||||
use shared::core::spectrum::Spectrum;
|
||||
use shared::core::texture::{SpectrumType, TextureMapping2D};
|
||||
use shared::spectra::ConstantSpectrum;
|
||||
use shared::textures::{FloatBilerpTexture, SpectrumBilerpTexture};
|
||||
use shared::utils::Transform;
|
||||
|
||||
impl CreateFloatTexture for FloatBilerpTexture {
|
||||
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 = TextureMapping2D::create(¶meters, &render_from_texture, &loc)?;
|
||||
|
||||
let tex = FloatBilerpTexture::new(
|
||||
map,
|
||||
parameters.get_one_float("v00", 0.)?,
|
||||
parameters.get_one_float("v01", 1.)?,
|
||||
parameters.get_one_float("v10", 0.)?,
|
||||
parameters.get_one_float("v11", 1.)?,
|
||||
);
|
||||
Ok(FloatTexture::Bilerp(tex))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl CreateSpectrumTexture for SpectrumBilerpTexture {
|
||||
fn create(
|
||||
_render_from_texture: Transform,
|
||||
_parameters: TextureParameterDictionary,
|
||||
_spectrum_type: SpectrumType,
|
||||
_loc: FileLoc,
|
||||
render_from_texture: Transform,
|
||||
parameters: TextureParameterDictionary,
|
||||
spectrum_type: SpectrumType,
|
||||
loc: FileLoc,
|
||||
arena: &Arena,
|
||||
) -> Result<SpectrumTexture> {
|
||||
todo!()
|
||||
let map = TextureMapping2D::create(¶meters, &render_from_texture, &loc)?;
|
||||
let zero = Spectrum::Constant(ConstantSpectrum::new(0.));
|
||||
let one = Spectrum::Constant(ConstantSpectrum::new(1.));
|
||||
|
||||
// `Spectrum` is already a device type, so it is allocated into the arena
|
||||
// rather than uploaded -- upload is for host trees (Arc) -> device (Ptr).
|
||||
let mut get = |name: &str, def: Spectrum| {
|
||||
let s = parameters
|
||||
.get_one_spectrum(name, Some(def), spectrum_type)
|
||||
.unwrap_or(def);
|
||||
arena.alloc(s)
|
||||
};
|
||||
|
||||
let tex = SpectrumBilerpTexture::new(
|
||||
map,
|
||||
get("v00", zero),
|
||||
get("v01", one),
|
||||
get("v10", zero),
|
||||
get("v11", one),
|
||||
);
|
||||
Ok(SpectrumTexture::Bilerp(tex))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ impl CreateSpectrumTexture for SpectrumCheckerboardTexture {
|
|||
_parameters: TextureParameterDictionary,
|
||||
_spectrum_type: SpectrumType,
|
||||
_loc: FileLoc,
|
||||
_arena: &Arena,
|
||||
) -> Result<SpectrumTexture> {
|
||||
todo!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
use crate::Arena;
|
||||
use anyhow::Result;
|
||||
use shared::core::spectrum::Spectrum;
|
||||
use shared::spectra::ConstantSpectrum;
|
||||
use shared::{
|
||||
core::texture::{SpectrumType, TextureEvalContext},
|
||||
core::texture::SpectrumType,
|
||||
textures::{FloatConstantTexture, SpectrumConstantTexture},
|
||||
utils::Transform
|
||||
utils::Transform,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
|
@ -15,22 +17,30 @@ use crate::{
|
|||
impl CreateFloatTexture for FloatConstantTexture {
|
||||
fn create(
|
||||
_render_from_texture: Transform,
|
||||
_parameters: TextureParameterDictionary,
|
||||
parameters: TextureParameterDictionary,
|
||||
_loc: FileLoc,
|
||||
_arena: &Arena,
|
||||
) -> Result<FloatTexture> {
|
||||
todo!()
|
||||
let value = parameters.get_one_float("value", 1.)?;
|
||||
Ok(FloatTexture::Constant(FloatConstantTexture::new(value)))
|
||||
}
|
||||
}
|
||||
|
||||
impl CreateSpectrumTexture for SpectrumConstantTexture {
|
||||
fn create(
|
||||
_render_from_texture: Transform,
|
||||
_parameters: TextureParameterDictionary,
|
||||
_spectrum_type: SpectrumType,
|
||||
parameters: TextureParameterDictionary,
|
||||
spectrum_type: SpectrumType,
|
||||
_loc: FileLoc,
|
||||
_arena: &Arena,
|
||||
) -> Result<SpectrumTexture> {
|
||||
todo!()
|
||||
let one = Spectrum::Constant(ConstantSpectrum::new(1.));
|
||||
let value = parameters
|
||||
.get_one_spectrum("value", Some(one), spectrum_type)
|
||||
.unwrap_or(one);
|
||||
Ok(SpectrumTexture::Constant(SpectrumConstantTexture::new(
|
||||
value,
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ impl CreateSpectrumTexture for SpectrumDotsTexture {
|
|||
_parameters: TextureParameterDictionary,
|
||||
_spectrum_type: SpectrumType,
|
||||
_loc: FileLoc,
|
||||
_arena: &Arena,
|
||||
) -> Result<SpectrumTexture> {
|
||||
todo!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ impl CreateSpectrumTexture for SpectrumImageTexture {
|
|||
parameters: TextureParameterDictionary,
|
||||
spectrum_type: SpectrumType,
|
||||
loc: FileLoc,
|
||||
_arena: &Arena,
|
||||
) -> Result<SpectrumTexture> {
|
||||
let mapping = TextureMapping2D::create(¶meters, &render_from_texture, &loc)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,19 @@
|
|||
use crate::core::texture::{CreateSpectrumTexture, SpectrumTexture };
|
||||
use crate::core::texture::{CreateSpectrumTexture, SpectrumTexture};
|
||||
use crate::utils::{FileLoc, TextureParameterDictionary};
|
||||
use crate::Arena;
|
||||
use anyhow::Result;
|
||||
use shared::Transform;
|
||||
use shared::core::texture::SpectrumType;
|
||||
use shared::textures::MarbleTexture;
|
||||
|
||||
impl CreateSpectrumTexture for MarbleTexture {
|
||||
fn create(
|
||||
_render_from_texture: shared::utils::Transform,
|
||||
_parameters: crate::utils::TextureParameterDictionary,
|
||||
_render_from_texture: Transform,
|
||||
_parameters: TextureParameterDictionary,
|
||||
_spectrum_type: SpectrumType,
|
||||
_loc: crate::utils::FileLoc,
|
||||
) -> anyhow::Result<SpectrumTexture> {
|
||||
_loc: FileLoc,
|
||||
_arena: &Arena,
|
||||
) -> Result<SpectrumTexture> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ impl CreateSpectrumTexture for SpectrumMixTexture {
|
|||
_parameters: TextureParameterDictionary,
|
||||
_spectrum_type: SpectrumType,
|
||||
_loc: FileLoc,
|
||||
_arena: &Arena,
|
||||
) -> Result<SpectrumTexture> {
|
||||
todo!()
|
||||
}
|
||||
|
|
@ -98,6 +99,7 @@ impl CreateSpectrumTexture for SpectrumDirectionMixTexture {
|
|||
_parameters: TextureParameterDictionary,
|
||||
_spectrum_type: SpectrumType,
|
||||
_loc: FileLoc,
|
||||
_arena: &Arena,
|
||||
) -> Result<SpectrumTexture> {
|
||||
todo!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ mod scaled;
|
|||
mod windy;
|
||||
mod wrinkled;
|
||||
|
||||
pub use bilerp::*;
|
||||
pub use image::*;
|
||||
pub use mix::*;
|
||||
pub use scaled::*;
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ impl CreateSpectrumTexture for SpectrumScaledTexture {
|
|||
parameters: TextureParameterDictionary,
|
||||
spectrum_type: SpectrumType,
|
||||
_loc: FileLoc,
|
||||
_arena: &Arena,
|
||||
) -> Result<SpectrumTexture> {
|
||||
let one = Spectrum::Constant(ConstantSpectrum::new(1.0));
|
||||
let tex = parameters
|
||||
|
|
|
|||
Loading…
Reference in a new issue