WARNING: Redesigned SetShaderValue()
This commit is contained in:
parent
7c4a0f963d
commit
55f8dbc755
@ -64,7 +64,7 @@ int main()
|
||||
|
||||
// Send to material PBR shader camera view position
|
||||
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
|
||||
SetShaderValue(model.material.shader, model.material.shader.locs[LOC_VECTOR_VIEW], cameraPos, 3);
|
||||
SetShaderValue(model.material.shader, model.material.shader.locs[LOC_VECTOR_VIEW], cameraPos, UNIFORM_VEC3);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
@ -148,9 +148,9 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
||||
Shader shdrBRDF = LoadShader(PATH_BRDF_VS, PATH_BRDF_FS);
|
||||
|
||||
// Setup required shader locations
|
||||
SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, 1);
|
||||
SetShaderValuei(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1]){ 0 }, 1);
|
||||
SetShaderValuei(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1]){ 0 }, 1);
|
||||
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT);
|
||||
SetShaderValue(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1]){ 0 }, UNIFORM_INT);
|
||||
SetShaderValue(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1]){ 0 }, UNIFORM_INT);
|
||||
|
||||
Texture2D texHDR = LoadTexture("resources/dresden_square.hdr");
|
||||
Texture2D cubemap = GenTextureCubemap(shdrCubemap, texHDR, CUBEMAP_SIZE);
|
||||
@ -174,14 +174,14 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
||||
SetTextureFilter(mat.maps[MAP_OCCLUSION].texture, FILTER_BILINEAR);
|
||||
|
||||
// Enable sample usage in shader for assigned textures
|
||||
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), (int[1]){ 1 }, 1);
|
||||
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), (int[1]){ 1 }, 1);
|
||||
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "metalness.useSampler"), (int[1]){ 1 }, 1);
|
||||
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "roughness.useSampler"), (int[1]){ 1 }, 1);
|
||||
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "occlusion.useSampler"), (int[1]){ 1 }, 1);
|
||||
SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
|
||||
SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
|
||||
SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "metalness.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
|
||||
SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "roughness.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
|
||||
SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "occlusion.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
|
||||
|
||||
int renderModeLoc = GetShaderLocation(mat.shader, "renderMode");
|
||||
SetShaderValuei(mat.shader, renderModeLoc, (int[1]){ 0 }, 1);
|
||||
SetShaderValue(mat.shader, renderModeLoc, (int[1]){ 0 }, UNIFORM_INT);
|
||||
|
||||
// Set up material properties color
|
||||
mat.maps[MAP_ALBEDO].color = albedo;
|
||||
|
@ -30,11 +30,11 @@ int main()
|
||||
// Load skybox shader and set required locations
|
||||
// NOTE: Some locations are automatically set at shader loading
|
||||
skybox.material.shader = LoadShader("resources/shaders/skybox.vs", "resources/shaders/skybox.fs");
|
||||
SetShaderValuei(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, 1);
|
||||
SetShaderValue(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, UNIFORM_INT);
|
||||
|
||||
// Load cubemap shader and setup required shader locations
|
||||
Shader shdrCubemap = LoadShader("resources/shaders/cubemap.vs", "resources/shaders/cubemap.fs");
|
||||
SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, 1);
|
||||
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT);
|
||||
|
||||
// Load HDR panorama (sphere) texture
|
||||
Texture2D texHDR = LoadTexture("resources/dresden_square.hdr");
|
||||
|
@ -158,20 +158,20 @@ Light CreateLight(int type, Vector3 pos, Vector3 targ, Color color, Shader shade
|
||||
void UpdateLightValues(Shader shader, Light light)
|
||||
{
|
||||
// Send to shader light enabled state and type
|
||||
SetShaderValuei(shader, light.enabledLoc, (int[1]){ light.enabled }, 1);
|
||||
SetShaderValuei(shader, light.typeLoc, (int[1]){ light.type }, 1);
|
||||
SetShaderValue(shader, light.enabledLoc, &light.enabled, UNIFORM_INT);
|
||||
SetShaderValue(shader, light.typeLoc, &light.type, UNIFORM_INT);
|
||||
|
||||
// Send to shader light position values
|
||||
float position[3] = { light.position.x, light.position.y, light.position.z };
|
||||
SetShaderValue(shader, light.posLoc, position, 3);
|
||||
SetShaderValue(shader, light.posLoc, position, UNIFORM_VEC3);
|
||||
|
||||
// Send to shader light target position values
|
||||
float target[3] = { light.target.x, light.target.y, light.target.z };
|
||||
SetShaderValue(shader, light.targetLoc, target, 3);
|
||||
SetShaderValue(shader, light.targetLoc, target, UNIFORM_VEC3);
|
||||
|
||||
// Send to shader light color values
|
||||
float diff[4] = { (float)light.color.r/(float)255, (float)light.color.g/(float)255, (float)light.color.b/(float)255, (float)light.color.a/(float)255 };
|
||||
SetShaderValue(shader, light.colorLoc, diff, 4);
|
||||
SetShaderValue(shader, light.colorLoc, diff, UNIFORM_VEC4);
|
||||
}
|
||||
|
||||
#endif // RLIGHTS_IMPLEMENTATION
|
@ -350,9 +350,6 @@ static void GetShaderLightsLocations(Shader shader)
|
||||
|
||||
// Set shader uniform values for lights
|
||||
// NOTE: It would be far easier with shader UBOs but are not supported on OpenGL ES 2.0
|
||||
// TODO: Replace glUniform1i(), glUniform1f(), glUniform3f(), glUniform4f():
|
||||
//SetShaderValue(Shader shader, int uniformLoc, float *value, int size)
|
||||
//SetShaderValuei(Shader shader, int uniformLoc, int *value, int size)
|
||||
static void SetShaderLightsValues(Shader shader)
|
||||
{
|
||||
int tempInt[8] = { 0 };
|
||||
@ -363,20 +360,20 @@ static void SetShaderLightsValues(Shader shader)
|
||||
if (i < lightsCount)
|
||||
{
|
||||
tempInt[0] = lights[i]->enabled;
|
||||
SetShaderValuei(shader, lightsLocs[i][0], tempInt, 1); //glUniform1i(lightsLocs[i][0], lights[i]->enabled);
|
||||
SetShaderValue(shader, lightsLocs[i][0], tempInt, UNIFORM_INT); //glUniform1i(lightsLocs[i][0], lights[i]->enabled);
|
||||
|
||||
tempInt[0] = lights[i]->type;
|
||||
SetShaderValuei(shader, lightsLocs[i][1], tempInt, 1); //glUniform1i(lightsLocs[i][1], lights[i]->type);
|
||||
SetShaderValue(shader, lightsLocs[i][1], tempInt, UNIFORM_INT); //glUniform1i(lightsLocs[i][1], lights[i]->type);
|
||||
|
||||
tempFloat[0] = (float)lights[i]->diffuse.r/255.0f;
|
||||
tempFloat[1] = (float)lights[i]->diffuse.g/255.0f;
|
||||
tempFloat[2] = (float)lights[i]->diffuse.b/255.0f;
|
||||
tempFloat[3] = (float)lights[i]->diffuse.a/255.0f;
|
||||
SetShaderValue(shader, lightsLocs[i][5], tempFloat, 4);
|
||||
SetShaderValue(shader, lightsLocs[i][5], tempFloat, UNIFORM_VEC4);
|
||||
//glUniform4f(lightsLocs[i][5], (float)lights[i]->diffuse.r/255, (float)lights[i]->diffuse.g/255, (float)lights[i]->diffuse.b/255, (float)lights[i]->diffuse.a/255);
|
||||
|
||||
tempFloat[0] = lights[i]->intensity;
|
||||
SetShaderValue(shader, lightsLocs[i][6], tempFloat, 1);
|
||||
SetShaderValue(shader, lightsLocs[i][6], tempFloat, UNIFORM_FLOAT);
|
||||
|
||||
switch (lights[i]->type)
|
||||
{
|
||||
@ -385,10 +382,10 @@ static void SetShaderLightsValues(Shader shader)
|
||||
tempFloat[0] = lights[i]->position.x;
|
||||
tempFloat[1] = lights[i]->position.y;
|
||||
tempFloat[2] = lights[i]->position.z;
|
||||
SetShaderValue(shader, lightsLocs[i][2], tempFloat, 3);
|
||||
SetShaderValue(shader, lightsLocs[i][2], tempFloat, UNIFORM_VEC3);
|
||||
|
||||
tempFloat[0] = lights[i]->radius;
|
||||
SetShaderValue(shader, lightsLocs[i][4], tempFloat, 1);
|
||||
SetShaderValue(shader, lightsLocs[i][4], tempFloat, UNIFORM_FLOAT);
|
||||
|
||||
//glUniform3f(lightsLocs[i][2], lights[i]->position.x, lights[i]->position.y, lights[i]->position.z);
|
||||
//glUniform1f(lightsLocs[i][4], lights[i]->radius);
|
||||
@ -401,7 +398,7 @@ static void SetShaderLightsValues(Shader shader)
|
||||
tempFloat[0] = direction.x;
|
||||
tempFloat[1] = direction.y;
|
||||
tempFloat[2] = direction.z;
|
||||
SetShaderValue(shader, lightsLocs[i][3], tempFloat, 3);
|
||||
SetShaderValue(shader, lightsLocs[i][3], tempFloat, UNIFORM_VEC3);
|
||||
|
||||
//glUniform3f(lightsLocs[i][3], direction.x, direction.y, direction.z);
|
||||
} break;
|
||||
@ -410,7 +407,7 @@ static void SetShaderLightsValues(Shader shader)
|
||||
tempFloat[0] = lights[i]->position.x;
|
||||
tempFloat[1] = lights[i]->position.y;
|
||||
tempFloat[2] = lights[i]->position.z;
|
||||
SetShaderValue(shader, lightsLocs[i][2], tempFloat, 3);
|
||||
SetShaderValue(shader, lightsLocs[i][2], tempFloat, UNIFORM_VEC3);
|
||||
|
||||
//glUniform3f(lightsLocs[i][2], lights[i]->position.x, lights[i]->position.y, lights[i]->position.z);
|
||||
|
||||
@ -420,11 +417,11 @@ static void SetShaderLightsValues(Shader shader)
|
||||
tempFloat[0] = direction.x;
|
||||
tempFloat[1] = direction.y;
|
||||
tempFloat[2] = direction.z;
|
||||
SetShaderValue(shader, lightsLocs[i][3], tempFloat, 3);
|
||||
SetShaderValue(shader, lightsLocs[i][3], tempFloat, UNIFORM_VEC3);
|
||||
//glUniform3f(lightsLocs[i][3], direction.x, direction.y, direction.z);
|
||||
|
||||
tempFloat[0] = lights[i]->coneAngle;
|
||||
SetShaderValue(shader, lightsLocs[i][7], tempFloat, 1);
|
||||
SetShaderValue(shader, lightsLocs[i][7], tempFloat, UNIFORM_FLOAT);
|
||||
//glUniform1f(lightsLocs[i][7], lights[i]->coneAngle);
|
||||
} break;
|
||||
default: break;
|
||||
@ -433,7 +430,7 @@ static void SetShaderLightsValues(Shader shader)
|
||||
else
|
||||
{
|
||||
tempInt[0] = 0;
|
||||
SetShaderValuei(shader, lightsLocs[i][0], tempInt, 1); //glUniform1i(lightsLocs[i][0], 0); // Light disabled
|
||||
SetShaderValue(shader, lightsLocs[i][0], tempInt, UNIFORM_INT); //glUniform1i(lightsLocs[i][0], 0); // Light disabled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ out vec4 finalColor;
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture(texture0, fragTexCoord) * fragColor;
|
||||
vec4 texelColor = texture(texture0, fragTexCoord)*fragColor;
|
||||
|
||||
// Convert the (normalized) texel color RED component (GB would work, too)
|
||||
// to the palette index by scaling up from [0, 1] to [0, 255].
|
||||
|
@ -79,7 +79,7 @@ int main()
|
||||
swirlCenter[1] = screenHeight - mousePosition.y;
|
||||
|
||||
// Send new value to the shader to be used on drawing
|
||||
SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2);
|
||||
SetShaderValue(shader, swirlCenterLoc, swirlCenter, UNIFORM_VEC2);
|
||||
|
||||
UpdateCamera(&camera); // Update camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shaders] example - Apply a postprocessing shader to a scene
|
||||
* raylib [shaders] example - Color palette switch
|
||||
*
|
||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
||||
@ -9,10 +9,10 @@
|
||||
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
||||
* raylib comes with shaders ready for both versions, check raylib/shaders install folder
|
||||
*
|
||||
* This example has been created using raylib 2.x (www.raylib.com)
|
||||
* This example has been created using raylib 2.3 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
* Copyright (c) 2019 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
#define COLORS_PER_PALETTE 8
|
||||
#define VALUES_PER_COLOR 3
|
||||
|
||||
static const int palettes[MAX_PALETTES][COLORS_PER_PALETTE * VALUES_PER_COLOR] = {
|
||||
static const int palettes[MAX_PALETTES][COLORS_PER_PALETTE*VALUES_PER_COLOR] = {
|
||||
{
|
||||
0, 0, 0,
|
||||
255, 0, 0,
|
||||
@ -74,7 +74,7 @@ int main()
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - palette-switch shader");
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - color palette switch");
|
||||
|
||||
// Load shader to be used on some parts drawing
|
||||
// NOTE 1: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
|
||||
@ -106,9 +106,10 @@ int main()
|
||||
// Send new value to the shader to be used on drawing.
|
||||
// Note that we are sending RGB triplets w/o the alpha channel *only* if the current
|
||||
// palette index has changed (in order to save performances).
|
||||
if (currentPalette != paletteIndex) {
|
||||
if (currentPalette != paletteIndex)
|
||||
{
|
||||
currentPalette = paletteIndex;
|
||||
SetShaderValueArrayi(shader, paletteLoc, palettes[currentPalette], VALUES_PER_COLOR, COLORS_PER_PALETTE);
|
||||
SetShaderValueV(shader, paletteLoc, palettes[currentPalette], UNIFORM_IVEC3, COLORS_PER_PALETTE);
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
@ -126,14 +127,17 @@ int main()
|
||||
int leftover = screenHeight % COLORS_PER_PALETTE;
|
||||
int y = 0;
|
||||
|
||||
for (int i = 0; i < COLORS_PER_PALETTE; ++i) {
|
||||
for (int i = 0; i < COLORS_PER_PALETTE; ++i)
|
||||
{
|
||||
int height = linesPerRectangle;
|
||||
if (leftover > 0) {
|
||||
|
||||
if (leftover > 0)
|
||||
{
|
||||
height += 1;
|
||||
leftover -= 1;
|
||||
}
|
||||
|
||||
DrawRectangle(0, y, screenWidth, height, CLITERAL{ i, i, i, 255 });
|
||||
DrawRectangle(0, y, screenWidth, height, (Color){ i, i, i, 255 });
|
||||
|
||||
y += height;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ int main()
|
||||
int resolutionLoc = GetShaderLocation(shader, "resolution");
|
||||
|
||||
float resolution[2] = { screenWidth, screenHeight };
|
||||
SetShaderValue(shader, resolutionLoc, resolution, 2);
|
||||
SetShaderValue(shader, resolutionLoc, resolution, UNIFORM_VEC2);
|
||||
|
||||
float runTime = 0.0f;
|
||||
|
||||
@ -70,11 +70,11 @@ int main()
|
||||
runTime += deltaTime;
|
||||
|
||||
// Set shader required uniform values
|
||||
SetShaderValue(shader, viewEyeLoc, cameraPos, 3);
|
||||
SetShaderValue(shader, viewCenterLoc, cameraTarget, 3);
|
||||
SetShaderValue(shader, viewUpLoc, cameraUp, 3);
|
||||
SetShaderValue(shader, deltaTimeLoc, &deltaTime, 1);
|
||||
SetShaderValue(shader, runTimeLoc, &runTime, 1);
|
||||
SetShaderValue(shader, viewEyeLoc, cameraPos, UNIFORM_VEC3);
|
||||
SetShaderValue(shader, viewCenterLoc, cameraTarget, UNIFORM_VEC3);
|
||||
SetShaderValue(shader, viewUpLoc, cameraUp, UNIFORM_VEC3);
|
||||
SetShaderValue(shader, deltaTimeLoc, &deltaTime, UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, runTimeLoc, &runTime, UNIFORM_FLOAT);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
|
23
src/raylib.h
23
src/raylib.h
@ -676,6 +676,23 @@ typedef enum {
|
||||
#define LOC_MAP_DIFFUSE LOC_MAP_ALBEDO
|
||||
#define LOC_MAP_SPECULAR LOC_MAP_METALNESS
|
||||
|
||||
// Shader uniform data types
|
||||
typedef enum {
|
||||
UNIFORM_BOOL = 0,
|
||||
UNIFORM_INT,
|
||||
UNIFORM_UNIT,
|
||||
UNIFORM_FLOAT,
|
||||
UNIFORM_IVEC2,
|
||||
UNIFORM_IVEC3,
|
||||
UNIFORM_IVEC4,
|
||||
UNIFORM_UVEC2,
|
||||
UNIFORM_UVEC3,
|
||||
UNIFORM_UVEC4,
|
||||
UNIFORM_VEC2,
|
||||
UNIFORM_VEC3,
|
||||
UNIFORM_VEC4,
|
||||
} ShaderUniformDataType;
|
||||
|
||||
// Material map type
|
||||
typedef enum {
|
||||
MAP_ALBEDO = 0, // MAP_DIFFUSE
|
||||
@ -1229,10 +1246,8 @@ RLAPI Texture2D GetTextureDefault(void); // Get
|
||||
|
||||
// Shader configuration functions
|
||||
RLAPI int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location
|
||||
RLAPI void SetShaderValue(Shader shader, int uniformLoc, const float *value, int size); // Set shader uniform value (float)
|
||||
RLAPI void SetShaderValuei(Shader shader, int uniformLoc, const int *value, int size); // Set shader uniform value (int)
|
||||
RLAPI void SetShaderValueArray(Shader shader, int uniformLoc, const float *value, int size, int count); // Set shader uniform value (array of float/vec2/vec3/vec4)
|
||||
RLAPI void SetShaderValueArrayi(Shader shader, int uniformLoc, const int *value, int size, int count); // Set shader uniform value (array of int/ivec2/ivec3/ivec4)
|
||||
RLAPI void SetShaderValue(Shader shader, int uniformLoc, const void *value, int uniformType); // Set shader uniform value
|
||||
RLAPI void SetShaderValueV(Shader shader, int uniformLoc, const void *value, int uniformType, int count); // Set shader uniform value vector
|
||||
RLAPI void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4)
|
||||
RLAPI void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix)
|
||||
RLAPI void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix)
|
||||
|
94
src/rlgl.h
94
src/rlgl.h
@ -332,6 +332,23 @@ typedef unsigned char byte;
|
||||
LOC_MAP_PREFILTER,
|
||||
LOC_MAP_BRDF
|
||||
} ShaderLocationIndex;
|
||||
|
||||
// Shader uniform data types
|
||||
typedef enum {
|
||||
UNIFORM_BOOL = 0,
|
||||
UNIFORM_INT,
|
||||
UNIFORM_UNIT,
|
||||
UNIFORM_FLOAT,
|
||||
UNIFORM_IVEC2,
|
||||
UNIFORM_IVEC3,
|
||||
UNIFORM_IVEC4,
|
||||
UNIFORM_UVEC2,
|
||||
UNIFORM_UVEC3,
|
||||
UNIFORM_UVEC4,
|
||||
UNIFORM_VEC2,
|
||||
UNIFORM_VEC3,
|
||||
UNIFORM_VEC4,
|
||||
} ShaderUniformDataType;
|
||||
|
||||
#define LOC_MAP_DIFFUSE LOC_MAP_ALBEDO
|
||||
#define LOC_MAP_SPECULAR LOC_MAP_METALNESS
|
||||
@ -468,10 +485,8 @@ Texture2D GetTextureDefault(void); // Get defau
|
||||
|
||||
// Shader configuration functions
|
||||
int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location
|
||||
void SetShaderValue(Shader shader, int uniformLoc, const float *value, int size); // Set shader uniform value (float)
|
||||
void SetShaderValuei(Shader shader, int uniformLoc, const int *value, int size); // Set shader uniform value (int)
|
||||
void SetShaderValueArray(Shader shader, int uniformLoc, const float *value, int size, int count); // Set shader uniform value (array of float/vec2/vec3/vec4)
|
||||
void SetShaderValueArrayi(Shader shader, int uniformLoc, const int *value, int size, int count); // Set shader uniform value (array of int/ivec2/ivec3/ivec4)
|
||||
void SetShaderValue(Shader shader, int uniformLoc, const void *value, int uniformType); // Set shader uniform value
|
||||
void SetShaderValueV(Shader shader, int uniformLoc, const void *value, int uniformType, int count); // Set shader uniform value vector
|
||||
void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4)
|
||||
void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix)
|
||||
void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix)
|
||||
@ -2893,49 +2908,40 @@ int GetShaderLocation(Shader shader, const char *uniformName)
|
||||
return location;
|
||||
}
|
||||
|
||||
// Set shader uniform value (float/vec2/vec3/vec4)
|
||||
void SetShaderValue(Shader shader, int uniformLoc, const float *value, int size)
|
||||
// Set shader uniform value
|
||||
void SetShaderValue(Shader shader, int uniformLoc, const void *value, int uniformType)
|
||||
{
|
||||
SetShaderValueArray(shader, uniformLoc, value, size, 1);
|
||||
SetShaderValueV(shader, uniformLoc, value, uniformType, 1);
|
||||
}
|
||||
|
||||
// Set shader uniform value (int/ivec2/ivec3/ivec4)
|
||||
void SetShaderValuei(Shader shader, int uniformLoc, const int *value, int size)
|
||||
{
|
||||
SetShaderValueArrayi(shader, uniformLoc, value, size, 1);
|
||||
}
|
||||
|
||||
// Set shader uniform value (array of float/vec2/vec3/vec4)
|
||||
void SetShaderValueArray(Shader shader, int uniformLoc, const float *value, int size, int count)
|
||||
// Set shader uniform value vector
|
||||
void SetShaderValueV(Shader shader, int uniformLoc, const void *value, int uniformType, int count)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
glUseProgram(shader.id);
|
||||
|
||||
if (size == 1) glUniform1fv(uniformLoc, count, value); // Shader uniform type: float[]
|
||||
else if (size == 2) glUniform2fv(uniformLoc, count, value); // Shader uniform type: vec2[]
|
||||
else if (size == 3) glUniform3fv(uniformLoc, count, value); // Shader uniform type: vec3[]
|
||||
else if (size == 4) glUniform4fv(uniformLoc, count, value); // Shader uniform type: vec4[]
|
||||
else TraceLog(LOG_WARNING, "Wrong size for shader's uniform value (1 to 4 supported)");
|
||||
|
||||
switch (uniformType)
|
||||
{
|
||||
case UNIFORM_BOOL: glUniform1iv(uniformLoc, count, (int *)value); break;
|
||||
case UNIFORM_INT: glUniform1iv(uniformLoc, count, (int *)value); break;
|
||||
case UNIFORM_UNIT: glUniform1uiv(uniformLoc, count, (unsigned int *)value); break;
|
||||
case UNIFORM_FLOAT: glUniform1fv(uniformLoc, count, (float *)value); break;
|
||||
case UNIFORM_IVEC2: glUniform2iv(uniformLoc, count, (int *)value); break;
|
||||
case UNIFORM_IVEC3: glUniform3iv(uniformLoc, count, (int *)value); break;
|
||||
case UNIFORM_IVEC4: glUniform4iv(uniformLoc, count, (int *)value); break;
|
||||
case UNIFORM_UVEC2: glUniform2uiv(uniformLoc, count, (unsigned int *)value); break;
|
||||
case UNIFORM_UVEC3: glUniform3uiv(uniformLoc, count, (unsigned int *)value); break;
|
||||
case UNIFORM_UVEC4: glUniform4uiv(uniformLoc, count, (unsigned int *)value); break;
|
||||
case UNIFORM_VEC2: glUniform2fv(uniformLoc, count, (float *)value); break;
|
||||
case UNIFORM_VEC3: glUniform3fv(uniformLoc, count, (float *)value); break;
|
||||
case UNIFORM_VEC4: glUniform4fv(uniformLoc, count, (float *)value); break;
|
||||
default: TraceLog(LOG_WARNING, "Shader uniform could not be set data type not recognized");
|
||||
}
|
||||
|
||||
//glUseProgram(0); // Avoid reseting current shader program, in case other uniforms are set
|
||||
#endif
|
||||
}
|
||||
|
||||
// Set shader uniform value (array of int/ivec2/ivec3/ivec4)
|
||||
void SetShaderValueArrayi(Shader shader, int uniformLoc, const int *value, int size, int count)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
glUseProgram(shader.id);
|
||||
|
||||
if (size == 1) glUniform1iv(uniformLoc, count, value); // Shader uniform type: int[]
|
||||
else if (size == 2) glUniform2iv(uniformLoc, count, value); // Shader uniform type: ivec2[]
|
||||
else if (size == 3) glUniform3iv(uniformLoc, count, value); // Shader uniform type: ivec3[]
|
||||
else if (size == 4) glUniform4iv(uniformLoc, count, value); // Shader uniform type: ivec4[]
|
||||
else TraceLog(LOG_WARNING, "Wrong size for shader's uniform value (1 to 4 supported)");
|
||||
|
||||
//glUseProgram(0); // Avoid reseting current shader program, in case other uniforms are set
|
||||
#endif
|
||||
}
|
||||
|
||||
// Set shader uniform value (matrix 4x4)
|
||||
void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat)
|
||||
@ -4286,15 +4292,15 @@ static void SetStereoConfig(VrDeviceInfo hmd)
|
||||
|
||||
#if defined(SUPPORT_DISTORTION_SHADER)
|
||||
// Update distortion shader with lens and distortion-scale parameters
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "leftLensCenter"), leftLensCenter, 2);
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "rightLensCenter"), rightLensCenter, 2);
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "leftScreenCenter"), leftScreenCenter, 2);
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "rightScreenCenter"), rightScreenCenter, 2);
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "leftLensCenter"), leftLensCenter, UNIFORM_VEC2);
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "rightLensCenter"), rightLensCenter, UNIFORM_VEC2);
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "leftScreenCenter"), leftScreenCenter, UNIFORM_VEC2);
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "rightScreenCenter"), rightScreenCenter, UNIFORM_VEC2);
|
||||
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "scale"), scale, 2);
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "scaleIn"), scaleIn, 2);
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "hmdWarpParam"), hmd.lensDistortionValues, 4);
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "chromaAbParam"), hmd.chromaAbCorrection, 4);
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "scale"), scale, UNIFORM_VEC2);
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "scaleIn"), scaleIn, UNIFORM_VEC2);
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "hmdWarpParam"), hmd.lensDistortionValues, UNIFORM_VEC4);
|
||||
SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "chromaAbParam"), hmd.chromaAbCorrection, UNIFORM_VEC4);
|
||||
#endif
|
||||
|
||||
// Fovy is normally computed with: 2*atan2(hmd.vScreenSize, 2*hmd.eyeToScreenDistance)
|
||||
|
Loading…
Reference in New Issue
Block a user