Added time parameter to shader evaluation.
It's not used right now, but in the future I want shaders to be able to vary over time and have motion blur. This serves as a nice little reminder by putting it in the API.
This commit is contained in:
parent
6f5984a379
commit
e2a417884d
|
@ -10,7 +10,12 @@ use surface::SurfaceIntersectionData;
|
||||||
pub trait SurfaceShader: Debug + Sync {
|
pub trait SurfaceShader: Debug + Sync {
|
||||||
/// Takes the result of a surface intersection and returns the surface
|
/// Takes the result of a surface intersection and returns the surface
|
||||||
/// closure to be evaluated at that intersection point.
|
/// closure to be evaluated at that intersection point.
|
||||||
fn shade(&self, data: &SurfaceIntersectionData, wavelength: f32) -> SurfaceClosureUnion;
|
fn shade(
|
||||||
|
&self,
|
||||||
|
data: &SurfaceIntersectionData,
|
||||||
|
time: f32,
|
||||||
|
wavelength: f32,
|
||||||
|
) -> SurfaceClosureUnion;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clearly we must eat this brownie before the world ends, lest it
|
/// Clearly we must eat this brownie before the world ends, lest it
|
||||||
|
@ -37,8 +42,13 @@ pub enum SimpleSurfaceShader {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SurfaceShader for SimpleSurfaceShader {
|
impl SurfaceShader for SimpleSurfaceShader {
|
||||||
fn shade(&self, data: &SurfaceIntersectionData, wavelength: f32) -> SurfaceClosureUnion {
|
fn shade(
|
||||||
let _ = data; // Silence "unused" compiler warning
|
&self,
|
||||||
|
data: &SurfaceIntersectionData,
|
||||||
|
time: f32,
|
||||||
|
wavelength: f32,
|
||||||
|
) -> SurfaceClosureUnion {
|
||||||
|
let _ = (data, time); // Silence "unused" compiler warning
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
SimpleSurfaceShader::Emit { color } => {
|
SimpleSurfaceShader::Emit { color } => {
|
||||||
|
|
|
@ -249,7 +249,11 @@ impl<'a> Surface for TriangleMesh<'a> {
|
||||||
// Fill in intersection data
|
// Fill in intersection data
|
||||||
isects[r.id as usize] = SurfaceIntersection::Hit {
|
isects[r.id as usize] = SurfaceIntersection::Hit {
|
||||||
intersection_data: intersection_data,
|
intersection_data: intersection_data,
|
||||||
closure: shader.shade(&intersection_data, wr.wavelength),
|
closure: shader.shade(
|
||||||
|
&intersection_data,
|
||||||
|
wr.time,
|
||||||
|
wr.wavelength,
|
||||||
|
),
|
||||||
};
|
};
|
||||||
r.max_t = t;
|
r.max_t = t;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user