From 3468af213f88cd367eac43826ad49f9e9fc730f4 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 15 Jun 2016 00:54:55 +0200 Subject: Reviewing Oculus rendering... --- examples/core_oculus_rift.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'examples') diff --git a/examples/core_oculus_rift.c b/examples/core_oculus_rift.c index 86517829..3c9d7840 100644 --- a/examples/core_oculus_rift.c +++ b/examples/core_oculus_rift.c @@ -55,6 +55,8 @@ int main() for (int eye = 0; eye < 2; eye++) { + // TODO: Probably projection and view matrices could be created here... + // ...without the need to create it internally through Begin3dMode() Begin3dMode(camera); SetOculusMatrix(eye); @@ -64,6 +66,8 @@ int main() DrawGrid(10, 1.0f); + // TODO: Call internal buffers drawing directly (rlglDraw()) and... + // ...reset internal matrices, instead of letting End3dMode() do that End3dMode(); } -- cgit v1.2.3 From 24c9b1f717bd9a6510667907614928188a6b6a6f Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 17 Jun 2016 13:54:45 +0200 Subject: Improving Oculus Rift example... Under design... looking for the easiest and most comprehensive way for the user to use VR... --- examples/core_oculus_rift.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'examples') diff --git a/examples/core_oculus_rift.c b/examples/core_oculus_rift.c index 3c9d7840..32e6b1c6 100644 --- a/examples/core_oculus_rift.c +++ b/examples/core_oculus_rift.c @@ -51,27 +51,31 @@ int main() ClearBackground(RAYWHITE); - BeginOculusDrawing(); + Begin3dMode(camera); + //BeginOculusDrawing(camera); // Add it to Begin3dMode() ? - for (int eye = 0; eye < 2; eye++) - { - // TODO: Probably projection and view matrices could be created here... - // ...without the need to create it internally through Begin3dMode() - Begin3dMode(camera); + for (int eye = 0; eye < 2; eye++) + { + // TODO: Probably projection and view matrices could be created here... + // ...without the need to create it internally through Begin3dMode() + //Begin3dMode(camera); + + SetOculusView(eye); + + DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); + DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); + + DrawGrid(10, 1.0f); + + // TODO: Call internal buffers drawing directly (rlglDraw()) and... + // ...reset internal matrices, instead of letting End3dMode() do that + //End3dMode(); - SetOculusMatrix(eye); - - DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); - DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); - - DrawGrid(10, 1.0f); - - // TODO: Call internal buffers drawing directly (rlglDraw()) and... - // ...reset internal matrices, instead of letting End3dMode() do that - End3dMode(); - } + DrawDefaultBuffers(); // Process internal dynamic buffers + } - EndOculusDrawing(); + End3dMode(); + //EndOculusDrawing(); // Add it to End3dMode() ? EndDrawing(); //---------------------------------------------------------------------------------- -- cgit v1.2.3 From 6062201e8f543c227a0adbb77f3a0941772be889 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 21 Jun 2016 08:59:29 +0200 Subject: Simplify Oculus example... ...to align it with standard raylib code. Final goal would be having the same code work for every platform with no changes... --- examples/core_oculus_rift.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'examples') diff --git a/examples/core_oculus_rift.c b/examples/core_oculus_rift.c index 32e6b1c6..e0ab61fd 100644 --- a/examples/core_oculus_rift.c +++ b/examples/core_oculus_rift.c @@ -52,14 +52,9 @@ int main() ClearBackground(RAYWHITE); Begin3dMode(camera); - //BeginOculusDrawing(camera); // Add it to Begin3dMode() ? - + for (int eye = 0; eye < 2; eye++) { - // TODO: Probably projection and view matrices could be created here... - // ...without the need to create it internally through Begin3dMode() - //Begin3dMode(camera); - SetOculusView(eye); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); @@ -67,15 +62,10 @@ int main() DrawGrid(10, 1.0f); - // TODO: Call internal buffers drawing directly (rlglDraw()) and... - // ...reset internal matrices, instead of letting End3dMode() do that - //End3dMode(); - DrawDefaultBuffers(); // Process internal dynamic buffers } End3dMode(); - //EndOculusDrawing(); // Add it to End3dMode() ? EndDrawing(); //---------------------------------------------------------------------------------- -- cgit v1.2.3 From c28a5fbd62e82f776f4399a1e561c7c4f4bff898 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Tue, 21 Jun 2016 13:44:56 +0200 Subject: Code tweak --- examples/oculus_glfw_sample/rlgl_standalone_stereo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/oculus_glfw_sample/rlgl_standalone_stereo.c b/examples/oculus_glfw_sample/rlgl_standalone_stereo.c index 1955d11e..fa7f3e4a 100644 --- a/examples/oculus_glfw_sample/rlgl_standalone_stereo.c +++ b/examples/oculus_glfw_sample/rlgl_standalone_stereo.c @@ -184,7 +184,7 @@ int main(void) rlMatrixMode(RL_PROJECTION); // Enable internal projection matrix rlLoadIdentity(); // Reset internal projection matrix - rlOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0); // Recalculate internal projection matrix + rlOrtho(0.0, screenWidth/2, screenHeight, 0.0, 0.0, 1.0); // Recalculate internal projection matrix rlMatrixMode(RL_MODELVIEW); // Enable internal modelview matrix rlLoadIdentity(); // Reset internal modelview matrix #endif -- cgit v1.2.3 From e913de58c73ff82fbcd8f23b8cb1fd1a88664164 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Tue, 21 Jun 2016 13:45:35 +0200 Subject: Added distortion shader for testing --- examples/resources/shaders/base.vs | 26 ++++++++++++++ examples/resources/shaders/distortion.fs | 59 ++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 examples/resources/shaders/base.vs create mode 100644 examples/resources/shaders/distortion.fs (limited to 'examples') diff --git a/examples/resources/shaders/base.vs b/examples/resources/shaders/base.vs new file mode 100644 index 00000000..638cb8ae --- /dev/null +++ b/examples/resources/shaders/base.vs @@ -0,0 +1,26 @@ +#version 330 + +// Input vertex attributes +in vec3 vertexPosition; +in vec2 vertexTexCoord; +in vec3 vertexNormal; +in vec4 vertexColor; + +// Input uniform values +uniform mat4 mvpMatrix; + +// Output vertex attributes (to fragment shader) +out vec2 fragTexCoord; +out vec4 fragColor; + +// NOTE: Add here your custom variables + +void main() +{ + // Send vertex attributes to fragment shader + fragTexCoord = vertexTexCoord; + fragColor = vertexColor; + + // Calculate final vertex position + gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); +} \ No newline at end of file diff --git a/examples/resources/shaders/distortion.fs b/examples/resources/shaders/distortion.fs new file mode 100644 index 00000000..cd5951fe --- /dev/null +++ b/examples/resources/shaders/distortion.fs @@ -0,0 +1,59 @@ +#version 330 + +// Input vertex attributes (from vertex shader) +in vec2 fragTexCoord; + +// Input uniform values +uniform sampler2D texture0; + +// Output fragment color +out vec4 finalColor; + +// NOTE: Add here your custom variables +const vec2 LeftLensCenter = vec2(0.2863248, 0.5); +const vec2 RightLensCenter = vec2(0.7136753, 0.5); +const vec2 LeftScreenCenter = vec2(0.25, 0.5); +const vec2 RightScreenCenter = vec2(0.75, 0.5); +const vec2 Scale = vec2(0.25, 0.45); //vec2(0.1469278, 0.2350845); +const vec2 ScaleIn = vec2(4, 2.2222); +const vec4 HmdWarpParam = vec4(1, 0.22, 0.24, 0); + +/* +// Another set of default values +ChromaAbCorrection = {1.0, 0.0, 1.0, 0} +DistortionK = {1.0, 0.22, 0.24, 0} +Scale = {0.25, 0.5*AspectRatio, 0, 0} +ScaleIn = {4.0, 2/AspectRatio, 0, 0} +Left Screen Center = {0.25, 0.5, 0, 0} +Left Lens Center = {0.287994117, 0.5, 0, 0} +Right Screen Center = {0.75, 0.5, 0, 0} +Right Lens Center = {0.712005913, 0.5, 0, 0} +*/ + +// Scales input texture coordinates for distortion. +vec2 HmdWarp(vec2 in01, vec2 LensCenter) +{ + vec2 theta = (in01 - LensCenter)*ScaleIn; // Scales to [-1, 1] + float rSq = theta.x*theta.x + theta.y*theta.y; + vec2 rvector = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq); + + return LensCenter + Scale*rvector; +} + +void main() +{ + // SOURCE: http://www.mtbs3d.com/phpbb/viewtopic.php?f=140&t=17081 + + // The following two variables need to be set per eye + vec2 LensCenter = gl_FragCoord.x < 540 ? LeftLensCenter : RightLensCenter; + vec2 ScreenCenter = gl_FragCoord.x < 540 ? LeftScreenCenter : RightScreenCenter; + + vec2 tc = HmdWarp(fragTexCoord, LensCenter); + + if (any(bvec2(clamp(tc,ScreenCenter-vec2(0.25,0.5), ScreenCenter+vec2(0.25,0.5)) - tc))) finalColor = vec4(0.0, 0.0, 0.0, 1.0); + else + { + //tc.x = gl_FragCoord.x < 640 ? (2.0 * tc.x) : (2.0 * (tc.x - 0.5)); + finalColor = texture2D(texture0, tc); + } +} -- cgit v1.2.3 From 5f7ac64c44543383b10ec6a56e5ec1db5706276e Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 24 Jun 2016 19:49:36 +0200 Subject: Removed function SetModelTexture() It's more educational to go through new material system, so, I decide to remove this function to avoid students confusion... --- examples/models_cubicmap.c | 2 +- examples/models_heightmap.c | 2 +- examples/models_obj_loading.c | 2 +- examples/shaders_custom_uniform.c | 2 +- examples/shaders_postprocessing.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/models_cubicmap.c b/examples/models_cubicmap.c index 1ca27dfd..89bc75cf 100644 --- a/examples/models_cubicmap.c +++ b/examples/models_cubicmap.c @@ -29,7 +29,7 @@ int main() // NOTE: By default each cube is mapped to one part of texture atlas Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture - SetModelTexture(&map, texture); // Bind texture to map model + map.material.texDiffuse = texture; // Set map diffuse texture Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position diff --git a/examples/models_heightmap.c b/examples/models_heightmap.c index c8e5ff35..90e5f5bb 100644 --- a/examples/models_heightmap.c +++ b/examples/models_heightmap.c @@ -26,7 +26,7 @@ int main() Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM) Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM) Model map = LoadHeightmap(image, (Vector3){ 16, 8, 16 }); // Load heightmap model with defined size - SetModelTexture(&map, texture); // Bind texture to model + map.material.texDiffuse = texture; // Set map diffuse texture Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Set model position (depends on model scaling!) UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM diff --git a/examples/models_obj_loading.c b/examples/models_obj_loading.c index e8dd0adc..a6969f70 100644 --- a/examples/models_obj_loading.c +++ b/examples/models_obj_loading.c @@ -25,7 +25,7 @@ int main() Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture - SetModelTexture(&dwarf, texture); // Bind texture to model + dwarf.material.texDiffuse = texture; // Set dwarf model diffuse texture Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position SetTargetFPS(60); // Set our game to run at 60 frames-per-second diff --git a/examples/shaders_custom_uniform.c b/examples/shaders_custom_uniform.c index 516d5087..c4f87259 100644 --- a/examples/shaders_custom_uniform.c +++ b/examples/shaders_custom_uniform.c @@ -34,7 +34,7 @@ int main() Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture (diffuse map) - SetModelTexture(&dwarf, texture); // Bind texture to model + dwarf.material.texDiffuse = texture; // Set dwarf model diffuse texture Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position diff --git a/examples/shaders_postprocessing.c b/examples/shaders_postprocessing.c index 5e8b5a80..43d21e08 100644 --- a/examples/shaders_postprocessing.c +++ b/examples/shaders_postprocessing.c @@ -34,7 +34,7 @@ int main() Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture (diffuse map) - SetModelTexture(&dwarf, texture); // Bind texture to model + dwarf.material.texDiffuse = texture; // Set dwarf model diffuse texture Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position -- cgit v1.2.3 From f9f33926f79b972b10c275d7d742c92337a7b0a2 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 25 Jun 2016 22:41:45 +0200 Subject: Corrected window size to unify with other examples --- examples/core_color_select.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/core_color_select.c b/examples/core_color_select.c index 118dc88a..002a6931 100644 --- a/examples/core_color_select.c +++ b/examples/core_color_select.c @@ -16,7 +16,7 @@ int main() // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; - int screenHeight = 400; + int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - color selection (collision detection)"); @@ -30,7 +30,7 @@ int main() for (int i = 0; i < 21; i++) { colorsRecs[i].x = 20 + 100*(i%7) + 10*(i%7); - colorsRecs[i].y = 40 + 100*(i/7) + 10*(i/7); + colorsRecs[i].y = 60 + 100*(i/7) + 10*(i/7); colorsRecs[i].width = 100; colorsRecs[i].height = 100; } -- cgit v1.2.3 From 8fb84d9e638dea9b4eaaee52b61e1a7ea6681005 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 25 Jun 2016 23:29:03 +0200 Subject: Updated to new rlgl --- examples/oculus_glfw_sample/rlgl_standalone.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/oculus_glfw_sample/rlgl_standalone.c b/examples/oculus_glfw_sample/rlgl_standalone.c index 4728160a..33e91631 100644 --- a/examples/oculus_glfw_sample/rlgl_standalone.c +++ b/examples/oculus_glfw_sample/rlgl_standalone.c @@ -96,11 +96,19 @@ int main(void) // Initialize rlgl internal buffers and OpenGL state rlglInit(); - rlglInitGraphics(0, 0, screenWidth, screenHeight); - rlClearColor(245, 245, 245, 255); // Define clear color - rlEnableDepthTest(); // Enable DEPTH_TEST for 3D - Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; + // Initialize viewport and internal projection/modelview matrices + rlViewport(0, 0, screenWidth, screenHeight); + rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix + rlLoadIdentity(); // Reset current matrix (PROJECTION) + rlOrtho(0, screenWidth, screenHeight, 0, 0.0f, 1.0f); // Orthographic projection with top-left corner at (0,0) + rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix + rlLoadIdentity(); // Reset current matrix (MODELVIEW) + + rlClearColor(245, 245, 245, 255); // Define clear color + rlEnableDepthTest(); // Enable DEPTH_TEST for 3D + + Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; // Cube default position (center) Camera camera; camera.position = (Vector3){ 5.0f, 5.0f, 5.0f }; // Camera position -- cgit v1.2.3 From 4ff85c2ac257eb5494626dae30e79c5f48430609 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 26 Jun 2016 10:22:17 +0200 Subject: Added notes about chromatic aberration --- examples/resources/shaders/distortion.fs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'examples') diff --git a/examples/resources/shaders/distortion.fs b/examples/resources/shaders/distortion.fs index cd5951fe..79bc5fa1 100644 --- a/examples/resources/shaders/distortion.fs +++ b/examples/resources/shaders/distortion.fs @@ -56,4 +56,14 @@ void main() //tc.x = gl_FragCoord.x < 640 ? (2.0 * tc.x) : (2.0 * (tc.x - 0.5)); finalColor = texture2D(texture0, tc); } + + /* + // Chromatic aberration is caused when a lens can't focus every color to the same focal point. + // A simple way to fake this effect, and render it as a quick full-screen post-process, + // is to apply an offset to each color channel in a fragment shader. + vec4 rValue = texture2D(texture0, fragTexCoord - rOffset); + vec4 gValue = texture2D(texture0, fragTexCoord - gOffset); + vec4 bValue = texture2D(texture0, fragTexCoord - bOffset); + finalColor = vec4(rValue.r, gValue.g, bValue.b, 1.0); + */ } -- cgit v1.2.3 From 9127b5a57d317c3be76be48deb7395069ae6ab12 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 26 Jun 2016 15:36:12 +0200 Subject: Enable/Disable VR experience --- examples/core_oculus_rift.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/core_oculus_rift.c b/examples/core_oculus_rift.c index e0ab61fd..4fe35607 100644 --- a/examples/core_oculus_rift.c +++ b/examples/core_oculus_rift.c @@ -30,7 +30,7 @@ int main() camera.position = (Vector3){ 5.0f, 5.0f, 5.0f }; // Camera position camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) - camera.fovy = 45.0f; // Camera field-of-view Y + camera.fovy = 60.0f; // Camera field-of-view Y Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; @@ -43,6 +43,8 @@ int main() // Update //---------------------------------------------------------------------------------- UpdateOculusTracking(); + + if (IsKeyPressed(KEY_SPACE)) ToggleVR(); //---------------------------------------------------------------------------------- // Draw -- cgit v1.2.3 From a8bed54586d721cb08dacceedcd669afcf582e67 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 27 Jun 2016 18:30:18 +0200 Subject: Corrected stream playing with index --- examples/audio_music_stream.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/audio_music_stream.c b/examples/audio_music_stream.c index 8c668cce..e135a6e4 100644 --- a/examples/audio_music_stream.c +++ b/examples/audio_music_stream.c @@ -24,7 +24,7 @@ int main() InitAudioDevice(); // Initialize audio device - PlayMusicStream("resources/audio/guitar_noodling.ogg"); // Play music stream + PlayMusicStream(0, "resources/audio/guitar_noodling.ogg"); // Play music stream int framesCounter = 0; float timePlayed = 0.0f; @@ -52,18 +52,18 @@ int main() { volume = 1.0; framesCounter = 0; - PlayMusicStream("resources/audio/another_file.ogg"); + PlayMusicStream(1, "resources/audio/another_file.ogg"); } SetMusicVolume(volume); } */ - if (IsWindowMinimized()) PauseMusicStream(); - else ResumeMusicStream(); + if (IsWindowMinimized()) PauseMusicStream(0); + else ResumeMusicStream(0); - timePlayed = GetMusicTimePlayed()/GetMusicTimeLength()*100*4; // We scale by 4 to fit 400 pixels + timePlayed = GetMusicTimePlayed(0)/GetMusicTimeLength(0)*100*4; // We scale by 4 to fit 400 pixels - UpdateMusicStream(); // Update music buffer with new stream data + UpdateMusicStream(0); // Update music buffer with new stream data //---------------------------------------------------------------------------------- // Draw -- cgit v1.2.3 From e977915577c1e5a7d46f85e385a27872e6a3f626 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 27 Jun 2016 18:31:23 +0200 Subject: Review examples makefile for RPI --- examples/Makefile | 53 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 22 deletions(-) (limited to 'examples') diff --git a/examples/Makefile b/examples/Makefile index 2d2344af..15df3ec9 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -78,44 +78,38 @@ endif #CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes # define any directories containing required header files +INCLUDES = -I. -I../src -I../src/external + ifeq ($(PLATFORM),PLATFORM_RPI) - INCLUDES = -I. -I../../src -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads + INCLUDES += -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads endif ifeq ($(PLATFORM),PLATFORM_DESKTOP) # add standard directories for GNU/Linux ifeq ($(PLATFORM_OS),LINUX) - INCLUDES = -I. -I../src -I/usr/local/include/raylib/ - else ifeq ($(PLATFORM_OS),OSX) - INCLUDES = -I. -I../src - else - INCLUDES = -I. -I../../src -IC:/raylib/raylib/src + INCLUDES += -I/usr/local/include/raylib/ + else ifeq ($(PLATFORM_OS),WINDOWS) # external libraries headers # GLFW3 - INCLUDES += -I../../external/glfw3/include + INCLUDES += -I../src/external/glfw3/include # OpenAL Soft - INCLUDES += -I../../external/openal_soft/include + INCLUDES += -I../src/external/openal_soft/include endif endif # define library paths containing required libs +LFLAGS = -L. -L../src + ifeq ($(PLATFORM),PLATFORM_RPI) - LFLAGS = -L. -L../../src -L/opt/vc/lib + LFLAGS += -L/opt/vc/lib endif ifeq ($(PLATFORM),PLATFORM_DESKTOP) # add standard directories for GNU/Linux - ifeq ($(PLATFORM_OS),LINUX) - LFLAGS = -L. -L../../src - else ifeq ($(PLATFORM_OS),OSX) - LFLAGS = -L. -L../src - else - LFLAGS = -L. -L../../src -LC:/raylib/raylib/src + ifeq ($(PLATFORM_OS),WINDOWS) # external libraries to link with # GLFW3 - LFLAGS += -L../../external/glfw3/lib/$(LIBPATH) - ifneq ($(PLATFORM_OS),OSX) + LFLAGS += -L../src/external/glfw3/lib/$(LIBPATH) # OpenAL Soft - LFLAGS += -L../../external/openal_soft/lib/$(LIBPATH) - endif + LFLAGS += -L../src/external/openal_soft/lib/$(LIBPATH) endif endif @@ -148,7 +142,7 @@ ifeq ($(PLATFORM),PLATFORM_RPI) endif ifeq ($(PLATFORM),PLATFORM_WEB) # just adjust the correct path to libraylib.bc - LIBS = ../src/libraylib.bc + LIBS = ../release/html5/libraylib.bc endif # define additional parameters and flags for windows @@ -178,6 +172,8 @@ EXAMPLES = \ core_3d_picking \ core_3d_camera_free \ core_3d_camera_first_person \ + core_2d_camera \ + core_oculus_rift \ shapes_logo_raylib \ shapes_basic_shapes \ shapes_colors_palette \ @@ -208,6 +204,7 @@ EXAMPLES = \ shaders_shapes_textures \ shaders_custom_uniform \ shaders_postprocessing \ + shaders_standard_lighting \ audio_sound_loading \ audio_music_stream \ fix_dylib \ @@ -287,7 +284,15 @@ core_3d_camera_free: core_3d_camera_free.c # compile [core] example - 3d camera first person core_3d_camera_first_person: core_3d_camera_first_person.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) - + +# compile [core] example - 2d camera +core_2d_camera: core_2d_camera.c + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) + +# compile [core] example - oculus rift +core_oculus_rift: core_oculus_rift.c + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) + # compile [shapes] example - raylib logo (with basic shapes) shapes_logo_raylib: shapes_logo_raylib.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) @@ -411,7 +416,11 @@ shaders_custom_uniform: shaders_custom_uniform.c # compile [shaders] example - postprocessing shader shaders_postprocessing: shaders_postprocessing.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) - + +# compile [shaders] example - standard lighting +shaders_standard_lighting: shaders_standard_lighting.c + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) + # compile [audio] example - sound loading and playing (WAV and OGG) audio_sound_loading: audio_sound_loading.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) -- cgit v1.2.3 From c4922c9e8854f9c936b28c3f8b00162b407ae503 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 27 Jun 2016 18:32:56 +0200 Subject: Reorganize shaders to respective folders --- examples/resources/shaders/base.vs | 26 ---- examples/resources/shaders/distortion.fs | 69 ---------- examples/resources/shaders/glsl100/distortion.fs | 68 ++++++++++ examples/resources/shaders/glsl330/distortion.fs | 69 ++++++++++ examples/resources/shaders/standard.fs | 155 ----------------------- examples/resources/shaders/standard.vs | 23 ---- 6 files changed, 137 insertions(+), 273 deletions(-) delete mode 100644 examples/resources/shaders/base.vs delete mode 100644 examples/resources/shaders/distortion.fs create mode 100644 examples/resources/shaders/glsl100/distortion.fs create mode 100644 examples/resources/shaders/glsl330/distortion.fs delete mode 100644 examples/resources/shaders/standard.fs delete mode 100644 examples/resources/shaders/standard.vs (limited to 'examples') diff --git a/examples/resources/shaders/base.vs b/examples/resources/shaders/base.vs deleted file mode 100644 index 638cb8ae..00000000 --- a/examples/resources/shaders/base.vs +++ /dev/null @@ -1,26 +0,0 @@ -#version 330 - -// Input vertex attributes -in vec3 vertexPosition; -in vec2 vertexTexCoord; -in vec3 vertexNormal; -in vec4 vertexColor; - -// Input uniform values -uniform mat4 mvpMatrix; - -// Output vertex attributes (to fragment shader) -out vec2 fragTexCoord; -out vec4 fragColor; - -// NOTE: Add here your custom variables - -void main() -{ - // Send vertex attributes to fragment shader - fragTexCoord = vertexTexCoord; - fragColor = vertexColor; - - // Calculate final vertex position - gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); -} \ No newline at end of file diff --git a/examples/resources/shaders/distortion.fs b/examples/resources/shaders/distortion.fs deleted file mode 100644 index 79bc5fa1..00000000 --- a/examples/resources/shaders/distortion.fs +++ /dev/null @@ -1,69 +0,0 @@ -#version 330 - -// Input vertex attributes (from vertex shader) -in vec2 fragTexCoord; - -// Input uniform values -uniform sampler2D texture0; - -// Output fragment color -out vec4 finalColor; - -// NOTE: Add here your custom variables -const vec2 LeftLensCenter = vec2(0.2863248, 0.5); -const vec2 RightLensCenter = vec2(0.7136753, 0.5); -const vec2 LeftScreenCenter = vec2(0.25, 0.5); -const vec2 RightScreenCenter = vec2(0.75, 0.5); -const vec2 Scale = vec2(0.25, 0.45); //vec2(0.1469278, 0.2350845); -const vec2 ScaleIn = vec2(4, 2.2222); -const vec4 HmdWarpParam = vec4(1, 0.22, 0.24, 0); - -/* -// Another set of default values -ChromaAbCorrection = {1.0, 0.0, 1.0, 0} -DistortionK = {1.0, 0.22, 0.24, 0} -Scale = {0.25, 0.5*AspectRatio, 0, 0} -ScaleIn = {4.0, 2/AspectRatio, 0, 0} -Left Screen Center = {0.25, 0.5, 0, 0} -Left Lens Center = {0.287994117, 0.5, 0, 0} -Right Screen Center = {0.75, 0.5, 0, 0} -Right Lens Center = {0.712005913, 0.5, 0, 0} -*/ - -// Scales input texture coordinates for distortion. -vec2 HmdWarp(vec2 in01, vec2 LensCenter) -{ - vec2 theta = (in01 - LensCenter)*ScaleIn; // Scales to [-1, 1] - float rSq = theta.x*theta.x + theta.y*theta.y; - vec2 rvector = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq); - - return LensCenter + Scale*rvector; -} - -void main() -{ - // SOURCE: http://www.mtbs3d.com/phpbb/viewtopic.php?f=140&t=17081 - - // The following two variables need to be set per eye - vec2 LensCenter = gl_FragCoord.x < 540 ? LeftLensCenter : RightLensCenter; - vec2 ScreenCenter = gl_FragCoord.x < 540 ? LeftScreenCenter : RightScreenCenter; - - vec2 tc = HmdWarp(fragTexCoord, LensCenter); - - if (any(bvec2(clamp(tc,ScreenCenter-vec2(0.25,0.5), ScreenCenter+vec2(0.25,0.5)) - tc))) finalColor = vec4(0.0, 0.0, 0.0, 1.0); - else - { - //tc.x = gl_FragCoord.x < 640 ? (2.0 * tc.x) : (2.0 * (tc.x - 0.5)); - finalColor = texture2D(texture0, tc); - } - - /* - // Chromatic aberration is caused when a lens can't focus every color to the same focal point. - // A simple way to fake this effect, and render it as a quick full-screen post-process, - // is to apply an offset to each color channel in a fragment shader. - vec4 rValue = texture2D(texture0, fragTexCoord - rOffset); - vec4 gValue = texture2D(texture0, fragTexCoord - gOffset); - vec4 bValue = texture2D(texture0, fragTexCoord - bOffset); - finalColor = vec4(rValue.r, gValue.g, bValue.b, 1.0); - */ -} diff --git a/examples/resources/shaders/glsl100/distortion.fs b/examples/resources/shaders/glsl100/distortion.fs new file mode 100644 index 00000000..3a1a45d3 --- /dev/null +++ b/examples/resources/shaders/glsl100/distortion.fs @@ -0,0 +1,68 @@ +#version 100 + +precision mediump float; + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; + +// Input uniform values +uniform sampler2D texture0; + +// NOTE: Add here your custom variables +const vec2 LeftLensCenter = vec2(0.2863248, 0.5); +const vec2 RightLensCenter = vec2(0.7136753, 0.5); +const vec2 LeftScreenCenter = vec2(0.25, 0.5); +const vec2 RightScreenCenter = vec2(0.75, 0.5); +const vec2 Scale = vec2(0.25, 0.45); //vec2(0.1469278, 0.2350845); +const vec2 ScaleIn = vec2(4, 2.2222); +const vec4 HmdWarpParam = vec4(1, 0.22, 0.24, 0); + +/* +// Another set of default values +ChromaAbCorrection = {1.0, 0.0, 1.0, 0} +DistortionK = {1.0, 0.22, 0.24, 0} +Scale = {0.25, 0.5*AspectRatio, 0, 0} +ScaleIn = {4.0, 2/AspectRatio, 0, 0} +Left Screen Center = {0.25, 0.5, 0, 0} +Left Lens Center = {0.287994117, 0.5, 0, 0} +Right Screen Center = {0.75, 0.5, 0, 0} +Right Lens Center = {0.712005913, 0.5, 0, 0} +*/ + +// Scales input texture coordinates for distortion. +vec2 HmdWarp(vec2 in01, vec2 LensCenter) +{ + vec2 theta = (in01 - LensCenter)*ScaleIn; // Scales to [-1, 1] + float rSq = theta.x*theta.x + theta.y*theta.y; + vec2 rvector = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq); + + return LensCenter + Scale*rvector; +} + +void main() +{ + // SOURCE: http://www.mtbs3d.com/phpbb/viewtopic.php?f=140&t=17081 + + // The following two variables need to be set per eye + vec2 LensCenter = fragTexCoord.x < 540 ? LeftLensCenter : RightLensCenter; + vec2 ScreenCenter = fragTexCoord.x < 540 ? LeftScreenCenter : RightScreenCenter; + + vec2 tc = HmdWarp(fragTexCoord, LensCenter); + + if (any(bvec2(clamp(tc,ScreenCenter-vec2(0.25,0.5), ScreenCenter+vec2(0.25,0.5)) - tc))) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); + else + { + //tc.x = gl_FragCoord.x < 640 ? (2.0 * tc.x) : (2.0 * (tc.x - 0.5)); + gl_FragColor = texture2D(texture0, tc); + } + + /* + // Chromatic aberration is caused when a lens can't focus every color to the same focal point. + // A simple way to fake this effect, and render it as a quick full-screen post-process, + // is to apply an offset to each color channel in a fragment shader. + vec4 rValue = texture2D(texture0, fragTexCoord - rOffset); + vec4 gValue = texture2D(texture0, fragTexCoord - gOffset); + vec4 bValue = texture2D(texture0, fragTexCoord - bOffset); + finalColor = vec4(rValue.r, gValue.g, bValue.b, 1.0); + */ +} diff --git a/examples/resources/shaders/glsl330/distortion.fs b/examples/resources/shaders/glsl330/distortion.fs new file mode 100644 index 00000000..e43f8451 --- /dev/null +++ b/examples/resources/shaders/glsl330/distortion.fs @@ -0,0 +1,69 @@ +#version 330 + +// Input vertex attributes (from vertex shader) +in vec2 fragTexCoord; + +// Input uniform values +uniform sampler2D texture0; + +// Output fragment color +out vec4 finalColor; + +// NOTE: Add here your custom variables +const vec2 LeftLensCenter = vec2(0.2863248, 0.5); +const vec2 RightLensCenter = vec2(0.7136753, 0.5); +const vec2 LeftScreenCenter = vec2(0.25, 0.5); +const vec2 RightScreenCenter = vec2(0.75, 0.5); +const vec2 Scale = vec2(0.25, 0.45); //vec2(0.1469278, 0.2350845); +const vec2 ScaleIn = vec2(4, 2.2222); +const vec4 HmdWarpParam = vec4(1, 0.22, 0.24, 0); + +/* +// Another set of default values +ChromaAbCorrection = {1.0, 0.0, 1.0, 0} +DistortionK = {1.0, 0.22, 0.24, 0} +Scale = {0.25, 0.5*AspectRatio, 0, 0} +ScaleIn = {4.0, 2/AspectRatio, 0, 0} +Left Screen Center = {0.25, 0.5, 0, 0} +Left Lens Center = {0.287994117, 0.5, 0, 0} +Right Screen Center = {0.75, 0.5, 0, 0} +Right Lens Center = {0.712005913, 0.5, 0, 0} +*/ + +// Scales input texture coordinates for distortion. +vec2 HmdWarp(vec2 in01, vec2 LensCenter) +{ + vec2 theta = (in01 - LensCenter)*ScaleIn; // Scales to [-1, 1] + float rSq = theta.x*theta.x + theta.y*theta.y; + vec2 rvector = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq); + + return LensCenter + Scale*rvector; +} + +void main() +{ + // SOURCE: http://www.mtbs3d.com/phpbb/viewtopic.php?f=140&t=17081 + + // The following two variables need to be set per eye + vec2 LensCenter = fragTexCoord.x < 540 ? LeftLensCenter : RightLensCenter; + vec2 ScreenCenter = fragTexCoord.x < 540 ? LeftScreenCenter : RightScreenCenter; + + vec2 tc = HmdWarp(fragTexCoord, LensCenter); + + if (any(bvec2(clamp(tc,ScreenCenter-vec2(0.25,0.5), ScreenCenter+vec2(0.25,0.5)) - tc))) finalColor = vec4(0.0, 0.0, 0.0, 1.0); + else + { + //tc.x = gl_FragCoord.x < 640 ? (2.0 * tc.x) : (2.0 * (tc.x - 0.5)); + finalColor = texture2D(texture0, tc); + } + + /* + // Chromatic aberration is caused when a lens can't focus every color to the same focal point. + // A simple way to fake this effect, and render it as a quick full-screen post-process, + // is to apply an offset to each color channel in a fragment shader. + vec4 rValue = texture2D(texture0, fragTexCoord - rOffset); + vec4 gValue = texture2D(texture0, fragTexCoord - gOffset); + vec4 bValue = texture2D(texture0, fragTexCoord - bOffset); + finalColor = vec4(rValue.r, gValue.g, bValue.b, 1.0); + */ +} diff --git a/examples/resources/shaders/standard.fs b/examples/resources/shaders/standard.fs deleted file mode 100644 index e5a6d1bc..00000000 --- a/examples/resources/shaders/standard.fs +++ /dev/null @@ -1,155 +0,0 @@ -#version 330 - -in vec3 fragPosition; -in vec2 fragTexCoord; -in vec4 fragColor; -in vec3 fragNormal; - -out vec4 finalColor; - -uniform sampler2D texture0; -uniform sampler2D texture1; -uniform sampler2D texture2; - -uniform vec4 colAmbient; -uniform vec4 colDiffuse; -uniform vec4 colSpecular; -uniform float glossiness; - -uniform int useNormal; -uniform int useSpecular; - -uniform mat4 modelMatrix; -uniform vec3 viewDir; - -struct Light { - int enabled; - int type; - vec3 position; - vec3 direction; - vec4 diffuse; - float intensity; - float radius; - float coneAngle; -}; - -const int maxLights = 8; -uniform int lightsCount; -uniform Light lights[maxLights]; - -vec3 CalcPointLight(Light l, vec3 n, vec3 v, float s) -{ - vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1)); - vec3 surfaceToLight = l.position - surfacePos; - - // Diffuse shading - float brightness = clamp(dot(n, surfaceToLight)/(length(surfaceToLight)*length(n)), 0, 1); - float diff = 1.0/dot(surfaceToLight/l.radius, surfaceToLight/l.radius)*brightness*l.intensity; - - // Specular shading - float spec = 0.0; - if (diff > 0.0) - { - vec3 h = normalize(-l.direction + v); - spec = pow(dot(n, h), 3 + glossiness)*s; - } - - return (diff*l.diffuse.rgb + spec*colSpecular.rgb); -} - -vec3 CalcDirectionalLight(Light l, vec3 n, vec3 v, float s) -{ - vec3 lightDir = normalize(-l.direction); - - // Diffuse shading - float diff = clamp(dot(n, lightDir), 0.0, 1.0)*l.intensity; - - // Specular shading - float spec = 0.0; - if (diff > 0.0) - { - vec3 h = normalize(lightDir + v); - spec = pow(dot(n, h), 3 + glossiness)*s; - } - - // Combine results - return (diff*l.intensity*l.diffuse.rgb + spec*colSpecular.rgb); -} - -vec3 CalcSpotLight(Light l, vec3 n, vec3 v, float s) -{ - vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1)); - vec3 lightToSurface = normalize(surfacePos - l.position); - vec3 lightDir = normalize(-l.direction); - - // Diffuse shading - float diff = clamp(dot(n, lightDir), 0.0, 1.0)*l.intensity; - - // Spot attenuation - float attenuation = clamp(dot(n, lightToSurface), 0.0, 1.0); - attenuation = dot(lightToSurface, -lightDir); - - float lightToSurfaceAngle = degrees(acos(attenuation)); - if (lightToSurfaceAngle > l.coneAngle) attenuation = 0.0; - - float falloff = (l.coneAngle - lightToSurfaceAngle)/l.coneAngle; - - // Combine diffuse and attenuation - float diffAttenuation = diff*attenuation; - - // Specular shading - float spec = 0.0; - if (diffAttenuation > 0.0) - { - vec3 h = normalize(lightDir + v); - spec = pow(dot(n, h), 3 + glossiness)*s; - } - - return (falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb)); -} - -void main() -{ - // Calculate fragment normal in screen space - // NOTE: important to multiply model matrix by fragment normal to apply model transformation (rotation and scale) - mat3 normalMatrix = transpose(inverse(mat3(modelMatrix))); - vec3 normal = normalize(normalMatrix*fragNormal); - - // Normalize normal and view direction vectors - vec3 n = normalize(normal); - vec3 v = normalize(viewDir); - - // Calculate diffuse texture color fetching - vec4 texelColor = texture(texture0, fragTexCoord); - vec3 lighting = colAmbient.rgb; - - // Calculate normal texture color fetching or set to maximum normal value by default - if (useNormal == 1) - { - n *= texture(texture1, fragTexCoord).rgb; - n = normalize(n); - } - - // Calculate specular texture color fetching or set to maximum specular value by default - float spec = 1.0; - if (useSpecular == 1) spec *= normalize(texture(texture2, fragTexCoord).r); - - for (int i = 0; i < lightsCount; i++) - { - // Check if light is enabled - if (lights[i].enabled == 1) - { - // Calculate lighting based on light type - switch (lights[i].type) - { - case 0: lighting += CalcPointLight(lights[i], n, v, spec); break; - case 1: lighting += CalcDirectionalLight(lights[i], n, v, spec); break; - case 2: lighting += CalcSpotLight(lights[i], n, v, spec); break; - default: break; - } - } - } - - // Calculate final fragment color - finalColor = vec4(texelColor.rgb*lighting*colDiffuse.rgb, texelColor.a*colDiffuse.a); -} diff --git a/examples/resources/shaders/standard.vs b/examples/resources/shaders/standard.vs deleted file mode 100644 index fc0a5ff4..00000000 --- a/examples/resources/shaders/standard.vs +++ /dev/null @@ -1,23 +0,0 @@ -#version 330 - -in vec3 vertexPosition; -in vec3 vertexNormal; -in vec2 vertexTexCoord; -in vec4 vertexColor; - -out vec3 fragPosition; -out vec2 fragTexCoord; -out vec4 fragColor; -out vec3 fragNormal; - -uniform mat4 mvpMatrix; - -void main() -{ - fragPosition = vertexPosition; - fragTexCoord = vertexTexCoord; - fragColor = vertexColor; - fragNormal = vertexNormal; - - gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); -} \ No newline at end of file -- cgit v1.2.3 From 5a4eb34c39e404fdd5804299111477a10dd3895d Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 27 Jun 2016 18:59:03 +0200 Subject: Corrected issue on distortion shader --- examples/core_oculus_rift.c | 4 +++- examples/resources/shaders/glsl100/distortion.fs | 10 +++------- examples/resources/shaders/glsl330/distortion.fs | 22 ++++++++++------------ 3 files changed, 16 insertions(+), 20 deletions(-) (limited to 'examples') diff --git a/examples/core_oculus_rift.c b/examples/core_oculus_rift.c index 4fe35607..95b89106 100644 --- a/examples/core_oculus_rift.c +++ b/examples/core_oculus_rift.c @@ -63,11 +63,13 @@ int main() DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawGrid(10, 1.0f); - + DrawDefaultBuffers(); // Process internal dynamic buffers } End3dMode(); + + DrawFPS(10, 10); EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples/resources/shaders/glsl100/distortion.fs b/examples/resources/shaders/glsl100/distortion.fs index 3a1a45d3..19e6656a 100644 --- a/examples/resources/shaders/glsl100/distortion.fs +++ b/examples/resources/shaders/glsl100/distortion.fs @@ -44,17 +44,13 @@ void main() // SOURCE: http://www.mtbs3d.com/phpbb/viewtopic.php?f=140&t=17081 // The following two variables need to be set per eye - vec2 LensCenter = fragTexCoord.x < 540 ? LeftLensCenter : RightLensCenter; - vec2 ScreenCenter = fragTexCoord.x < 540 ? LeftScreenCenter : RightScreenCenter; + vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter; + vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter; vec2 tc = HmdWarp(fragTexCoord, LensCenter); if (any(bvec2(clamp(tc,ScreenCenter-vec2(0.25,0.5), ScreenCenter+vec2(0.25,0.5)) - tc))) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); - else - { - //tc.x = gl_FragCoord.x < 640 ? (2.0 * tc.x) : (2.0 * (tc.x - 0.5)); - gl_FragColor = texture2D(texture0, tc); - } + else gl_FragColor = texture2D(texture0, tc); /* // Chromatic aberration is caused when a lens can't focus every color to the same focal point. diff --git a/examples/resources/shaders/glsl330/distortion.fs b/examples/resources/shaders/glsl330/distortion.fs index e43f8451..c8777c18 100644 --- a/examples/resources/shaders/glsl330/distortion.fs +++ b/examples/resources/shaders/glsl330/distortion.fs @@ -17,6 +17,7 @@ const vec2 RightScreenCenter = vec2(0.75, 0.5); const vec2 Scale = vec2(0.25, 0.45); //vec2(0.1469278, 0.2350845); const vec2 ScaleIn = vec2(4, 2.2222); const vec4 HmdWarpParam = vec4(1, 0.22, 0.24, 0); +const vec4 ChromaAbCorrection = vec4(0.99599999, -0.0040000002, 1.0140001, 0.0); /* // Another set of default values @@ -45,25 +46,22 @@ void main() // SOURCE: http://www.mtbs3d.com/phpbb/viewtopic.php?f=140&t=17081 // The following two variables need to be set per eye - vec2 LensCenter = fragTexCoord.x < 540 ? LeftLensCenter : RightLensCenter; - vec2 ScreenCenter = fragTexCoord.x < 540 ? LeftScreenCenter : RightScreenCenter; + vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter; + vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter; vec2 tc = HmdWarp(fragTexCoord, LensCenter); - if (any(bvec2(clamp(tc,ScreenCenter-vec2(0.25,0.5), ScreenCenter+vec2(0.25,0.5)) - tc))) finalColor = vec4(0.0, 0.0, 0.0, 1.0); - else - { - //tc.x = gl_FragCoord.x < 640 ? (2.0 * tc.x) : (2.0 * (tc.x - 0.5)); - finalColor = texture2D(texture0, tc); - } + if (any(bvec2(clamp(tc, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tc))) finalColor = vec4(0.0, 0.0, 0.0, 1.0); + else finalColor = texture2D(texture0, tc); - /* // Chromatic aberration is caused when a lens can't focus every color to the same focal point. // A simple way to fake this effect, and render it as a quick full-screen post-process, // is to apply an offset to each color channel in a fragment shader. - vec4 rValue = texture2D(texture0, fragTexCoord - rOffset); - vec4 gValue = texture2D(texture0, fragTexCoord - gOffset); - vec4 bValue = texture2D(texture0, fragTexCoord - bOffset); + /* + vec4 rValue = texture2D(texture0, fragTexCoord - ChromaAbCorrection.x); + vec4 gValue = texture2D(texture0, fragTexCoord - ChromaAbCorrection.y); + vec4 bValue = texture2D(texture0, fragTexCoord - ChromaAbCorrection.z); + finalColor = vec4(rValue.r, gValue.g, bValue.b, 1.0); */ } -- cgit v1.2.3 From 6fbf6a1c234ab7db9b975109c3c2138f83684442 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 27 Jun 2016 19:18:53 +0200 Subject: Redesigned distortion shader, added chromatic aberration --- examples/resources/shaders/glsl100/distortion.fs | 51 ++++++++++++----------- examples/resources/shaders/glsl330/distortion.fs | 53 ++++++++++++------------ 2 files changed, 53 insertions(+), 51 deletions(-) (limited to 'examples') diff --git a/examples/resources/shaders/glsl100/distortion.fs b/examples/resources/shaders/glsl100/distortion.fs index 19e6656a..d7b687bf 100644 --- a/examples/resources/shaders/glsl100/distortion.fs +++ b/examples/resources/shaders/glsl100/distortion.fs @@ -29,36 +29,37 @@ Right Screen Center = {0.75, 0.5, 0, 0} Right Lens Center = {0.712005913, 0.5, 0, 0} */ -// Scales input texture coordinates for distortion. -vec2 HmdWarp(vec2 in01, vec2 LensCenter) -{ - vec2 theta = (in01 - LensCenter)*ScaleIn; // Scales to [-1, 1] - float rSq = theta.x*theta.x + theta.y*theta.y; - vec2 rvector = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq); - - return LensCenter + Scale*rvector; -} - void main() { - // SOURCE: http://www.mtbs3d.com/phpbb/viewtopic.php?f=140&t=17081 - // The following two variables need to be set per eye vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter; vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter; + + // Scales input texture coordinates for distortion: vec2 HmdWarp(vec2 fragTexCoord, vec2 LensCenter) + vec2 theta = (fragTexCoord - LensCenter)*ScaleIn; // Scales to [-1, 1] + float rSq = theta.x*theta.x + theta.y*theta.y; + vec2 theta1 = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq); + //vec2 tc = LensCenter + Scale*theta1; + + // Detect whether blue texture coordinates are out of range since these will scaled out the furthest + vec2 thetaBlue = theta1*(ChromaAbParam.z + ChromaAbParam.w*rSq); + vec2 tcBlue = LensCenter + Scale*thetaBlue; - vec2 tc = HmdWarp(fragTexCoord, LensCenter); + if (any(bvec2(clamp(tcBlue, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tcBlue))) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); + else + { + // Do blue texture lookup + float blue = texture2D(texture0, tcBlue).b; - if (any(bvec2(clamp(tc,ScreenCenter-vec2(0.25,0.5), ScreenCenter+vec2(0.25,0.5)) - tc))) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); - else gl_FragColor = texture2D(texture0, tc); - - /* - // Chromatic aberration is caused when a lens can't focus every color to the same focal point. - // A simple way to fake this effect, and render it as a quick full-screen post-process, - // is to apply an offset to each color channel in a fragment shader. - vec4 rValue = texture2D(texture0, fragTexCoord - rOffset); - vec4 gValue = texture2D(texture0, fragTexCoord - gOffset); - vec4 bValue = texture2D(texture0, fragTexCoord - bOffset); - finalColor = vec4(rValue.r, gValue.g, bValue.b, 1.0); - */ + // Do green lookup (no scaling) + vec2 tcGreen = LensCenter + Scale*theta1; + float green = texture2D(texture0, tcGreen).g; + + // Do red scale and lookup + vec2 thetaRed = theta1*(ChromaAbParam.x + ChromaAbParam.y*rSq); + vec2 tcRed = LensCenter + Scale*thetaRed; + float red = texture2D(texture0, tcRed).r; + + gl_FragColor = vec4(red, green, blue, 1.0); + } } diff --git a/examples/resources/shaders/glsl330/distortion.fs b/examples/resources/shaders/glsl330/distortion.fs index c8777c18..4cd9937f 100644 --- a/examples/resources/shaders/glsl330/distortion.fs +++ b/examples/resources/shaders/glsl330/distortion.fs @@ -17,7 +17,7 @@ const vec2 RightScreenCenter = vec2(0.75, 0.5); const vec2 Scale = vec2(0.25, 0.45); //vec2(0.1469278, 0.2350845); const vec2 ScaleIn = vec2(4, 2.2222); const vec4 HmdWarpParam = vec4(1, 0.22, 0.24, 0); -const vec4 ChromaAbCorrection = vec4(0.99599999, -0.0040000002, 1.0140001, 0.0); +const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.0); /* // Another set of default values @@ -31,37 +31,38 @@ Right Screen Center = {0.75, 0.5, 0, 0} Right Lens Center = {0.712005913, 0.5, 0, 0} */ -// Scales input texture coordinates for distortion. -vec2 HmdWarp(vec2 in01, vec2 LensCenter) -{ - vec2 theta = (in01 - LensCenter)*ScaleIn; // Scales to [-1, 1] - float rSq = theta.x*theta.x + theta.y*theta.y; - vec2 rvector = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq); - - return LensCenter + Scale*rvector; -} - void main() { - // SOURCE: http://www.mtbs3d.com/phpbb/viewtopic.php?f=140&t=17081 - // The following two variables need to be set per eye vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter; vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter; + + // Scales input texture coordinates for distortion: vec2 HmdWarp(vec2 fragTexCoord, vec2 LensCenter) + vec2 theta = (fragTexCoord - LensCenter)*ScaleIn; // Scales to [-1, 1] + float rSq = theta.x*theta.x + theta.y*theta.y; + vec2 theta1 = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq); + //vec2 tc = LensCenter + Scale*theta1; + + // Detect whether blue texture coordinates are out of range since these will scaled out the furthest + vec2 thetaBlue = theta1*(ChromaAbParam.z + ChromaAbParam.w*rSq); + vec2 tcBlue = LensCenter + Scale*thetaBlue; - vec2 tc = HmdWarp(fragTexCoord, LensCenter); + if (any(bvec2(clamp(tcBlue, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tcBlue))) finalColor = vec4(0.0, 0.0, 0.0, 1.0); + else + { + // Do blue texture lookup + float blue = texture(texture0, tcBlue).b; - if (any(bvec2(clamp(tc, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tc))) finalColor = vec4(0.0, 0.0, 0.0, 1.0); - else finalColor = texture2D(texture0, tc); - - // Chromatic aberration is caused when a lens can't focus every color to the same focal point. - // A simple way to fake this effect, and render it as a quick full-screen post-process, - // is to apply an offset to each color channel in a fragment shader. - /* - vec4 rValue = texture2D(texture0, fragTexCoord - ChromaAbCorrection.x); - vec4 gValue = texture2D(texture0, fragTexCoord - ChromaAbCorrection.y); - vec4 bValue = texture2D(texture0, fragTexCoord - ChromaAbCorrection.z); + // Do green lookup (no scaling) + vec2 tcGreen = LensCenter + Scale*theta1; + float green = texture(texture0, tcGreen).g; + + // Do red scale and lookup + vec2 thetaRed = theta1*(ChromaAbParam.x + ChromaAbParam.y*rSq); + vec2 tcRed = LensCenter + Scale*thetaRed; + float red = texture(texture0, tcRed).r; - finalColor = vec4(rValue.r, gValue.g, bValue.b, 1.0); - */ + finalColor = vec4(red, green, blue, 1.0); + } } + -- cgit v1.2.3 From be61d2f8c1d3ce4579b4e74557fb4773624bf00c Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 27 Jun 2016 20:09:10 +0200 Subject: Added missing parameter --- examples/resources/shaders/glsl100/distortion.fs | 1 + 1 file changed, 1 insertion(+) (limited to 'examples') diff --git a/examples/resources/shaders/glsl100/distortion.fs b/examples/resources/shaders/glsl100/distortion.fs index d7b687bf..a0a6cc18 100644 --- a/examples/resources/shaders/glsl100/distortion.fs +++ b/examples/resources/shaders/glsl100/distortion.fs @@ -16,6 +16,7 @@ const vec2 RightScreenCenter = vec2(0.75, 0.5); const vec2 Scale = vec2(0.25, 0.45); //vec2(0.1469278, 0.2350845); const vec2 ScaleIn = vec2(4, 2.2222); const vec4 HmdWarpParam = vec4(1, 0.22, 0.24, 0); +const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.0); /* // Another set of default values -- cgit v1.2.3 From f88c95ce2d48730a7c4025a65d7b65402ffb8467 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 30 Jun 2016 00:26:56 +0200 Subject: Updated examples and makefile --- examples/Makefile | 5 +++++ examples/core_2d_camera.c | 4 ++-- examples/core_oculus_rift.c | 2 +- examples/core_world_screen.c | 1 - 4 files changed, 8 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/Makefile b/examples/Makefile index 15df3ec9..711f03a7 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -173,6 +173,7 @@ EXAMPLES = \ core_3d_camera_free \ core_3d_camera_first_person \ core_2d_camera \ + core_world_screen \ core_oculus_rift \ shapes_logo_raylib \ shapes_basic_shapes \ @@ -288,6 +289,10 @@ core_3d_camera_first_person: core_3d_camera_first_person.c # compile [core] example - 2d camera core_2d_camera: core_2d_camera.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) + +# compile [core] example - world screen +core_world_screen: core_world_screen.c + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) # compile [core] example - oculus rift core_oculus_rift: core_oculus_rift.c diff --git a/examples/core_2d_camera.c b/examples/core_2d_camera.c index 73e1d65f..f2f219ef 100644 --- a/examples/core_2d_camera.c +++ b/examples/core_2d_camera.c @@ -23,8 +23,8 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera"); Rectangle player = { 400, 280, 40, 40 }; - Rectangle buildings[MAX_BUILDINGS] = { 0, 0, 0, 0 }; - Color buildColors[MAX_BUILDINGS] = { 80, 80, 80, 255 }; + Rectangle buildings[MAX_BUILDINGS]; + Color buildColors[MAX_BUILDINGS]; int spacing = 0; diff --git a/examples/core_oculus_rift.c b/examples/core_oculus_rift.c index 95b89106..c073d3d6 100644 --- a/examples/core_oculus_rift.c +++ b/examples/core_oculus_rift.c @@ -34,7 +34,7 @@ int main() Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; - //SetTargetFPS(90); // Set our game to run at 90 frames-per-second + SetTargetFPS(90); // Set our game to run at 90 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop diff --git a/examples/core_world_screen.c b/examples/core_world_screen.c index f3798830..aa9505e8 100644 --- a/examples/core_world_screen.c +++ b/examples/core_world_screen.c @@ -63,7 +63,6 @@ int main() DrawText("Enemy: 100 / 100", cubeScreenPosition.x - MeasureText("Enemy: 100 / 100", 20) / 2, cubeScreenPosition.y, 20, BLACK); DrawText("Text is always on top of the cube", (screenWidth - MeasureText("Text is always on top of the cube", 20)) / 2, 25, 20, GRAY); - EndDrawing(); //---------------------------------------------------------------------------------- -- cgit v1.2.3 From ee72654b557202a673f042484c83d3020ae618b8 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 4 Jul 2016 01:29:23 +0200 Subject: Redesigned stereo rendering mechanism Now it's easier for the user! Just init Oculus device and get stereo rendering! --- examples/core_oculus_rift.c | 11 ++--------- examples/resources/shaders/glsl330/distortion.fs | 9 +++++---- 2 files changed, 7 insertions(+), 13 deletions(-) (limited to 'examples') diff --git a/examples/core_oculus_rift.c b/examples/core_oculus_rift.c index c073d3d6..131a21c2 100644 --- a/examples/core_oculus_rift.c +++ b/examples/core_oculus_rift.c @@ -50,22 +50,15 @@ int main() // Draw //---------------------------------------------------------------------------------- BeginDrawing(); - + ClearBackground(RAYWHITE); - + Begin3dMode(camera); - for (int eye = 0; eye < 2; eye++) - { - SetOculusView(eye); - DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawGrid(10, 1.0f); - - DrawDefaultBuffers(); // Process internal dynamic buffers - } End3dMode(); diff --git a/examples/resources/shaders/glsl330/distortion.fs b/examples/resources/shaders/glsl330/distortion.fs index 4cd9937f..62856341 100644 --- a/examples/resources/shaders/glsl330/distortion.fs +++ b/examples/resources/shaders/glsl330/distortion.fs @@ -10,12 +10,13 @@ uniform sampler2D texture0; out vec4 finalColor; // NOTE: Add here your custom variables -const vec2 LeftLensCenter = vec2(0.2863248, 0.5); -const vec2 RightLensCenter = vec2(0.7136753, 0.5); +const vec2 LeftLensCenter = vec2(0.288, 0.5); +const vec2 RightLensCenter = vec2(0.712, 0.5); const vec2 LeftScreenCenter = vec2(0.25, 0.5); const vec2 RightScreenCenter = vec2(0.75, 0.5); -const vec2 Scale = vec2(0.25, 0.45); //vec2(0.1469278, 0.2350845); -const vec2 ScaleIn = vec2(4, 2.2222); +uniform vec2 Scale = vec2(0.25, 0.45); //vec2(0.1469278, 0.2350845); +uniform vec2 ScaleIn = vec2(4, 2.2222); + const vec4 HmdWarpParam = vec4(1, 0.22, 0.24, 0); const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.0); -- cgit v1.2.3 From 2ff2096b36d80078cbda5e61ff77d7fedeeeaeb5 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 4 Jul 2016 18:35:50 +0200 Subject: Moved Oculus enable drawing to user side... Still thinking about the best way to manage this... --- examples/core_oculus_rift.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'examples') diff --git a/examples/core_oculus_rift.c b/examples/core_oculus_rift.c index 131a21c2..734ba8fd 100644 --- a/examples/core_oculus_rift.c +++ b/examples/core_oculus_rift.c @@ -52,6 +52,8 @@ int main() BeginDrawing(); ClearBackground(RAYWHITE); + + if (IsOculusReady()) BeginOculusDrawing(); Begin3dMode(camera); @@ -62,6 +64,8 @@ int main() End3dMode(); + if (IsOculusReady()) EndOculusDrawing(); + DrawFPS(10, 10); EndDrawing(); -- cgit v1.2.3