Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update multisplat16.shader #301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions addons/zylann.hterrain/shaders/multisplat16.shader
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ uniform bool u_depth_blending = true;
uniform float u_globalmap_blend_start;
uniform float u_globalmap_blend_distance;
uniform bool u_tile_reduction = false;
uniform float low_edge = 0.1;
uniform float smoothness = 0.2;
uniform float height_boost = 0.1;
Copy link
Owner

@Zylann Zylann Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should respect naming convention, uniforms start with u_ (I wish I could use _ only but Godot reserves that).
Also I have no idea what these do just from the name. I see they all affect how textures are blended (when depth blending is on) but their name alone doesnt reflect that either.


varying float v_hole;
varying vec3 v_tint;
Expand Down Expand Up @@ -52,13 +55,16 @@ vec4 pack_normal(vec3 n, float a) {
// Blends weights according to the bump of detail textures,
// so for example it allows to have sand fill the gaps between pebbles
vec4 get_depth_blended_weights(vec4 splat, vec4 bumps) {
float dh = 0.2;

float dh = height_boost;
bumps.r = 1.0 - pow(1.0 - bumps.r, 0.5);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful with pow, it's a transcendental math function, it's expensive. Here you raise to power 0.5, which is actually square root, so maybe use sqrt instead?
Not sure what this formula does

bumps.g = pow(bumps.g, 2.0);
Copy link
Owner

@Zylann Zylann Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pow again, prefer squaring by multiplying by itself. Are GLSL compilers smart enough to replace the call with that? Still no idea why you do this though, it's like some textures are more important than others or something

bumps.b = pow(bumps.b, 3.0);
bumps.a = pow(bumps.a, 4.0);
vec4 h = bumps + splat;

// TODO Keep improving multilayer blending, there are still some edge cases...
// Mitigation: nullify layers with near-zero splat
h *= smoothstep(0, 0.05, splat);
h *= smoothstep(low_edge, smoothness, splat);

vec4 d = h + dh;
d.r -= max(h.g, max(h.b, h.a));
Expand Down