mirror of
https://github.com/Kaehvaman/OAIP.git
synced 2025-01-30 16:58:26 +04:00
finish watershader
This commit is contained in:
parent
4dd9bf6d5a
commit
2ca2ecae6a
@ -104,7 +104,7 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\include</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\resources</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@ -121,7 +121,7 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\include</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\resources</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
@ -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);
|
||||
}
|
28
lab16 with raylib/resources/blur13.frag
Normal file
28
lab16 with raylib/resources/blur13.frag
Normal file
@ -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;
|
||||
}
|
@ -8,45 +8,39 @@ 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;
|
||||
|
||||
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);
|
||||
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;
|
||||
|
||||
|
@ -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);
|
||||
@ -700,6 +710,34 @@ int main()
|
||||
}
|
||||
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);
|
||||
|
||||
//DrawTextureRec(canvas.texture, rec, (Vector2) { 0.0f, 0.0f }, SKYBLUE);
|
||||
|
Loading…
Reference in New Issue
Block a user