1 #ifndef MATERIAL_HXX
  2 #define MATERIAL_HXX
  3 
  4 #include "Vec3f.hxx"
  5 #include "Texture.hxx"
  6 #include "Procedural.hxx"
  7 
  8 #include "defines.h"
  9 
 10 // Class to store several material properties
 11 
 12 class Material
 13 {
 14 public:
 15 	Vec3f      color;                      // Color vector (RGB)
 16 	float      ambient,                    // Percentage of *additional* ambient light
 17 	           mirror,                     // Percentage of mirroring component
 18 	           mirror_filter,              // Filter mirrored image in object color                               (0 = no filter,  1 = colored)
 19 	           glossy_mirror,              // Percentage of glossy mirror component
 20 	           glossy_transparency,        // Percentage of glossy transparency component
 21 	           glossy_mirror_filter,       // Filter glossy mirrored image in object color                        (0 = no filter,  1 = colored)
 22 	           glossy_transparency_filter, // Filter glossy mirrored image in object color                        (0 = no filter,  1 = colored)
 23 	           transparency,               // Percentage of transparency
 24 	           refrac_index,               // Refraction index of material                                        (Vacuum = 1.0,   Glass = 1.5 - 1.9)
 25 	           refrac_filter,              // Filter refracted image in object color                              (0 = no filter,  1 = colored)
 26 	           subsurface_scat,            // Percentage of subsurface scattered illumination, these are
 27 	                                       // multiplicative, NOT additive to those of mirror and reflection!
 28 	           c1,                         // Reflectance coefficient for Schlick shading, primary   layer        See note below
 29 	           c2,                         // Reflectance coefficient for Schlick shading, secondary layer        See note below
 30 	           p1,                         // Isotropy    coefficient for Schlick shading, primary   layer        (0 = anisotropy, 1 = isotropy)
 31 	           p2,                         // Isotropy    coefficient for Schlick shading, secondary layer        (0 = anisotropy, 1 = isotropy)
 32 	           r1,                         // Specular    coefficient for Schlick shading, primary   layer        (0 = specular,   1 = diffuse)
 33 	           r2;                         // Specular    coefficient for Schlick shading, secondary layer        (0 = specular,   1 = diffuse)
 34 
 35 	// Note:
 36 	// The Schlick coefficient is calculated as follows: Let nm be the refraction index of the material and nv = 1.0 the index in vacuum.
 37 	// Use n = nv/nm to calculate c = ((n-1)/(n+1))^2.
 38 
 39 	Texture             *texture;
 40 	vector<Procedural *> procedural;
 41 
 42 	Material(Vec3f Color)
 43 		: color(Color), ambient(0.0f), mirror(UNDEF), mirror_filter(UNDEF),
 44 		  glossy_mirror(UNDEF), glossy_transparency(UNDEF),
 45 		  glossy_mirror_filter(UNDEF), glossy_transparency_filter(UNDEF),
 46 	          transparency(UNDEF), refrac_index(UNDEF), refrac_filter(UNDEF),
 47 		  subsurface_scat(0.0f),
 48 		  c1(UNDEF), c2(UNDEF), p1(UNDEF), p2(UNDEF), r1(UNDEF), r2(UNDEF),
 49 		  texture(NULL)
 50 	{
 51 		
 52 	};
 53 
 54 	virtual ~Material(){};
 55 
 56 	virtual void SetSchlickParams(float C1, float P1, float R1, float C2 = UNDEF, float P2 = UNDEF, float R2 = UNDEF)
 57 	{
 58 		c1 = C1;
 59 		p1 = P1;
 60 		r1 = R1;
 61 		c2 = C2;
 62 		p2 = P2;
 63 		r2 = R2;
 64 	}
 65 
 66 	virtual void SetMirrorParams(float mirror = UNDEF, float mirror_filter = UNDEF)
 67 	{
 68 		this->mirror        = mirror;
 69 		this->mirror_filter = mirror_filter;
 70 	}
 71 
 72 	virtual void SetGlossyMirrorParams(float glossy_mirror = UNDEF, float glossy_mirror_filter = UNDEF)
 73 	{
 74 		this->glossy_mirror        = glossy_mirror;
 75 		this->glossy_mirror_filter = glossy_mirror_filter;
 76 	}
 77 
 78 	virtual void SetGlossyTransparencyParams(float glossy_transparency = UNDEF, float glossy_transparency_filter = UNDEF)
 79 	{
 80 		this->glossy_transparency        = glossy_transparency;
 81 		this->glossy_transparency_filter = glossy_transparency_filter;
 82 	}
 83 
 84 	virtual void SetTransparencyParams(float transparency = UNDEF, float refrac_index = UNDEF, float refrac_filter = UNDEF)
 85 	{
 86 		this->transparency  = transparency;
 87 		this->refrac_index  = refrac_index;
 88 		this->refrac_filter = refrac_filter;
 89 	}
 90 
 91 	// Remember that these percentages are multiplicative to those of mirror/transparency, not additive!!
 92 	virtual void SetSubsurfaceScattering(float percentage = 0.0f)
 93 	{
 94 		this->subsurface_scat = percentage;
 95 	}
 96 
 97 	virtual void LoadTexture(char* textureFileName)
 98 	{
 99 		texture = new Texture(textureFileName);
100 	}
101 };
102 
103 #endif


syntax highlighted by Code2HTML, v. 0.9.1