1// tMaterial.h 
2// 
3// This file implements a tScene material. The parameters represent a legacy Blinn-Phong material which more or less 
4// matches the fixed function pipeline of OpenGL. More advanced materials/shader-models are handled by explicitly 
5// setting the ShaderFile member to point to a shader, in which case the Blinn-Phong parameters are ignored. 
6// 
7// Copyright (c) 2006, 2017 Tristan Grimmer. 
8// Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby 
9// granted, provided that the above copyright notice and this permission notice appear in all copies. 
10// 
11// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL 
12// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 
13// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 
14// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 
15// PERFORMANCE OF THIS SOFTWARE. 
16 
17#pragma once 
18#include "Scene/tObject.h" 
19namespace tScene 
20
21 
22 
23class tMaterial : public tObject 
24
25public
26 // The default constructor makes a reasonable default texture with non-zero ambient colours etc. This allows it to 
27 // be used to create a default material that can be used to display a default diffuse texture. All texture names 
28 // are left empty. 
29 tMaterial() { Clear(); } 
30 tMaterial(const tMaterial& src) { *this = src; } 
31 
32 tMaterial(const tChunk& chunk) { Load(chunk); } 
33 virtual ~tMaterial() { } 
34 
35 void Clear(); 
36 void Load(const tChunk&); 
37 void Save(tChunkWriter&) const
38 float GetOpacity() const { return 1.0f - float(Transparency.R + Transparency.G + Transparency.B) / 765.0f; } // 765 = 255 * 3. 
39 
40 // Checks if 2 materials are visually identical. If a shader file (shd) is specified then it is checked and the 
41 // other quantities are not since shd files override all other material parameters. The ID/Name is not checked as 
42 // it has no effect visually. The attributes must match (but the order doesn't matter). 
43 bool IsFunctionallySame(const tMaterial&) const
44 
45 // These check everything including Name and ID. 
46 bool operator==(const tMaterial& mat) const { return IsFunctionallySame(mat) && (tObject::operator== (mat)); } 
47 bool operator!=(const tMaterial& mat) const { return !(*this == mat); } 
48 tMaterial& operator=(const tMaterial& src); 
49 
50 tColouri AmbientColour
51 tColouri DiffuseColour
52 tColouri SpecularColour
53 
54 float Shininess; // In [0.0, 1.0] 
55 float Reflectivity
56 float Diffusion; // In [0.0, 1.0] 
57 
58 tColouri ReflectedColour
59 tColouri Transparency
60 tColouri Incandescence
61 bool UseDiffuseColour; // Whether to use the diffuse colour, or the diffusion variable. If the exporter supports it, this is better if it's true. 
62 
63 tString TextureDiffuse
64 tString TextureNormalMap
65 
66 // Additional diffuse textures for multi-texturing or swapping. 
67 tString TextureA
68 tString TextureB
69 tString TextureC
70 tString TextureD
71 tString TextureE
72 
73 tString ShaderFile
74}; 
75 
76 
77
78