1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Fix stuff and slight changes

This commit is contained in:
Gefüllte Taubenbrust 2024-09-25 21:45:13 +02:00
parent 71e648a776
commit da1a688493
3 changed files with 12 additions and 44 deletions

View file

@ -59,7 +59,7 @@ varying highp vec3 eyeVec;
varying float nightRatio; varying float nightRatio;
#ifdef ENABLE_DYNAMIC_SHADOWS #ifdef ENABLE_DYNAMIC_SHADOWS
#if (defined(MATERIAL_WAVING_LIQUID) && defined(ENABLE_WATER_REFLECTIONS) && ENABLE_WAVING_WATER) #if ((defined(MATERIAL_WAVING_LIQUID) && defined(ENABLE_WATER_REFLECTIONS) && ENABLE_WAVING_WATER) || defined(ENABLE_BUMPMAPS))
vec4 perm(vec4 x) vec4 perm(vec4 x)
{ {
return mod(((x * 34.0) + 1.0) * x, 289.0); return mod(((x * 34.0) + 1.0) * x, 289.0);
@ -103,36 +103,6 @@ vec2 wave_noise(vec3 p, float off) {
} }
#endif #endif
#ifdef ENABLE_BUMPMAPS
vec4 perm(vec4 x)
{
return mod(((x * 34.0) + 1.0) * x, 289.0);
}
float snoise(vec3 p)
{
vec3 a = floor(p);
vec3 d = p - a;
d = d * d * (3.0 - 2.0 * d);
vec4 b = a.xxyy + vec4(0.0, 1.0, 0.0, 1.0);
vec4 k1 = perm(b.xyxy);
vec4 k2 = perm(k1.xyxy + b.zzww);
vec4 c = k2 + a.zzzz;
vec4 k3 = perm(c);
vec4 k4 = perm(c + 1.0);
vec4 o1 = fract(k3 * (1.0 / 41.0));
vec4 o2 = fract(k4 * (1.0 / 41.0));
vec4 o3 = o2 * d.z + o1 * (1.0 - d.z);
vec2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x);
return o4.y * d.y + o4.x * (1.0 - d.y);
}
#endif
// assuming near is always 1.0 // assuming near is always 1.0
float getLinearDepth() float getLinearDepth()
{ {
@ -474,17 +444,19 @@ void main(void)
// Fragment normal, can differ from vNormal which is derived from vertex normals. // Fragment normal, can differ from vNormal which is derived from vertex normals.
vec3 fNormal = vNormal; vec3 fNormal = vNormal;
#if ((defined(ENABLE_DYNAMIC_SHADOWS) && defined(ENABLE_BUMPMAPS)) && !defined(MATERIAL_LIQUID))
vec2 dr = vec2(0.25) * texelSize0; vec2 dr = vec2(0.25) * texelSize0;
// Sample the texture to then compute the derivative // Sample the texture to then compute the gradient
float fx0y0 = texture2D(baseTexture, uv).r; float fx0y0 = texture2D(baseTexture, uv).r;
float fx1y0 = texture2D(baseTexture, uv + vec2(dr.x, 0.0)).r; float fx1y0 = texture2D(baseTexture, uv + vec2(dr.x, 0.0)).r;
float fx0y1 = texture2D(baseTexture, uv + vec2(0.0, dr.y)).r; float fx0y1 = texture2D(baseTexture, uv + vec2(0.0, dr.y)).r;
vec2 gradient = 0.2 * vec2((fx1y0 - fx0y0) / dr.x, (fx0y1 - fx0y0) / dr.y) + 0.1 * gnoise(vec3(2.0 * uv / texelSize0, 0.0)).xy;
// Compute a set of orthogonal basis vectors representing the node's surface plane. // Compute a set of orthogonal basis vectors representing the node's surface plane.
vec3 orth1 = normalize(cross(vNormal, mix(vec3(0.0, -1.0, 0.0), vec3(0.0, 0.0, -1.0), step(0.9, abs(vNormal.y))))); vec3 orth1 = normalize(cross(vNormal, mix(vec3(0.0, -1.0, 0.0), vec3(0.0, 0.0, -1.0), step(0.9, abs(vNormal.y)))));
vec3 orth2 = normalize(cross(vNormal, orth1)); vec3 orth2 = normalize(cross(vNormal, orth1));
// The normal is computed using the partial derivatives along the texture space x and y axes. // The normal is computed using the partial derivatives along the texture space x and y axes.
// These axes in world space are assumed to be parallel to the basis vectors we defined before. // These axes in world space are assumed to be parallel to the basis vectors we defined before.
fNormal = normalize(vNormal + (orth1 * (fx1y0 - fx0y0) / dr.x + orth2 * (fx0y1 - fx0y0) / dr.y) * 0.25 * snoise(vec3(uv / texelSize0, 0.0))); fNormal = normalize(vNormal + orth1 * gradient.x + orth2 * gradient.y);
float adj_cosLight = max(1e-5, dot(fNormal, -v_LightDirection)); float adj_cosLight = max(1e-5, dot(fNormal, -v_LightDirection));
#else #else
float adj_cosLight = cosLight; float adj_cosLight = cosLight;
@ -578,7 +550,7 @@ void main(void)
// Sky reflection // Sky reflection
col.rgb += reflection_color * pow(fresnel_factor, 2.0) * 0.5 * brightness_factor; col.rgb += reflection_color * pow(fresnel_factor, 2.0) * 0.5 * brightness_factor;
vec3 water_reflect_color = 12.0 * dayLight * fresnel_factor * mtsmoothstep(0.85, 0.9, pow(clamp(dot(reflect_ray, viewVec), 0.0, 1.0), 32.0)) * max(1.0 - shadow_uncorrected, 0.0); vec3 water_reflect_color = 12.0 * sunTint * dayLight * fresnel_factor * mtsmoothstep(0.85, 0.9, pow(clamp(dot(reflect_ray, viewVec), 0.0, 1.0), 32.0)) * max(1.0 - shadow_uncorrected, 0.0);
// This line exists to prevent ridiculously bright reflection colors. // This line exists to prevent ridiculously bright reflection colors.
water_reflect_color /= clamp(max(water_reflect_color.r, max(water_reflect_color.g, water_reflect_color.b)) * 0.375, 1.0, 400.0); water_reflect_color /= clamp(max(water_reflect_color.r, max(water_reflect_color.g, water_reflect_color.b)) * 0.375, 1.0, 400.0);
@ -593,7 +565,7 @@ void main(void)
const float fresnel_exponent = 4.0; const float fresnel_exponent = 4.0;
col.rgb += col.rgb +=
intensity * dayLight * (1.0 - nightRatio) * (1.0 - shadow_uncorrected) * f_adj_shadow_strength * sunTint * intensity * dayLight * (1.0 - nightRatio) * (1.0 - shadow_uncorrected) * f_adj_shadow_strength *
pow(max(dot(reflect_ray, viewVec), 0.0), fresnel_exponent) * pow(1.0 - abs(dot(viewVec, fNormal)), specular_exponent); pow(max(dot(reflect_ray, viewVec), 0.0), fresnel_exponent) * pow(1.0 - abs(dot(viewVec, fNormal)), specular_exponent);
} }
#endif #endif

