displacement smoothbump3(float Km = 0.1, min_s = 0.1, max_s = 0.8, min_t = 0.1, max_t = 0.8, fuzz = 0.1) { float hump = 0; normal n; /* STEP 1 - make a copy of the surface normal one unit in length */ n = normalize(N); /* STEP 2 - calculate an appropriate value for the displacement */ hump = smoothstep(min_s, min_s + fuzz, s) * (1 - smoothstep(max_s, max_s + fuzz, s)) * smoothstep(min_t, min_t + fuzz, t) * (1 - smoothstep(max_t, max_t + fuzz, t)); /* STEP 3 - calculate the new position of the surface point */ /* "P" based on the value of hump */ P = P - n * hump * Km; /* STEP 4 - calculate the new orientation of the surface normal */ N = calculatenormal(P); }