structures, also they're a little broken, they need to check for neighbouring YZones as well
This commit is contained in:
parent
a0b00b0f1c
commit
d1abde919d
12 changed files with 604 additions and 134 deletions
|
|
@ -110,7 +110,8 @@ void main() {
|
|||
faceId = min(faceId, 7u);
|
||||
|
||||
vec3 localPos = vec3(voxelX, voxelY, voxelZ) + FACE_CORNERS[faceId][cornerIndex];
|
||||
vec3 worldPos = localPos + push_constants.ModelOffset.xyz * 16.0;
|
||||
vec3 Offset = vec3(0,0,0);
|
||||
vec3 worldPos = localPos + Offset + push_constants.ModelOffset.xyz * 16.0;
|
||||
|
||||
vec4 worldPosVec4 = vec4(worldPos, 1.0);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
#version 460 core
|
||||
|
||||
in vec3 FragPos;
|
||||
in vec2 TexCoords;
|
||||
in vec3 Normal;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec3 cameraPos;
|
||||
uniform vec3 lightPos;
|
||||
|
||||
// Material constants
|
||||
const vec3 waterShallowColor = vec3(0.0, 0.6, 0.7);
|
||||
const vec3 waterDeepColor = vec3(0.05, 0.15, 0.3);
|
||||
const vec3 sunColor = vec3(1.0, 0.95, 0.8);
|
||||
|
||||
void main() {
|
||||
// Normalize vectors
|
||||
vec3 n = normalize(Normal);
|
||||
vec3 viewDir = normalize(cameraPos - FragPos);
|
||||
vec3 lightDir = normalize(lightPos - FragPos);
|
||||
|
||||
// 1. Ambient Lighting
|
||||
vec3 ambient = 0.3 * waterShallowColor;
|
||||
|
||||
// 2. Diffuse Shading
|
||||
float diff = max(dot(n, lightDir), 0.0);
|
||||
vec3 diffuse = diff * sunColor * 0.4;
|
||||
|
||||
// 3. Specular Highlights (Blinn-Phong)
|
||||
vec3 halfwayDir = normalize(lightDir + viewDir);
|
||||
float spec = pow(max(dot(n, halfwayDir), 0.0), 64.0); // High shininess for water glaze
|
||||
vec3 specular = spec * sunColor * 0.8;
|
||||
|
||||
// 4. Fresnel Approximation (Schlick's approximation)
|
||||
// Water has a base reflectivity of roughly 0.02 at a perpendicular view angle
|
||||
float F0 = 0.02;
|
||||
float fresnel = F0 + (1.0 - F0) * pow(1.0 - max(dot(n, viewDir), 0.0), 5.0);
|
||||
|
||||
// Mix deep and shallow water colors based on the normal angle
|
||||
vec3 baseWaterColor = mix(waterShallowColor, waterDeepColor, max(dot(n, vec3(0.0, 1.0, 0.0)), 0.0));
|
||||
|
||||
// Combine lighting results
|
||||
vec3 lightingResult = ambient + diffuse + specular;
|
||||
|
||||
// Blend final look with Fresnel reflection dominance
|
||||
vec3 finalColor = mix(baseWaterColor + specular, lightingResult + vec3(fresnel * 0.5), fresnel);
|
||||
|
||||
// Output final color with subtle translucency opacity
|
||||
FragColor = vec4(finalColor, 0.85);
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
#version 450
|
||||
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec2 aTexCoords;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec2 TexCoords;
|
||||
out vec3 Normal;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
uniform float uTime;
|
||||
|
||||
// Wave configuration constants
|
||||
const float AMPLITUDE = 0.15;
|
||||
const float FREQUENCY = 1.5;
|
||||
const float SPEED = 2.0;
|
||||
|
||||
// Simple wave function that modifies elevation based on position and time
|
||||
float calculateWave(vec3 pos, float time, vec2 direction) {
|
||||
return AMPLITUDE * sin(dot(pos.xz, direction) * FREQUENCY + time * SPEED);
|
||||
}
|
||||
|
||||
// Derivative of the wave function to calculate accurate dynamic surface normals
|
||||
vec3 calculateWaveNormal(vec3 pos, float time) {
|
||||
float dx = AMPLITUDE * FREQUENCY * cos(pos.x * FREQUENCY + time * SPEED);
|
||||
float dz = AMPLITUDE * FREQUENCY * cos(pos.z * FREQUENCY + time * SPEED);
|
||||
return normalize(vec3(-dx, 1.0, -dz));
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec3 displacedPos = aPos;
|
||||
|
||||
// Combine two wave directions for a less predictable, more organic look
|
||||
displacedPos.y += calculateWave(aPos, uTime, vec2(1.0, 0.0));
|
||||
displacedPos.y += calculateWave(aPos, uTime * 1.2, vec2(0.5, 0.8));
|
||||
|
||||
FragPos = vec3(model * vec4(displacedPos, 1.0));
|
||||
TexCoords = aTexCoords;
|
||||
|
||||
// Pass transformed normals and position to the fragment shader
|
||||
Normal = mat3(transpose(inverse(model))) * calculateWaveNormal(displacedPos, uTime);
|
||||
|
||||
gl_Position = projection * view * model * vec4(displacedPos, 1.0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue