diff --git a/lab16 with raylib/lab16 with raylib/lab16 with raylib.vcxproj b/lab16 with raylib/lab16 with raylib/lab16 with raylib.vcxproj
index 50328ce..d29a66f 100644
--- a/lab16 with raylib/lab16 with raylib/lab16 with raylib.vcxproj
+++ b/lab16 with raylib/lab16 with raylib/lab16 with raylib.vcxproj
@@ -104,7 +104,7 @@
true
_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
- $(SolutionDir)\include
+ $(SolutionDir)\include;$(SolutionDir)\resources
Console
@@ -121,7 +121,7 @@
true
NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
- $(SolutionDir)\include
+ $(SolutionDir)\include;$(SolutionDir)\resources
Windows
diff --git a/lab16 with raylib/resources/blur.frag b/lab16 with raylib/resources/blur.frag
index 7eba3d7..2336c32 100644
--- a/lab16 with raylib/resources/blur.frag
+++ b/lab16 with raylib/resources/blur.frag
@@ -14,13 +14,45 @@ out vec4 finalColor;
// NOTE: Add here your custom variables
// NOTE: values must be passed from code
-uniform float renderWidth = 750;
+uniform float renderWidth;
uniform float renderHeight;
uniform float seconds;
float offset[3] = float[](0.0, 1.3846153846, 3.2307692308);
float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);
+vec4 getAverageColor(sampler2D iTexture, vec2 resolution, vec2 uv, float power)
+{
+ vec4 color = vec4(0);
+ for (int x = -1; x < 2; x++)
+ {
+ for (int y = -1; y < 2; y++)
+ {
+ vec2 offset = vec2(x,y) / resolution.xy * power;
+ color += texture(iTexture, uv + offset);
+ }
+ }
+
+ color /= 9.0;
+
+ return color;
+}
+
+vec4 blur13(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
+ vec4 color = vec4(0.0);
+ vec2 off1 = vec2(1.411764705882353) * direction;
+ vec2 off2 = vec2(3.2941176470588234) * direction;
+ vec2 off3 = vec2(5.176470588235294) * direction;
+ color += texture2D(image, uv) * 0.1964825501511404;
+ color += texture2D(image, uv + (off1 / resolution)) * 0.2969069646728344;
+ color += texture2D(image, uv - (off1 / resolution)) * 0.2969069646728344;
+ color += texture2D(image, uv + (off2 / resolution)) * 0.09447039785044732;
+ color += texture2D(image, uv - (off2 / resolution)) * 0.09447039785044732;
+ color += texture2D(image, uv + (off3 / resolution)) * 0.010381362401148057;
+ color += texture2D(image, uv - (off3 / resolution)) * 0.010381362401148057;
+ return color;
+}
+
void main()
{
// Texel color fetching from texture sampler
@@ -38,7 +70,9 @@ void main()
vec4 blue = vec4(0.0, 0.5, 0.5, 1.0);
//finalColor = mix(red, blue, (sin(fragTexCoord.x * 24 + seconds * 4.0) + 1.0) / 2.0);
-
+ //vec4 xBlur = blur13(texture0, fragTexCoord, vec2(renderWidth, renderHeight), vec2(1, 0));
+ //vec4 yBlur = blur13(texture0, fragTexCoord, vec2(renderWidth, renderHeight), vec2(0, 1));
+ //finalColor = (xBlur + yBlur) * 0.5;
finalColor = texelColor;
//finalColor = vec4((sin(fragTexCoord.x * 24 + seconds * 4.0) + 1.0) / 2.0, 0.5, 0.5, 1.0);
}
\ No newline at end of file
diff --git a/lab16 with raylib/resources/blur13.frag b/lab16 with raylib/resources/blur13.frag
new file mode 100644
index 0000000..8e30d19
--- /dev/null
+++ b/lab16 with raylib/resources/blur13.frag
@@ -0,0 +1,28 @@
+#version 330
+
+in vec2 fragTexCoord; // Fragment input attribute: texture coordinate
+in vec4 fragColor; // Fragment input attribute: color
+out vec4 finalColor; // Fragment output: color
+uniform sampler2D texture0; // Fragment input texture (always required, could be a white pixel)
+uniform vec4 colDiffuse; // Fragment input color diffuse (multiplied by texture color)
+
+uniform vec2 resolution;
+uniform vec2 direction;
+
+void main()
+{
+ vec4 color = vec4(0.0);
+ vec2 off1 = vec2(1.411764705882353) * direction;
+ vec2 off2 = vec2(3.2941176470588234) * direction;
+ vec2 off3 = vec2(5.176470588235294) * direction;
+
+ color += texture(texture0, fragTexCoord) * 0.1964825501511404;
+ color += texture(texture0, fragTexCoord + (off1 / resolution)) * 0.2969069646728344;
+ color += texture(texture0, fragTexCoord - (off1 / resolution)) * 0.2969069646728344;
+ color += texture(texture0, fragTexCoord + (off2 / resolution)) * 0.09447039785044732;
+ color += texture(texture0, fragTexCoord - (off2 / resolution)) * 0.09447039785044732;
+ color += texture(texture0, fragTexCoord + (off3 / resolution)) * 0.010381362401148057;
+ color += texture(texture0, fragTexCoord - (off3 / resolution)) * 0.010381362401148057;
+
+ finalColor = color*colDiffuse*fragColor;
+}
\ No newline at end of file
diff --git a/lab16 with raylib/resources/watershader.frag b/lab16 with raylib/resources/watershader.frag
index b7cf58f..b83189e 100644
--- a/lab16 with raylib/resources/watershader.frag
+++ b/lab16 with raylib/resources/watershader.frag
@@ -8,47 +8,41 @@ uniform vec4 colDiffuse; // Fragment input color diffuse (multiplied by textu
// Custom variables
uniform sampler2D texture1; // water bump map
-
-uniform float xBlurDistance = 0.5 / 750;
uniform float xWaveWidth = 0.1;
uniform float xWaveHeight = 0.1;
uniform float seconds;
-
uniform vec2 iResolution;
-//uniform vec4 waterColor = vec4(0.8, 0.95, 1.0, 1.0);
-
-vec4 getAverageColor(sampler2D iTexture, vec2 uv, float power)
+vec4 blur13(sampler2D image, vec2 uv, vec2 resolution, vec2 direction)
{
- vec4 color = vec4(0);
- for (int x = -1; x < 2; x++)
- {
- for (int y = -1; y < 2; y++)
- {
- vec2 offset = vec2(x,y) / iResolution.xy * power;
- color += texture(iTexture, uv + offset);
- }
- }
-
- color /= 9.0;
-
- return color;
+ vec4 color = vec4(0.0);
+ vec2 off1 = vec2(1.411764705882353) * direction;
+ vec2 off2 = vec2(3.2941176470588234) * direction;
+ vec2 off3 = vec2(5.176470588235294) * direction;
+ color += texture2D(image, uv) * 0.1964825501511404;
+ color += texture2D(image, uv + (off1 / resolution)) * 0.2969069646728344;
+ color += texture2D(image, uv - (off1 / resolution)) * 0.2969069646728344;
+ color += texture2D(image, uv + (off2 / resolution)) * 0.09447039785044732;
+ color += texture2D(image, uv - (off2 / resolution)) * 0.09447039785044732;
+ color += texture2D(image, uv + (off3 / resolution)) * 0.010381362401148057;
+ color += texture2D(image, uv - (off3 / resolution)) * 0.010381362401148057;
+ return color;
}
-
void main()
{
vec4 bumpColor = texture(texture1, fragTexCoord + sin(seconds / 2.0) / 20.0);
bumpColor = (bumpColor + texture(texture1, fragTexCoord*1.5 + cos(seconds / 2.0) / 20.0)) * 0.5;
vec2 samplePos = fragTexCoord;
-
samplePos.x += (bumpColor.r - 0.5) * xWaveWidth * fragColor.r;
samplePos.y += (bumpColor.g - 0.5) * xWaveHeight * fragColor.g;
- vec4 result = getAverageColor(texture0, samplePos, 0.7);
-
- result = result*colDiffuse*fragColor;
+ vec4 xBlur = blur13(texture0, samplePos, iResolution, vec2(0.5, 0));
+ vec4 yBlur = blur13(texture0, samplePos, iResolution, vec2(0, 0.5));
+ vec4 result = (xBlur + yBlur) * 0.5;
+
+ result = result*colDiffuse*fragColor;
finalColor = result;
}
diff --git a/lab16 with raylib/src/main.c b/lab16 with raylib/src/main.c
index 87266fc..83ef6ae 100644
--- a/lab16 with raylib/src/main.c
+++ b/lab16 with raylib/src/main.c
@@ -532,6 +532,10 @@ int main()
SetTextureFilter(canvas.texture, TEXTURE_FILTER_BILINEAR);
SetTextureWrap(canvas.texture, TEXTURE_WRAP_CLAMP);
+ RenderTexture2D canvasBlurX = LoadRenderTexture(screenWidth, screenHeight);
+ SetTextureFilter(canvasBlurX.texture, TEXTURE_FILTER_BILINEAR);
+ SetTextureWrap(canvasBlurX.texture, TEXTURE_WRAP_CLAMP);
+
Shader blur = LoadShader(0, "blur.frag");
int blurRenderWidthLoc = GetShaderLocation(blur, "renderWidth");
int blurRenderHeightLoc = GetShaderLocation(blur, "renderHeight");
@@ -568,6 +572,11 @@ int main()
SetShaderValue(watershader, iResolutionLoc, &iResolution, SHADER_UNIFORM_VEC2);
SetShaderValueTexture(watershader, xWaterBumpMapLoc, waterbump);
+ Shader blur13 = LoadShader(0, "blur13.frag");
+ int blur13resolution = GetShaderLocation(blur13, "resolution");
+ int blur13direction = GetShaderLocation(blur13, "direction");
+ SetShaderValue(blur13, blur13resolution, &iResolution, SHADER_UNIFORM_VEC2);
+
GuiSetFont(InconsolataBold);
GuiSetStyle(DEFAULT, TEXT_SIZE, 24);
GuiSetStyle(DEFAULT, TEXT_SPACING, 0);
@@ -639,11 +648,12 @@ int main()
// Draw
//------------------------------------------------------------------
BeginDrawing();
- // Setup the back buffer for drawing (clear color and depth buffers)
- ClearBackground(WHITE);
BeginTextureMode(canvas);
+ // Setup the back buffer for drawing (clear color and depth buffers)
+ ClearBackground(MAGENTA);
+
drawMap();
drawPlayer();
drawBottomBar(InconsolataBold, 24);
@@ -699,6 +709,34 @@ int main()
DrawTextureRec(canvas.texture, rec, (Vector2) { 0.0f, 0.0f }, WATERBLUE);
}
EndShaderMode();
+
+
+ //BeginTextureMode(canvasBlurX);
+ //{
+ // BeginShaderMode(blur13);
+ // {
+ // BeginShaderMode(watershader);
+ // {
+ // Vector2 dir = { 0.25f, 0.0f };
+ // SetShaderValue(blur13, blur13direction, &dir, SHADER_UNIFORM_VEC2);
+ // SetShaderValueTexture(watershader, xWaterBumpMapLoc, waterbump);
+ // DrawTextureRec(canvas.texture, rec, (Vector2) { 0.0f, 0.0f }, WATERBLUE);
+ // }
+ // EndShaderMode();
+ // }
+ // EndShaderMode();
+ //}
+ //EndTextureMode();
+
+
+ //BeginShaderMode(blur13);
+ //{
+ // Vector2 dir = { 0.0f, 0.25f };
+ // SetShaderValue(blur13, blur13direction, &dir, SHADER_UNIFORM_VEC2);
+ // DrawTextureRec(canvasBlurX.texture, rec, (Vector2) { 0.0f, 0.0f }, WHITE);
+ //}
+ //EndShaderMode();
+
//drawBottomBar(InconsolataBold, 24);