aboutsummaryrefslogtreecommitdiff
path: root/deps/raylib/examples/shaders/shaders_vertex_displacement.c
diff options
context:
space:
mode:
authorbonmas14 <bonmas14@gmail.com>2025-09-20 22:28:15 +0300
committerbonmas14 <bonmas14@gmail.com>2025-09-20 22:28:15 +0300
commitcdda4c4182c9ee068567529715e4a5c68a8efb58 (patch)
tree38a63f62a64018a2d35fc33354f8589fd33b7514 /deps/raylib/examples/shaders/shaders_vertex_displacement.c
downloadc_wizard-cdda4c4182c9ee068567529715e4a5c68a8efb58.tar.gz
c_wizard-cdda4c4182c9ee068567529715e4a5c68a8efb58.zip
Init commit v1.0
Diffstat (limited to 'deps/raylib/examples/shaders/shaders_vertex_displacement.c')
-rw-r--r--deps/raylib/examples/shaders/shaders_vertex_displacement.c119
1 files changed, 119 insertions, 0 deletions
diff --git a/deps/raylib/examples/shaders/shaders_vertex_displacement.c b/deps/raylib/examples/shaders/shaders_vertex_displacement.c
new file mode 100644
index 0000000..207a237
--- /dev/null
+++ b/deps/raylib/examples/shaders/shaders_vertex_displacement.c
@@ -0,0 +1,119 @@
+/*******************************************************************************************
+*
+* raylib [shaders] example - Vertex displacement
+*
+* Example originally created with raylib 5.0, last time updated with raylib 4.5
+*
+* Example contributed by <Alex ZH> (@ZzzhHe) 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 <Alex ZH> (@ZzzhHe)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+#include "rlgl.h"
+
+#define RLIGHTS_IMPLEMENTATION
+#include "rlights.h"
+
+#if defined(PLATFORM_DESKTOP)
+ #define GLSL_VERSION 330
+#else // PLATFORM_ANDROID, PLATFORM_WEB
+ #define GLSL_VERSION 100
+#endif
+
+//------------------------------------------------------------------------------------
+// Program main entry point
+//------------------------------------------------------------------------------------
+int main(void)
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [shaders] example - vertex displacement");
+
+ // set up camera
+ Camera camera = {0};
+ camera.position = (Vector3) {20.0f, 5.0f, -20.0f};
+ camera.target = (Vector3) {0.0f, 0.0f, 0.0f};
+ camera.up = (Vector3) {0.0f, 1.0f, 0.0f};
+ camera.fovy = 60.0f;
+ camera.projection = CAMERA_PERSPECTIVE;
+
+ // Load vertex and fragment shaders
+ Shader shader = LoadShader(
+ TextFormat("resources/shaders/glsl%i/vertex_displacement.vs", GLSL_VERSION),
+ TextFormat("resources/shaders/glsl%i/vertex_displacement.fs", GLSL_VERSION));
+
+ // Load perlin noise texture
+ Image perlinNoiseImage = GenImagePerlinNoise(512, 512, 0, 0, 1.0f);
+ Texture perlinNoiseMap = LoadTextureFromImage(perlinNoiseImage);
+ UnloadImage(perlinNoiseImage);
+
+ // Set shader uniform location
+ int perlinNoiseMapLoc = GetShaderLocation(shader, "perlinNoiseMap");
+ rlEnableShader(shader.id);
+ rlActiveTextureSlot(1);
+ rlEnableTexture(perlinNoiseMap.id);
+ rlSetUniformSampler(perlinNoiseMapLoc, 1);
+
+ // Create a plane mesh and model
+ Mesh planeMesh = GenMeshPlane(50, 50, 50, 50);
+ Model planeModel = LoadModelFromMesh(planeMesh);
+ // Set plane model material
+ planeModel.materials[0].shader = shader;
+
+ float time = 0.0f;
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ UpdateCamera(&camera, CAMERA_FREE); // Update camera
+
+ time += GetFrameTime(); // Update time variable
+ SetShaderValue(shader, GetShaderLocation(shader, "time"), &time, SHADER_UNIFORM_FLOAT); // Send time value to shader
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ BeginMode3D(camera);
+
+ BeginShaderMode(shader);
+ // Draw plane model
+ DrawModel(planeModel, (Vector3){ 0.0f, 0.0f, 0.0f }, 1.0f, (Color) {255, 255, 255, 255});
+ EndShaderMode();
+
+ EndMode3D();
+
+ DrawText("Vertex displacement", 10, 10, 20, DARKGRAY);
+ DrawFPS(10, 40);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadShader(shader);
+ UnloadModel(planeModel);
+ UnloadTexture(perlinNoiseMap);
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}