74 lines
2.1 KiB
Rust
74 lines
2.1 KiB
Rust
// use crate::utils::{Arena, FileLoc, TextureParameterDictionary};
|
|
use crate::core::texture::{FloatTextureTrait, SpectrumTextureTrait};
|
|
use crate::spectra::get_colorspace_context;
|
|
use shared::core::spectrum::SpectrumTrait;
|
|
// use ptex::Cache;
|
|
// use ptex_filter::{PtexFilter, PtexFilterOptions, PtexFilterType};
|
|
|
|
use shared::Float;
|
|
use shared::core::color::{ColorEncoding, RGB};
|
|
use shared::core::texture::{SpectrumType, TextureEvalContext};
|
|
use shared::spectra::{RGBIlluminantSpectrum, SampledSpectrum, SampledWavelengths};
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct PtexTextureBase {
|
|
pub valid: bool,
|
|
pub filename: String,
|
|
pub encoding: ColorEncoding,
|
|
pub scale: Float,
|
|
}
|
|
|
|
impl PtexTextureBase {
|
|
pub fn new(filename: String, encoding: ColorEncoding, scale: Float) -> Self {
|
|
log::warn!(
|
|
"Ptex support is currently disabled. Texture '{}' will render as Magenta.",
|
|
filename
|
|
);
|
|
|
|
Self {
|
|
filename,
|
|
encoding,
|
|
scale,
|
|
valid: false,
|
|
}
|
|
}
|
|
|
|
pub fn sample_texture(&self, _ctx: &TextureEvalContext) -> Option<RGB> {
|
|
Some(RGB::new(1.0, 0.0, 1.0) * self.scale)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct FloatPtexTexture {
|
|
pub base: PtexTextureBase,
|
|
}
|
|
|
|
impl FloatTextureTrait for FloatPtexTexture {
|
|
fn evaluate(&self, ctx: &TextureEvalContext) -> Float {
|
|
if let Some(rgb) = self.base.sample_texture(ctx) {
|
|
rgb.g
|
|
} else {
|
|
0.0
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct SpectrumPtexTexture {
|
|
pub base: PtexTextureBase,
|
|
pub spectrum_type: SpectrumType,
|
|
}
|
|
|
|
impl SpectrumTextureTrait for SpectrumPtexTexture {
|
|
fn evaluate(&self, ctx: &TextureEvalContext, lambda: &SampledWavelengths) -> SampledSpectrum {
|
|
if let Some(rgb) = self.base.sample_texture(ctx) {
|
|
let stdcs = get_colorspace_context();
|
|
let srgb = stdcs.srgb.as_ref();
|
|
RGBIlluminantSpectrum::new(srgb, rgb).sample(lambda)
|
|
} else {
|
|
SampledSpectrum::new(0.0)
|
|
}
|
|
}
|
|
}
|
|
|
|
pub trait CreateGPUPtexTexture {}
|