diff options
author | Anthony LaTorre <telatorre@gmail.com> | 2011-06-12 21:31:22 -0400 |
---|---|---|
committer | Anthony LaTorre <telatorre@gmail.com> | 2011-06-12 21:31:22 -0400 |
commit | 870236b3c4950762a73247c68023a8dee6e14a7b (patch) | |
tree | a9b634e0ef43f17c00e725972240d48673a708b6 /src/materials.h | |
parent | e06a8b551c730e3d1111fc571c5d48edb85f70ce (diff) | |
download | chroma-870236b3c4950762a73247c68023a8dee6e14a7b.tar.gz chroma-870236b3c4950762a73247c68023a8dee6e14a7b.tar.bz2 chroma-870236b3c4950762a73247c68023a8dee6e14a7b.zip |
added some fun models; added some untested code to implement absorption, scattering, reflection, and refraction
Diffstat (limited to 'src/materials.h')
-rw-r--r-- | src/materials.h | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/src/materials.h b/src/materials.h index 05aa121..47b7d22 100644 --- a/src/materials.h +++ b/src/materials.h @@ -1,3 +1,20 @@ +#ifndef __MATERIALS_H__ +#define __MATERIALS_H__ + +__device__ float min_wavelength; +__device__ float max_wavelength; +__device__ float wavelength_step; +__device__ unsigned int wavelength_size; + +enum +{ + INIT = -1, + MAX_DEPTH_REACHED, + NO_HIT, + BULK_ABSORB, + SURFACE_ABSORB +}; + struct Material { float *refractive_index; @@ -12,12 +29,34 @@ struct Surface float *reflection_specular; }; -__device__ struct Material materials[100]; -__device__ struct Surface surfaces[100]; +__device__ Material materials[100]; +__device__ Surface surfaces[100]; + +__device__ float interp_property(const float &x, const float *fp) +{ + if (x < min_wavelength) + return fp[0]; + + if (x > max_wavelength) + return fp[wavelength_size-1]; + + unsigned int jl = (x-min_wavelength)/wavelength_step; + float xl = min_wavelength + jl*wavelength_step; + + return xl + (x-xl)*(fp[jl+1]-fp[jl])/wavelength_step; +} extern "C" { +__global__ void set_wavelength_range(float _min_wavelength, float _max_wavelength, float _wavelength_step, unsigned int _wavelength_size) +{ + min_wavelength = _min_wavelength; + max_wavelength = _max_wavelength; + wavelength_step = _wavelength_step; + wavelength_size = _wavelength_size; +} + __global__ void set_material(int material_index, float *refractive_index, float *absorption_length, float *scattering_length) { materials[material_index].refractive_index = refractive_index; @@ -33,3 +72,5 @@ __global__ void set_surface(int surface_index, float *absorption, float *reflect } } // extern "c" + +#endif |