aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorvictorfisac <victorfisac@gmail.com>2016-07-05 11:57:05 +0200
committervictorfisac <victorfisac@gmail.com>2016-07-05 11:57:05 +0200
commit1aecd5be072083e27e4289499865b5681f1ea656 (patch)
tree808159aa95df9b2be5509d83791aa6cad4ddf6b8 /examples
parent1b0996fb0bcf68e2a14bc6260c6f2c5366ab033f (diff)
parent2ff2096b36d80078cbda5e61ff77d7fedeeeaeb5 (diff)
downloadraylib-1aecd5be072083e27e4289499865b5681f1ea656.tar.gz
raylib-1aecd5be072083e27e4289499865b5681f1ea656.zip
Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile56
-rw-r--r--examples/audio_music_stream.c12
-rw-r--r--examples/core_2d_camera.c4
-rw-r--r--examples/core_color_select.c4
-rw-r--r--examples/core_oculus_rift.c35
-rw-r--r--examples/core_world_screen.c1
-rw-r--r--examples/models_cubicmap.c2
-rw-r--r--examples/models_heightmap.c2
-rw-r--r--examples/models_obj_loading.c2
-rw-r--r--examples/oculus_glfw_sample/rlgl_standalone.c16
-rw-r--r--examples/oculus_glfw_sample/rlgl_standalone_stereo.c2
-rw-r--r--examples/resources/shaders/glsl100/distortion.fs66
-rw-r--r--examples/resources/shaders/glsl330/distortion.fs69
-rw-r--r--examples/resources/shaders/standard.fs155
-rw-r--r--examples/resources/shaders/standard.vs23
-rw-r--r--examples/shaders_custom_uniform.c2
-rw-r--r--examples/shaders_postprocessing.c2
17 files changed, 215 insertions, 238 deletions
diff --git a/examples/Makefile b/examples/Makefile
index 2d2344af..711f03a7 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,9 @@ EXAMPLES = \
core_3d_picking \
core_3d_camera_free \
core_3d_camera_first_person \
+ core_2d_camera \
+ core_world_screen \
+ core_oculus_rift \
shapes_logo_raylib \
shapes_basic_shapes \
shapes_colors_palette \
@@ -208,6 +205,7 @@ EXAMPLES = \
shaders_shapes_textures \
shaders_custom_uniform \
shaders_postprocessing \
+ shaders_standard_lighting \
audio_sound_loading \
audio_music_stream \
fix_dylib \
@@ -287,7 +285,19 @@ 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 - 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
+ $(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 +421,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)
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
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_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;
}
diff --git a/examples/core_oculus_rift.c b/examples/core_oculus_rift.c
index 86517829..734ba8fd 100644
--- a/examples/core_oculus_rift.c
+++ b/examples/core_oculus_rift.c
@@ -30,11 +30,11 @@ 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 };
- //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
@@ -43,31 +43,30 @@ int main()
// Update
//----------------------------------------------------------------------------------
UpdateOculusTracking();
+
+ if (IsKeyPressed(KEY_SPACE)) ToggleVR();
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
-
+
ClearBackground(RAYWHITE);
- BeginOculusDrawing();
-
- for (int eye = 0; eye < 2; eye++)
- {
- Begin3dMode(camera);
+ if (IsOculusReady()) BeginOculusDrawing();
+
+ Begin3dMode(camera);
+
+ DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
+ DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
- SetOculusMatrix(eye);
-
- DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
- DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
-
- DrawGrid(10, 1.0f);
-
- End3dMode();
- }
+ DrawGrid(10, 1.0f);
+
+ End3dMode();
+
+ if (IsOculusReady()) EndOculusDrawing();
- EndOculusDrawing();
+ DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
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();
//----------------------------------------------------------------------------------
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/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
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
diff --git a/examples/resources/shaders/glsl100/distortion.fs b/examples/resources/shaders/glsl100/distortion.fs
new file mode 100644
index 00000000..a0a6cc18
--- /dev/null
+++ b/examples/resources/shaders/glsl100/distortion.fs
@@ -0,0 +1,66 @@
+#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);
+const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.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}
+*/
+
+void main()
+{
+ // 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;
+
+ 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;
+
+ // 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
new file mode 100644
index 00000000..62856341
--- /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.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);
+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);
+
+/*
+// 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}
+*/
+
+void main()
+{
+ // 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;
+
+ 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;
+
+ // 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(red, green, blue, 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
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