Working on materials system...
This commit is contained in:
parent
cc39b4660a
commit
0e6d1cb272
2 changed files with 14 additions and 21 deletions
21
src/raylib.h
21
src/raylib.h
|
@ -355,7 +355,7 @@ typedef struct Camera {
|
||||||
// Camera2D type, defines a 2d camera
|
// Camera2D type, defines a 2d camera
|
||||||
typedef struct Camera2D {
|
typedef struct Camera2D {
|
||||||
Vector2 offset; // Camera offset (displacement from target)
|
Vector2 offset; // Camera offset (displacement from target)
|
||||||
Vector2 target; // Camera target (for rotation and zoom)
|
Vector2 target; // Camera target (rotation and zoom origin)
|
||||||
float rotation; // Camera rotation in degrees
|
float rotation; // Camera rotation in degrees
|
||||||
float zoom; // Camera zoom (scaling), should be 1.0f by default
|
float zoom; // Camera zoom (scaling), should be 1.0f by default
|
||||||
} Camera2D;
|
} Camera2D;
|
||||||
|
@ -386,16 +386,17 @@ typedef struct Mesh {
|
||||||
typedef struct Shader {
|
typedef struct Shader {
|
||||||
unsigned int id; // Shader program id
|
unsigned int id; // Shader program id
|
||||||
|
|
||||||
// Variable attributes
|
// Variable attributes locations
|
||||||
int vertexLoc; // Vertex attribute location point (vertex shader)
|
int vertexLoc; // Vertex attribute location point (vertex shader)
|
||||||
int texcoordLoc; // Texcoord attribute location point (vertex shader)
|
int texcoordLoc; // Texcoord attribute location point (vertex shader)
|
||||||
int normalLoc; // Normal attribute location point (vertex shader)
|
int normalLoc; // Normal attribute location point (vertex shader)
|
||||||
int colorLoc; // Color attibute location point (vertex shader)
|
int colorLoc; // Color attibute location point (vertex shader)
|
||||||
|
|
||||||
// Uniforms
|
// Uniform locations
|
||||||
int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader)
|
int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader)
|
||||||
int tintColorLoc; // Color uniform location point (fragment shader)
|
int tintColorLoc; // Color uniform location point (fragment shader)
|
||||||
|
|
||||||
|
// Texture map locations
|
||||||
int mapDiffuseLoc; // Diffuse map texture uniform location point (fragment shader)
|
int mapDiffuseLoc; // Diffuse map texture uniform location point (fragment shader)
|
||||||
int mapNormalLoc; // Normal map texture uniform location point (fragment shader)
|
int mapNormalLoc; // Normal map texture uniform location point (fragment shader)
|
||||||
int mapSpecularLoc; // Specular map texture uniform location point (fragment shader)
|
int mapSpecularLoc; // Specular map texture uniform location point (fragment shader)
|
||||||
|
@ -832,18 +833,14 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
|
||||||
Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations
|
Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations
|
||||||
unsigned int LoadShaderProgram(char *vShaderStr, char *fShaderStr); // Load custom shaders strings and return program id
|
unsigned int LoadShaderProgram(char *vShaderStr, char *fShaderStr); // Load custom shaders strings and return program id
|
||||||
void UnloadShader(Shader shader); // Unload a custom shader from memory
|
void UnloadShader(Shader shader); // Unload a custom shader from memory
|
||||||
void SetCustomShader(Shader shader); // Set custom shader to be used in batch draw
|
|
||||||
void SetDefaultShader(void); // Set default shader to be used in batch draw
|
void SetDefaultShader(void); // Set default shader to be used in batch draw
|
||||||
|
void SetCustomShader(Shader shader); // Set custom shader to be used in batch draw
|
||||||
void SetModelShader(Model *model, Shader shader); // Link a shader to a model
|
void SetModelShader(Model *model, Shader shader); // Link a shader to a model
|
||||||
|
|
||||||
int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location
|
int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location
|
||||||
void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float)
|
void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float)
|
||||||
void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int)
|
void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int)
|
||||||
void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4)
|
void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4)
|
||||||
//void SetShaderMapDiffuse(Shader *shader, Texture2D texture); // Default diffuse shader map texture assignment
|
|
||||||
//void SetShaderMapNormal(Shader *shader, const char *uniformName, Texture2D texture); // Normal map texture shader assignment
|
|
||||||
//void SetShaderMapSpecular(Shader *shader, const char *uniformName, Texture2D texture); // Specular map texture shader assignment
|
|
||||||
//void SetShaderMap(Shader *shader, int mapLocation, Texture2D texture, int textureUnit); // TODO: Generic shader map assignment
|
|
||||||
|
|
||||||
void SetBlendMode(int mode); // Set blending mode (alpha, additive, multiplied)
|
void SetBlendMode(int mode); // Set blending mode (alpha, additive, multiplied)
|
||||||
|
|
||||||
|
|
14
src/rlgl.c
14
src/rlgl.c
|
@ -1350,14 +1350,14 @@ void rlglDrawModel(Model model, Vector3 position, Vector3 rotationAxis, float ro
|
||||||
glBindTexture(GL_TEXTURE_2D, model.material.texDiffuse.id);
|
glBindTexture(GL_TEXTURE_2D, model.material.texDiffuse.id);
|
||||||
glUniform1i(model.material.shader.mapDiffuseLoc, 0); // Texture fits in active texture unit 0
|
glUniform1i(model.material.shader.mapDiffuseLoc, 0); // Texture fits in active texture unit 0
|
||||||
|
|
||||||
if (model.material.texNormal.id != 0)
|
if ((model.material.texNormal.id != 0) && (model.material.shader.mapNormalLoc != -1))
|
||||||
{
|
{
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
glBindTexture(GL_TEXTURE_2D, model.material.texNormal.id);
|
glBindTexture(GL_TEXTURE_2D, model.material.texNormal.id);
|
||||||
glUniform1i(model.material.shader.mapNormalLoc, 1); // Texture fits in active texture unit 1
|
glUniform1i(model.material.shader.mapNormalLoc, 1); // Texture fits in active texture unit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model.material.texSpecular.id != 0)
|
if ((model.material.texSpecular.id != 0) && (model.material.shader.mapSpecularLoc != -1))
|
||||||
{
|
{
|
||||||
glActiveTexture(GL_TEXTURE2);
|
glActiveTexture(GL_TEXTURE2);
|
||||||
glBindTexture(GL_TEXTURE_2D, model.material.texSpecular.id);
|
glBindTexture(GL_TEXTURE_2D, model.material.texSpecular.id);
|
||||||
|
@ -2125,17 +2125,13 @@ Shader LoadShader(char *vsFileName, char *fsFileName)
|
||||||
|
|
||||||
// After shader loading, we try to load default location names
|
// After shader loading, we try to load default location names
|
||||||
if (shader.id != 0) LoadDefaultShaderLocations(&shader);
|
if (shader.id != 0) LoadDefaultShaderLocations(&shader);
|
||||||
else
|
|
||||||
{
|
|
||||||
TraceLog(WARNING, "Custom shader could not be loaded");
|
|
||||||
shader = defaultShader;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shader strings must be freed
|
// Shader strings must be freed
|
||||||
free(vShaderStr);
|
free(vShaderStr);
|
||||||
free(fShaderStr);
|
free(fShaderStr);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (shader.id == 0)
|
||||||
{
|
{
|
||||||
TraceLog(WARNING, "Custom shader could not be loaded");
|
TraceLog(WARNING, "Custom shader could not be loaded");
|
||||||
shader = defaultShader;
|
shader = defaultShader;
|
||||||
|
@ -2494,7 +2490,7 @@ static Shader LoadDefaultShader(void)
|
||||||
if (shader.id != 0) TraceLog(INFO, "[SHDR ID %i] Default shader loaded successfully", shader.id);
|
if (shader.id != 0) TraceLog(INFO, "[SHDR ID %i] Default shader loaded successfully", shader.id);
|
||||||
else TraceLog(WARNING, "[SHDR ID %i] Default shader could not be loaded", shader.id);
|
else TraceLog(WARNING, "[SHDR ID %i] Default shader could not be loaded", shader.id);
|
||||||
|
|
||||||
LoadDefaultShaderLocations(&shader);
|
if (shader.id != 0) LoadDefaultShaderLocations(&shader);
|
||||||
|
|
||||||
return shader;
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue