Fixed hill shading for transparent structures a bit. Still not optimal.

This commit is contained in:
Sascha L. Teichmann 2014-10-28 11:53:18 +01:00
parent 6afed94154
commit cf9cbe7087
2 changed files with 32 additions and 4 deletions

View File

@ -55,6 +55,13 @@ func max(a, b int) int {
return b return b
} }
func max32(a, b int32) int32 {
if a > b {
return a
}
return b
}
func copyData(data []byte) []byte { func copyData(data []byte) []byte {
l := len(data) l := len(data)
ndata := make([]byte, l, max(l, 8*1024)) ndata := make([]byte, l, max(l, 8*1024))
@ -429,17 +436,32 @@ func (r *Renderer) CreateShadedImage(
pix[iofs+2] = background.B pix[iofs+2] = background.B
pix[iofs+3] = 0xff pix[iofs+3] = 0xff
} else { } else {
var y, y1, y2 int32 y := r.yBuffer[ofs]
y = r.yBuffer[ofs] t := r.tBuffer[ofs]
opaque := t == nil || t.Top() < y
var y1, y2 int32
if x == 0 { if x == 0 {
y1 = y y1 = y
} else { } else {
y1 = r.yBuffer[ofs-1] y1 = r.yBuffer[ofs-1]
if opaque {
if s := r.tBuffer[ofs-1]; s != nil {
y1 = max32(y1, s.Top())
}
}
} }
if z == 0 { if z == 0 {
y2 = y y2 = y
} else { } else {
y2 = r.yBuffer[ofs+pw] y2 = r.yBuffer[ofs+pw]
if opaque {
if s := r.tBuffer[ofs+pw]; s != nil {
y1 = max32(y1, s.Top())
}
}
} }
d := ((y - y1) + (y - y2)) * 12 d := ((y - y1) + (y - y2)) * 12
if d > 36 { if d > 36 {
@ -451,8 +473,8 @@ func (r *Renderer) CreateShadedImage(
G: safeColor(int32(col.G) + d), G: safeColor(int32(col.G) + d),
B: safeColor(int32(col.B) + d), B: safeColor(int32(col.B) + d),
A: 0xff} A: 0xff}
if r.tBuffer[ofs] != nil { if !opaque {
col = cols.BlendColors(r.tBuffer[ofs], col, y) col = cols.BlendColors(t, col, y)
} }
pix[iofs] = col.R pix[iofs] = col.R
pix[iofs+1] = col.G pix[iofs+1] = col.G

View File

@ -136,6 +136,12 @@ func (s *Span) Len() int {
return n return n
} }
func (s *Span) Top() int32 {
for ; s.Next != nil; s = s.Next {
}
return s.To
}
func (s *Span) String() string { func (s *Span) String() string {
var buf bytes.Buffer var buf bytes.Buffer
first := true first := true