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

View File

@ -8,20 +8,23 @@ import (
"flag"
"fmt"
"log"
"bitbucket.org/s_l_teichmann/mtsatellite/common"
)
func main() {
var (
port int
host string
xMin, zMin int
xMax, zMax int
colorsFile string
outDir string
numWorkers int
skipBaseLevel bool
skipPyramid bool
transparent bool
port int
host string
xMin, zMin int
xMax, zMax int
colorsFile string
outDir string
numWorkers int
skipBaseLevel bool
skipPyramid bool
transparent bool
transparentDim float64
)
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(&transparent, "transparent", false, "Render transparent blocks.")
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()
if !skipBaseLevel {
td := common.Clamp32f(float32(transparentDim/100.0), 0.0, 1.0)
address := fmt.Sprintf("%s:%d", host, port)
if err := createBaseLevel(
address,
xMin, zMin, xMax, zMax,
transparent,
transparent, td,
colorsFile,
outDir,
numWorkers); err != nil {

View File

@ -27,6 +27,7 @@ func main() {
shaded bool
transparent bool
cpuProfile string
transparentDim float64
)
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.BoolVar(&shaded, "shaded", true, "draw relief")
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.Parse()
@ -66,6 +70,9 @@ func main() {
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)
var client *common.RedisClient

View File

@ -18,18 +18,19 @@ import (
func main() {
var (
webPort int
webHost string
webDir string
mapDir string
redisPort int
redisHost string
colorsFile string
workers int
transparent bool
updateHosts string
websockets bool
playersFIFO string
webPort int
webHost string
webDir string
mapDir string
redisPort int
redisHost string
colorsFile string
workers int
transparent bool
transparentDim float64
updateHosts string
websockets bool
playersFIFO string
)
flag.IntVar(&webPort, "web-port", 8808, "port of the web server")
flag.IntVar(&webPort, "p", 8808, "port of the web server (shorthand)")
@ -52,6 +53,12 @@ func main() {
flag.StringVar(&colorsFile, "c", "colors.txt", "colors used to render map tiles (shorthand).")
flag.BoolVar(&transparent, "transparent", false, "Render transparent blocks.")
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, "ws", false, "Forward tile changes to clients via websockets (shorthand).")
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 {
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)
var allowedUpdateIps []net.IP

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
}