update examples/README & add some comments
This commit is contained in:
parent
97b154960e
commit
029fc59b4a
|
|
@ -477,7 +477,7 @@ SHADERS = \
|
||||||
shaders/shaders_texture_tiling \
|
shaders/shaders_texture_tiling \
|
||||||
shaders/shaders_texture_waves \
|
shaders/shaders_texture_waves \
|
||||||
shaders/shaders_write_depth \
|
shaders/shaders_write_depth \
|
||||||
shaders/shaders_vertex_displacement \
|
shaders/shaders_vertex_displacement
|
||||||
|
|
||||||
AUDIO = \
|
AUDIO = \
|
||||||
audio/audio_mixed_processor \
|
audio/audio_mixed_processor \
|
||||||
|
|
|
||||||
|
|
@ -178,6 +178,7 @@ Examples using raylib shaders functionality, including shaders loading, paramete
|
||||||
| 115 | [shaders_multi_sample2d](shaders/shaders_multi_sample2d.c) | <img src="shaders/shaders_multi_sample2d.png" alt="shaders_multi_sample2d" width="80"> | ⭐️⭐️☆☆ | 3.5 | 3.5 | [Ray](https://github.com/raysan5) |
|
| 115 | [shaders_multi_sample2d](shaders/shaders_multi_sample2d.c) | <img src="shaders/shaders_multi_sample2d.png" alt="shaders_multi_sample2d" width="80"> | ⭐️⭐️☆☆ | 3.5 | 3.5 | [Ray](https://github.com/raysan5) |
|
||||||
| 116 | [shaders_spotlight](shaders/shaders_spotlight.c) | <img src="shaders/shaders_spotlight.png" alt="shaders_spotlight" width="80"> | ⭐️⭐️☆☆ | 2.5 | 3.7 | [Chris Camacho](https://github.com/codifies) |
|
| 116 | [shaders_spotlight](shaders/shaders_spotlight.c) | <img src="shaders/shaders_spotlight.png" alt="shaders_spotlight" width="80"> | ⭐️⭐️☆☆ | 2.5 | 3.7 | [Chris Camacho](https://github.com/codifies) |
|
||||||
| 117 | [shaders_deferred_render](shaders/shaders_deferred_render.c) | <img src="shaders/shaders_deferred_render.png" alt="shaders_deferred_render" width="80"> | ⭐️⭐️⭐️⭐️ | 4.5 | 4.5 | [Justin Andreas Lacoste](https://github.com/27justin) |
|
| 117 | [shaders_deferred_render](shaders/shaders_deferred_render.c) | <img src="shaders/shaders_deferred_render.png" alt="shaders_deferred_render" width="80"> | ⭐️⭐️⭐️⭐️ | 4.5 | 4.5 | [Justin Andreas Lacoste](https://github.com/27justin) |
|
||||||
|
| 118 | [shaders_vertex_displacement](shaders/shaders_vertex_displacement.c) | <img src="shaders/shaders_vertex_displacement.png" alt="shaders_deferred_render" width="80"> | ⭐️☆☆☆ | 1.5 | 1.5 | [Alex ZH](https://github.com/ZzzhHe) |
|
||||||
|
|
||||||
### category: audio
|
### category: audio
|
||||||
|
|
||||||
|
|
@ -185,10 +186,10 @@ Examples using raylib audio functionality, including sound/music loading and pla
|
||||||
|
|
||||||
| ## | example | image | difficulty<br>level | version<br>created | last version<br>updated | original<br>developer |
|
| ## | example | image | difficulty<br>level | version<br>created | last version<br>updated | original<br>developer |
|
||||||
|----|----------|--------|:-------------------:|:------------------:|:------------------:|:----------|
|
|----|----------|--------|:-------------------:|:------------------:|:------------------:|:----------|
|
||||||
| 118 | [audio_module_playing](audio/audio_module_playing.c) | <img src="audio/audio_module_playing.png" alt="audio_module_playing" width="80"> | ⭐️☆☆☆ | 1.5 | 3.5 | [Ray](https://github.com/raysan5) |
|
| 119 | [audio_module_playing](audio/audio_module_playing.c) | <img src="audio/audio_module_playing.png" alt="audio_module_playing" width="80"> | ⭐️☆☆☆ | 1.5 | 3.5 | [Ray](https://github.com/raysan5) |
|
||||||
| 119 | [audio_music_stream](audio/audio_music_stream.c) | <img src="audio/audio_music_stream.png" alt="audio_music_stream" width="80"> | ⭐️☆☆☆ | 1.3 | **4.2** | [Ray](https://github.com/raysan5) |
|
| 120 | [audio_music_stream](audio/audio_music_stream.c) | <img src="audio/audio_music_stream.png" alt="audio_music_stream" width="80"> | ⭐️☆☆☆ | 1.3 | **4.2** | [Ray](https://github.com/raysan5) |
|
||||||
| 120 | [audio_raw_stream](audio/audio_raw_stream.c) | <img src="audio/audio_raw_stream.png" alt="audio_raw_stream" width="80"> | ⭐️⭐️⭐️☆ | 1.6 | **4.2** | [Ray](https://github.com/raysan5) |
|
| 121 | [audio_raw_stream](audio/audio_raw_stream.c) | <img src="audio/audio_raw_stream.png" alt="audio_raw_stream" width="80"> | ⭐️⭐️⭐️☆ | 1.6 | **4.2** | [Ray](https://github.com/raysan5) |
|
||||||
| 121 | [audio_sound_loading](audio/audio_sound_loading.c) | <img src="audio/audio_sound_loading.png" alt="audio_sound_loading" width="80"> | ⭐️☆☆☆ | 1.1 | 3.5 | [Ray](https://github.com/raysan5) |
|
| 122 | [audio_sound_loading](audio/audio_sound_loading.c) | <img src="audio/audio_sound_loading.png" alt="audio_sound_loading" width="80"> | ⭐️☆☆☆ | 1.1 | 3.5 | [Ray](https://github.com/raysan5) |
|
||||||
|
|
||||||
### category: others
|
### category: others
|
||||||
|
|
||||||
|
|
@ -196,11 +197,11 @@ Examples showing raylib misc functionality that does not fit in other categories
|
||||||
|
|
||||||
| ## | example | image | difficulty<br>level | version<br>created | last version<br>updated | original<br>developer |
|
| ## | example | image | difficulty<br>level | version<br>created | last version<br>updated | original<br>developer |
|
||||||
|----|----------|--------|:-------------------:|:------------------:|:------------------:|:----------|
|
|----|----------|--------|:-------------------:|:------------------:|:------------------:|:----------|
|
||||||
| 122 | [rlgl_standalone](others/rlgl_standalone.c) | <img src="others/rlgl_standalone.png" alt="rlgl_standalone" width="80"> | ⭐️⭐️⭐️⭐️ | 1.6 | **4.0** | [Ray](https://github.com/raysan5) |
|
| 123 | [rlgl_standalone](others/rlgl_standalone.c) | <img src="others/rlgl_standalone.png" alt="rlgl_standalone" width="80"> | ⭐️⭐️⭐️⭐️ | 1.6 | **4.0** | [Ray](https://github.com/raysan5) |
|
||||||
| 123 | [rlgl_compute_shader](others/rlgl_compute_shader.c) | <img src="others/rlgl_compute_shader.png" alt="rlgl_compute_shader" width="80"> | ⭐️⭐️⭐️⭐️ | **4.0** | **4.0** | [Teddy Astie](https://github.com/tsnake41) |
|
| 124 | [rlgl_compute_shader](others/rlgl_compute_shader.c) | <img src="others/rlgl_compute_shader.png" alt="rlgl_compute_shader" width="80"> | ⭐️⭐️⭐️⭐️ | **4.0** | **4.0** | [Teddy Astie](https://github.com/tsnake41) |
|
||||||
| 124 | [easings_testbed](others/easings_testbed.c) | <img src="others/easings_testbed.png" alt="easings_testbed" width="80"> | ⭐️⭐️⭐️☆ | 3.0 | 3.0 | [Juan Miguel López](https://github.com/flashback-fx) |
|
| 125 | [easings_testbed](others/easings_testbed.c) | <img src="others/easings_testbed.png" alt="easings_testbed" width="80"> | ⭐️⭐️⭐️☆ | 3.0 | 3.0 | [Juan Miguel López](https://github.com/flashback-fx) |
|
||||||
| 125 | [raylib_opengl_interop](others/raylib_opengl_interop.c) | <img src="others/raylib_opengl_interop.png" alt="raylib_opengl_interop" width="80"> | ⭐️⭐️⭐️⭐️ | **4.0** | **4.0** | [Stephan Soller](https://github.com/arkanis) |
|
| 126 | [raylib_opengl_interop](others/raylib_opengl_interop.c) | <img src="others/raylib_opengl_interop.png" alt="raylib_opengl_interop" width="80"> | ⭐️⭐️⭐️⭐️ | **4.0** | **4.0** | [Stephan Soller](https://github.com/arkanis) |
|
||||||
| 126 | [embedded_files_loading](others/embedded_files_loading.c) | <img src="others/embedded_files_loading.png" alt="embedded_files_loading" width="80"> | ⭐️⭐️☆☆ | 3.5 | 3.5 | [Kristian Holmgren](https://github.com/defutura) |
|
| 127 | [embedded_files_loading](others/embedded_files_loading.c) | <img src="others/embedded_files_loading.png" alt="embedded_files_loading" width="80"> | ⭐️⭐️☆☆ | 3.5 | 3.5 | [Kristian Holmgren](https://github.com/defutura) |
|
||||||
|
|
||||||
As always contributions are welcome, feel free to send new examples! Here is an [examples template](examples_template.c) to start with!
|
As always contributions are welcome, feel free to send new examples! Here is an [examples template](examples_template.c) to start with!
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,6 @@ void main()
|
||||||
{
|
{
|
||||||
vec4 darkblue = vec4(0.0, 0.13, 0.18, 1.0);
|
vec4 darkblue = vec4(0.0, 0.13, 0.18, 1.0);
|
||||||
vec4 lightblue = vec4(1.0, 1.0, 1.0, 1.0);
|
vec4 lightblue = vec4(1.0, 1.0, 1.0, 1.0);
|
||||||
|
// interplate between two colors based on height
|
||||||
finalColor = mix(darkblue, lightblue, height);
|
finalColor = mix(darkblue, lightblue, height);
|
||||||
}
|
}
|
||||||
|
|
@ -23,19 +23,23 @@ out float height;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 animatedTexCoord = sin(vertexTexCoord + vec2(sin(time + vertexPosition.x * 0.1), cos(time + vertexPosition.z * 0.1)) * 0.3) * 0.5 + 0.5;
|
// 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);
|
||||||
|
|
||||||
// Fetch displacement from the displacement map and amplify it
|
// Normalize animated texture coordinates to range [0, 1]
|
||||||
|
animatedTexCoord = animatedTexCoord * 0.5 + 0.5;
|
||||||
|
|
||||||
|
// Fetch displacement from the perlin noise map
|
||||||
float displacement = texture(perlinNoiseMap, animatedTexCoord).r * 7; // Amplified displacement
|
float displacement = texture(perlinNoiseMap, animatedTexCoord).r * 7; // Amplified displacement
|
||||||
|
|
||||||
// Combine displacement and wave motion
|
// Displace vertex position
|
||||||
vec3 displacedPosition = vertexPosition + vec3(0.0, displacement, 0.0);
|
vec3 displacedPosition = vertexPosition + vec3(0.0, displacement, 0.0);
|
||||||
|
|
||||||
// Send vertex attributes to fragment shader
|
// Send vertex attributes to fragment shader
|
||||||
fragPosition = vec3(matModel*vec4(displacedPosition, 1.0));
|
fragPosition = vec3(matModel*vec4(displacedPosition, 1.0));
|
||||||
fragTexCoord = vertexTexCoord;
|
fragTexCoord = vertexTexCoord;
|
||||||
fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
|
fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
|
||||||
height = displacedPosition.y * 0.2;
|
height = displacedPosition.y * 0.2; // send height to fragment shader for coloring
|
||||||
|
|
||||||
// Calculate final vertex position
|
// Calculate final vertex position
|
||||||
gl_Position = mvp*vec4(displacedPosition , 1.0);
|
gl_Position = mvp*vec4(displacedPosition , 1.0);
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@
|
||||||
*
|
*
|
||||||
* raylib [core] example - Basic window
|
* raylib [core] example - Basic window
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
* Example originally created with raylib 5.0, last time updated with raylib 4.5
|
||||||
*
|
*
|
||||||
* Example contributed by <user_name> (@<user_github>) and reviewed by Ramon Santamaria (@raysan5)
|
* 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,
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||||
* BSD-like license that allows static linking with closed source software
|
* BSD-like license that allows static linking with closed source software
|
||||||
*
|
*
|
||||||
* Copyright (c) 2023 <user_name> (@<user_github>)
|
* Copyright (c) 2023 <Alex ZH> (@ZzzhHe)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|
@ -40,6 +40,7 @@ int main(void)
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - vertex displacement");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - vertex displacement");
|
||||||
|
|
||||||
|
// set up camera
|
||||||
Camera camera = {0};
|
Camera camera = {0};
|
||||||
camera.position = (Vector3) {20.0f, 5.0f, -20.0f};
|
camera.position = (Vector3) {20.0f, 5.0f, -20.0f};
|
||||||
camera.target = (Vector3) {0.0f, 0.0f, 0.0f};
|
camera.target = (Vector3) {0.0f, 0.0f, 0.0f};
|
||||||
|
|
@ -47,29 +48,28 @@ int main(void)
|
||||||
camera.fovy = 60.0f;
|
camera.fovy = 60.0f;
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
Mesh planeMesh = GenMeshPlane(50, 50, 50, 50);
|
// Load vertex and fragment shaders
|
||||||
Model planeModel = LoadModelFromMesh(planeMesh);
|
|
||||||
|
|
||||||
Shader shader = LoadShader(
|
Shader shader = LoadShader(
|
||||||
TextFormat("resources/shaders/glsl%i/vertex_displacement.vs", GLSL_VERSION),
|
TextFormat("resources/shaders/glsl%i/vertex_displacement.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/vertex_displacement.fs", GLSL_VERSION)
|
TextFormat("resources/shaders/glsl%i/vertex_displacement.fs", GLSL_VERSION)
|
||||||
);
|
);
|
||||||
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
|
|
||||||
|
|
||||||
int ambientLoc = GetShaderLocation(shader, "ambient");
|
|
||||||
SetShaderValue(shader, ambientLoc, (float[4]){ 0.1f, 0.1f, 0.1f, 1.0f }, SHADER_UNIFORM_VEC4);
|
|
||||||
|
|
||||||
|
// Load perlin noise texture
|
||||||
Image perlinNoiseImage = GenImagePerlinNoise(512, 512, 0, 0, 1.0f);
|
Image perlinNoiseImage = GenImagePerlinNoise(512, 512, 0, 0, 1.0f);
|
||||||
Texture perlinNoiseMap = LoadTextureFromImage(perlinNoiseImage);
|
Texture perlinNoiseMap = LoadTextureFromImage(perlinNoiseImage);
|
||||||
UnloadImage(perlinNoiseImage);
|
UnloadImage(perlinNoiseImage);
|
||||||
|
|
||||||
|
// Set shader uniform location
|
||||||
int perlinNoiseMapLoc = GetShaderLocation(shader, "perlinNoiseMap");
|
int perlinNoiseMapLoc = GetShaderLocation(shader, "perlinNoiseMap");
|
||||||
rlEnableShader(shader.id);
|
rlEnableShader(shader.id);
|
||||||
rlActiveTextureSlot(1);
|
rlActiveTextureSlot(1);
|
||||||
rlEnableTexture(perlinNoiseMap.id);
|
rlEnableTexture(perlinNoiseMap.id);
|
||||||
rlSetUniformSampler(perlinNoiseMapLoc, 1);
|
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;
|
planeModel.materials[0].shader = shader;
|
||||||
|
|
||||||
float time = 0.0f;
|
float time = 0.0f;
|
||||||
|
|
@ -81,13 +81,11 @@ int main(void)
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
UpdateCamera(&camera, CAMERA_FREE);
|
//----------------------------------------------------------------------------------
|
||||||
|
UpdateCamera(&camera, CAMERA_FREE); // Update camera
|
||||||
|
|
||||||
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
|
time += GetFrameTime(); // Update time variable
|
||||||
SetShaderValue(shader, shader.locs[SHADER_LOC_VECTOR_VIEW], cameraPos, SHADER_UNIFORM_VEC3);
|
SetShaderValue(shader, GetShaderLocation(shader, "time"), &time, SHADER_UNIFORM_FLOAT); // Send time value to shader
|
||||||
|
|
||||||
time += GetFrameTime();
|
|
||||||
SetShaderValue(shader, GetShaderLocation(shader, "time"), &time, SHADER_UNIFORM_FLOAT);
|
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -98,12 +96,13 @@ int main(void)
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
||||||
BeginShaderMode(shader);
|
BeginShaderMode(shader);
|
||||||
|
// Draw plane model
|
||||||
DrawModel(planeModel, (Vector3){ 0.0f, 0.0f, 0.0f }, 1.0f, (Color) {255, 255, 255, 255});
|
DrawModel(planeModel, (Vector3){ 0.0f, 0.0f, 0.0f }, 1.0f, (Color) {255, 255, 255, 255});
|
||||||
EndShaderMode();
|
EndShaderMode();
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawText("Displacement mapping", 10, 10, 20, DARKGRAY);
|
DrawText("Vertex displacement", 10, 10, 20, DARKGRAY);
|
||||||
DrawFPS(10, 40);
|
DrawFPS(10, 40);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
|
||||||
BIN
examples/shaders/shaders_vertex_displacement.png
Normal file
BIN
examples/shaders/shaders_vertex_displacement.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 302 KiB |
Loading…
Reference in New Issue
Block a user