diff options
author | nathan <nathansmith@disroot.org> | 2025-08-09 06:27:38 +0000 |
---|---|---|
committer | nathan <nathansmith@disroot.org> | 2025-08-09 06:27:38 +0000 |
commit | b53a1285f75a6d8eda6d4e96f3d7bb3faa442962 (patch) | |
tree | 37e295f1be72c6718eea4b399ae4af6e72568c31 | |
parent | 9008ba69ba749e96da1ce0c56dce91ea72296223 (diff) | |
download | FindThings-b53a1285f75a6d8eda6d4e96f3d7bb3faa442962.tar.gz FindThings-b53a1285f75a6d8eda6d4e96f3d7bb3faa442962.tar.bz2 FindThings-b53a1285f75a6d8eda6d4e96f3d7bb3faa442962.zip |
Figured out the shader thingy
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | assets/shaders/glsl330/instancing.vs | 22 | ||||
-rw-r--r-- | src/utils.h | 2 | ||||
-rw-r--r-- | src/world.c | 5 |
4 files changed, 19 insertions, 15 deletions
@@ -1,3 +1,6 @@ compile_commands.json +*.o +src/assets +src/FindThings .cache -*~
\ No newline at end of file +*~ diff --git a/assets/shaders/glsl330/instancing.vs b/assets/shaders/glsl330/instancing.vs index f537278..6473ccf 100644 --- a/assets/shaders/glsl330/instancing.vs +++ b/assets/shaders/glsl330/instancing.vs @@ -1,29 +1,33 @@ -#version 330 core +#version 330 // Input vertex attributes in vec3 vertexPosition; in vec2 vertexTexCoord; +in vec3 vertexNormal; +//in vec4 vertexColor; // Not required -layout (location = 12) in mat4 instance; +in mat4 instanceTransform; // Input uniform values uniform mat4 mvp; -uniform mat4 projection; -uniform mat4 view; +uniform mat4 matNormal; // Output vertex attributes (to fragment shader) +out vec3 fragPosition; out vec2 fragTexCoord; out vec4 fragColor; out vec3 fragNormal; -// NOTE: Add here your custom variables +// NOTE: Add your custom variables here void main() { // Send vertex attributes to fragment shader + fragPosition = vec3(instanceTransform*vec4(vertexPosition, 1.0)); fragTexCoord = vertexTexCoord; + fragColor = vec4(1.0); + fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0))); - // Calculate final vertex position - mat4 mvpi = mvp * instance; - gl_Position = mvpi * vec4(vertexPosition, 1.0); -}
\ No newline at end of file + // Calculate final vertex position, note that we multiply mvp by instanceTransform + gl_Position = mvp*instanceTransform*vec4(vertexPosition, 1.0); +} diff --git a/src/utils.h b/src/utils.h index 4f6bf6d..4f09c0d 100644 --- a/src/utils.h +++ b/src/utils.h @@ -30,6 +30,8 @@ #define ALLOCATION_ERROR TraceLog(LOG_ERROR, "Allocation error in %s:%d", \ __FILE__, __LINE__) +#define PLATFORM_DESKTOP + // GLSL version #ifdef PLATFORM_DESKTOP #define GLSL_VERSION 330 diff --git a/src/world.c b/src/world.c index 7a50885..bbaf225 100644 --- a/src/world.c +++ b/src/world.c @@ -488,11 +488,6 @@ Seed generateWorldUtilityPoles(World* world, const Assets* assets, Seed seed, // Instancing shader. Shader shader = assets->shaders[INSTANCING_SHADER]; shader.locs[SHADER_LOC_MATRIX_MVP] = GetShaderLocation(shader, "mvp"); - shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocationAttrib(shader, - "instance"); - shader.locs[SHADER_LOC_MATRIX_VIEW] = GetShaderLocation(shader, "view"); - shader.locs[SHADER_LOC_MATRIX_PROJECTION] = GetShaderLocation(shader, - "projection"); assets->models[UTILITY_POLE_MODEL].materials[0].shader = shader; assets->models[UTILITY_POLE_MODEL].materials[0] .maps[MATERIAL_MAP_DIFFUSE].color = BLUE; |