Randoloot/scripts/planets/surface_landscape.gd

33 lines
2.0 KiB
GDScript

extends RefCounted
const PALETTES := [
{"name":"Zielone doliny","low":Color("406338"),"high":Color("82935b"),"sand":Color("baaf83"),"rock":Color("737770"),"trees":Color("e4f1ce"),"density":0.78},
{"name":"Jesienne lasy","low":Color("5f6540"),"high":Color("99905d"),"sand":Color("c6b58b"),"rock":Color("777671"),"trees":Color("e4ae63"),"density":0.86},
{"name":"Mokradła","low":Color("3c6153"),"high":Color("74835a"),"sand":Color("98947b"),"rock":Color("646f6b"),"trees":Color("b3d8ad"),"density":0.42},
{"name":"Skaliste wyżyny","low":Color("697250"),"high":Color("9b9b7e"),"sand":Color("c3b89c"),"rock":Color("83827c"),"trees":Color("d4d8bb"),"density":0.35},
{"name":"Suche kaniony","low":Color("8c7652"),"high":Color("b49968"),"sand":Color("d3ba87"),"rock":Color("9e7960"),"trees":Color("c8bb7a"),"density":0.23},
{"name":"Alpejska tundra","low":Color("6d827a"),"high":Color("a7afa1"),"sand":Color("aaa99a"),"rock":Color("858c89"),"trees":Color("c5dcdb"),"density":0.32}
]
static func choose(seed_value: int, profile: Dictionary) -> Dictionary:
var index := posmod(seed_value,4)
if int(profile.temperature) > 40:
index = 4
elif int(profile.temperature) < -10:
index = 5
var result: Dictionary = PALETTES[index].duplicate()
result.index = index
return result
static func height_texture(heights: PackedFloat32Array) -> ImageTexture:
var image := Image.create_from_data(96,96,false,Image.FORMAT_RF,heights.to_byte_array())
# Smooth the scalar field in native code, without enlarging the gameplay grid.
image.resize(1024,1024,Image.INTERPOLATE_CUBIC)
return ImageTexture.create_from_image(image)
static func color_at(h: float, wet: float, palette: Dictionary) -> Color:
var land: Color = palette.low.lerp(palette.high,smoothstep(0.31,0.72,h))
land = land.lerp(palette.rock,smoothstep(0.61,0.76,h))
var shore: Color = palette.sand.lerp(land,smoothstep(0.275,0.33,h))
var water := Color("327c80").lerp(Color("183d52"),smoothstep(0.3,0.12,h))
var color := water.lerp(shore,smoothstep(0.265,0.285,h))
return color.lerp(Color("2d6875"),smoothstep(0.35,0.5,wet))