aboutsummaryrefslogtreecommitdiff
path: root/examples/shaders
diff options
context:
space:
mode:
authorIndustrious Nomad <44799276+IndustriousNomad@users.noreply.github.com>2019-10-26 03:45:15 -0400
committerRay <raysan5@gmail.com>2019-10-26 09:45:15 +0200
commita6db31c01e57ba9b0370190b11222dfaf4023b73 (patch)
tree2cb0821b430c2e9613d74d9c4a1c0cb00bd103d2 /examples/shaders
parent39e22046c144e551ada940facd98f5f3d7039e59 (diff)
downloadraylib-a6db31c01e57ba9b0370190b11222dfaf4023b73.tar.gz
raylib-a6db31c01e57ba9b0370190b11222dfaf4023b73.zip
updated RayMarching Demo (#997)
* Removed Unused Uniforms uniform vec3 viewUp; uniform float deltaTime; * Removed Unused uniforms uniform vec3 viewUp; uniform float deltaTime; * Updated Source Added - #define PLATFORM_DESKTOP line for desktop users. This now will correctly find the proper glsl version for the raymarching.fs file. Removed - Uniforms --> deltaTime and viewUp. Including the code that was setting them. They were never used and they were triggering a log warning. Removed - The const from both screenWidth and screenHeight. Now they can be used to update the shader resolution when screen is resized. NOTE : This is a quick fix and probably not the best idea. Added - IsWindowResized() to check if screen is resized. If window is resized then width, height and shader resolution are updated. Changed - MIT tag at bottom right color value to BLACK. Now it's easier to see. * Closer Match to original code * Removed the PLATFORM_DESKTOP Define
Diffstat (limited to 'examples/shaders')
-rw-r--r--examples/shaders/resources/shaders/glsl100/raymarching.fs4
-rw-r--r--examples/shaders/resources/shaders/glsl330/raymarching.fs4
-rw-r--r--examples/shaders/shaders_raymarching.c26
3 files changed, 18 insertions, 16 deletions
diff --git a/examples/shaders/resources/shaders/glsl100/raymarching.fs b/examples/shaders/resources/shaders/glsl100/raymarching.fs
index 4ae71297..c823e01e 100644
--- a/examples/shaders/resources/shaders/glsl100/raymarching.fs
+++ b/examples/shaders/resources/shaders/glsl100/raymarching.fs
@@ -8,8 +8,6 @@ varying vec4 fragColor;
uniform vec3 viewEye;
uniform vec3 viewCenter;
-uniform vec3 viewUp;
-uniform float deltaTime;
uniform float runTime;
uniform vec2 resolution;
@@ -428,4 +426,4 @@ void main()
#endif
gl_FragColor = vec4( tot, 1.0 );
-} \ No newline at end of file
+}
diff --git a/examples/shaders/resources/shaders/glsl330/raymarching.fs b/examples/shaders/resources/shaders/glsl330/raymarching.fs
index 7c9fbcb1..3cec58a2 100644
--- a/examples/shaders/resources/shaders/glsl330/raymarching.fs
+++ b/examples/shaders/resources/shaders/glsl330/raymarching.fs
@@ -9,8 +9,6 @@ out vec4 finalColor;
uniform vec3 viewEye;
uniform vec3 viewCenter;
-uniform vec3 viewUp;
-uniform float deltaTime;
uniform float runTime;
uniform vec2 resolution;
@@ -429,4 +427,4 @@ void main()
#endif
finalColor = vec4( tot, 1.0 );
-} \ No newline at end of file
+}
diff --git a/examples/shaders/shaders_raymarching.c b/examples/shaders/shaders_raymarching.c
index 34091792..06ad0f92 100644
--- a/examples/shaders/shaders_raymarching.c
+++ b/examples/shaders/shaders_raymarching.c
@@ -28,9 +28,10 @@ int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
- const int screenWidth = 800;
- const int screenHeight = 450;
+ int screenWidth = 800;
+ int screenHeight = 450;
+ SetConfigFlags(FLAG_WINDOW_RESIZABLE);
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - raymarching shapes");
Camera camera = { 0 };
@@ -48,12 +49,10 @@ int main(void)
// Get shader locations for required uniforms
int viewEyeLoc = GetShaderLocation(shader, "viewEye");
int viewCenterLoc = GetShaderLocation(shader, "viewCenter");
- int viewUpLoc = GetShaderLocation(shader, "viewUp");
- int deltaTimeLoc = GetShaderLocation(shader, "deltaTime");
int runTimeLoc = GetShaderLocation(shader, "runTime");
int resolutionLoc = GetShaderLocation(shader, "resolution");
- float resolution[2] = { screenWidth, screenHeight };
+ float resolution[2] = { (float)screenWidth, (float)screenHeight };
SetShaderValue(shader, resolutionLoc, resolution, UNIFORM_VEC2);
float runTime = 0.0f;
@@ -64,13 +63,22 @@ int main(void)
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
+ // Check if screen is resized
+ //----------------------------------------------------------------------------------
+ if(IsWindowResized())
+ {
+ screenWidth = GetScreenWidth();
+ screenHeight = GetScreenHeight();
+ float resolution[2] = { (float)screenWidth, (float)screenHeight };
+ SetShaderValue(shader, resolutionLoc, resolution, UNIFORM_VEC2);
+ }
+
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera); // Update camera
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
float cameraTarget[3] = { camera.target.x, camera.target.y, camera.target.z };
- float cameraUp[3] = { camera.up.x, camera.up.y, camera.up.z };
float deltaTime = GetFrameTime();
runTime += deltaTime;
@@ -78,8 +86,6 @@ int main(void)
// Set shader required uniform values
SetShaderValue(shader, viewEyeLoc, cameraPos, UNIFORM_VEC3);
SetShaderValue(shader, viewCenterLoc, cameraTarget, UNIFORM_VEC3);
- SetShaderValue(shader, viewUpLoc, cameraUp, UNIFORM_VEC3);
- SetShaderValue(shader, deltaTimeLoc, &deltaTime, UNIFORM_FLOAT);
SetShaderValue(shader, runTimeLoc, &runTime, UNIFORM_FLOAT);
//----------------------------------------------------------------------------------
@@ -95,7 +101,7 @@ int main(void)
DrawRectangle(0, 0, screenWidth, screenHeight, WHITE);
EndShaderMode();
- DrawText("(c) Raymarching shader by Iñigo Quilez. MIT License.", screenWidth - 280, screenHeight - 20, 10, GRAY);
+ DrawText("(c) Raymarching shader by Iñigo Quilez. MIT License.", screenWidth - 280, screenHeight - 20, 10, BLACK);
EndDrawing();
//----------------------------------------------------------------------------------
@@ -109,4 +115,4 @@ int main(void)
//--------------------------------------------------------------------------------------
return 0;
-} \ No newline at end of file
+}