mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-08 12:28:15 +00:00
Renamed shader variables (more generic names)
Now shader maps use a generic naming convention for any kind of texture maps (not only diffuse, normal or specular). Useful for custom shaders.
This commit is contained in:
26
src/rlgl.c
26
src/rlgl.c
@@ -1792,23 +1792,23 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
|
|||||||
// Set shader textures (diffuse, normal, specular)
|
// Set shader textures (diffuse, normal, specular)
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, material.texDiffuse.id);
|
glBindTexture(GL_TEXTURE_2D, material.texDiffuse.id);
|
||||||
glUniform1i(material.shader.mapDiffuseLoc, 0); // Texture fits in active texture unit 0
|
glUniform1i(material.shader.mapTexture0Loc, 0); // Diffuse texture fits in active texture unit 0
|
||||||
|
|
||||||
if ((material.texNormal.id != 0) && (material.shader.mapNormalLoc != -1))
|
if ((material.texNormal.id != 0) && (material.shader.mapTexture1Loc != -1))
|
||||||
{
|
{
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
glBindTexture(GL_TEXTURE_2D, material.texNormal.id);
|
glBindTexture(GL_TEXTURE_2D, material.texNormal.id);
|
||||||
glUniform1i(material.shader.mapNormalLoc, 1); // Texture fits in active texture unit 1
|
glUniform1i(material.shader.mapTexture1Loc, 1); // Normal texture fits in active texture unit 1
|
||||||
|
|
||||||
// TODO: Upload to shader normalDepth
|
// TODO: Upload to shader normalDepth
|
||||||
//glUniform1f(???, material.normalDepth);
|
//glUniform1f(???, material.normalDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((material.texSpecular.id != 0) && (material.shader.mapSpecularLoc != -1))
|
if ((material.texSpecular.id != 0) && (material.shader.mapTexture2Loc != -1))
|
||||||
{
|
{
|
||||||
glActiveTexture(GL_TEXTURE2);
|
glActiveTexture(GL_TEXTURE2);
|
||||||
glBindTexture(GL_TEXTURE_2D, material.texSpecular.id);
|
glBindTexture(GL_TEXTURE_2D, material.texSpecular.id);
|
||||||
glUniform1i(material.shader.mapSpecularLoc, 2); // Texture fits in active texture unit 2
|
glUniform1i(material.shader.mapTexture2Loc, 2); // Specular texture fits in active texture unit 2
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vaoSupported)
|
if (vaoSupported)
|
||||||
@@ -2569,19 +2569,19 @@ static void LoadDefaultShaderLocations(Shader *shader)
|
|||||||
// Get handles to GLSL input attibute locations
|
// Get handles to GLSL input attibute locations
|
||||||
shader->vertexLoc = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_POSITION_NAME);
|
shader->vertexLoc = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_POSITION_NAME);
|
||||||
shader->texcoordLoc = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_TEXCOORD_NAME);
|
shader->texcoordLoc = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_TEXCOORD_NAME);
|
||||||
shader->normalLoc = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_NORMAL_NAME);
|
|
||||||
shader->colorLoc = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_COLOR_NAME);
|
|
||||||
shader->tangentLoc = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_TANGENT_NAME);
|
|
||||||
shader->texcoord2Loc = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_TEXCOORD2_NAME);
|
shader->texcoord2Loc = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_TEXCOORD2_NAME);
|
||||||
|
shader->normalLoc = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_NORMAL_NAME);
|
||||||
|
shader->tangentLoc = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_TANGENT_NAME);
|
||||||
|
shader->colorLoc = glGetAttribLocation(shader->id, DEFAULT_ATTRIB_COLOR_NAME);
|
||||||
|
|
||||||
// Get handles to GLSL uniform locations (vertex shader)
|
// Get handles to GLSL uniform locations (vertex shader)
|
||||||
shader->mvpLoc = glGetUniformLocation(shader->id, "mvpMatrix");
|
shader->mvpLoc = glGetUniformLocation(shader->id, "mvpMatrix");
|
||||||
|
|
||||||
// Get handles to GLSL uniform locations (fragment shader)
|
// Get handles to GLSL uniform locations (fragment shader)
|
||||||
shader->tintColorLoc = glGetUniformLocation(shader->id, "colDiffuse");
|
shader->tintColorLoc = glGetUniformLocation(shader->id, "colDiffuse");
|
||||||
shader->mapDiffuseLoc = glGetUniformLocation(shader->id, "texture0");
|
shader->mapTexture0Loc = glGetUniformLocation(shader->id, "texture0");
|
||||||
shader->mapNormalLoc = glGetUniformLocation(shader->id, "texture1");
|
shader->mapTexture1Loc = glGetUniformLocation(shader->id, "texture1");
|
||||||
shader->mapSpecularLoc = glGetUniformLocation(shader->id, "texture2");
|
shader->mapTexture2Loc = glGetUniformLocation(shader->id, "texture2");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unload default shader
|
// Unload default shader
|
||||||
@@ -2864,8 +2864,10 @@ static void DrawDefaultBuffers(void)
|
|||||||
Matrix matMVP = MatrixMultiply(modelview, projection);
|
Matrix matMVP = MatrixMultiply(modelview, projection);
|
||||||
|
|
||||||
glUniformMatrix4fv(currentShader.mvpLoc, 1, false, MatrixToFloat(matMVP));
|
glUniformMatrix4fv(currentShader.mvpLoc, 1, false, MatrixToFloat(matMVP));
|
||||||
glUniform1i(currentShader.mapDiffuseLoc, 0);
|
|
||||||
glUniform4f(currentShader.tintColorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
|
glUniform4f(currentShader.tintColorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
glUniform1i(currentShader.mapTexture0Loc, 0);
|
||||||
|
|
||||||
|
// NOTE: Additional map textures not considered for default buffers drawing
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw lines buffers
|
// Draw lines buffers
|
||||||
|
@@ -171,10 +171,10 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
|
|||||||
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
|
// Texture map locations (generic for any kind of map)
|
||||||
int mapDiffuseLoc; // Diffuse map texture uniform location point (fragment shader)
|
int mapTexture0Loc; // Map texture uniform location point (default-texture-unit = 0)
|
||||||
int mapNormalLoc; // Normal map texture uniform location point (fragment shader)
|
int mapTexture1Loc; // Map texture uniform location point (default-texture-unit = 1)
|
||||||
int mapSpecularLoc; // Specular map texture uniform location point (fragment shader)
|
int mapTexture2Loc; // Map texture uniform location point (default-texture-unit = 2)
|
||||||
} Shader;
|
} Shader;
|
||||||
|
|
||||||
// Texture2D type
|
// Texture2D type
|
||||||
|
Reference in New Issue
Block a user