View file

@ -247,7 +247,7 @@ void Clouds::updateMesh()
case 1: // back case 1: // back
if (INAREA(xi, zi - 1, m_cloud_radius_i)) { if (INAREA(xi, zi - 1, m_cloud_radius_i)) {
u32 j = GETINDEX(xi, zi - 1, m_cloud_radius_i); u32 j = GETINDEX(xi, zi - 1, m_cloud_radius_i);
if (grid[j]) if (m_grid[j])
continue; continue;
} }
if (soft_clouds_enabled) { if (soft_clouds_enabled) {
@ -270,7 +270,7 @@ void Clouds::updateMesh()
case 2: //right case 2: //right
if (INAREA(xi + 1, zi, m_cloud_radius_i)) { if (INAREA(xi + 1, zi, m_cloud_radius_i)) {
u32 j = GETINDEX(xi + 1, zi, m_cloud_radius_i); u32 j = GETINDEX(xi + 1, zi, m_cloud_radius_i);
if (grid[j]) if (m_grid[j])
continue; continue;
} }
if (soft_clouds_enabled) { if (soft_clouds_enabled) {
@ -294,7 +294,7 @@ void Clouds::updateMesh()
case 3: // front case 3: // front
if (INAREA(xi, zi + 1, m_cloud_radius_i)) { if (INAREA(xi, zi + 1, m_cloud_radius_i)) {
u32 j = GETINDEX(xi, zi + 1, m_cloud_radius_i); u32 j = GETINDEX(xi, zi + 1, m_cloud_radius_i);
if (grid[j]) if (m_grid[j])
continue; continue;
} }
if (soft_clouds_enabled) { if (soft_clouds_enabled) {
@ -317,7 +317,7 @@ void Clouds::updateMesh()
case 4: // left case 4: // left
if (INAREA(xi - 1, zi, m_cloud_radius_i)) { if (INAREA(xi - 1, zi, m_cloud_radius_i)) {
u32 j = GETINDEX(xi - 1, zi, m_cloud_radius_i); u32 j = GETINDEX(xi - 1, zi, m_cloud_radius_i);
if (grid[j]) if (m_grid[j])
continue; continue;
} }
if (soft_clouds_enabled) { if (soft_clouds_enabled) {

View file

@ -536,10 +536,6 @@ public:
float camera_far = m_client->getCamera()->getCameraNode()->getFarValue(); float camera_far = m_client->getCamera()->getCameraNode()->getFarValue();
m_camera_far_pixel.set(&camera_far, services); m_camera_far_pixel.set(&camera_far, services);
v3f camera_position = m_client->getCamera()->getPosition();
m_camera_position_pixel.set(camera_position, services);
m_camera_position_pixel.set(camera_position, services);
SamplerLayer_t tex_id; SamplerLayer_t tex_id;
tex_id = 0; tex_id = 0;
m_texture0.set(&tex_id, services); m_texture0.set(&tex_id, services);
@ -1592,7 +1588,7 @@ bool Game::createClient(const GameStartData &start_data)
*/ */
if (m_cache_enable_clouds) if (m_cache_enable_clouds)
clouds = make_irr<Clouds>(smgr, shader_src, -1, rand()); clouds = make_irr<Clouds>(smgr, shader_src, -1, rand());
client->setClouds(clouds); client->setClouds(clouds.get());
/* Skybox /* Skybox
*/ */