Corrected issue with shader loading
When using FormatText() several times in same function, returned string is static and so, the same is returned, resulting in failures on shader loading.
This commit is contained in:
parent
5ef7beb0c5
commit
6332bc0398
@ -17,12 +17,6 @@
|
||||
#define RLIGHTS_IMPLEMENTATION
|
||||
#include "rlights.h"
|
||||
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
#define GLSL_VERSION 330
|
||||
#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
|
||||
#define GLSL_VERSION 100
|
||||
#endif
|
||||
|
||||
#define CUBEMAP_SIZE 512 // Cubemap texture size
|
||||
#define IRRADIANCE_SIZE 32 // Irradiance texture size
|
||||
#define PREFILTERED_SIZE 256 // Prefiltered HDR environment texture size
|
||||
@ -120,9 +114,12 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
||||
{
|
||||
Material mat = { 0 }; // NOTE: All maps textures are set to { 0 }
|
||||
|
||||
mat.shader = LoadShader(FormatText("resources/shaders/glsl%i/pbr.vs", GLSL_VERSION),
|
||||
FormatText("resources/shaders/glsl%i/pbr.fs", GLSL_VERSION));
|
||||
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
mat.shader = LoadShader("resources/shaders/glsl330/pbr.vs", "resources/shaders/glsl330/pbr.fs");
|
||||
#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
|
||||
mat.shader = LoadShader("resources/shaders/glsl100/pbr.vs", "resources/shaders/glsl100/pbr.fs");
|
||||
#endif
|
||||
|
||||
// Get required locations points for PBR material
|
||||
// NOTE: Those location names must be available and used in the shader code
|
||||
mat.shader.locs[LOC_MAP_ALBEDO] = GetShaderLocation(mat.shader, "albedo.sampler");
|
||||
@ -149,20 +146,32 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
||||
mat.maps[MAP_OCCLUSION].texture = LoadTexture("resources/pbr/trooper_ao.png");
|
||||
|
||||
// Load equirectangular to cubemap shader
|
||||
Shader shdrCubemap = LoadShader(FormatText("resources/shaders/glsl%i/cubemap.vs", GLSL_VERSION),
|
||||
FormatText("resources/shaders/glsl%i/cubemap.fs", GLSL_VERSION));
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
Shader shdrCubemap = LoadShader("resources/shaders/glsl330/cubemap.vs", "resources/shaders/glsl330/cubemap.fs");
|
||||
#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
|
||||
Shader shdrCubemap = LoadShader("resources/shaders/glsl100/cubemap.vs", "resources/shaders/glsl100/cubemap.fs");
|
||||
#endif
|
||||
|
||||
// Load irradiance (GI) calculation shader
|
||||
Shader shdrIrradiance = LoadShader(FormatText("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
|
||||
FormatText("resources/shaders/glsl%i/irradiance.fs", GLSL_VERSION));
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
Shader shdrIrradiance = LoadShader("resources/shaders/glsl330/skybox.vs", "resources/shaders/glsl330/irradiance.fs");
|
||||
#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
|
||||
Shader shdrIrradiance = LoadShader("resources/shaders/glsl100/skybox.vs", "resources/shaders/glsl100/irradiance.fs");
|
||||
#endif
|
||||
|
||||
// Load reflection prefilter calculation shader
|
||||
Shader shdrPrefilter = LoadShader(FormatText("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
|
||||
FormatText("resources/shaders/glsl%i/prefilter.fs", GLSL_VERSION));
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
Shader shdrPrefilter = LoadShader("resources/shaders/glsl330/skybox.vs", "resources/shaders/glsl330/prefilter.fs");
|
||||
#else
|
||||
Shader shdrPrefilter = LoadShader("resources/shaders/glsl100/skybox.vs", "resources/shaders/glsl100/prefilter.fs");
|
||||
#endif
|
||||
|
||||
// Load bidirectional reflectance distribution function shader
|
||||
Shader shdrBRDF = LoadShader(FormatText("resources/shaders/glsl%i/brdf.vs", GLSL_VERSION),
|
||||
FormatText("resources/shaders/glsl%i/brdf.fs", GLSL_VERSION));
|
||||
// Load bidirectional reflectance distribution function shader
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
Shader shdrBRDF = LoadShader("resources/shaders/glsl330/brdf.vs", "resources/shaders/glsl330/brdf.fs");
|
||||
#else
|
||||
Shader shdrBRDF = LoadShader("resources/shaders/glsl100/brdf.vs", "resources/shaders/glsl100/brdf.fs");
|
||||
#endif
|
||||
|
||||
// Setup required shader locations
|
||||
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT);
|
||||
|
@ -11,12 +11,6 @@
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
#define GLSL_VERSION 330
|
||||
#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
|
||||
#define GLSL_VERSION 100
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
// Initialization
|
||||
@ -35,13 +29,19 @@ int main()
|
||||
|
||||
// Load skybox shader and set required locations
|
||||
// NOTE: Some locations are automatically set at shader loading
|
||||
skybox.materials[0].shader = LoadShader(FormatText("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
|
||||
FormatText("resources/shaders/glsl%i/skybox.fs", GLSL_VERSION));
|
||||
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
skybox.materials[0].shader = LoadShader("resources/shaders/glsl330/skybox.vs", "resources/shaders/glsl330/skybox.fs");
|
||||
#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
|
||||
skybox.materials[0].shader = LoadShader("resources/shaders/glsl100/skybox.vs", "resources/shaders/glsl100/skybox.fs");
|
||||
#endif
|
||||
SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].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");
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
Shader shdrCubemap = LoadShader("resources/shaders/glsl330/cubemap.vs", "resources/shaders/glsl330/cubemap.fs");
|
||||
#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
|
||||
Shader shdrCubemap = LoadShader("resources/shaders/glsl100/cubemap.vs", "resources/shaders/glsl100/cubemap.fs");
|
||||
#endif
|
||||
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT);
|
||||
|
||||
// Load HDR panorama (sphere) texture
|
||||
|
@ -28,5 +28,5 @@ void main()
|
||||
vec4 clipPos = projection*rotView*vec4(vertexPosition, 1.0);
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = clipPos.xyww;
|
||||
gl_Position = clipPos.xyzw;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user