|
AGL
0
3D graphics library
|
Material class for entities. More...

Public Member Functions | |
| Material () | |
| Creates a material. More... | |
| ~Material () | |
| Material | operator+ (const Material &other) const |
| Mix two material. More... | |
| Material & | operator+= (const Material &other) |
| Same as operator+ but modifies the current material. More... | |
| Material | operator* (const Material &other) const |
| Mix two material. More... | |
| Material & | operator*= (const Material &other) |
| Same as operator* but modifies the current material. More... | |
| void | setColor (glm::vec4 color=glm::vec4(1)) |
| Set color for all the components. More... | |
| void | setColor (float r=1, float g=1, float b=1, float a=1) |
| Same as setColor. More... | |
| void | setColor (const Material &other) |
| Sets each color components from another Material. More... | |
| void | createTexture (const char *path=nullptr) |
| Creates a texture. More... | |
| virtual std::pair< std::string, std::string > | createShader (Entity *e=nullptr, std::vector< Light *> lights=std::vector< Light *>()) |
| Create a shader algorithmically. More... | |
| virtual void | setShader (std::string vertexShader, std::string fragmentShader) |
| Compile and set the shader for the material. More... | |
Public Attributes | |
| glm::vec4 | emission |
| Emission, self color of the material. More... | |
| glm::vec4 | ambient |
| Ambient, color due to ambient light. More... | |
| glm::vec4 | diffuse |
| Diffuse, color when light hits a surface. More... | |
| glm::vec4 | specular |
| Specular, color due to the reflection of light. More... | |
| glm::vec4 | ratios |
| float | shininess = 32 |
| Shininess, amount of light reflected by the material. More... | |
| bool | lightsEnabled = false |
| If true, no lighting calculations are done. More... | |
| bool | customShader = false |
| If true, Scene::prepare do not create shaders. More... | |
| int | shadingType = AGL_SHADING_PHONG |
| Type of shading, currently unused. More... | |
| int | tex_width = -1 |
| Width of texture,if used. More... | |
| int | tex_height = -1 |
| Height of texture, if used. More... | |
| int | tex_channel = -1 |
| Number of channels in texture, if used. More... | |
| GLubyte * | texture = nullptr |
| Pointer to texture data, if present. More... | |
| GLuint | progID = 0 |
| program ID More... | |
| GLuint | tID = 0 |
| texture ID More... | |
| GLuint | mvpID |
| MVP matrix ID. More... | |
| GLuint | mID |
| model matrix ID More... | |
| GLuint | nID |
| normal matrix ID More... | |
| GLuint | eID |
| emission color ID More... | |
| GLuint | aID |
| ambient color ID More... | |
| GLuint | dID |
| diffuse color ID More... | |
| GLuint | sID |
| specular color ID More... | |
| GLuint | gID |
| shininess color ID More... | |
| GLuint | vID |
| camera position ID More... | |
Static Public Attributes | |
| static const Material | emerald = Material(0.0215, 0.1745, 0.0215, 0.07568, 0.61424, 0.07568, 0.633, 0.727811, 0.633, 76.8) |
| static const Material | jade = Material(0.135, 0.2225, 0.1575, 0.54, 0.89, 0.63, 0.316228, 0.316228, 0.316228, 12.8) |
| static const Material | obsidian = Material(0.05375, 0.05, 0.06625, 0.18275, 0.17, 0.22525, 0.332741, 0.328634, 0.346435, 38.4) |
| static const Material | pearl = Material(0.25, 0.20725, 0.20725, 1, 0.829, 0.829, 0.296648, 0.296648, 0.296648, 11.264) |
| static const Material | ruby = Material(0.1745, 0.01175, 0.01175, 0.61424, 0.04136, 0.04136, 0.727811, 0.626959, 0.626959, 76.8) |
| static const Material | turquoise = Material(0.1, 0.18725, 0.1745, 0.396, 0.74151, 0.69102, 0.297254, 0.30829, 0.306678, 12.8) |
| static const Material | brass = Material(0.329412, 0.223529, 0.027451, 0.780392, 0.568627, 0.113725, 0.992157, 0.941176, 0.807843, 27.89743616) |
| static const Material | bronze = Material(0.2125, 0.1275, 0.054, 0.714, 0.4284, 0.18144, 0.393548, 0.271906, 0.166721, 25.6) |
| static const Material | chrome = Material(0.25, 0.25, 0.25, 0.4, 0.4, 0.4, 0.774597, 0.774597, 0.774597, 76.8) |
| static const Material | copper = Material(0.19125, 0.0735, 0.0225, 0.7038, 0.27048, 0.0828, 0.256777, 0.137622, 0.086014, 12.8) |
| static const Material | gold = Material(0.24725, 0.1995, 0.0745, 0.75164, 0.60648, 0.22648, 0.628281, 0.555802, 0.366065, 51.2) |
| static const Material | silver = Material(0.19225, 0.19225, 0.19225, 0.50754, 0.50754, 0.50754, 0.508273, 0.508273, 0.508273, 51.2) |
| static const Material | black_plastic = Material(0, 0, 0, 0.01, 0.01, 0.01, 0.50, 0.50, 0.50, 32) |
| static const Material | cyan_plastic = Material(0, 0.1, 0.06, 0, 0.50980392, 0.50980392, 0.50196078, 0.50196078, 0.50196078, 32) |
| static const Material | green_plastic = Material(0, 0, 0, 0.1, 0.35, 0.1, 0.45, 0.55, 0.45, 32) |
| static const Material | red_plastic = Material(0, 0, 0, 0.5, 0, 0, 0.7, 0.6, 0.6, 32) |
| static const Material | white_plastic = Material(0, 0, 0, 0.55, 0.55, 0.55, 0.70, 0.70, 0.70, 32) |
| static const Material | yellow_plastic = Material(0, 0, 0, 0.5, 0.5, 0, 0.60, 0.60, 0.50, 32) |
| static const Material | black_rubber = Material(0.02, 0.02, 0.02, 0.01, 0.01, 0.01, 0.4, 0.4, 0.4, 10) |
| static const Material | cyan_rubber = Material(0, 0.05, 0.05, 0.4, 0.5, 0.5, 0.04, 0.7, 0.7, 10) |
| static const Material | green_rubber = Material(0, 0.05, 0, 0.4, 0.5, 0.4, 0.04, 0.7, 0.04, 10) |
| static const Material | red_rubber = Material(0.05, 0, 0, 0.5, 0.4, 0.4, 0.7, 0.04, 0.04, 10) |
| static const Material | white_rubber = Material(0.05, 0.05, 0.05, 0.5, 0.5, 0.5, 0.7, 0.7, 0.7, 10) |
| static const Material | yellow_rubber = Material(0.05, 0.05, 0, 0.5, 0.5, 0.4, 0.7, 0.7, 0.04, 10) |
Material class for entities.
This class defines the kind of material used by the shader to render the Entity. It defines several different components (emission, ambient, diffuse and specular) for the materials or a single texture. Each of the components can be a valid color or a special color.
AGL supports several special colors for the materials. This allows for procedurally generated textures for the rendering. These colors are defined with a negative alpha value for the components. Each of these color can take several parameters, defined by values in the rgb part of the colors. These colors are hard-coded in the generated shaders, ie. they can't be animated without recreating the shaders. Available special colors are:
This is enabled by AGL_COLOR_POS2RGB. The position of the fragment is mapped to a color for the same. All the fragments are scaled between 0 to 1 and the value is used as RGB. The R, G, and B part of the color must be -1 for the corresponding coordinates (x, y, and z) to contribute to the final color. If not -1, the value is used as-is in the final color.
This is enabled by AGL_COLOR_NORM2RGB. The normal of the fragment is mapped to a color for the same. This mode requires that the normal is included with the buffers. The x, y, and z components of the normal is directly used for the R, G, and B components of the color.
This is enabled by AGL_COLOR_CHECKER. The position of the fragment is used to generate either black or white color to give a checkerboard pattern finally. The R, G, or B component must be set to -1 to use the same for the color calculation. If set to anything else, they're ignored. The equation used is \(\left(\sum_{i\text{th component of color is -1}} \left\lfloor\text{normal}_i\right\rfloor\right) \mod 2\).
| Material | ( | ) |
Creates a material.
| ~Material | ( | ) |
|
virtual |
Create a shader algorithmically.
| e | Entity, needed for which to create the position based coloring. |
| lights | All the lights in the scene. |
| void createTexture | ( | const char * | path = nullptr | ) |
Creates a texture.
| path | Path to the texture. |
If no path is provided, assumes that the texture is already loaded, else loads the texture, and loads and creates the ID.
delete or stbi_image_free to avoid memory leak. This might change in future. Mix two material.
| other | The material to mix with. |
This mixes two materials by multiplying the colors. The shininess is geometrically meaned.
Same as operator* but modifies the current material.
Mix two material.
| other | The material to mix with. |
This mixes two materials by averaging the colors. The shininess is geometrically meaned.
Same as operator+ but modifies the current material.
| void setColor | ( | glm::vec4 | color = glm::vec4(1) | ) |
Set color for all the components.
| color | Color for all the components. |
| void setColor | ( | float | r = 1, |
| float | g = 1, |
||
| float | b = 1, |
||
| float | a = 1 |
||
| ) |
Same as setColor.
| r | Red. |
| g | Green. |
| b | Blue. |
| a | Alpha. |
| void setColor | ( | const Material & | other | ) |
|
virtual |
Compile and set the shader for the material.
| vertexShader | Vertex shader. |
| fragmentShader | Fragment shader. |
This can load shaders that were created by createShader or those loaded manually. This will also set all the required IDs automatically.
| GLuint aID |
ambient color ID
| glm::vec4 ambient |
Ambient, color due to ambient light.
| bool customShader = false |
If true, Scene::prepare do not create shaders.
| GLuint dID |
diffuse color ID
| glm::vec4 diffuse |
Diffuse, color when light hits a surface.
| GLuint eID |
emission color ID
| glm::vec4 emission |
Emission, self color of the material.
| GLuint gID |
shininess color ID
| bool lightsEnabled = false |
If true, no lighting calculations are done.
| GLuint mID |
model matrix ID
| GLuint mvpID |
MVP matrix ID.
| GLuint nID |
normal matrix ID
| GLuint progID = 0 |
program ID
| glm::vec4 ratios |
| int shadingType = AGL_SHADING_PHONG |
Type of shading, currently unused.
| float shininess = 32 |
Shininess, amount of light reflected by the material.
| GLuint sID |
specular color ID
| glm::vec4 specular |
Specular, color due to the reflection of light.
| int tex_channel = -1 |
Number of channels in texture, if used.
| int tex_height = -1 |
Height of texture, if used.
| int tex_width = -1 |
Width of texture,if used.
| GLubyte* texture = nullptr |
Pointer to texture data, if present.
| GLuint tID = 0 |
texture ID
| GLuint vID |
camera position ID