Watch
2
0
Fork
You've already forked raylib-cs
0

Upgrade Raylib to 6.0 (#337)

* Updated target to Raylib 6 + synced invoke called with the changes in C. [WARNING: Breaking changes!]

* Added severial examples. Corrected towards the correct return type and add utilities to prevent working with pointers

* Additional resources from the Raylib repo.

* Fixed additional pinvokes to match with the new raylib bindings. [Warning breaking changes!]

* Fixing the QOL utils

* Fixing the Mesh struct

* Applying changes after review. Merged resources.LICENSE + raylib-cs.Native.csproj only targets dotnet8

* Updated README to reflect .NET 10 and Raylib 6 compatibility changes.

* Updated shader colors, adjusted car model scale, disabled HDR in SkyboxDemo, and fixed camera mode assignment. Removed unused `Capacity` field in FilePathList struct.

* Improved XML comments for consistency, fixed spacing and formatting across examples, added new resources to `resources.LICENSE`.

* Updated XML comment for `GetDirectoryFileCountEx` to clarify behavior and filtering options.

* Updated and clarified XML comments for methods and parameters, improved naming consistency, and refined shader-related functions. Renamed enums in `Shader.cs` for so it is inline with the upstream.

* Improved XML comments for clarity and consistency in `Model.cs` and `Mesh.cs`, updated method and variable names for better readability, and adjusted logic in span creation methods.

* Corrected XML comment capitalization in `Model.cs`.

---------

Co-authored-by: Meatcorps <info@meatcorps.nl>
This commit is contained in:
Dennis Steffen 2026-05-24 08:21:12 +02:00 committed by GitHub
commit 21d83c60a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
189 changed files with 43644 additions and 380 deletions

View file

@ -1,21 +1,28 @@
/*******************************************************************************************
*
* raylib [core] example - Basic window
* raylib [core] example - basic window
*
* Example complexity rating: [] 1/4
*
* Welcome to raylib!
*
* To test examples, just press F6 and execute raylib_compile_execute script
* To test examples, just press F6 and execute 'raylib_compile_execute' script
* Note that compiled executable is placed in the same folder as .c file
*
* To test the examples on Web, press F6 and execute 'raylib_compile_execute_web' script
* Web version of the program is generated in the same folder as .c file
*
* You can find all basic examples on C:\raylib\raylib\examples folder or
* raylib official webpage: www.raylib.com
*
* Enjoy using raylib. :)
*
* This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* Example originally created with raylib 1.0, last time updated with raylib 1.0
*
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2013-2026 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
@ -53,7 +60,7 @@ public class BasicWindow
BeginDrawing();
ClearBackground(Color.RayWhite);
DrawText("Congrats! You created your first window!", 190, 200, 20, Color.Maroon);
DrawText("Congrats! You created your first window!", 190, 200, 20, Color.LightGray);
EndDrawing();
//----------------------------------------------------------------------------------

View file

@ -2,10 +2,14 @@
*
* raylib [core] example - 2d camera
*
* This example has been created using raylib 1.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* Example complexity rating: [] 2/4
*
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
* Example originally created with raylib 1.5, last time updated with raylib 3.0
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2016-2025 Ramon Santamaria (@raysan5)
*
********************************************************************************************/

View file

@ -113,7 +113,7 @@ public class Camera3dFirstPerson
// Update camera computes movement internally depending on the camera mode
// Some default standard keyboard/mouse inputs are hardcoded to simplify use
// For advance camera controls, it's reecommended to compute camera movement manually
UpdateCamera(ref camera, CameraMode.Custom);
UpdateCamera(ref camera, cameraMode);
//----------------------------------------------------------------------------------
// Draw

View file

@ -50,7 +50,7 @@ public unsafe class CustomLogging
// First thing we do is setting our custom logger to ensure everything raylib logs
// will use our own logger instead of its internal one
Raylib.SetTraceLogCallback(&LogCustom);
SetTraceLogCallback(&LogCustom);
InitWindow(screenWidth, screenHeight, "raylib [core] example - custom logging");
@ -79,7 +79,7 @@ public unsafe class CustomLogging
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow();
Raylib.SetTraceLogCallback(&Logging.LogConsole);
SetTraceLogCallback(&Logging.LogConsole);
//--------------------------------------------------------------------------------------
return 0;

130
Examples/Core/DeltaTime.cs Normal file
View file

@ -0,0 +1,130 @@
/*******************************************************************************************
*
* raylib [core] example - delta time
*
* Example complexity rating: [] 1/4
*
* Example originally created with raylib 5.5, last time updated with raylib 6.0
*
* Example contributed by Robin (@RobinsAviary) and reviewed by Ramon Santamaria (@raysan5)
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2025 Robin (@RobinsAviary)
*
********************************************************************************************/
using System.Numerics;
namespace Examples.Core;
using static Raylib_cs.Raylib;
public class DeltaTime
{
public static int Main()
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - delta time");
int currentFps = 60;
Vector2 deltaCircle = new Vector2(0, (float)screenHeight / 3.0f);
Vector2 frameCircle = new Vector2(0, (float)screenHeight * (2.0f / 3.0f));
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
const float speed = 10.0f;
const float circleRadius = 32.0f;
// Main game loop
while (!WindowShouldClose())
{
// Update
//----------------------------------------------------------------------------------
// Adjust the FPS target based on the mouse wheel
float mouseWheel = GetMouseWheelMove();
if (mouseWheel != 0)
{
currentFps += (int)mouseWheel;
if (currentFps < 0)
{
currentFps = 0;
}
SetTargetFPS(currentFps);
}
// GetFrameTime() returns the time it took to draw the last frame, in seconds (usually called delta time)
// Uses the delta time to make the circle look like it's moving at a "consistent" speed regardless of FPS
// Multiply by 6.0 (an arbitrary value) in order to make the speed
// visually closer to the other circle (at 60 fps), for comparison
deltaCircle.X += GetFrameTime() * 6.0f * speed;
// This circle can move faster or slower visually depending on the FPS
frameCircle.X += 0.1f * speed;
// If either circle is off the screen, reset it back to the start
if (deltaCircle.X > screenWidth)
{
deltaCircle.X = 0;
}
if (frameCircle.X > screenWidth)
{
frameCircle.X = 0;
}
// Reset both circles positions
if (IsKeyPressed(KeyboardKey.R))
{
deltaCircle.X = 0;
frameCircle.X = 0;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(Color.RayWhite);
// Draw both circles to the screen
DrawCircleV(deltaCircle, circleRadius, Color.Red);
DrawCircleV(frameCircle, circleRadius, Color.Blue);
// Draw the help text
// Determine what help text to show depending on the current FPS target
var fpsText = "";
if (currentFps <= 0)
{
fpsText = $"FPS: unlimited ({GetFPS()})";
}
else
{
fpsText = $"FPS: {GetFPS()} (target: {currentFps})";
}
DrawText(fpsText, 10, 10, 20, Color.DarkGray);
DrawText($"Frame time: {GetFrameTime():F2} ms", 10, 30, 20, Color.DarkGray);
DrawText("Use the scroll wheel to change the fps limit, r to reset", 10, 50, 20, Color.DarkGray);
// Draw the text above the circles
DrawText("FUNC: x += GetFrameTime()*speed", 10, 90, 20, Color.Red);
DrawText("FUNC: x += speed", 10, 240, 20, Color.Blue);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow();
//--------------------------------------------------------------------------------------
return 0;
}
}

View file

@ -1,6 +1,8 @@
/*******************************************************************************************
*
* raylib [core] example - Gamepad input
* raylib [core] example - input gamepad
*
* Example complexity rating: [] 1/4
*
* NOTE: This example requires a Gamepad connected to the system
* raylib is configured to work with the following gamepads:
@ -8,13 +10,16 @@
* - PLAYSTATION(R)3 Controller
* Check raylib.h for buttons configuration
*
* This example has been created using raylib 1.6 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* Example originally created with raylib 1.1, last time updated with raylib 4.2
*
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2013-2025 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
using System.Numerics;
using Raylib_cs;
using static Raylib_cs.Raylib;
@ -25,10 +30,10 @@ public class InputGamepad
{
// NOTE: Gamepad name ID depends on drivers and OS
// These are some possible names the gamepads could have.
public const string XBOX360_LEGACY_NAME_ID = "Xbox Controller";
public const string XBOX360_NAME_ID = "Xbox 360 Controller";
public const string XBOX360_NAME_ID_RPI = "Microsoft X-Box 360 pad";
public const string PS3_NAME_ID = "PLAYSTATION(R)3 Controller";
public const string XBOX_ALIAS_1 = "xbox";
public const string XBOX_ALIAS_2 = "x-box";
public const string PS_ALIAS_1 = "playstation";
public const string PS_ALIAS_2 = "sony";
public static int Main()
{
@ -47,12 +52,32 @@ public class InputGamepad
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
int gamepad = 0;
Rectangle vibrateButton = new Rectangle();
// Main game loop
while (!WindowShouldClose())
{
// Update
//----------------------------------------------------------------------------------
// ...
if (IsKeyPressed(KeyboardKey.Left) && gamepad > 0)
{
gamepad--;
}
if (IsKeyPressed(KeyboardKey.Right))
{
gamepad++;
}
Vector2 mousePosition = GetMousePosition();
vibrateButton = new Rectangle(10, 70.0f + 20 * GetGamepadAxisCount(gamepad) + 20, 75, 24);
if (IsMouseButtonPressed(MouseButton.Left) && CheckCollisionPointRec(mousePosition, vibrateButton))
{
SetGamepadVibration(gamepad, 1.0f, 1.0f, 1.0f);
}
//----------------------------------------------------------------------------------
// Draw
@ -60,50 +85,49 @@ public class InputGamepad
BeginDrawing();
ClearBackground(Color.RayWhite);
if (IsGamepadAvailable(0))
if (IsGamepadAvailable(gamepad))
{
string gamepadName = GetGamepadName_(0);
DrawText($"GP1: {gamepadName}", 10, 10, 10, Color.Black);
string gamepadName = GetGamepadName_(gamepad);
DrawText($"GP{gamepad}: {gamepadName}", 10, 10, 10, Color.Black);
if (gamepadName == XBOX360_LEGACY_NAME_ID ||
gamepadName == XBOX360_NAME_ID ||
gamepadName == XBOX360_NAME_ID_RPI)
if (gamepadName.Contains(XBOX_ALIAS_1, StringComparison.OrdinalIgnoreCase) ||
gamepadName.Contains(XBOX_ALIAS_2, StringComparison.OrdinalIgnoreCase))
{
DrawTexture(texXboxPad, 0, 0, Color.DarkGray);
// Draw buttons: xbox home
if (IsGamepadButtonDown(0, GamepadButton.Middle))
if (IsGamepadButtonDown(gamepad, GamepadButton.Middle))
{
DrawCircle(394, 89, 19, Color.Red);
}
// Draw buttons: basic
if (IsGamepadButtonDown(0, GamepadButton.MiddleRight))
if (IsGamepadButtonDown(gamepad, GamepadButton.MiddleRight))
{
DrawCircle(436, 150, 9, Color.Red);
}
if (IsGamepadButtonDown(0, GamepadButton.MiddleLeft))
if (IsGamepadButtonDown(gamepad, GamepadButton.MiddleLeft))
{
DrawCircle(352, 150, 9, Color.Red);
}
if (IsGamepadButtonDown(0, GamepadButton.RightFaceLeft))
if (IsGamepadButtonDown(gamepad, GamepadButton.RightFaceLeft))
{
DrawCircle(501, 151, 15, Color.Blue);
}
if (IsGamepadButtonDown(0, GamepadButton.RightFaceDown))
if (IsGamepadButtonDown(gamepad, GamepadButton.RightFaceDown))
{
DrawCircle(536, 187, 15, Color.Lime);
}
if (IsGamepadButtonDown(0, GamepadButton.RightFaceRight))
if (IsGamepadButtonDown(gamepad, GamepadButton.RightFaceRight))
{
DrawCircle(572, 151, 15, Color.Maroon);
}
if (IsGamepadButtonDown(0, GamepadButton.RightFaceUp))
if (IsGamepadButtonDown(gamepad, GamepadButton.RightFaceUp))
{
DrawCircle(536, 115, 15, Color.Gold);
}
@ -111,33 +135,33 @@ public class InputGamepad
// Draw buttons: d-pad
DrawRectangle(317, 202, 19, 71, Color.Black);
DrawRectangle(293, 228, 69, 19, Color.Black);
if (IsGamepadButtonDown(0, GamepadButton.LeftFaceUp))
if (IsGamepadButtonDown(gamepad, GamepadButton.LeftFaceUp))
{
DrawRectangle(317, 202, 19, 26, Color.Red);
}
if (IsGamepadButtonDown(0, GamepadButton.LeftFaceDown))
if (IsGamepadButtonDown(gamepad, GamepadButton.LeftFaceDown))
{
DrawRectangle(317, 202 + 45, 19, 26, Color.Red);
}
if (IsGamepadButtonDown(0, GamepadButton.LeftFaceLeft))
if (IsGamepadButtonDown(gamepad, GamepadButton.LeftFaceLeft))
{
DrawRectangle(292, 228, 25, 19, Color.Red);
}
if (IsGamepadButtonDown(0, GamepadButton.LeftFaceRight))
if (IsGamepadButtonDown(gamepad, GamepadButton.LeftFaceRight))
{
DrawRectangle(292 + 44, 228, 26, 19, Color.Red);
}
// Draw buttons: left-right back
if (IsGamepadButtonDown(0, GamepadButton.LeftTrigger1))
if (IsGamepadButtonDown(gamepad, GamepadButton.LeftTrigger1))
{
DrawCircle(259, 61, 20, Color.Red);
}
if (IsGamepadButtonDown(0, GamepadButton.RightTrigger1))
if (IsGamepadButtonDown(gamepad, GamepadButton.RightTrigger1))
{
DrawCircle(536, 61, 20, Color.Red);
}
@ -146,8 +170,8 @@ public class InputGamepad
DrawCircle(259, 152, 39, Color.Black);
DrawCircle(259, 152, 34, Color.LightGray);
DrawCircle(
259 + (int)(GetGamepadAxisMovement(0, GamepadAxis.LeftX) * 20),
152 + (int)(GetGamepadAxisMovement(0, GamepadAxis.LeftY) * 20),
259 + (int)(GetGamepadAxisMovement(gamepad, GamepadAxis.LeftX) * 20),
152 + (int)(GetGamepadAxisMovement(gamepad, GamepadAxis.LeftY) * 20),
25,
Color.Black
);
@ -156,36 +180,36 @@ public class InputGamepad
DrawCircle(461, 237, 38, Color.Black);
DrawCircle(461, 237, 33, Color.LightGray);
DrawCircle(
461 + (int)(GetGamepadAxisMovement(0, GamepadAxis.RightX) * 20),
237 + (int)(GetGamepadAxisMovement(0, GamepadAxis.RightY) * 20),
461 + (int)(GetGamepadAxisMovement(gamepad, GamepadAxis.RightX) * 20),
237 + (int)(GetGamepadAxisMovement(gamepad, GamepadAxis.RightY) * 20),
25, Color.Black
);
// Draw axis: left-right triggers
float leftTriggerX = GetGamepadAxisMovement(0, GamepadAxis.LeftTrigger);
float rightTriggerX = GetGamepadAxisMovement(0, GamepadAxis.RightTrigger);
float leftTriggerX = GetGamepadAxisMovement(gamepad, GamepadAxis.LeftTrigger);
float rightTriggerX = GetGamepadAxisMovement(gamepad, GamepadAxis.RightTrigger);
DrawRectangle(170, 30, 15, 70, Color.Gray);
DrawRectangle(604, 30, 15, 70, Color.Gray);
DrawRectangle(170, 30, 15, (int)(((1.0f + leftTriggerX) / 2.0f) * 70), Color.Red);
DrawRectangle(604, 30, 15, (int)(((1.0f + rightTriggerX) / 2.0f) * 70), Color.Red);
}
else if (gamepadName == PS3_NAME_ID)
else if (gamepadName.Contains(PS_ALIAS_1, StringComparison.OrdinalIgnoreCase) || gamepadName.Contains(PS_ALIAS_2, StringComparison.OrdinalIgnoreCase))
{
DrawTexture(texPs3Pad, 0, 0, Color.DarkGray);
// Draw buttons: ps
if (IsGamepadButtonDown(0, GamepadButton.Middle))
if (IsGamepadButtonDown(gamepad, GamepadButton.Middle))
{
DrawCircle(396, 222, 13, Color.Red);
}
// Draw buttons: basic
if (IsGamepadButtonDown(0, GamepadButton.MiddleLeft))
if (IsGamepadButtonDown(gamepad, GamepadButton.MiddleLeft))
{
DrawRectangle(328, 170, 32, 13, Color.Red);
}
if (IsGamepadButtonDown(0, GamepadButton.MiddleRight))
if (IsGamepadButtonDown(gamepad, GamepadButton.MiddleRight))
{
DrawTriangle(
new Vector2(436, 168),
@ -195,22 +219,22 @@ public class InputGamepad
);
}
if (IsGamepadButtonDown(0, GamepadButton.RightFaceUp))
if (IsGamepadButtonDown(gamepad, GamepadButton.RightFaceUp))
{
DrawCircle(557, 144, 13, Color.Lime);
}
if (IsGamepadButtonDown(0, GamepadButton.RightFaceRight))
if (IsGamepadButtonDown(gamepad, GamepadButton.RightFaceRight))
{
DrawCircle(586, 173, 13, Color.Red);
}
if (IsGamepadButtonDown(0, GamepadButton.RightFaceDown))
if (IsGamepadButtonDown(gamepad, GamepadButton.RightFaceDown))
{
DrawCircle(557, 203, 13, Color.Violet);
}
if (IsGamepadButtonDown(0, GamepadButton.RightFaceLeft))
if (IsGamepadButtonDown(gamepad, GamepadButton.RightFaceLeft))
{
DrawCircle(527, 173, 13, Color.Pink);
}
@ -218,33 +242,33 @@ public class InputGamepad
// Draw buttons: d-pad
DrawRectangle(225, 132, 24, 84, Color.Black);
DrawRectangle(195, 161, 84, 25, Color.Black);
if (IsGamepadButtonDown(0, GamepadButton.LeftFaceUp))
if (IsGamepadButtonDown(gamepad, GamepadButton.LeftFaceUp))
{
DrawRectangle(225, 132, 24, 29, Color.Red);
}
if (IsGamepadButtonDown(0, GamepadButton.LeftFaceDown))
if (IsGamepadButtonDown(gamepad, GamepadButton.LeftFaceDown))
{
DrawRectangle(225, 132 + 54, 24, 30, Color.Red);
}
if (IsGamepadButtonDown(0, GamepadButton.LeftFaceLeft))
if (IsGamepadButtonDown(gamepad, GamepadButton.LeftFaceLeft))
{
DrawRectangle(195, 161, 30, 25, Color.Red);
}
if (IsGamepadButtonDown(0, GamepadButton.LeftFaceRight))
if (IsGamepadButtonDown(gamepad, GamepadButton.LeftFaceRight))
{
DrawRectangle(195 + 54, 161, 30, 25, Color.Red);
}
// Draw buttons: left-right back buttons
if (IsGamepadButtonDown(0, GamepadButton.LeftTrigger1))
if (IsGamepadButtonDown(gamepad, GamepadButton.LeftTrigger1))
{
DrawCircle(239, 82, 20, Color.Red);
}
if (IsGamepadButtonDown(0, GamepadButton.RightTrigger1))
if (IsGamepadButtonDown(gamepad, GamepadButton.RightTrigger1))
{
DrawCircle(557, 82, 20, Color.Red);
}
@ -253,8 +277,8 @@ public class InputGamepad
DrawCircle(319, 255, 35, Color.Black);
DrawCircle(319, 255, 31, Color.LightGray);
DrawCircle(
319 + (int)(GetGamepadAxisMovement(0, GamepadAxis.LeftX) * 20),
255 + (int)(GetGamepadAxisMovement(0, GamepadAxis.LeftY) * 20),
319 + (int)(GetGamepadAxisMovement(gamepad, GamepadAxis.LeftX) * 20),
255 + (int)(GetGamepadAxisMovement(gamepad, GamepadAxis.LeftY) * 20),
25,
Color.Black
);
@ -263,15 +287,15 @@ public class InputGamepad
DrawCircle(475, 255, 35, Color.Black);
DrawCircle(475, 255, 31, Color.LightGray);
DrawCircle(
475 + (int)(GetGamepadAxisMovement(0, GamepadAxis.RightX) * 20),
255 + (int)(GetGamepadAxisMovement(0, GamepadAxis.RightY) * 20),
475 + (int)(GetGamepadAxisMovement(gamepad, GamepadAxis.RightX) * 20),
255 + (int)(GetGamepadAxisMovement(gamepad, GamepadAxis.RightY) * 20),
25,
Color.Black
);
// Draw axis: left-right triggers
float leftTriggerX = GetGamepadAxisMovement(0, GamepadAxis.LeftTrigger);
float rightTriggerX = GetGamepadAxisMovement(0, GamepadAxis.RightTrigger);
float leftTriggerX = GetGamepadAxisMovement(gamepad, GamepadAxis.LeftTrigger);
float rightTriggerX = GetGamepadAxisMovement(gamepad, GamepadAxis.RightTrigger);
DrawRectangle(169, 48, 15, 70, Color.Gray);
DrawRectangle(611, 48, 15, 70, Color.Gray);
DrawRectangle(169, 48, 15, (int)(((1.0f - leftTriggerX) / 2.0f) * 70), Color.Red);
@ -283,12 +307,12 @@ public class InputGamepad
// TODO: Draw generic gamepad
}
DrawText($"DETECTED AXIS [{GetGamepadAxisCount(0)}]:", 10, 50, 10, Color.Maroon);
DrawText($"DETECTED AXIS [{GetGamepadAxisCount(gamepad)}]:", 10, 50, 10, Color.Maroon);
for (int i = 0; i < GetGamepadAxisCount(0); i++)
for (int i = 0; i < GetGamepadAxisCount(gamepad); i++)
{
DrawText(
$"AXIS {i}: {GetGamepadAxisMovement(0, (GamepadAxis)i)}",
$"AXIS {i}: {GetGamepadAxisMovement(gamepad, (GamepadAxis)i)}",
20,
70 + 20 * i,
10,
@ -296,6 +320,10 @@ public class InputGamepad
);
}
DrawRectangleRec(vibrateButton, Color.SkyBlue);
DrawText("VIBRATE", (int)(vibrateButton.X + 14), (int)(vibrateButton.Y + 1), 10, Color.DarkGray);
if (GetGamepadButtonPressed() != (int)GamepadButton.Unknown)
{
DrawText($"DETECTED BUTTON: {GetGamepadButtonPressed()}", 10, 430, 10, Color.Red);
@ -307,7 +335,7 @@ public class InputGamepad
}
else
{
DrawText("GP1: NOT DETECTED", 10, 10, 10, Color.Gray);
DrawText($"GP{gamepad}: NOT DETECTED", 10, 10, 10, Color.Gray);
DrawTexture(texXboxPad, 0, 0, Color.LightGray);
}

View file

@ -1,11 +1,15 @@
/*******************************************************************************************
*
* raylib [core] example - Gestures Detection
* raylib [core] example - input gestures
*
* This example has been created using raylib 1.4 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* Example complexity rating: [] 2/4
*
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
* Example originally created with raylib 1.4, last time updated with raylib 4.2
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2016-2025 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
@ -25,7 +29,7 @@ public class InputGestures
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - gestures detection");
InitWindow(screenWidth, screenHeight, "raylib [core] example - input gestures");
Vector2 touchPosition = new(0, 0);
Rectangle touchArea = new(220, 10, screenWidth - 230, screenHeight - 20);

View file

@ -0,0 +1,474 @@
/*******************************************************************************************
*
* raylib [core] example - input gestures testbed
*
* Example complexity rating: [] 3/4
*
* Example originally created with raylib 5.0, last time updated with raylib 6.0
*
* Example contributed by ubkp (@ubkp) and reviewed by Ramon Santamaria (@raysan5)
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2023-2025 ubkp (@ubkp)
*
********************************************************************************************/
using System.Numerics;
namespace Examples.Core;
using static Raylib_cs.Raylib;
public class InputGesturesTestBed
{
public const int GESTURE_LOG_SIZE = 20;
public const int MAX_TOUCH_COUNT = 32;
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
public static int Main()
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - input gestures testbed");
Vector2 messagePosition = new Vector2(160, 7);
// Last gesture variables definitions
Gesture lastGesture = 0;
Vector2 lastGesturePosition = new Vector2(165, 130);
// Gesture log variables definitions
// NOTE: The gesture log uses an array (as an inverted circular queue) to store the performed gestures
string[] gestureLog = new string[GESTURE_LOG_SIZE + 1];
for (int i = 0; i < GESTURE_LOG_SIZE; i++)
{
gestureLog[i] = new string(new char[12]);
}
;
// NOTE: The index for the inverted circular queue (moving from last to first direction, then looping around)
int gestureLogIndex = GESTURE_LOG_SIZE;
Gesture previousGesture = 0;
// Log mode values:
// - 0 shows repeated events
// - 1 hides repeated events
// - 2 shows repeated events but hide hold events
// - 3 hides repeated events and hide hold events
int logMode = 1;
Color gestureColor = new Color(0, 0, 0, 255);
Rectangle logButton1 = new Rectangle(53, 7, 48, 26);
Rectangle logButton2 = new Rectangle(108, 7, 36, 26);
Vector2 gestureLogPosition = new Vector2(10, 10);
// Protractor variables definitions
float angleLength = 90.0f;
float currentAngleDegrees = 0.0f;
Vector2 finalVector = new Vector2(0.0f, 0.0f);
Vector2 protractorPosition = new Vector2(266.0f, 315.0f);
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//--------------------------------------------------------------------------------------
// Handle common gestures data
int i, ii; // Iterators that will be reused by all for loops
Gesture currentGesture = GetGestureDetected();
float currentDragDegrees = GetGestureDragAngle();
float currentPitchDegrees = GetGesturePinchAngle();
int touchCount = GetTouchPointCount();
// Handle last gesture
if ((currentGesture != 0) && ((int)currentGesture != 4) && (currentGesture != previousGesture))
{
lastGesture = currentGesture; // Filter the meaningful gestures (1, 2, 8 to 512) for the display
}
// Handle gesture log
if (IsMouseButtonReleased(MouseButton.Left))
{
if (CheckCollisionPointRec(GetMousePosition(), logButton1))
{
switch (logMode)
{
case 3:
logMode = 2;
break;
case 2:
logMode = 3;
break;
case 1:
logMode = 0;
break;
default:
logMode = 1;
break;
}
}
else if (CheckCollisionPointRec(GetMousePosition(), logButton2))
{
switch (logMode)
{
case 3:
logMode = 1;
break;
case 2:
logMode = 0;
break;
case 1:
logMode = 3;
break;
default:
logMode = 2;
break;
}
}
}
int fillLog = 0; // Gate variable to be used to allow or not the gesture log to be filled
if (currentGesture != 0)
{
if (logMode == 3) // 3 hides repeated events and hide hold events
{
if ((((int)currentGesture != 4) && (currentGesture != previousGesture)) || ((int)currentGesture < 3))
{
fillLog = 1;
}
}
else if (logMode == 2) // 2 shows repeated events but hide hold events
{
if ((int)currentGesture != 4)
{
fillLog = 1;
}
}
else if (logMode == 1) // 1 hides repeated events
{
if (currentGesture != previousGesture)
{
fillLog = 1;
}
}
else // 0 shows repeated events
{
fillLog = 1;
}
}
if (fillLog > 0) // If one of the conditions from logMode was met, fill the gesture log
{
previousGesture = currentGesture;
gestureColor = GetGestureColor((int)currentGesture);
if (gestureLogIndex <= 0)
{
gestureLogIndex = GESTURE_LOG_SIZE;
}
gestureLogIndex--;
// Copy the gesture respective name to the gesture log array
gestureLog[gestureLogIndex] = GetGestureName((int)currentGesture);
}
// Handle protractor
if ((int)currentGesture > 255)
{
currentAngleDegrees = currentPitchDegrees; // Pinch In and Pinch Out
}
else if ((int)currentGesture > 15)
{
currentAngleDegrees = currentDragDegrees; // Swipe Right, Swipe Left, Swipe Up and Swipe Down
}
else if (currentGesture > 0)
{
currentAngleDegrees = 0.0f; // Tap, Doubletap, Hold and Grab
}
float currentAngleRadians =
((currentAngleDegrees + 90.0f) * MathF.PI / 180); // Convert the current angle to Radians
// Calculate the final vector for display
finalVector = new Vector2(
(angleLength * MathF.Sin(currentAngleRadians)) + protractorPosition.X,
(angleLength * MathF.Cos(currentAngleRadians)) + protractorPosition.Y
)
;
// Handle touch and mouse pointer points
Vector2[] touchPosition = new Vector2[MAX_TOUCH_COUNT];
Vector2 mousePosition = Vector2.Zero;
if (currentGesture != Gesture.None)
{
if (touchCount != 0)
{
for (i = 0; i < touchCount; i++)
{
touchPosition[i] = GetTouchPosition(i); // Fill the touch positions
}
}
else
{
mousePosition = GetMousePosition();
}
}
//--------------------------------------------------------------------------------------
// Draw
//--------------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(Color.RayWhite);
// Draw common elements
DrawText("*", (int)messagePosition.X + 5, (int)messagePosition.Y + 5, 10, Color.Black);
DrawText("Example optimized for Web/HTML5\non Smartphones with Touch Screen.", (int)messagePosition.X + 15,
(int)messagePosition.Y + 5, 10, Color.Black);
DrawText("*", (int)messagePosition.X + 5, (int)messagePosition.Y + 35, 10, Color.Black);
DrawText("While running on Desktop Web Browsers,\ninspect and turn on Touch Emulation.",
(int)messagePosition.X + 15, (int)messagePosition.Y + 35, 10, Color.Black);
// Draw last gesture
DrawText("Last gesture", (int)lastGesturePosition.X + 33, (int)lastGesturePosition.Y - 47, 20, Color.Black);
DrawText("Swipe Tap Pinch Touch", (int)lastGesturePosition.X + 17,
(int)lastGesturePosition.Y - 18, 10, Color.Black);
DrawRectangle((int)lastGesturePosition.X + 20, (int)lastGesturePosition.Y, 20, 20,
lastGesture == Gesture.SwipeUp ? Color.Red : Color.LightGray);
DrawRectangle((int)lastGesturePosition.X, (int)lastGesturePosition.Y + 20, 20, 20,
lastGesture == Gesture.SwipeLeft ? Color.Red : Color.LightGray);
DrawRectangle((int)lastGesturePosition.X + 40, (int)lastGesturePosition.Y + 20, 20, 20,
lastGesture == Gesture.SwipeRight ? Color.Red : Color.LightGray);
DrawRectangle((int)lastGesturePosition.X + 20, (int)lastGesturePosition.Y + 40, 20, 20,
lastGesture == Gesture.SwipeDown ? Color.Red : Color.LightGray);
DrawCircle((int)lastGesturePosition.X + 80, (int)lastGesturePosition.Y + 16, 10,
lastGesture == Gesture.Tap ? Color.Blue : Color.LightGray);
DrawRing(new Vector2(
lastGesturePosition.X + 103, lastGesturePosition.Y + 16
), 6.0f, 11.0f, 0.0f, 360.0f, 0, lastGesture == Gesture.Drag ? Color.Lime : Color.LightGray);
DrawCircle((int)lastGesturePosition.X + 80, (int)lastGesturePosition.Y + 43, 10,
lastGesture == Gesture.DoubleTap ? Color.SkyBlue : Color.LightGray);
DrawCircle((int)lastGesturePosition.X + 103, (int)lastGesturePosition.Y + 43, 10,
lastGesture == Gesture.DoubleTap ? Color.SkyBlue : Color.LightGray);
DrawTriangle(new Vector2(
lastGesturePosition.X + 122, lastGesturePosition.Y + 16
), new Vector2(
lastGesturePosition.X + 137, lastGesturePosition.Y + 26
), new Vector2(
lastGesturePosition.X + 137, lastGesturePosition.Y + 6
), lastGesture == Gesture.PinchOut ? Color.Orange : Color.LightGray);
DrawTriangle(new Vector2(
lastGesturePosition.X + 147, lastGesturePosition.Y + 6
), new Vector2(
lastGesturePosition.X + 147, lastGesturePosition.Y + 26
), new Vector2(
lastGesturePosition.X + 162, lastGesturePosition.Y + 16
), lastGesture == Gesture.PinchOut ? Color.Orange : Color.Gray);
DrawTriangle(new Vector2(
lastGesturePosition.X + 125, lastGesturePosition.Y + 33
), new Vector2(
lastGesturePosition.X + 125, lastGesturePosition.Y + 53
), new Vector2(
lastGesturePosition.X + 140, lastGesturePosition.Y + 43
), lastGesture == Gesture.PinchIn ? Color.Violet : Color.LightGray);
DrawTriangle(new Vector2(
lastGesturePosition.X + 144, lastGesturePosition.Y + 43
), new Vector2(
lastGesturePosition.X + 159, lastGesturePosition.Y + 53
), new Vector2(
lastGesturePosition.X + 159, lastGesturePosition.Y + 33
), lastGesture == Gesture.PinchIn ? Color.Violet : Color.LightGray);
for (i = 0; i < 4; i++)
{
DrawCircle((int)lastGesturePosition.X + 180, (int)lastGesturePosition.Y + 7 + i * 15, 5,
touchCount <= i ? Color.LightGray : gestureColor);
}
// Draw gesture log
DrawText("Log", (int)gestureLogPosition.X, (int)gestureLogPosition.Y, 20, Color.Black);
// Loop in both directions to print the gesture log array in the inverted order (and looping around if the index started somewhere in the middle)
for (i = 0, ii = gestureLogIndex; i < GESTURE_LOG_SIZE; i++, ii = (ii + 1) % GESTURE_LOG_SIZE)
{
DrawText(gestureLog[ii], (int)gestureLogPosition.X, (int)gestureLogPosition.Y + 410 - i * 20, 20,
(i == 0 ? gestureColor : Color.LightGray));
}
Color logButton1Color, logButton2Color;
switch (logMode)
{
case 3:
logButton1Color = Color.Maroon;
logButton2Color = Color.Maroon;
break;
case 2:
logButton1Color = Color.Gray;
logButton2Color = Color.Maroon;
break;
case 1:
logButton1Color = Color.Maroon;
logButton2Color = Color.Gray;
break;
default:
logButton1Color = Color.Gray;
logButton2Color = Color.Gray;
break;
}
DrawRectangleRec(logButton1, logButton1Color);
DrawText("Hide", (int)logButton1.X + 7, (int)logButton1.Y + 3, 10, Color.White);
DrawText("Repeat", (int)logButton1.X + 7, (int)logButton1.Y + 13, 10, Color.White);
DrawRectangleRec(logButton2, logButton2Color);
DrawText("Hide", (int)logButton1.X + 62, (int)logButton1.Y + 3, 10, Color.White);
DrawText("Hold", (int)logButton1.X + 62, (int)logButton1.Y + 13, 10, Color.White);
// Draw protractor
DrawText("Angle", (int)protractorPosition.X + 55, (int)protractorPosition.Y + 76, 10, Color.Black);
// Note: Official it's using raylibs functions for string manipulation. But in C# it will end up in an unsafe handling.
string angleString = currentAngleDegrees.ToString("F3");
int angleStringDot = angleString.IndexOf('.');
string angleStringTrim = angleString.Substring(0, angleStringDot + 3);
DrawText(angleStringTrim, (int)protractorPosition.X + 55, (int)protractorPosition.Y + 92, 20, gestureColor);
DrawCircleV(protractorPosition, 80.0f, Color.White);
DrawLineEx(new Vector2(
protractorPosition.X - 90, protractorPosition.Y
), new Vector2(
protractorPosition.X + 90, protractorPosition.Y
), 3.0f, Color.LightGray);
DrawLineEx(new Vector2(
protractorPosition.X, protractorPosition.Y - 90
), new Vector2(
protractorPosition.X, protractorPosition.Y + 90
), 3.0f, Color.LightGray);
DrawLineEx(new Vector2(
protractorPosition.X - 80, protractorPosition.Y - 45
), new Vector2(
protractorPosition.X + 80, protractorPosition.Y + 45
), 3.0f, Color.Green);
DrawLineEx(new Vector2(
protractorPosition.X - 80, protractorPosition.Y + 45
), new Vector2(
protractorPosition.X + 80, protractorPosition.Y - 45
), 3.0f, Color.Green);
DrawText("0", (int)protractorPosition.X + 96, (int)protractorPosition.Y - 9, 20, Color.Black);
DrawText("30", (int)protractorPosition.X + 74, (int)protractorPosition.Y - 68, 20, Color.Black);
DrawText("90", (int)protractorPosition.X - 11, (int)protractorPosition.Y - 110, 20, Color.Black);
DrawText("150", (int)protractorPosition.X - 100, (int)protractorPosition.Y - 68, 20, Color.Black);
DrawText("180", (int)protractorPosition.X - 124, (int)protractorPosition.Y - 9, 20, Color.Black);
DrawText("210", (int)protractorPosition.X - 100, (int)protractorPosition.Y + 50, 20, Color.Black);
DrawText("270", (int)protractorPosition.X - 18, (int)protractorPosition.Y + 92, 20, Color.Black);
DrawText("330", (int)protractorPosition.X + 72, (int)protractorPosition.Y + 50, 20, Color.Black);
if (currentAngleDegrees != 0.0f)
{
DrawLineEx(protractorPosition, finalVector, 3.0f, gestureColor);
}
// Draw touch and mouse pointer points
if (currentGesture != Gesture.None)
{
if (touchCount != 0)
{
for (i = 0; i < touchCount; i++)
{
DrawCircleV(touchPosition[i], 50.0f, Fade(gestureColor, 0.5f));
DrawCircleV(touchPosition[i], 5.0f, gestureColor);
}
if (touchCount == 2)
{
DrawLineEx(touchPosition[0], touchPosition[1], (((int)currentGesture == 512) ? 8.0f : 12.0f),
gestureColor);
}
}
else
{
DrawCircleV(mousePosition, 35.0f, Fade(gestureColor, 0.5f));
DrawCircleV(mousePosition, 5.0f, gestureColor);
}
}
EndDrawing();
//--------------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}
static string GetGestureName(int gesture)
{
switch (gesture)
{
case 0:
return "None";
case 1:
return "Tap";
case 2:
return "Double Tap";
case 4:
return "Hold";
case 8:
return "Drag";
case 16:
return "Swipe Right";
case 32:
return "Swipe Left";
case 64:
return "Swipe Up";
case 128:
return "Swipe Down";
case 256:
return "Pinch In";
case 512:
return "Pinch Out";
default:
return "Unknown";
}
}
// Get color for gesture value
static Color GetGestureColor(int gesture)
{
switch (gesture)
{
case 0:
return Color.Black;
case 1:
return Color.Blue;
case 2:
return Color.SkyBlue;
case 4:
return Color.Black;
case 8:
return Color.Lime;
case 16:
return Color.Red;
case 32:
return Color.Red;
case 64:
return Color.Red;
case 128:
return Color.Red;
case 256:
return Color.Violet;
case 512:
return Color.Orange;
default:
return Color.Black;
}
}
}

View file

@ -1,11 +1,15 @@
/*******************************************************************************************
*
* raylib [core] example - Keyboard input
* raylib [core] example - input keys
*
* This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* Example complexity rating: [] 1/4
*
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
* Example originally created with raylib 1.0, last time updated with raylib 1.0
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2014-2025 Ramon Santamaria (@raysan5)
*
********************************************************************************************/

View file

@ -1,14 +1,19 @@
/*******************************************************************************************
*
* raylib [core] example - Mouse input
* raylib [core] example - input mouse
*
* This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* Example complexity rating: [] 1/4
*
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
* Example originally created with raylib 1.0, last time updated with raylib 5.5
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2014-2025 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
@ -36,6 +41,19 @@ public class InputMouse
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KeyboardKey.H))
{
if (IsCursorHidden())
{
ShowCursor();
}
else
{
HideCursor();
}
}
ballPosition = GetMousePosition();
if (IsMouseButtonPressed(MouseButton.Left))
@ -50,6 +68,18 @@ public class InputMouse
{
ballColor = Color.DarkBlue;
}
else if (IsMouseButtonPressed(MouseButton.Extra))
{
ballColor = Color.Yellow;
}
else if (IsMouseButtonPressed(MouseButton.Forward))
{
ballColor = Color.Orange;
}
else if (IsMouseButtonPressed(MouseButton.Back))
{
ballColor = Color.Beige;
}
//----------------------------------------------------------------------------------
// Draw
@ -60,6 +90,16 @@ public class InputMouse
DrawCircleV(ballPosition, 40, ballColor);
DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, Color.DarkGray);
DrawText("Press 'H' to toggle cursor visibility", 10, 30, 20, Color.DarkGray);
if (IsCursorHidden())
{
DrawText("CURSOR HIDDEN", 20, 60, 20, Color.Red);
}
else
{
DrawText("CURSOR VISIBLE", 20, 60, 20, Color.Lime);
}
EndDrawing();
//----------------------------------------------------------------------------------

View file

@ -1,11 +1,15 @@
/*******************************************************************************************
*
* raylib [core] examples - Mouse wheel input
* raylib [core] example - input mouse wheel
*
* This test has been created using raylib 1.1 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* Example complexity rating: [] 1/4
*
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
* Example originally created with raylib 1.1, last time updated with raylib 1.3
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2014-2025 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
@ -25,9 +29,7 @@ public class InputMouseWheel
InitWindow(screenWidth, screenHeight, "raylib [core] example - input mouse wheel");
int boxPositionY = screenHeight / 2 - 40;
// Scrolling speed in pixels
int scrollSpeed = 4;
int scrollSpeed = 4; // Scrolling speed in pixels
SetTargetFPS(60);
//--------------------------------------------------------------------------------------

View file

@ -1,13 +1,17 @@
/*******************************************************************************************
*
* raylib [core] example - Input multitouch
* raylib [core] example - input multitouch
*
* This example has been created using raylib 2.1 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* Example complexity rating: [] 1/4
*
* Example originally created with raylib 2.1, last time updated with raylib 2.5
*
* Example contributed by Berni (@Berni8k) and reviewed by Ramon Santamaria (@raysan5)
*
* Copyright (c) 2019 Berni (@Berni8k) and Ramon Santamaria (@raysan5)
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2019-2025 Berni (@Berni8k) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/

View file

@ -0,0 +1,225 @@
/*******************************************************************************************
*
* raylib [core] example - input virtual controls
*
* Example complexity rating: [] 2/4
*
* Example originally created with raylib 5.0, last time updated with raylib 5.0
*
* Example contributed by GreenSnakeLinux (@GreenSnakeLinux),
* reviewed by Ramon Santamaria (@raysan5), oblerion (@oblerion) and danilwhale (@danilwhale)
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2024-2025 GreenSnakeLinux (@GreenSnakeLinux) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
using System.Numerics;
namespace Examples.Core;
using static Raylib_cs.Raylib;
public enum PadButton
{
BUTTON_NONE = -1,
BUTTON_UP,
BUTTON_LEFT,
BUTTON_RIGHT,
BUTTON_DOWN,
BUTTON_MAX
}
public class InputVirtualControls
{
public static int Main()
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - input virtual controls");
Vector2 padPosition = new Vector2(100, 350);
float buttonRadius = 30;
Vector2[] buttonPositions =
[
new Vector2(
padPosition.X,padPosition.Y - buttonRadius * 1.5f
), // Up
new Vector2(
padPosition.X - buttonRadius * 1.5f, padPosition.Y
), // Left
new Vector2(
padPosition.X + buttonRadius * 1.5f, padPosition.Y
), // Right
new Vector2(
padPosition.X, padPosition.Y + buttonRadius * 1.5f
) // Down
];
Vector2[][] arrowTris = [
// Up
[
new Vector2(
buttonPositions[0].X, buttonPositions[0].Y - 12
),
new Vector2(
buttonPositions[0].X - 9, buttonPositions[0].Y + 9
),
new Vector2(
buttonPositions[0].X + 9, buttonPositions[0].Y + 9
)
],
// Left
[
new Vector2(
buttonPositions[1].X + 9, buttonPositions[1].Y - 9
),
new Vector2(
buttonPositions[1].X - 12, buttonPositions[1].Y
),
new Vector2(
buttonPositions[1].X + 9, buttonPositions[1].Y + 9
)
],
// Right
[
new Vector2(
buttonPositions[2].X + 12, buttonPositions[2].Y
),
new Vector2(
buttonPositions[2].X - 9, buttonPositions[2].Y - 9
),
new Vector2(
buttonPositions[2].X - 9, buttonPositions[2].Y + 9
)
],
// Down
[
new Vector2(
buttonPositions[3].X - 9, buttonPositions[3].Y - 9
),
new Vector2(
buttonPositions[3].X, buttonPositions[3].Y + 12
),
new Vector2(
buttonPositions[3].X + 9, buttonPositions[3].Y - 9
)
]
]
;
Color[] buttonLabelColors = [
Color.Yellow, // Up
Color.Blue, // Left
Color.Red, // Right
Color.Green // Down
];
int pressedButton = (int)PadButton.BUTTON_NONE;
Vector2 inputPosition = new Vector2(0, 0);
Vector2 playerPosition = new Vector2((float)screenWidth / 2, (float)screenHeight / 2);
float playerSpeed = 75f;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//--------------------------------------------------------------------------
if ((GetTouchPointCount() > 0))
{
inputPosition = GetTouchPosition(0); // Use touch position
}
else
{
inputPosition = GetMousePosition(); // Use mouse position
}
// Reset pressed button to none
pressedButton = (int)PadButton.BUTTON_NONE;
// Make sure user is pressing left mouse button if they're from desktop
if ((GetTouchPointCount() > 0) ||
((GetTouchPointCount() == 0) && IsMouseButtonDown(MouseButton.Left)))
{
// Find nearest D-Pad button to the input position
for (int i = 0; i < (int)PadButton.BUTTON_MAX; i++)
{
float distX = MathF.Abs(buttonPositions[i].X - inputPosition.X);
float distY = MathF.Abs(buttonPositions[i].Y - inputPosition.Y);
if ((distX + distY < buttonRadius))
{
pressedButton = i;
break;
}
}
}
// Move player according to pressed button
switch ((PadButton)pressedButton)
{
case PadButton.BUTTON_UP:
playerPosition.Y -= playerSpeed * GetFrameTime();
break;
case PadButton.BUTTON_LEFT:
playerPosition.X -= playerSpeed * GetFrameTime();
break;
case PadButton.BUTTON_RIGHT:
playerPosition.X += playerSpeed * GetFrameTime();
break;
case PadButton.BUTTON_DOWN:
playerPosition.Y += playerSpeed * GetFrameTime();
break;
default:
break;
}
;
//--------------------------------------------------------------------------
// Draw
//--------------------------------------------------------------------------
BeginDrawing();
ClearBackground(Color.RayWhite);
// Draw world
DrawCircleV(playerPosition, 50, Color.Maroon);
// Draw GUI
for (int i = 0; i < (int)PadButton.BUTTON_MAX; i++)
{
DrawCircleV(buttonPositions[i], buttonRadius, (i == pressedButton) ? Color.DarkGray : Color.Black);
DrawTriangle(
arrowTris[i][0],
arrowTris[i][1],
arrowTris[i][2],
buttonLabelColors[i]
);
}
DrawText("move the player with D-Pad buttons", 10, 10, 20, Color.DarkGray);
EndDrawing();
//--------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}
}

View file

@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<StartupObject>Examples.Program</StartupObject>
<RunWorkingDirectory>$(MSBuildThisFileDirectory)</RunWorkingDirectory>
<LangVersion>12</LangVersion>
<LangVersion>default</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

View file

@ -0,0 +1,117 @@
/*******************************************************************************************
*
* raylib [models] example - loading gltf
*
* Example complexity rating: [] 1/4
*
* LIMITATIONS:
* - Only supports 1 armature per file, and skips loading it if there are multiple armatures
* - Only supports linear interpolation (default method in Blender when checked
* "Always Sample Animations" when exporting a GLTF file)
* - Only supports translation/rotation/scale animation channel.path,
* weights not considered (i.e. morph targets)
*
* Example originally created with raylib 3.7, last time updated with raylib 4.2
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2020-2025 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Models;
public class LoadingGltf
{
public static int Main()
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - loading gltf");
// Define the camera to look into our 3d world
Camera3D camera = new();
camera.Position = new Vector3(6.0f, 6.0f, 6.0f);
camera.Target = new Vector3(0.0f, 2.0f, 0.0f);
camera.Up = new Vector3(0.0f, 1.0f, 0.0f);
camera.FovY = 45.0f;
camera.Projection = CameraProjection.Perspective;
Model model = LoadModel("resources/models/gltf/robot.glb");
Vector3 position = new(0.0f, 0.0f, 0.0f);
// Load animation data
var anims = LoadModelAnimations("resources/models/gltf/robot.glb");
// Animation playing variables
int animIndex = 0;
float animCurrentFrame = 0.0f;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose())
{
// Update
//----------------------------------------------------------------------------------
UpdateCamera(ref camera, CameraMode.Orbital);
if (IsKeyPressed(KeyboardKey.Right))
{
animIndex = (animIndex + 1) % anims.Length;
}
else if (IsKeyPressed(KeyboardKey.Left))
{
animIndex = (animIndex + anims.Length - 1) % anims.Length;
}
// Update model animation
animCurrentFrame = (animCurrentFrame + 1) % anims[animIndex].KeyFrameCount;
UpdateModelAnimation(model, anims[animIndex], (float)animCurrentFrame);
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(Color.RayWhite);
BeginMode3D(camera);
DrawModel(
model,
position,
1f,
Color.White
);
DrawGrid(10, 1.0f);
EndMode3D();
DrawText($"Current animation: {anims[animIndex].NameToString()}", 10, 40, 20, Color.Maroon);
DrawText("Use the LEFT/RIGHT keys to switch animation", 10, 10, 20, Color.Gray);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadModelAnimations(anims);
UnloadModel(model);
CloseWindow();
//--------------------------------------------------------------------------------------
return 0;
}
}

View file

@ -1,28 +1,31 @@
/*******************************************************************************************
*
* raylib [models] example - Load 3d model with animations and play them
* raylib [models] example - loading iqm
*
* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* Example complexity rating: [] 2/4
*
* Example originally created with raylib 2.5, last time updated with raylib 3.5
*
* Example contributed by Culacant (@culacant) and reviewed by Ramon Santamaria (@raysan5)
*
* Copyright (c) 2019 Culacant (@culacant) and Ramon Santamaria (@raysan5)
* NOTES: To export an IQM model from blender, make sure it is not posed, the vertices need
* to be in the same position as they would be in edit mode and the scale of the models is
* set to 0; scaling can be set from the export menu
*
********************************************************************************************
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* To export a model from blender, make sure it is not posed, the vertices need to be in the
* same position as they would be in edit mode.
* and that the scale of your models is set to 0. Scaling can be done from the export menu.
* Copyright (c) 2019-2025 Culacant (@culacant) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
using System.Numerics;
using System.Runtime.InteropServices;
using static Raylib_cs.Raylib;
namespace Examples.Models;
public class AnimationDemo
public class LoadingIqm
{
public unsafe static int Main()
{
@ -36,20 +39,22 @@ public class AnimationDemo
// Define the camera to look into our 3d world
Camera3D camera = new();
camera.Position = new Vector3(10.0f, 10.0f, 10.0f);
camera.Target = new Vector3(0.0f, 0.0f, 0.0f);
camera.Target = new Vector3(0.0f, 4.0f, 0.0f);
camera.Up = new Vector3(0.0f, 1.0f, 0.0f);
camera.FovY = 45.0f;
camera.Projection = CameraProjection.Perspective;
Model model = LoadModel("resources/models/iqm/guy.iqm");
Texture2D texture = LoadTexture("resources/models/iqm/guytex.png");
Raylib.SetMaterialTexture(ref model, 0, MaterialMapIndex.Albedo, ref texture);
Raylib.SetMaterialTexture(ref model, 0, MaterialMapIndex.Diffuse, ref texture);
Vector3 position = new(0.0f, 0.0f, 0.0f);
// Load animation data
int animsCount = 0;
var anims = LoadModelAnimations("resources/models/iqm/guyanim.iqm", ref animsCount);
int animFrameCounter = 0;
var anims = LoadModelAnimations("resources/models/iqm/guyanim.iqm");
// Animation playing variables
int animIndex = 0;
float animCurrentFrame = 0.0f;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@ -59,17 +64,15 @@ public class AnimationDemo
{
// Update
//----------------------------------------------------------------------------------
UpdateCamera(ref camera, CameraMode.Free);
UpdateCamera(ref camera, CameraMode.Orbital);
// Play animation when spacebar is held down
if (IsKeyDown(KeyboardKey.Space))
animCurrentFrame += 1.0f;
UpdateModelAnimation(model, anims[0], animCurrentFrame);
if (animCurrentFrame >= anims[0].KeyFrameCount)
{
animFrameCounter++;
UpdateModelAnimation(model, anims[0], animFrameCounter);
if (animFrameCounter >= anims[0].FrameCount)
{
animFrameCounter = 0;
}
animCurrentFrame = 0;
}
//----------------------------------------------------------------------------------
@ -89,17 +92,10 @@ public class AnimationDemo
Color.White
);
for (int i = 0; i < model.BoneCount; i++)
{
var framePoses = anims[0].FramePoses;
DrawCube(framePoses[animFrameCounter][i].Translation, 0.2f, 0.2f, 0.2f, Color.Red);
}
DrawGrid(10, 1.0f);
EndMode3D();
DrawText("PRESS SPACE to PLAY MODEL ANIMATION", 10, 10, 20, Color.Maroon);
DrawText($"Current animation: {anims[animIndex].NameToString()}", 10, 10, 20, Color.Maroon);
DrawText("(c) Guy IQM 3D model by @culacant", screenWidth - 200, screenHeight - 20, 10, Color.Gray);
EndDrawing();
@ -109,9 +105,7 @@ public class AnimationDemo
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(texture);
UnloadModelAnimations(anims, animsCount);
UnloadModelAnimations(anims);
UnloadModel(model);
CloseWindow();

View file

@ -64,7 +64,7 @@ public class ModelLoading
{
// Update
//----------------------------------------------------------------------------------
UpdateCamera(ref camera, CameraMode.Free);
UpdateCamera(ref camera, CameraMode.Orbital);
if (IsFileDropped())
{

View file

@ -37,7 +37,7 @@ public class SkyboxDemo
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
Model skybox = LoadModelFromMesh(cube);
bool useHdr = true;
bool useHdr = false;
// Load skybox shader and set required locations
// NOTE: Some locations are automatically set at shader loading

View file

@ -1,4 +1,3 @@
using System;
using System.Diagnostics;
using Examples.Core;
using Examples.Shapes;
@ -34,6 +33,9 @@ public class ExampleList
public static ExampleInfo[] AllExamples = new[]
{
// Core
new ExampleInfo("DeltaTime", DeltaTime.Main),
new ExampleInfo("InputGesturesTestBed", InputGesturesTestBed.Main),
new ExampleInfo("InputVirtualControls", InputVirtualControls.Main),
new ExampleInfo("Camera2dPlatformer", Camera2dPlatformer.Main),
new ExampleInfo("Camera2dDemo", Camera2dDemo.Main),
new ExampleInfo("Camera3dFirstPerson", Camera3dFirstPerson.Main),
@ -110,7 +112,8 @@ public class ExampleList
new ExampleInfo("WritingAnim", WritingAnim.Main),
// Models
new ExampleInfo("AnimationDemo", AnimationDemo.Main),
new ExampleInfo("LoadingIqm", LoadingIqm.Main),
new ExampleInfo("LoadingGltf", LoadingGltf.Main),
new ExampleInfo("BillboardDemo", BillboardDemo.Main),
new ExampleInfo("BoxCollisions", BoxCollisions.Main),
new ExampleInfo("CubicmapDemo", CubicmapDemo.Main),
@ -127,6 +130,7 @@ public class ExampleList
new ExampleInfo("SkyboxDemo", SkyboxDemo.Main),
new ExampleInfo("WavingCubes", WavingCubes.Main),
new ExampleInfo("YawPitchRoll", YawPitchRoll.Main),
new ExampleInfo("DynamicMesh", DynamicMesh.Main),
// Shaders
new ExampleInfo("BasicLighting", BasicLighting.Main),

View file

@ -156,7 +156,7 @@ public class BasicPbr
PbrLightType.Point,
new Vector3(1.0f, 1.0f, -2.0f),
new Vector3(0.0f, 0.0f, 0.0f),
Color.Black,
Color.Blue,
2.0f,
shader);
@ -232,7 +232,7 @@ public class BasicPbr
var emissiveIntensity = 0.01f;
SetShaderValue(shader, emissiveIntensityLoc, &emissiveIntensity, ShaderUniformDataType.Float);
DrawModel(car, Vector3.Zero, 0.005f, Color.White); // Draw car model
DrawModel(car, Vector3.Zero, 0.25f, Color.White); // Draw car model
// Draw spheres to show the lights positions
for (var i = 0; i < 4; i++)

View file

@ -60,7 +60,7 @@ public class ShapesTextures
DrawText("USING DEFAULT SHADER", 20, 40, 10, Color.Red);
DrawCircle(80, 120, 35, Color.DarkBlue);
DrawCircleGradient(80, 220, 60, Color.Green, Color.SkyBlue);
DrawCircleGradient(new Vector2(80, 220), 60, Color.Green, Color.SkyBlue);
DrawCircleLines(80, 340, 80, Color.DarkBlue);

View file

@ -46,7 +46,7 @@ public class BasicShapes
DrawLine(18, 42, screenWidth - 18, 42, Color.Black);
DrawCircle(screenWidth / 4, 120, 35, Color.DarkBlue);
DrawCircleGradient(screenWidth / 4, 220, 60, Color.Green, Color.SkyBlue);
DrawCircleGradient(new Vector2(screenWidth / 4, 220), 60, Color.Green, Color.SkyBlue);
DrawCircleLines(screenWidth / 4, 340, 80, Color.DarkBlue);
DrawRectangle(screenWidth / 4 * 2 - 60, 100, 120, 60, Color.Red);

View file

@ -35,14 +35,10 @@ fonts:
| pixantiqua.fnt, pixantiqua.png | Gerhard Großmann | [Freeware](https://www.dafont.com/es/pixantiqua.font) | Atlas made with [BMFont](https://www.angelcode.com/products/bmfont/) by [@raysan5](https://github.com/raysan5) |
| pixantiqua.ttf | Gerhard Großmann | [Freeware](https://www.dafont.com/es/pixantiqua.font) | - |
| symbola.fnt, symbola.png | George Douros | [Freeware](https://fontlibrary.org/en/font/symbola) | Atlas made with [BMFont](https://www.angelcode.com/products/bmfont/) by [@raysan5](https://github.com/raysan5) |
| DotGothic16-Regular.ttf | [The DotGothic16 Project Authors](https://github.com/fontworks-fonts/DotGothic16) | [Open Font License](https://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL) | - |
| NotoSansTC-Regular.ttf | [Adobe](http://www.adobe.com/) | [SIL Open Font License](https://openfontlicense.org/documents/OFL.txt) | - |
models:
| resource | author | licence | notes |
| :------------------- | :---------: | :------ | :---- |
| models/obj/barracks.obj,<br> models/barracks_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
| models/obj/church.obj,<br> models/church_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
| models/obj/watermill.obj,<br> models/watermill_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
| models/obj/castle.obj,<br>models/obj/castle_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
| models/obj/bridge.obj,<br>models/obj/bridge_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
| models/obj/house.obj,<br>models/obj/house_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
@ -56,7 +52,10 @@ models:
| models/vox/chr_knight.vox | ❔ | ❔ | - |
| models/vox/chr_sword.vox | ❔ | ❔ | - |
| models/vox/monu9.vox | ❔ | ❔ | - |
| models/barracks.obj,<br> models/barracks_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
| models/church.obj,<br> models/church_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
| models/watermill.obj,<br> models/watermill_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
| greenman.glb, greenman_hat.glb, greenman_sword.glb, greenman_shield.glb | [@ip](https://github.com/ipzaur) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - |
images:
| resource | author | licence | notes |
@ -92,4 +91,4 @@ images:
| dresden_square_1k.hdr | [HDRIHaven](https://hdrihaven.com/hdri/?h=dresden_square) | [CC0](https://hdrihaven.com/p/license.php) | - |
| dresden_square_2k.hdr | [HDRIHaven](https://hdrihaven.com/hdri/?h=dresden_square) | [CC0](https://hdrihaven.com/p/license.php) | - |
| skybox.png | ❔ | ❔ | - |
| mandrill.png | ❔ | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Mandrill (a.k.a. Baboon) |

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 291 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 828 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 615 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 KiB

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 KiB

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 KiB

View file

@ -1,5 +0,0 @@
robot.glb model by @Quaternius (https://www.patreon.com/quaternius)
Licensed under CC0 1.0 Universal (CC0 1.0) - Public Domain Dedication (https://creativecommons.org/publicdomain/zero/1.0/)
greenman.glb, greenman_hat.glb, greenman_sword.glb, greenman_shield.glb models by @iP (https://github.com/ipzaur)
Licensed under CC0 1.0 Universal (CC0 1.0) - Public Domain Dedication (https://creativecommons.org/publicdomain/zero/1.0/)

View file

@ -0,0 +1,12 @@
# Blender MTL File: 'None'
# Material Count: 1
newmtl skin
Ns 86.470579
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 0.000000
illum 9

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,9 +0,0 @@
The following models are provided by the official github repo of voxel-model format by MagikaVoxel developer @ephtracy
GitHub official repo: https://github.com/ephtracy/voxel-model
- chr_knight.vox - https://github.com/ephtracy/voxel-model/blob/master/vox/character/chr_knight.vox
- chr_sword.vox - https://github.com/ephtracy/voxel-model/blob/master/vox/character/chr_sword.vox
- monu9.vox - https://github.com/ephtracy/voxel-model/blob/master/vox/monument/monu9.vox
Worth mentioning there is no license specified for the models yet: https://github.com/ephtracy/voxel-model/issues/22

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View file

@ -0,0 +1,80 @@
#version 100
precision mediump float;
// Input from the vertex shader
varying vec2 fragTexCoord;
// Output color for the screen
varying vec4 finalColor;
uniform sampler2D texture0;
uniform vec2 resolution;
// Fontsize less then 9 may be not complete
uniform float fontSize;
float GreyScale(in vec3 col)
{
return dot(col, vec3(0.2126, 0.7152, 0.0722));
}
float GetCharacter(float n, vec2 p)
{
p = floor(p*vec2(-4.0, 4.0) + 2.5);
// Check if the calculated coordinate is inside the 5x5 grid (from 0.0 to 4.0)
if (clamp(p.x, 0.0, 4.0) == p.x && clamp(p.y, 0.0, 4.0) == p.y)
{
float a = floor(p.x + 0.5) + 5.0*floor(p.y + 0.5);
// This checked if the 'a'-th bit of 'n' was set
float shiftedN = floor(n/pow(2.0, a));
if (mod(shiftedN, 2.0) == 1.0)
{
return 1.0; // The bit is on
}
}
return 0.0; // The bit is off, or we are outside the grid
}
// -----------------------------------------------------------------------------
// Main shader logic
// -----------------------------------------------------------------------------
void main()
{
vec2 charPixelSize = vec2(fontSize, fontSize);
vec2 uvCellSize = charPixelSize/resolution;
// The cell size is based on the fontSize set by application
vec2 cellUV = floor(fragTexCoord/uvCellSize)*uvCellSize;
vec3 cellColor = texture2D(texture0, cellUV).rgb;
// Gray is used to define what character will be selected to draw
float gray = GreyScale(cellColor);
float n = 4096.0;
// Character set from https://www.shadertoy.com/view/lssGDj
// Create new bitmaps https://thrill-project.com/archiv/coding/bitmap/
if (gray > 0.2) n = 65600.0; // :
if (gray > 0.3) n = 18725316.0; // v
if (gray > 0.4) n = 15255086.0; // o
if (gray > 0.5) n = 13121101.0; // &
if (gray > 0.6) n = 15252014.0; // 8
if (gray > 0.7) n = 13195790.0; // @
if (gray > 0.8) n = 11512810.0; // #
vec2 localUV = (fragTexCoord - cellUV)/uvCellSize; // Range [0.0, 1.0]
vec2 p = localUV*2.0 - 1.0; // Range [-1.0, 1.0]
// cellColor and charShape will define the color of the char
vec3 color = cellColor*GetCharacter(n, p);
gl_FragColor = vec4(color, 1.0);
}

View file

@ -0,0 +1,58 @@
#version 100
precision mediump float;
varying vec3 fragPosition;
varying vec2 fragTexCoord;
varying vec4 fragColor;
varying vec3 fragNormal;
uniform sampler2D texture0;
uniform vec4 colDiffuse;
uniform vec3 viewPos;
uniform float numBands;
struct Light {
int enabled;
int type;
vec3 position;
vec3 target;
vec4 color;
};
uniform Light lights[4];
void main()
{
vec4 texColor = texture2D(texture0, fragTexCoord);
vec3 baseColor = texColor.rgb * fragColor.rgb * colDiffuse.rgb;
vec3 norm = normalize(fragNormal);
float lightAccum = 0.08; // ambient floor
for (int i = 0; i < 4; i++)
{
if (lights[i].enabled == 1) // no continue in GLSL ES 1.0
{
vec3 lightDir;
if (lights[i].type == 0)
{
// Directional: direction is from position toward target.
lightDir = normalize(lights[i].position - lights[i].target);
}
else
{
// Point: direction from surface to light.
lightDir = normalize(lights[i].position - fragPosition);
}
float NdotL = max(dot(norm, lightDir), 0.0);
// Quantize NdotL into numBands discrete steps.
float quantized = min(floor(NdotL * numBands), numBands - 1.0) / (numBands - 1.0);
lightAccum += quantized * lights[i].color.r;
}
}
lightAccum = clamp(lightAccum, 0.0, 1.0);
gl_FragColor = vec4(baseColor * lightAccum, texColor.a * colDiffuse.a);
}

View file

@ -0,0 +1,47 @@
#version 100
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec3 vertexNormal;
attribute vec4 vertexColor;
uniform mat4 mvp;
uniform mat4 matModel;
varying vec3 fragPosition;
varying vec2 fragTexCoord;
varying vec4 fragColor;
varying vec3 fragNormal;
mat3 inverse(mat3 m)
{
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
float b01 = a22*a11 - a12*a21;
float b11 = -a22*a10 + a12*a20;
float b21 = a21*a10 - a11*a20;
float det = a00*b01 + a01*b11 + a02*b21;
return mat3(b01, (-a22*a01 + a02*a21), ( a12*a01 - a02*a11),
b11, ( a22*a00 - a02*a20), (-a12*a00 + a02*a10),
b21, (-a21*a00 + a01*a20), ( a11*a00 - a01*a10)) / det;
}
mat3 transpose(mat3 m)
{
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
void main()
{
fragPosition = vec3(matModel * vec4(vertexPosition, 1.0));
fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
fragNormal = normalize(normalMatrix * vertexNormal);
gl_Position = mvp * vec4(vertexPosition, 1.0);
}

View file

@ -0,0 +1,34 @@
#version 100
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
uniform float contrast;
uniform float saturation;
uniform float brightness;
void main()
{
// Get texel color
vec4 texel = texture2D(texture0, fragTexCoord);
// Apply contrast
texel.rgb = (texel.rgb - 0.5)*(contrast/100.0 + 1.0) + 0.5;
// Apply brightness
texel.rgb = texel.rgb + brightness/100.0;
// Apply saturation
float intensity = dot(texel.rgb, vec3(0.299, 0.587, 0.114));
texel.rgb = (texel.rgb - intensity)*saturation/100.0 + texel.rgb;
// Output resulting color
gl_FragColor = texel;
}

View file

@ -0,0 +1,59 @@
#version 100
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D gPosition;
uniform sampler2D gNormal;
uniform sampler2D gAlbedoSpec;
struct Light {
int enabled;
int type; // Unused in this demo
vec3 position;
vec3 target; // Unused in this demo
vec4 color;
};
const int NR_LIGHTS = 4;
uniform Light lights[NR_LIGHTS];
uniform vec3 viewPosition;
const float QUADRATIC = 0.032;
const float LINEAR = 0.09;
void main()
{
vec3 fragPosition = texture2D(gPosition, fragTexCoord).rgb;
vec3 normal = texture2D(gNormal, fragTexCoord).rgb;
vec3 albedo = texture2D(gAlbedoSpec, fragTexCoord).rgb;
float specular = texture2D(gAlbedoSpec, fragTexCoord).a;
vec3 ambient = albedo*vec3(0.1);
vec3 viewDirection = normalize(viewPosition - fragPosition);
for (int i = 0; i < NR_LIGHTS; i++)
{
if (lights[i].enabled == 0) continue;
vec3 lightDirection = lights[i].position - fragPosition;
vec3 diffuse = max(dot(normal, lightDirection), 0.0)*albedo*lights[i].color.xyz;
vec3 halfwayDirection = normalize(lightDirection + viewDirection);
float spec = pow(max(dot(normal, halfwayDirection), 0.0), 32.0);
vec3 specular = specular*spec*lights[i].color.xyz;
// Attenuation
float distance = length(lights[i].position - fragPosition);
float attenuation = 1.0/(1.0 + LINEAR*distance + QUADRATIC*distance*distance);
diffuse *= attenuation;
specular *= attenuation;
ambient += diffuse + specular;
}
gl_FragColor = vec4(ambient, 1.0);
}

View file

@ -0,0 +1,16 @@
#version 100
// Input vertex attributes
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
// Output vertex attributes (to fragment shader)
varying vec2 fragTexCoord;
void main()
{
fragTexCoord = vertexTexCoord;
// Calculate final vertex position
gl_Position = vec4(vertexPosition, 1.0);
}

View file

@ -0,0 +1,29 @@
#version 100
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
// Input uniform values
uniform sampler2D depthTexture;
uniform bool flipY;
float nearPlane = 0.1;
float farPlane = 100.0;
void main()
{
// Handle potential Y-flipping
vec2 texCoord = fragTexCoord;
if (flipY) texCoord.y = 1.0 - texCoord.y;
// Sample depth texture
float depth = texture2D(depthTexture, texCoord).r;
// Linearize depth
float linearDepth = (2.0*nearPlane)/(farPlane + nearPlane - depth*(farPlane - nearPlane));
// Output final color
gl_FragColor = vec4(vec3(linearDepth), 1.0);
}

View file

@ -0,0 +1,20 @@
#version 100
#extension GL_EXT_frag_depth : enable
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
void main()
{
vec4 texelColor = texture2D(texture0, fragTexCoord);
gl_FragColor = texelColor*colDiffuse*fragColor;
gl_FragDepthEXT = 1.0 - gl_FragCoord.z;
}

View file

@ -0,0 +1,44 @@
#version 100
precision highp float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
// Input size in pixels of the textures
uniform vec2 resolution;
void main()
{
// Size of one pixel in texture coordinates (from 0.0 to 1.0)
float x = 1.0/resolution.x;
float y = 1.0/resolution.y;
// Status of the current cell (1 = alive, 0 = dead)
int origValue = (texture2D(texture0, fragTexCoord).r < 0.1)? 1 : 0;
// Sum of alive neighbors
int sumValue = (texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y)).r < 0.1)? 1 : 0; // Top-left
sumValue += (texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y )).r < 0.1)? 1 : 0; // Top
sumValue += (texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y)).r < 0.1)? 1 : 0; // Top-right
sumValue += (texture2D(texture0, vec2(fragTexCoord.x, fragTexCoord.y - y)).r < 0.1)? 1 : 0; // Left
sumValue += (texture2D(texture0, vec2(fragTexCoord.x, fragTexCoord.y + y)).r < 0.1)? 1 : 0; // Right
sumValue += (texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y)).r < 0.1)? 1 : 0; // Bottom-left
sumValue += (texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y )).r < 0.1)? 1 : 0; // Bottom
sumValue += (texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y)).r < 0.1)? 1 : 0; // Bottom-right
// Game of life rules:
// Current cell remains alive when 2 or 3 neighbors are alive, dies otherwise
// Current cell goes from dead to alive when exactly 3 neighbors are alive
if ((origValue == 1 && sumValue == 2) || sumValue == 3)
gl_FragColor = vec4(0.0, 0.0, 0.0, 255.0); // Alive: draw the pixel black
else
gl_FragColor = fragColor; // Dead: draw the pixel with the background color, RAYWHITE
}

View file

@ -0,0 +1,36 @@
#version 100
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec3 fragPosition;
varying vec2 fragTexCoord;
varying vec3 fragNormal;
varying vec4 fragColor;
// TODO: Is there some alternative for GLSL100
//layout (location = 0) out vec3 gPosition;
//layout (location = 1) out vec3 gNormal;
//layout (location = 2) out vec4 gAlbedoSpec;
//uniform vec3 gPosition;
//uniform vec3 gNormal;
//uniform vec4 gAlbedoSpec;
// Input uniform values
uniform sampler2D texture0; // Diffuse texture
uniform sampler2D specularTexture;
void main()
{
// Store the fragment position vector in the first gbuffer texture
//gPosition = fragPosition;
// Store the per-fragment normals into the gbuffer
//gNormal = normalize(fragNormal);
// Store the diffuse per-fragment color
gl_FragColor.rgb = texture2D(texture0, fragTexCoord).rgb;
// Store specular intensity in gAlbedoSpec's alpha component
gl_FragColor.a = texture2D(specularTexture, fragTexCoord).r;
}

View file

@ -0,0 +1,60 @@
#version 100
// Input vertex attributes
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec3 vertexNormal;
attribute vec4 vertexColor;
// Input uniform values
uniform mat4 matModel;
uniform mat4 matView;
uniform mat4 matProjection;
// Output vertex attributes (to fragment shader)
varying vec3 fragPosition;
varying vec2 fragTexCoord;
varying vec3 fragNormal;
varying vec4 fragColor;
// https://github.com/glslify/glsl-inverse
mat3 inverse(mat3 m)
{
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
float b01 = a22*a11 - a12*a21;
float b11 = -a22*a10 + a12*a20;
float b21 = a21*a10 - a11*a20;
float det = a00*b01 + a01*b11 + a02*b21;
return mat3(b01, (-a22*a01 + a02*a21), (a12*a01 - a02*a11),
b11, (a22*a00 - a02*a20), (-a12*a00 + a02*a10),
b21, (-a21*a00 + a01*a20), (a11*a00 - a01*a10))/det;
}
// https://github.com/glslify/glsl-transpose
mat3 transpose(mat3 m)
{
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
void main()
{
// Calculate vertex attributes for fragment shader
vec4 worldPos = matModel*vec4(vertexPosition, 1.0);
fragPosition = worldPos.xyz;
fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
fragNormal = normalMatrix*vertexNormal;
// Calculate final vertex position
gl_Position = matProjection*matView*worldPos;
}

View file

@ -0,0 +1,22 @@
#version 100
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec2 fragTexCoord2;
varying vec3 fragPosition;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform sampler2D texture1;
void main()
{
// Texel color fetching from texture sampler
vec4 texelColor = texture2D(texture0, fragTexCoord);
vec4 texelColor2 = texture2D(texture1, fragTexCoord2);
gl_FragColor = texelColor*texelColor2;
}

View file

@ -0,0 +1,31 @@
#version 100
// Input vertex attributes
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec2 vertexTexCoord2;
attribute vec4 vertexColor;
// Input uniform values
uniform mat4 mvp;
uniform mat4 matModel;
// Output vertex attributes (to fragment shader)
varying vec3 fragPosition;
varying vec2 fragTexCoord;
varying vec2 fragTexCoord2;
varying vec4 fragColor;
// NOTE: Add your custom variables here
void main()
{
// Send vertex attributes to fragment shader
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
fragTexCoord = vertexTexCoord;
fragTexCoord2 = vertexTexCoord2;
fragColor = vertexColor;
// Calculate final vertex position
gl_Position = mvp*vec4(vertexPosition, 1.0);
}

View file

@ -0,0 +1,62 @@
#version 100
#define PI 3.1415926535897932384626433832795
precision highp float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
uniform vec2 offset; // Offset of the scale
uniform float zoom; // Zoom of the scale
// NOTE: Maximum number of shader for-loop iterations depend on GPU,
// For example, on RasperryPi for this examply only supports up to 60
uniform int maxIterations; // Max iterations per pixel
const float max = 4.0; // We consider infinite as 4.0: if a point reaches a distance of 4.0 it will escape to infinity
const float max2 = max*max; // Square of max to avoid computing square root
// WebGL shaders for loop iteration limit only const
const int maxIterationsLimit = 20000;
void main()
{
// The pixel coordinates are scaled so they are on the mandelbrot scale
// NOTE: fragTexCoord already comes as normalized screen coordinates but offset must be normalized before scaling and zoom
vec2 c = vec2((fragTexCoord.x - 0.5)*2.5, (fragTexCoord.y - 0.5)*1.5)/zoom;
c.x += offset.x;
c.y += offset.y;
float a = 0.0;
float b = 0.0;
// The Mandelbrot set is a two-dimensional set defined in the complex plane on which the iteration of the function
// Fc(z) = z^2 + c on the complex numbers c from the plane does not diverge to infinity starting at z = 0
// Here: z = a + bi. Iterations: z -> z^2 + c = (a + bi)^2 + (c.x + c.yi) = (a^2 - b^2 + c.x) + (2ab + c.y)i
for (int iter = 0; iter < maxIterationsLimit; iter++)
{
float aa = a*a;
float bb = b*b;
if (iter >= maxIterations)
{
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
return;
}
if (aa + bb > max2)
{
float normR = float(iter - (iter/55)*55)/55.0;
float normG = float(iter - (iter/69)*69)/69.0;
float normB = float(iter - (iter/40)*40)/40.0;
gl_FragColor = vec4(sin(normR*PI), sin(normG*PI), sin(normB*PI), 1.0);
return;
}
float twoab = 2.0*a*b;
a = aa - bb + c.x;
b = twoab + c.y;
}
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
}

View file

@ -0,0 +1,64 @@
#version 100
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec3 fragPosition;
varying vec2 fragTexCoord;
varying vec3 fragNormal; //used for when normal mapping is toggled off
varying vec4 fragColor;
varying mat3 TBN;
// Input uniform values
uniform sampler2D texture0;
uniform sampler2D normalMap;
uniform vec4 colDiffuse;
uniform vec3 viewPos;
// NOTE: Add your custom variables here
uniform vec3 lightPos;
uniform bool useNormalMap;
uniform float specularExponent;
void main()
{
vec4 texelColor = texture2D(texture0, vec2(fragTexCoord.x, fragTexCoord.y));
vec3 specular = vec3(0.0);
vec3 viewDir = normalize(viewPos - fragPosition);
vec3 lightDir = normalize(lightPos - fragPosition);
vec3 normal = vec3(0.0);
if (useNormalMap)
{
normal = texture2D(normalMap, vec2(fragTexCoord.x, fragTexCoord.y)).rgb;
// Transform normal values to the range -1.0 ... 1.0
normal = normalize(normal*2.0 - 1.0);
// Transform the normal from tangent-space to world-space for lighting calculation
normal = normalize(normal*TBN);
}
else
{
normal = normalize(fragNormal);
}
vec4 tint = colDiffuse*fragColor;
vec3 lightColor = vec3(1.0, 1.0, 1.0);
float NdotL = max(dot(normal, lightDir), 0.0);
vec3 lightDot = lightColor*NdotL;
float specCo = 0.0;
if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewDir, reflect(-lightDir, normal))), specularExponent);
specular += specCo;
vec4 finalColor = (texelColor*((tint + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
finalColor += texelColor*(vec4(1.0, 1.0, 1.0, 1.0)/40.0)*tint;
// Gamma correction
gl_FragColor = pow(finalColor, vec4(1.0/2.2));
}

View file

@ -0,0 +1,76 @@
#version 100
// Input vertex attributes
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec3 vertexNormal;
attribute vec4 vertexTangent;
attribute vec4 vertexColor;
// Input uniform values
uniform mat4 mvp;
uniform mat4 matModel;
// Output vertex attributes (to fragment shader)
varying vec3 fragPosition;
varying vec2 fragTexCoord;
varying vec3 fragNormal; //used for when normal mapping is toggled off
varying vec4 fragColor;
varying mat3 TBN;
// NOTE: Add your custom variables here
// https://github.com/glslify/glsl-inverse
mat3 inverse(mat3 m)
{
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
float b01 = a22*a11 - a12*a21;
float b11 = -a22*a10 + a12*a20;
float b21 = a21*a10 - a11*a20;
float det = a00*b01 + a01*b11 + a02*b21;
return mat3(b01, (-a22*a01 + a02*a21), (a12*a01 - a02*a11),
b11, (a22*a00 - a02*a20), (-a12*a00 + a02*a10),
b21, (-a21*a00 + a01*a20), (a11*a00 - a01*a10))/det;
}
// https://github.com/glslify/glsl-transpose
mat3 transpose(mat3 m)
{
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
void main()
{
// Compute binormal from vertex normal and tangent. W component is the tangent handedness
vec3 vertexBinormal = cross(vertexNormal, vertexTangent.xyz)*vertexTangent.w;
// Compute fragment normal based on normal transformations
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
// Compute fragment position based on model transformations
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
//Create TBN matrix for transforming the normal map values from tangent-space to world-space
fragNormal = normalize(normalMatrix*vertexNormal);
vec3 fragTangent = normalize(normalMatrix*vertexTangent.xyz);
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
vec3 fragBinormal = normalize(normalMatrix*vertexBinormal);
fragBinormal = cross(fragNormal, fragTangent);
TBN = transpose(mat3(fragTangent, fragBinormal, fragNormal));
fragColor = vertexColor;
fragTexCoord = vertexTexCoord;
gl_Position = mvp*vec4(vertexPosition, 1.0);
}

View file

@ -0,0 +1,8 @@
#version 100
precision mediump float;
void main()
{
gl_FragColor = vec4(0.05, 0.05, 0.05, 1.0);
}

View file

@ -0,0 +1,15 @@
#version 100
attribute vec3 vertexPosition;
attribute vec3 vertexNormal;
attribute vec2 vertexTexCoord;
attribute vec4 vertexColor;
uniform mat4 mvp;
uniform float outlineThickness;
void main()
{
vec3 extruded = vertexPosition + vertexNormal * outlineThickness;
gl_Position = mvp * vec4(extruded, 1.0);
}

View file

@ -0,0 +1,161 @@
#version 100
precision highp float;
#define MAX_LIGHTS 4
#define LIGHT_DIRECTIONAL 0
#define LIGHT_POINT 1
#define PI 3.14159265358979323846
struct Light {
int enabled;
int type;
vec3 position;
vec3 target;
vec4 color;
float intensity;
};
// Input vertex attributes (from vertex shader)
varying vec3 fragPosition;
varying vec2 fragTexCoord;
varying vec4 fragColor;
varying vec3 fragNormal;
varying vec4 shadowPos;
varying mat3 TBN;
// Input uniform values
uniform int numOfLights;
uniform sampler2D albedoMap;
uniform sampler2D mraMap;
uniform sampler2D normalMap;
uniform sampler2D emissiveMap; // r: Hight g:emissive
uniform vec2 tiling;
uniform vec2 offset;
uniform int useTexAlbedo;
uniform int useTexNormal;
uniform int useTexMRA;
uniform int useTexEmissive;
uniform vec4 albedoColor;
uniform vec4 emissiveColor;
uniform float normalValue;
uniform float metallicValue;
uniform float roughnessValue;
uniform float aoValue;
uniform float emissivePower;
// Input lighting values
uniform Light lights[MAX_LIGHTS];
uniform vec3 viewPos;
uniform vec3 ambientColor;
uniform float ambient;
// Reflectivity in range 0.0 to 1.0
// NOTE: Reflectivity is increased when surface view at larger angle
vec3 SchlickFresnel(float hDotV,vec3 refl)
{
return refl + (1.0 - refl)*pow(1.0 - hDotV, 5.0);
}
float GgxDistribution(float nDotH,float roughness)
{
float a = roughness*roughness*roughness*roughness;
float d = nDotH*nDotH*(a - 1.0) + 1.0;
d = PI*d*d;
return (a/max(d,0.0000001));
}
float GeomSmith(float nDotV,float nDotL,float roughness)
{
float r = roughness + 1.0;
float k = r*r/8.0;
float ik = 1.0 - k;
float ggx1 = nDotV/(nDotV*ik + k);
float ggx2 = nDotL/(nDotL*ik + k);
return ggx1*ggx2;
}
vec3 ComputePBR()
{
vec3 albedo = texture2D(albedoMap, vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y)).rgb;
albedo = vec3(albedoColor.x*albedo.x, albedoColor.y*albedo.y, albedoColor.z*albedo.z);
float metallic = clamp(metallicValue, 0.0, 1.0);
float roughness = clamp(roughnessValue, 0.0, 1.0);
float ao = clamp(aoValue, 0.0, 1.0);
if (useTexMRA == 1)
{
vec4 mra = texture2D(mraMap, vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y));
metallic = clamp(mra.r + metallicValue, 0.04, 1.0);
roughness = clamp(mra.g + roughnessValue, 0.04, 1.0);
ao = (mra.b + aoValue)*0.5;
}
vec3 N = normalize(fragNormal);
if (useTexNormal == 1)
{
N = texture2D(normalMap, vec2(fragTexCoord.x*tiling.x + offset.y, fragTexCoord.y*tiling.y + offset.y)).rgb;
N = normalize(N*2.0 - 1.0);
N = normalize(N*TBN);
}
vec3 V = normalize(viewPos - fragPosition);
vec3 emissive = vec3(0);
emissive = (texture2D(emissiveMap, vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y)).rgb).g*emissiveColor.rgb*emissivePower*float(useTexEmissive);
// return N;//vec3(metallic,metallic,metallic);
// If dia-electric use base reflectivity of 0.04 otherwise ut is a metal use albedo as base reflectivity
vec3 baseRefl = mix(vec3(0.04), albedo.rgb, metallic);
vec3 lightAccum = vec3(0.0); // Acumulate lighting lum
for (int i = 0; i < 4; i++)
{
vec3 L = normalize(lights[i].position - fragPosition); // Compute light vector
vec3 H = normalize(V + L); // Compute halfway bisecting vector
float dist = length(lights[i].position - fragPosition); // Compute distance to light
float attenuation = 1.0/(dist*dist*0.23); // Compute attenuation
vec3 radiance = lights[i].color.rgb*lights[i].intensity*attenuation; // Compute input radiance, light energy comming in
// Cook-Torrance BRDF distribution function
float nDotV = max(dot(N,V), 0.0000001);
float nDotL = max(dot(N,L), 0.0000001);
float hDotV = max(dot(H,V), 0.0);
float nDotH = max(dot(N,H), 0.0);
float D = GgxDistribution(nDotH, roughness); // Larger the more micro-facets aligned to H
float G = GeomSmith(nDotV, nDotL, roughness); // Smaller the more micro-facets shadow
vec3 F = SchlickFresnel(hDotV, baseRefl); // Fresnel proportion of specular reflectance
vec3 spec = (D*G*F)/(4.0*nDotV*nDotL);
// Difuse and spec light can't be above 1.0
// kD = 1.0 - kS diffuse component is equal 1.0 - spec comonent
vec3 kD = vec3(1.0) - F;
// Mult kD by the inverse of metallnes, only non-metals should have diffuse light
kD *= 1.0 - metallic;
lightAccum += ((kD*albedo.rgb/PI + spec)*radiance*nDotL)*float(lights[i].enabled); // Angle of light has impact on result
}
vec3 ambientFinal = (ambientColor + albedo)*ambient*0.5;
return (ambientFinal + lightAccum*ao + emissive);
}
void main()
{
vec3 color = ComputePBR();
// HDR tonemapping
color = pow(color, color + vec3(1.0));
// Gamma correction
color = pow(color, vec3(1.0/2.2));
gl_FragColor = vec4(color,1.0);
}

View file

@ -0,0 +1,74 @@
#version 100
// Input vertex attributes
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec3 vertexNormal;
attribute vec4 vertexTangent;
attribute vec4 vertexColor;
// Input uniform values
uniform mat4 mvp;
uniform mat4 matModel;
uniform mat4 matNormal;
uniform vec3 lightPos;
uniform vec4 difColor;
// Output vertex attributes (to fragment shader)
varying vec3 fragPosition;
varying vec2 fragTexCoord;
varying vec4 fragColor;
varying vec3 fragNormal;
varying mat3 TBN;
const float normalOffset = 0.1;
// https://github.com/glslify/glsl-inverse
mat3 inverse(mat3 m)
{
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
float b01 = a22*a11 - a12*a21;
float b11 = -a22*a10 + a12*a20;
float b21 = a21*a10 - a11*a20;
float det = a00*b01 + a01*b11 + a02*b21;
return mat3(b01, (-a22*a01 + a02*a21), (a12*a01 - a02*a11),
b11, (a22*a00 - a02*a20), (-a12*a00 + a02*a10),
b21, (-a21*a00 + a01*a20), (a11*a00 - a01*a10))/det;
}
// https://github.com/glslify/glsl-transpose
mat3 transpose(mat3 m)
{
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
void main()
{
// Compute binormal from vertex normal and tangent
vec3 vertexBinormal = cross(vertexNormal, vertexTangent.xyz)*vertexTangent.w;
// Compute fragment normal based on normal transformations
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
// Compute fragment position based on model transformations
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
fragTexCoord = vertexTexCoord*2.0;
fragNormal = normalize(normalMatrix*vertexNormal);
vec3 fragTangent = normalize(normalMatrix*vertexTangent.xyz);
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
vec3 fragBinormal = normalize(normalMatrix*vertexBinormal);
fragBinormal = cross(fragNormal, fragTangent);
TBN = transpose(mat3(fragTangent, fragBinormal, fragNormal));
// Calculate final vertex position
gl_Position = mvp*vec4(vertexPosition, 1.0);
}

View file

@ -0,0 +1,16 @@
#version 100
precision mediump float;
// Input uniform values
uniform vec4 color;
// NOTE: Add your custom variables here
void main()
{
// Each point is drawn as a screen space square of gl_PointSize size. gl_PointCoord contains where we are inside of
// it. (0, 0) is the top left, (1, 1) the bottom right corner
// Draw each point as a colored circle with alpha 1.0 in the center and 0.0 at the outer edges
gl_FragColor = vec4(color.rgb, color.a*(1.0 - length(gl_PointCoord.xy - vec2(0.5))*2.0));
}

View file

@ -0,0 +1,24 @@
#version 100
// Input vertex attributes
attribute vec3 vertexPosition;
// Input uniform values
uniform mat4 mvp;
uniform float currentTime;
// NOTE: Add your custom variables here
void main()
{
// Unpack data from vertexPosition
vec2 pos = vertexPosition.xy;
float period = vertexPosition.z;
// Calculate final vertex position (jiggle it around a bit horizontally)
pos += vec2(100.0, 0.0)*sin(period*currentTime);
gl_Position = mvp*vec4(pos.x, pos.y, 0.0, 1.0);
// Calculate the screen space size of this particle (also vary it over time)
gl_PointSize = 10.0 - 5.0*abs(sin(period*currentTime));
}

View file

@ -0,0 +1,76 @@
#version 100
precision mediump float;
// NOTE: SDF by Iñigo Quilez, licensed under MIT License
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
uniform vec4 rectangle; // Rectangle dimensions (x, y, width, height)
uniform vec4 radius; // Corner radius (top-left, top-right, bottom-left, bottom-right)
uniform vec4 color;
// Shadow parameters
uniform float shadowRadius;
uniform vec2 shadowOffset;
uniform float shadowScale;
uniform vec4 shadowColor;
// Border parameters
uniform float borderThickness;
uniform vec4 borderColor;
// Create a rounded rectangle using signed distance field
// Thanks to Iñigo Quilez (https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm)
// And thanks to inobelar (https://www.shadertoy.com/view/fsdyzB) for shader
// MIT License
float RoundedRectangleSDF(vec2 fragCoord, vec2 center, vec2 halfSize, vec4 radius)
{
vec2 fragFromCenter = fragCoord - center;
// Determine which corner radius to use
radius.xy = (fragFromCenter.y > 0.0) ? radius.xy : radius.zw;
radius.x = (fragFromCenter.x < 0.0) ? radius.x : radius.y;
// Calculate signed distance field
vec2 dist = abs(fragFromCenter) - halfSize + radius.x;
return min(max(dist.x, dist.y), 0.0) + length(max(dist, 0.0)) - radius.x;
}
void main()
{
// Texel color fetching from texture sampler
vec4 texelColor = texture2D(texture0, fragTexCoord);
// Requires fragment coordinate varying pixels
vec2 fragCoord = gl_FragCoord.xy;
// Calculate signed distance field for rounded rectangle
vec2 halfSize = rectangle.zw*0.5;
vec2 center = rectangle.xy + halfSize;
float recSDF = RoundedRectangleSDF(fragCoord, center, halfSize, radius);
// Calculate signed distance field for rectangle shadow
vec2 shadowHalfSize = halfSize*shadowScale;
vec2 shadowCenter = center + shadowOffset;
float shadowSDF = RoundedRectangleSDF(fragCoord, shadowCenter, shadowHalfSize, radius);
// Caculate alpha factors
float recFactor = smoothstep(1.0, 0.0, recSDF);
float shadowFactor = smoothstep(shadowRadius, 0.0, shadowSDF);
float borderFactor = smoothstep(0.0, 1.0, recSDF + borderThickness)*recFactor;
// Multiply each color by its respective alpha factor
vec4 recColor = vec4(color.rgb, color.a*recFactor);
vec4 shadowCol = vec4(shadowColor.rgb, shadowColor.a*shadowFactor);
vec4 borderCol = vec4(borderColor.rgb, borderColor.a*borderFactor);
// Combine the colors varying the order (shadow, rectangle, border)
gl_FragColor = mix(mix(shadowCol, recColor, recColor.a), borderCol, borderCol.a);
}

View file

@ -0,0 +1,86 @@
#version 100
precision mediump float;
// This shader is based on the basic lighting shader
// This only supports one light, which is directional, and it (of course) supports shadows
// Input vertex attributes (from vertex shader)
varying vec3 fragPosition;
varying vec2 fragTexCoord;
//varying in vec4 fragColor;
varying vec3 fragNormal;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
// Input lighting values
uniform vec3 lightDir;
uniform vec4 lightColor;
uniform vec4 ambient;
uniform vec3 viewPos;
// Input shadowmapping values
uniform mat4 lightVP; // Light source view-projection matrix
uniform sampler2D shadowMap;
uniform int shadowMapResolution;
void main()
{
// Texel color fetching from texture sampler
vec4 texelColor = texture2D(texture0, fragTexCoord);
vec3 lightDot = vec3(0.0);
vec3 normal = normalize(fragNormal);
vec3 viewD = normalize(viewPos - fragPosition);
vec3 specular = vec3(0.0);
vec3 l = -lightDir;
float NdotL = max(dot(normal, l), 0.0);
lightDot += lightColor.rgb*NdotL;
float specCo = 0.0;
if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewD, reflect(-(l), normal))), 16.0); // 16 refers to shine
specular += specCo;
vec4 finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
// Shadow calculations
vec4 fragPosLightSpace = lightVP*vec4(fragPosition, 1);
fragPosLightSpace.xyz /= fragPosLightSpace.w; // Perform the perspective division
fragPosLightSpace.xyz = (fragPosLightSpace.xyz + 1.0)/2.0; // Transform from [-1, 1] range to [0, 1] range
vec2 sampleCoords = fragPosLightSpace.xy;
float curDepth = fragPosLightSpace.z;
// Slope-scale depth bias: depth biasing reduces "shadow acne" artifacts, where dark stripes appear all over the scene
// The solution is adding a small bias to the depth
// In this case, the bias is proportional to the slope of the surface, relative to the light
float bias = max(0.0008*(1.0 - dot(normal, l)), 0.00008);
int shadowCounter = 0;
const int numSamples = 9;
// PCF (percentage-closer filtering) algorithm:
// Instead of testing if just one point is closer to the current point,
// we test the surrounding points as well
// This blurs shadow edges, hiding aliasing artifacts
vec2 texelSize = vec2(1.0/float(shadowMapResolution));
for (int x = -1; x <= 1; x++)
{
for (int y = -1; y <= 1; y++)
{
float sampleDepth = texture2D(shadowMap, sampleCoords + texelSize*vec2(x, y)).r;
if (curDepth - bias > sampleDepth) shadowCounter++;
}
}
finalColor = mix(finalColor, vec4(0, 0, 0, 1), float(shadowCounter)/float(numSamples));
// Add ambient lighting whether in shadow or not
finalColor += texelColor*(ambient/10.0)*colDiffuse;
// Gamma correction
finalColor = pow(finalColor, vec4(1.0/2.2));
gl_FragColor = finalColor;
}

View file

@ -0,0 +1,32 @@
#version 100
// Input vertex attributes
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec3 vertexNormal;
attribute vec4 vertexColor;
// Input uniform values
uniform mat4 mvp;
uniform mat4 matModel;
uniform mat4 matNormal;
// Output vertex attributes (to fragment shader)
varying vec3 fragPosition;
varying vec2 fragTexCoord;
varying vec4 fragColor;
varying vec3 fragNormal;
// NOTE: Add your custom variables here
void main()
{
// Send vertex attributes to fragment shader
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
// Calculate final vertex position
gl_Position = mvp*vec4(vertexPosition, 1.0);
}

View file

@ -0,0 +1,20 @@
#version 100
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
void main()
{
// Fetch color from texture sampler
vec4 texelColor = texture2D(texture0, fragTexCoord);
// Calculate final fragment color
gl_FragColor = texelColor*colDiffuse*fragColor;
}

View file

@ -0,0 +1,59 @@
#version 100
#define MAX_BONE_NUM 64
// Input vertex attributes
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec4 vertexColor;
attribute vec4 vertexBoneIndices;
attribute vec4 vertexBoneWeights;
// Input uniform values
uniform mat4 mvp;
uniform mat4 boneMatrices[MAX_BONE_NUM];
// Output vertex attributes (to fragment shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
void main()
{
int boneIndex0 = int(vertexBoneIndices.x);
int boneIndex1 = int(vertexBoneIndices.y);
int boneIndex2 = int(vertexBoneIndices.z);
int boneIndex3 = int(vertexBoneIndices.w);
// WARNING: OpenGL ES 2.0 does not support automatic matrix transposing, neither transpose() function
mat4 boneMatrixTransposed0 = mat4(
vec4(boneMatrices[boneIndex0][0].x, boneMatrices[boneIndex0][1].x, boneMatrices[boneIndex0][2].x, boneMatrices[boneIndex0][3].x),
vec4(boneMatrices[boneIndex0][0].y, boneMatrices[boneIndex0][1].y, boneMatrices[boneIndex0][2].y, boneMatrices[boneIndex0][3].y),
vec4(boneMatrices[boneIndex0][0].z, boneMatrices[boneIndex0][1].z, boneMatrices[boneIndex0][2].z, boneMatrices[boneIndex0][3].z),
vec4(boneMatrices[boneIndex0][0].w, boneMatrices[boneIndex0][1].w, boneMatrices[boneIndex0][2].w, boneMatrices[boneIndex0][3].w));
mat4 boneMatrixTransposed1 = mat4(
vec4(boneMatrices[boneIndex1][0].x, boneMatrices[boneIndex1][1].x, boneMatrices[boneIndex1][2].x, boneMatrices[boneIndex1][3].x),
vec4(boneMatrices[boneIndex1][0].y, boneMatrices[boneIndex1][1].y, boneMatrices[boneIndex1][2].y, boneMatrices[boneIndex1][3].y),
vec4(boneMatrices[boneIndex1][0].z, boneMatrices[boneIndex1][1].z, boneMatrices[boneIndex1][2].z, boneMatrices[boneIndex1][3].z),
vec4(boneMatrices[boneIndex1][0].w, boneMatrices[boneIndex1][1].w, boneMatrices[boneIndex1][2].w, boneMatrices[boneIndex1][3].w));
mat4 boneMatrixTransposed2 = mat4(
vec4(boneMatrices[boneIndex2][0].x, boneMatrices[boneIndex2][1].x, boneMatrices[boneIndex2][2].x, boneMatrices[boneIndex2][3].x),
vec4(boneMatrices[boneIndex2][0].y, boneMatrices[boneIndex2][1].y, boneMatrices[boneIndex2][2].y, boneMatrices[boneIndex2][3].y),
vec4(boneMatrices[boneIndex2][0].z, boneMatrices[boneIndex2][1].z, boneMatrices[boneIndex2][2].z, boneMatrices[boneIndex2][3].z),
vec4(boneMatrices[boneIndex2][0].w, boneMatrices[boneIndex2][1].w, boneMatrices[boneIndex2][2].w, boneMatrices[boneIndex2][3].w));
mat4 boneMatrixTransposed3 = mat4(
vec4(boneMatrices[boneIndex3][0].x, boneMatrices[boneIndex3][1].x, boneMatrices[boneIndex3][2].x, boneMatrices[boneIndex3][3].x),
vec4(boneMatrices[boneIndex3][0].y, boneMatrices[boneIndex3][1].y, boneMatrices[boneIndex3][2].y, boneMatrices[boneIndex3][3].y),
vec4(boneMatrices[boneIndex3][0].z, boneMatrices[boneIndex3][1].z, boneMatrices[boneIndex3][2].z, boneMatrices[boneIndex3][3].z),
vec4(boneMatrices[boneIndex3][0].w, boneMatrices[boneIndex3][1].w, boneMatrices[boneIndex3][2].w, boneMatrices[boneIndex3][3].w));
vec4 skinnedPosition =
vertexBoneWeights.x*(boneMatrixTransposed0*vec4(vertexPosition, 1.0)) +
vertexBoneWeights.y*(boneMatrixTransposed1*vec4(vertexPosition, 1.0)) +
vertexBoneWeights.z*(boneMatrixTransposed2*vec4(vertexPosition, 1.0)) +
vertexBoneWeights.w*(boneMatrixTransposed3*vec4(vertexPosition, 1.0));
fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
gl_Position = mvp*skinnedPosition;
}

View file

@ -0,0 +1,21 @@
#version 100
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
// NOTE: Add your custom variables here
uniform vec2 tiling;
void main()
{
vec2 texCoord = fragTexCoord*tiling;
gl_FragColor = texture2D(texture0, texCoord)*colDiffuse;
}

View file

@ -0,0 +1,17 @@
#version 100
precision mediump float;
// Input vertex attributes (from fragment shader)
varying vec2 fragTexCoord;
varying float height;
void main()
{
vec4 darkblue = vec4(0.0, 0.13, 0.18, 1.0);
vec4 lightblue = vec4(1.0, 1.0, 1.0, 1.0);
// Interpolate between two colors based on height
vec4 finalColor = mix(darkblue, lightblue, height);
gl_FragColor = finalColor;
}

View file

@ -0,0 +1,45 @@
#version 100
precision mediump float;
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec3 vertexNormal;
attribute vec4 vertexColor;
uniform mat4 mvp;
uniform mat4 matModel;
uniform mat4 matNormal;
uniform float time;
uniform sampler2D perlinNoiseMap;
varying vec3 fragPosition;
varying vec2 fragTexCoord;
varying vec3 fragNormal;
varying float height;
void main()
{
// Calculate animated texture coordinates based on time and vertex position
vec2 animatedTexCoord = sin(vertexTexCoord + vec2(sin(time + vertexPosition.x*0.1), cos(time + vertexPosition.z*0.1))*0.3);
// Normalize animated texture coordinates to range [0, 1]
animatedTexCoord = animatedTexCoord*0.5 + 0.5;
// Fetch displacement from the perlin noise map
float displacement = texture2D(perlinNoiseMap, animatedTexCoord).r*7.0; // Amplified displacement
// Displace vertex position
vec3 displacedPosition = vertexPosition + vec3(0.0, displacement, 0.0);
// Send vertex attributes to fragment shader
fragPosition = vec3(matModel*vec4(displacedPosition, 1.0));
fragTexCoord = vertexTexCoord;
fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
height = displacedPosition.y*0.2; // send height to fragment shader for coloring
// Calculate final vertex position
gl_Position = mvp*vec4(displacedPosition, 1.0);
}

View file

@ -0,0 +1,65 @@
#version 100
precision mediump float;
// Input from vertex shader
varying vec3 fragPosition;
varying vec4 fragColor;
varying vec3 fragNormal;
// Uniforms
uniform vec4 colDiffuse;
uniform vec4 ambient;
uniform vec3 viewPos;
#define MAX_LIGHTS 4
#define LIGHT_DIRECTIONAL 0
#define LIGHT_POINT 1
struct Light {
int enabled;
int type;
vec3 position;
vec3 target;
vec4 color;
};
uniform Light lights[MAX_LIGHTS];
void main()
{
vec3 lightDot = vec3(0.0);
vec3 normal = normalize(fragNormal);
vec3 viewD = normalize(viewPos - fragPosition);
vec3 specular = vec3(0.0);
for (int i = 0; i < MAX_LIGHTS; i++)
{
if (lights[i].enabled == 1)
{
vec3 light = vec3(0.0);
if (lights[i].type == LIGHT_DIRECTIONAL)
light = -normalize(lights[i].target - lights[i].position);
if (lights[i].type == LIGHT_POINT)
light = normalize(lights[i].position - fragPosition);
float NdotL = max(dot(normal, light), 0.0);
lightDot += lights[i].color.rgb*NdotL;
if (NdotL > 0.0)
{
float specCo = pow(max(0.0, dot(viewD, reflect(-light, normal))), 16.0);
specular += specCo;
}
}
}
vec4 finalColor = (fragColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
finalColor += fragColor*(ambient/10.0)*colDiffuse;
finalColor = pow(finalColor, vec4(1.0/2.2)); // gamma correction
gl_FragColor = finalColor;
}

View file

@ -0,0 +1,28 @@
#version 100
precision mediump float;
// Input vertex attributes
attribute vec3 vertexPosition;
attribute vec3 vertexNormal;
attribute vec4 vertexColor;
// attribute vec2 vertexTexCoord;
// Input uniform values
uniform mat4 mvp;
uniform mat4 matModel;
uniform mat4 matNormal;
// Output to fragment shader
varying vec3 fragPosition;
varying vec4 fragColor;
varying vec3 fragNormal;
void main()
{
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
fragColor = vertexColor;
fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
gl_Position = mvp*vec4(vertexPosition, 1.0);
}

View file

@ -0,0 +1,18 @@
#version 120
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
void main()
{
vec4 texelColor = texture2D(texture0, fragTexCoord);
if (texelColor.a == 0.0) discard;
gl_FragColor = texelColor*fragColor*colDiffuse;
}

View file

@ -0,0 +1,78 @@
#version 120
// Input from the vertex shader
varying vec2 fragTexCoord;
// Output color for the screen
varying vec4 finalColor;
uniform sampler2D texture0;
uniform vec2 resolution;
// Fontsize less then 9 may be not complete
uniform float fontSize;
float GreyScale(in vec3 col)
{
return dot(col, vec3(0.2126, 0.7152, 0.0722));
}
float GetCharacter(float n, vec2 p)
{
p = floor(p*vec2(-4.0, 4.0) + 2.5);
// Check if the calculated coordinate is inside the 5x5 grid (from 0.0 to 4.0)
if (clamp(p.x, 0.0, 4.0) == p.x && clamp(p.y, 0.0, 4.0) == p.y)
{
float a = floor(p.x + 0.5) + 5.0*floor(p.y + 0.5);
// This checked if the 'a'-th bit of 'n' was set
float shiftedN = floor(n/pow(2.0, a));
if (mod(shiftedN, 2.0) == 1.0)
{
return 1.0; // The bit is on
}
}
return 0.0; // The bit is off, or we are outside the grid
}
// -----------------------------------------------------------------------------
// Main shader logic
// -----------------------------------------------------------------------------
void main()
{
vec2 charPixelSize = vec2(fontSize, fontSize);
vec2 uvCellSize = charPixelSize / resolution;
// The cell size is based on the fontSize set by application
vec2 cellUV = floor(fragTexCoord / uvCellSize)*uvCellSize;
vec3 cellColor = texture2D(texture0, cellUV).rgb;
// Gray is used to define what character will be selected to draw
float gray = GreyScale(cellColor);
float n = 4096.0;
// Character set from https://www.shadertoy.com/view/lssGDj
// Create new bitmaps https://thrill-project.com/archiv/coding/bitmap/
if (gray > 0.2) n = 65600.0; // :
if (gray > 0.3) n = 18725316.0; // v
if (gray > 0.4) n = 15255086.0; // o
if (gray > 0.5) n = 13121101.0; // &
if (gray > 0.6) n = 15252014.0; // 8
if (gray > 0.7) n = 13195790.0; // @
if (gray > 0.8) n = 11512810.0; // #
vec2 localUV = (fragTexCoord - cellUV)/uvCellSize; // Range [0.0, 1.0]
vec2 p = localUV*2.0 - 1.0; // Range [-1.0, 1.0]
// cellColor and charShape will define the color of the char
vec3 color = cellColor*GetCharacter(n, p);
gl_FragColor = vec4(color, 1.0);
}

View file

@ -0,0 +1,56 @@
#version 120
varying vec3 fragPosition;
varying vec2 fragTexCoord;
varying vec4 fragColor;
varying vec3 fragNormal;
uniform sampler2D texture0;
uniform vec4 colDiffuse;
uniform vec3 viewPos;
uniform float numBands;
struct Light {
int enabled;
int type;
vec3 position;
vec3 target;
vec4 color;
};
uniform Light lights[4];
void main()
{
vec4 texColor = texture2D(texture0, fragTexCoord);
vec3 baseColor = texColor.rgb * fragColor.rgb * colDiffuse.rgb;
vec3 norm = normalize(fragNormal);
float lightAccum = 0.08; // ambient floor
for (int i = 0; i < 4; i++)
{
if (lights[i].enabled == 1)
{
vec3 lightDir;
if (lights[i].type == 0)
{
// Directional: direction is from position toward target.
lightDir = normalize(lights[i].position - lights[i].target);
}
else
{
// Point: direction from surface to light.
lightDir = normalize(lights[i].position - fragPosition);
}
float NdotL = max(dot(norm, lightDir), 0.0);
// Quantize NdotL into numBands discrete steps.
float quantized = min(floor(NdotL * numBands), numBands - 1.0) / (numBands - 1.0);
lightAccum += quantized * lights[i].color.r;
}
}
lightAccum = clamp(lightAccum, 0.0, 1.0);
gl_FragColor = vec4(baseColor * lightAccum, texColor.a * colDiffuse.a);
}

View file

@ -0,0 +1,48 @@
#version 120
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec3 vertexNormal;
attribute vec4 vertexColor;
uniform mat4 mvp;
uniform mat4 matModel;
varying vec3 fragPosition;
varying vec2 fragTexCoord;
varying vec4 fragColor;
varying vec3 fragNormal;
// inverse() and transpose() are not built-in until GLSL 1.40
mat3 inverse(mat3 m)
{
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
float b01 = a22*a11 - a12*a21;
float b11 = -a22*a10 + a12*a20;
float b21 = a21*a10 - a11*a20;
float det = a00*b01 + a01*b11 + a02*b21;
return mat3(b01, (-a22*a01 + a02*a21), ( a12*a01 - a02*a11),
b11, ( a22*a00 - a02*a20), (-a12*a00 + a02*a10),
b21, (-a21*a00 + a01*a20), ( a11*a00 - a01*a10)) / det;
}
mat3 transpose(mat3 m)
{
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
void main()
{
fragPosition = vec3(matModel * vec4(vertexPosition, 1.0));
fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
fragNormal = normalize(normalMatrix * vertexNormal);
gl_Position = mvp * vec4(vertexPosition, 1.0);
}

View file

@ -0,0 +1,31 @@
#version 120
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
uniform float contrast;
uniform float saturation;
uniform float brightness;
void main()
{
vec4 texel = texture2D(texture0, fragTexCoord); // Get texel color
// Apply contrast
texel.rgb = (texel.rgb - 0.5)*(contrast/100.0 + 1.0) + 0.5;
// Apply brightness
texel.rgb = texel.rgb + brightness/100.0;
// Apply saturation
float intensity = dot(texel.rgb, vec3(0.299, 0.587, 0.114));
texel.rgb = (texel.rgb - intensity)*saturation/100.0 + texel.rgb;
// Output resulting color
gl_FragColor = texel;
}

View file

@ -0,0 +1,24 @@
#version 120
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform sampler2D texture1;
uniform vec4 colDiffuse;
uniform float divider;
void main()
{
// Texel color fetching from texture sampler
vec4 texelColor0 = texture2D(texture0, fragTexCoord);
vec4 texelColor1 = texture2D(texture1, fragTexCoord);
float x = fract(fragTexCoord.s);
float final = smoothstep(divider - 0.1, divider + 0.1, x);
gl_FragColor = mix(texelColor0, texelColor1, final);
}

View file

@ -0,0 +1,27 @@
#version 120
// Input vertex attributes (from vertex shader)
varying vec3 fragPosition;
// Input uniform values
uniform sampler2D equirectangularMap;
vec2 SampleSphericalMap(vec3 v)
{
vec2 uv = vec2(atan(v.z, v.x), asin(v.y));
uv *= vec2(0.1591, 0.3183);
uv += 0.5;
return uv;
}
void main()
{
// Normalize local position
vec2 uv = SampleSphericalMap(normalize(fragPosition));
// Fetch color from texture map
vec3 color = texture2D(equirectangularMap, uv).rgb;
// Calculate final fragment color
gl_FragColor = vec4(color, 1.0);
}

View file

@ -0,0 +1,20 @@
#version 120
// Input vertex attributes
attribute vec3 vertexPosition;
// Input uniform values
uniform mat4 matProjection;
uniform mat4 matView;
// Output vertex attributes (to fragment shader)
varying vec3 fragPosition;
void main()
{
// Calculate fragment position based on model transformations
fragPosition = vertexPosition;
// Calculate final vertex position
gl_Position = matProjection*matView*vec4(vertexPosition, 1.0);
}

View file

@ -0,0 +1,58 @@
#version 120
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Custom variables
const float PI = 3.14159265358979323846;
uniform float uTime;
float divisions = 5.0;
float angle = 0.0;
vec2 VectorRotateTime(vec2 v, float speed)
{
float time = uTime*speed;
float localTime = fract(time); // The time domain this works on is 1 sec
if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0;
else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4.0*sin(2.0*PI*localTime - PI/2.0);
else if ((localTime >= 0.50) && (localTime < 0.75)) angle = PI*0.25;
else if ((localTime >= 0.75) && (localTime < 1.00)) angle = PI/4.0*sin(2.0*PI*localTime);
// Rotate vector by angle
v -= 0.5;
v = mat2(cos(angle), -sin(angle), sin(angle), cos(angle))*v;
v += 0.5;
return v;
}
float Rectangle(in vec2 st, in float size, in float fill)
{
float roundSize = 0.5 - size/2.0;
float left = step(roundSize, st.x);
float top = step(roundSize, st.y);
float bottom = step(roundSize, 1.0 - st.y);
float right = step(roundSize, 1.0 - st.x);
return (left*bottom*right*top)*fill;
}
void main()
{
vec2 fragPos = fragTexCoord;
fragPos.xy += uTime/9.0;
fragPos *= divisions;
vec2 ipos = floor(fragPos); // Get the integer coords
vec2 fpos = fract(fragPos); // Get the fractional coords
fpos = VectorRotateTime(fpos, 0.2);
float alpha = Rectangle(fpos, 0.216, 1.0);
vec3 color = vec3(0.3, 0.3, 0.3);
gl_FragColor = vec4(color, alpha);
}

View file

@ -0,0 +1,57 @@
#version 120
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D gPosition;
uniform sampler2D gNormal;
uniform sampler2D gAlbedoSpec;
struct Light {
int enabled;
int type; // Unused in this demo
vec3 position;
vec3 target; // Unused in this demo
vec4 color;
};
const int NR_LIGHTS = 4;
uniform Light lights[NR_LIGHTS];
uniform vec3 viewPosition;
const float QUADRATIC = 0.032;
const float LINEAR = 0.09;
void main()
{
vec3 fragPosition = texture2D(gPosition, fragTexCoord).rgb;
vec3 normal = texture2D(gNormal, fragTexCoord).rgb;
vec3 albedo = texture2D(gAlbedoSpec, fragTexCoord).rgb;
float specular = texture2D(gAlbedoSpec, fragTexCoord).a;
vec3 ambient = albedo*vec3(0.1);
vec3 viewDirection = normalize(viewPosition - fragPosition);
for (int i = 0; i < NR_LIGHTS; i++)
{
if (lights[i].enabled == 0) continue;
vec3 lightDirection = lights[i].position - fragPosition;
vec3 diffuse = max(dot(normal, lightDirection), 0.0)*albedo*lights[i].color.xyz;
vec3 halfwayDirection = normalize(lightDirection + viewDirection);
float spec = pow(max(dot(normal, halfwayDirection), 0.0), 32.0);
vec3 specular = specular*spec*lights[i].color.xyz;
// Attenuation
float distance = length(lights[i].position - fragPosition);
float attenuation = 1.0/(1.0 + LINEAR*distance + QUADRATIC*distance*distance);
diffuse *= attenuation;
specular *= attenuation;
ambient += diffuse + specular;
}
gl_FragColor = vec4(ambient, 1.0);
}

View file

@ -0,0 +1,16 @@
#version 120
// Input vertex attributes
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
// Output vertex attributes (to fragment shader)
varying vec2 fragTexCoord;
void main()
{
fragTexCoord = vertexTexCoord;
// Calculate final vertex position
gl_Position = vec4(vertexPosition, 1.0);
}

View file

@ -0,0 +1,28 @@
#version 120
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
// Input uniform values
uniform sampler2D depthTexture;
uniform bool flipY;
float nearPlane = 0.1;
float farPlane = 100.0;
void main()
{
// Handle potential Y-flipping
vec2 texCoord = fragTexCoord;
if (flipY)
texCoord.y = 1.0 - texCoord.y;
// Sample depth texture
float depth = texture2D(depthTexture, texCoord).r;
// Linearize depth
float linearDepth = (2.0*nearPlane)/(farPlane + nearPlane - depth*(farPlane - nearPlane));
// Output final color
gl_FragColor = vec4(vec3(linearDepth), 1.0);
}

View file

@ -0,0 +1,17 @@
#version 120
#extension GL_EXT_frag_depth : enable
varying vec2 fragTexCoord;
varying vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 colDiffuse;
void main()
{
vec4 texelColor = texture2D(texture0, fragTexCoord);
gl_FragColor = texelColor*colDiffuse*fragColor;
gl_FragDepthEXT = 1.0 - gl_FragCoord.z;
}

View file

@ -0,0 +1,58 @@
#version 120
/*************************************************************************************
The Sieve of Eratosthenes -- a simple shader by ProfJski
An early prime number sieve: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
The screen is divided into a square grid of boxes, each representing an integer value
Each integer is tested to see if it is a prime number. Primes are colored white
Non-primes are colored with a color that indicates the smallest factor which evenly divdes our integer
You can change the scale variable to make a larger or smaller grid
Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers
WARNING: If you make scale too large, your GPU may bog down!
***************************************************************************************/
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Make a nice spectrum of colors based on counter and maxSize
vec4 Colorizer(float counter, float maxSize)
{
float red = 0.0, green = 0.0, blue = 0.0;
float normsize = counter/maxSize;
red = smoothstep(0.3, 0.7, normsize);
green = sin(3.14159*normsize);
blue = 1.0 - smoothstep(0.0, 0.4, normsize);
return vec4(0.8*red, 0.8*green, 0.8*blue, 1.0);
}
void main()
{
vec4 color = vec4(1.0);
float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid
float value = scale*floor(fragTexCoord.y*scale) + floor(fragTexCoord.x*scale); // Group pixels into boxes representing integer values
int valuei = int(value);
//if ((valuei == 0) || (valuei == 1) || (valuei == 2)) gl_FragColor = vec4(1.0);
//else
{
//for (int i = 2; (i < int(max(2.0, sqrt(value) + 1.0))); i++)
// NOTE: On GLSL 100 for loops are restricted and loop condition must be a constant
// Tested on RPI, it seems loops are limited around 60 iteractions
for (int i = 2; i < 48; i++)
{
if ((value - float(i)*floor(value/float(i))) <= 0.0)
{
gl_FragColor = Colorizer(float(i), scale);
//break; // Uncomment to color by the largest factor instead
}
}
}
}

View file

@ -0,0 +1,42 @@
#version 120
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
// Input size in pixels of the textures
uniform vec2 resolution;
void main()
{
// Size of one pixel in texture coordinates (from 0.0 to 1.0)
float x = 1.0/resolution.x;
float y = 1.0/resolution.y;
// Status of the current cell (1 = alive, 0 = dead)
int origValue = (texture2D(texture0, fragTexCoord).r < 0.1)? 1 : 0;
// Sum of alive neighbors
int sumValue = (texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y)).r < 0.1)? 1 : 0; // Top-left
sumValue += (texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y )).r < 0.1)? 1 : 0; // Top
sumValue += (texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y)).r < 0.1)? 1 : 0; // Top-right
sumValue += (texture2D(texture0, vec2(fragTexCoord.x, fragTexCoord.y - y)).r < 0.1)? 1 : 0; // Left
sumValue += (texture2D(texture0, vec2(fragTexCoord.x, fragTexCoord.y + y)).r < 0.1)? 1 : 0; // Right
sumValue += (texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y)).r < 0.1)? 1 : 0; // Bottom-left
sumValue += (texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y )).r < 0.1)? 1 : 0; // Bottom
sumValue += (texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y)).r < 0.1)? 1 : 0; // Bottom-right
// Game of life rules:
// Current cell remains alive when 2 or 3 neighbors are alive, dies otherwise
// Current cell goes from dead to alive when exactly 3 neighbors are alive
if (((origValue == 1) && (sumValue == 2)) || sumValue == 3)
gl_FragColor = vec4(0.0, 0.0, 0.0, 255.0); // Alive: draw the pixel black
else
gl_FragColor = fragColor; // Dead: draw the pixel with the background color, RAYWHITE
}

View file

@ -0,0 +1,34 @@
#version 120
// Input vertex attributes (from vertex shader)
varying vec3 fragPosition;
varying vec2 fragTexCoord;
varying vec3 fragNormal;
varying vec4 fragColor;
// TODO: Is there some alternative for GLSL100
//layout (location = 0) out vec3 gPosition;
//layout (location = 1) out vec3 gNormal;
//layout (location = 2) out vec4 gAlbedoSpec;
//uniform vec3 gPosition;
//uniform vec3 gNormal;
//uniform vec4 gAlbedoSpec;
// Input uniform values
uniform sampler2D texture0; // Diffuse texture
uniform sampler2D specularTexture;
void main()
{
// Store the fragment position vector in the first gbuffer texture
//gPosition = fragPosition;
// Store the per-fragment normals into the gbuffer
//gNormal = normalize(fragNormal);
// Store the diffuse per-fragment color
gl_FragColor.rgb = texture2D(texture0, fragTexCoord).rgb;
// Store specular intensity in gAlbedoSpec's alpha component
gl_FragColor.a = texture2D(specularTexture, fragTexCoord).r;
}

Some files were not shown because too many files have changed in this diff Show more