From 90f01de0cbcd94531b5f3553b40fb04d2173551a Mon Sep 17 00:00:00 2001 From: Sara Date: Thu, 19 Sep 2024 15:45:01 +0200 Subject: [PATCH] fix: OnShaderLoaded now checks if locations exist before setting uniforms --- src/core/render.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/render.c b/src/core/render.c index cf816c4..5dcb217 100644 --- a/src/core/render.c +++ b/src/core/render.c @@ -11,7 +11,7 @@ static Matrix g_light_direction = {}; void InitializeRenderingSubsystem() { g_render_objects = list_from_type(Renderable); // Allocate list of renderable typeclass wrappers - g_light_direction = QuaternionToMatrix(QuaternionFromEuler(-65.f, 45.f, 0.f)); + g_light_direction = QuaternionToMatrix(QuaternionFromEuler(50.f * DEG2RAD, 0.f, 0.f)); g_shaders = list_from_type(ShaderResource); } @@ -64,9 +64,13 @@ void RenderNextFrame() { void Internal_OnShaderLoaded(ShaderResource resource) { list_add(&g_shaders, &resource); int light_direction_loc = GetShaderLocation(*resource.resource, "lightDirection"); - int ambient_level_loc = GetShaderLocation(*resource.resource, "ambient"); - SetShaderValue(*resource.resource, light_direction_loc, &MATRIX_FORWARD(g_light_direction), SHADER_UNIFORM_VEC3); - SetShaderValue(*resource.resource, ambient_level_loc, &WHITE, SHADER_UNIFORM_VEC4); + int ambient_level_loc = GetShaderLocation(*resource.resource, "ambientLight"); + Vector3 lightdir = MATRIX_FORWARD(g_light_direction); + Vector4 ambient_color = {0.2, 0.2, 0.2, 1.0}; + if(light_direction_loc != -1) + SetShaderValue(*resource.resource, light_direction_loc, &MATRIX_FORWARD(g_light_direction), SHADER_UNIFORM_VEC3); + if(ambient_level_loc != -1) + SetShaderValue(*resource.resource, ambient_level_loc, &ambient_color, SHADER_UNIFORM_VEC4); } void Internal_OnShaderUnloaded(ShaderResource resource) {