Skip to content

Commit

Permalink
Episode 4 - Water
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanatorM committed Oct 18, 2024
1 parent 117e2c3 commit 4e1c4fe
Show file tree
Hide file tree
Showing 22 changed files with 1,016 additions and 307 deletions.
11 changes: 9 additions & 2 deletions ScuffedMinecraft/ScuffedMinecraft.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
<ClInclude Include="src\Planet.h" />
<ClInclude Include="src\Shader.h" />
<ClInclude Include="src\SurfaceFeature.h" />
<ClInclude Include="src\Vertex.h" />
<ClInclude Include="vendor\imgui\imconfig.h" />
<ClInclude Include="vendor\imgui\imgui.h" />
<ClInclude Include="vendor\imgui\imgui_impl_glfw.h" />
Expand All @@ -193,8 +194,14 @@
<ClInclude Include="vendor\stb_image.h" />
</ItemGroup>
<ItemGroup>
<None Include="assets\shaders\fragment_shader.glsl" />
<None Include="assets\shaders\vertex_shader.glsl" />
<None Include="assets\shaders\billboard_frag.glsl" />
<None Include="assets\shaders\billboard_vert.glsl" />
<None Include="assets\shaders\framebuffer_frag.glsl" />
<None Include="assets\shaders\framebuffer_vert.glsl" />
<None Include="assets\shaders\main_frag.glsl" />
<None Include="assets\shaders\main_vert.glsl" />
<None Include="assets\shaders\water_frag.glsl" />
<None Include="assets\shaders\water_vert.glsl" />
</ItemGroup>
<ItemGroup>
<Image Include="assets\sprites\block_map.png" />
Expand Down
13 changes: 11 additions & 2 deletions ScuffedMinecraft/ScuffedMinecraft.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,19 @@
<ClInclude Include="src\SurfaceFeature.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Vertex.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="assets\shaders\vertex_shader.glsl" />
<None Include="assets\shaders\fragment_shader.glsl" />
<None Include="assets\shaders\main_vert.glsl" />
<None Include="assets\shaders\main_frag.glsl" />
<None Include="assets\shaders\water_frag.glsl" />
<None Include="assets\shaders\water_vert.glsl" />
<None Include="assets\shaders\billboard_vert.glsl" />
<None Include="assets\shaders\billboard_frag.glsl" />
<None Include="assets\shaders\framebuffer_vert.glsl" />
<None Include="assets\shaders\framebuffer_frag.glsl" />
</ItemGroup>
<ItemGroup>
<Image Include="assets\sprites\block_map.png">
Expand Down
27 changes: 27 additions & 0 deletions ScuffedMinecraft/assets/shaders/billboard_frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#version 330 core

in vec2 TexCoord;

out vec4 FragColor;

uniform sampler2D tex;

const vec3 ambient = vec3(.5);
const vec3 lightDirection = vec3(0.8, 1, 0.7);

const vec3 normal = vec3( 0, -1, 0);

void main()
{
vec3 lightDir = normalize(-lightDirection);

float diff = max(dot(normal, lightDir), 0.0);
vec3 diffuse = diff * vec3(1);

vec4 result = vec4(ambient + diffuse, 1.0);

vec4 texResult = texture(tex, TexCoord);
if (texResult.a == 0)
discard;
FragColor = texResult * result;
}
19 changes: 19 additions & 0 deletions ScuffedMinecraft/assets/shaders/billboard_vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#version 330 core

layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoord;

out vec2 TexCoord;
out vec3 Normal;

uniform float texMultiplier;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main()
{
gl_Position = projection * view * model * vec4(aPos, 1.0);
TexCoord = aTexCoord * texMultiplier;
}
32 changes: 32 additions & 0 deletions ScuffedMinecraft/assets/shaders/framebuffer_frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#version 330 core

out vec4 FragColor;
in vec2 TexCoords;

uniform sampler2D screenTexture;
uniform sampler2D depthTexture;

uniform bool underwater;

const vec3 fogColor = vec3(0, 0, 0.25);
const float fogNear = 0.9;
const float fogFar = 1.0;

void main()
{
vec3 color = texture(screenTexture, TexCoords).rgb;
float depth = texture(depthTexture, TexCoords).r;

vec3 finalColor = color;

// Calculate fog
if (underwater)
{
float fogFactor = (fogFar - depth) / (fogFar - fogNear);
fogFactor = clamp(fogFactor, 0.0, 1.0);

finalColor = mix(fogColor, color, fogFactor);
}

FragColor = vec4(vec3(finalColor), 1.0);
}
12 changes: 12 additions & 0 deletions ScuffedMinecraft/assets/shaders/framebuffer_vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 330 core

layout (location = 0) in vec2 inPos;
layout (location = 1) in vec2 inTexCoords;

out vec2 TexCoords;

void main()
{
gl_Position = vec4(inPos.x, inPos.y, 0.0, 1.0);
TexCoords = inTexCoords;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#version 330 core


layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoord;
layout (location = 2) in int aDirection;
Expand All @@ -13,6 +12,7 @@ uniform float texMultiplier;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform float time;

// Array of possible normals based on direction
const vec3 normals[] = vec3[](
Expand Down
26 changes: 26 additions & 0 deletions ScuffedMinecraft/assets/shaders/water_frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#version 330 core

in vec2 TexCoord;
in vec3 Normal;

out vec4 FragColor;

uniform sampler2D tex;

vec3 ambient = vec3(.5);
vec3 lightDirection = vec3(0.8, 1, 0.7);

void main()
{
vec3 lightDir = normalize(-lightDirection);

float diff = max(dot(Normal, lightDir), 0.0);
vec3 diffuse = diff * vec3(1);

vec4 result = vec4(ambient + diffuse, 1.0);

vec4 texResult = texture(tex, TexCoord);
if (texResult.a == 0)
discard;
FragColor = texResult * result;
}
47 changes: 47 additions & 0 deletions ScuffedMinecraft/assets/shaders/water_vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#version 330 core

layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoord;
layout (location = 2) in int aDirection;
layout (location = 3) in int aTop;

out vec2 TexCoord;
out vec3 Normal;

uniform float texMultiplier;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform float time;

// Array of possible normals based on direction
const vec3 normals[] = vec3[](
vec3( 0, 0, 1), // 0
vec3( 0, 0, -1), // 1
vec3( 1, 0, 0), // 2
vec3(-1, 0, 0), // 3
vec3( 0, 1, 0), // 4
vec3( 0, -1, 0), // 5
vec3( 0, -1, 0) // 6
);

const int aFrames = 32;
const float animationTime = 5;
const int texNum = 16;
void main()
{
vec3 pos = aPos;
if (aTop == 1)
{
pos.y -= .1;
pos.y += (sin(pos.x * 3.1415926535 / 2 + time) + sin(pos.z * 3.1415926535 / 2 + time * 1.5)) * .05;
}
gl_Position = projection * view * model * vec4(pos, 1.0);
vec2 currentTex = aTexCoord;
currentTex.x += mod(floor(mod(time / animationTime, 1) * aFrames), texNum);
currentTex.y += floor(floor(mod(time / animationTime, 1) * aFrames) / texNum);
TexCoord = currentTex * texMultiplier;

Normal = normals[aDirection];
}
Binary file modified ScuffedMinecraft/assets/sprites/block_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ScuffedMinecraft/assets/sprites/block_map.psd
Binary file not shown.
Loading

0 comments on commit 4e1c4fe

Please sign in to comment.