Dealing with custom shaders and making them generic is not an easy task. There are many things to consider for a shader because, after all, the shader is responsible for processing all the data sent to the GPU (mesh, materials, textures, lighting) to generate the final frame.
Dealing with custom shaders and making them generic is not an easy task. There are many things to consider for a shader because, after all, shaders are responsible for processing all the data sent to the GPU (mesh, materials, textures, lighting) to generate the final frame.
Finding a unified generic shader to deal with all kinds of stuff is very complicated and, after analyzing some of the big engines out there, I decided to go for a custom uber-shader-based solution.
Finding a unified generic shader to deal with all kinds of stuff is very complicated so, after analyzing some of the big engines out there, I decided to go for a custom uber-shader-based solution.
By default, raylib's shader struct is defined as:
By default, raylib's shader struct is defined as:
```c
```c
typedef struct Shader {
typedef struct Shader {
unsigned int id; // Shader program id
int locs[MAX_SHADER_LOCATIONS]; // Shader locations array
unsigned int id; // Shader program id
int *locs; // Shader locations array (MAX_SHADER_LOCATIONS)
} Shader;
} Shader;
```
```
This struct provides an array to store shader locations, those locations can be accessed by position using predefined values for convenience:
This struct provides an array to store shader locations, those locations can be accessed by position using predefined enum values for convenience:
```c
```c
// Shader location point type
// Shader location point type
typedef enum {
typedef enum {
@ -45,7 +45,7 @@ typedef enum {
#define LOC_MAP_SPECULAR LOC_MAP_METALNESS
#define LOC_MAP_SPECULAR LOC_MAP_METALNESS
```
```
On shader loading, the following location names are checked:
On shader loading, the following GLSL location names are checked: