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

@ -81,7 +81,8 @@ need a `colors.txt` to map the block nodes to pixel colors of your map. The repo
If you want to have certain nodes to be transparent you can add `-transparent=true` to the If you want to have certain nodes to be transparent you can add `-transparent=true` to the
options. In this case if a color from colors.txt does have a forth color component the numerical options. In this case if a color from colors.txt does have a forth color component the numerical
value between 0 (fully transparent) and 255 (fully opaque) will be the base transparency of the value between 0 (fully transparent) and 255 (fully opaque) will be the base transparency of the
pixel. Every depth meter of the same material will reduce the transparency by 2%. pixel. Every depth meter of the same material will reduce the transparency by 2%. This can be adjusted
with the `-transparent-dim=percent` flags.
See `mtseeder --help` for all options. See `mtseeder --help` for all options.
The `-workers=` option and the `GOMAXPROCS=` environment variable are completely optional but very useful The `-workers=` option and the `GOMAXPROCS=` environment variable are completely optional but very useful

View File

@ -45,7 +45,7 @@ func order(a, b int) (int, int) {
func createBaseLevel( func createBaseLevel(
address string, address string,
xMin, zMin, xMax, zMax int, xMin, zMin, xMax, zMax int,
transparent bool, transparent bool, transparentDim float32,
colorsFile, outDir string, colorsFile, outDir string,
numWorkers int) (err error) { numWorkers int) (err error) {
@ -55,6 +55,8 @@ func createBaseLevel(
return return
} }
colors.TransparentDim = transparentDim
baseDir := filepath.Join(outDir, baseLevelDir) baseDir := filepath.Join(outDir, baseLevelDir)
if err = os.MkdirAll(baseDir, os.ModePerm); err != nil { if err = os.MkdirAll(baseDir, os.ModePerm); err != nil {
return return

View File

@ -8,6 +8,8 @@ import (
"flag" "flag"
"fmt" "fmt"
"log" "log"
"bitbucket.org/s_l_teichmann/mtsatellite/common"
) )
func main() { func main() {
@ -22,6 +24,7 @@ func main() {
skipBaseLevel bool skipBaseLevel bool
skipPyramid bool skipPyramid bool
transparent bool transparent bool
transparentDim float64
) )
flag.IntVar(&port, "port", 6379, "port to of mtredisalize server") flag.IntVar(&port, "port", 6379, "port to of mtredisalize server")
@ -42,15 +45,22 @@ func main() {
flag.BoolVar(&skipPyramid, "sp", false, "Do not generate pyramid tiles (shorthand)") flag.BoolVar(&skipPyramid, "sp", false, "Do not generate pyramid tiles (shorthand)")
flag.BoolVar(&transparent, "transparent", false, "Render transparent blocks.") flag.BoolVar(&transparent, "transparent", false, "Render transparent blocks.")
flag.BoolVar(&transparent, "t", false, "Render transparent blocks (shorthand).") flag.BoolVar(&transparent, "t", false, "Render transparent blocks (shorthand).")
flag.Float64Var(&transparentDim,
"transparent-dim", common.DefaultTransparentDim*100.0,
"Extra dimming of transparent nodes each depth meter in percent.")
flag.Float64Var(&transparentDim,
"td", common.DefaultTransparentDim*100.0,
"Extra fimming of transparent nodes each depth meter in percent. (shorthand)")
flag.Parse() flag.Parse()
if !skipBaseLevel { if !skipBaseLevel {
td := common.Clamp32f(float32(transparentDim/100.0), 0.0, 1.0)
address := fmt.Sprintf("%s:%d", host, port) address := fmt.Sprintf("%s:%d", host, port)
if err := createBaseLevel( if err := createBaseLevel(
address, address,
xMin, zMin, xMax, zMax, xMin, zMin, xMax, zMax,
transparent, transparent, td,
colorsFile, colorsFile,
outDir, outDir,
numWorkers); err != nil { numWorkers); err != nil {

View File

@ -27,6 +27,7 @@ func main() {
shaded bool shaded bool
transparent bool transparent bool
cpuProfile string cpuProfile string
transparentDim float64
) )
flag.IntVar(&port, "port", 6379, "port to of mtredisalize server") flag.IntVar(&port, "port", 6379, "port to of mtredisalize server")
@ -46,6 +47,9 @@ func main() {
flag.StringVar(&outfile, "o", "out.png", "image file of result (shorthand)") flag.StringVar(&outfile, "o", "out.png", "image file of result (shorthand)")
flag.BoolVar(&shaded, "shaded", true, "draw relief") flag.BoolVar(&shaded, "shaded", true, "draw relief")
flag.BoolVar(&transparent, "transparent", false, "render transparent blocks") flag.BoolVar(&transparent, "transparent", false, "render transparent blocks")
flag.Float64Var(
&transparentDim, "transparent-dim", common.DefaultTransparentDim*100,
"Extra dimming of transparent nodes every depth meter in percent (0-100).")
flag.StringVar(&cpuProfile, "cpuprofile", "", "write cpu profile to file") flag.StringVar(&cpuProfile, "cpuprofile", "", "write cpu profile to file")
flag.Parse() flag.Parse()
@ -66,6 +70,9 @@ func main() {
log.Fatalf("Cannot open color file: %s", err) log.Fatalf("Cannot open color file: %s", err)
} }
colors.TransparentDim = common.Clamp32f(
float32(transparentDim/100.0), 0.0, 100.0)
address := fmt.Sprintf("%s:%d", host, port) address := fmt.Sprintf("%s:%d", host, port)
var client *common.RedisClient var client *common.RedisClient

View File

@ -27,6 +27,7 @@ func main() {
colorsFile string colorsFile string
workers int workers int
transparent bool transparent bool
transparentDim float64
updateHosts string updateHosts string
websockets bool websockets bool
playersFIFO string playersFIFO string
@ -52,6 +53,12 @@ func main() {
flag.StringVar(&colorsFile, "c", "colors.txt", "colors used to render map tiles (shorthand).") flag.StringVar(&colorsFile, "c", "colors.txt", "colors used to render map tiles (shorthand).")
flag.BoolVar(&transparent, "transparent", false, "Render transparent blocks.") flag.BoolVar(&transparent, "transparent", false, "Render transparent blocks.")
flag.BoolVar(&transparent, "t", false, "Render transparent blocks (shorthand).") flag.BoolVar(&transparent, "t", false, "Render transparent blocks (shorthand).")
flag.Float64Var(&transparentDim,
"transparent-dim", common.DefaultTransparentDim*100.0,
"Extra dimming of transparent nodes each depth meter in percent.")
flag.Float64Var(&transparentDim,
"td", common.DefaultTransparentDim*100.0,
"Extra fimming of transparent nodes each depth meter in percent. (shorthand)")
flag.BoolVar(&websockets, "websockets", false, "Forward tile changes to clients via websockets.") flag.BoolVar(&websockets, "websockets", false, "Forward tile changes to clients via websockets.")
flag.BoolVar(&websockets, "ws", false, "Forward tile changes to clients via websockets (shorthand).") flag.BoolVar(&websockets, "ws", false, "Forward tile changes to clients via websockets (shorthand).")
flag.StringVar(&playersFIFO, "players", "", "Path to FIFO file to read active players from.") flag.StringVar(&playersFIFO, "players", "", "Path to FIFO file to read active players from.")
@ -86,6 +93,8 @@ func main() {
if colors, err = common.ParseColors(colorsFile); err != nil { if colors, err = common.ParseColors(colorsFile); err != nil {
log.Fatalf("ERROR: problem loading colors: %s", err) log.Fatalf("ERROR: problem loading colors: %s", err)
} }
colors.TransparentDim = common.Clamp32f(
float32(transparentDim/100.0), 0.0, 100.0)
redisAddress := fmt.Sprintf("%s:%d", redisHost, redisPort) redisAddress := fmt.Sprintf("%s:%d", redisHost, redisPort)
var allowedUpdateIps []net.IP var allowedUpdateIps []net.IP

View File

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

View File

@ -34,3 +34,20 @@ func min16(a, b int16) int16 {
} }
return b 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
}