Add a -transparent-dim=percent flag to set the extra dimming of transparent materials each depth meter.

This commit is contained in:
Sascha L. Teichmann
2015-07-26 11:55:38 +02:00
parent 68bb1ee320
commit e1eb03813f
7 changed files with 81 additions and 37 deletions

View File

@ -13,10 +13,14 @@ import (
"strings"
)
// Dim transparent 2% every node.
const DefaultTransparentDim = 2.0 / 100.0
type Colors struct {
Colors []color.RGBA
NameIndex map[string]int32
NumTransparent int32
TransparentDim float32
}
type namedColor struct {
@ -81,7 +85,8 @@ func ParseColors(filename string) (colors *Colors, err error) {
colors = &Colors{
Colors: cs,
NameIndex: nameIndex,
NumTransparent: numTransparent}
NumTransparent: numTransparent,
TransparentDim: DefaultTransparentDim}
return
}
@ -89,13 +94,6 @@ func (colors *Colors) IsTransparent(index int32) bool {
return index < colors.NumTransparent
}
func min(a, b int32) int32 {
if a < b {
return a
}
return b
}
func BlendColor(c1, c2 color.RGBA, a float32) color.RGBA {
b := float32(1) - a
return color.RGBA{
@ -113,12 +111,12 @@ func (colors *Colors) BlendColors(span *Span, col color.RGBA, pos int32) color.R
if curr == nil {
return col
}
const scale = float32(1) / 100
dim := colors.TransparentDim
for ; curr != nil; curr = curr.Next {
c := colors.Colors[curr.Value]
// At least alpha channel attenuation + 2% extra for each depth meter.
base := (int32(c.A) * 100) / 255
factor := float32(min(100, base+(curr.To-curr.From)*2)) * scale
// At least alpha channel attenuation + dim% extra for each depth meter.
base := float32(c.A) / 255.0
factor := min32f(1.0, base+float32(curr.To-curr.From)*dim)
col = BlendColor(c, col, factor)
}
return col

View File

@ -34,3 +34,20 @@ func min16(a, b int16) int16 {
}
return b
}
func min32f(a, b float32) float32 {
if a < b {
return a
}
return b
}
func Clamp32f(x, a, b float32) float32 {
switch {
case x < a:
return a
case x > b:
return b
}
return x
}