diff --git a/init.lua b/init.lua index f2a466f..f927d3c 100644 --- a/init.lua +++ b/init.lua @@ -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