summaryrefslogtreecommitdiffhomepage
path: root/examples/web/shaders/shaders_fog.c
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2021-10-17 21:02:18 +0200
committerraysan5 <[email protected]>2021-10-17 21:02:18 +0200
commit35e67da08e3d214589968c19b4b2fb31d8e566cc (patch)
tree5054bcea5f6df754f467590101789b17dd9d9944 /examples/web/shaders/shaders_fog.c
parentb2228039039afc05c41edd12103123f2a36c8080 (diff)
downloadraylib.com-35e67da08e3d214589968c19b4b2fb31d8e566cc.tar.gz
raylib.com-35e67da08e3d214589968c19b4b2fb31d8e566cc.zip
UPDATED: examples to raylib 4.0
Some new examples added
Diffstat (limited to 'examples/web/shaders/shaders_fog.c')
-rw-r--r--examples/web/shaders/shaders_fog.c203
1 files changed, 0 insertions, 203 deletions
diff --git a/examples/web/shaders/shaders_fog.c b/examples/web/shaders/shaders_fog.c
deleted file mode 100644
index 0e0b000..0000000
--- a/examples/web/shaders/shaders_fog.c
+++ /dev/null
@@ -1,203 +0,0 @@
-/*******************************************************************************************
-*
-* raylib [shaders] example - fog
-*
-* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
-* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
-*
-* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3).
-*
-* 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 contributed by Chris Camacho (@codifies) and reviewed by Ramon Santamaria (@raysan5)
-*
-* Chris Camacho (@codifies - http://bedroomcoders.co.uk/) notes:
-*
-* This is based on the PBR lighting example, but greatly simplified to aid learning...
-* actually there is very little of the PBR example left!
-* When I first looked at the bewildering complexity of the PBR example I feared
-* I would never understand how I could do simple lighting with raylib however its
-* a testement to the authors of raylib (including rlights.h) that the example
-* came together fairly quickly.
-*
-* Copyright (c) 2019 Chris Camacho (@codifies) and Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-#include "raymath.h"
-
-#define RLIGHTS_IMPLEMENTATION
-#include "rlights.h"
-
-#if defined(PLATFORM_WEB)
- #include <emscripten/emscripten.h>
-#endif
-
-#if defined(PLATFORM_DESKTOP)
- #define GLSL_VERSION 330
-#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
- #define GLSL_VERSION 100
-#endif
-
-//----------------------------------------------------------------------------------
-// Global Variables Definition
-//----------------------------------------------------------------------------------
-const int screenWidth = 800;
-const int screenHeight = 450;
-
-static Camera camera = { 0 };
-
-static Model modelA = { 0 };
-static Model modelB = { 0 };
-static Model modelC = { 0 };
-static Shader shader = { 0 };
-
-static Texture texture = { 0 };
-
-static int ambientLoc = 0;
-static float fogDensity = 0.15f;
-static int fogDensityLoc = 0;
-
-//----------------------------------------------------------------------------------
-// Module Functions Declaration
-//----------------------------------------------------------------------------------
-void UpdateDrawFrame(void); // Update and Draw one frame
-
-//----------------------------------------------------------------------------------
-// Program Main Entry Point
-//----------------------------------------------------------------------------------
-int main(void)
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- const int screenWidth = 800;
- const int screenHeight = 450;
-
- SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available)
- InitWindow(screenWidth, screenHeight, "raylib [shaders] example - fog");
-
- // Define the camera to look into our 3d world
- camera.position = (Vector3){ 2.0f, 2.0f, 6.0f };
- camera.target = (Vector3){ 0.0f, 0.5f, 0.0f };
- camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
- camera.fovy = 45.0f;
- camera.projection = CAMERA_PERSPECTIVE;
-
- // Load models and texture
- modelA = LoadModelFromMesh(GenMeshTorus(0.4f, 1.0f, 16, 32));
- modelB = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f));
- modelC = LoadModelFromMesh(GenMeshSphere(0.5f, 32, 32));
- texture = LoadTexture("resources/texel_checker.png");
-
- // Assign texture to default model material
- modelA.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
- modelB.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
- modelC.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
-
- // Load shader and set up some uniforms
- shader = LoadShader(TextFormat("resources/shaders/glsl%i/base_lighting.vs", GLSL_VERSION),
- TextFormat("resources/shaders/glsl%i/fog.fs", GLSL_VERSION));
-
- shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
- shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
-
- // Ambient light level
- ambientLoc = GetShaderLocation(shader, "ambient");
- SetShaderValue(shader, ambientLoc, (float[4]){ 0.2f, 0.2f, 0.2f, 1.0f }, SHADER_UNIFORM_VEC4);
-
- fogDensityLoc = GetShaderLocation(shader, "fogDensity");
- SetShaderValue(shader, fogDensityLoc, &fogDensity, SHADER_UNIFORM_FLOAT);
-
- // NOTE: All models share the same shader
- modelA.materials[0].shader = shader;
- modelB.materials[0].shader = shader;
- modelC.materials[0].shader = shader;
-
- // Using just 1 point lights
- CreateLight(LIGHT_POINT, (Vector3){ 0, 2, 6 }, Vector3Zero(), WHITE, shader);
-
- SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
-
-#if defined(PLATFORM_WEB)
- emscripten_set_main_loop(UpdateDrawFrame, 60, 1);
-#else
- SetTargetFPS(60); // Set our game to run at 60 frames-per-second
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- UpdateDrawFrame();
- }
-#endif
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadModel(modelA); // Unload the model A
- UnloadModel(modelB); // Unload the model B
- UnloadModel(modelC); // Unload the model C
- UnloadTexture(texture); // Unload the texture
- UnloadShader(shader); // Unload shader
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-}
-
-//----------------------------------------------------------------------------------
-// Module Functions Definitions
-//----------------------------------------------------------------------------------
-void UpdateDrawFrame(void)
-{
- // Update
- //----------------------------------------------------------------------------------
- UpdateCamera(&camera); // Update camera
-
- if (IsKeyDown(KEY_UP))
- {
- fogDensity += 0.001;
- if (fogDensity > 1.0) fogDensity = 1.0;
- }
-
- if (IsKeyDown(KEY_DOWN))
- {
- fogDensity -= 0.001;
- if (fogDensity < 0.0) fogDensity = 0.0;
- }
-
- SetShaderValue(shader, fogDensityLoc, &fogDensity, SHADER_UNIFORM_FLOAT);
-
- // Rotate the torus
- modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateX(-0.025));
- modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateZ(0.012));
-
- // Update the light shader with the camera view position
- SetShaderValue(shader, shader.locs[SHADER_LOC_VECTOR_VIEW], &camera.position.x, SHADER_UNIFORM_VEC3);
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- BeginDrawing();
-
- ClearBackground(GRAY);
-
- BeginMode3D(camera);
-
- // Draw the three models
- DrawModel(modelA, Vector3Zero(), 1.0f, WHITE);
- DrawModel(modelB, (Vector3){ -2.6, 0, 0 }, 1.0f, WHITE);
- DrawModel(modelC, (Vector3){ 2.6, 0, 0 }, 1.0f, WHITE);
-
- for (int i = -20; i < 20; i += 2) DrawModel(modelA,(Vector3){ i, 0, 2 }, 1.0f, WHITE);
-
- EndMode3D();
-
- DrawText(TextFormat("Use KEY_UP/KEY_DOWN to change fog density [%.2f]", fogDensity), 10, 10, 20, RAYWHITE);
-
- EndDrawing();
- //----------------------------------------------------------------------------------
-}