major gfx refactor from fixed function to shader based
This commit is contained in:
parent
0c0aa792c1
commit
40b385607d
58 changed files with 3681 additions and 2982 deletions
|
|
@ -1,7 +1,6 @@
|
|||
(local pxl8 (require :pxl8))
|
||||
(local effects (require :pxl8.effects))
|
||||
(local net (require :pxl8.net))
|
||||
(local shader (require :pxl8.shader))
|
||||
|
||||
(local colormap (require :mod.colormap))
|
||||
(local entities (require :mod.entities))
|
||||
|
|
@ -124,9 +123,7 @@
|
|||
(set lights (pxl8.create_lights)))
|
||||
|
||||
(entities.init textures)
|
||||
|
||||
(sky.generate-stars 12345)
|
||||
|
||||
(sky.generate-stars)
|
||||
(preload)
|
||||
|
||||
(when (not ceiling-tex)
|
||||
|
|
@ -136,22 +133,17 @@
|
|||
(when (not trim-tex)
|
||||
(set trim-tex (textures.wood-trim 77777 WOOD_COLOR)))
|
||||
(when (not wall-tex)
|
||||
(set wall-tex (textures.cobble-timber 55555 STONE_WALL_START MOSS_COLOR WOOD_COLOR)))
|
||||
|
||||
)
|
||||
(set wall-tex (textures.cobble-timber 55555 STONE_WALL_START MOSS_COLOR WOOD_COLOR))))
|
||||
|
||||
(fn setup-materials []
|
||||
(when (and world (not bsp-materials-setup) ceiling-tex floor-tex trim-tex wall-tex)
|
||||
(when (and world (not bsp-materials-setup) floor-tex trim-tex wall-tex)
|
||||
(let [chunk (world:active_chunk)]
|
||||
(when (and chunk (chunk:ready))
|
||||
(let [ceiling-mat (pxl8.create_material {:texture ceiling-tex})
|
||||
floor-mat (pxl8.create_material {:texture floor-tex :lighting true})
|
||||
trim-mat (pxl8.create_material {:texture trim-tex :lighting true})
|
||||
wall-mat (pxl8.create_material {:texture wall-tex :lighting true})]
|
||||
|
||||
(let [floor-mat (pxl8.create_material {:texture floor-tex :lighting true :double_sided true})
|
||||
trim-mat (pxl8.create_material {:texture trim-tex :lighting true :double_sided true})
|
||||
wall-mat (pxl8.create_material {:texture wall-tex :lighting true :double_sided true})]
|
||||
(world:set_bsp_material 0 floor-mat)
|
||||
(world:set_bsp_material 1 wall-mat)
|
||||
(world:set_bsp_material 2 ceiling-mat)
|
||||
(world:set_bsp_material 3 trim-mat)
|
||||
(set bsp-materials-setup true))))))
|
||||
|
||||
|
|
@ -199,7 +191,7 @@
|
|||
(when (> portal-cooldown 0)
|
||||
(set portal-cooldown (- portal-cooldown dt)))
|
||||
|
||||
(when (and network (<= portal-cooldown 0))
|
||||
(when (and world network (<= portal-cooldown 0))
|
||||
(let [chunk (world:active_chunk)
|
||||
in-bsp (not= chunk nil)
|
||||
(door-x door-z) (entities.get-door-position)
|
||||
|
|
@ -240,7 +232,7 @@
|
|||
expecting-bsp (> chunk-id 0)
|
||||
voxel-space (and (not chunk) (= chunk-id 0))
|
||||
ready (or voxel-space (and chunk (chunk:ready)))]
|
||||
(when ready
|
||||
(when world
|
||||
(let [input (sample-input)
|
||||
grid-max (if voxel-space 100000 (* grid-size chunk-size))
|
||||
movement-yaw cam-yaw]
|
||||
|
|
@ -322,10 +314,14 @@
|
|||
voxel-space (and world (not chunk) (not expecting-bsp))
|
||||
ready (or voxel-space (and chunk (chunk:ready)))]
|
||||
|
||||
(when (not camera)
|
||||
(pxl8.text "camera nil" 5 30 12))
|
||||
(when (not world)
|
||||
(pxl8.text "world nil" 5 40 12))
|
||||
(when (and world (not ready))
|
||||
(pxl8.text "Waiting for world data..." 5 30 12))
|
||||
(pxl8.text (.. "Waiting... chunk=" (tostring chunk) " voxel=" (tostring voxel-space)) 5 50 12))
|
||||
|
||||
(when (and camera world ready)
|
||||
(when (and camera world)
|
||||
(let [bob-offset (* (math.sin bob-time) bob-amount)
|
||||
eye-y (+ cam-y player-eye-height bob-offset land-squash)
|
||||
forward-x (- (math.sin cam-yaw))
|
||||
|
|
@ -353,19 +349,22 @@
|
|||
r2 (* 0.04 (math.sin (+ (* real-time 3.2) phase)))
|
||||
light-radius (* 150 (+ 0.95 r1 r2))]
|
||||
(lights:clear)
|
||||
(lights:add light-x light-y light-z 0xFF8C32 light-intensity light-radius)
|
||||
(lights:add light-x light-y light-z 0xFFB888 light-intensity light-radius)
|
||||
|
||||
(pxl8.push_target)
|
||||
(pxl8.begin_frame_3d camera lights {
|
||||
:ambient 30
|
||||
:ambient 25
|
||||
:fog_density 0.0
|
||||
:celestial_dir [0.5 -0.8 0.3]
|
||||
:celestial_intensity 0.5})
|
||||
:celestial_intensity 0.3})
|
||||
(pxl8.clear_depth)
|
||||
|
||||
(sky.update-gradient 1 2 6 6 10 18)
|
||||
(sky.render smooth-cam-x eye-y smooth-cam-z (menu.is-wireframe))
|
||||
(sky.render-stars smooth-cam-x eye-y smooth-cam-z 1.0 last-dt)
|
||||
(pxl8.clear_depth)
|
||||
|
||||
(world:set_wireframe (menu.is-wireframe))
|
||||
(pxl8.set_wireframe (menu.is-wireframe))
|
||||
(world:render [smooth-cam-x eye-y smooth-cam-z])
|
||||
|
||||
(when chunk
|
||||
|
|
@ -373,16 +372,10 @@
|
|||
|
||||
(entities.render-door (menu.is-wireframe) (if voxel-space 128 0))
|
||||
|
||||
(pxl8.end_frame_3d))
|
||||
|
||||
;; TODO: shader needs to run at present time, not mid-frame
|
||||
;; (shader.begin_frame)
|
||||
;; (shader.run shader.presets.light_with_fog
|
||||
;; {:fog_r 6 :fog_g 6 :fog_b 12
|
||||
;; :fog_start 0.1 :fog_end 0.85})
|
||||
|
||||
(sky.render-stars smooth-cam-x eye-y smooth-cam-z 1.0 last-dt)
|
||||
(pxl8.end_frame_3d)
|
||||
(pxl8.pop_target))
|
||||
|
||||
(pxl8.push_target)
|
||||
(let [cx (/ (pxl8.get_width) 2)
|
||||
cy (/ (pxl8.get_height) 2)
|
||||
crosshair-size 4
|
||||
|
|
@ -394,7 +387,8 @@
|
|||
(pxl8.text (.. "fps: " (string.format "%.0f" fps-avg)) 5 5 text-color)
|
||||
(pxl8.text (.. "pos: " (string.format "%.0f" cam-x) ","
|
||||
(string.format "%.0f" cam-y) ","
|
||||
(string.format "%.0f" cam-z)) 5 15 text-color))))))
|
||||
(string.format "%.0f" cam-z)) 5 15 text-color))
|
||||
(pxl8.pop_target)))))
|
||||
|
||||
{:preload preload
|
||||
:is-connected is-connected
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue