+ Render water nodes partially transparent

This commit is contained in:
Nils Dagsson Moskopp 2023-11-09 17:56:35 +01:00
parent ffdc5db2c6
commit bcba3312f2
Signed by: erlehmann
GPG Key ID: A3BC671C35191080
1 changed files with 22 additions and 7 deletions

View File

@ -52,9 +52,9 @@ local get_fog = function( distance )
return clamp( math.pow ( distance / 128, 2 ), 0, 1 )
end
local shade = function( origin, target, background_color )
local ray = minetest.raycast( origin, target, false, true )
local color
local shade = function( origin, target, background_color, liquids )
local ray = minetest.raycast( origin, target, false, liquids )
local color, hit_water
for pointed_thing in ray do
if "node" == pointed_thing.type then
local position = pointed_thing.under
@ -74,10 +74,11 @@ local shade = function( origin, target, background_color )
l_color * ( 1 - fog ) +
background_color * fog
)
hit_water = node.name:find("water")
break
end
end
return color
return color, hit_water
end
x_offset_by_sample = { 0, 1, 0, 1, 0, 1,-1,-1,-1 }
@ -104,6 +105,7 @@ local create_photo_pixels = function( player_name )
pixels[h] = {}
for w = 1,width,1 do
local x = width - ( w - 1 )
local sky_color = 191 - math.floor ( y / 2 )
local samples = 4 -- can be up to 9
local acc_color = 0
for sample = 1,samples,1 do
@ -115,9 +117,22 @@ local create_photo_pixels = function( player_name )
) * 2
local pos1 = eye
local pos2 = eye + lens + ( dir * 128 )
local color = shade( pos1, pos2, bg )
if nil == color then -- probably the sky
color = 191 - math.floor ( y / 2 )
local color, hit_water = shade(
pos1,
pos2,
bg,
true
)
color = color or sky_color
if hit_water then
local color2, _ = shade(
pos1,
pos2,
bg,
false -- no liquids
)
color2 = color2 or sky_color
color = ( color * 3 + color2 ) / 4
end
acc_color = acc_color + (
clamp(