From 01c68d7e7529827ae34555b0710ea5a3e4fc937e Mon Sep 17 00:00:00 2001 From: Johnny Cena Date: Tue, 19 Aug 2025 12:30:07 +0200 Subject: [PATCH 1/9] fix typo in workflow name --- .github/workflows/{analize_codeql.yml => analyze_codeql.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{analize_codeql.yml => analyze_codeql.yml} (100%) diff --git a/.github/workflows/analize_codeql.yml b/.github/workflows/analyze_codeql.yml similarity index 100% rename from .github/workflows/analize_codeql.yml rename to .github/workflows/analyze_codeql.yml From 25d00130a8880ef736bc8e7aa22dbf5cd1fbdc4a Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 19 Aug 2025 13:17:50 +0200 Subject: [PATCH 2/9] REVIEWED: example: `text_unicode_ranges` --- examples/text/text_unicode_font.c | 127 ------------------- examples/text/text_unicode_ranges.c | 183 ++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+), 127 deletions(-) delete mode 100644 examples/text/text_unicode_font.c create mode 100644 examples/text/text_unicode_ranges.c diff --git a/examples/text/text_unicode_font.c b/examples/text/text_unicode_font.c deleted file mode 100644 index 316d8c874..000000000 --- a/examples/text/text_unicode_font.c +++ /dev/null @@ -1,127 +0,0 @@ -#include -#include - -#define SCREEN_WIDTH 800 -#define SCREEN_HEIGHT 450 - -typedef struct { - int* data; - int count; - int capacity; -} CodepointsArray; - -static void AddRange(CodepointsArray* array, int start, int stop) { - int rangeSize = stop - start + 1; - - if (array->count + rangeSize > array->capacity) { - array->capacity = array->count + rangeSize + 1024; - array->data = (int*)MemRealloc(array->data, array->capacity * sizeof(int)); - if (!array->data) { - TraceLog(LOG_ERROR, "FONTUTIL: Memory allocation failed"); - exit(1); - } - } - - for (int i = start; i <= stop; i++) { - array->data[array->count++] = i; - } -} - -Font LoadUnicodeFont(const char* fileName, int fontSize, int textureFilter) { - CodepointsArray cp = {0}; - cp.capacity = 2048; - cp.data = (int*)MemAlloc(cp.capacity * sizeof(int)); - - if (!cp.data) { - TraceLog(LOG_ERROR, "FONTUTIL: Initial allocation failed"); - return GetFontDefault(); - } - - // Basic ASCII - AddRange(&cp, 32, 126); - - // European Languages - AddRange(&cp, 0xC0, 0x17F); - AddRange(&cp, 0x180, 0x24F); - AddRange(&cp, 0x1E00, 0x1EFF); - AddRange(&cp, 0x2C60, 0x2C7F); - - // Greek - AddRange(&cp, 0x370, 0x3FF); - AddRange(&cp, 0x1F00, 0x1FFF); - - // Cyrillic - AddRange(&cp, 0x400, 0x4FF); - AddRange(&cp, 0x500, 0x52F); - AddRange(&cp, 0x2DE0, 0x2DFF); - AddRange(&cp, 0xA640, 0xA69F); - - // CJK - AddRange(&cp, 0x4E00, 0x9FFF); - AddRange(&cp, 0x3400, 0x4DBF); - AddRange(&cp, 0x3000, 0x303F); - AddRange(&cp, 0x3040, 0x309F); - AddRange(&cp, 0x30A0, 0x30FF); - AddRange(&cp, 0x31F0, 0x31FF); - AddRange(&cp, 0xFF00, 0xFFEF); - AddRange(&cp, 0xAC00, 0xD7AF); - AddRange(&cp, 0x1100, 0x11FF); - - // Other - AddRange(&cp, 0x900, 0x97F); // Devanagari - AddRange(&cp, 0x600, 0x6FF); // Arabic - AddRange(&cp, 0x5D0, 0x5EA); // Hebrew - - Font font = {0}; - - if (FileExists(fileName)) { - font = LoadFontEx(fileName, fontSize, cp.data, cp.count); - } - - if (font.texture.id == 0) { - font = GetFontDefault(); - TraceLog(LOG_WARNING, "FONTUTIL: Using default font"); - } - - SetTextureFilter(font.texture, textureFilter); - MemFree(cp.data); - - return font; -} - -/** - * Main entry point - */ -int main(void) -{ - // Initialize window - InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Unicode Font Example"); - SetTargetFPS(60); - - // Load font with Unicode support - Font myFont = LoadUnicodeFont("resources/NotoSansTC-Regular.ttf", 36, TEXTURE_FILTER_BILINEAR); - - // Main render loop - while (!WindowShouldClose()) - { - BeginDrawing(); - ClearBackground(RAYWHITE); - - // Render test strings in different languages - DrawTextEx(myFont, "English: Hello World!", (Vector2){50, 50}, 36, 1, DARKGRAY); - DrawTextEx(myFont, "Русский: Привет мир!", (Vector2){50, 100}, 36, 0, DARKGRAY); - DrawTextEx(myFont, "中文: 你好世界!", (Vector2){50, 150}, 36, 1, DARKGRAY); - DrawTextEx(myFont, "日本語: こんにちは世界!", (Vector2){50, 200}, 36, 1, DARKGRAY); - - // Display font attribution - DrawText("Font: Noto Sans TC. License: SIL Open Font License 1.1", - 10, SCREEN_HEIGHT - 20, 10, GRAY); - EndDrawing(); - } - - // Cleanup resources - UnloadFont(myFont); - CloseWindow(); - - return 0; -} diff --git a/examples/text/text_unicode_ranges.c b/examples/text/text_unicode_ranges.c new file mode 100644 index 000000000..d3cb4b5e5 --- /dev/null +++ b/examples/text/text_unicode_ranges.c @@ -0,0 +1,183 @@ +/******************************************************************************************* +* +* raylib [text] example - unicode ranges +* +* Example complexity rating: [★★★★] 4/4 +* +* Example originally created with raylib 2.5, last time updated with raylib 4.0 +* +* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5) +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2019-2025 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include + +typedef struct { + int* data; + int count; + int capacity; +} CodepointsArray; + +//-------------------------------------------------------------------------------------- +// Module functions declaration +//-------------------------------------------------------------------------------------- +static void AddRange(CodepointsArray* array, int start, int stop); +static Font LoadUnicodeFont(const char* fileName, int fontSize); + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [text] example - unicode ranges"); + + // Load font with Unicode support + Font fontUni = LoadUnicodeFont("resources/NotoSansTC-Regular.ttf", 32); + SetTextureFilter(fontUni.texture, TEXTURE_FILTER_BILINEAR); + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + //... + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // Render test strings in different languages + DrawTextEx(fontUni, "English: Hello World!", (Vector2){ 50, 50 }, 32, 1, DARKGRAY); // English + DrawTextEx(fontUni, "Español: Hola mundo!", (Vector2){ 50, 100 }, 32, 1, DARKGRAY); // Spanish + DrawTextEx(fontUni, "Ελληνικά: Γειά σου κόσμε!", (Vector2){ 50, 150 }, 32, 1, DARKGRAY); // Greek + DrawTextEx(fontUni, "Русский: Привет мир!", (Vector2){ 50, 200 }, 32, 0, DARKGRAY); // Russian + DrawTextEx(fontUni, "中文: 你好世界!", (Vector2){ 50, 250 }, 32, 1, DARKGRAY); // Chinese + DrawTextEx(fontUni, "日本語: こんにちは世界!", (Vector2){ 50, 300 }, 32, 1, DARKGRAY); // Japanese + DrawTextEx(fontUni, "देवनागरी: होला मुंडो!", (Vector2){ 50, 350 }, 32, 1, DARKGRAY); // Devanagari + + DrawRectangle(400, 16, 380, 400, BLACK); + DrawTexturePro(fontUni.texture, (Rectangle){ 0, 0, fontUni.texture.width, fontUni.texture.height }, + (Rectangle){ 400, 16, 380, 400 }, (Vector2){ 0, 0 }, 0.0f, WHITE); + + // Display font attribution + DrawText("Font: Noto Sans TC. License: SIL Open Font License 1.1", screenWidth - 300, screenHeight - 20, 10, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadFont(fontUni); // Unload font resource + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +//-------------------------------------------------------------------------------------- +// Module functions definition +//-------------------------------------------------------------------------------------- +static void AddRange(CodepointsArray* array, int start, int stop) +{ + int rangeSize = stop - start + 1; + + if ((array->count + rangeSize) > array->capacity) + { + array->capacity = array->count + rangeSize + 1024; + array->data = (int *)MemRealloc(array->data, array->capacity*sizeof(int)); + + if (!array->data) + { + TraceLog(LOG_ERROR, "FONTUTIL: Memory allocation failed"); + exit(1); + } + } + + for (int i = start; i <= stop; i++) array->data[array->count++] = i; +} + +Font LoadUnicodeFont(const char *fileName, int fontSize) +{ + CodepointsArray cp = { 0 }; + cp.capacity = 2048; + cp.data = (int *)MemAlloc(cp.capacity*sizeof(int)); + + if (!cp.data) + { + TraceLog(LOG_ERROR, "FONTUTIL: Initial allocation failed"); + return GetFontDefault(); + } + + // Unicode range: Basic ASCII + AddRange(&cp, 32, 126); + + // Unicode range: European Languages + AddRange(&cp, 0xC0, 0x17F); + AddRange(&cp, 0x180, 0x24F); + AddRange(&cp, 0x1E00, 0x1EFF); + AddRange(&cp, 0x2C60, 0x2C7F); + + // Unicode range: Greek + AddRange(&cp, 0x370, 0x3FF); + AddRange(&cp, 0x1F00, 0x1FFF); + + // Unicode range: Cyrillic + AddRange(&cp, 0x400, 0x4FF); + AddRange(&cp, 0x500, 0x52F); + AddRange(&cp, 0x2DE0, 0x2DFF); + AddRange(&cp, 0xA640, 0xA69F); + + // Unicode range: CJK + AddRange(&cp, 0x4E00, 0x9FFF); + AddRange(&cp, 0x3400, 0x4DBF); + AddRange(&cp, 0x3000, 0x303F); + AddRange(&cp, 0x3040, 0x309F); + AddRange(&cp, 0x30A0, 0x30FF); + AddRange(&cp, 0x31F0, 0x31FF); + AddRange(&cp, 0xFF00, 0xFFEF); + AddRange(&cp, 0xAC00, 0xD7AF); + AddRange(&cp, 0x1100, 0x11FF); + + // Unicode range: Other + // WARNING: Not available on provided font + AddRange(&cp, 0x900, 0x97F); // Devanagari + AddRange(&cp, 0x600, 0x6FF); // Arabic + AddRange(&cp, 0x5D0, 0x5EA); // Hebrew + + Font font = {0}; + + if (FileExists(fileName)) + { + font = LoadFontEx(fileName, fontSize, cp.data, cp.count); + } + + if (font.texture.id == 0) + { + font = GetFontDefault(); + TraceLog(LOG_WARNING, "FONTUTIL: Using default font"); + } + + MemFree(cp.data); + + return font; +} From 8ba4ff21430b64b1799834a5a8f5a902fff38d87 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 19 Aug 2025 13:22:04 +0200 Subject: [PATCH 3/9] Renamed directory for sprite fonts --- .../resources/{fonts => sprite_fonts}/alagard.png | Bin .../{fonts => sprite_fonts}/alpha_beta.png | Bin .../{fonts => sprite_fonts}/jupiter_crash.png | Bin .../resources/{fonts => sprite_fonts}/mecha.png | Bin .../{fonts => sprite_fonts}/pixantiqua.png | Bin .../resources/{fonts => sprite_fonts}/pixelplay.png | Bin .../resources/{fonts => sprite_fonts}/romulus.png | Bin .../resources/{fonts => sprite_fonts}/setback.png | Bin 8 files changed, 0 insertions(+), 0 deletions(-) rename examples/text/resources/{fonts => sprite_fonts}/alagard.png (100%) rename examples/text/resources/{fonts => sprite_fonts}/alpha_beta.png (100%) rename examples/text/resources/{fonts => sprite_fonts}/jupiter_crash.png (100%) rename examples/text/resources/{fonts => sprite_fonts}/mecha.png (100%) rename examples/text/resources/{fonts => sprite_fonts}/pixantiqua.png (100%) rename examples/text/resources/{fonts => sprite_fonts}/pixelplay.png (100%) rename examples/text/resources/{fonts => sprite_fonts}/romulus.png (100%) rename examples/text/resources/{fonts => sprite_fonts}/setback.png (100%) diff --git a/examples/text/resources/fonts/alagard.png b/examples/text/resources/sprite_fonts/alagard.png similarity index 100% rename from examples/text/resources/fonts/alagard.png rename to examples/text/resources/sprite_fonts/alagard.png diff --git a/examples/text/resources/fonts/alpha_beta.png b/examples/text/resources/sprite_fonts/alpha_beta.png similarity index 100% rename from examples/text/resources/fonts/alpha_beta.png rename to examples/text/resources/sprite_fonts/alpha_beta.png diff --git a/examples/text/resources/fonts/jupiter_crash.png b/examples/text/resources/sprite_fonts/jupiter_crash.png similarity index 100% rename from examples/text/resources/fonts/jupiter_crash.png rename to examples/text/resources/sprite_fonts/jupiter_crash.png diff --git a/examples/text/resources/fonts/mecha.png b/examples/text/resources/sprite_fonts/mecha.png similarity index 100% rename from examples/text/resources/fonts/mecha.png rename to examples/text/resources/sprite_fonts/mecha.png diff --git a/examples/text/resources/fonts/pixantiqua.png b/examples/text/resources/sprite_fonts/pixantiqua.png similarity index 100% rename from examples/text/resources/fonts/pixantiqua.png rename to examples/text/resources/sprite_fonts/pixantiqua.png diff --git a/examples/text/resources/fonts/pixelplay.png b/examples/text/resources/sprite_fonts/pixelplay.png similarity index 100% rename from examples/text/resources/fonts/pixelplay.png rename to examples/text/resources/sprite_fonts/pixelplay.png diff --git a/examples/text/resources/fonts/romulus.png b/examples/text/resources/sprite_fonts/romulus.png similarity index 100% rename from examples/text/resources/fonts/romulus.png rename to examples/text/resources/sprite_fonts/romulus.png diff --git a/examples/text/resources/fonts/setback.png b/examples/text/resources/sprite_fonts/setback.png similarity index 100% rename from examples/text/resources/fonts/setback.png rename to examples/text/resources/sprite_fonts/setback.png From 0658abc64c06c1877a053fe87540a7e1defe99f7 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 19 Aug 2025 13:22:15 +0200 Subject: [PATCH 4/9] Update text_raylib_fonts.c --- examples/text/text_raylib_fonts.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/text/text_raylib_fonts.c b/examples/text/text_raylib_fonts.c index 7248be128..99937549d 100644 --- a/examples/text/text_raylib_fonts.c +++ b/examples/text/text_raylib_fonts.c @@ -1,6 +1,6 @@ /******************************************************************************************* * -* raylib [text] example - raylib fonts loading +* raylib [text] example - sprite fonts loading * * Example complexity rating: [★☆☆☆] 1/4 * @@ -30,19 +30,19 @@ int main(void) const int screenWidth = 800; const int screenHeight = 450; - InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts"); + InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite fonts"); // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) Font fonts[MAX_FONTS] = { 0 }; - fonts[0] = LoadFont("resources/fonts/alagard.png"); - fonts[1] = LoadFont("resources/fonts/pixelplay.png"); - fonts[2] = LoadFont("resources/fonts/mecha.png"); - fonts[3] = LoadFont("resources/fonts/setback.png"); - fonts[4] = LoadFont("resources/fonts/romulus.png"); - fonts[5] = LoadFont("resources/fonts/pixantiqua.png"); - fonts[6] = LoadFont("resources/fonts/alpha_beta.png"); - fonts[7] = LoadFont("resources/fonts/jupiter_crash.png"); + fonts[0] = LoadFont("resources/sprite_fonts/alagard.png"); + fonts[1] = LoadFont("resources/sprite_fonts/pixelplay.png"); + fonts[2] = LoadFont("resources/sprite_fonts/mecha.png"); + fonts[3] = LoadFont("resources/sprite_fonts/setback.png"); + fonts[4] = LoadFont("resources/sprite_fonts/romulus.png"); + fonts[5] = LoadFont("resources/sprite_fonts/pixantiqua.png"); + fonts[6] = LoadFont("resources/sprite_fonts/alpha_beta.png"); + fonts[7] = LoadFont("resources/sprite_fonts/jupiter_crash.png"); const char *messages[MAX_FONTS] = { "ALAGARD FONT designed by Hewett Tsoi", "PIXELPLAY FONT designed by Aleksander Shevchuk", @@ -87,8 +87,8 @@ int main(void) ClearBackground(RAYWHITE); - DrawText("free fonts included with raylib", 250, 20, 20, DARKGRAY); - DrawLine(220, 50, 590, 50, DARKGRAY); + DrawText("free sprite fonts included with raylib", 220, 20, 20, DARKGRAY); + DrawLine(220, 50, 600, 50, DARKGRAY); for (int i = 0; i < MAX_FONTS; i++) { From 572230c8adfca8b2ee8550a8746a11d8717be00b Mon Sep 17 00:00:00 2001 From: Jeffery Myers Date: Tue, 19 Aug 2025 08:16:20 -0700 Subject: [PATCH 5/9] Initialize sound alias properties as if it was a new sound --- src/raudio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/raudio.c b/src/raudio.c index 76fee2333..e21bf578c 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -982,9 +982,13 @@ Sound LoadSoundAlias(Sound source) } audioBuffer->sizeInFrames = source.stream.buffer->sizeInFrames; - audioBuffer->volume = source.stream.buffer->volume; audioBuffer->data = source.stream.buffer->data; + // initalize the buffer as if it was new + audioBuffer->volume = 1.0f; + audioBuffer->pitch = 1.0f; + audioBuffer->pan = 0.5f; + sound.frameCount = source.frameCount; sound.stream.sampleRate = AUDIO.System.device.sampleRate; sound.stream.sampleSize = 32; From 15baf176b2e1f6441efb5bef525bf65aaf47a41d Mon Sep 17 00:00:00 2001 From: Jeffery Myers Date: Tue, 19 Aug 2025 10:39:38 -0700 Subject: [PATCH 6/9] Add a utility header to external that undefines the parts of windows that conflict with raylib, allowing raylib functions to run unimpeded --- src/external/fix_win32_compatibility.h | 63 ++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/external/fix_win32_compatibility.h diff --git a/src/external/fix_win32_compatibility.h b/src/external/fix_win32_compatibility.h new file mode 100644 index 000000000..fb0f606fb --- /dev/null +++ b/src/external/fix_win32_compatibility.h @@ -0,0 +1,63 @@ +/********************************************************************************************** +* +* fix_win32_compatibility.h Utility to help include windows.h with raylib projects +* +* Useage: #include "fix_win32_compatibility.h" any library that uses windows.h +* order is critical, this must be done before raylib +* +* LICENSE: MIT +* +* Copyright (c) 2025 Jeffery Myers +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +**********************************************************************************************/ + +#pragma once + +// move the windows functions to new names +// note that you can't call these functions or structures from your code, but you should not neeed to +#define CloseWindow CloseWindowWin32 +#define Rectangle RectangleWin32 +#define ShowCursor ShowCursorWin32 +#define LoadImageA LoadImageAWin32 +#define LoadImageW LoadImageWin32 +#define DrawTextA DrawTextAWin32 +#define DrawTextW DrawTextWin32 +#define DrawTextExA DrawTextExAWin32 +#define DrawTextExW DrawTextExWin32 +#define PlaySoundA PlaySoundAWin32\ +// include windows +#define WIN32_LEAN_AND_MEAN +#include + +// remove all our redfintions so that raylib can define them properly +#undef CloseWindow +#undef Rectangle +#undef ShowCursor +#undef LoadImage +#undef LoadImageA +#undef LoadImageW +#undef DrawText +#undef DrawTextA +#undef DrawTextW +#undef DrawTextEx +#undef DrawTextExA +#undef DrawTextExW +#undef PlaySoundA From cb05945e764982357092a40a83c454c2037f303a Mon Sep 17 00:00:00 2001 From: Johnny Cena Date: Wed, 20 Aug 2025 11:17:44 +0200 Subject: [PATCH 7/9] add missing shaders --- .../shaders/glsl100/voxel_lighting.fs | 65 +++++++++++++++++++ .../shaders/glsl100/voxel_lighting.vs | 28 ++++++++ .../shaders/glsl120/voxel_lighting.fs | 61 +++++++++++++++++ .../shaders/glsl120/voxel_lighting.vs | 23 +++++++ 4 files changed, 177 insertions(+) create mode 100644 examples/models/resources/shaders/glsl100/voxel_lighting.fs create mode 100644 examples/models/resources/shaders/glsl100/voxel_lighting.vs create mode 100644 examples/models/resources/shaders/glsl120/voxel_lighting.fs create mode 100644 examples/models/resources/shaders/glsl120/voxel_lighting.vs diff --git a/examples/models/resources/shaders/glsl100/voxel_lighting.fs b/examples/models/resources/shaders/glsl100/voxel_lighting.fs new file mode 100644 index 000000000..ba02ad21e --- /dev/null +++ b/examples/models/resources/shaders/glsl100/voxel_lighting.fs @@ -0,0 +1,65 @@ +#ifdef GL_ES +precision mediump float; +#endif + +// Input from vertex shader +varying vec3 fragPosition; +varying vec4 fragColor; +varying vec3 fragNormal; + +// Uniforms +uniform vec4 colDiffuse; +uniform vec4 ambient; +uniform vec3 viewPos; + +#define MAX_LIGHTS 4 +#define LIGHT_DIRECTIONAL 0 +#define LIGHT_POINT 1 + +struct Light { + int enabled; + int type; + vec3 position; + vec3 target; + vec4 color; +}; + +uniform Light lights[MAX_LIGHTS]; + +void main() +{ + vec3 lightDot = vec3(0.0); + vec3 normal = normalize(fragNormal); + vec3 viewD = normalize(viewPos - fragPosition); + vec3 specular = vec3(0.0); + + for (int i = 0; i < MAX_LIGHTS; i++) + { + if (lights[i].enabled == 1) + { + vec3 light = vec3(0.0); + + if (lights[i].type == LIGHT_DIRECTIONAL) + light = -normalize(lights[i].target - lights[i].position); + + if (lights[i].type == LIGHT_POINT) + light = normalize(lights[i].position - fragPosition); + + float NdotL = max(dot(normal, light), 0.0); + lightDot += lights[i].color.rgb * NdotL; + + if (NdotL > 0.0) + { + float specCo = pow(max(0.0, dot(viewD, reflect(-light, normal))), 16.0); + specular += specCo; + } + } + } + + vec4 finalColor = (fragColor * ((colDiffuse + vec4(specular, 1.0)) * vec4(lightDot, 1.0))); + finalColor += fragColor * (ambient / 10.0) * colDiffuse; + + finalColor = pow(finalColor, vec4(1.0/2.2)); // gamma correction + + gl_FragColor = finalColor; +} diff --git a/examples/models/resources/shaders/glsl100/voxel_lighting.vs b/examples/models/resources/shaders/glsl100/voxel_lighting.vs new file mode 100644 index 000000000..e8951eb75 --- /dev/null +++ b/examples/models/resources/shaders/glsl100/voxel_lighting.vs @@ -0,0 +1,28 @@ +#ifdef GL_ES +precision mediump float; +#endif + +// Input vertex attributes +attribute vec3 vertexPosition; +attribute vec3 vertexNormal; +attribute vec4 vertexColor; +// attribute vec2 vertexTexCoord; + +// Input uniform values +uniform mat4 mvp; +uniform mat4 matModel; +uniform mat4 matNormal; + +// Output to fragment shader +varying vec3 fragPosition; +varying vec4 fragColor; +varying vec3 fragNormal; + +void main() +{ + fragPosition = vec3(matModel * vec4(vertexPosition, 1.0)); + fragColor = vertexColor; + fragNormal = normalize(vec3(matNormal * vec4(vertexNormal, 1.0))); + + gl_Position = mvp * vec4(vertexPosition, 1.0); +} diff --git a/examples/models/resources/shaders/glsl120/voxel_lighting.fs b/examples/models/resources/shaders/glsl120/voxel_lighting.fs new file mode 100644 index 000000000..dab171950 --- /dev/null +++ b/examples/models/resources/shaders/glsl120/voxel_lighting.fs @@ -0,0 +1,61 @@ +// Input from vertex shader +varying vec3 fragPosition; +varying vec4 fragColor; +varying vec3 fragNormal; + +// Uniforms +uniform vec4 colDiffuse; +uniform vec4 ambient; +uniform vec3 viewPos; + +#define MAX_LIGHTS 4 +#define LIGHT_DIRECTIONAL 0 +#define LIGHT_POINT 1 + +struct Light { + int enabled; + int type; + vec3 position; + vec3 target; + vec4 color; +}; + +uniform Light lights[MAX_LIGHTS]; + +void main() +{ + vec3 lightDot = vec3(0.0); + vec3 normal = normalize(fragNormal); + vec3 viewD = normalize(viewPos - fragPosition); + vec3 specular = vec3(0.0); + + for (int i = 0; i < MAX_LIGHTS; i++) + { + if (lights[i].enabled == 1) + { + vec3 light = vec3(0.0); + + if (lights[i].type == LIGHT_DIRECTIONAL) + light = -normalize(lights[i].target - lights[i].position); + + if (lights[i].type == LIGHT_POINT) + light = normalize(lights[i].position - fragPosition); + + float NdotL = max(dot(normal, light), 0.0); + lightDot += lights[i].color.rgb * NdotL; + + if (NdotL > 0.0) + { + float specCo = pow(max(0.0, dot(viewD, reflect(-light, normal))), 16.0); + specular += specCo; + } + } + } + + vec4 finalColor = (fragColor * ((colDiffuse + vec4(specular, 1.0)) * vec4(lightDot, 1.0))); + finalColor += fragColor * (ambient / 10.0) * colDiffuse; + + finalColor = pow(finalColor, vec4(1.0/2.2)); // gamma correction + + gl_FragColor = finalColor; +} diff --git a/examples/models/resources/shaders/glsl120/voxel_lighting.vs b/examples/models/resources/shaders/glsl120/voxel_lighting.vs new file mode 100644 index 000000000..2a5930fd9 --- /dev/null +++ b/examples/models/resources/shaders/glsl120/voxel_lighting.vs @@ -0,0 +1,23 @@ +// Input vertex attributes +attribute vec3 vertexPosition; +attribute vec3 vertexNormal; +attribute vec4 vertexColor; + +// Uniforms +uniform mat4 mvp; +uniform mat4 matModel; +uniform mat4 matNormal; + +// Output to fragment shader +varying vec3 fragPosition; +varying vec4 fragColor; +varying vec3 fragNormal; + +void main() +{ + fragPosition = vec3(matModel * vec4(vertexPosition, 1.0)); + fragColor = vertexColor; + fragNormal = normalize(vec3(matNormal * vec4(vertexNormal, 1.0))); + + gl_Position = mvp * vec4(vertexPosition, 1.0); +} From df200b942c2a9fa3f33583f2d42c4291cde3f740 Mon Sep 17 00:00:00 2001 From: Johnny Cena Date: Wed, 20 Aug 2025 12:16:57 +0200 Subject: [PATCH 8/9] add versions to new shaders --- examples/models/resources/shaders/glsl100/voxel_lighting.fs | 1 + examples/models/resources/shaders/glsl100/voxel_lighting.vs | 1 + examples/models/resources/shaders/glsl120/voxel_lighting.fs | 1 + examples/models/resources/shaders/glsl120/voxel_lighting.vs | 1 + 4 files changed, 4 insertions(+) diff --git a/examples/models/resources/shaders/glsl100/voxel_lighting.fs b/examples/models/resources/shaders/glsl100/voxel_lighting.fs index ba02ad21e..b9a57cfc9 100644 --- a/examples/models/resources/shaders/glsl100/voxel_lighting.fs +++ b/examples/models/resources/shaders/glsl100/voxel_lighting.fs @@ -1,3 +1,4 @@ +#version 100 #ifdef GL_ES precision mediump float; #endif diff --git a/examples/models/resources/shaders/glsl100/voxel_lighting.vs b/examples/models/resources/shaders/glsl100/voxel_lighting.vs index e8951eb75..165365528 100644 --- a/examples/models/resources/shaders/glsl100/voxel_lighting.vs +++ b/examples/models/resources/shaders/glsl100/voxel_lighting.vs @@ -1,3 +1,4 @@ +#version 100 #ifdef GL_ES precision mediump float; #endif diff --git a/examples/models/resources/shaders/glsl120/voxel_lighting.fs b/examples/models/resources/shaders/glsl120/voxel_lighting.fs index dab171950..eb01f96bb 100644 --- a/examples/models/resources/shaders/glsl120/voxel_lighting.fs +++ b/examples/models/resources/shaders/glsl120/voxel_lighting.fs @@ -1,3 +1,4 @@ +#version 120 // Input from vertex shader varying vec3 fragPosition; varying vec4 fragColor; diff --git a/examples/models/resources/shaders/glsl120/voxel_lighting.vs b/examples/models/resources/shaders/glsl120/voxel_lighting.vs index 2a5930fd9..75163c7f8 100644 --- a/examples/models/resources/shaders/glsl120/voxel_lighting.vs +++ b/examples/models/resources/shaders/glsl120/voxel_lighting.vs @@ -1,3 +1,4 @@ +#version 120 // Input vertex attributes attribute vec3 vertexPosition; attribute vec3 vertexNormal; From a99649b455a9fb05c825776cf02a75302fbe4dac Mon Sep 17 00:00:00 2001 From: Johnny Cena Date: Wed, 20 Aug 2025 12:18:51 +0200 Subject: [PATCH 9/9] remove unneeded checks --- examples/models/resources/shaders/glsl100/voxel_lighting.fs | 3 +-- examples/models/resources/shaders/glsl100/voxel_lighting.vs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/models/resources/shaders/glsl100/voxel_lighting.fs b/examples/models/resources/shaders/glsl100/voxel_lighting.fs index b9a57cfc9..f23d9292d 100644 --- a/examples/models/resources/shaders/glsl100/voxel_lighting.fs +++ b/examples/models/resources/shaders/glsl100/voxel_lighting.fs @@ -1,7 +1,6 @@ #version 100 -#ifdef GL_ES + precision mediump float; -#endif // Input from vertex shader varying vec3 fragPosition; diff --git a/examples/models/resources/shaders/glsl100/voxel_lighting.vs b/examples/models/resources/shaders/glsl100/voxel_lighting.vs index 165365528..12f53ed32 100644 --- a/examples/models/resources/shaders/glsl100/voxel_lighting.vs +++ b/examples/models/resources/shaders/glsl100/voxel_lighting.vs @@ -1,7 +1,6 @@ #version 100 -#ifdef GL_ES + precision mediump float; -#endif // Input vertex attributes attribute vec3 vertexPosition;