+ Add noise to nodes

This commit is contained in:
Nils Dagsson Moskopp 2023-11-09 23:44:19 +01:00
parent bcba3312f2
commit f3506c3544
Signed by: erlehmann
GPG Key ID: A3BC671C35191080
1 changed files with 19 additions and 1 deletions

View File

@ -52,6 +52,10 @@ local get_fog = function( distance )
return clamp( math.pow ( distance / 128, 2 ), 0, 1 )
end
local step = function( value, steps )
return math.floor( ( value - math.floor(value) ) * steps ) / steps
end
local shade = function( origin, target, background_color, liquids )
local ray = minetest.raycast( origin, target, false, liquids )
local color, hit_water
@ -69,7 +73,21 @@ local shade = function( origin, target, background_color, liquids )
pointed_thing.intersection_normal.y * 3 +
pointed_thing.intersection_normal.z * 1
) / 12
local l_color = math.min( base_color * n * light, 255 )
local point = pointed_thing.intersection_point
local x = step( point.x, 8 )
local y = step( point.y, 8 )
local z = step( point.z, 8 )
local noise = math.floor(
(
( math.sin(x) * math.tan(z) ) * 65497 +
( math.sin(y) * math.tan(x) ) * 65519 +
( math.sin(z) * math.tan(y) ) * 65521
) / 3
) % 16
local l_color = math.min(
( base_color + noise ) * n * light,
255
)
color = math.floor(
l_color * ( 1 - fog ) +
background_color * fog