00001
00005 #ifndef _MATERIAL_H_
00006 #define _MATERIAL_H_
00007
00008 #include "texture.h"
00009
00011 #define BUFFER 512
00012
00014 const TVector white(1.0f,1.0f,1.0f);
00016 const TVector black(0.0f,0.0f,0.0f);
00018 const TVector dgrey(0.1f,0.1f,0.1f);
00020 const TVector grey(0.3f,0.3f,0.3f);
00022 const TVector lgrey(0.5f,0.5f,0.5f);
00024 const TVector silver(0.7f,0.7f,0.7f);
00026 const TVector red(1.0f,0.0f,0.0f);
00028 const TVector green(0.0f,1.0f,0.0f);
00030 const TVector blue(0.0f,0.0f,1.0f);
00032 const TVector yellow(1.0f,1.0f,0.0f);
00034 const TVector magenta(1.0f,0.0f,1.0f);
00036 const TVector cyan(0.0f,1.0f,1.0f);
00037
00038
00041 class TMaterial
00042 {
00043 private:
00044
00045 string name;
00046 map<string,Texture> textures;
00047 map<string,Texture>::iterator it;
00048
00049 TVector ambColor, diffColor, specColor;
00050 float shininess, transparency, reflection;
00051
00052
00053 string source;
00054 GLuint f_shader, g_shader, v_shader, shader, gshader_ref;
00055
00056
00057 bool baked, custom_shader, receive_shadows, use_gshader_ref, useMRT;
00058 int lightModel;
00059
00060 public:
00061
00062 TMaterial()
00063 { TMaterial("basic",black,silver,white,64.0,0.0,0.0,NONE); }
00064
00065 TMaterial(const char* _name, TVector amb, TVector diff, TVector spec, GLfloat shin, GLfloat reflect, GLfloat transp, GLint lm);
00066
00067 ~TMaterial();
00068
00070 string GetName()
00071 { return name; }
00073 GLfloat GetTrasparency()
00074 { return transparency; }
00075
00076
00077
00078 GLint AddTexture(const char *file, GLint textype, GLint texmode,
00079 GLfloat intensity, GLfloat tileX, GLfloat tileY, bool mipmap, bool aniso, GLint cache);
00080
00081 GLint AddTexture(const char **files, GLint textype, GLint texmode,
00082 GLfloat intensity, GLfloat tileX, GLfloat tileY, bool aniso, GLint cache);
00083
00084 string NextTexture(string textype);
00089 void DeleteTexture(string texname)
00090 { textures.erase(texname); }
00091
00092
00093
00094 void AddShadowMap(GLuint map, GLfloat intensity);
00095
00096 void SetShadowMatrix(TMatrix &m, GLint l_num);
00097
00098
00099
00100 bool CustomShader(const char* vert_source, const char* geom_source, const char* frag_source,
00101 const char *vert_defines, const char *frag_defines, const char *geom_defines);
00102
00103 void SetUniform(const char* v_name, float value);
00104 void SetUniform(const char* v_name, double value);
00105 void SetUniform(const char* v_name, int value);
00106
00107 void SetUniforms(const char* v_name, float *value, int values);
00109 void UseGShaderCubeMapRender(bool flag)
00110 { use_gshader_ref = flag; }
00112 void UseMRT(bool flag)
00113 { useMRT = flag; }
00114
00115
00116 bool BakeMaterial(bool use_geom = false);
00117
00118 void RenderMaterial(bool render_all = true);
00120 void SetLights(int lights)
00121 { SetUniform("LIGHTS",lights); }
00122
00124 void ReceiveShadow(bool flag)
00125 { receive_shadows = flag; }
00126
00128 float GetReflect()
00129 { return reflection; }
00130 };
00131
00132 #endif