Add Pbrt scale texture and initial material stuff
This commit is contained in:
		
							parent
							
								
									2476d2d49a
								
							
						
					
					
						commit
						0dfa2128dd
					
				
					 6 changed files with 176 additions and 8 deletions
				
			
		|  | @ -35,6 +35,10 @@ impl PbrtTexture for FloatCheckerboardTexture2d { | |||
|     fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>> { | ||||
|         Err(miette!("Unable to use this texture as a spectrum texture")) | ||||
|     } | ||||
| 
 | ||||
|     fn get_dimension(&self) -> TextureDimension { | ||||
|         TextureDimension::D2 | ||||
|     } | ||||
| } | ||||
| #[derive(Debug)] | ||||
| pub(super) struct SpectrumCheckerboardTexture2d { | ||||
|  | @ -71,4 +75,8 @@ impl PbrtTexture for SpectrumCheckerboardTexture2d { | |||
|     fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>> { | ||||
|         Ok(self) | ||||
|     } | ||||
| 
 | ||||
|     fn get_dimension(&self) -> TextureDimension { | ||||
|         TextureDimension::D2 | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -46,7 +46,6 @@ impl ImageMapEncoding { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
| pub(super) struct SpectrumImageMapTexture { | ||||
|     mapping: UVMapping, | ||||
|     scale: Float, | ||||
|  | @ -55,6 +54,18 @@ pub(super) struct SpectrumImageMapTexture { | |||
|     image: image::Rgb32FImage, | ||||
| } | ||||
| 
 | ||||
| impl std::fmt::Debug for SpectrumImageMapTexture { | ||||
|     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||
|         f.debug_struct("SpectrumImageMapTexture") | ||||
|             .field("mapping", &self.mapping) | ||||
|             .field("scale", &self.scale) | ||||
|             .field("wrap", &self.wrap) | ||||
|             .field("invert", &self.invert) | ||||
|             .field("image", &"image data") | ||||
|             .finish() | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| fn srgb_nonlinear(x: f32) -> f32 { | ||||
|     if x <= 0.04045 { | ||||
|         x / 12.92 | ||||
|  | @ -125,4 +136,8 @@ impl PbrtTexture for SpectrumImageMapTexture { | |||
|     fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>> { | ||||
|         Ok(self) | ||||
|     } | ||||
| 
 | ||||
|     fn get_dimension(&self) -> TextureDimension { | ||||
|         TextureDimension::D2 | ||||
|     } | ||||
| } | ||||
|  |  | |||
							
								
								
									
										37
									
								
								ray-tracing-pbrt-scene/src/texture/scale.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								ray-tracing-pbrt-scene/src/texture/scale.rs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,37 @@ | |||
| use super::*; | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
| pub(super) struct SpectrumScaleTexture2d { | ||||
|     pub(super) tex: ValueTexture<Color, Arc<dyn Pbrt_2d_spectrum_texture>>, | ||||
|     pub(super) scale: ValueTexture<Float, Arc<dyn Pbrt_2d_float_texture>>, | ||||
| } | ||||
| 
 | ||||
| impl PbrtTexture for SpectrumScaleTexture2d { | ||||
|     fn get_dimension(&self) -> TextureDimension { | ||||
|         TextureDimension::D2 | ||||
|     } | ||||
| 
 | ||||
|     fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_float_texture>> { | ||||
|         Err(miette!("Unable to convert to float texture")) | ||||
|     } | ||||
| 
 | ||||
|     fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>> { | ||||
|         Ok(self) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl Pbrt_2d_spectrum_texture for SpectrumScaleTexture2d { | ||||
|     fn get(&self, u: Float, v: Float) -> Color { | ||||
|         let x = match &self.tex { | ||||
|             ValueTexture::Value(x) => *x, | ||||
|             ValueTexture::Texture(t) => t.get(u, v), | ||||
|         }; | ||||
| 
 | ||||
|         let s = match &self.scale { | ||||
|             ValueTexture::Value(s) => *s, | ||||
|             ValueTexture::Texture(t) => t.get(u, v), | ||||
|         }; | ||||
| 
 | ||||
|         x * s | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue