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

View File

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