Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
Bugfix request - Jess
Browse files Browse the repository at this point in the history
  • Loading branch information
swr06 committed May 5, 2022
1 parent 1648b50 commit e09cf1a
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Source/Core/ChunkMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,14 @@ namespace Minecraft
}
}

if (type == BlockType::Water) {

v1.block_face_lighting = 85;
v2.block_face_lighting = 85;
v3.block_face_lighting = 85;
v4.block_face_lighting = 85;
}

// Get required texture coordinates

const std::array<uint16_t, 8>& TextureCoordinates = BlockDatabase::GetBlockTexture(type, face_type);
Expand Down
6 changes: 6 additions & 0 deletions Source/Core/Renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace Minecraft
{
m_DefaultChunkShader.SetInteger("u_ChunkX", chunk->p_Position.x);
m_DefaultChunkShader.SetInteger("u_ChunkZ", chunk->p_Position.z);
m_DefaultChunkShader.SetInteger("u_Transparent", 0);
m_DefaultChunkShader.SetInteger("u_VTransparent", 0);

chunk->GetChunkMesh()->p_VAO.Bind();
(glDrawElements(GL_TRIANGLES, floor(chunk->GetChunkMesh()->p_VerticesCount / 4) * 6, GL_UNSIGNED_INT, 0));
Expand All @@ -33,6 +35,8 @@ namespace Minecraft
{
m_DefaultChunkShader.SetInteger("u_ChunkX", chunk->p_Position.x);
m_DefaultChunkShader.SetInteger("u_ChunkZ", chunk->p_Position.z);
m_DefaultChunkShader.SetInteger("u_Transparent", 1);
m_DefaultChunkShader.SetInteger("u_VTransparent", 1);

chunk->GetChunkMesh()->p_TransparentVAO.Bind();
(glDrawElements(GL_TRIANGLES, floor(chunk->GetChunkMesh()->p_TransparentVerticesCount / 4) * 6, GL_UNSIGNED_INT, 0));
Expand All @@ -55,6 +59,8 @@ namespace Minecraft
m_DefaultChunkShader.SetInteger("u_CHUNK_SIZE_X", CHUNK_SIZE_X);
m_DefaultChunkShader.SetInteger("u_CHUNK_SIZE_Z", CHUNK_SIZE_Z);
m_DefaultChunkShader.SetFloat("u_SunPositionY", sun_position.y);
m_DefaultChunkShader.SetFloat("u_Time", glfwGetTime());
m_DefaultChunkShader.SetFloat("u_VertexTime", glfwGetTime());
m_DefaultChunkShader.SetVector4f("u_FogColor", FogColor); // WHITE FOG
}

Expand Down
102 changes: 101 additions & 1 deletion Source/Shaders/BlockRendererFrag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,68 @@ in vec2 v_TexCoord;
in vec4 v_TintColor;
in float v_SunlightIntensity;

in vec3 v_WorldPosition;

flat in int v_LightlevelRAW;

out vec4 o_Color;

uniform sampler2D u_Texture;
uniform vec4 u_FogColor;

uniform float u_Time;

uniform int u_Transparent;

vec3 SkyTint = vec3(151.0f, 183.0f, 245.0f) / 255.0f;

bool CompareVec3(vec3 v1, vec3 v2) {
float e = 0.01f;
return abs(v1.x - v2.x) < e && abs(v1.y - v2.y) < e && abs(v1.z - v2.z) < e;
}

void CalculateUV(vec3 world_pos, in vec3 normal, out vec2 uv)
{
const vec3 NORMAL_TOP = vec3(0.0f, 1.0f, 0.0f);
const vec3 NORMAL_BOTTOM = vec3(0.0f, -1.0f, 0.0f);
const vec3 NORMAL_FRONT = vec3(0.0f, 0.0f, 1.0f);
const vec3 NORMAL_BACK = vec3(0.0f, 0.0f, -1.0f);
const vec3 NORMAL_LEFT = vec3(-1.0f, 0.0f, 0.0f);
const vec3 NORMAL_RIGHT = vec3(1.0f, 0.0f, 0.0f);

if (CompareVec3(normal, NORMAL_TOP))
{
uv = vec2(fract(world_pos.xz));
}

else if (CompareVec3(normal, NORMAL_BOTTOM))
{
uv = vec2(fract(world_pos.xz));
}

else if (CompareVec3(normal, NORMAL_RIGHT))
{
uv = vec2(fract(world_pos.zy));
}

else if (CompareVec3(normal, NORMAL_LEFT))
{
uv = vec2(fract(world_pos.zy));
}

else if (CompareVec3(normal, NORMAL_FRONT))
{
uv = vec2(fract(world_pos.xy));
}

else if (CompareVec3(normal, NORMAL_BACK))
{
uv = vec2(fract(world_pos.xy));
}
}




vec3 RomBinDaHouseToneMapping(vec3 color)
{
Expand All @@ -19,10 +74,48 @@ vec3 RomBinDaHouseToneMapping(vec3 color)
return color;
}

vec4 GetWater(vec2 puv) {
vec4 texture_color = vec4(0.192156862745098, 0.6627450980392157, 0.9333333333333333, 1.0);
vec4 k = vec4(u_Time)*0.8;
k.xy = puv.xy * 7.0;
float val1 = length(0.5-fract(k.xyw*=mat3(vec3(-2.0,-1.0,0.0), vec3(3.0,-1.0,1.0), vec3(1.0,-1.0,-1.0))*0.5));
float val2 = length(0.5-fract(k.xyw*=mat3(vec3(-2.0,-1.0,0.0), vec3(3.0,-1.0,1.0), vec3(1.0,-1.0,-1.0))*0.2));
float val3 = length(0.5-fract(k.xyw*=mat3(vec3(-2.0,-1.0,0.0), vec3(3.0,-1.0,1.0), vec3(1.0,-1.0,-1.0))*0.5));
vec4 color = vec4 ( pow(min(min(val1,val2),val3), 5.0) * 3.0)+texture_color;
return color;
}

vec2 BasicTextureDistortion(vec2 UV) {
vec2 UVxy = UV.xy;
float time = u_Time;
UV.x += sin(time * 0.25f);
UV.y += pow(cos(time * 0.15f),2.);
UV.x += cos(UV.x*10.0f + time)*0.3f;
UV.y += sin(UV.y*5.0f + UV.x*4.0f + time*1.3f)*0.4f;
UV.xy = mix(UV.xy,UVxy.xy,0.91f);
return UV;
}

vec4 PixelArtFilter(sampler2D tex, vec2 uv)
{
vec2 res = vec2(textureSize(tex,0));
uv = uv*res;
vec2 seam = floor(uv+0.5);
uv = seam + clamp( (uv-seam)/fwidth(uv), -0.5, 0.5);
return texture(tex, uv/res);
}

vec2 HalfCorrection(int x, int y, int tex_width, int tex_height) {
float u = (x + 0.5) / tex_width;
float v = (y + 0.5) / tex_height;
return vec2(u, v);
}

void main()
{
const float threshhold = 0.1;
o_Color = texelFetch(u_Texture, ivec2(v_TexCoord.xy), 0) ;
//o_Color = PixelArtFilter(u_Texture, vec2(HalfCorrection(int(v_TexCoord.x), int(v_TexCoord.y), 3048, 64))) ;

o_Color.xyz = pow(o_Color.xyz, vec3(2.2));
o_Color *= v_TintColor;
Expand All @@ -34,6 +127,13 @@ void main()

o_Color = o_Color * vec4(v_SunlightIntensity, v_SunlightIntensity, v_SunlightIntensity, 1.0f) ;
o_Color.xyz = mix(o_Color.xyz * 1.1f, o_Color.xyz * 1.1 * SkyTint.xyz, 0.65f);
o_Color = mix(u_FogColor, o_Color, v_Visibility);


// water
if (v_LightlevelRAW > 84 && u_Transparent == 1) {
}

o_Color = mix(vec4(pow(u_FogColor.xyz, vec3(1.75)), u_FogColor.w), o_Color, v_Visibility);
o_Color = vec4(RomBinDaHouseToneMapping(o_Color.xyz), o_Color.w);

}
31 changes: 30 additions & 1 deletion Source/Shaders/BlockRendererVertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,41 @@ out float v_Visibility; // For implementing fog
out vec2 v_TexCoord;
out vec4 v_TintColor;
out float v_SunlightIntensity;
flat out int v_LightlevelRAW;
out vec3 v_WorldPosition;

const float fog_density = 0.01f;
float fog_gradient = 4.0f;

uniform float u_VertexTime;
uniform int u_VTransparent;

float WavingWater(vec3 worldPos)
{
float frametime = 1.0f * u_VertexTime;

float fractY = fract(worldPos.y + 0.005);

float wave = sin(6.28 * (frametime * 0.7 + worldPos.x * 0.14 + worldPos.z * 0.07)) +
sin(6.28 * (frametime * 0.5 + worldPos.x * 0.10 + worldPos.z * 0.20));

if (fractY > 0.01)
{
return wave * 0.0125;
}

return 0.0;
}

void main()
{
vec3 real_pos = vec3(a_Position.x + (u_ChunkX * u_CHUNK_SIZE_X), a_Position.y, a_Position.z + (u_ChunkZ * u_CHUNK_SIZE_Z));
v_WorldPosition = real_pos;

if (u_VTransparent == 1 && a_BlockFaceLightLevel > 83) {
real_pos.y -= 0.21f;
real_pos.y += WavingWater(real_pos * 1.5) * 10.0f;
}

// Calculate fog
vec4 relative_camera_pos = u_ViewMatrix * vec4(real_pos, 1.0f);
Expand All @@ -40,7 +67,7 @@ void main()
lighting_level *= lighting_level;
lighting_level *= 2.0f;

float block_light = float(a_BlockFaceLightLevel);
float block_light = a_BlockFaceLightLevel < 16.0f ? float(a_BlockFaceLightLevel) : 10.0f;
block_light /= 10.0f;

v_SunlightIntensity = max(u_SunPositionY / 1000.0f, 0.6f);
Expand All @@ -66,6 +93,8 @@ void main()
}
}

v_LightlevelRAW = int(a_BlockFaceLightLevel);

gl_Position = u_ViewProjection * vec4(real_pos, 1.0);
v_TexCoord = vec2(a_TexCoords.xy);
}
2 changes: 1 addition & 1 deletion Source/Shaders/ModelRendererFrag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void main()
vec3 SkyTint = vec3(151.0f, 183.0f, 245.0f) / 255.0f;
o_Color.xyz = mix(o_Color.xyz * 1.1f, o_Color.xyz * 1.1 * SkyTint.xyz, 0.65f);

o_Color = mix(u_FogColor, o_Color, v_Visibility);
o_Color = mix(vec4(pow(u_FogColor.xyz, vec3(1.6)), u_FogColor.w), o_Color, v_Visibility);

o_Color = vec4(RomBinDaHouseToneMapping(o_Color.xyz), o_Color.w);
}

0 comments on commit e09cf1a

Please sign in to comment.