Simplified shader matrix uniforms
This commit is contained in:
parent
d0ff78e7f4
commit
99f99bea47
2 changed files with 35 additions and 32 deletions
42
src/raylib.h
42
src/raylib.h
|
@ -358,12 +358,31 @@ typedef struct Shader {
|
||||||
int mapSpecularLoc; // Specular map texture uniform location point (fragment shader)
|
int mapSpecularLoc; // Specular map texture uniform location point (fragment shader)
|
||||||
} Shader;
|
} Shader;
|
||||||
|
|
||||||
|
// Material type
|
||||||
|
// TODO: Redesign material-shaders-textures system
|
||||||
|
typedef struct Material {
|
||||||
|
//Shader shader;
|
||||||
|
|
||||||
|
//Texture2D texDiffuse; // Diffuse texture
|
||||||
|
//Texture2D texNormal; // Normal texture
|
||||||
|
//Texture2D texSpecular; // Specular texture
|
||||||
|
|
||||||
|
Color colDiffuse;
|
||||||
|
Color colAmbient;
|
||||||
|
Color colSpecular;
|
||||||
|
|
||||||
|
float glossiness;
|
||||||
|
float normalDepth;
|
||||||
|
} Material;
|
||||||
|
|
||||||
// 3d Model type
|
// 3d Model type
|
||||||
|
// TODO: Replace shader/testure by material
|
||||||
typedef struct Model {
|
typedef struct Model {
|
||||||
Mesh mesh;
|
Mesh mesh;
|
||||||
Matrix transform;
|
Matrix transform;
|
||||||
Texture2D texture; // Only for OpenGL 1.1, on newer versions this should be in the shader
|
Texture2D texture; // Only for OpenGL 1.1, on newer versions this should be in the shader
|
||||||
Shader shader;
|
Shader shader;
|
||||||
|
//Material material;
|
||||||
} Model;
|
} Model;
|
||||||
|
|
||||||
// Ray type (useful for raycast)
|
// Ray type (useful for raycast)
|
||||||
|
@ -387,26 +406,6 @@ typedef struct Wave {
|
||||||
short channels;
|
short channels;
|
||||||
} Wave;
|
} Wave;
|
||||||
|
|
||||||
// Light type
|
|
||||||
typedef struct Light {
|
|
||||||
Vector3 position;
|
|
||||||
Vector3 direction;
|
|
||||||
float intensity;
|
|
||||||
float specIntensity;
|
|
||||||
Color diffuse;
|
|
||||||
Color ambient;
|
|
||||||
Color specular;
|
|
||||||
} Light;
|
|
||||||
|
|
||||||
// Material type
|
|
||||||
typedef struct Material {
|
|
||||||
Color diffuse;
|
|
||||||
Color ambient;
|
|
||||||
Color specular;
|
|
||||||
float glossiness;
|
|
||||||
float normalDepth;
|
|
||||||
} Material;
|
|
||||||
|
|
||||||
// Texture formats
|
// Texture formats
|
||||||
// NOTE: Support depends on OpenGL version and platform
|
// NOTE: Support depends on OpenGL version and platform
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -535,11 +534,12 @@ void BeginDrawing(void); // Setup drawing can
|
||||||
void BeginDrawingEx(int blendMode, Shader shader, Matrix transform); // Setup drawing canvas with extended parameters
|
void BeginDrawingEx(int blendMode, Shader shader, Matrix transform); // Setup drawing canvas with extended parameters
|
||||||
void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering)
|
void EndDrawing(void); // End canvas drawing and Swap Buffers (Double Buffering)
|
||||||
|
|
||||||
void Begin3dMode(Camera cam); // Initializes 3D mode for drawing (Camera setup)
|
void Begin3dMode(Camera camera); // Initializes 3D mode for drawing (Camera setup)
|
||||||
void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode
|
void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode
|
||||||
|
|
||||||
Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position
|
Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position
|
||||||
Vector2 WorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position
|
Vector2 WorldToScreen(Vector3 position, Camera camera); // Returns the screen space position from a 3d world space position
|
||||||
|
Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix)
|
||||||
|
|
||||||
void SetTargetFPS(int fps); // Set target FPS (maximum)
|
void SetTargetFPS(int fps); // Set target FPS (maximum)
|
||||||
float GetFPS(void); // Returns current FPS
|
float GetFPS(void); // Returns current FPS
|
||||||
|
|
25
src/rlgl.c
25
src/rlgl.c
|
@ -1477,8 +1477,8 @@ void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 r
|
||||||
|
|
||||||
// NOTE: Drawing in OpenGL 3.3+, matrices are passed to shader
|
// NOTE: Drawing in OpenGL 3.3+, matrices are passed to shader
|
||||||
// TODO: Reduce number of matrices passed to shaders, use only matMVP
|
// TODO: Reduce number of matrices passed to shaders, use only matMVP
|
||||||
glUniformMatrix4fv(model.shader.modelLoc, 1, false, MatrixToFloat(matModel));
|
//glUniformMatrix4fv(model.material.shader.modelLoc, 1, false, MatrixToFloat(matModel));
|
||||||
glUniformMatrix4fv(model.shader.viewLoc, 1, false, MatrixToFloat(matView));
|
//glUniformMatrix4fv(model.material.shader.viewLoc, 1, false, MatrixToFloat(matView));
|
||||||
|
|
||||||
glUniformMatrix4fv(model.shader.mvpLoc, 1, false, MatrixToFloat(matMVP));
|
glUniformMatrix4fv(model.shader.mvpLoc, 1, false, MatrixToFloat(matMVP));
|
||||||
|
|
||||||
|
@ -2201,9 +2201,6 @@ Shader LoadShader(char *vsFileName, char *fsFileName)
|
||||||
|
|
||||||
// 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");
|
||||||
|
|
||||||
shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix");
|
|
||||||
shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix");
|
|
||||||
|
|
||||||
// Get handles to GLSL uniform locations (fragment shader)
|
// Get handles to GLSL uniform locations (fragment shader)
|
||||||
shader.tintColorLoc = glGetUniformLocation(shader.id, "fragTintColor");
|
shader.tintColorLoc = glGetUniformLocation(shader.id, "fragTintColor");
|
||||||
|
@ -2503,6 +2500,18 @@ void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set shader uniform value (matrix 4x4)
|
||||||
|
void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat)
|
||||||
|
{
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
|
glUseProgram(shader.id);
|
||||||
|
|
||||||
|
glUniformMatrix4fv(uniformLoc, 1, false, MatrixToFloat(mat));
|
||||||
|
|
||||||
|
glUseProgram(0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Default diffuse shader map texture assignment
|
// Default diffuse shader map texture assignment
|
||||||
void SetShaderMapDiffuse(Shader *shader, Texture2D texture)
|
void SetShaderMapDiffuse(Shader *shader, Texture2D texture)
|
||||||
{
|
{
|
||||||
|
@ -2741,9 +2750,6 @@ static Shader LoadDefaultShader(void)
|
||||||
|
|
||||||
// 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");
|
||||||
|
|
||||||
shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix");
|
|
||||||
shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix");
|
|
||||||
|
|
||||||
// Get handles to GLSL uniform locations (fragment shader)
|
// Get handles to GLSL uniform locations (fragment shader)
|
||||||
shader.tintColorLoc = -1;
|
shader.tintColorLoc = -1;
|
||||||
|
@ -2822,9 +2828,6 @@ static Shader LoadSimpleShader(void)
|
||||||
|
|
||||||
// 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");
|
||||||
|
|
||||||
shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix");
|
|
||||||
shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix");
|
|
||||||
|
|
||||||
// Get handles to GLSL uniform locations (fragment shader)
|
// Get handles to GLSL uniform locations (fragment shader)
|
||||||
shader.tintColorLoc = glGetUniformLocation(shader.id, "fragTintColor");
|
shader.tintColorLoc = glGetUniformLocation(shader.id, "fragTintColor");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue