Skip to content

Commit

Permalink
fix csm; readjust water waves
Browse files Browse the repository at this point in the history
  • Loading branch information
null511 committed Oct 11, 2022
1 parent d1f0538 commit 3083758
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 22 deletions.
8 changes: 4 additions & 4 deletions shaders/lib/common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ const bool colortex12Clear = false;
#define WATER_FANCY
#define WATER_REFRACTION 1 // [0 1 2]
#define WATER_WAVE_TYPE 2 // [0 1 2]
#define WATER_SCALE 16.0
#define WATER_SCALE 18.0
#define WATER_RADIUS 50
#define WATER_OCTAVES_NEAR 64
#define WATER_OCTAVES_FAR 16
#define WATER_OCTAVES_NEAR 48
#define WATER_OCTAVES_FAR 24
#define WATER_OCTAVES_VERTEX 8
#define WATER_PARALLAX_DEPTH 0.03
#define WATER_PARALLAX_DEPTH 0.02
#define WATER_PARALLAX_SAMPLES 64
#define WATER_WAVE_DEPTH 1.0
#define WATER_RESOLUTION 2048
Expand Down
20 changes: 15 additions & 5 deletions shaders/lib/lighting/pbr.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
viewTangent = normalize(gl_NormalMatrix * at_tangent.xyz);
tangentW = at_tangent.w;

#ifdef PARALLAX_ENABLED
#if defined PARALLAX_ENABLED || (WATER_WAVE_TYPE == WATER_WAVE_PARALLAX && (defined RENDER_WATER || defined RENDER_HAND_WATER))
vec3 viewBinormal = normalize(cross(viewTangent, viewNormal) * at_tangent.w);
mat3 matTBN = mat3(viewTangent, viewBinormal, viewNormal);

Expand Down Expand Up @@ -215,10 +215,20 @@
// float opaqueShadowDepth = SampleDepth(lightData.shadowPos, vec2(0.0));
// #endif

if (
lightData.shadowPos.x > 0.0 && lightData.shadowPos.x < 1.0 &&
lightData.shadowPos.y > 0.0 && lightData.shadowPos.y < 1.0
) {
#if SHADOW_TYPE == SHADOW_TYPE_CASCADED
bool isInBounds = false;
for (int i = 0; i < 4 && !isInBounds; i++) {
isInBounds =
lightData.shadowPos[i].x > 0.0 && lightData.shadowPos[i].x < 1.0 &&
lightData.shadowPos[i].y > 0.0 && lightData.shadowPos[i].y < 1.0;
}
#else
bool isInBounds =
lightData.shadowPos.x > 0.0 && lightData.shadowPos.x < 1.0 &&
lightData.shadowPos.y > 0.0 && lightData.shadowPos.y < 1.0;
#endif

if (isInBounds) {
if (shadow > EPSILON)
shadow *= GetShadowing(lightData);

Expand Down
8 changes: 4 additions & 4 deletions shaders/lib/lighting/pbr_forward.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
lightData.sunTransmittanceEye = GetSunTransmittance(colortex9, eyeAltitude, skyLightLevels.x);// * sunColor;
#endif

#ifdef PARALLAX_ENABLED
#if defined PARALLAX_ENABLED || WATER_WAVE_TYPE == WATER_WAVE_PARALLAX
vec3 tanViewDir = normalize(tanViewPos);
#endif

Expand Down Expand Up @@ -124,8 +124,8 @@

float waterScale = WATER_SCALE * rcp(2.0*WATER_RADIUS);
vec2 waterWorldPos = waterScale * (localPos.xz + cameraPosition.xz);
vec2 waterWorldPosX = waterWorldPos + vec2(1.0, 0.0)*waterPixelSize;
vec2 waterWorldPosY = waterWorldPos + vec2(0.0, 1.0)*waterPixelSize;
vec2 waterWorldPosX = waterWorldPos + vec2(1.0, 0.0)*0.01;
vec2 waterWorldPosY = waterWorldPos + vec2(0.0, 1.0)*0.01;

float skyLight = saturate((lmcoord.y - (0.5/16.0)) / (15.0/16.0));

Expand All @@ -134,7 +134,7 @@
depth = GetWaves(waterWorldPos, waveSpeed, octaves);
depthX = GetWaves(waterWorldPosX, waveSpeed, octaves);
depthY = GetWaves(waterWorldPosY, waveSpeed, octaves);
zScale *= 0.2*WATER_SCALE;
zScale *= 0.04*WATER_SCALE;

#if WATER_WAVE_TYPE == WATER_WAVE_PARALLAX
}
Expand Down
4 changes: 2 additions & 2 deletions shaders/lib/world/water.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ float GetWaves(inout vec2 position, const in float waveSpeed, const in int itera
accumWeight += waveDX.x * weight;
maxWeight += weight;

weight = mix(weight, 0.0, 0.2);
weight = mix(weight, 0.0, 0.18);

iter += 0.9*i;//12.0;
iter += 12.0;
phase *= 1.18;
speed *= 1.07;
}
Expand Down
2 changes: 1 addition & 1 deletion shaders/program/final.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ out vec3 outColor0;
vec2 tileTex = texcoord * (tileMax - tileMin) + tileMin;
tileTex = clamp(tileTex, tileMin, tileMax);

bloom += textureLod(BUFFER_BLOOM, tileTex, 0).rgb;// * exp2(i);
bloom += textureLod(BUFFER_BLOOM, tileTex, 0).rgb;
}

bloom *= (0.01 * BLOOM_STRENGTH);
Expand Down
2 changes: 1 addition & 1 deletion shaders/program/gbuffers_hand_water.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ flat in mat2 atlasBounds;
flat in float matEmissive;
#endif

#ifdef PARALLAX_ENABLED
#if defined PARALLAX_ENABLED || WATER_WAVE_TYPE == WATER_WAVE_PARALLAX
in vec2 localCoord;
in vec3 tanViewPos;

Expand Down
4 changes: 2 additions & 2 deletions shaders/program/gbuffers_hand_water.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ flat out mat2 atlasBounds;
flat out float matEmissive;
#endif

#ifdef PARALLAX_ENABLED
#if defined PARALLAX_ENABLED || WATER_WAVE_TYPE == WATER_WAVE_PARALLAX
out vec2 localCoord;
out vec3 tanViewPos;

Expand Down Expand Up @@ -90,7 +90,7 @@ in vec3 vaPosition;
in vec4 at_tangent;
in vec3 at_midBlock;

#if defined PARALLAX_ENABLED || defined AF_ENABLED
#if defined PARALLAX_ENABLED || WATER_WAVE_TYPE == WATER_WAVE_PARALLAX || defined AF_ENABLED
in vec4 mc_midTexCoord;
#endif

Expand Down
2 changes: 1 addition & 1 deletion shaders/program/gbuffers_water.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ flat in mat2 atlasBounds;
flat in float matEmissive;
#endif

#ifdef PARALLAX_ENABLED
#if defined PARALLAX_ENABLED || WATER_WAVE_TYPE == WATER_WAVE_PARALLAX
in vec2 localCoord;
in vec3 tanViewPos;

Expand Down
4 changes: 2 additions & 2 deletions shaders/program/gbuffers_water.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ flat out mat2 atlasBounds;
flat out float matEmissive;
#endif

#ifdef PARALLAX_ENABLED
#if defined PARALLAX_ENABLED || WATER_WAVE_TYPE == WATER_WAVE_PARALLAX
out vec2 localCoord;
out vec3 tanViewPos;

Expand Down Expand Up @@ -90,7 +90,7 @@ in vec3 vaPosition;
in vec4 at_tangent;
in vec3 at_midBlock;

#if defined PARALLAX_ENABLED || defined AF_ENABLED
#if defined PARALLAX_ENABLED || WATER_WAVE_TYPE == WATER_WAVE_PARALLAX || defined AF_ENABLED
in vec4 mc_midTexCoord;
#endif

Expand Down

0 comments on commit 3083758

Please sign in to comment.