├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── binding_generator ├── generic-binding-generator.lua ├── lpeg-raylib-parser.lua ├── modified-raylib.h ├── modified-raymath.h └── raylib-binding-generator.lua ├── examples ├── audio │ └── resources │ │ ├── chiptun1.mod │ │ ├── coin.wav │ │ ├── guitar_noodling.ogg │ │ ├── mini1111.xm │ │ ├── sound.wav │ │ ├── spring.wav │ │ ├── tanatana.flac │ │ ├── tanatana.ogg │ │ └── weird.wav ├── core │ ├── 2d-camera-platformer.nelua │ ├── 2d-camera.nelua │ ├── 3d-camera-first-person.nelua │ ├── 3d-camera-free.nelua │ ├── 3d-camera-mode.nelua │ ├── 3d-picking.nelua │ ├── basic-window.nelua │ ├── drop-files.nelua │ ├── input-gamepad.nelua │ ├── input-keys.nelua │ ├── input-mouse.nelua │ ├── input-mouse_wheel.nelua │ ├── loading-thread.nelua │ ├── random-values.nelua │ ├── resources │ │ ├── distortion100.fs │ │ ├── distortion330.fs │ │ ├── ps3.png │ │ └── xbox.png │ ├── scissor-text.nelua │ ├── storage-values.nelua │ ├── vr-simulator.nelua │ ├── window-letterbox.nelua │ └── world-screen.nelua ├── models │ └── resources │ │ ├── angle_gauge.png │ │ ├── background.png │ │ ├── billboard.png │ │ ├── cubicmap.png │ │ ├── cubicmap_atlas.png │ │ ├── dresden_square.hdr │ │ ├── guy │ │ ├── guy.blend │ │ ├── guy.iqm │ │ ├── guyanim.iqm │ │ └── guytex.png │ │ ├── heightmap.png │ │ ├── models │ │ ├── Duck │ │ │ ├── Duck.glb │ │ │ ├── Duck.gltf │ │ │ ├── Duck0.bin │ │ │ ├── DuckCM.png │ │ │ └── Duck_license.txt │ │ ├── LICENSE │ │ ├── bridge.obj │ │ ├── bridge_diffuse.png │ │ ├── castle.obj │ │ ├── castle_diffuse.png │ │ ├── cube.obj │ │ ├── cube_diffuse.png │ │ ├── house.obj │ │ ├── house_diffuse.png │ │ ├── market.obj │ │ ├── market_diffuse.png │ │ ├── turret.obj │ │ ├── turret_diffuse.png │ │ ├── well.obj │ │ └── well_diffuse.png │ │ ├── pbr │ │ ├── trooper.obj │ │ ├── trooper_albedo.png │ │ ├── trooper_ao.png │ │ ├── trooper_metalness.png │ │ ├── trooper_normals.png │ │ └── trooper_roughness.png │ │ ├── pitch.png │ │ ├── plane.obj │ │ ├── plane.png │ │ ├── plane_diffuse.png │ │ └── shaders │ │ ├── glsl100 │ │ ├── cubemap.fs │ │ ├── cubemap.vs │ │ ├── skybox.fs │ │ └── skybox.vs │ │ └── glsl330 │ │ ├── brdf.fs │ │ ├── brdf.vs │ │ ├── cubemap.fs │ │ ├── cubemap.vs │ │ ├── irradiance.fs │ │ ├── pbr.fs │ │ ├── pbr.vs │ │ ├── prefilter.fs │ │ ├── skybox.fs │ │ └── skybox.vs ├── others │ └── resources │ │ └── audio │ │ ├── guitar_noodling.ogg │ │ ├── tanatana.ogg │ │ └── weird.wav ├── shaders │ └── resources │ │ ├── fudesumi.png │ │ ├── mask.png │ │ ├── models │ │ ├── barracks.obj │ │ ├── barracks_diffuse.png │ │ ├── church.obj │ │ ├── church_diffuse.png │ │ ├── watermill.obj │ │ └── watermill_diffuse.png │ │ ├── plasma.png │ │ ├── raysan.png │ │ ├── shaders │ │ ├── glsl100 │ │ │ ├── base.fs │ │ │ ├── base.vs │ │ │ ├── base_lighting.vs │ │ │ ├── bloom.fs │ │ │ ├── blur.fs │ │ │ ├── cross_hatching.fs │ │ │ ├── cross_stitching.fs │ │ │ ├── cubes_panning.fs │ │ │ ├── depth.fs │ │ │ ├── distortion.fs │ │ │ ├── dream_vision.fs │ │ │ ├── eratosthenes.fs │ │ │ ├── fisheye.fs │ │ │ ├── fog.fs │ │ │ ├── grayscale.fs │ │ │ ├── julia_set.fs │ │ │ ├── lighting.fs │ │ │ ├── mask.fs │ │ │ ├── palette_switch.fs │ │ │ ├── pixelizer.fs │ │ │ ├── posterization.fs │ │ │ ├── predator.fs │ │ │ ├── raymarching.fs │ │ │ ├── scanlines.fs │ │ │ ├── sobel.fs │ │ │ ├── spotlight.fs │ │ │ ├── swirl.fs │ │ │ └── wave.fs │ │ ├── glsl120 │ │ │ ├── base.fs │ │ │ ├── base.vs │ │ │ ├── base_lighting.vs │ │ │ ├── bloom.fs │ │ │ ├── blur.fs │ │ │ ├── cross_hatching.fs │ │ │ ├── cross_stitching.fs │ │ │ ├── distortion.fs │ │ │ ├── dream_vision.fs │ │ │ ├── fisheye.fs │ │ │ ├── fog.fs │ │ │ ├── grayscale.fs │ │ │ ├── palette_switch.fs │ │ │ ├── pixelizer.fs │ │ │ ├── posterization.fs │ │ │ ├── predator.fs │ │ │ ├── scanlines.fs │ │ │ ├── sobel.fs │ │ │ └── swirl.fs │ │ └── glsl330 │ │ │ ├── base.fs │ │ │ ├── base.vs │ │ │ ├── base_lighting.vs │ │ │ ├── bloom.fs │ │ │ ├── blur.fs │ │ │ ├── cross_hatching.fs │ │ │ ├── cross_stitching.fs │ │ │ ├── cubes_panning.fs │ │ │ ├── depth.fs │ │ │ ├── distortion.fs │ │ │ ├── dream_vision.fs │ │ │ ├── eratosthenes.fs │ │ │ ├── fisheye.fs │ │ │ ├── fog.fs │ │ │ ├── grayscale.fs │ │ │ ├── julia_set.fs │ │ │ ├── lighting.fs │ │ │ ├── mask.fs │ │ │ ├── overdraw.fs │ │ │ ├── palette_switch.fs │ │ │ ├── pixelizer.fs │ │ │ ├── posterization.fs │ │ │ ├── predator.fs │ │ │ ├── raymarching.fs │ │ │ ├── scanlines.fs │ │ │ ├── sobel.fs │ │ │ ├── spotlight.fs │ │ │ ├── swirl.fs │ │ │ └── wave.fs │ │ ├── space.png │ │ └── texel_checker.png ├── shapes │ └── logo-raylib-nelua.nelua ├── test_all_examples.nelua ├── text │ ├── raylib-fonts.nelua │ └── resources │ │ ├── AnonymousPro-Bold.ttf │ │ ├── KAISG.ttf │ │ ├── LICENSE │ │ ├── bmfont.fnt │ │ ├── bmfont.png │ │ ├── custom_alagard.png │ │ ├── custom_jupiter_crash.png │ │ ├── custom_mecha.png │ │ ├── dejavu.fnt │ │ ├── dejavu.png │ │ ├── emoji.fnt │ │ ├── emoji.png │ │ ├── fonts │ │ ├── alagard.png │ │ ├── alpha_beta.png │ │ ├── jupiter_crash.png │ │ ├── mecha.png │ │ ├── pixantiqua.png │ │ ├── pixelplay.png │ │ ├── romulus.png │ │ └── setback.png │ │ ├── notoCJK.fnt │ │ ├── notoCJK.png │ │ ├── pixantiqua.fnt │ │ ├── pixantiqua.png │ │ ├── pixantiqua.ttf │ │ └── shaders │ │ ├── glsl100 │ │ └── sdf.fs │ │ └── glsl330 │ │ └── sdf.fs └── textures │ └── resources │ ├── KAISG.ttf │ ├── LICENSE │ ├── boom.wav │ ├── button.png │ ├── buttonfx.wav │ ├── cat.png │ ├── custom_jupiter_crash.png │ ├── cyberpunk_street_background.png │ ├── cyberpunk_street_foreground.png │ ├── cyberpunk_street_midground.png │ ├── explosion.png │ ├── fudesumi.png │ ├── fudesumi.raw │ ├── ninepatch_button.png │ ├── parrots.png │ ├── raylib_logo.png │ ├── scarfy.png │ ├── smoke.png │ └── wabbit_alpha.png ├── raylib-nelualogo.svg └── raylib.nelua /.gitattributes: -------------------------------------------------------------------------------- 1 | *.nelua text linguist-language=lua 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | nelua_cache/* 2 | old_raylib-git/* 3 | raylib-3.0.0/* 4 | *.c 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UNMAINTAINED 2 | 3 | This library it's really important to me, however I've been focusing on [my own game framework](https://github.com/Andre-LA/nene/) and thus this library got unmaintained. 4 | 5 | If you need bindings of raylib for Nelua, you should check out Kenta's one, it's updated and covers more of raylib stack: 6 | https://github.com/Its-Kenta/Raylib.nelua 7 | 8 | # raylib-nelua 9 | 10 | ![raylib-nelua-logo](raylib-nelualogo.svg) 11 | 12 | This is a [Raylib][raylib-website] binding for [Nelua language][nelua-website]. 13 | 14 | ## How to use 15 | 16 | First, [install Nelua language][nelua-install] and [Raylib library][raylib-install]. 17 | 18 | Then, you can use `raylib.nelua`, you can use it as a project file or as a external library: 19 | 20 | ### As project file 21 | Just move `raylib.nelua` file to your project. 22 | 23 | ### As external library 24 | Clone or download this repository somewhere and then either: 25 | * use the `-L` option, for example: `nelua -L ~/path/to/nelua-raylib my-game.nelua` 26 | * use a `neluacfg.lua` script on the project's root directory or on your `$HOME/.config/nelua` with the content `return { add_path = {'/path/to/nelua-raylib'} }` 27 | [(See about this here)][nelua-L-option] 28 | 29 | ## Quick Raylib-nelua specific changes: 30 | This binding contains some extra features to better integrate with `nelua` language: 31 | 32 | * unbounded arrays are specified on arguments and return types; for example, `Raylib.GetWaveData` returns a `*[0]float32` instead of just `*float32` 33 | * for every record an `is_*` field is defined on the type information; for example, `## rAudioBuffer.value.is_raudiobuffer` is `true`; 34 | * several functions are also applied to records, for example, `function Camera.UpdateCamera(camera: *Camera)` is defined, which can be used as a method `camera:UpdateCamera()`; 35 | * operator overloading functions for `raymath.h`functions defined: 36 | * `Vector2`: 37 | * `__add`: calls `Vector2Add` 38 | * `__sub`: calls `Vector2Subtract` 39 | * `__len`: calls `Vector2Length` 40 | * `__unm`: calls `Vector2Negate` 41 | * `__div`: calls `Vector2Divide` or `Vector2DivideV` 42 | * `__mul`: calls `Vector2Scale` or `Vector2MultiplyV` 43 | * `Vector3`: 44 | * `__add`: calls `Vector3Add` 45 | * `__sub`: calls `Vector3Subtract` 46 | * `__len`: calls `Vector3Length` 47 | * `__unm`: calls `Vector3Negate` 48 | * `__mul`: calls `Vector3Scale` or `Vector3Multiply` 49 | * `__div`: calls `Vector3Divide` or `Vector3DivideV` 50 | * `Matrix`: 51 | * `__add`: calls `MatrixAdd` 52 | * `__sub`: calls `MatrixSubtract` 53 | * `__mul`: calls `MatrixMultiply` 54 | * `Quaternion`: 55 | * `__len`: calls `QuaternionLength` 56 | * `__mul`: calls `QuaternionMultiply` 57 | 58 | **NOTE: TraceLogCallback and SetTraceLogCallback aren't imported** 59 | 60 | ## Example 61 | 62 | ```Lua 63 | require 'raylib' 64 | 65 | -- [[ Initialization [[ 66 | local screen_width: integer = 800 67 | local screen_height: integer = 450 68 | Raylib.InitWindow(screen_width, screen_height, "raylib-nelua [core] example - keyboard input") 69 | 70 | local ball_position: Vector2 = { screen_width / 2, screen_height / 2} 71 | 72 | Raylib.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 73 | -- ]] Initialization ]] 74 | 75 | -- [[ Main game loop [[ 76 | while not Raylib.WindowShouldClose() do -- Detect window close button or ESC key 77 | -- [[ Update [[ 78 | if Raylib.IsKeyDown(KeyboardKey.KEY_RIGHT) then 79 | ball_position.x = ball_position.x + 2 80 | end 81 | if Raylib.IsKeyDown(KeyboardKey.KEY_LEFT) then 82 | ball_position.x = ball_position.x - 2 83 | end 84 | if Raylib.IsKeyDown(KeyboardKey.KEY_UP) then 85 | ball_position.y = ball_position.y - 2 86 | end 87 | if Raylib.IsKeyDown(KeyboardKey.KEY_DOWN) then 88 | ball_position.y = ball_position.y + 2 89 | end 90 | -- ]] Update ]] 91 | 92 | -- [[ Draw [[ 93 | Raylib.BeginDrawing() 94 | Raylib.ClearBackground(RAYWHITE) 95 | Raylib.DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY) 96 | Raylib.DrawCircleV(ball_position, 50, MAROON) 97 | Raylib.EndDrawing() 98 | -- ]] Draw ]] 99 | end 100 | 101 | -- [[ De-Initialization [[ 102 | Raylib.CloseWindow() -- Close window and OpenGL context 103 | -- ]] De-Initialization ]] 104 | ``` 105 | 106 | [raylib-website]: https://www.raylib.com/ 107 | [raylib-install]: https://github.com/raysan5/raylib#build-and-installation 108 | [nelua-website]: https://nelua.io/ 109 | [nelua-install]: https://nelua.io/installing/ 110 | [nelua-L-option]: https://github.com/edubart/nelua-lang/commit/9683c40d2d99e119990ea19666be0f22fa7f9303 111 | -------------------------------------------------------------------------------- /examples/audio/resources/chiptun1.mod: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/audio/resources/chiptun1.mod -------------------------------------------------------------------------------- /examples/audio/resources/coin.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/audio/resources/coin.wav -------------------------------------------------------------------------------- /examples/audio/resources/guitar_noodling.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/audio/resources/guitar_noodling.ogg -------------------------------------------------------------------------------- /examples/audio/resources/mini1111.xm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/audio/resources/mini1111.xm -------------------------------------------------------------------------------- /examples/audio/resources/sound.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/audio/resources/sound.wav -------------------------------------------------------------------------------- /examples/audio/resources/spring.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/audio/resources/spring.wav -------------------------------------------------------------------------------- /examples/audio/resources/tanatana.flac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/audio/resources/tanatana.flac -------------------------------------------------------------------------------- /examples/audio/resources/tanatana.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/audio/resources/tanatana.ogg -------------------------------------------------------------------------------- /examples/audio/resources/weird.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/audio/resources/weird.wav -------------------------------------------------------------------------------- /examples/core/2d-camera.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "2d camera" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_2d_camera.c 7 | 8 | -- Note: unfortunately my controller doens't worked on my SO, so, I can't really test this 9 | 10 | require 'raylib' 11 | 12 | local MAX_BUILDINGS: integer = 100 13 | 14 | -- [[ Initialization [[ 15 | local screen_width: integer = 800 16 | local screen_height: integer = 450 17 | 18 | Raylib.InitWindow(screen_width, screen_height, "raylib-nelua [core] example - 2d camera") 19 | 20 | local player: Rectangle = { 400, 280, 40, 40 } 21 | local buildings: [MAX_BUILDINGS]Rectangle; 22 | local build_colors: [MAX_BUILDINGS]Color; 23 | 24 | local spacing: integer = 0 25 | 26 | for i: integer = 0, < MAX_BUILDINGS do 27 | buildings[i].width = Raylib.GetRandomValue(50, 200) 28 | buildings[i].height = Raylib.GetRandomValue(100, 800) 29 | buildings[i].y = screen_height - 130 - buildings[i].height 30 | buildings[i].x = -6000 + spacing 31 | 32 | spacing = spacing + buildings[i].width 33 | 34 | build_colors[i] = { Raylib.GetRandomValue(200, 240), Raylib.GetRandomValue(200, 240), Raylib.GetRandomValue(200, 250), 255 } 35 | end 36 | 37 | local camera: Camera2D = { 38 | target = { player.x + 20, player.y + 20 }, 39 | offset = { screen_width / 2, screen_height / 2 }, 40 | rotation = 0, 41 | zoom = 1 42 | } 43 | 44 | Raylib.SetTargetFPS(60); -- Set our game to run at 60 frames-per-second 45 | -- ]] Initialization ]] 46 | 47 | -- [[ Main game loop [[ 48 | while not Raylib.WindowShouldClose() do -- Detect window close button or ESC key 49 | -- [[ Update [[ 50 | -- Player movement 51 | if Raylib.IsKeyDown(KeyboardKey.KEY_RIGHT) then 52 | player.x = player.x + 2 53 | elseif Raylib.IsKeyDown(KeyboardKey.KEY_LEFT) then 54 | player.x = player.x - 2 55 | end 56 | 57 | -- Camera target follows player 58 | camera.target = { player.x + 20, player.y + 20 } 59 | 60 | -- Camera rotation controls 61 | if Raylib.IsKeyDown(KeyboardKey.KEY_A) then 62 | camera.rotation = camera.rotation - 1 63 | elseif Raylib.IsKeyDown(KeyboardKey.KEY_S) then 64 | camera.rotation = camera.rotation + 1 65 | end 66 | 67 | -- Limit camera rotation to 80 degrees (-40 to 40) 68 | if camera.rotation > 40 then 69 | camera.rotation = 40 70 | elseif camera.rotation < -40 then 71 | camera.rotation = -40 72 | end 73 | 74 | -- Camera zoom controls 75 | camera.zoom = camera.zoom + (@number)(Raylib.GetMouseWheelMove() * 0.05) 76 | 77 | if camera.zoom > 3 then 78 | camera.zoom = 3 79 | elseif camera.zoom < 0.1 then 80 | camera.zoom = 0.1 81 | end 82 | 83 | -- Camera reset (zoom and rotation) 84 | if Raylib.IsKeyPressed(KeyboardKey.KEY_R) then 85 | camera.zoom = 1 86 | camera.rotation = 0 87 | end 88 | -- ]] Update ]] 89 | 90 | -- [[ Draw [[ 91 | Raylib.BeginDrawing() 92 | do 93 | Raylib.ClearBackground(RAYWHITE) 94 | 95 | Raylib.BeginMode2D(camera) 96 | do 97 | Raylib.DrawRectangle(-6000, 320, 13000, 8000, DARKGRAY) 98 | 99 | for i: integer = 0, < MAX_BUILDINGS do 100 | Raylib.DrawRectangleRec(buildings[i], build_colors[i]) 101 | end 102 | 103 | Raylib.DrawRectangleRec(player, RED) 104 | 105 | Raylib.DrawLine(camera.target.x, -screen_height * 10, camera.target.x, screen_height * 10, GREEN) 106 | Raylib.DrawLine(-screen_width * 10, camera.target.y, screen_width * 10, camera.target.y, GREEN) 107 | end 108 | Raylib.EndMode2D() 109 | 110 | Raylib.DrawText("SCREEN AREA", 640, 10, 20, RED) 111 | 112 | Raylib.DrawRectangle(0, 0, screen_width, 5, RED) 113 | Raylib.DrawRectangle(0, 5, 5, screen_height - 10, RED) 114 | Raylib.DrawRectangle(screen_width - 5, 5, 5, screen_height - 10, RED) 115 | Raylib.DrawRectangle(0, screen_height - 5, screen_width, 5, RED) 116 | 117 | Raylib.DrawRectangle( 10, 10, 250, 113, Raylib.Fade(SKYBLUE, 0.5)) 118 | Raylib.DrawRectangleLines( 10, 10, 250, 113, BLUE) 119 | 120 | Raylib.DrawText("Free 2d camera controls:", 20, 20, 10, BLACK) 121 | Raylib.DrawText("- Right/Left to move Offset", 40, 40, 10, DARKGRAY) 122 | Raylib.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, DARKGRAY) 123 | Raylib.DrawText("- A / S to Rotate", 40, 80, 10, DARKGRAY) 124 | Raylib.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, DARKGRAY) 125 | end 126 | Raylib.EndDrawing() 127 | -- ]] Draw ]] 128 | end 129 | -- ]] Main game loop ]] 130 | 131 | -- [ De-Initialization [ 132 | Raylib.CloseWindow() -- Close window and OpenGL context 133 | -- ] De-Initialization ] 134 | -------------------------------------------------------------------------------- /examples/core/3d-camera-first-person.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "3d camera first person" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_camera_first_person.c 7 | 8 | require 'raylib' 9 | 10 | local MAX_COLUMNS: integer = 20 11 | 12 | -- [[ Initialization [[ 13 | local screen_width: integer = 800 14 | local screen_height: integer = 450 15 | 16 | Raylib.InitWindow(screen_width, screen_height, "raylib-nelua [core] example - 3d camera first person") 17 | 18 | -- Define the camera to look into our 3d world (position, target, up vector) 19 | local camera: Camera = { 20 | position = {4, 2, 4}, 21 | target = {0, 1, 0}, 22 | up = {0, 1, 0}, 23 | fovy = 60, 24 | type = CameraType.CAMERA_PERSPECTIVE 25 | } 26 | 27 | -- Generates some random columns 28 | local heights: [MAX_COLUMNS]number; 29 | local positions: [MAX_COLUMNS]Vector3; 30 | local colors: [MAX_COLUMNS]Color; 31 | 32 | for i: integer = 0, < MAX_COLUMNS do 33 | heights[i] = (@number)(Raylib.GetRandomValue(1, 12)) 34 | positions[i] = { Raylib.GetRandomValue(-15, 15), heights[i] / 2, Raylib.GetRandomValue(-15, 15) } 35 | colors[i] = { Raylib.GetRandomValue(20, 255), Raylib.GetRandomValue(10, 55), 30, 255 } 36 | end 37 | 38 | Raylib.SetCameraMode(camera, CameraMode.CAMERA_FIRST_PERSON) -- Set a first person camera mode 39 | 40 | Raylib.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 41 | -- ]] Initialization ]] 42 | 43 | -- [[ Main game loop [[ 44 | while not Raylib.WindowShouldClose() do -- Detect window close button or ESC key 45 | -- [[ Update [[ 46 | camera:Update() -- Update camera 47 | -- ]] Update ]] 48 | 49 | -- [[ Draw [[ 50 | Raylib.BeginDrawing() 51 | do 52 | Raylib.ClearBackground(RAYWHITE) 53 | 54 | Raylib.BeginMode3D(camera) 55 | do 56 | Raylib.DrawPlane({ 0, 0.0, 0}, {32, 32}, LIGHTGRAY) -- Draw ground 57 | Raylib.DrawCube({-16, 2.5, 0}, 1, 5, 32, BLUE) -- Draw a blue wall 58 | Raylib.DrawCube({ 16, 2.5, 0}, 1, 5, 32, LIME) -- Draw a green wall 59 | Raylib.DrawCube({ 0, 2.5, 16}, 32, 5, 1, GOLD) -- Draw a yellow wall 60 | 61 | -- Draw some cubes around 62 | for i: integer = 0, < MAX_COLUMNS do 63 | Raylib.DrawCube(positions[i], 2, heights[i], 2, colors[i]) 64 | Raylib.DrawCubeWires(positions[i], 2, heights[i], 2, MAROON) 65 | end 66 | end 67 | Raylib.EndMode3D() 68 | 69 | Raylib.DrawRectangle( 10, 10, 220, 70, Raylib.Fade(SKYBLUE, 0.5)) 70 | Raylib.DrawRectangleLines( 10, 10, 220, 70, BLUE) 71 | 72 | Raylib.DrawText("First person camera default controls:", 20, 20, 10, BLACK) 73 | Raylib.DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY) 74 | Raylib.DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY) 75 | end 76 | Raylib.EndDrawing() 77 | -- ]] Draw ]] 78 | end 79 | -- ]] Main game loop ]] 80 | 81 | -- [[ De-Initialization [[ 82 | Raylib.CloseWindow() -- Close window and OpenGL context 83 | -- ]] De-Initialization ]] 84 | -------------------------------------------------------------------------------- /examples/core/3d-camera-free.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "3d camera free" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_camera_free.c 7 | 8 | require 'raylib' 9 | 10 | -- [[ Initialization [[ 11 | local screen_width: integer = 800 12 | local screen_height: integer = 450 13 | 14 | Raylib.InitWindow(screen_width, screen_height, "raylib-nelua [core] example - 3d camera free") 15 | 16 | -- Define the camera to look into uor 3d world 17 | local camera: Camera3D = { 18 | position = {10, 10, 10}, -- Camera position 19 | target = { 0, 0, 0}, -- Camera looking at point 20 | up = { 0, 1, 0}, -- Camera up vector (rotation towards target) 21 | fovy = 45, -- Camera field-of-view 22 | type = CameraType.CAMERA_PERSPECTIVE -- Camera mode type 23 | } 24 | 25 | local cube_position: Vector3 = {0, 0, 0} 26 | 27 | Raylib.SetCameraMode(camera, CameraMode.CAMERA_FREE) -- Set a free camera mode 28 | 29 | Raylib.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 30 | -- ]] Initialization ]] 31 | 32 | -- [[ Main game loop [[ 33 | while not Raylib.WindowShouldClose() do -- Detect window close button or ESC key 34 | -- [[ Update [[ 35 | camera:Update() -- Update camera 36 | 37 | if Raylib.IsKeyDown(KeyboardKey.KEY_Z) then 38 | camera.target = {0, 0, 0} 39 | end 40 | -- ]] Update ]] 41 | 42 | -- [[ Draw [[ 43 | Raylib.BeginDrawing() 44 | do 45 | Raylib.ClearBackground(RAYWHITE) 46 | 47 | Raylib.BeginMode3D(camera) 48 | do 49 | Raylib.DrawCube(cube_position, 2, 2, 2, RED) 50 | Raylib.DrawCubeWires(cube_position, 2, 2, 2, MAROON) 51 | 52 | Raylib.DrawGrid(10, 1) 53 | end 54 | Raylib.EndMode3D() 55 | 56 | Raylib.DrawRectangle(10, 10, 320, 133, Raylib.Fade(SKYBLUE, 0.5)) 57 | Raylib.DrawRectangleLines(10, 10, 320, 133, BLUE) 58 | 59 | Raylib.DrawText("Free camera default controls:", 20, 20, 10, BLACK) 60 | Raylib.DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY) 61 | Raylib.DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY) 62 | Raylib.DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY) 63 | Raylib.DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY) 64 | Raylib.DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY) 65 | end 66 | Raylib.EndDrawing() 67 | -- ]] Draw ]] 68 | end 69 | -- ]] Main game loop ]] 70 | 71 | -- [[ De-Initialization [[ 72 | Raylib.CloseWindow() -- Close window and OpenGL context 73 | -- ]] De-Initialization ]] 74 | -------------------------------------------------------------------------------- /examples/core/3d-camera-mode.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "3d camera mode" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_camera_mode.c 7 | 8 | require 'raylib' 9 | 10 | -- [[ Initialization [[ 11 | local screen_width: integer = 800 12 | local screen_height: integer = 450 13 | 14 | Raylib.InitWindow(screen_width, screen_height, "raylib-nelua [core] example - 3d camera mode") 15 | 16 | -- Define a camera to look into our 3d world 17 | local camera: Camera3D = { 18 | position = {0, 10, 10}, 19 | target = {0, 0, 0}, 20 | up = {0, 1, 0}, 21 | fovy = 45, 22 | type = CameraType.CAMERA_PERSPECTIVE 23 | } 24 | 25 | local cube_position: Vector3 = {0, 0, 0} 26 | 27 | Raylib.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 28 | -- ]] Initialization ]] 29 | 30 | -- [[ Main game loop [[ 31 | while not Raylib.WindowShouldClose() do -- Detect window close button or ESC key 32 | -- [[ Update [[ 33 | --TODO: Update your variables here 34 | -- ]] Update ]] 35 | 36 | -- [[ Draw [[ 37 | Raylib.BeginDrawing() 38 | do 39 | Raylib.ClearBackground(RAYWHITE) 40 | 41 | Raylib.BeginMode3D(camera) 42 | do 43 | Raylib.DrawCube(cube_position, 2.0, 2.0, 2.0, RED) 44 | Raylib.DrawCubeWires(cube_position, 2.0, 2.0, 2.0, MAROON) 45 | 46 | Raylib.DrawGrid(10, 1.0) 47 | end 48 | Raylib.EndMode3D() 49 | 50 | Raylib.DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY) 51 | 52 | Raylib.DrawFPS(10, 10) 53 | end 54 | Raylib.EndDrawing() 55 | -- ]] Draw ]] 56 | end 57 | 58 | -- [[ De-Initialization [[ 59 | Raylib.CloseWindow() 60 | -- ]] De-Initialization ]] 61 | -------------------------------------------------------------------------------- /examples/core/3d-picking.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "3d picking" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_picking.c 7 | 8 | require 'raylib' 9 | 10 | -- [[ Initialization [[ 11 | local screen_width: integer = 800 12 | local screen_height: integer = 450 13 | 14 | Raylib.InitWindow(screen_width, screen_height, "raylib [core] example - 3d picking") 15 | 16 | -- Define the camera to look into our 3d world 17 | local camera: Camera = { 18 | position = { 10.0, 10.0, 10.0 }, -- Camera position 19 | target = { 0.0, 0.0, 0.0 }, -- Camera looking at point 20 | up = { 0.0, 1.0, 0.0 }, -- Camera up vector (rotation towards target) 21 | fovy = 45.0, -- Camera field-of-view Y 22 | type = CameraType.CAMERA_PERSPECTIVE, -- Camera mode type 23 | } 24 | 25 | local cube_position: Vector3 = { 0.0, 1.0, 0.0 } 26 | local cube_size: Vector3 = { 2.0, 2.0, 2.0 } 27 | 28 | local ray: Ray = {} -- Picking line ray 29 | 30 | local collision = false; 31 | 32 | Raylib.SetCameraMode(camera, CameraMode.CAMERA_FREE) -- Set a free camera mode 33 | 34 | Raylib.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 35 | -- ]] Initialization ]] 36 | 37 | -- [[ Main game loop [[ 38 | while not Raylib.WindowShouldClose() do -- Detect window close button or ESC key 39 | -- [[ Update [[ 40 | camera:Update() -- Update camera 41 | 42 | if Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON) then 43 | if not collision then 44 | ray = Raylib.GetMouseRay(Raylib.GetMousePosition(), camera) 45 | 46 | -- Check collision between ray and box 47 | collision = Raylib.CheckCollisionRayBox( 48 | ray, 49 | { 50 | { cube_position.x - cube_size.x/2, cube_position.y - cube_size.y/2, cube_position.z - cube_size.z/2 }, 51 | { cube_position.x + cube_size.x/2, cube_position.y + cube_size.y/2, cube_position.z + cube_size.z/2 } 52 | } 53 | ) 54 | else 55 | collision = false 56 | end 57 | end 58 | -- ]] Update ]] 59 | 60 | -- [[ Draw [[ 61 | Raylib.BeginDrawing() 62 | do 63 | Raylib.ClearBackground(RAYWHITE) 64 | Raylib.BeginMode3D(camera) 65 | do 66 | if collision then 67 | Raylib.DrawCube(cube_position, cube_size.x, cube_size.y, cube_size.z, RED) 68 | Raylib.DrawCubeWires(cube_position, cube_size.x, cube_size.y, cube_size.z, MAROON) 69 | 70 | Raylib.DrawCubeWires(cube_position, cube_size.x + 0.2, cube_size.y + 0.2, cube_size.z + 0.2, GREEN) 71 | else 72 | Raylib.DrawCube(cube_position, cube_size.x, cube_size.y, cube_size.z, GRAY) 73 | Raylib.DrawCubeWires(cube_position, cube_size.x, cube_size.y, cube_size.z, DARKGRAY) 74 | end 75 | 76 | Raylib.DrawRay(ray, MAROON) 77 | Raylib.DrawGrid(10, 1.0) 78 | end 79 | Raylib.EndMode3D() 80 | 81 | Raylib.DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY) 82 | 83 | if collision then 84 | Raylib.DrawText("BOX SELECTED", (screen_width - Raylib.MeasureText("BOX SELECTED", 30)) // 2, (@cint)(screen_height * 0.1 // 1), 30, GREEN) 85 | end 86 | 87 | Raylib.DrawFPS(10, 10) 88 | end 89 | Raylib.EndDrawing() 90 | -- ]] Draw ]] 91 | end 92 | -- ]] Main game loop ]] 93 | 94 | -- [ De-Initialization [ 95 | Raylib.CloseWindow() -- Close window and OpenGL context 96 | -- ] De-Initialization ] 97 | -------------------------------------------------------------------------------- /examples/core/basic-window.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "basic window" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_basic_window.c 7 | 8 | require 'raylib' 9 | 10 | -- [[ Initialization [[ 11 | local screen_width: integer = 800 12 | local screen_height: integer = 450 13 | 14 | Raylib.InitWindow(screen_width, screen_height, "raylib-nelua [core] example - basic window") 15 | 16 | Raylib.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 17 | -- ]] Initialization ]] 18 | 19 | -- [[ Main game loop [[ 20 | while not Raylib.WindowShouldClose() do -- Detect window close button or ESC key 21 | -- [[ Update [[ 22 | -- TODO: Update your variables here 23 | -- ]] Update ]] 24 | 25 | -- [[ Draw [[ 26 | Raylib.BeginDrawing() 27 | do 28 | Raylib.ClearBackground(RAYWHITE) 29 | 30 | Raylib.DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY) 31 | end 32 | Raylib.EndDrawing() --] 33 | -- ]] Draw ]] 34 | end 35 | -- ]] Main game loop ]] 36 | 37 | -- [[ De-Initialization [[ 38 | Raylib.CloseWindow() -- Close window and OpenGL context 39 | -- ]] De-Initialization ]] 40 | -------------------------------------------------------------------------------- /examples/core/drop-files.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "Drop Files" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_drop_files.c 7 | 8 | require 'raylib' 9 | 10 | -- [[ Initialization [[ 11 | local screen_width = 800 12 | local screen_height = 450 13 | 14 | Raylib.InitWindow(screen_width, screen_height, "raylib-nelua [core] example - drop files") 15 | 16 | local count: cint = 0 17 | local dropped_files: *[0]cstring; 18 | 19 | -- Set our game to run at 60 frames-per-second 20 | Raylib.SetTargetFPS(60) 21 | -- ]] Initialization ]] 22 | 23 | -- [[ Main game loop [[ 24 | -- Detect window close button or ESC key 25 | while not Raylib.WindowShouldClose() do 26 | -- [[ Update [[ 27 | if Raylib.IsFileDropped() then 28 | dropped_files = Raylib.GetDroppedFiles(&count) 29 | end 30 | -- ]] Update ]] 31 | 32 | -- [[ Draw [[ 33 | Raylib.BeginDrawing() 34 | do 35 | Raylib.ClearBackground(RAYWHITE) 36 | 37 | if count == 0 then 38 | Raylib.DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY) 39 | else 40 | Raylib.DrawText("Dropped files:", 100, 40, 20, DARKGRAY) 41 | 42 | for i = 0, < count do 43 | if i % 2 == 0 then 44 | Raylib.DrawRectangle(0, 85 + 40 * i, screen_width, 40, Raylib.Fade(LIGHTGRAY, 0.5)) 45 | else 46 | Raylib.DrawRectangle(0, 85 + 40 * i, screen_width, 40, Raylib.Fade(LIGHTGRAY, 0.3)) 47 | end 48 | 49 | Raylib.DrawText(dropped_files[i], 120, 100 + 40 * i, 10, GRAY) 50 | end 51 | 52 | Raylib.DrawText("Drop new files...", 100, 110 + 40 * count, 20, DARKGRAY) 53 | end 54 | end 55 | Raylib.EndDrawing() 56 | -- ]] Draw ]] 57 | end 58 | -- ]] Main game loop ]] 59 | 60 | -- [[ De-Initialization [[ 61 | -- Clear internal buffers 62 | Raylib.ClearDroppedFiles() 63 | 64 | -- Close window and OpenGL context 65 | Raylib.CloseWindow() 66 | -- ]] De-Initialization ]] 67 | -------------------------------------------------------------------------------- /examples/core/input-keys.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "input keys" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_input_keys.c 7 | 8 | require 'raylib' 9 | 10 | -- [[ Initialization [[ 11 | local screen_width: integer = 800 12 | local screen_height: integer = 450 13 | 14 | Raylib.InitWindow(screen_width, screen_height, "raylib-nelua [core] example - keyboard input") 15 | 16 | local ball_position: Vector2 = { screen_width / 2, screen_height / 2} 17 | 18 | Raylib.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 19 | -- ]] Initialization ]] 20 | 21 | -- [[ Main game loop [[ 22 | while not Raylib.WindowShouldClose() do -- Detect window close button or ESC key 23 | -- [[ Update [[ 24 | if Raylib.IsKeyDown(KeyboardKey.KEY_RIGHT) then 25 | ball_position.x = ball_position.x + 2 26 | end 27 | if Raylib.IsKeyDown(KeyboardKey.KEY_LEFT) then 28 | ball_position.x = ball_position.x - 2 29 | end 30 | if Raylib.IsKeyDown(KeyboardKey.KEY_UP) then 31 | ball_position.y = ball_position.y - 2 32 | end 33 | if Raylib.IsKeyDown(KeyboardKey.KEY_DOWN) then 34 | ball_position.y = ball_position.y + 2 35 | end 36 | -- ]] Update ]] 37 | 38 | -- [[ Draw [[ 39 | Raylib.BeginDrawing() 40 | do 41 | Raylib.ClearBackground(RAYWHITE) 42 | 43 | Raylib.DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY) 44 | Raylib.DrawCircleV(ball_position, 50, MAROON) 45 | end 46 | Raylib.EndDrawing() 47 | -- ]] Draw ]] 48 | end 49 | 50 | -- [[ De-Initialization [[ 51 | Raylib.CloseWindow() -- Close window and OpenGL context 52 | -- ]] De-Initialization ]] 53 | -------------------------------------------------------------------------------- /examples/core/input-mouse.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "input mouse" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_input_mouse.c 7 | 8 | require 'raylib' 9 | 10 | -- [[ Initialization [[ 11 | local screen_width: integer = 800 12 | local screen_height: integer = 450 13 | 14 | Raylib.InitWindow(screen_width, screen_height, "raylib-nelua [core] example - mouse input") 15 | 16 | local ball_position: Vector2 = { -100, -100 } 17 | local ball_color = DARKBLUE 18 | 19 | Raylib.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 20 | -- ]] Initialization ]] 21 | 22 | -- [[ Main game loop [[ 23 | while not Raylib.WindowShouldClose() do -- Detect window close button or ESC key 24 | -- [[ Update [[ 25 | ball_position = Raylib.GetMousePosition() 26 | 27 | if Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON) then 28 | ball_color = MAROON 29 | elseif Raylib.IsMouseButtonPressed(MouseButton.MOUSE_MIDDLE_BUTTON) then 30 | ball_color = LIME 31 | elseif Raylib.IsMouseButtonPressed(MouseButton.MOUSE_RIGHT_BUTTON) then 32 | ball_color = DARKBLUE 33 | end 34 | -- ]] Update ]] 35 | 36 | -- [[ Draw [[ 37 | Raylib.BeginDrawing() 38 | do 39 | Raylib.ClearBackground(RAYWHITE) 40 | 41 | Raylib.DrawCircleV(ball_position, 40, ball_color) 42 | Raylib.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY) 43 | end 44 | Raylib.EndDrawing() 45 | -- ]] Draw ]] 46 | end 47 | 48 | -- [[ De-Initialization [[ 49 | Raylib.CloseWindow() -- Close window and OpenGL context 50 | -- ]] De-Initialization ]] 51 | 52 | -------------------------------------------------------------------------------- /examples/core/input-mouse_wheel.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "input mouse wheel" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_input_mouse_wheel.c 7 | 8 | require 'raylib' 9 | 10 | -- [[ Initialization [[ 11 | local screen_width: integer = 800 12 | local screen_height: integer = 450 13 | 14 | Raylib.InitWindow(screen_width, screen_height, 'raylib-nelua [core] example - input mouse wheel') 15 | 16 | local box_position_y = screen_height // 2 - 40 17 | local scroll_speed = 4 -- Scrolling speed in pixels 18 | 19 | Raylib.SetTargetFPS(60) -- Set out game to run 60 frames-per-second 20 | -- ]] Initialization ]] 21 | 22 | -- [[ Main game loop [[ 23 | while not Raylib.WindowShouldClose() do -- Detect window close button or ECS key 24 | -- [[ Update [[ 25 | box_position_y = box_position_y - Raylib.GetMouseWheelMove() * scroll_speed 26 | -- ]] Update ]] 27 | 28 | -- [[ Draw [[ 29 | Raylib.BeginDrawing() 30 | do 31 | Raylib.ClearBackground(RAYWHITE) 32 | 33 | Raylib.DrawRectangle(screen_width // 2 - 40, box_position_y, 80, 80, MAROON) 34 | 35 | Raylib.DrawText('Use mouse wheel to move the cube up and down!', 10, 10, 20, GRAY) 36 | Raylib.DrawText(Raylib.TextFormat('Box position Y: %03i', box_position_y), 10, 40, 20, LIGHTGRAY) 37 | end 38 | Raylib.EndDrawing() 39 | -- ]] Draw ]] 40 | end 41 | 42 | -- [[ De-Initialization [[ 43 | Raylib.CloseWindow() -- Close window and OpenGL context 44 | -- ]] De-Initialization ]] 45 | -------------------------------------------------------------------------------- /examples/core/random-values.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "Generate random values" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_random_values.c 7 | 8 | require 'raylib' 9 | 10 | -- [[ Initialization [[ 11 | local screen_width = 800 12 | local screen_height = 450 13 | 14 | Raylib.InitWindow(screen_width, screen_height, "raylib-nelua [core] example - generate random values") 15 | 16 | local frames_counter = 0 -- Variable used to count frames 17 | 18 | local rand_value = Raylib.GetRandomValue(-8, 5) -- Get a random integer number between -8 and 5 (both included) 19 | 20 | Raylib.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 21 | -- ]] Initialization ]] 22 | 23 | -- [[ Main game loop [[ 24 | while not Raylib.WindowShouldClose() do --Detect window close button or ESC key 25 | -- [[ Update [[ 26 | frames_counter = frames_counter + 1 27 | 28 | -- Every two seconds (120 frames) a new random value is generated 29 | if (frames_counter // 120) % 2 == 1 then 30 | rand_value = Raylib.GetRandomValue(-8, 5) 31 | frames_counter = 0 32 | end 33 | -- ]] Update ]] 34 | 35 | -- [[ Draw [[ 36 | Raylib.BeginDrawing() 37 | do 38 | Raylib.ClearBackground(RAYWHITE) 39 | 40 | Raylib.DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON) 41 | Raylib.DrawText(Raylib.TextFormat("%i", rand_value), 360, 180, 80, LIGHTGRAY) 42 | end 43 | Raylib.EndDrawing() 44 | -- ]] Draw ]] 45 | end 46 | -- ]] Main game loop ]] 47 | 48 | -- [[ De-Initialization [[ 49 | Raylib.CloseWindow() -- Close window and OpenGL context 50 | -- ]] De-Initialization ]] 51 | -------------------------------------------------------------------------------- /examples/core/resources/distortion100.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | uniform vec2 leftLensCenter; 15 | uniform vec2 rightLensCenter; 16 | uniform vec2 leftScreenCenter; 17 | uniform vec2 rightScreenCenter; 18 | uniform vec2 scale; 19 | uniform vec2 scaleIn; 20 | uniform vec4 hmdWarpParam; 21 | uniform vec4 chromaAbParam; 22 | 23 | void main() 24 | { 25 | // Compute lens distortion 26 | vec2 lensCenter = fragTexCoord.x < 0.5? leftLensCenter : rightLensCenter; 27 | vec2 screenCenter = fragTexCoord.x < 0.5? leftScreenCenter : rightScreenCenter; 28 | vec2 theta = (fragTexCoord - lensCenter)*scaleIn; 29 | float rSq = theta.x*theta.x + theta.y*theta.y; 30 | vec2 theta1 = theta*(hmdWarpParam.x + hmdWarpParam.y*rSq + hmdWarpParam.z*rSq*rSq + hmdWarpParam.w*rSq*rSq*rSq); 31 | vec2 thetaBlue = theta1*(chromaAbParam.z + chromaAbParam.w*rSq); 32 | vec2 tcBlue = lensCenter + scale*thetaBlue; 33 | 34 | if (any(bvec2(clamp(tcBlue, screenCenter - vec2(0.25, 0.5), screenCenter + vec2(0.25, 0.5)) - tcBlue))) 35 | { 36 | // Set black fragment for everything outside the lens border 37 | gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 38 | } 39 | else 40 | { 41 | // Compute color chroma aberration 42 | float blue = texture2D(texture0, tcBlue).b; 43 | vec2 tcGreen = lensCenter + scale*theta1; 44 | float green = texture2D(texture0, tcGreen).g; 45 | 46 | vec2 thetaRed = theta1*(chromaAbParam.x + chromaAbParam.y*rSq); 47 | vec2 tcRed = lensCenter + scale*thetaRed; 48 | 49 | float red = texture2D(texture0, tcRed).r; 50 | gl_FragColor = vec4(red, green, blue, 1.0); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/core/resources/distortion330.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | uniform vec2 leftLensCenter = vec2(0.288, 0.5); 16 | uniform vec2 rightLensCenter = vec2(0.712, 0.5); 17 | uniform vec2 leftScreenCenter = vec2(0.25, 0.5); 18 | uniform vec2 rightScreenCenter = vec2(0.75, 0.5); 19 | uniform vec2 scale = vec2(0.25, 0.45); 20 | uniform vec2 scaleIn = vec2(4, 2.2222); 21 | uniform vec4 hmdWarpParam = vec4(1, 0.22, 0.24, 0); 22 | uniform vec4 chromaAbParam = vec4(0.996, -0.004, 1.014, 0.0); 23 | 24 | void main() 25 | { 26 | // Compute lens distortion 27 | vec2 lensCenter = fragTexCoord.x < 0.5? leftLensCenter : rightLensCenter; 28 | vec2 screenCenter = fragTexCoord.x < 0.5? leftScreenCenter : rightScreenCenter; 29 | vec2 theta = (fragTexCoord - lensCenter)*scaleIn; 30 | float rSq = theta.x*theta.x + theta.y*theta.y; 31 | vec2 theta1 = theta*(hmdWarpParam.x + hmdWarpParam.y*rSq + hmdWarpParam.z*rSq*rSq + hmdWarpParam.w*rSq*rSq*rSq); 32 | vec2 thetaBlue = theta1*(chromaAbParam.z + chromaAbParam.w*rSq); 33 | vec2 tcBlue = lensCenter + scale*thetaBlue; 34 | 35 | if (any(bvec2(clamp(tcBlue, screenCenter - vec2(0.25, 0.5), screenCenter + vec2(0.25, 0.5)) - tcBlue))) 36 | { 37 | // Set black fragment for everything outside the lens border 38 | finalColor = vec4(0.0, 0.0, 0.0, 1.0); 39 | } 40 | else 41 | { 42 | // Compute color chroma aberration 43 | float blue = texture(texture0, tcBlue).b; 44 | vec2 tcGreen = lensCenter + scale*theta1; 45 | float green = texture(texture0, tcGreen).g; 46 | 47 | vec2 thetaRed = theta1*(chromaAbParam.x + chromaAbParam.y*rSq); 48 | vec2 tcRed = lensCenter + scale*thetaRed; 49 | 50 | float red = texture(texture0, tcRed).r; 51 | finalColor = vec4(red, green, blue, 1.0); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /examples/core/resources/ps3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/core/resources/ps3.png -------------------------------------------------------------------------------- /examples/core/resources/xbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/core/resources/xbox.png -------------------------------------------------------------------------------- /examples/core/scissor-text.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "Scissor test" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_scissor_test.c 7 | 8 | require 'raylib' 9 | 10 | -- [[ Initialization [[ 11 | local screen_width = 800 12 | local screen_height = 450 13 | 14 | Raylib.InitWindow(screen_width, screen_height, "raylib-nelua [core] example - scissor test") 15 | 16 | local scissor_area: Rectangle = { 0, 0, 300, 300 } 17 | local scissor_mode = true 18 | 19 | Raylib.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 20 | -- ]] Initialization ]] 21 | 22 | -- [[ Main game loop [[ 23 | while not Raylib.WindowShouldClose() do -- Detect window close button or ESC key 24 | -- [[ Update [[ 25 | if Raylib.IsKeyPressed(KeyboardKey.KEY_S) then 26 | scissor_mode = not scissor_mode 27 | end 28 | 29 | -- Centre the scissor area around the mouse position 30 | scissor_area.x = Raylib.GetMouseX() - scissor_area.width / 2 31 | scissor_area.y = Raylib.GetMouseY() - scissor_area.height / 2 32 | -- ]] Update ]] 33 | 34 | -- [[ Draw [[ 35 | Raylib.BeginDrawing() 36 | do 37 | Raylib.ClearBackground(RAYWHITE) 38 | 39 | if scissor_mode then 40 | Raylib.BeginScissorMode(scissor_area.x, scissor_area.y, scissor_area.width, scissor_area.height) 41 | end 42 | 43 | -- Draw full screen rectangle and some text 44 | -- NOTE: Only part defined by scissor area will be rendered 45 | Raylib.DrawRectangle(0, 0, Raylib.GetScreenWidth(), Raylib.GetScreenHeight(), RED) 46 | Raylib.DrawText("Move the mouse around to reveal this text!", 190, 200, 20, LIGHTGRAY) 47 | 48 | if scissor_mode then 49 | Raylib.EndScissorMode() 50 | end 51 | 52 | Raylib.DrawRectangleLinesEx(scissor_area, 1, BLACK) 53 | Raylib.DrawText("Press S to toggle scissor test", 10, 10, 20, BLACK) 54 | end 55 | Raylib.EndDrawing() 56 | -- ]] Draw ]] 57 | end 58 | -- ]] Main game loop ]] 59 | 60 | -- [[ De-Initialization [[ 61 | Raylib.CloseWindow() -- Close window and OpenGL context 62 | -- ]] De-Initialization ]] 63 | -------------------------------------------------------------------------------- /examples/core/storage-values.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "storage values" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_storage_values.c 7 | 8 | require 'raylib' 9 | 10 | -- NOTE: Storage positions must start with 0, directly related to file memory layout 11 | local StorageData = @enum{ 12 | PositionScore = 0, 13 | PositionHiScore, 14 | } 15 | 16 | -- [[ Initialization [[ 17 | local screen_width = 800 18 | local screen_height = 450 19 | 20 | Raylib.InitWindow(screen_width, screen_height, "raylib-nelua [core] example - storage save/load values") 21 | 22 | local score = 0 23 | local hiscore = 0 24 | local frames_counter = 0 25 | 26 | Raylib.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 27 | -- ]] Initialization ]] 28 | 29 | -- [[ Main game loop [[ 30 | while not Raylib.WindowShouldClose() do -- Detect window close button or ESC key 31 | -- [[ Update [[ 32 | if Raylib.IsKeyPressed(KeyboardKey.KEY_R) then 33 | score = Raylib.GetRandomValue(1000, 2000) 34 | hiscore = Raylib.GetRandomValue(2000, 4000) 35 | end 36 | 37 | if Raylib.IsKeyPressed(KeyboardKey.KEY_ENTER) then 38 | Raylib.SaveStorageValue(StorageData.PositionScore, score) 39 | Raylib.SaveStorageValue(StorageData.PositionHiScore, hiscore) 40 | elseif Raylib.IsKeyPressed(KeyboardKey.KEY_SPACE) then 41 | -- NOTE: If requested position could not be found, value 0 is returned 42 | score = Raylib.LoadStorageValue(StorageData.PositionScore) 43 | hiscore = Raylib.LoadStorageValue(StorageData.PositionHiScore) 44 | end 45 | 46 | frames_counter = frames_counter + 1 47 | -- ]] Update ]] 48 | 49 | -- [[ Draw [[ 50 | Raylib.BeginDrawing() 51 | do 52 | Raylib.ClearBackground(RAYWHITE) 53 | 54 | Raylib.DrawText(Raylib.TextFormat("SCORE: %i", score), 280, 130, 40, MAROON) 55 | Raylib.DrawText(Raylib.TextFormat("HI-SCORE: %i", hiscore), 210, 200, 50, BLACK) 56 | 57 | Raylib.DrawText(Raylib.TextFormat("frames: %i", frames_counter), 10, 10, 20, LIME) 58 | 59 | Raylib.DrawText("Press R to generate random numbers", 220, 40, 20, LIGHTGRAY) 60 | Raylib.DrawText("Press ENTER to SAVE values", 250, 310, 20, LIGHTGRAY) 61 | Raylib.DrawText("Press SPACE to LOAD values", 252, 350, 20, LIGHTGRAY) 62 | end 63 | Raylib.EndDrawing() 64 | -- ]] Draw ]] 65 | end 66 | -- ]] Main game loop ]] 67 | 68 | -- [[ De-Initialization [[ 69 | Raylib.CloseWindow() -- Close window and OpenGL context 70 | -- ]] De-Initialization ]] 71 | -------------------------------------------------------------------------------- /examples/core/vr-simulator.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "VR Simulator (Oculus Rift CV1 parameters)" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_vr_simulator.c 7 | 8 | require 'raylib' 9 | 10 | ##[=[ cemitdef[[ 11 | #if defined(PLATFORM_DESKTOP) 12 | #define GLSL_VERSION 330 13 | #else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB 14 | #define GLSL_VERSION 100 15 | #endif 16 | ]] ]=] 17 | 18 | local GLSL_VERSION: integer 19 | 20 | -- [[ Initialization [[ 21 | local screen_width = 800 22 | local screen_height = 450 23 | 24 | -- NOTE: screen_width / screen_height should match VR device aspect ratio 25 | 26 | Raylib.SetConfigFlags(ConfigFlag.FLAG_MSAA_4X_HINT) 27 | Raylib.InitWindow(screen_width, screen_height, "raylib-nelua [core] example - vr simulator") 28 | 29 | -- Init VR simulator (Oculus Rift CV1 parameters) 30 | Raylib.InitVrSimulator() 31 | 32 | local hmd: VrDeviceInfo = { -- VR device parameters (head-mounted-device) 33 | -- Oculus Rift CV1 parameters for simulator 34 | hResolution = 2160, -- HMD horizontal resolution in pixels 35 | vResolution = 1200, -- HMD vertical resolution in pixels 36 | hScreenSize = 0.133793, -- HMD horizontal size in meters 37 | vScreenSize = 0.0669, -- HMD vertical size in meters 38 | vScreenCenter = 0.04678, -- HMD screen center in meters 39 | eyeToScreenDistance = 0.041, -- HMD distance between eye and display in meters 40 | lensSeparationDistance = 0.07, -- HMD lens separation distance in meters 41 | interpupillaryDistance = 0.07, -- HMD IPD (distance between pupils) in meters 42 | 43 | -- NOTE: CV1 uses a Fresnel-hybrid-asymmetric lenses with specific distortion compute shaders. 44 | -- Following parameters are an approximation to distortion stereo rendering but results differ from actual device. 45 | lensDistortionValues = { 46 | 1.0, -- HMD lens distortion constant parameter 0 47 | 0.22, -- HMD lens distortion constant parameter 1 48 | 0.24, -- HMD lens distortion constant parameter 2 49 | 0.0 -- HMD lens distortion constant parameter 3 50 | }, 51 | chromaAbCorrection = { 52 | 0.996, -- HMD chromatic aberration correction parameter 0 53 | -0.004, -- HMD chromatic aberration correction parameter 1 54 | 1.014, -- HMD chromatic aberration correction parameter 2 55 | 0.0 -- HMD chromatic aberration correction parameter 3 56 | } 57 | } 58 | 59 | -- Distortion shader (uses device lens distortion and chroma) 60 | local distortion: Shader = Raylib.LoadShader(nilptr, Raylib.TextFormat("resources/distortion%i.fs", GLSL_VERSION)) 61 | 62 | Raylib.SetVrConfiguration(hmd, distortion) -- Set Vr device parameters for stereo rendering 63 | 64 | -- Define the camera to look into our 3d world 65 | local camera: Camera = { 66 | position = { 5.0, 2.0, 5.0 }, -- Camera position 67 | target = { 0.0, 2.0, 0.0 }, -- Camera looking at point 68 | up = { 0.0, 1.0, 0.0 }, -- Camera up vector (rotation towards target) 69 | fovy = 60.0, -- Camera field-of-view Y 70 | type = CameraType.CAMERA_PERSPECTIVE, -- Camera type 71 | } 72 | 73 | local cube_position: Vector3 = { 0, 0, 0 } 74 | 75 | camera:SetMode(CameraMode.CAMERA_FIRST_PERSON) -- Set first person camera mode 76 | 77 | Raylib.SetTargetFPS(90) -- Set our game to run at 90 frames-per-second 78 | -- ]] Initialization ]] 79 | 80 | -- [[ Main game loop [[ 81 | while not Raylib.WindowShouldClose() do --Detect window close button or ESC key 82 | -- [[ Update [[ 83 | camera:Update() -- Update camera (simulator mode) 84 | 85 | if Raylib.IsKeyPressed(KeyboardKey.KEY_SPACE) then 86 | Raylib.ToggleVrMode() -- Toggle VR mode 87 | end 88 | -- ]] Update ]] 89 | 90 | -- [[ Draw [[ 91 | Raylib.BeginDrawing() 92 | do 93 | Raylib.ClearBackground(RAYWHITE) 94 | 95 | Raylib.BeginVrDrawing() 96 | do 97 | Raylib.BeginMode3D(camera) 98 | do 99 | Raylib.DrawCube(cube_position, 2.0, 2.0, 2.0, RED) 100 | Raylib.DrawCubeWires(cube_position, 2.0, 2.0, 2.0, MAROON) 101 | 102 | Raylib.DrawGrid(40, 1.0) 103 | end 104 | Raylib.EndMode3D() 105 | end 106 | Raylib.EndVrDrawing() 107 | 108 | Raylib.DrawFPS(10, 10) 109 | end 110 | Raylib.EndDrawing() 111 | -- ]] Draw ]] 112 | end 113 | -- ]] Main game loop ]] 114 | 115 | -- [[ De-Initialization [[ 116 | Raylib.UnloadShader(distortion) -- Unload distortion shader 117 | 118 | Raylib.CloseVrSimulator() -- Close VR simulator 119 | 120 | Raylib.CloseWindow() -- Close window and OpenGL context 121 | -- ]] De-Initialization ]] 122 | -------------------------------------------------------------------------------- /examples/core/world-screen.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "World Screen" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_world_screen.c 7 | 8 | require 'raylib' 9 | require 'math' 10 | 11 | -- [[ Initialization [[ 12 | local screen_width = 800 13 | local screen_height = 450 14 | 15 | Raylib.InitWindow(screen_width, screen_height, "raylib-nelua [core] example - 3d camera free") 16 | 17 | -- Define the camera to look into our 3d world 18 | local camera: Camera = { 19 | position = { 10, 10, 10 }, 20 | target = { 0, 0, 0 }, 21 | up = { 0, 1, 0 }, 22 | fovy = 45, 23 | type = CameraType.CAMERA_PERSPECTIVE 24 | } 25 | 26 | local cube_position: Vector3 = { 0, 0, 0 } 27 | local cube_screen_position: Vector2 = { 0, 0 } 28 | 29 | camera:SetMode(CameraMode.CAMERA_FREE) -- Set a free camera mode 30 | 31 | Raylib.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 32 | -- ]] Initialization ]] 33 | 34 | -- [[ Main game loop [[ 35 | while not Raylib.WindowShouldClose() do -- Detect window close button or ESC key 36 | -- [[ Update [[ 37 | camera:Update() -- Update camera 38 | 39 | -- Calculate cube screen space position (with a little offset to be in top) 40 | cube_screen_position = Raylib.GetWorldToScreen( {cube_position.x, cube_position.y + 2.5, cube_position.z}, camera) 41 | -- ]] Update ]] 42 | 43 | -- [[ Draw [[ 44 | Raylib.BeginDrawing() 45 | do 46 | Raylib.ClearBackground(RAYWHITE) 47 | 48 | Raylib.BeginMode3D(camera) 49 | do 50 | Raylib.DrawCube(cube_position, 2, 2, 2, RED) 51 | Raylib.DrawCubeWires(cube_position, 2, 2, 2, MAROON) 52 | 53 | Raylib.DrawGrid(10, 1) 54 | end 55 | Raylib.EndMode3D() 56 | 57 | Raylib.DrawText("Enemy: 100 / 100", math.ifloor(cube_screen_position.x - Raylib.MeasureText("Enemy: 100/100", 20) / 2), math.ifloor(cube_screen_position.y), 20, BLACK) 58 | Raylib.DrawText("Text is always on top of the cube", math.ifloor((screen_width - Raylib.MeasureText("Text is always on top of the cube", 20)) / 2), 25, 20, GRAY) 59 | end 60 | Raylib.EndDrawing() 61 | -- ]] Draw ]] 62 | end 63 | -- ]] Main game loop ]] 64 | 65 | -- [[ De-Initialization [[ 66 | Raylib.CloseWindow() -- Close window and OpenGL context 67 | -- ]] De-Initialization ]] 68 | -------------------------------------------------------------------------------- /examples/models/resources/angle_gauge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/angle_gauge.png -------------------------------------------------------------------------------- /examples/models/resources/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/background.png -------------------------------------------------------------------------------- /examples/models/resources/billboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/billboard.png -------------------------------------------------------------------------------- /examples/models/resources/cubicmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/cubicmap.png -------------------------------------------------------------------------------- /examples/models/resources/cubicmap_atlas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/cubicmap_atlas.png -------------------------------------------------------------------------------- /examples/models/resources/dresden_square.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/dresden_square.hdr -------------------------------------------------------------------------------- /examples/models/resources/guy/guy.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/guy/guy.blend -------------------------------------------------------------------------------- /examples/models/resources/guy/guy.iqm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/guy/guy.iqm -------------------------------------------------------------------------------- /examples/models/resources/guy/guyanim.iqm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/guy/guyanim.iqm -------------------------------------------------------------------------------- /examples/models/resources/guy/guytex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/guy/guytex.png -------------------------------------------------------------------------------- /examples/models/resources/heightmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/heightmap.png -------------------------------------------------------------------------------- /examples/models/resources/models/Duck/Duck.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/models/Duck/Duck.glb -------------------------------------------------------------------------------- /examples/models/resources/models/Duck/Duck0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/models/Duck/Duck0.bin -------------------------------------------------------------------------------- /examples/models/resources/models/Duck/DuckCM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/models/Duck/DuckCM.png -------------------------------------------------------------------------------- /examples/models/resources/models/Duck/Duck_license.txt: -------------------------------------------------------------------------------- 1 | # Duck 2 | ## Screenshot 3 | 4 | ![screenshot](screenshot/screenshot.png) 5 | 6 | ## License Information 7 | 8 | Copyright 2006 Sony Computer Entertainment Inc. 9 | 10 | Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: 11 | 12 | http://research.scea.com/scea_shared_source_license.html 13 | 14 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -------------------------------------------------------------------------------- /examples/models/resources/models/LICENSE: -------------------------------------------------------------------------------- 1 | Medieval City models and textures have been created by Alberto Cano, 2 | and licensed as Creative Commons Attribution-NonCommercial 4.0. 3 | 4 | Check for details: https://creativecommons.org/licenses/by-nc/4.0/legalcode 5 | -------------------------------------------------------------------------------- /examples/models/resources/models/bridge_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/models/bridge_diffuse.png -------------------------------------------------------------------------------- /examples/models/resources/models/castle_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/models/castle_diffuse.png -------------------------------------------------------------------------------- /examples/models/resources/models/cube.obj: -------------------------------------------------------------------------------- 1 | # reference material 2 | #mtllib cube.mtl 3 | 4 | # object box 5 | 6 | # vertex (XZY) 7 | v 5.5 0 1.5 8 | v 8.5 0 1.5 9 | v 5.5 0 -1.5 10 | v 8.5 0 -1.5 11 | v 5.5 3 1.5 12 | v 8.5 3 1.5 13 | v 5.5 3 -1.5 14 | v 8.5 3 -1.5 15 | 16 | # normals (XYZ) 17 | vn 0 -1 0 18 | vn 0 1 0 19 | vn 0 0 1 20 | vn 1 0 0 21 | vn 0 0 -1 22 | vn -1 0 0 23 | 24 | # UVs (XY) 25 | vt 0.5 0 0 26 | vt 1 0 0 27 | vt 1 0.5 0 28 | vt 0.5 0.5 0 29 | vt 0.5 0.5 0 30 | vt 1 0.5 0 31 | vt 0.5 1 0 32 | vt 1 1 0 33 | vt 0 0.5 0 34 | vt 1 0.5 0 35 | vt 1 0 0 36 | vt 0 0 0 37 | vt 0 0.5 0 38 | vt 1 0.5 0 39 | vt 1 1 0 40 | vt 0 1 0 41 | vt 0.5 0 0 42 | vt 0 0 0 43 | vt 0 0.5 0 44 | vt 0.5 0.5 0 45 | vt 0 0.5 0 46 | vt 0.5 0.5 0 47 | vt 0.5 1 0 48 | vt 0 1 0 49 | 50 | # merger 51 | g box 52 | 53 | # reference material 54 | #usemtl mat01 55 | 56 | # faces 57 | f 1/9/1 3/10/1 4/11/1 58 | f 4/11/1 2/12/1 1/9/1 59 | f 5/13/2 6/14/2 8/15/2 60 | f 8/15/2 7/16/2 5/13/2 61 | f 1/17/6 2/18/6 6/19/6 62 | f 6/19/6 5/20/6 1/17/6 63 | f 2/6/1 4/5/1 8/7/1 64 | f 8/7/1 6/8/1 2/6/1 65 | f 4/2/3 3/1/3 7/4/3 66 | f 7/4/3 8/3/3 4/2/3 67 | f 3/22/5 1/21/5 5/24/5 68 | f 5/24/5 7/23/5 3/22/5 69 | -------------------------------------------------------------------------------- /examples/models/resources/models/cube_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/models/cube_diffuse.png -------------------------------------------------------------------------------- /examples/models/resources/models/house_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/models/house_diffuse.png -------------------------------------------------------------------------------- /examples/models/resources/models/market_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/models/market_diffuse.png -------------------------------------------------------------------------------- /examples/models/resources/models/turret_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/models/turret_diffuse.png -------------------------------------------------------------------------------- /examples/models/resources/models/well_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/models/well_diffuse.png -------------------------------------------------------------------------------- /examples/models/resources/pbr/trooper_albedo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/pbr/trooper_albedo.png -------------------------------------------------------------------------------- /examples/models/resources/pbr/trooper_ao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/pbr/trooper_ao.png -------------------------------------------------------------------------------- /examples/models/resources/pbr/trooper_metalness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/pbr/trooper_metalness.png -------------------------------------------------------------------------------- /examples/models/resources/pbr/trooper_normals.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/pbr/trooper_normals.png -------------------------------------------------------------------------------- /examples/models/resources/pbr/trooper_roughness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/pbr/trooper_roughness.png -------------------------------------------------------------------------------- /examples/models/resources/pitch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/pitch.png -------------------------------------------------------------------------------- /examples/models/resources/plane.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/plane.png -------------------------------------------------------------------------------- /examples/models/resources/plane_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/models/resources/plane_diffuse.png -------------------------------------------------------------------------------- /examples/models/resources/shaders/glsl100/cubemap.fs: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * rPBR [shader] - Equirectangular to cubemap fragment shader 4 | * 5 | * Copyright (c) 2017 Victor Fisac 6 | * 7 | **********************************************************************************************/ 8 | 9 | #version 330 10 | 11 | // Input vertex attributes (from vertex shader) 12 | in vec3 fragPosition; 13 | 14 | // Input uniform values 15 | uniform sampler2D equirectangularMap; 16 | 17 | // Output fragment color 18 | out vec4 finalColor; 19 | 20 | vec2 SampleSphericalMap(vec3 v) 21 | { 22 | vec2 uv = vec2(atan(v.z, v.x), asin(v.y)); 23 | uv *= vec2(0.1591, 0.3183); 24 | uv += 0.5; 25 | return uv; 26 | } 27 | 28 | void main() 29 | { 30 | // Normalize local position 31 | vec2 uv = SampleSphericalMap(normalize(fragPosition)); 32 | 33 | // Fetch color from texture map 34 | vec3 color = texture(equirectangularMap, uv).rgb; 35 | 36 | // Calculate final fragment color 37 | finalColor = vec4(color, 1.0); 38 | } 39 | -------------------------------------------------------------------------------- /examples/models/resources/shaders/glsl100/cubemap.vs: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * rPBR [shader] - Equirectangular to cubemap vertex shader 4 | * 5 | * Copyright (c) 2017 Victor Fisac 6 | * 7 | **********************************************************************************************/ 8 | 9 | #version 330 10 | 11 | // Input vertex attributes 12 | in vec3 vertexPosition; 13 | 14 | // Input uniform values 15 | uniform mat4 projection; 16 | uniform mat4 view; 17 | 18 | // Output vertex attributes (to fragment shader) 19 | out vec3 fragPosition; 20 | 21 | void main() 22 | { 23 | // Calculate fragment position based on model transformations 24 | fragPosition = vertexPosition; 25 | 26 | // Calculate final vertex position 27 | gl_Position = projection*view*vec4(vertexPosition, 1.0); 28 | } 29 | -------------------------------------------------------------------------------- /examples/models/resources/shaders/glsl100/skybox.fs: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * rPBR [shader] - Background skybox fragment shader 4 | * 5 | * Copyright (c) 2017 Victor Fisac 6 | * 7 | **********************************************************************************************/ 8 | 9 | #version 330 10 | 11 | // Input vertex attributes (from vertex shader) 12 | in vec3 fragPosition; 13 | 14 | // Input uniform values 15 | uniform samplerCube environmentMap; 16 | 17 | // Output fragment color 18 | out vec4 finalColor; 19 | 20 | void main() 21 | { 22 | // Fetch color from texture map 23 | vec3 color = texture(environmentMap, fragPosition).rgb; 24 | 25 | // Apply gamma correction 26 | color = color/(color + vec3(1.0)); 27 | color = pow(color, vec3(1.0/2.2)); 28 | 29 | // Calculate final fragment color 30 | finalColor = vec4(color, 1.0); 31 | } 32 | -------------------------------------------------------------------------------- /examples/models/resources/shaders/glsl100/skybox.vs: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * rPBR [shader] - Background skybox vertex shader 4 | * 5 | * Copyright (c) 2017 Victor Fisac 6 | * 7 | **********************************************************************************************/ 8 | 9 | #version 330 10 | 11 | // Input vertex attributes 12 | in vec3 vertexPosition; 13 | 14 | // Input uniform values 15 | uniform mat4 projection; 16 | uniform mat4 view; 17 | 18 | // Output vertex attributes (to fragment shader) 19 | out vec3 fragPosition; 20 | 21 | void main() 22 | { 23 | // Calculate fragment position based on model transformations 24 | fragPosition = vertexPosition; 25 | 26 | // Remove translation from the view matrix 27 | mat4 rotView = mat4(mat3(view)); 28 | vec4 clipPos = projection*rotView*vec4(vertexPosition, 1.0); 29 | 30 | // Calculate final vertex position 31 | gl_Position = clipPos.xyww; 32 | } 33 | -------------------------------------------------------------------------------- /examples/models/resources/shaders/glsl330/brdf.vs: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * rPBR [shader] - Bidirectional reflectance distribution function vertex shader 4 | * 5 | * Copyright (c) 2017 Victor Fisac 6 | * 7 | **********************************************************************************************/ 8 | 9 | #version 330 10 | 11 | // Input vertex attributes 12 | in vec3 vertexPosition; 13 | in vec2 vertexTexCoord; 14 | 15 | // Output vertex attributes (to fragment shader) 16 | out vec2 fragTexCoord; 17 | 18 | void main() 19 | { 20 | // Calculate fragment position based on model transformations 21 | fragTexCoord = vertexTexCoord; 22 | 23 | // Calculate final vertex position 24 | gl_Position = vec4(vertexPosition, 1.0); 25 | } -------------------------------------------------------------------------------- /examples/models/resources/shaders/glsl330/cubemap.fs: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * rPBR [shader] - Equirectangular to cubemap fragment shader 4 | * 5 | * Copyright (c) 2017 Victor Fisac 6 | * 7 | **********************************************************************************************/ 8 | 9 | #version 330 10 | 11 | // Input vertex attributes (from vertex shader) 12 | in vec3 fragPosition; 13 | 14 | // Input uniform values 15 | uniform sampler2D equirectangularMap; 16 | 17 | // Output fragment color 18 | out vec4 finalColor; 19 | 20 | vec2 SampleSphericalMap(vec3 v) 21 | { 22 | vec2 uv = vec2(atan(v.z, v.x), asin(v.y)); 23 | uv *= vec2(0.1591, 0.3183); 24 | uv += 0.5; 25 | return uv; 26 | } 27 | 28 | void main() 29 | { 30 | // Normalize local position 31 | vec2 uv = SampleSphericalMap(normalize(fragPosition)); 32 | 33 | // Fetch color from texture map 34 | vec3 color = texture(equirectangularMap, uv).rgb; 35 | 36 | // Calculate final fragment color 37 | finalColor = vec4(color, 1.0); 38 | } 39 | -------------------------------------------------------------------------------- /examples/models/resources/shaders/glsl330/cubemap.vs: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * rPBR [shader] - Equirectangular to cubemap vertex shader 4 | * 5 | * Copyright (c) 2017 Victor Fisac 6 | * 7 | **********************************************************************************************/ 8 | 9 | #version 330 10 | 11 | // Input vertex attributes 12 | in vec3 vertexPosition; 13 | 14 | // Input uniform values 15 | uniform mat4 projection; 16 | uniform mat4 view; 17 | 18 | // Output vertex attributes (to fragment shader) 19 | out vec3 fragPosition; 20 | 21 | void main() 22 | { 23 | // Calculate fragment position based on model transformations 24 | fragPosition = vertexPosition; 25 | 26 | // Calculate final vertex position 27 | gl_Position = projection*view*vec4(vertexPosition, 1.0); 28 | } 29 | -------------------------------------------------------------------------------- /examples/models/resources/shaders/glsl330/irradiance.fs: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * rPBR [shader] - Irradiance cubemap fragment shader 4 | * 5 | * Copyright (c) 2017 Victor Fisac 6 | * 7 | **********************************************************************************************/ 8 | 9 | #version 330 10 | 11 | // Input vertex attributes (from vertex shader) 12 | in vec3 fragPosition; 13 | 14 | // Input uniform values 15 | uniform samplerCube environmentMap; 16 | 17 | // Constant values 18 | const float PI = 3.14159265359; 19 | 20 | // Output fragment color 21 | out vec4 finalColor; 22 | 23 | void main() 24 | { 25 | // The sample direction equals the hemisphere's orientation 26 | vec3 normal = normalize(fragPosition); 27 | 28 | vec3 irradiance = vec3(0.0); 29 | 30 | vec3 up = vec3(0.0, 1.0, 0.0); 31 | vec3 right = cross(up, normal); 32 | up = cross(normal, right); 33 | 34 | float sampleDelta = 0.025; 35 | float nrSamples = 0.0; 36 | 37 | for (float phi = 0.0; phi < 2.0*PI; phi += sampleDelta) 38 | { 39 | for (float theta = 0.0; theta < 0.5*PI; theta += sampleDelta) 40 | { 41 | // Spherical to cartesian (in tangent space) 42 | vec3 tangentSample = vec3(sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta)); 43 | 44 | // tangent space to world 45 | vec3 sampleVec = tangentSample.x*right + tangentSample.y*up + tangentSample.z*normal; 46 | 47 | // Fetch color from environment cubemap 48 | irradiance += texture(environmentMap, sampleVec).rgb*cos(theta)*sin(theta); 49 | nrSamples++; 50 | } 51 | } 52 | 53 | // Calculate irradiance average value from samples 54 | irradiance = PI*irradiance*(1.0/float(nrSamples)); 55 | 56 | // Calculate final fragment color 57 | finalColor = vec4(irradiance, 1.0); 58 | } 59 | -------------------------------------------------------------------------------- /examples/models/resources/shaders/glsl330/pbr.vs: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * rPBR [shader] - Physically based rendering vertex shader 4 | * 5 | * Copyright (c) 2017 Victor Fisac 6 | * 7 | **********************************************************************************************/ 8 | 9 | #version 330 10 | 11 | // Input vertex attributes 12 | in vec3 vertexPosition; 13 | in vec2 vertexTexCoord; 14 | in vec3 vertexNormal; 15 | in vec4 vertexTangent; 16 | 17 | // Input uniform values 18 | uniform mat4 mvp; 19 | uniform mat4 matModel; 20 | 21 | // Output vertex attributes (to fragment shader) 22 | out vec3 fragPosition; 23 | out vec2 fragTexCoord; 24 | out vec3 fragNormal; 25 | out vec3 fragTangent; 26 | out vec3 fragBinormal; 27 | 28 | void main() 29 | { 30 | // Calculate binormal from vertex normal and tangent 31 | vec3 vertexBinormal = cross(vertexNormal, vec3(vertexTangent)); 32 | 33 | // Calculate fragment normal based on normal transformations 34 | mat3 normalMatrix = transpose(inverse(mat3(matModel))); 35 | 36 | // Calculate fragment position based on model transformations 37 | fragPosition = vec3(matModel*vec4(vertexPosition, 1.0)); 38 | 39 | // Send vertex attributes to fragment shader 40 | fragTexCoord = vertexTexCoord; 41 | fragNormal = normalize(normalMatrix*vertexNormal); 42 | fragTangent = normalize(normalMatrix*vec3(vertexTangent)); 43 | fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal); 44 | fragBinormal = normalize(normalMatrix*vertexBinormal); 45 | fragBinormal = cross(fragNormal, fragTangent); 46 | 47 | // Calculate final vertex position 48 | gl_Position = mvp*vec4(vertexPosition, 1.0); 49 | } -------------------------------------------------------------------------------- /examples/models/resources/shaders/glsl330/prefilter.fs: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * rPBR [shader] - Prefiltered environment for reflections fragment shader 4 | * 5 | * Copyright (c) 2017 Victor Fisac 6 | * 7 | **********************************************************************************************/ 8 | 9 | #version 330 10 | #define MAX_SAMPLES 1024u 11 | #define CUBEMAP_RESOLUTION 1024.0 12 | 13 | // Input vertex attributes (from vertex shader) 14 | in vec3 fragPosition; 15 | 16 | // Input uniform values 17 | uniform samplerCube environmentMap; 18 | uniform float roughness; 19 | 20 | // Constant values 21 | const float PI = 3.14159265359; 22 | 23 | // Output fragment color 24 | out vec4 finalColor; 25 | 26 | float DistributionGGX(vec3 N, vec3 H, float roughness); 27 | float RadicalInverse_VdC(uint bits); 28 | vec2 Hammersley(uint i, uint N); 29 | vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness); 30 | 31 | float DistributionGGX(vec3 N, vec3 H, float roughness) 32 | { 33 | float a = roughness*roughness; 34 | float a2 = a*a; 35 | float NdotH = max(dot(N, H), 0.0); 36 | float NdotH2 = NdotH*NdotH; 37 | 38 | float nom = a2; 39 | float denom = (NdotH2*(a2 - 1.0) + 1.0); 40 | denom = PI*denom*denom; 41 | 42 | return nom/denom; 43 | } 44 | 45 | float RadicalInverse_VdC(uint bits) 46 | { 47 | bits = (bits << 16u) | (bits >> 16u); 48 | bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u); 49 | bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u); 50 | bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u); 51 | bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u); 52 | return float(bits)*2.3283064365386963e-10; // / 0x100000000 53 | } 54 | 55 | vec2 Hammersley(uint i, uint N) 56 | { 57 | return vec2(float(i)/float(N), RadicalInverse_VdC(i)); 58 | } 59 | 60 | vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness) 61 | { 62 | float a = roughness*roughness; 63 | float phi = 2.0*PI*Xi.x; 64 | float cosTheta = sqrt((1.0 - Xi.y)/(1.0 + (a*a - 1.0)*Xi.y)); 65 | float sinTheta = sqrt(1.0 - cosTheta*cosTheta); 66 | 67 | // Transform from spherical coordinates to cartesian coordinates (halfway vector) 68 | vec3 H = vec3(cos(phi)*sinTheta, sin(phi)*sinTheta, cosTheta); 69 | 70 | // Transform from tangent space H vector to world space sample vector 71 | vec3 up = ((abs(N.z) < 0.999) ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0)); 72 | vec3 tangent = normalize(cross(up, N)); 73 | vec3 bitangent = cross(N, tangent); 74 | vec3 sampleVec = tangent*H.x + bitangent*H.y + N*H.z; 75 | 76 | return normalize(sampleVec); 77 | } 78 | 79 | void main() 80 | { 81 | // Make the simplyfying assumption that V equals R equals the normal 82 | vec3 N = normalize(fragPosition); 83 | vec3 R = N; 84 | vec3 V = R; 85 | 86 | vec3 prefilteredColor = vec3(0.0); 87 | float totalWeight = 0.0; 88 | 89 | for (uint i = 0u; i < MAX_SAMPLES; i++) 90 | { 91 | // Generate a sample vector that's biased towards the preferred alignment direction (importance sampling) 92 | vec2 Xi = Hammersley(i, MAX_SAMPLES); 93 | vec3 H = ImportanceSampleGGX(Xi, N, roughness); 94 | vec3 L = normalize(2.0*dot(V, H)*H - V); 95 | 96 | float NdotL = max(dot(N, L), 0.0); 97 | if(NdotL > 0.0) 98 | { 99 | // Sample from the environment's mip level based on roughness/pdf 100 | float D = DistributionGGX(N, H, roughness); 101 | float NdotH = max(dot(N, H), 0.0); 102 | float HdotV = max(dot(H, V), 0.0); 103 | float pdf = D*NdotH/(4.0*HdotV) + 0.0001; 104 | 105 | float resolution = CUBEMAP_RESOLUTION; 106 | float saTexel = 4.0*PI/(6.0*resolution*resolution); 107 | float saSample = 1.0/(float(MAX_SAMPLES)*pdf + 0.0001); 108 | float mipLevel = ((roughness == 0.0) ? 0.0 : 0.5*log2(saSample/saTexel)); 109 | 110 | prefilteredColor += textureLod(environmentMap, L, mipLevel).rgb*NdotL; 111 | totalWeight += NdotL; 112 | } 113 | } 114 | 115 | // Calculate prefilter average color 116 | prefilteredColor = prefilteredColor/totalWeight; 117 | 118 | // Calculate final fragment color 119 | finalColor = vec4(prefilteredColor, 1.0); 120 | } 121 | -------------------------------------------------------------------------------- /examples/models/resources/shaders/glsl330/skybox.fs: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * rPBR [shader] - Background skybox fragment shader 4 | * 5 | * Copyright (c) 2017 Victor Fisac 6 | * 7 | **********************************************************************************************/ 8 | 9 | #version 330 10 | 11 | // Input vertex attributes (from vertex shader) 12 | in vec3 fragPosition; 13 | 14 | // Input uniform values 15 | uniform samplerCube environmentMap; 16 | 17 | // Output fragment color 18 | out vec4 finalColor; 19 | 20 | void main() 21 | { 22 | // Fetch color from texture map 23 | vec3 color = texture(environmentMap, fragPosition).rgb; 24 | 25 | // Apply gamma correction 26 | color = color/(color + vec3(1.0)); 27 | color = pow(color, vec3(1.0/2.2)); 28 | 29 | // Calculate final fragment color 30 | finalColor = vec4(color, 1.0); 31 | } 32 | -------------------------------------------------------------------------------- /examples/models/resources/shaders/glsl330/skybox.vs: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * rPBR [shader] - Background skybox vertex shader 4 | * 5 | * Copyright (c) 2017 Victor Fisac 6 | * 7 | **********************************************************************************************/ 8 | 9 | #version 330 10 | 11 | // Input vertex attributes 12 | in vec3 vertexPosition; 13 | 14 | // Input uniform values 15 | uniform mat4 projection; 16 | uniform mat4 view; 17 | 18 | // Output vertex attributes (to fragment shader) 19 | out vec3 fragPosition; 20 | 21 | void main() 22 | { 23 | // Calculate fragment position based on model transformations 24 | fragPosition = vertexPosition; 25 | 26 | // Remove translation from the view matrix 27 | mat4 rotView = mat4(mat3(view)); 28 | vec4 clipPos = projection*rotView*vec4(vertexPosition, 1.0); 29 | 30 | // Calculate final vertex position 31 | gl_Position = clipPos.xyzw; 32 | } 33 | -------------------------------------------------------------------------------- /examples/others/resources/audio/guitar_noodling.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/others/resources/audio/guitar_noodling.ogg -------------------------------------------------------------------------------- /examples/others/resources/audio/tanatana.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/others/resources/audio/tanatana.ogg -------------------------------------------------------------------------------- /examples/others/resources/audio/weird.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/others/resources/audio/weird.wav -------------------------------------------------------------------------------- /examples/shaders/resources/fudesumi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/shaders/resources/fudesumi.png -------------------------------------------------------------------------------- /examples/shaders/resources/mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/shaders/resources/mask.png -------------------------------------------------------------------------------- /examples/shaders/resources/models/barracks_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/shaders/resources/models/barracks_diffuse.png -------------------------------------------------------------------------------- /examples/shaders/resources/models/church_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/shaders/resources/models/church_diffuse.png -------------------------------------------------------------------------------- /examples/shaders/resources/models/watermill_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/shaders/resources/models/watermill_diffuse.png -------------------------------------------------------------------------------- /examples/shaders/resources/plasma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/shaders/resources/plasma.png -------------------------------------------------------------------------------- /examples/shaders/resources/raysan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/shaders/resources/raysan.png -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/base.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | 15 | void main() 16 | { 17 | // Texel color fetching from texture sampler 18 | vec4 texelColor = texture2D(texture0, fragTexCoord); 19 | 20 | // NOTE: Implement here your fragment shader code 21 | 22 | gl_FragColor = texelColor*colDiffuse; 23 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/base.vs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | // Input vertex attributes 4 | attribute vec3 vertexPosition; 5 | attribute vec2 vertexTexCoord; 6 | attribute vec3 vertexNormal; 7 | attribute vec4 vertexColor; 8 | 9 | // Input uniform values 10 | uniform mat4 mvp; 11 | 12 | // Output vertex attributes (to fragment shader) 13 | varying vec2 fragTexCoord; 14 | varying vec4 fragColor; 15 | 16 | // NOTE: Add here your custom variables 17 | 18 | void main() 19 | { 20 | // Send vertex attributes to fragment shader 21 | fragTexCoord = vertexTexCoord; 22 | fragColor = vertexColor; 23 | 24 | // Calculate final vertex position 25 | gl_Position = mvp*vec4(vertexPosition, 1.0); 26 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/base_lighting.vs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | // Input vertex attributes 4 | attribute vec3 vertexPosition; 5 | attribute vec2 vertexTexCoord; 6 | attribute vec3 vertexNormal; 7 | attribute vec4 vertexColor; 8 | 9 | // Input uniform values 10 | uniform mat4 mvp; 11 | uniform mat4 matModel; 12 | 13 | // Output vertex attributes (to fragment shader) 14 | varying vec3 fragPosition; 15 | varying vec2 fragTexCoord; 16 | varying vec4 fragColor; 17 | varying vec3 fragNormal; 18 | 19 | // NOTE: Add here your custom variables 20 | 21 | // https://github.com/glslify/glsl-inverse 22 | mat3 inverse(mat3 m) 23 | { 24 | float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2]; 25 | float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2]; 26 | float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2]; 27 | 28 | float b01 = a22*a11 - a12*a21; 29 | float b11 = -a22*a10 + a12*a20; 30 | float b21 = a21*a10 - a11*a20; 31 | 32 | float det = a00*b01 + a01*b11 + a02*b21; 33 | 34 | return mat3(b01, (-a22*a01 + a02*a21), (a12*a01 - a02*a11), 35 | b11, (a22*a00 - a02*a20), (-a12*a00 + a02*a10), 36 | b21, (-a21*a00 + a01*a20), (a11*a00 - a01*a10))/det; 37 | } 38 | 39 | // https://github.com/glslify/glsl-transpose 40 | mat3 transpose(mat3 m) 41 | { 42 | return mat3(m[0][0], m[1][0], m[2][0], 43 | m[0][1], m[1][1], m[2][1], 44 | m[0][2], m[1][2], m[2][2]); 45 | } 46 | 47 | void main() 48 | { 49 | // Send vertex attributes to fragment shader 50 | fragPosition = vec3(matModel*vec4(vertexPosition, 1.0)); 51 | fragTexCoord = vertexTexCoord; 52 | fragColor = vertexColor; 53 | 54 | mat3 normalMatrix = transpose(inverse(mat3(matModel))); 55 | fragNormal = normalize(normalMatrix*vertexNormal); 56 | 57 | // Calculate final vertex position 58 | gl_Position = mvp*vec4(vertexPosition, 1.0); 59 | } 60 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/bloom.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | 15 | const vec2 size = vec2(800, 450); // render size 16 | const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance 17 | const float quality = 2.5; // lower = smaller glow, better quality 18 | 19 | void main() 20 | { 21 | vec4 sum = vec4(0); 22 | vec2 sizeFactor = vec2(1)/size*quality; 23 | 24 | // Texel color fetching from texture sampler 25 | vec4 source = texture2D(texture0, fragTexCoord); 26 | 27 | const int range = 2; // should be = (samples - 1)/2; 28 | 29 | for (int x = -range; x <= range; x++) 30 | { 31 | for (int y = -range; y <= range; y++) 32 | { 33 | sum += texture2D(texture0, fragTexCoord + vec2(x, y)*sizeFactor); 34 | } 35 | } 36 | 37 | // Calculate final fragment color 38 | gl_FragColor = ((sum/(samples*samples)) + source)*colDiffuse; 39 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/blur.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | 15 | // NOTE: Render size values must be passed from code 16 | const float renderWidth = 800.0; 17 | const float renderHeight = 450.0; 18 | 19 | vec3 offset = vec3(0.0, 1.3846153846, 3.2307692308); 20 | vec3 weight = vec3(0.2270270270, 0.3162162162, 0.0702702703); 21 | 22 | void main() 23 | { 24 | // Texel color fetching from texture sampler 25 | vec3 tc = texture2D(texture0, fragTexCoord).rgb*weight.x; 26 | 27 | tc += texture2D(texture0, fragTexCoord + vec2(offset.y)/renderWidth, 0.0).rgb*weight.y; 28 | tc += texture2D(texture0, fragTexCoord - vec2(offset.y)/renderWidth, 0.0).rgb*weight.y; 29 | 30 | tc += texture2D(texture0, fragTexCoord + vec2(offset.z)/renderWidth, 0.0).rgb*weight.z; 31 | tc += texture2D(texture0, fragTexCoord - vec2(offset.z)/renderWidth, 0.0).rgb*weight.z; 32 | 33 | gl_FragColor = vec4(tc, 1.0); 34 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/cross_hatching.fs: -------------------------------------------------------------------------------- 1 | # version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | 15 | float hatchOffsetY = 5.0; 16 | float lumThreshold01 = 0.9; 17 | float lumThreshold02 = 0.7; 18 | float lumThreshold03 = 0.5; 19 | float lumThreshold04 = 0.3; 20 | 21 | void main() 22 | { 23 | vec3 tc = vec3(1.0, 1.0, 1.0); 24 | float lum = length(texture2D(texture0, fragTexCoord).rgb); 25 | 26 | if (lum < lumThreshold01) 27 | { 28 | if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 29 | } 30 | 31 | if (lum < lumThreshold02) 32 | { 33 | if (mod(gl_FragCoord .x - gl_FragCoord .y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 34 | } 35 | 36 | if (lum < lumThreshold03) 37 | { 38 | if (mod(gl_FragCoord .x + gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 39 | } 40 | 41 | if (lum < lumThreshold04) 42 | { 43 | if (mod(gl_FragCoord .x - gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 44 | } 45 | 46 | gl_FragColor = vec4(tc, 1.0); 47 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/cross_stitching.fs: -------------------------------------------------------------------------------- 1 | # version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | 15 | // NOTE: Render size values must be passed from code 16 | const float renderWidth = 800.0; 17 | const float renderHeight = 450.0; 18 | 19 | float stitchingSize = 6.0; 20 | int invert = 0; 21 | 22 | vec4 PostFX(sampler2D tex, vec2 uv) 23 | { 24 | vec4 c = vec4(0.0); 25 | float size = stitchingSize; 26 | vec2 cPos = uv * vec2(renderWidth, renderHeight); 27 | vec2 tlPos = floor(cPos / vec2(size, size)); 28 | tlPos *= size; 29 | 30 | int remX = int(mod(cPos.x, size)); 31 | int remY = int(mod(cPos.y, size)); 32 | 33 | if (remX == 0 && remY == 0) tlPos = cPos; 34 | 35 | vec2 blPos = tlPos; 36 | blPos.y += (size - 1.0); 37 | 38 | if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y))))) 39 | { 40 | if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0); 41 | else c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; 42 | } 43 | else 44 | { 45 | if (invert == 1) c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; 46 | else c = vec4(0.0, 0.0, 0.0, 1.0); 47 | } 48 | 49 | return c; 50 | } 51 | 52 | void main() 53 | { 54 | vec3 tc = PostFX(texture0, fragTexCoord).rgb; 55 | 56 | gl_FragColor = vec4(tc, 1.0); 57 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/cubes_panning.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Custom variables 10 | const float PI = 3.14159265358979323846; 11 | uniform float uTime; 12 | 13 | float divisions = 5.0; 14 | float angle = 0.0; 15 | 16 | vec2 VectorRotateTime(vec2 v, float speed) 17 | { 18 | float time = uTime*speed; 19 | float localTime = fract(time); // The time domain this works on is 1 sec. 20 | 21 | if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0; 22 | else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4.0*sin(2.0*PI*localTime - PI/2.0); 23 | else if ((localTime >= 0.50) && (localTime < 0.75)) angle = PI*0.25; 24 | else if ((localTime >= 0.75) && (localTime < 1.00)) angle = PI/4.0*sin(2.0*PI*localTime); 25 | 26 | // Rotate vector by angle 27 | v -= 0.5; 28 | v = mat2(cos(angle), -sin(angle), sin(angle), cos(angle))*v; 29 | v += 0.5; 30 | 31 | return v; 32 | } 33 | 34 | float Rectangle(in vec2 st, in float size, in float fill) 35 | { 36 | float roundSize = 0.5 - size/2.0; 37 | float left = step(roundSize, st.x); 38 | float top = step(roundSize, st.y); 39 | float bottom = step(roundSize, 1.0 - st.y); 40 | float right = step(roundSize, 1.0 - st.x); 41 | 42 | return (left*bottom*right*top)*fill; 43 | } 44 | 45 | void main() 46 | { 47 | vec2 fragPos = fragTexCoord; 48 | fragPos.xy += uTime/9.0; 49 | 50 | fragPos *= divisions; 51 | vec2 ipos = floor(fragPos); // Get the integer coords 52 | vec2 fpos = fract(fragPos); // Get the fractional coords 53 | 54 | fpos = VectorRotateTime(fpos, 0.2); 55 | 56 | float alpha = Rectangle(fpos, 0.216, 1.0); 57 | vec3 color = vec3(0.3, 0.3, 0.3); 58 | 59 | gl_FragColor = vec4(color, alpha); 60 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/depth.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; // Depth texture 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | 15 | void main() 16 | { 17 | float zNear = 0.01; // camera z near 18 | float zFar = 10.0; // camera z far 19 | float z = texture2D(texture0, fragTexCoord).x; 20 | 21 | // Linearize depth value 22 | float depth = (2.0*zNear)/(zFar + zNear - z*(zFar - zNear)); 23 | 24 | // Calculate final fragment color 25 | gl_FragColor = vec4(depth, depth, depth, 1.0f); 26 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/distortion.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | 8 | // Input uniform values 9 | uniform sampler2D texture0; 10 | 11 | // NOTE: Default parameters for Oculus Rift DK2 device 12 | const vec2 LeftLensCenter = vec2(0.2863248, 0.5); 13 | const vec2 RightLensCenter = vec2(0.7136753, 0.5); 14 | const vec2 LeftScreenCenter = vec2(0.25, 0.5); 15 | const vec2 RightScreenCenter = vec2(0.75, 0.5); 16 | const vec2 Scale = vec2(0.25, 0.45); 17 | const vec2 ScaleIn = vec2(4.0, 2.5); 18 | const vec4 HmdWarpParam = vec4(1.0, 0.22, 0.24, 0.0); 19 | const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.0); 20 | 21 | void main() 22 | { 23 | // The following two variables need to be set per eye 24 | vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter; 25 | vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter; 26 | 27 | // Scales input texture coordinates for distortion: vec2 HmdWarp(vec2 fragTexCoord, vec2 LensCenter) 28 | vec2 theta = (fragTexCoord - LensCenter)*ScaleIn; // Scales to [-1, 1] 29 | float rSq = theta.x*theta.x + theta.y*theta.y; 30 | vec2 theta1 = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq); 31 | //vec2 tc = LensCenter + Scale*theta1; 32 | 33 | // Detect whether blue texture coordinates are out of range since these will scaled out the furthest 34 | vec2 thetaBlue = theta1*(ChromaAbParam.z + ChromaAbParam.w*rSq); 35 | vec2 tcBlue = LensCenter + Scale*thetaBlue; 36 | 37 | if (any(bvec2(clamp(tcBlue, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tcBlue))) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 38 | else 39 | { 40 | // Do blue texture lookup 41 | float blue = texture2D(texture0, tcBlue).b; 42 | 43 | // Do green lookup (no scaling) 44 | vec2 tcGreen = LensCenter + Scale*theta1; 45 | float green = texture2D(texture0, tcGreen).g; 46 | 47 | // Do red scale and lookup 48 | vec2 thetaRed = theta1*(ChromaAbParam.x + ChromaAbParam.y*rSq); 49 | vec2 tcRed = LensCenter + Scale*thetaRed; 50 | float red = texture2D(texture0, tcRed).r; 51 | 52 | gl_FragColor = vec4(red, green, blue, 1.0); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/dream_vision.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | 15 | void main() 16 | { 17 | vec4 color = texture2D(texture0, fragTexCoord); 18 | 19 | color += texture2D(texture0, fragTexCoord + 0.001); 20 | color += texture2D(texture0, fragTexCoord + 0.003); 21 | color += texture2D(texture0, fragTexCoord + 0.005); 22 | color += texture2D(texture0, fragTexCoord + 0.007); 23 | color += texture2D(texture0, fragTexCoord + 0.009); 24 | color += texture2D(texture0, fragTexCoord + 0.011); 25 | 26 | color += texture2D(texture0, fragTexCoord - 0.001); 27 | color += texture2D(texture0, fragTexCoord - 0.003); 28 | color += texture2D(texture0, fragTexCoord - 0.005); 29 | color += texture2D(texture0, fragTexCoord - 0.007); 30 | color += texture2D(texture0, fragTexCoord - 0.009); 31 | color += texture2D(texture0, fragTexCoord - 0.011); 32 | 33 | color.rgb = vec3((color.r + color.g + color.b)/3.0); 34 | color = color/9.5; 35 | 36 | gl_FragColor = color; 37 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/eratosthenes.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | /************************************************************************************* 6 | 7 | The Sieve of Eratosthenes -- a simple shader by ProfJski 8 | An early prime number sieve: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes 9 | 10 | The screen is divided into a square grid of boxes, each representing an integer value. 11 | Each integer is tested to see if it is a prime number. Primes are colored white. 12 | Non-primes are colored with a color that indicates the smallest factor which evenly divdes our integer. 13 | 14 | You can change the scale variable to make a larger or smaller grid. 15 | Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers. 16 | 17 | WARNING: If you make scale too large, your GPU may bog down! 18 | 19 | ***************************************************************************************/ 20 | 21 | // Input vertex attributes (from vertex shader) 22 | varying vec2 fragTexCoord; 23 | varying vec4 fragColor; 24 | 25 | // Make a nice spectrum of colors based on counter and maxSize 26 | vec4 Colorizer(float counter, float maxSize) 27 | { 28 | float red = 0.0, green = 0.0, blue = 0.0; 29 | float normsize = counter/maxSize; 30 | 31 | red = smoothstep(0.3, 0.7, normsize); 32 | green = sin(3.14159*normsize); 33 | blue = 1.0 - smoothstep(0.0, 0.4, normsize); 34 | 35 | return vec4(0.8*red, 0.8*green, 0.8*blue, 1.0); 36 | } 37 | 38 | void main() 39 | { 40 | vec4 color = vec4(1.0); 41 | float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid. 42 | float value = scale*floor(fragTexCoord.y*scale) + floor(fragTexCoord.x*scale); // Group pixels into boxes representing integer values 43 | int valuei = int(value); 44 | 45 | //if ((valuei == 0) || (valuei == 1) || (valuei == 2)) gl_FragColor = vec4(1.0); 46 | //else 47 | { 48 | //for (int i = 2; (i < int(max(2.0, sqrt(value) + 1.0))); i++) 49 | // NOTE: On GLSL 100 for loops are restricted and loop condition must be a constant 50 | // Tested on RPI, it seems loops are limited around 60 iteractions 51 | for (int i = 2; i < 48; i++) 52 | { 53 | if ((value - float(i)*floor(value/float(i))) <= 0.0) 54 | { 55 | gl_FragColor = Colorizer(float(i), scale); 56 | //break; // Uncomment to color by the largest factor instead 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/fisheye.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | 15 | const float PI = 3.1415926535; 16 | 17 | void main() 18 | { 19 | float aperture = 178.0; 20 | float apertureHalf = 0.5 * aperture * (PI / 180.0); 21 | float maxFactor = sin(apertureHalf); 22 | 23 | vec2 uv = vec2(0.0); 24 | vec2 xy = 2.0 * fragTexCoord.xy - 1.0; 25 | float d = length(xy); 26 | 27 | if (d < (2.0 - maxFactor)) 28 | { 29 | d = length(xy * maxFactor); 30 | float z = sqrt(1.0 - d * d); 31 | float r = atan(d, z) / PI; 32 | float phi = atan(xy.y, xy.x); 33 | 34 | uv.x = r * cos(phi) + 0.5; 35 | uv.y = r * sin(phi) + 0.5; 36 | } 37 | else 38 | { 39 | uv = fragTexCoord.xy; 40 | } 41 | 42 | gl_FragColor = texture2D(texture0, uv); 43 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/fog.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec3 fragPosition; 7 | varying vec2 fragTexCoord; 8 | varying vec4 fragColor; 9 | varying vec3 fragNormal; 10 | 11 | // Input uniform values 12 | uniform sampler2D texture0; 13 | uniform vec4 colDiffuse; 14 | 15 | // NOTE: Add here your custom variables 16 | 17 | #define MAX_LIGHTS 4 18 | #define LIGHT_DIRECTIONAL 0 19 | #define LIGHT_POINT 1 20 | 21 | struct MaterialProperty { 22 | vec3 color; 23 | int useSampler; 24 | sampler2D sampler; 25 | }; 26 | 27 | struct Light { 28 | int enabled; 29 | int type; 30 | vec3 position; 31 | vec3 target; 32 | vec4 color; 33 | }; 34 | 35 | // Input lighting values 36 | uniform Light lights[MAX_LIGHTS]; 37 | uniform vec4 ambient; 38 | uniform vec3 viewPos; 39 | uniform float fogDensity; 40 | 41 | void main() 42 | { 43 | // Texel color fetching from texture sampler 44 | vec4 texelColor = texture2D(texture0, fragTexCoord); 45 | vec3 lightDot = vec3(0.0); 46 | vec3 normal = normalize(fragNormal); 47 | vec3 viewD = normalize(viewPos - fragPosition); 48 | vec3 specular = vec3(0.0); 49 | 50 | // NOTE: Implement here your fragment shader code 51 | 52 | for (int i = 0; i < MAX_LIGHTS; i++) 53 | { 54 | if (lights[i].enabled == 1) 55 | { 56 | vec3 light = vec3(0.0); 57 | 58 | if (lights[i].type == LIGHT_DIRECTIONAL) light = -normalize(lights[i].target - lights[i].position); 59 | if (lights[i].type == LIGHT_POINT) light = normalize(lights[i].position - fragPosition); 60 | 61 | float NdotL = max(dot(normal, light), 0.0); 62 | lightDot += lights[i].color.rgb*NdotL; 63 | 64 | float specCo = 0.0; 65 | if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewD, reflect(-(light), normal))), 16.0); // Shine: 16.0 66 | specular += specCo; 67 | } 68 | } 69 | 70 | vec4 finalColor = (texelColor*((colDiffuse + vec4(specular,1))*vec4(lightDot, 1.0))); 71 | finalColor += texelColor*(ambient/10.0); 72 | 73 | // Gamma correction 74 | finalColor = pow(finalColor, vec4(1.0/2.2)); 75 | 76 | // Fog calculation 77 | float dist = length(viewPos - fragPosition); 78 | 79 | // these could be parameters... 80 | const vec4 fogColor = vec4(0.5, 0.5, 0.5, 1.0); 81 | //const float fogDensity = 0.16; 82 | 83 | // Exponential fog 84 | float fogFactor = 1.0/exp((dist*fogDensity)*(dist*fogDensity)); 85 | 86 | // Linear fog (less nice) 87 | //const float fogStart = 2.0; 88 | //const float fogEnd = 10.0; 89 | //float fogFactor = (fogEnd - dist)/(fogEnd - fogStart); 90 | 91 | fogFactor = clamp(fogFactor, 0.0, 1.0); 92 | 93 | gl_FragColor = mix(fogColor, finalColor, fogFactor); 94 | } 95 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/grayscale.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | 15 | void main() 16 | { 17 | // Texel color fetching from texture sampler 18 | vec4 texelColor = texture2D(texture0, fragTexCoord)*colDiffuse*fragColor; 19 | 20 | // Convert texel color to grayscale using NTSC conversion weights 21 | float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); 22 | 23 | // Calculate final fragment color 24 | gl_FragColor = vec4(gray, gray, gray, texelColor.a); 25 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/julia_set.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | uniform vec2 screenDims; // Dimensions of the screen 10 | uniform vec2 c; // c.x = real, c.y = imaginary component. Equation done is z^2 + c 11 | uniform vec2 offset; // Offset of the scale. 12 | uniform float zoom; // Zoom of the scale. 13 | 14 | // NOTE: Maximum number of shader for-loop iterations depend on GPU, 15 | // for example, on RasperryPi for this examply only supports up to 60 16 | const int MAX_ITERATIONS = 48; // Max iterations to do 17 | 18 | // Square a complex number 19 | vec2 ComplexSquare(vec2 z) 20 | { 21 | return vec2( 22 | z.x * z.x - z.y * z.y, 23 | z.x * z.y * 2.0 24 | ); 25 | } 26 | 27 | // Convert Hue Saturation Value (HSV) color into RGB 28 | vec3 Hsv2rgb(vec3 c) 29 | { 30 | vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 31 | vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); 32 | return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); 33 | } 34 | 35 | void main() 36 | { 37 | /********************************************************************************************** 38 | Julia sets use a function z^2 + c, where c is a constant. 39 | This function is iterated until the nature of the point is determined. 40 | 41 | If the magnitude of the number becomes greater than 2, then from that point onward 42 | the number will get bigger and bigger, and will never get smaller (tends towards infinity). 43 | 2^2 = 4, 4^2 = 8 and so on. 44 | So at 2 we stop iterating. 45 | 46 | If the number is below 2, we keep iterating. 47 | But when do we stop iterating if the number is always below 2 (it converges)? 48 | That is what MAX_ITERATIONS is for. 49 | Then we can divide the iterations by the MAX_ITERATIONS value to get a normalized value that we can 50 | then map to a color. 51 | 52 | We use dot product (z.x * z.x + z.y * z.y) to determine the magnitude (length) squared. 53 | And once the magnitude squared is > 4, then magnitude > 2 is also true (saves computational power). 54 | *************************************************************************************************/ 55 | 56 | // The pixel coordinates are scaled so they are on the mandelbrot scale 57 | // NOTE: fragTexCoord already comes as normalized screen coordinates but offset must be normalized before scaling and zoom 58 | vec2 z = vec2((fragTexCoord.x + offset.x/screenDims.x)*2.5/zoom, (fragTexCoord.y + offset.y/screenDims.y)*1.5/zoom); 59 | 60 | int iter = 0; 61 | for (int iterations = 0; iterations < 60; iterations++) 62 | { 63 | z = ComplexSquare(z) + c; // Iterate function 64 | if (dot(z, z) > 4.0) break; 65 | 66 | iter = iterations; 67 | } 68 | 69 | // Another few iterations decreases errors in the smoothing calculation. 70 | // See http://linas.org/art-gallery/escape/escape.html for more information. 71 | z = ComplexSquare(z) + c; 72 | z = ComplexSquare(z) + c; 73 | 74 | // This last part smooths the color (again see link above). 75 | float smoothVal = float(iter) + 1.0 - (log(log(length(z)))/log(2.0)); 76 | 77 | // Normalize the value so it is between 0 and 1. 78 | float norm = smoothVal/float(MAX_ITERATIONS); 79 | 80 | // If in set, color black. 0.999 allows for some float accuracy error. 81 | if (norm > 0.999) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 82 | else gl_FragColor = vec4(Hsv2rgb(vec3(norm, 1.0, 1.0)), 1.0); 83 | } 84 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/lighting.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec3 fragPosition; 7 | varying vec2 fragTexCoord; 8 | varying vec4 fragColor; 9 | varying vec3 fragNormal; 10 | 11 | // Input uniform values 12 | uniform sampler2D texture0; 13 | uniform vec4 colDiffuse; 14 | 15 | // NOTE: Add here your custom variables 16 | 17 | #define MAX_LIGHTS 4 18 | #define LIGHT_DIRECTIONAL 0 19 | #define LIGHT_POINT 1 20 | 21 | struct MaterialProperty { 22 | vec3 color; 23 | int useSampler; 24 | sampler2D sampler; 25 | }; 26 | 27 | struct Light { 28 | int enabled; 29 | int type; 30 | vec3 position; 31 | vec3 target; 32 | vec4 color; 33 | }; 34 | 35 | // Input lighting values 36 | uniform Light lights[MAX_LIGHTS]; 37 | uniform vec4 ambient; 38 | uniform vec3 viewPos; 39 | 40 | void main() 41 | { 42 | // Texel color fetching from texture sampler 43 | vec4 texelColor = texture2D(texture0, fragTexCoord); 44 | vec3 lightDot = vec3(0.0); 45 | vec3 normal = normalize(fragNormal); 46 | vec3 viewD = normalize(viewPos - fragPosition); 47 | vec3 specular = vec3(0.0); 48 | 49 | // NOTE: Implement here your fragment shader code 50 | 51 | for (int i = 0; i < MAX_LIGHTS; i++) 52 | { 53 | if (lights[i].enabled == 1) 54 | { 55 | vec3 light = vec3(0.0); 56 | 57 | if (lights[i].type == LIGHT_DIRECTIONAL) 58 | { 59 | light = -normalize(lights[i].target - lights[i].position); 60 | } 61 | 62 | if (lights[i].type == LIGHT_POINT) 63 | { 64 | light = normalize(lights[i].position - fragPosition); 65 | } 66 | 67 | float NdotL = max(dot(normal, light), 0.0); 68 | lightDot += lights[i].color.rgb*NdotL; 69 | 70 | float specCo = 0.0; 71 | if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewD, reflect(-(light), normal))), 16.0); // 16 refers to shine 72 | specular += specCo; 73 | } 74 | } 75 | 76 | vec4 finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0))); 77 | finalColor += texelColor*(ambient/10.0); 78 | 79 | // Gamma correction 80 | gl_FragColor = pow(finalColor, vec4(1.0/2.2)); 81 | } 82 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/mask.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform sampler2D mask; 12 | uniform vec4 colDiffuse; 13 | uniform int frame; 14 | 15 | // NOTE: Add here your custom variables 16 | 17 | void main() 18 | { 19 | vec4 maskColour = texture2D(mask, fragTexCoord + vec2(sin(-float(frame)/150.0)/10.0, cos(-float(frame)/170.0)/10.0)); 20 | if (maskColour.r < 0.25) discard; 21 | vec4 texelColor = texture2D(texture0, fragTexCoord + vec2(sin(float(frame)/90.0)/8.0, cos(float(frame)/60.0)/8.0)); 22 | 23 | gl_FragColor = texelColor*maskColour; 24 | } 25 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/palette_switch.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | const int colors = 8; 6 | 7 | // Input vertex attributes (from vertex shader) 8 | varying vec2 fragTexCoord; 9 | varying vec4 fragColor; 10 | 11 | // Input uniform values 12 | uniform sampler2D texture0; 13 | uniform ivec3 palette[colors]; 14 | 15 | void main() 16 | { 17 | // Texel color fetching from texture sampler 18 | vec4 texelColor = texture2D(texture0, fragTexCoord)*fragColor; 19 | 20 | // Convert the (normalized) texel color RED component (GB would work, too) 21 | // to the palette index by scaling up from [0, 1] to [0, 255]. 22 | int index = int(texelColor.r*255.0); 23 | 24 | ivec3 color = ivec3(0); 25 | 26 | // NOTE: On GLSL 100 we are not allowed to index a uniform array by a variable value, 27 | // a constantmust be used, so this logic... 28 | if (index == 0) color = palette[0]; 29 | else if (index == 1) color = palette[1]; 30 | else if (index == 2) color = palette[2]; 31 | else if (index == 3) color = palette[3]; 32 | else if (index == 4) color = palette[4]; 33 | else if (index == 5) color = palette[5]; 34 | else if (index == 6) color = palette[6]; 35 | else if (index == 7) color = palette[7]; 36 | 37 | // Calculate final fragment color. Note that the palette color components 38 | // are defined in the range [0, 255] and need to be normalized to [0, 1] 39 | // for OpenGL to work. 40 | gl_FragColor = vec4(float(color.x)/255.0, float(color.y)/255.0, float(color.z)/255.0, texelColor.a); 41 | } 42 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/pixelizer.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | 15 | // NOTE: Render size values must be passed from code 16 | const float renderWidth = 800.0; 17 | const float renderHeight = 450.0; 18 | 19 | float pixelWidth = 5.0; 20 | float pixelHeight = 5.0; 21 | 22 | void main() 23 | { 24 | float dx = pixelWidth*(1.0/renderWidth); 25 | float dy = pixelHeight*(1.0/renderHeight); 26 | 27 | vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy)); 28 | 29 | vec3 tc = texture2D(texture0, coord).rgb; 30 | 31 | gl_FragColor = vec4(tc, 1.0); 32 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/posterization.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | 15 | float gamma = 0.6; 16 | float numColors = 8.0; 17 | 18 | void main() 19 | { 20 | vec3 color = texture2D(texture0, fragTexCoord.xy).rgb; 21 | 22 | color = pow(color, vec3(gamma, gamma, gamma)); 23 | color = color*numColors; 24 | color = floor(color); 25 | color = color/numColors; 26 | color = pow(color, vec3(1.0/gamma)); 27 | 28 | gl_FragColor = vec4(color, 1.0); 29 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/predator.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | 15 | void main() 16 | { 17 | vec3 color = texture2D(texture0, fragTexCoord).rgb; 18 | vec3 colors[3]; 19 | colors[0] = vec3(0.0, 0.0, 1.0); 20 | colors[1] = vec3(1.0, 1.0, 0.0); 21 | colors[2] = vec3(1.0, 0.0, 0.0); 22 | 23 | float lum = (color.r + color.g + color.b)/3.0; 24 | 25 | vec3 tc = vec3(0.0, 0.0, 0.0); 26 | 27 | if (lum < 0.5) tc = mix(colors[0], colors[1], lum/0.5); 28 | else tc = mix(colors[1], colors[2], (lum - 0.5)/0.5); 29 | 30 | gl_FragColor = vec4(tc, 1.0); 31 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/scanlines.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | 15 | float offset = 0.0; 16 | float frequency = 450.0/3.0; 17 | 18 | uniform float time; 19 | 20 | void main() 21 | { 22 | /* 23 | // Scanlines method 1 24 | float tval = 0; //time 25 | vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval)); 26 | 27 | vec4 color = texture2D(texture0, fragTexCoord); 28 | 29 | color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0); 30 | color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y); 31 | color *= vec4(0.8, 1.0, 0.7, 1); 32 | color *= 0.9 + 0.1*sin(10.0*tval + uv.y*1000.0); 33 | color *= 0.97 + 0.03*sin(110.0*tval); 34 | 35 | fragColor = color; 36 | */ 37 | // Scanlines method 2 38 | float globalPos = (fragTexCoord.y + offset) * frequency; 39 | float wavePos = cos((fract(globalPos) - 0.5)*3.14); 40 | 41 | vec4 color = texture2D(texture0, fragTexCoord); 42 | 43 | gl_FragColor = mix(vec4(0.0, 0.3, 0.0, 0.0), color, wavePos); 44 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/sobel.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | vec2 resolution = vec2(800.0, 450.0); 15 | 16 | void main() 17 | { 18 | float x = 1.0/resolution.x; 19 | float y = 1.0/resolution.y; 20 | 21 | vec4 horizEdge = vec4(0.0); 22 | horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; 23 | horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0; 24 | horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; 25 | horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; 26 | horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0; 27 | horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; 28 | 29 | vec4 vertEdge = vec4(0.0); 30 | vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; 31 | vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0; 32 | vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; 33 | vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; 34 | vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0; 35 | vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; 36 | 37 | vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb)); 38 | 39 | gl_FragColor = vec4(edge, texture2D(texture0, fragTexCoord).a); 40 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/spotlight.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | #define MAX_SPOTS 3 6 | 7 | struct Spot { 8 | vec2 pos; // window coords of spot 9 | float inner; // inner fully transparent centre radius 10 | float radius; // alpha fades out to this radius 11 | }; 12 | 13 | uniform Spot spots[MAX_SPOTS]; // Spotlight positions array 14 | uniform float screenWidth; // Width of the screen 15 | 16 | void main() 17 | { 18 | float alpha = 1.0; 19 | 20 | // Get the position of the current fragment (screen coordinates!) 21 | vec2 pos = vec2(gl_FragCoord.x, gl_FragCoord.y); 22 | 23 | // Find out which spotlight is nearest 24 | float d = 65000.0; // some high value 25 | int fi = -1; // found index 26 | 27 | for (int i = 0; i < MAX_SPOTS; i++) 28 | { 29 | for (int j = 0; j < MAX_SPOTS; j++) 30 | { 31 | float dj = distance(pos, spots[j].pos) - spots[j].radius + spots[i].radius; 32 | 33 | if (d > dj) 34 | { 35 | d = dj; 36 | fi = i; 37 | } 38 | } 39 | } 40 | 41 | // d now equals distance to nearest spot... 42 | // allowing for the different radii of all spotlights 43 | if (fi == 0) 44 | { 45 | if (d > spots[0].radius) alpha = 1.0; 46 | else 47 | { 48 | if (d < spots[0].inner) alpha = 0.0; 49 | else alpha = (d - spots[0].inner)/(spots[0].radius - spots[0].inner); 50 | } 51 | } 52 | else if (fi == 1) 53 | { 54 | if (d > spots[1].radius) alpha = 1.0; 55 | else 56 | { 57 | if (d < spots[1].inner) alpha = 0.0; 58 | else alpha = (d - spots[1].inner)/(spots[1].radius - spots[1].inner); 59 | } 60 | } 61 | else if (fi == 2) 62 | { 63 | if (d > spots[2].radius) alpha = 1.0; 64 | else 65 | { 66 | if (d < spots[2].inner) alpha = 0.0; 67 | else alpha = (d - spots[2].inner)/(spots[2].radius - spots[2].inner); 68 | } 69 | } 70 | 71 | // Right hand side of screen is dimly lit, 72 | // could make the threshold value user definable 73 | if ((pos.x > screenWidth/2.0) && (alpha > 0.9)) alpha = 0.9; 74 | 75 | // could make the black out colour user definable... 76 | gl_FragColor = vec4(0, 0, 0, alpha); 77 | } 78 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/swirl.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | 15 | // NOTE: Render size values should be passed from code 16 | const float renderWidth = 800.0; 17 | const float renderHeight = 450.0; 18 | 19 | float radius = 250.0; 20 | float angle = 0.8; 21 | 22 | uniform vec2 center; 23 | 24 | void main() 25 | { 26 | vec2 texSize = vec2(renderWidth, renderHeight); 27 | vec2 tc = fragTexCoord*texSize; 28 | tc -= center; 29 | 30 | float dist = length(tc); 31 | 32 | if (dist < radius) 33 | { 34 | float percent = (radius - dist)/radius; 35 | float theta = percent*percent*angle*8.0; 36 | float s = sin(theta); 37 | float c = cos(theta); 38 | 39 | tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c))); 40 | } 41 | 42 | tc += center; 43 | vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;; 44 | 45 | gl_FragColor = vec4(color.rgb, 1.0);; 46 | } 47 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl100/wave.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | precision mediump float; 4 | 5 | // Input vertex attributes (from vertex shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | uniform float secondes; 14 | 15 | uniform vec2 size; 16 | 17 | uniform float freqX; 18 | uniform float freqY; 19 | uniform float ampX; 20 | uniform float ampY; 21 | uniform float speedX; 22 | uniform float speedY; 23 | 24 | void main() { 25 | float pixelWidth = 1.0 / size.x; 26 | float pixelHeight = 1.0 / size.y; 27 | float aspect = pixelHeight / pixelWidth; 28 | float boxLeft = 0.0; 29 | float boxTop = 0.0; 30 | 31 | vec2 p = fragTexCoord; 32 | p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth; 33 | p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight; 34 | 35 | gl_FragColor = texture2D(texture0, p)*colDiffuse*fragColor; 36 | } 37 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/base.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // NOTE: Add here your custom variables 12 | uniform vec2 resolution = vec2(800, 450); 13 | 14 | void main() 15 | { 16 | // Texel color fetching from texture sampler 17 | vec4 texelColor = texture2D(texture0, fragTexCoord); 18 | 19 | // NOTE: Implement here your fragment shader code 20 | 21 | gl_FragColor = texelColor*colDiffuse; 22 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/base.vs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes 4 | attribute vec3 vertexPosition; 5 | attribute vec2 vertexTexCoord; 6 | attribute vec3 vertexNormal; 7 | attribute vec4 vertexColor; 8 | 9 | // Input uniform values 10 | uniform mat4 mvp; 11 | 12 | // Output vertex attributes (to fragment shader) 13 | varying vec2 fragTexCoord; 14 | varying vec4 fragColor; 15 | 16 | // NOTE: Add here your custom variables 17 | 18 | void main() 19 | { 20 | // Send vertex attributes to fragment shader 21 | fragTexCoord = vertexTexCoord; 22 | fragColor = vertexColor; 23 | 24 | // Calculate final vertex position 25 | gl_Position = mvp*vec4(vertexPosition, 1.0); 26 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/base_lighting.vs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes 4 | attribute vec3 vertexPosition; 5 | attribute vec2 vertexTexCoord; 6 | attribute vec3 vertexNormal; 7 | attribute vec4 vertexColor; 8 | 9 | // Input uniform values 10 | uniform mat4 mvp; 11 | uniform mat4 matModel; 12 | 13 | // Output vertex attributes (to fragment shader) 14 | varying vec3 fragPosition; 15 | varying vec2 fragTexCoord; 16 | varying vec4 fragColor; 17 | varying vec3 fragNormal; 18 | 19 | // NOTE: Add here your custom variables 20 | 21 | // https://github.com/glslify/glsl-inverse 22 | mat3 inverse(mat3 m) 23 | { 24 | float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2]; 25 | float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2]; 26 | float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2]; 27 | 28 | float b01 = a22*a11 - a12*a21; 29 | float b11 = -a22*a10 + a12*a20; 30 | float b21 = a21*a10 - a11*a20; 31 | 32 | float det = a00*b01 + a01*b11 + a02*b21; 33 | 34 | return mat3(b01, (-a22*a01 + a02*a21), (a12*a01 - a02*a11), 35 | b11, (a22*a00 - a02*a20), (-a12*a00 + a02*a10), 36 | b21, (-a21*a00 + a01*a20), (a11*a00 - a01*a10))/det; 37 | } 38 | 39 | // https://github.com/glslify/glsl-transpose 40 | mat3 transpose(mat3 m) 41 | { 42 | return mat3(m[0][0], m[1][0], m[2][0], 43 | m[0][1], m[1][1], m[2][1], 44 | m[0][2], m[1][2], m[2][2]); 45 | } 46 | 47 | void main() 48 | { 49 | // Send vertex attributes to fragment shader 50 | fragPosition = vec3(matModel*vec4(vertexPosition, 1.0)); 51 | fragTexCoord = vertexTexCoord; 52 | fragColor = vertexColor; 53 | 54 | mat3 normalMatrix = transpose(inverse(mat3(matModel))); 55 | fragNormal = normalize(normalMatrix*vertexNormal); 56 | 57 | // Calculate final vertex position 58 | gl_Position = mvp*vec4(vertexPosition, 1.0); 59 | } 60 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/bloom.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // NOTE: Add here your custom variables 12 | 13 | const vec2 size = vec2(800, 450); // render size 14 | const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance 15 | const float quality = 2.5; // lower = smaller glow, better quality 16 | 17 | void main() 18 | { 19 | vec4 sum = vec4(0); 20 | vec2 sizeFactor = vec2(1)/size*quality; 21 | 22 | // Texel color fetching from texture sampler 23 | vec4 source = texture2D(texture0, fragTexCoord); 24 | 25 | const int range = 2; // should be = (samples - 1)/2; 26 | 27 | for (int x = -range; x <= range; x++) 28 | { 29 | for (int y = -range; y <= range; y++) 30 | { 31 | sum += texture2D(texture0, fragTexCoord + vec2(x, y)*sizeFactor); 32 | } 33 | } 34 | 35 | // Calculate final fragment color 36 | gl_FragColor = ((sum/(samples*samples)) + source)*colDiffuse; 37 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/blur.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // NOTE: Add here your custom variables 12 | 13 | // NOTE: Render size values must be passed from code 14 | const float renderWidth = 800.0; 15 | const float renderHeight = 450.0; 16 | 17 | vec3 offset = vec3(0.0, 1.3846153846, 3.2307692308); 18 | vec3 weight = vec3(0.2270270270, 0.3162162162, 0.0702702703); 19 | 20 | void main() 21 | { 22 | // Texel color fetching from texture sampler 23 | vec3 tc = texture2D(texture0, fragTexCoord).rgb*weight.x; 24 | 25 | tc += texture2D(texture0, fragTexCoord + vec2(offset.y)/renderWidth, 0.0).rgb*weight.y; 26 | tc += texture2D(texture0, fragTexCoord - vec2(offset.y)/renderWidth, 0.0).rgb*weight.y; 27 | 28 | tc += texture2D(texture0, fragTexCoord + vec2(offset.z)/renderWidth, 0.0).rgb*weight.z; 29 | tc += texture2D(texture0, fragTexCoord - vec2(offset.z)/renderWidth, 0.0).rgb*weight.z; 30 | 31 | gl_FragColor = vec4(tc, 1.0); 32 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/cross_hatching.fs: -------------------------------------------------------------------------------- 1 | # version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // NOTE: Add here your custom variables 12 | 13 | float hatchOffsetY = 5.0; 14 | float lumThreshold01 = 0.9; 15 | float lumThreshold02 = 0.7; 16 | float lumThreshold03 = 0.5; 17 | float lumThreshold04 = 0.3; 18 | 19 | void main() 20 | { 21 | vec3 tc = vec3(1.0, 1.0, 1.0); 22 | float lum = length(texture2D(texture0, fragTexCoord).rgb); 23 | 24 | if (lum < lumThreshold01) 25 | { 26 | if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 27 | } 28 | 29 | if (lum < lumThreshold02) 30 | { 31 | if (mod(gl_FragCoord .x - gl_FragCoord .y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 32 | } 33 | 34 | if (lum < lumThreshold03) 35 | { 36 | if (mod(gl_FragCoord .x + gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 37 | } 38 | 39 | if (lum < lumThreshold04) 40 | { 41 | if (mod(gl_FragCoord .x - gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 42 | } 43 | 44 | gl_FragColor = vec4(tc, 1.0); 45 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/cross_stitching.fs: -------------------------------------------------------------------------------- 1 | # version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // NOTE: Add here your custom variables 12 | 13 | // NOTE: Render size values must be passed from code 14 | const float renderWidth = 800.0; 15 | const float renderHeight = 450.0; 16 | 17 | float stitchingSize = 6.0; 18 | int invert = 0; 19 | 20 | vec4 PostFX(sampler2D tex, vec2 uv) 21 | { 22 | vec4 c = vec4(0.0); 23 | float size = stitchingSize; 24 | vec2 cPos = uv * vec2(renderWidth, renderHeight); 25 | vec2 tlPos = floor(cPos / vec2(size, size)); 26 | tlPos *= size; 27 | 28 | int remX = int(mod(cPos.x, size)); 29 | int remY = int(mod(cPos.y, size)); 30 | 31 | if (remX == 0 && remY == 0) tlPos = cPos; 32 | 33 | vec2 blPos = tlPos; 34 | blPos.y += (size - 1.0); 35 | 36 | if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y))))) 37 | { 38 | if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0); 39 | else c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; 40 | } 41 | else 42 | { 43 | if (invert == 1) c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; 44 | else c = vec4(0.0, 0.0, 0.0, 1.0); 45 | } 46 | 47 | return c; 48 | } 49 | 50 | void main() 51 | { 52 | vec3 tc = PostFX(texture0, fragTexCoord).rgb; 53 | 54 | gl_FragColor = vec4(tc, 1.0); 55 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/distortion.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | 6 | // Input uniform values 7 | uniform sampler2D texture0; 8 | 9 | // NOTE: Default parameters for Oculus Rift DK2 device 10 | const vec2 LeftLensCenter = vec2(0.2863248, 0.5); 11 | const vec2 RightLensCenter = vec2(0.7136753, 0.5); 12 | const vec2 LeftScreenCenter = vec2(0.25, 0.5); 13 | const vec2 RightScreenCenter = vec2(0.75, 0.5); 14 | const vec2 Scale = vec2(0.25, 0.45); 15 | const vec2 ScaleIn = vec2(4.0, 2.5); 16 | const vec4 HmdWarpParam = vec4(1.0, 0.22, 0.24, 0.0); 17 | const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.0); 18 | 19 | void main() 20 | { 21 | // The following two variables need to be set per eye 22 | vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter; 23 | vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter; 24 | 25 | // Scales input texture coordinates for distortion: vec2 HmdWarp(vec2 fragTexCoord, vec2 LensCenter) 26 | vec2 theta = (fragTexCoord - LensCenter)*ScaleIn; // Scales to [-1, 1] 27 | float rSq = theta.x*theta.x + theta.y*theta.y; 28 | vec2 theta1 = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq); 29 | //vec2 tc = LensCenter + Scale*theta1; 30 | 31 | // Detect whether blue texture coordinates are out of range since these will scaled out the furthest 32 | vec2 thetaBlue = theta1*(ChromaAbParam.z + ChromaAbParam.w*rSq); 33 | vec2 tcBlue = LensCenter + Scale*thetaBlue; 34 | 35 | if (any(bvec2(clamp(tcBlue, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tcBlue))) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 36 | else 37 | { 38 | // Do blue texture lookup 39 | float blue = texture2D(texture0, tcBlue).b; 40 | 41 | // Do green lookup (no scaling) 42 | vec2 tcGreen = LensCenter + Scale*theta1; 43 | float green = texture2D(texture0, tcGreen).g; 44 | 45 | // Do red scale and lookup 46 | vec2 thetaRed = theta1*(ChromaAbParam.x + ChromaAbParam.y*rSq); 47 | vec2 tcRed = LensCenter + Scale*thetaRed; 48 | float red = texture2D(texture0, tcRed).r; 49 | 50 | gl_FragColor = vec4(red, green, blue, 1.0); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/dream_vision.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // NOTE: Add here your custom variables 12 | 13 | void main() 14 | { 15 | vec4 color = texture2D(texture0, fragTexCoord); 16 | 17 | color += texture2D(texture0, fragTexCoord + 0.001); 18 | color += texture2D(texture0, fragTexCoord + 0.003); 19 | color += texture2D(texture0, fragTexCoord + 0.005); 20 | color += texture2D(texture0, fragTexCoord + 0.007); 21 | color += texture2D(texture0, fragTexCoord + 0.009); 22 | color += texture2D(texture0, fragTexCoord + 0.011); 23 | 24 | color += texture2D(texture0, fragTexCoord - 0.001); 25 | color += texture2D(texture0, fragTexCoord - 0.003); 26 | color += texture2D(texture0, fragTexCoord - 0.005); 27 | color += texture2D(texture0, fragTexCoord - 0.007); 28 | color += texture2D(texture0, fragTexCoord - 0.009); 29 | color += texture2D(texture0, fragTexCoord - 0.011); 30 | 31 | color.rgb = vec3((color.r + color.g + color.b)/3.0); 32 | color = color/9.5; 33 | 34 | gl_FragColor = color; 35 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/fisheye.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // NOTE: Add here your custom variables 12 | 13 | const float PI = 3.1415926535; 14 | 15 | void main() 16 | { 17 | float aperture = 178.0; 18 | float apertureHalf = 0.5 * aperture * (PI / 180.0); 19 | float maxFactor = sin(apertureHalf); 20 | 21 | vec2 uv = vec2(0.0); 22 | vec2 xy = 2.0 * fragTexCoord.xy - 1.0; 23 | float d = length(xy); 24 | 25 | if (d < (2.0 - maxFactor)) 26 | { 27 | d = length(xy * maxFactor); 28 | float z = sqrt(1.0 - d * d); 29 | float r = atan(d, z) / PI; 30 | float phi = atan(xy.y, xy.x); 31 | 32 | uv.x = r * cos(phi) + 0.5; 33 | uv.y = r * sin(phi) + 0.5; 34 | } 35 | else 36 | { 37 | uv = fragTexCoord.xy; 38 | } 39 | 40 | gl_FragColor = texture2D(texture0, uv); 41 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/fog.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec3 fragPosition; 5 | varying vec2 fragTexCoord; 6 | varying vec4 fragColor; 7 | varying vec3 fragNormal; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // NOTE: Add here your custom variables 14 | 15 | #define MAX_LIGHTS 4 16 | #define LIGHT_DIRECTIONAL 0 17 | #define LIGHT_POINT 1 18 | 19 | struct MaterialProperty { 20 | vec3 color; 21 | int useSampler; 22 | sampler2D sampler; 23 | }; 24 | 25 | struct Light { 26 | int enabled; 27 | int type; 28 | vec3 position; 29 | vec3 target; 30 | vec4 color; 31 | }; 32 | 33 | // Input lighting values 34 | uniform Light lights[MAX_LIGHTS]; 35 | uniform vec4 ambient; 36 | uniform vec3 viewPos; 37 | uniform float fogDensity; 38 | 39 | void main() 40 | { 41 | // Texel color fetching from texture sampler 42 | vec4 texelColor = texture2D(texture0, fragTexCoord); 43 | vec3 lightDot = vec3(0.0); 44 | vec3 normal = normalize(fragNormal); 45 | vec3 viewD = normalize(viewPos - fragPosition); 46 | vec3 specular = vec3(0.0); 47 | 48 | // NOTE: Implement here your fragment shader code 49 | 50 | for (int i = 0; i < MAX_LIGHTS; i++) 51 | { 52 | if (lights[i].enabled == 1) 53 | { 54 | vec3 light = vec3(0.0); 55 | 56 | if (lights[i].type == LIGHT_DIRECTIONAL) light = -normalize(lights[i].target - lights[i].position); 57 | if (lights[i].type == LIGHT_POINT) light = normalize(lights[i].position - fragPosition); 58 | 59 | float NdotL = max(dot(normal, light), 0.0); 60 | lightDot += lights[i].color.rgb*NdotL; 61 | 62 | float specCo = 0.0; 63 | if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewD, reflect(-(light), normal))), 16.0); // Shine: 16.0 64 | specular += specCo; 65 | } 66 | } 67 | 68 | vec4 finalColor = (texelColor*((colDiffuse + vec4(specular,1))*vec4(lightDot, 1.0))); 69 | finalColor += texelColor*(ambient/10.0); 70 | 71 | // Gamma correction 72 | finalColor = pow(finalColor, vec4(1.0/2.2)); 73 | 74 | // Fog calculation 75 | float dist = length(viewPos - fragPosition); 76 | 77 | // these could be parameters... 78 | const vec4 fogColor = vec4(0.5, 0.5, 0.5, 1.0); 79 | //const float fogDensity = 0.16; 80 | 81 | // Exponential fog 82 | float fogFactor = 1.0/exp((dist*fogDensity)*(dist*fogDensity)); 83 | 84 | // Linear fog (less nice) 85 | //const float fogStart = 2.0; 86 | //const float fogEnd = 10.0; 87 | //float fogFactor = (fogEnd - dist)/(fogEnd - fogStart); 88 | 89 | fogFactor = clamp(fogFactor, 0.0, 1.0); 90 | 91 | gl_FragColor = mix(fogColor, finalColor, fogFactor); 92 | } 93 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/grayscale.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // NOTE: Add here your custom variables 12 | 13 | void main() 14 | { 15 | // Texel color fetching from texture sampler 16 | vec4 texelColor = texture2D(texture0, fragTexCoord)*colDiffuse*fragColor; 17 | 18 | // Convert texel color to grayscale using NTSC conversion weights 19 | float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); 20 | 21 | // Calculate final fragment color 22 | gl_FragColor = vec4(gray, gray, gray, texelColor.a); 23 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/palette_switch.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | const int colors = 8; 4 | 5 | // Input fragment attributes (from fragment shader) 6 | varying vec2 fragTexCoord; 7 | varying vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform ivec3 palette[colors]; 12 | 13 | void main() 14 | { 15 | // Texel color fetching from texture sampler 16 | vec4 texelColor = texture(texture0, fragTexCoord) * fragColor; 17 | 18 | // Convert the (normalized) texel color RED component (GB would work, too) 19 | // to the palette index by scaling up from [0, 1] to [0, 255]. 20 | int index = int(texelColor.r * 255.0); 21 | ivec3 color = palette[index]; 22 | 23 | // Calculate final fragment color. Note that the palette color components 24 | // are defined in the range [0, 255] and need to be normalized to [0, 1] 25 | // for OpenGL to work. 26 | gl_FragColor = vec4(color / 255.0, texelColor.a); 27 | } 28 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/pixelizer.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // NOTE: Add here your custom variables 12 | 13 | // NOTE: Render size values must be passed from code 14 | const float renderWidth = 800.0; 15 | const float renderHeight = 450.0; 16 | 17 | float pixelWidth = 5.0; 18 | float pixelHeight = 5.0; 19 | 20 | void main() 21 | { 22 | float dx = pixelWidth*(1.0/renderWidth); 23 | float dy = pixelHeight*(1.0/renderHeight); 24 | 25 | vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy)); 26 | 27 | vec3 tc = texture2D(texture0, coord).rgb; 28 | 29 | gl_FragColor = vec4(tc, 1.0); 30 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/posterization.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // NOTE: Add here your custom variables 12 | 13 | float gamma = 0.6; 14 | float numColors = 8.0; 15 | 16 | void main() 17 | { 18 | vec3 color = texture2D(texture0, fragTexCoord.xy).rgb; 19 | 20 | color = pow(color, vec3(gamma, gamma, gamma)); 21 | color = color*numColors; 22 | color = floor(color); 23 | color = color/numColors; 24 | color = pow(color, vec3(1.0/gamma)); 25 | 26 | gl_FragColor = vec4(color, 1.0); 27 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/predator.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // NOTE: Add here your custom variables 12 | 13 | void main() 14 | { 15 | vec3 color = texture2D(texture0, fragTexCoord).rgb; 16 | vec3 colors[3]; 17 | colors[0] = vec3(0.0, 0.0, 1.0); 18 | colors[1] = vec3(1.0, 1.0, 0.0); 19 | colors[2] = vec3(1.0, 0.0, 0.0); 20 | 21 | float lum = (color.r + color.g + color.b)/3.0; 22 | 23 | vec3 tc = vec3(0.0, 0.0, 0.0); 24 | 25 | if (lum < 0.5) tc = mix(colors[0], colors[1], lum/0.5); 26 | else tc = mix(colors[1], colors[2], (lum - 0.5)/0.5); 27 | 28 | gl_FragColor = vec4(tc, 1.0); 29 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/scanlines.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // NOTE: Add here your custom variables 12 | 13 | float offset = 0.0; 14 | float frequency = 450.0/3.0; 15 | 16 | uniform float time; 17 | 18 | void main() 19 | { 20 | /* 21 | // Scanlines method 1 22 | float tval = 0; //time 23 | vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval)); 24 | 25 | vec4 color = texture2D(texture0, fragTexCoord); 26 | 27 | color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0); 28 | color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y); 29 | color *= vec4(0.8, 1.0, 0.7, 1); 30 | color *= 0.9 + 0.1*sin(10.0*tval + uv.y*1000.0); 31 | color *= 0.97 + 0.03*sin(110.0*tval); 32 | 33 | fragColor = color; 34 | */ 35 | // Scanlines method 2 36 | float globalPos = (fragTexCoord.y + offset) * frequency; 37 | float wavePos = cos((fract(globalPos) - 0.5)*3.14); 38 | 39 | vec4 color = texture2D(texture0, fragTexCoord); 40 | 41 | gl_FragColor = mix(vec4(0.0, 0.3, 0.0, 0.0), color, wavePos); 42 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/sobel.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // NOTE: Add here your custom variables 12 | vec2 resolution = vec2(800.0, 450.0); 13 | 14 | void main() 15 | { 16 | float x = 1.0/resolution.x; 17 | float y = 1.0/resolution.y; 18 | 19 | vec4 horizEdge = vec4(0.0); 20 | horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; 21 | horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0; 22 | horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; 23 | horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; 24 | horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0; 25 | horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; 26 | 27 | vec4 vertEdge = vec4(0.0); 28 | vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; 29 | vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0; 30 | vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; 31 | vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; 32 | vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0; 33 | vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; 34 | 35 | vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb)); 36 | 37 | gl_FragColor = vec4(edge, texture2D(texture0, fragTexCoord).a); 38 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl120/swirl.fs: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // NOTE: Add here your custom variables 12 | 13 | // NOTE: Render size values should be passed from code 14 | const float renderWidth = 800; 15 | const float renderHeight = 450; 16 | 17 | float radius = 250.0; 18 | float angle = 0.8; 19 | 20 | uniform vec2 center; 21 | 22 | void main() 23 | { 24 | vec2 texSize = vec2(renderWidth, renderHeight); 25 | vec2 tc = fragTexCoord*texSize; 26 | tc -= center; 27 | 28 | float dist = length(tc); 29 | 30 | if (dist < radius) 31 | { 32 | float percent = (radius - dist)/radius; 33 | float theta = percent*percent*angle*8.0; 34 | float s = sin(theta); 35 | float c = cos(theta); 36 | 37 | tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c))); 38 | } 39 | 40 | tc += center; 41 | vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;; 42 | 43 | gl_FragColor = vec4(color.rgb, 1.0);; 44 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/base.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | void main() 17 | { 18 | // Texel color fetching from texture sampler 19 | vec4 texelColor = texture(texture0, fragTexCoord); 20 | 21 | // NOTE: Implement here your fragment shader code 22 | 23 | finalColor = texelColor*colDiffuse; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/base.vs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes 4 | in vec3 vertexPosition; 5 | in vec2 vertexTexCoord; 6 | in vec3 vertexNormal; 7 | in vec4 vertexColor; 8 | 9 | // Input uniform values 10 | uniform mat4 mvp; 11 | 12 | // Output vertex attributes (to fragment shader) 13 | out vec2 fragTexCoord; 14 | out vec4 fragColor; 15 | 16 | // NOTE: Add here your custom variables 17 | 18 | void main() 19 | { 20 | // Send vertex attributes to fragment shader 21 | fragTexCoord = vertexTexCoord; 22 | fragColor = vertexColor; 23 | 24 | // Calculate final vertex position 25 | gl_Position = mvp*vec4(vertexPosition, 1.0); 26 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/base_lighting.vs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes 4 | in vec3 vertexPosition; 5 | in vec2 vertexTexCoord; 6 | in vec3 vertexNormal; 7 | in vec4 vertexColor; 8 | 9 | // Input uniform values 10 | uniform mat4 mvp; 11 | uniform mat4 matModel; 12 | 13 | // Output vertex attributes (to fragment shader) 14 | out vec3 fragPosition; 15 | out vec2 fragTexCoord; 16 | out vec4 fragColor; 17 | out vec3 fragNormal; 18 | 19 | // NOTE: Add here your custom variables 20 | 21 | void main() 22 | { 23 | // Send vertex attributes to fragment shader 24 | fragPosition = vec3(matModel*vec4(vertexPosition, 1.0)); 25 | fragTexCoord = vertexTexCoord; 26 | fragColor = vertexColor; 27 | 28 | mat3 normalMatrix = transpose(inverse(mat3(matModel))); 29 | fragNormal = normalize(normalMatrix*vertexNormal); 30 | 31 | // Calculate final vertex position 32 | gl_Position = mvp*vec4(vertexPosition, 1.0); 33 | } 34 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/bloom.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | const vec2 size = vec2(800, 450); // render size 17 | const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance 18 | const float quality = 2.5; // lower = smaller glow, better quality 19 | 20 | void main() 21 | { 22 | vec4 sum = vec4(0); 23 | vec2 sizeFactor = vec2(1)/size*quality; 24 | 25 | // Texel color fetching from texture sampler 26 | vec4 source = texture(texture0, fragTexCoord); 27 | 28 | const int range = 2; // should be = (samples - 1)/2; 29 | 30 | for (int x = -range; x <= range; x++) 31 | { 32 | for (int y = -range; y <= range; y++) 33 | { 34 | sum += texture(texture0, fragTexCoord + vec2(x, y)*sizeFactor); 35 | } 36 | } 37 | 38 | // Calculate final fragment color 39 | finalColor = ((sum/(samples*samples)) + source)*colDiffuse; 40 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/blur.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | // NOTE: Render size values must be passed from code 17 | const float renderWidth = 800; 18 | const float renderHeight = 450; 19 | 20 | float offset[3] = float[](0.0, 1.3846153846, 3.2307692308); 21 | float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703); 22 | 23 | void main() 24 | { 25 | // Texel color fetching from texture sampler 26 | vec3 texelColor = texture(texture0, fragTexCoord).rgb*weight[0]; 27 | 28 | for (int i = 1; i < 3; i++) 29 | { 30 | texelColor += texture(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; 31 | texelColor += texture(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; 32 | } 33 | 34 | finalColor = vec4(texelColor, 1.0); 35 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/cross_hatching.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | float hatchOffsetY = 5.0; 17 | float lumThreshold01 = 0.9; 18 | float lumThreshold02 = 0.7; 19 | float lumThreshold03 = 0.5; 20 | float lumThreshold04 = 0.3; 21 | 22 | void main() 23 | { 24 | vec3 tc = vec3(1.0, 1.0, 1.0); 25 | float lum = length(texture(texture0, fragTexCoord).rgb); 26 | 27 | if (lum < lumThreshold01) 28 | { 29 | if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 30 | } 31 | 32 | if (lum < lumThreshold02) 33 | { 34 | if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 35 | } 36 | 37 | if (lum < lumThreshold03) 38 | { 39 | if (mod(gl_FragCoord.x + gl_FragCoord.y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 40 | } 41 | 42 | if (lum < lumThreshold04) 43 | { 44 | if (mod(gl_FragCoord.x - gl_FragCoord.y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); 45 | } 46 | 47 | finalColor = vec4(tc, 1.0); 48 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/cross_stitching.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | // NOTE: Render size values must be passed from code 17 | const float renderWidth = 800.0; 18 | const float renderHeight = 450.0; 19 | 20 | float stitchingSize = 6.0; 21 | 22 | uniform int invert = 0; 23 | 24 | vec4 PostFX(sampler2D tex, vec2 uv) 25 | { 26 | vec4 c = vec4(0.0); 27 | float size = stitchingSize; 28 | vec2 cPos = uv * vec2(renderWidth, renderHeight); 29 | vec2 tlPos = floor(cPos / vec2(size, size)); 30 | tlPos *= size; 31 | 32 | int remX = int(mod(cPos.x, size)); 33 | int remY = int(mod(cPos.y, size)); 34 | 35 | if (remX == 0 && remY == 0) tlPos = cPos; 36 | 37 | vec2 blPos = tlPos; 38 | blPos.y += (size - 1.0); 39 | 40 | if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y))))) 41 | { 42 | if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0); 43 | else c = texture(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; 44 | } 45 | else 46 | { 47 | if (invert == 1) c = texture(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; 48 | else c = vec4(0.0, 0.0, 0.0, 1.0); 49 | } 50 | 51 | return c; 52 | } 53 | 54 | void main() 55 | { 56 | vec3 tc = PostFX(texture0, fragTexCoord).rgb; 57 | 58 | finalColor = vec4(tc, 1.0); 59 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/cubes_panning.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Output fragment color 8 | out vec4 finalColor; 9 | 10 | // Custom variables 11 | #define PI 3.14159265358979323846 12 | uniform float uTime = 0.0; 13 | 14 | float divisions = 5.0; 15 | float angle = 0.0; 16 | 17 | vec2 VectorRotateTime(vec2 v, float speed) 18 | { 19 | float time = uTime*speed; 20 | float localTime = fract(time); // The time domain this works on is 1 sec. 21 | 22 | if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0; 23 | else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4*sin(2*PI*localTime - PI/2); 24 | else if ((localTime >= 0.50) && (localTime < 0.75)) angle = PI*0.25; 25 | else if ((localTime >= 0.75) && (localTime < 1.00)) angle = PI/4*sin(2*PI*localTime); 26 | 27 | // Rotate vector by angle 28 | v -= 0.5; 29 | v = mat2(cos(angle), -sin(angle), sin(angle), cos(angle))*v; 30 | v += 0.5; 31 | 32 | return v; 33 | } 34 | 35 | float Rectangle(in vec2 st, in float size, in float fill) 36 | { 37 | float roundSize = 0.5 - size/2.0; 38 | float left = step(roundSize, st.x); 39 | float top = step(roundSize, st.y); 40 | float bottom = step(roundSize, 1.0 - st.y); 41 | float right = step(roundSize, 1.0 - st.x); 42 | 43 | return (left*bottom*right*top)*fill; 44 | } 45 | 46 | void main() 47 | { 48 | vec2 fragPos = fragTexCoord; 49 | fragPos.xy += uTime/9.0; 50 | 51 | fragPos *= divisions; 52 | vec2 ipos = floor(fragPos); // Get the integer coords 53 | vec2 fpos = fract(fragPos); // Get the fractional coords 54 | 55 | fpos = VectorRotateTime(fpos, 0.2); 56 | 57 | float alpha = Rectangle(fpos, 0.216, 1.0); 58 | vec3 color = vec3(0.3, 0.3, 0.3); 59 | 60 | finalColor = vec4(color, alpha); 61 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/depth.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; // Depth texture 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | void main() 17 | { 18 | float zNear = 0.01; // camera z near 19 | float zFar = 10.0; // camera z far 20 | float z = texture(texture0, fragTexCoord).x; 21 | 22 | // Linearize depth value 23 | float depth = (2.0*zNear)/(zFar + zNear - z*(zFar - zNear)); 24 | 25 | // Calculate final fragment color 26 | finalColor = vec4(depth, depth, depth, 1.0f); 27 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/distortion.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | 6 | // Input uniform values 7 | uniform sampler2D texture0; 8 | 9 | // Output fragment color 10 | out vec4 finalColor; 11 | 12 | // NOTE: Default parameters for Oculus Rift DK2 device 13 | const vec2 LeftLensCenter = vec2(0.2863248, 0.5); 14 | const vec2 RightLensCenter = vec2(0.7136753, 0.5); 15 | const vec2 LeftScreenCenter = vec2(0.25, 0.5); 16 | const vec2 RightScreenCenter = vec2(0.75, 0.5); 17 | const vec2 Scale = vec2(0.25, 0.45); 18 | const vec2 ScaleIn = vec2(4.0, 2.5); 19 | const vec4 HmdWarpParam = vec4(1.0, 0.22, 0.24, 0.0); 20 | const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.0); 21 | 22 | void main() 23 | { 24 | // The following two variables need to be set per eye 25 | vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter; 26 | vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter; 27 | 28 | // Scales input texture coordinates for distortion: vec2 HmdWarp(vec2 fragTexCoord, vec2 LensCenter) 29 | vec2 theta = (fragTexCoord - LensCenter)*ScaleIn; // Scales to [-1, 1] 30 | float rSq = theta.x*theta.x + theta.y*theta.y; 31 | vec2 theta1 = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq); 32 | //vec2 tc = LensCenter + Scale*theta1; 33 | 34 | // Detect whether blue texture coordinates are out of range since these will scaled out the furthest 35 | vec2 thetaBlue = theta1*(ChromaAbParam.z + ChromaAbParam.w*rSq); 36 | vec2 tcBlue = LensCenter + Scale*thetaBlue; 37 | 38 | if (any(bvec2(clamp(tcBlue, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tcBlue))) finalColor = vec4(0.0, 0.0, 0.0, 1.0); 39 | else 40 | { 41 | // Do blue texture lookup 42 | float blue = texture(texture0, tcBlue).b; 43 | 44 | // Do green lookup (no scaling) 45 | vec2 tcGreen = LensCenter + Scale*theta1; 46 | float green = texture(texture0, tcGreen).g; 47 | 48 | // Do red scale and lookup 49 | vec2 thetaRed = theta1*(ChromaAbParam.x + ChromaAbParam.y*rSq); 50 | vec2 tcRed = LensCenter + Scale*thetaRed; 51 | float red = texture(texture0, tcRed).r; 52 | 53 | finalColor = vec4(red, green, blue, 1.0); 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/dream_vision.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 fragTexCoord; 4 | 5 | out vec4 fragColor; 6 | 7 | uniform sampler2D texture0; 8 | uniform vec4 colDiffuse; 9 | 10 | // NOTE: Add here your custom variables 11 | 12 | void main() 13 | { 14 | vec4 color = texture(texture0, fragTexCoord); 15 | 16 | color += texture(texture0, fragTexCoord + 0.001); 17 | color += texture(texture0, fragTexCoord + 0.003); 18 | color += texture(texture0, fragTexCoord + 0.005); 19 | color += texture(texture0, fragTexCoord + 0.007); 20 | color += texture(texture0, fragTexCoord + 0.009); 21 | color += texture(texture0, fragTexCoord + 0.011); 22 | 23 | color += texture(texture0, fragTexCoord - 0.001); 24 | color += texture(texture0, fragTexCoord - 0.003); 25 | color += texture(texture0, fragTexCoord - 0.005); 26 | color += texture(texture0, fragTexCoord - 0.007); 27 | color += texture(texture0, fragTexCoord - 0.009); 28 | color += texture(texture0, fragTexCoord - 0.011); 29 | 30 | color.rgb = vec3((color.r + color.g + color.b)/3.0); 31 | color = color/9.5; 32 | 33 | fragColor = color; 34 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/eratosthenes.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | /************************************************************************************* 4 | 5 | The Sieve of Eratosthenes -- a simple shader by ProfJski 6 | An early prime number sieve: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes 7 | 8 | The screen is divided into a square grid of boxes, each representing an integer value. 9 | Each integer is tested to see if it is a prime number. Primes are colored white. 10 | Non-primes are colored with a color that indicates the smallest factor which evenly divdes our integer. 11 | 12 | You can change the scale variable to make a larger or smaller grid. 13 | Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers. 14 | 15 | WARNING: If you make scale too large, your GPU may bog down! 16 | 17 | ***************************************************************************************/ 18 | 19 | // Input vertex attributes (from vertex shader) 20 | in vec2 fragTexCoord; 21 | in vec4 fragColor; 22 | 23 | // Output fragment color 24 | out vec4 finalColor; 25 | 26 | // Make a nice spectrum of colors based on counter and maxSize 27 | vec4 Colorizer(float counter, float maxSize) 28 | { 29 | float red = 0.0, green = 0.0, blue = 0.0; 30 | float normsize = counter/maxSize; 31 | 32 | red = smoothstep(0.3, 0.7, normsize); 33 | green = sin(3.14159*normsize); 34 | blue = 1.0 - smoothstep(0.0, 0.4, normsize); 35 | 36 | return vec4(0.8*red, 0.8*green, 0.8*blue, 1.0); 37 | } 38 | 39 | void main() 40 | { 41 | vec4 color = vec4(1.0); 42 | float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid. 43 | int value = int(scale*floor(fragTexCoord.y*scale)+floor(fragTexCoord.x*scale)); // Group pixels into boxes representing integer values 44 | 45 | if ((value == 0) || (value == 1) || (value == 2)) finalColor = vec4(1.0); 46 | else 47 | { 48 | for (int i = 2; (i < max(2, sqrt(value) + 1)); i++) 49 | { 50 | if ((value - i*floor(value/i)) == 0) 51 | { 52 | color = Colorizer(float(i), scale); 53 | //break; // Uncomment to color by the largest factor instead 54 | } 55 | } 56 | 57 | finalColor = color; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/fisheye.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 fragTexCoord; 4 | 5 | out vec4 fragColor; 6 | 7 | uniform sampler2D texture0; 8 | uniform vec4 colDiffuse; 9 | 10 | // NOTE: Add here your custom variables 11 | 12 | const float PI = 3.1415926535; 13 | 14 | void main() 15 | { 16 | float aperture = 178.0; 17 | float apertureHalf = 0.5 * aperture * (PI / 180.0); 18 | float maxFactor = sin(apertureHalf); 19 | 20 | vec2 uv = vec2(0); 21 | vec2 xy = 2.0 * fragTexCoord.xy - 1.0; 22 | float d = length(xy); 23 | 24 | if (d < (2.0 - maxFactor)) 25 | { 26 | d = length(xy * maxFactor); 27 | float z = sqrt(1.0 - d * d); 28 | float r = atan(d, z) / PI; 29 | float phi = atan(xy.y, xy.x); 30 | 31 | uv.x = r * cos(phi) + 0.5; 32 | uv.y = r * sin(phi) + 0.5; 33 | } 34 | else 35 | { 36 | uv = fragTexCoord.xy; 37 | } 38 | 39 | fragColor = texture(texture0, uv); 40 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/fog.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | in vec3 fragPosition; 7 | in vec3 fragNormal; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // Output fragment color 14 | out vec4 finalColor; 15 | 16 | // NOTE: Add here your custom variables 17 | 18 | #define MAX_LIGHTS 4 19 | #define LIGHT_DIRECTIONAL 0 20 | #define LIGHT_POINT 1 21 | 22 | struct MaterialProperty { 23 | vec3 color; 24 | int useSampler; 25 | sampler2D sampler; 26 | }; 27 | 28 | struct Light { 29 | int enabled; 30 | int type; 31 | vec3 position; 32 | vec3 target; 33 | vec4 color; 34 | }; 35 | 36 | // Input lighting values 37 | uniform Light lights[MAX_LIGHTS]; 38 | uniform vec4 ambient; 39 | uniform vec3 viewPos; 40 | uniform float fogDensity; 41 | 42 | void main() 43 | { 44 | // Texel color fetching from texture sampler 45 | vec4 texelColor = texture(texture0, fragTexCoord); 46 | vec3 lightDot = vec3(0.0); 47 | vec3 normal = normalize(fragNormal); 48 | vec3 viewD = normalize(viewPos - fragPosition); 49 | vec3 specular = vec3(0.0); 50 | 51 | // NOTE: Implement here your fragment shader code 52 | 53 | for (int i = 0; i < MAX_LIGHTS; i++) 54 | { 55 | if (lights[i].enabled == 1) 56 | { 57 | vec3 light = vec3(0.0); 58 | 59 | if (lights[i].type == LIGHT_DIRECTIONAL) light = -normalize(lights[i].target - lights[i].position); 60 | if (lights[i].type == LIGHT_POINT) light = normalize(lights[i].position - fragPosition); 61 | 62 | float NdotL = max(dot(normal, light), 0.0); 63 | lightDot += lights[i].color.rgb*NdotL; 64 | 65 | float specCo = 0.0; 66 | if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewD, reflect(-(light), normal))), 16.0); // Shine: 16.0 67 | specular += specCo; 68 | } 69 | } 70 | 71 | finalColor = (texelColor*((colDiffuse + vec4(specular,1))*vec4(lightDot, 1.0))); 72 | finalColor += texelColor*(ambient/10.0); 73 | 74 | // Gamma correction 75 | finalColor = pow(finalColor, vec4(1.0/2.2)); 76 | 77 | // Fog calculation 78 | float dist = length(viewPos - fragPosition); 79 | 80 | // these could be parameters... 81 | const vec4 fogColor = vec4(0.5, 0.5, 0.5, 1.0); 82 | //const float fogDensity = 0.16; 83 | 84 | // Exponential fog 85 | float fogFactor = 1.0/exp((dist*fogDensity)*(dist*fogDensity)); 86 | 87 | // Linear fog (less nice) 88 | //const float fogStart = 2.0; 89 | //const float fogEnd = 10.0; 90 | //float fogFactor = (fogEnd - dist)/(fogEnd - fogStart); 91 | 92 | fogFactor = clamp(fogFactor, 0.0, 1.0); 93 | 94 | finalColor = mix(fogColor, finalColor, fogFactor); 95 | } 96 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/grayscale.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | void main() 17 | { 18 | // Texel color fetching from texture sampler 19 | vec4 texelColor = texture(texture0, fragTexCoord)*colDiffuse*fragColor; 20 | 21 | // Convert texel color to grayscale using NTSC conversion weights 22 | float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); 23 | 24 | // Calculate final fragment color 25 | finalColor = vec4(gray, gray, gray, texelColor.a); 26 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/julia_set.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Output fragment color 8 | out vec4 finalColor; 9 | 10 | uniform vec2 screenDims; // Dimensions of the screen 11 | uniform vec2 c; // c.x = real, c.y = imaginary component. Equation done is z^2 + c 12 | uniform vec2 offset; // Offset of the scale. 13 | uniform float zoom; // Zoom of the scale. 14 | 15 | const int MAX_ITERATIONS = 255; // Max iterations to do. 16 | 17 | // Square a complex number 18 | vec2 ComplexSquare(vec2 z) 19 | { 20 | return vec2( 21 | z.x * z.x - z.y * z.y, 22 | z.x * z.y * 2.0 23 | ); 24 | } 25 | 26 | // Convert Hue Saturation Value (HSV) color into RGB 27 | vec3 Hsv2rgb(vec3 c) 28 | { 29 | vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 30 | vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); 31 | return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); 32 | } 33 | 34 | void main() 35 | { 36 | /********************************************************************************************** 37 | Julia sets use a function z^2 + c, where c is a constant. 38 | This function is iterated until the nature of the point is determined. 39 | 40 | If the magnitude of the number becomes greater than 2, then from that point onward 41 | the number will get bigger and bigger, and will never get smaller (tends towards infinity). 42 | 2^2 = 4, 4^2 = 8 and so on. 43 | So at 2 we stop iterating. 44 | 45 | If the number is below 2, we keep iterating. 46 | But when do we stop iterating if the number is always below 2 (it converges)? 47 | That is what MAX_ITERATIONS is for. 48 | Then we can divide the iterations by the MAX_ITERATIONS value to get a normalized value that we can 49 | then map to a color. 50 | 51 | We use dot product (z.x * z.x + z.y * z.y) to determine the magnitude (length) squared. 52 | And once the magnitude squared is > 4, then magnitude > 2 is also true (saves computational power). 53 | *************************************************************************************************/ 54 | 55 | // The pixel coordinates are scaled so they are on the mandelbrot scale 56 | // NOTE: fragTexCoord already comes as normalized screen coordinates but offset must be normalized before scaling and zoom 57 | vec2 z = vec2((fragTexCoord.x + offset.x/screenDims.x)*2.5/zoom, (fragTexCoord.y + offset.y/screenDims.y)*1.5/zoom); 58 | 59 | int iterations = 0; 60 | for (iterations = 0; iterations < MAX_ITERATIONS; iterations++) 61 | { 62 | z = ComplexSquare(z) + c; // Iterate function 63 | 64 | if (dot(z, z) > 4.0) break; 65 | } 66 | 67 | // Another few iterations decreases errors in the smoothing calculation. 68 | // See http://linas.org/art-gallery/escape/escape.html for more information. 69 | z = ComplexSquare(z) + c; 70 | z = ComplexSquare(z) + c; 71 | 72 | // This last part smooths the color (again see link above). 73 | float smoothVal = float(iterations) + 1.0 - (log(log(length(z)))/log(2.0)); 74 | 75 | // Normalize the value so it is between 0 and 1. 76 | float norm = smoothVal/float(MAX_ITERATIONS); 77 | 78 | // If in set, color black. 0.999 allows for some float accuracy error. 79 | if (norm > 0.999) finalColor = vec4(0.0, 0.0, 0.0, 1.0); 80 | else finalColor = vec4(Hsv2rgb(vec3(norm, 1.0, 1.0)), 1.0); 81 | } 82 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/lighting.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec3 fragPosition; 5 | in vec2 fragTexCoord; 6 | in vec4 fragColor; 7 | in vec3 fragNormal; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform vec4 colDiffuse; 12 | 13 | // Output fragment color 14 | out vec4 finalColor; 15 | 16 | // NOTE: Add here your custom variables 17 | 18 | #define MAX_LIGHTS 4 19 | #define LIGHT_DIRECTIONAL 0 20 | #define LIGHT_POINT 1 21 | 22 | struct MaterialProperty { 23 | vec3 color; 24 | int useSampler; 25 | sampler2D sampler; 26 | }; 27 | 28 | struct Light { 29 | int enabled; 30 | int type; 31 | vec3 position; 32 | vec3 target; 33 | vec4 color; 34 | }; 35 | 36 | // Input lighting values 37 | uniform Light lights[MAX_LIGHTS]; 38 | uniform vec4 ambient; 39 | uniform vec3 viewPos; 40 | 41 | void main() 42 | { 43 | // Texel color fetching from texture sampler 44 | vec4 texelColor = texture(texture0, fragTexCoord); 45 | vec3 lightDot = vec3(0.0); 46 | vec3 normal = normalize(fragNormal); 47 | vec3 viewD = normalize(viewPos - fragPosition); 48 | vec3 specular = vec3(0.0); 49 | 50 | // NOTE: Implement here your fragment shader code 51 | 52 | for (int i = 0; i < MAX_LIGHTS; i++) 53 | { 54 | if (lights[i].enabled == 1) 55 | { 56 | vec3 light = vec3(0.0); 57 | 58 | if (lights[i].type == LIGHT_DIRECTIONAL) 59 | { 60 | light = -normalize(lights[i].target - lights[i].position); 61 | } 62 | 63 | if (lights[i].type == LIGHT_POINT) 64 | { 65 | light = normalize(lights[i].position - fragPosition); 66 | } 67 | 68 | float NdotL = max(dot(normal, light), 0.0); 69 | lightDot += lights[i].color.rgb*NdotL; 70 | 71 | float specCo = 0.0; 72 | if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewD, reflect(-(light), normal))), 16.0); // 16 refers to shine 73 | specular += specCo; 74 | } 75 | } 76 | 77 | finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0))); 78 | finalColor += texelColor*(ambient/10.0); 79 | 80 | // Gamma correction 81 | finalColor = pow(finalColor, vec4(1.0/2.2)); 82 | } 83 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/mask.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform sampler2D mask; 10 | uniform int frame; 11 | 12 | // Output fragment color 13 | out vec4 finalColor; 14 | 15 | void main() 16 | { 17 | vec4 maskColour = texture(mask, fragTexCoord + vec2(sin(-frame/150.0)/10.0, cos(-frame/170.0)/10.0)); 18 | if (maskColour.r < 0.25) discard; 19 | vec4 texelColor = texture(texture0, fragTexCoord + vec2(sin(frame/90.0)/8.0, cos(frame/60.0)/8.0)); 20 | 21 | finalColor = texelColor*maskColour; 22 | } 23 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/overdraw.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | void main() 17 | { 18 | // To show overdraw, we just render all the fragments 19 | // with a solid color and some transparency 20 | 21 | // NOTE: This is not a postpro render, 22 | // it will only render all screen texture in a plain color 23 | 24 | finalColor = vec4(1.0, 0.0, 0.0, 0.2); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/palette_switch.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | const int colors = 8; 4 | 5 | // Input fragment attributes (from fragment shader) 6 | in vec2 fragTexCoord; 7 | in vec4 fragColor; 8 | 9 | // Input uniform values 10 | uniform sampler2D texture0; 11 | uniform ivec3 palette[colors]; 12 | 13 | // Output fragment color 14 | out vec4 finalColor; 15 | 16 | void main() 17 | { 18 | // Texel color fetching from texture sampler 19 | vec4 texelColor = texture(texture0, fragTexCoord)*fragColor; 20 | 21 | // Convert the (normalized) texel color RED component (GB would work, too) 22 | // to the palette index by scaling up from [0, 1] to [0, 255]. 23 | int index = int(texelColor.r*255.0); 24 | ivec3 color = palette[index]; 25 | 26 | // Calculate final fragment color. Note that the palette color components 27 | // are defined in the range [0, 255] and need to be normalized to [0, 1] 28 | // for OpenGL to work. 29 | finalColor = vec4(color/255.0, texelColor.a); 30 | } 31 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/pixelizer.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | // NOTE: Render size values must be passed from code 17 | const float renderWidth = 800; 18 | const float renderHeight = 450; 19 | 20 | uniform float pixelWidth = 5.0; 21 | uniform float pixelHeight = 5.0; 22 | 23 | void main() 24 | { 25 | float dx = pixelWidth*(1.0/renderWidth); 26 | float dy = pixelHeight*(1.0/renderHeight); 27 | 28 | vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy)); 29 | 30 | vec3 tc = texture(texture0, coord).rgb; 31 | 32 | finalColor = vec4(tc, 1.0); 33 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/posterization.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | float gamma = 0.6; 17 | float numColors = 8.0; 18 | 19 | void main() 20 | { 21 | // Texel color fetching from texture sampler 22 | vec3 texelColor = texture(texture0, fragTexCoord.xy).rgb; 23 | 24 | texelColor = pow(texelColor, vec3(gamma, gamma, gamma)); 25 | texelColor = texelColor*numColors; 26 | texelColor = floor(texelColor); 27 | texelColor = texelColor/numColors; 28 | texelColor = pow(texelColor, vec3(1.0/gamma)); 29 | 30 | finalColor = vec4(texelColor, 1.0); 31 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/predator.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | void main() 17 | { 18 | // Texel color fetching from texture sampler 19 | vec3 texelColor = texture(texture0, fragTexCoord).rgb; 20 | vec3 colors[3]; 21 | colors[0] = vec3(0.0, 0.0, 1.0); 22 | colors[1] = vec3(1.0, 1.0, 0.0); 23 | colors[2] = vec3(1.0, 0.0, 0.0); 24 | 25 | float lum = (texelColor.r + texelColor.g + texelColor.b)/3.0; 26 | 27 | int ix = (lum < 0.5)? 0:1; 28 | 29 | vec3 tc = mix(colors[ix], colors[ix + 1], (lum - float(ix)*0.5)/0.5); 30 | 31 | finalColor = vec4(tc, 1.0); 32 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/scanlines.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | // NOTE: Render size values must be passed from code 17 | const float renderWidth = 800; 18 | const float renderHeight = 450; 19 | float offset = 0.0; 20 | 21 | uniform float time; 22 | 23 | void main() 24 | { 25 | float frequency = renderHeight/3.0; 26 | /* 27 | // Scanlines method 1 28 | float tval = 0; //time 29 | vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval)); 30 | 31 | vec4 color = texture(texture0, fragTexCoord); 32 | 33 | color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0); 34 | color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y); 35 | color *= vec4(0.8, 1.0, 0.7, 1); 36 | color *= 0.9 + 0.1*sin(10.0*tval + uv.y*1000.0); 37 | color *= 0.97 + 0.03*sin(110.0*tval); 38 | 39 | fragColor = color; 40 | */ 41 | // Scanlines method 2 42 | float globalPos = (fragTexCoord.y + offset) * frequency; 43 | float wavePos = cos((fract(globalPos) - 0.5)*3.14); 44 | 45 | // Texel color fetching from texture sampler 46 | vec4 texelColor = texture(texture0, fragTexCoord); 47 | 48 | finalColor = mix(vec4(0.0, 0.3, 0.0, 0.0), texelColor, wavePos); 49 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/sobel.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | uniform vec2 resolution = vec2(800, 450); 16 | 17 | void main() 18 | { 19 | float x = 1.0/resolution.x; 20 | float y = 1.0/resolution.y; 21 | 22 | vec4 horizEdge = vec4(0.0); 23 | horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; 24 | horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0; 25 | horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; 26 | horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; 27 | horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0; 28 | horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; 29 | 30 | vec4 vertEdge = vec4(0.0); 31 | vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; 32 | vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0; 33 | vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; 34 | vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; 35 | vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0; 36 | vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; 37 | 38 | vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb)); 39 | 40 | finalColor = vec4(edge, texture2D(texture0, fragTexCoord).a); 41 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/spotlight.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Output fragment color 8 | out vec4 finalColor; 9 | 10 | // NOTE: Add here your custom variables 11 | 12 | #define MAX_SPOTS 3 13 | 14 | struct Spot { 15 | vec2 pos; // window coords of spot 16 | float inner; // inner fully transparent centre radius 17 | float radius; // alpha fades out to this radius 18 | }; 19 | 20 | uniform Spot spots[MAX_SPOTS]; // Spotlight positions array 21 | uniform float screenWidth; // Width of the screen 22 | 23 | void main() 24 | { 25 | float alpha = 1.0; 26 | 27 | // Get the position of the current fragment (screen coordinates!) 28 | vec2 pos = vec2(gl_FragCoord.x, gl_FragCoord.y); 29 | 30 | // Find out which spotlight is nearest 31 | float d = 65000; // some high value 32 | int fi = -1; // found index 33 | 34 | for (int i = 0; i < MAX_SPOTS; i++) 35 | { 36 | for (int j = 0; j < MAX_SPOTS; j++) 37 | { 38 | float dj = distance(pos, spots[j].pos) - spots[j].radius + spots[i].radius; 39 | 40 | if (d > dj) 41 | { 42 | d = dj; 43 | fi = i; 44 | } 45 | } 46 | } 47 | 48 | // d now equals distance to nearest spot... 49 | // allowing for the different radii of all spotlights 50 | if (fi != -1) 51 | { 52 | if (d > spots[fi].radius) alpha = 1.0; 53 | else 54 | { 55 | if (d < spots[fi].inner) alpha = 0.0; 56 | else alpha = (d - spots[fi].inner) / (spots[fi].radius - spots[fi].inner); 57 | } 58 | } 59 | 60 | // Right hand side of screen is dimly lit, 61 | // could make the threshold value user definable 62 | if ((pos.x > screenWidth/2.0) && (alpha > 0.9)) alpha = 0.9; 63 | 64 | finalColor = vec4(0, 0, 0, alpha); 65 | } 66 | -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/swirl.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | // NOTE: Render size values should be passed from code 17 | const float renderWidth = 800; 18 | const float renderHeight = 450; 19 | 20 | float radius = 250.0; 21 | float angle = 0.8; 22 | 23 | uniform vec2 center = vec2(200.0, 200.0); 24 | 25 | void main() 26 | { 27 | vec2 texSize = vec2(renderWidth, renderHeight); 28 | vec2 tc = fragTexCoord*texSize; 29 | tc -= center; 30 | 31 | float dist = length(tc); 32 | 33 | if (dist < radius) 34 | { 35 | float percent = (radius - dist)/radius; 36 | float theta = percent*percent*angle*8.0; 37 | float s = sin(theta); 38 | float c = cos(theta); 39 | 40 | tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c))); 41 | } 42 | 43 | tc += center; 44 | vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;; 45 | 46 | finalColor = vec4(color.rgb, 1.0);; 47 | } -------------------------------------------------------------------------------- /examples/shaders/resources/shaders/glsl330/wave.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | uniform float secondes; 15 | 16 | uniform vec2 size; 17 | 18 | uniform float freqX; 19 | uniform float freqY; 20 | uniform float ampX; 21 | uniform float ampY; 22 | uniform float speedX; 23 | uniform float speedY; 24 | 25 | void main() { 26 | float pixelWidth = 1.0 / size.x; 27 | float pixelHeight = 1.0 / size.y; 28 | float aspect = pixelHeight / pixelWidth; 29 | float boxLeft = 0.0; 30 | float boxTop = 0.0; 31 | 32 | vec2 p = fragTexCoord; 33 | p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth; 34 | p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight; 35 | 36 | finalColor = texture(texture0, p)*colDiffuse*fragColor; 37 | } 38 | -------------------------------------------------------------------------------- /examples/shaders/resources/space.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/shaders/resources/space.png -------------------------------------------------------------------------------- /examples/shaders/resources/texel_checker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/shaders/resources/texel_checker.png -------------------------------------------------------------------------------- /examples/shapes/logo-raylib-nelua.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on: 6 | 7 | -- The upstream issue #20 "Logo proposal", by TSnake41, 8 | -- available at: https://github.com/Andre-LA/raylib-nelua/issues/20#issue-765682233 9 | 10 | -- The "basic window" example by raysan5, 11 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/core/core_basic_window.c 12 | 13 | require 'raylib' 14 | 15 | -- [[ Initialization [[ 16 | local screen_width: integer = 800 17 | local screen_height: integer = 450 18 | 19 | local nelua_color: Color = { 0x2f, 0x7a, 0xe5, 255 } 20 | 21 | Raylib.InitWindow(800, 450, "raylib-nelua [shapes] example - basic window") 22 | 23 | Raylib.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 24 | -- ]] Initialization ]] 25 | 26 | -- [[ Main game loop [[ 27 | while not Raylib.WindowShouldClose() do 28 | -- [[ Update [[ 29 | -- TODO: Update your variables here 30 | -- ]] Update ]] 31 | 32 | -- [[ Draw [[ 33 | Raylib.BeginDrawing() 34 | do 35 | Raylib.ClearBackground(RAYWHITE) 36 | 37 | Raylib.DrawRectangle(screen_width // 2 - 128, screen_height // 2 - 128, 256, 256, nelua_color) 38 | Raylib.DrawRectangle(screen_width // 2 - 112, screen_height // 2 - 112, 224, 224, RAYWHITE) 39 | Raylib.DrawText("raylib", screen_width // 2 - 55, screen_height // 2 + 24, 50, nelua_color) 40 | Raylib.DrawText("Nelua", screen_width // 2 - 31, screen_height // 2 + 64, 50, nelua_color) 41 | 42 | Raylib.DrawText("this is NOT a texture!", 350, 370, 10, GRAY) 43 | end 44 | Raylib.EndDrawing() 45 | -- ]] Draw ]] 46 | end 47 | -- ]] Main game loop ]] 48 | 49 | -- [[ De-Initialization [[ 50 | Raylib.CloseWindow() -- Close window and OpenGL context 51 | -- ]] De-Initialization ]] 52 | -------------------------------------------------------------------------------- /examples/test_all_examples.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "input keys" example by raysan5, available at: https://www.raylib.com/examples.html 6 | 7 | require 'examples/core/2d-camera' 8 | require 'examples/core/2d-camera-platformer' 9 | require 'examples/core/3d-camera-first-person' 10 | require 'examples/core/3d-camera-free' 11 | require 'examples/core/3d-camera-mode' 12 | require 'examples/core/3d-picking' 13 | require 'examples/core/basic-window' 14 | require 'examples/core/drop-files' 15 | require 'examples/core/input-gamepad' 16 | require 'examples/core/input-keys' 17 | require 'examples/core/input-mouse' 18 | require 'examples/core/input-mouse_wheel' 19 | require 'examples/core/loading-thread' 20 | require 'examples/core/random-values' 21 | require 'examples/core/scissor-text' 22 | require 'examples/core/storage-values' 23 | require 'examples/core/vr-simulator' 24 | require 'examples/core/window-letterbox' 25 | require 'examples/core/world-screen' 26 | 27 | require 'examples/shapes/logo-raylib-nelua' 28 | 29 | require 'examples/text/raylib-fonts' 30 | -------------------------------------------------------------------------------- /examples/text/raylib-fonts.nelua: -------------------------------------------------------------------------------- 1 | --[[ This Source Code Form is subject to the terms of the Mozilla Public 2 | License, v. 2.0. If a copy of the MPL was not distributed with this 3 | file, You can obtain one at https://mozilla.org/MPL/2.0/. ]] 4 | 5 | -- This code is based on the "raylib fonts" example by raysan5, 6 | -- available at: https://github.com/raysan5/raylib/blob/master/examples/text/text_raylib_fonts.c 7 | 8 | require 'raylib' 9 | 10 | local MAX_FONTS = 8 11 | 12 | -- [[ Initialization [[ 13 | local screen_width = 800 14 | local screen_height = 450 15 | 16 | Raylib.InitWindow(screen_width, screen_height, "raylib-nelua [text] example - raylib fonts") 17 | 18 | -- NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) 19 | local fonts: [MAX_FONTS]Font = {} 20 | 21 | fonts[0] = Raylib.LoadFont('resources/fonts/alagard.png') 22 | fonts[1] = Raylib.LoadFont('resources/fonts/pixelplay.png') 23 | fonts[2] = Raylib.LoadFont('resources/fonts/mecha.png') 24 | fonts[3] = Raylib.LoadFont('resources/fonts/setback.png') 25 | fonts[4] = Raylib.LoadFont('resources/fonts/romulus.png') 26 | fonts[5] = Raylib.LoadFont('resources/fonts/pixantiqua.png') 27 | fonts[6] = Raylib.LoadFont('resources/fonts/alpha_beta.png') 28 | fonts[7] = Raylib.LoadFont('resources/fonts/jupiter_crash.png') 29 | 30 | local messages: [MAX_FONTS]stringview = { 31 | "ALAGARD FONT designed by Hewett Tsoi", 32 | "PIXELPLAY FONT designed by Aleksander Shevchuk", 33 | "MECHA FONT designed by Captain Falcon", 34 | "SETBACK FONT designed by Brian Kent (AEnigma)", 35 | "ROMULUS FONT designed by Hewett Tsoi", 36 | "PIXANTIQUA FONT designed by Gerhard Grossmann", 37 | "ALPHA_BETA FONT designed by Brian Kent (AEnigma)", 38 | "JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" 39 | } 40 | 41 | local spacings: [MAX_FONTS]integer = { 2, 4, 8, 4, 3, 4, 4, 1 } 42 | 43 | local positions: [MAX_FONTS]Vector2 = {} 44 | 45 | for i = 0, < MAX_FONTS do 46 | positions[i].x = screen_width / 2 - Raylib.MeasureTextEx(fonts[i], messages[i], fonts[i].baseSize*2, spacings[i]).x / 2 47 | positions[i].y = 60 + fonts[i].baseSize + 45 * i 48 | end 49 | 50 | -- Small Y position corrections 51 | positions[3].y = positions[3].y + 8 52 | positions[4].y = positions[4].y + 2 53 | positions[7].y = positions[7].y - 8 54 | 55 | local colors: [MAX_FONTS]Color = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED } 56 | 57 | Raylib.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second 58 | -- ]] Initialization ]] 59 | 60 | -- [[ Main game loop [[ 61 | while not Raylib.WindowShouldClose() do -- Detect window close button or ESC key 62 | -- [[ Update [[ 63 | -- TODO: Update your variables here 64 | -- ]] Update ]] 65 | 66 | -- [[ Draw [[ 67 | Raylib.BeginDrawing() 68 | do 69 | Raylib.ClearBackground(RAYWHITE) 70 | 71 | Raylib.DrawText("free fonts included with raylib", 250, 20, 20, DARKGRAY) 72 | Raylib.DrawLine(220, 50, 590, 50, DARKGRAY) 73 | 74 | for i = 0, < MAX_FONTS do 75 | Raylib.DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].baseSize*2, spacings[i], colors[i]) 76 | end 77 | end 78 | Raylib.EndDrawing() 79 | -- ]] Draw ]] 80 | end 81 | -- ]] Main game loop ]] 82 | 83 | -- [[ De-Initialization [[ 84 | 85 | -- Fonts unloading 86 | for i = 0, < MAX_FONTS do 87 | Raylib.UnloadFont(fonts[i]) 88 | end 89 | 90 | Raylib.CloseWindow() -- Close window and OpenGL context 91 | -- ]] De-Initialization ]] 92 | -------------------------------------------------------------------------------- /examples/text/resources/AnonymousPro-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/AnonymousPro-Bold.ttf -------------------------------------------------------------------------------- /examples/text/resources/KAISG.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/KAISG.ttf -------------------------------------------------------------------------------- /examples/text/resources/LICENSE: -------------------------------------------------------------------------------- 1 | All fonts used in examples are provided under a free and permissive license. 2 | Check individual licenses for details: 3 | 4 | - [Alpha Beta] by Brian Kent (AEnigma) - https://www.dafont.com/es/alpha-beta.font 5 | - [Setback] by Brian Kent (AEnigma) - https://www.dafont.com/es/setback.font 6 | - [Jupiter Crash] by Brian Kent (AEnigma) - https://www.dafont.com/es/jupiter-crash.font 7 | - [Alagard] by Hewett Tsoi - https://www.dafont.com/es/alagard.font 8 | - [Romulus] by Hewett Tsoi - https://www.dafont.com/es/romulus.font 9 | - [Mecha] by Captain Falcon - https://www.dafont.com/es/mecha-cf.font 10 | - [PixelPlay] by Aleksander Shevchuk - https://www.dafont.com/es/pixelplay.font 11 | - [PixAntiqua] by Gerhard Großmann - https://www.dafont.com/es/pixantiqua.font 12 | - [Kaiserzeit Gotisch] by Dieter Steffmann - https://www.dafont.com/es/kaiserzeit-gotisch.font 13 | - [Noto CJK] by Google Fonts - https://www.google.com/get/noto/help/cjk/ 14 | - [Anonymous Pro] by Mark Simonson - https://fonts.google.com/specimen/Anonymous+Pro 15 | - [DejaVu] by DejaVu Fonts - https://dejavu-fonts.github.io/ 16 | - [Symbola] by George Douros - https://fontlibrary.org/en/font/symbola 17 | -------------------------------------------------------------------------------- /examples/text/resources/bmfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/bmfont.png -------------------------------------------------------------------------------- /examples/text/resources/custom_alagard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/custom_alagard.png -------------------------------------------------------------------------------- /examples/text/resources/custom_jupiter_crash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/custom_jupiter_crash.png -------------------------------------------------------------------------------- /examples/text/resources/custom_mecha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/custom_mecha.png -------------------------------------------------------------------------------- /examples/text/resources/dejavu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/dejavu.png -------------------------------------------------------------------------------- /examples/text/resources/emoji.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/emoji.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/alagard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/fonts/alagard.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/alpha_beta.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/fonts/alpha_beta.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/jupiter_crash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/fonts/jupiter_crash.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/mecha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/fonts/mecha.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/pixantiqua.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/fonts/pixantiqua.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/pixelplay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/fonts/pixelplay.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/romulus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/fonts/romulus.png -------------------------------------------------------------------------------- /examples/text/resources/fonts/setback.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/fonts/setback.png -------------------------------------------------------------------------------- /examples/text/resources/notoCJK.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/notoCJK.png -------------------------------------------------------------------------------- /examples/text/resources/pixantiqua.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/pixantiqua.png -------------------------------------------------------------------------------- /examples/text/resources/pixantiqua.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/text/resources/pixantiqua.ttf -------------------------------------------------------------------------------- /examples/text/resources/shaders/glsl100/sdf.fs: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | // Input vertex attributes (from vertex shader) 4 | varying vec2 fragTexCoord; 5 | varying vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // NOTE: Add here your custom variables 12 | const float smoothing = 1.0/16.0; 13 | 14 | void main() 15 | { 16 | // Texel color fetching from texture sampler 17 | // NOTE: Calculate alpha using signed distance field (SDF) 18 | float distance = texture2D(texture0, fragTexCoord).a; 19 | float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance); 20 | 21 | // Calculate final fragment color 22 | gl_FragColor = vec4(fragColor.rgb, fragColor.a*alpha); 23 | } 24 | -------------------------------------------------------------------------------- /examples/text/resources/shaders/glsl330/sdf.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | const float smoothing = 1.0/16.0; 16 | 17 | void main() 18 | { 19 | // Texel color fetching from texture sampler 20 | // NOTE: Calculate alpha using signed distance field (SDF) 21 | float distance = texture(texture0, fragTexCoord).a; 22 | float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance); 23 | 24 | // Calculate final fragment color 25 | finalColor = vec4(fragColor.rgb, fragColor.a*alpha); 26 | } 27 | -------------------------------------------------------------------------------- /examples/textures/resources/KAISG.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/KAISG.ttf -------------------------------------------------------------------------------- /examples/textures/resources/LICENSE: -------------------------------------------------------------------------------- 1 | Art used in examples is provided under a free and permissive license. 2 | Check individual licenses for details: 3 | 4 | - [Jupiter Crash] font by Brian Kent (AEnigma) - https://www.dafont.com/es/jupiter-crash.font 5 | - [Kaiserzeit Gotisch] font by Dieter Steffmann - https://www.dafont.com/es/kaiserzeit-gotisch.font 6 | - [Scarfy spritesheet](scarfy.png) by [Eiden Marsal](https://www.artstation.com/artist/marshall_z), licensed as [Creative Commons Attribution-NonCommercial 3.0](https://creativecommons.org/licenses/by-nc/3.0/legalcode) 7 | - [Fudesumi image](fudesumi.png) by [Eiden Marsal](https://www.artstation.com/artist/marshall_z), licensed as [Creative Commons Attribution-NonCommercial 3.0](https://creativecommons.org/licenses/by-nc/3.0/legalcode) 8 | - [Cyberpunk Street Environment](https://ansimuz.itch.io/cyberpunk-street-environment) by Luis Zuno ([@ansimuz](https://twitter.com/ansimuz)), licensed as [CC-BY-3.0](http://creativecommons.org/licenses/by/3.0/) 9 | -------------------------------------------------------------------------------- /examples/textures/resources/boom.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/boom.wav -------------------------------------------------------------------------------- /examples/textures/resources/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/button.png -------------------------------------------------------------------------------- /examples/textures/resources/buttonfx.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/buttonfx.wav -------------------------------------------------------------------------------- /examples/textures/resources/cat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/cat.png -------------------------------------------------------------------------------- /examples/textures/resources/custom_jupiter_crash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/custom_jupiter_crash.png -------------------------------------------------------------------------------- /examples/textures/resources/cyberpunk_street_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/cyberpunk_street_background.png -------------------------------------------------------------------------------- /examples/textures/resources/cyberpunk_street_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/cyberpunk_street_foreground.png -------------------------------------------------------------------------------- /examples/textures/resources/cyberpunk_street_midground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/cyberpunk_street_midground.png -------------------------------------------------------------------------------- /examples/textures/resources/explosion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/explosion.png -------------------------------------------------------------------------------- /examples/textures/resources/fudesumi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/fudesumi.png -------------------------------------------------------------------------------- /examples/textures/resources/fudesumi.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/fudesumi.raw -------------------------------------------------------------------------------- /examples/textures/resources/ninepatch_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/ninepatch_button.png -------------------------------------------------------------------------------- /examples/textures/resources/parrots.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/parrots.png -------------------------------------------------------------------------------- /examples/textures/resources/raylib_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/raylib_logo.png -------------------------------------------------------------------------------- /examples/textures/resources/scarfy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/scarfy.png -------------------------------------------------------------------------------- /examples/textures/resources/smoke.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/smoke.png -------------------------------------------------------------------------------- /examples/textures/resources/wabbit_alpha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre-LA/raylib-nelua/22ba54dfc7a4c287618cd416bf03854d76791e46/examples/textures/resources/wabbit_alpha.png -------------------------------------------------------------------------------- /raylib-nelualogo.svg: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 39 | 41 | 42 | 44 | image/svg+xml 45 | 47 | 48 | 49 | 50 | 51 | 55 | 60 | 61 | 62 | --------------------------------------------------------------------------------