209 lines
6.8 KiB
Rust
209 lines
6.8 KiB
Rust
use crate::core::pbrt::Float;
|
|
use crate::geometry::{Point3f, Vector3f, Normal3f, Point2f};
|
|
use crate::core::interaction::SurfaceInteraction;
|
|
|
|
pub struct TextureEvalContext {
|
|
p: Point3f,
|
|
dpdx: Vector3f,
|
|
dpdy: Vector3f,
|
|
n: Normal3f,
|
|
uv: Point2f,
|
|
// All 0
|
|
dudx: Float,
|
|
dudy: Float,
|
|
dvdx: Float,
|
|
dvdy: Float,
|
|
face_index: usize,
|
|
}
|
|
|
|
impl TextureEvalContext {
|
|
pub fn new(p: Point3f,
|
|
dpdx: Vector3f,
|
|
dpdy: Vector3f,
|
|
n: Normal3f,
|
|
uv: Point2f,
|
|
dudx: Float,
|
|
dudy: Float,
|
|
dvdx: Float,
|
|
dvdy: Float,
|
|
face_index: usize,
|
|
) -> Self {
|
|
Self {p, dpdx, dpdy, n, uv, dudx, dudy, dvdx, dvdy , face_index }
|
|
}
|
|
}
|
|
|
|
impl From<&SurfaceInteraction> for TextureEvalContext {
|
|
fn from(si: &SurfaceInteraction) -> Self {
|
|
Self {
|
|
p: si.common.pi.into(),
|
|
dpdx: si.dpdx,
|
|
dpdy: si.dpdy,
|
|
n: si.common.n,
|
|
uv: si.uv,
|
|
dudx: si.dudx,
|
|
dudy: si.dudy,
|
|
dvdx: si.dvdx,
|
|
dvdy: si.dvdy,
|
|
face_index: si.face_index,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub trait FloatTextureTrait: Send + Sync + std::fmt::Debug {
|
|
fn evaluate(&self, _ctx: &TextureEvalContext) -> Float {
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct FloatImageTexture;
|
|
|
|
impl FloatTextureTrait for FloatImageTexture {
|
|
fn evaluate(&self, _ctx: &TextureEvalContext) -> Float {
|
|
todo!();
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct GPUFloatImageTexture;
|
|
impl FloatTextureTrait for GPUFloatImageTexture {}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct FloatMixTexture;
|
|
impl FloatTextureTrait for FloatMixTexture {}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct FloatDirectionMixTexture;
|
|
impl FloatTextureTrait for FloatDirectionMixTexture {}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct FloatScaledTexture;
|
|
impl FloatTextureTrait for FloatScaledTexture {}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct FloatConstantTexture;
|
|
impl FloatTextureTrait for FloatConstantTexture {}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct FloatBilerpTexture;
|
|
impl FloatTextureTrait for FloatBilerpTexture {}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct FloatCheckerboardTexture;
|
|
impl FloatTextureTrait for FloatCheckerboardTexture {}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct FloatDotsTexture;
|
|
impl FloatTextureTrait for FloatDotsTexture {}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct FBmTexture;
|
|
impl FloatTextureTrait for FBmTexture {}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct FloatPtexTexture;
|
|
impl FloatTextureTrait for FloatPtexTexture {}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct GPUFloatPtex;
|
|
impl FloatTextureTrait for GPUFloatPtex {}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct WindyTexture;
|
|
impl FloatTextureTrait for WindyTexture {}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct WrinkledTexture;
|
|
impl FloatTextureTrait for WrinkledTexture {}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub enum FloatTexture {
|
|
FloatImage(FloatImageTexture),
|
|
GPUFloatImage(GPUFloatImageTexture),
|
|
FloatMix(FloatMixTexture),
|
|
FloatDirectionMix(FloatDirectionMixTexture),
|
|
FloatScaled(FloatScaledTexture),
|
|
FloatConstant(FloatConstantTexture),
|
|
FloatBilerp(FloatBilerpTexture),
|
|
FloatCheckerboard(FloatCheckerboardTexture),
|
|
FloatDots(FloatDotsTexture),
|
|
FBm(FBmTexture),
|
|
FloatPtex(FloatPtexTexture),
|
|
GPUFloatPtex(GPUFloatPtex),
|
|
Windy(WindyTexture),
|
|
Wrinkled(WrinkledTexture),
|
|
}
|
|
|
|
impl FloatTextureTrait for FloatTexture {
|
|
fn evaluate(&self, ctx: &TextureEvalContext) -> Float {
|
|
match self {
|
|
FloatTexture::FloatImage(texture) => texture.evaluate(ctx),
|
|
FloatTexture::GPUFloatImage(texture) => texture.evaluate(ctx),
|
|
FloatTexture::FloatMix(texture) => texture.evaluate(ctx),
|
|
FloatTexture::FloatDirectionMix(texture) => texture.evaluate(ctx),
|
|
FloatTexture::FloatScaled(texture) => texture.evaluate(ctx),
|
|
FloatTexture::FloatConstant(texture) => texture.evaluate(ctx),
|
|
FloatTexture::FloatBilerp(texture) => texture.evaluate(ctx),
|
|
FloatTexture::FloatCheckerboard(texture) => texture.evaluate(ctx),
|
|
FloatTexture::FloatDots(texture) => texture.evaluate(ctx),
|
|
FloatTexture::FBm(texture) => texture.evaluate(ctx),
|
|
FloatTexture::FloatPtex(texture) => texture.evaluate(ctx),
|
|
FloatTexture::GPUFloatPtex(texture) => texture.evaluate(ctx),
|
|
FloatTexture::Windy(texture) => texture.evaluate(ctx),
|
|
FloatTexture::Wrinkled(texture) => texture.evaluate(ctx),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct RGBConstantTexture;
|
|
pub struct RGBReflectanceConstantTexture;
|
|
pub struct SpectrumConstantTexture;
|
|
pub struct SpectrumBilerpTexture;
|
|
pub struct SpectrumCheckerboardTexture;
|
|
pub struct SpectrumImageTexture;
|
|
pub struct GPUSpectrumImageTexture;
|
|
pub struct MarbleTexture;
|
|
pub struct SpectrumMixTexture;
|
|
pub struct SpectrumDirectionMixTexture;
|
|
pub struct SpectrumDotsTexture;
|
|
pub struct SpectrumPtexTexture;
|
|
pub struct GPUSpectrumPtexTexture;
|
|
pub struct SpectrumScaledTexture;
|
|
|
|
pub enum SpectrumTexture {
|
|
RGBConstant(RGBConstantTexture),
|
|
RGBReflectanceConstant(RGBReflectanceConstantTexture),
|
|
SpectrumConstant(SpectrumConstantTexture),
|
|
SpectrumBilerp(SpectrumBilerpTexture),
|
|
SpectrumCheckerboard(SpectrumCheckerboardTexture),
|
|
SpectrumImage(SpectrumImageTexture),
|
|
GPUSpectrumImage(GPUSpectrumImageTexture),
|
|
Marble(MarbleTexture),
|
|
SpectrumMix(SpectrumMixTexture),
|
|
SpectrumDirectionMix(SpectrumDirectionMixTexture),
|
|
SpectrumDots(SpectrumDotsTexture),
|
|
SpectrumPtex(SpectrumPtexTexture),
|
|
GPUSpectrumPtex(GPUSpectrumPtexTexture),
|
|
SpectrumScaled(SpectrumScaledTexture),
|
|
}
|
|
|
|
impl SpectrumTexture {
|
|
// pub fn evaluate(&self, ctx: TextureEvalContext) -> f32 {
|
|
// match self {
|
|
// SpectrumTexture::FloatImage(texture) => texture.evaluate(ctx),
|
|
// SpectrumTexture::GPUFloatImage(texture) => texture.evaluate(ctx),
|
|
// SpectrumTexture::FloatMix(texture) => texture.evaluate(ctx),
|
|
// SpectrumTexture::FloatDirectionMix(texture) => texture.evaluate(ctx),
|
|
// SpectrumTexture::FloatScaled(texture) => texture.evaluate(ctx),
|
|
// SpectrumTexture::FloatConstant(texture) => texture.evaluate(ctx),
|
|
// SpectrumTexture::FloatBilerp(texture) => texture.evaluate(ctx),
|
|
// SpectrumTexture::FloatCheckerboard(texture) => texture.evaluate(ctx),
|
|
// SpectrumTexture::FloatDots(texture) => texture.evaluate(ctx),
|
|
// SpectrumTexture::FBm(texture) => texture.evaluate(ctx),
|
|
// SpectrumTexture::FloatPtex(texture) => texture.evaluate(ctx),
|
|
// SpectrumTexture::GPUFloatPtex(texture) => texture.evaluate(ctx),
|
|
// SpectrumTexture::Windy(texture) => texture.evaluate(ctx),
|
|
// SpectrumTexture::Wrinkled(texture) => texture.evaluate(ctx),
|
|
// }
|
|
// }
|
|
}
|