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
|
|
@ -107,4 +107,6 @@
|
|||
(transition:render))
|
||||
|
||||
(when (menu.is-paused)
|
||||
(menu.draw))))
|
||||
(pxl8.push_target)
|
||||
(menu.draw)
|
||||
(pxl8.pop_target))))
|
||||
|
|
|
|||
|
|
@ -168,9 +168,8 @@
|
|||
(fn render-fireball [x y z wireframe]
|
||||
(when fireball-mesh
|
||||
(pxl8.draw_mesh fireball-mesh {:x x :y y :z z
|
||||
:passthrough true
|
||||
:wireframe wireframe
|
||||
:emissive 1.0})))
|
||||
:emissive true
|
||||
:wireframe wireframe})))
|
||||
|
||||
{:FIREBALL_COLOR FIREBALL_COLOR
|
||||
:get-door-position get-door-position
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
(local net-mod (require :pxl8.net))
|
||||
|
||||
(var paused false)
|
||||
(var wireframe false)
|
||||
(var gui nil)
|
||||
(var render-distance 3)
|
||||
(var sim-distance 4)
|
||||
|
|
@ -13,6 +12,11 @@
|
|||
(var current-items [])
|
||||
(var pending-action nil)
|
||||
|
||||
(var baked-lighting true)
|
||||
(var dynamic-lighting true)
|
||||
(var textures true)
|
||||
(var wireframe false)
|
||||
|
||||
(fn init []
|
||||
(set gui (pxl8.create_gui))
|
||||
(let [w (world-mod.World.get)]
|
||||
|
|
@ -100,24 +104,20 @@
|
|||
(or clicked (and is-selected (= pending-action label))))))
|
||||
|
||||
(fn draw-main-menu []
|
||||
(pxl8.gui_window 200 80 240 235 "pxl8 demo")
|
||||
(pxl8.gui_window 200 80 240 200 "pxl8 demo")
|
||||
|
||||
(when (menu-button 1 215 127 210 30 "Resume")
|
||||
(hide))
|
||||
|
||||
(let [wire-label (if wireframe "Wireframe: On" "Wireframe: Off")]
|
||||
(when (menu-button 4 215 162 210 30 wire-label)
|
||||
(set wireframe (not wireframe))))
|
||||
|
||||
(when (menu-button 5 215 197 210 30 "GFX")
|
||||
(when (menu-button 5 215 162 210 30 "GFX")
|
||||
(set current-panel :gfx)
|
||||
(set selected-item nil))
|
||||
|
||||
(when (menu-button 6 215 232 210 30 "SFX")
|
||||
(when (menu-button 6 215 197 210 30 "SFX")
|
||||
(set current-panel :sfx)
|
||||
(set selected-item nil))
|
||||
|
||||
(when (menu-button 2 215 267 210 30 "Quit")
|
||||
(when (menu-button 2 215 232 210 30 "Quit")
|
||||
(pxl8.quit)))
|
||||
|
||||
(fn draw-sfx-panel []
|
||||
|
|
@ -136,10 +136,18 @@
|
|||
(set selected-item nil)))
|
||||
|
||||
(fn draw-gfx-panel []
|
||||
(pxl8.gui_window 200 100 240 180 "GFX")
|
||||
(pxl8.gui_window 200 60 240 220 "GFX")
|
||||
|
||||
(pxl8.gui_label 215 150 (.. "Render: " render-distance) 15)
|
||||
(let [(changed new-val) (gui:slider_int 30 215 165 210 16 render-distance 1 8)]
|
||||
(let [baked-label (if baked-lighting "Baked Lighting: On" "Baked Lighting: Off")]
|
||||
(when (menu-button 40 215 107 210 24 baked-label)
|
||||
(set baked-lighting (not baked-lighting))))
|
||||
|
||||
(let [dynamic-label (if dynamic-lighting "Dynamic Lighting: On" "Dynamic Lighting: Off")]
|
||||
(when (menu-button 41 215 134 210 24 dynamic-label)
|
||||
(set dynamic-lighting (not dynamic-lighting))))
|
||||
|
||||
(pxl8.gui_label 215 162 (.. "Render: " render-distance) 15)
|
||||
(let [(changed new-val) (gui:slider_int 30 215 175 210 14 render-distance 1 8)]
|
||||
(when changed
|
||||
(set render-distance new-val)
|
||||
(let [w (world-mod.World.get)
|
||||
|
|
@ -147,16 +155,15 @@
|
|||
(when w (w:set_render_distance new-val))
|
||||
(when n (n:set_chunk_settings new-val sim-distance)))))
|
||||
|
||||
(pxl8.gui_label 215 190 (.. "Sim: " sim-distance) 15)
|
||||
(let [(changed new-val) (gui:slider_int 31 215 205 210 16 sim-distance 1 8)]
|
||||
(when changed
|
||||
(set sim-distance new-val)
|
||||
(let [w (world-mod.World.get)
|
||||
n (net-mod.get)]
|
||||
(when w (w:set_sim_distance new-val))
|
||||
(when n (n:set_chunk_settings render-distance new-val)))))
|
||||
(let [tex-label (if textures "Textures: On" "Textures: Off")]
|
||||
(when (menu-button 42 215 194 210 24 tex-label)
|
||||
(set textures (not textures))))
|
||||
|
||||
(when (menu-button 32 215 240 210 30 "Back")
|
||||
(let [wire-label (if wireframe "Wireframe: On" "Wireframe: Off")]
|
||||
(when (menu-button 43 215 221 210 24 wire-label)
|
||||
(set wireframe (not wireframe))))
|
||||
|
||||
(when (menu-button 32 215 248 210 24 "Back")
|
||||
(set current-panel :main)
|
||||
(set selected-item nil)))
|
||||
|
||||
|
|
@ -178,6 +185,9 @@
|
|||
|
||||
{:init init
|
||||
:is-paused (fn [] paused)
|
||||
:is-baked-lighting (fn [] baked-lighting)
|
||||
:is-dynamic-lighting (fn [] dynamic-lighting)
|
||||
:is-textures (fn [] textures)
|
||||
:is-wireframe (fn [] wireframe)
|
||||
:toggle toggle
|
||||
:show show
|
||||
|
|
|
|||
|
|
@ -176,7 +176,8 @@
|
|||
|
||||
(set star-count (+ (length tiny-stars) (length random-stars)))
|
||||
(set star-directions (pxl8.create_vec3_array star-count))
|
||||
(set star-glows (pxl8.create_glows 10000))
|
||||
(when pxl8.create_glows
|
||||
(set star-glows (pxl8.create_glows 10000)))
|
||||
(set star-projected (pxl8.create_vec3_array star-count))
|
||||
|
||||
(var idx 0)
|
||||
|
|
@ -247,7 +248,7 @@
|
|||
(fn render [cam-x cam-y cam-z wireframe]
|
||||
(when (not sky-mesh) (create-sky-dome))
|
||||
(when sky-mesh
|
||||
(pxl8.draw_mesh sky-mesh {:x cam-x :y cam-y :z cam-z :passthrough true :wireframe wireframe})))
|
||||
(pxl8.draw_mesh sky-mesh {:x cam-x :y cam-y :z cam-z :wireframe wireframe})))
|
||||
|
||||
{:render render
|
||||
:render-stars render-stars
|
||||
|
|
|
|||
BIN
demo/res/textures/door.ase
Normal file
BIN
demo/res/textures/door.ase
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue