@@ -72,25 +72,24 @@ const float shadowIntervalSize = 0.0f;
7272
7373// Texture targets clear settings
7474const bool colortex8Clear = false;
75- const vec4 shadowcolor0ClearColor = vec4 (0.0 , 0.0 , 0.0 , 5 .0 );
75+ const vec4 shadowcolor0ClearColor = vec4 (0.0 , 0.0 , 0.0 , 1 .0 );
7676
7777// Texture formats
7878/*
79- const int shadowcolor0Format = RGBA16F; // Reflection color
79+ const int shadowcolor0Format = RGBA; // Reflection color
8080const int shadowcolor1Format = RGBA; // Reflection mask (is water in reflection)
8181const int colortex0Format = RGBA; // Scene color
8282const int colortex1Format = RGBA32F; // Position of water blocks in model space
83- const int colortex2Format = RGBA; // Scene normal (encoded and in world space)
83+ const int colortex2Format = RGBA; // Scene normals (encoded and in world space)
8484const int colortex3Format = RGBA16F; // Water mask
85- const int colortex4Format = RGBA ; // -
85+ const int colortex4Format = RGBA16F ; // Cloud mask
8686const int colortex5Format = RGBA; // Ice mask
8787const int colortex6Format = RGBA16F; // Glass mask
8888const int colortex7Format = RGBA; // Lightmap color
8989const int colortex8Format = RGBA; // Sun and moon textures
9090const int colortex9Format = RGBA; // Water color
9191const int colortex10Format = RGBA; // Terrain mask
92- const int colortex11Format = RGBA; // Water tiling
93- const int colortex12Format = RGBA16F; // Cloud mask
92+ const int colortex11Format = RGBA; // Water tiling
9493*/
9594
9695// Constant variables for water shader
@@ -100,11 +99,11 @@ const vec4 necrowizzardUnderwaterFogColorDay = vec4(0.03, 0.05, 0.12, 0.99);
10099const vec4 superbomb17UnderwaterFogColorDay = vec4 (0.03 , 0.05 , 0.12 , 0.99 ); // Superbomb17 fog color when underwater (daytime)
101100const vec4 underwaterFogColorNight = vec4 (0.02 , 0.13 , 0.24 , 0.9 ); // Fog color when underwater (nighttime)
102101const float waterSurfaceTransparency = 0.35 ; // Water surface/texture transparency
102+ const float waterBlendFactor = 0.30 ; // How much to blend flowing water to scene
103103const float waterClipPlane = 1.0 ; // Delete vertices too close from water surface
104104const float eyeCameraOffset = 1.68 ; // Eye camera offset from player's feet
105105const float waterBlockOffset = 1.005 ; // Water block clipping plane height (inside block)
106106const int lowerWorldBound = - 64 ; // Lowest possible water reflection plane height (Minecraft minimum block height)
107- const float waterBlendFactor = 0.30 ; // How much to blend flowing water to scene
108107
109108// Fog constants
110109const int GL_LINEAR = 9729 ;
@@ -114,10 +113,10 @@ const int GL_EXP2 = 2049;
114113// Custom uniforms
115114uniform vec2 iresolution;
116115
117- #define INFO 0 // [0]
116+ #define INFO 0 // Shader version [0]
118117#define STYLE 1 // Water surface style [1 2]
119118#define PLANES 1 // Reflection planes allowed [1 2 3 4]
120- #define SKYTEXTURED 2 // Sun & moon reflection [1 2 ]
119+ #define SKYTEXTURED 0 // Sun & moon reflection [0 1 ]
121120
122121// Shader Storage Buffer Object for water information in player view
123122layout (std430, binding = 0 ) buffer SSBOWaterShader {
@@ -152,6 +151,7 @@ vec4 getUnderwaterDaytimeWaterColor() {
152151 #endif
153152}
154153
154+ // ---------------- Encoding ----------------
155155vec3 encodeNormal(vec3 normal) {
156156 return (normal + 1.0 ) / 2.0 ;
157157}
@@ -160,6 +160,23 @@ vec3 decodeNormal(vec3 normal) {
160160 return (normal * 2.0 ) - 1.0 ;
161161}
162162
163+ int YToArray(int Y) {
164+ return Y + 64 ;
165+ }
166+
167+ int ArrayToY(int index) {
168+ return index - 64 ;
169+ }
170+
171+ // ---------------- World ----------------
172+ vec3 getWorldPositionFromModelPosition(vec4 modelPos) {
173+ dvec3 viewPos = (gbufferModelView * modelPos).xyz;
174+ dvec3 eyePlayerPos = mat3 (gbufferModelViewInverse) * viewPos;
175+ dvec3 worldPos = eyePlayerPos + cameraPosition + gbufferModelViewInverse[3 ].xyz;
176+
177+ return vec3 (worldPos);
178+ }
179+
163180vec2 reproject(vec2 uv, float depth) {
164181 /* Find uv coordinate of the pixel in previous frame */
165182 vec4 frag = gbufferProjectionInverse * vec4 (vec3 (uv, depth) * 2.0 - 1.0 , 1.0 );
@@ -173,13 +190,8 @@ vec2 reproject(vec2 uv, float depth) {
173190 return prevPos.xy / prevPos.w * 0.5 + 0.5 ;
174191}
175192
193+ // ---------------- Textures ----------------
176194bool isWithinTexture(vec2 uv) {
177195 // Is uv within texture bounds
178196 return uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0 ;
179197}
180-
181- float linearizeDepth(float depth) {
182- // Implemetation from: LearnOpenGL
183- float z = depth * 2.0 - 1.0 ; // back to NDC
184- return ((2.0 * near * far) / (far + near - z * (far - near))) / far;
185- }
0 commit comments