55 lines
1.6 KiB
Rust
55 lines
1.6 KiB
Rust
use crate::Float;
|
|
use crate::core::texture::{SpectrumType, TextureEvalContext};
|
|
use crate::spectra::{
|
|
RGBAlbedoSpectrum, RGBColorSpace, RGBIlluminantSpectrum, RGBUnboundedSpectrum, SampledSpectrum,
|
|
SampledWavelengths,
|
|
};
|
|
|
|
/* GPU heavy code, have to see how to best approach this
|
|
*/
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct GPUFloatPtexTexture {
|
|
pub face_values: Vec<Float>,
|
|
}
|
|
|
|
impl GPUFloatPtexTexture {
|
|
pub fn evaluate(&self, ctx: &TextureEvalContext) -> Float {
|
|
self.face_values[ctx.face_index]
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct GPUSpectrumPtexTexture {
|
|
pub face_values: *const RGB,
|
|
pub n_faces: usize,
|
|
pub spectrum_type: SpectrumType,
|
|
}
|
|
|
|
impl GPUSpectrumPtexTexture {
|
|
pub fn evaluate(
|
|
&self,
|
|
ctx: &TextureEvalContext,
|
|
lambda: &SampledWavelengths,
|
|
) -> SampledSpectrum {
|
|
let index = ctx.face_index.clamp(0, self.n_faces.saturating_sub(1));
|
|
let rgb = unsafe { *self.face_values.add(index) };
|
|
let s_rgb = {
|
|
#[cfg(feature = "cuda")]
|
|
unsafe {
|
|
&*RGBColorSpace_sRGB
|
|
}
|
|
#[cfg(not(feature = "cuda"))]
|
|
RGBColorSpace::srgb()
|
|
};
|
|
|
|
match self.spectrum_type {
|
|
SpectrumType::Unbounded => RGBUnboundedSpectrum::new(s_rgb, rgb).sample(lambda),
|
|
SpectrumType::Albedo => {
|
|
let clamped_rgb = rgb.clamp(0.0, 1.0);
|
|
RGBAlbedoSpectrum::new(s_rgb, clamped_rgb).sample(lambda)
|
|
}
|
|
SpectrumType::Illuminant => RGBIlluminantSpectrum::new(s_rgb, rgb).sample(lambda),
|
|
}
|
|
}
|
|
}
|