원문 캡처 · datumhue.com
원문 캡처 · datumhue.com

DatumHue의 예제는 노이즈로 지형을 만들고 모래·풀·바위 색을 입힌 뒤 언덕에 등불을 배치한다. 자료는 이를 50줄짜리 Lua 코드로 소개한다.

local color = datumhue.color local vec3 = datumhue.math.vec3 local W, H, size = 1280, 720, 64 local WATER, SAND, GRASS, ROCK, LANTERN = 1, 2, 3, 4, 5 local scene = datumhue.scene.new({ width = W, height = H, hdr = true }) scene:mount({ width = W, height = H }) local shape = { width = size, height = 24, depth = size, sunlight = true } local land = datumhue.voxel.new(scene, shape) land:palette(WATER, { color = color("#3a515d"), transparent = true }) land:palette(SAND, { color = color("#dbbc7f") }) land:palette(GRASS, { color = color("#83c092") }) land:palette(ROCK, { color = color("#859289") }) land:palette(LANTERN, { emissive = color(16, 6, 1.5), light = 15 }) local rough = { seed = 11, frequency = 0.05, octaves = 5 } local hills = datumhue.noise.fbm(rough) local heights = datumhue.grid.new(size, size) for x = 0, size - 1 do for z = 0, size - 1 do local d = math.sqrt((x - 32) ^ 2 + (z - 32) ^ 2) / 30 local h = math.floor((hills:at(x, z) + 0.6) * 14 * (1 - d * d)) heights:set(x, z, h) if d < 1 then land:fill(x, 0, z, x, 2, z, WATER) end if h > 0 then local top = h > 11 and ROCK or h > 4 and GRASS or SAND land:fill(x, 0, z, x, h, z, top) end end end local dice = datumhue.random.new(5) for _ = 1, 12 do local x, z = dice:int(12, 52), dice:int(12, 52) local h = heights:get(x, z) if h > 4 then land:set(x, h + 1, z, LANTERN) end end scene.background = color("#2d353b") scene.tonemapping = "khronos_pbr_neutral" scene.bloom = { intensity = 0.4 } scene:directional_light({ direction = vec3(-0.6, -1, -0.3), intensity = 3000, shadows = true }) scene.camera.pos = vec3(90, 60, 90) scene.camera:look_at(vec3(32, 4, 32)) scene.camera:set_orthographic(44)