suppress shadows of invisible nodes

This commit is contained in:
Andrey Stepanov 2024-11-09 14:18:08 +05:00
parent c45f002f82
commit cde8ef4495
Signed by: Koldun
GPG Key ID: 53DE683337F5D25F

View File

@ -36,7 +36,7 @@ const (
EXPECTED_BLOCKS_PER_FLAT_MAPBLOCK = 16 * 16 EXPECTED_BLOCKS_PER_FLAT_MAPBLOCK = 16 * 16
) )
func IsViewBlocking(nodeName string) bool { func (r *MapBlockRenderer) IsViewBlocking(nodeName string, param2 int) bool {
if nodeName == "" { if nodeName == "" {
return false return false
} }
@ -49,6 +49,12 @@ func IsViewBlocking(nodeName string) bool {
return false return false
} }
c := r.colors.GetColor(nodeName, param2)
if c == nil {
return false
}
return true return true
} }
@ -147,12 +153,14 @@ func (r *MapBlockRenderer) Render(pos1, pos2 *types.MapBlockCoords) (*image.NRGB
if r.enableShadow { if r.enableShadow {
var left, leftAbove, top, topAbove string var left, leftAbove, top, topAbove string
var left_param2, leftAbove_param2, top_param2, topAbove_param2 int
if x > 0 { if x > 0 {
//same mapblock //same mapblock
left = mb.GetNodeName(x-1, y, z) left = mb.GetNodeName(x-1, y, z)
if y < 15 { if y < 15 {
leftAbove = mb.GetNodeName(x-1, y+1, z) leftAbove = mb.GetNodeName(x-1, y+1, z)
leftAbove_param2 = mb.GetParam2(x-1, y+1, z)
} }
} else { } else {
@ -162,8 +170,10 @@ func (r *MapBlockRenderer) Render(pos1, pos2 *types.MapBlockCoords) (*image.NRGB
if neighbourMapblock != nil && err == nil { if neighbourMapblock != nil && err == nil {
left = neighbourMapblock.GetNodeName(15, y, z) left = neighbourMapblock.GetNodeName(15, y, z)
left_param2 = neighbourMapblock.GetParam2(15, y, z)
if y < 15 { if y < 15 {
leftAbove = neighbourMapblock.GetNodeName(15, y+1, z) leftAbove = neighbourMapblock.GetNodeName(15, y+1, z)
leftAbove_param2 = neighbourMapblock.GetParam2(15, y+1, z)
} }
} }
} }
@ -173,6 +183,7 @@ func (r *MapBlockRenderer) Render(pos1, pos2 *types.MapBlockCoords) (*image.NRGB
top = mb.GetNodeName(x, y, z+1) top = mb.GetNodeName(x, y, z+1)
if y < 15 { if y < 15 {
topAbove = mb.GetNodeName(x, y+1, z+1) topAbove = mb.GetNodeName(x, y+1, z+1)
topAbove_param2 = mb.GetParam2(x, y+1, z+1)
} }
} else { } else {
@ -182,28 +193,30 @@ func (r *MapBlockRenderer) Render(pos1, pos2 *types.MapBlockCoords) (*image.NRGB
if neighbourMapblock != nil && err == nil { if neighbourMapblock != nil && err == nil {
top = neighbourMapblock.GetNodeName(x, y, 0) top = neighbourMapblock.GetNodeName(x, y, 0)
top_param2 = neighbourMapblock.GetParam2(x, y, 0)
if y < 15 { if y < 15 {
topAbove = neighbourMapblock.GetNodeName(x, y+1, 0) topAbove = neighbourMapblock.GetNodeName(x, y+1, 0)
topAbove_param2 = neighbourMapblock.GetParam2(x, y+1, 0)
} }
} }
} }
if IsViewBlocking(leftAbove) { if r.IsViewBlocking(leftAbove, leftAbove_param2) {
//add shadow //add shadow
c = addColorComponent(c, -10) c = addColorComponent(c, -10)
} }
if IsViewBlocking(topAbove) { if r.IsViewBlocking(topAbove, topAbove_param2) {
//add shadow //add shadow
c = addColorComponent(c, -10) c = addColorComponent(c, -10)
} }
if !IsViewBlocking(left) { if !r.IsViewBlocking(left, left_param2) {
//add light //add light
c = addColorComponent(c, 10) c = addColorComponent(c, 10)
} }
if !IsViewBlocking(top) { if !r.IsViewBlocking(top, top_param2) {
//add light //add light
c = addColorComponent(c, 10) c = addColorComponent(c, 10)
} }