Skip to content

Commit

Permalink
Merge pull request #25 from WebGPU-Art/compute
Browse files Browse the repository at this point in the history
port updates
  • Loading branch information
csvwolf authored Nov 20, 2024
2 parents bd2e66f 524dc00 commit 675783f
Show file tree
Hide file tree
Showing 7 changed files with 739 additions and 510 deletions.
Binary file removed .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 7,5 @@ node_modules/
dist/

yarn-error.log

.DS_Store
853 changes: 527 additions & 326 deletions calcit.cirru

Large diffs are not rendered by default.

154 changes: 88 additions & 66 deletions compact.cirru
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@

{} (:package |lagopus)
:configs $ {} (:init-fn |lagopus.main/main!) (:reload-fn |lagopus.main/reload!) (:version |0.5.5)
:configs $ {} (:init-fn |lagopus.main/main!) (:reload-fn |lagopus.main/reload!) (:version |0.5.9)
:modules $ [] |memof/ |quaternion/
:entries $ {}
:files $ {}
Expand Down Expand Up @@ -80,6 80,11 @@
:code $ quote
defn inject-shader-snippets (code)
-> code (.!replace "\"#import lagopus::simplex" wgsl-simplex) (.!replace "\"#import lagopus::perspective" wgsl-perspective) (.!replace "\"#import lagopus::colors" wgsl-colors) (.!replace "\"#import lagopus::rand" wgsl-rand) (.!replace "\"#import lagopus::rotation" wgsl-rotation) (.!replace "\"#import lagopus::hsluv" wgsl-hsluv)
|make-empty-js-arrays $ %{} :CodeEntry (:doc "|create nested array of js, as placeholder for attributes data")
:code $ quote
defn make-empty-js-arrays (n)
-> (new js/Array n) (.!fill 0)
.!map $ fn (x i _) (js-array)
|object $ %{} :CodeEntry (:doc |)
:code $ quote
defn object (options)
Expand Down Expand Up @@ -107,71 112,84 @@
eprintln "\"buffer size guessed incorrectly"
, buffer
; js/console.log vertices-size buffers
createRenderer
inject-shader-snippets $ &map:get options :shader
turn-string $ &map:get options :topology
to-js-data attrs-list
, vertices-size buffers nil
if-let
indices $ &map:get options :indices
u32buffer $ let
*arr $ js-array
collect! $ fn (x) (.!push *arr x )
collect-array! indices collect!
, *arr
&map:get options :get-params
js-array & $ either (&map:get options :textures) ([])
&map:get options :label
createRenderer $ js-object
:shader $ inject-shader-snippets (&map:get options :shader)
:topology $ turn-string (&map:get options :topology)
:attrsList $ to-js-data attrs-list
:verticesLength vertices-size
:vertices buffers
:hitRegion nil
:indices $ if-let
indices $ &map:get options :indices
u32buffer $ let
*arr $ js-array
collect! $ fn (x) (.!push *arr x )
collect-array! indices collect!
, *arr
:getParams $ &map:get options :get-params
:textures $ js-array &
either (&map:get options :textures) ([])
:label $ &map:get options :label
:computeOptions $ &map:get options :compute-options
|object-writer $ %{} :CodeEntry (:doc |)
:code $ quote
defn object-writer (options)
let
attrs-list $ map (&map:get options :attrs-list) expand-attr
writer $ &map:get options :writer
bundles $ js-array &
->
range $ count attrs-list
map $ fn (_) (js-array)
bundles $ noted "\"actually stores data in this nested list..."
make-empty-js-arrays $ count attrs-list
*counter $ atom 0
count! $ fn (x) (swap! *counter & x)
collect! $ fn (chunk)
&doseq (record chunk) (count! 1)
map-indexed attrs-list $ fn (idx attr)
let
arr $ aget bundles idx
data $ do
assert "\"expected tuple" $ tuple? record
if
not= :vertex $ nth record 0
js/console.warn "\"expected :vertex tag" record
nth record $ inc idx
if (tuple? data)
tag-match data $
:v3 x y z
do $ .!push arr x y z
if (list? data)
&doseq (d data) (.!push arr d)
.!push arr data
buffers $ do (writer collect!)
let
*counted $ atom 0
&doseq (attr attrs-list)
let
idx @*counted
arr $ js-get bundles idx
data $ do
assert "\"expected tuple" $ tuple? record
if
not= :vertex $ nth record 0
js/console.warn "\"expected :vertex tag" record
nth record $ inc idx
if (tuple? data)
tag-match data $
:v3 x y z
do $ .!push arr x y z
if (list? data)
&doseq (d data) (.!push arr d)
.!push arr data
swap! *counted inc
buffers $ do
noted "\"call writer function to fill data into buffer" $ writer collect!
js-array & $ map-indexed attrs-list
fn (idx attr)
newBufferFormatArray
buffer-format $ &map:get attr :format
aget bundles idx
js-get bundles idx
; js/console.log @*counter buffers
createRenderer
inject-shader-snippets $ &map:get options :shader
turn-string $ &map:get options :topology
to-js-data attrs-list
, @*counter buffers nil
if-let
indices $ &map:get options :indices
u32buffer $ let
*arr $ js-array
collect! $ fn (x) (.!push *arr x)
collect-array! indices collect!
, *arr
&map:get options :get-params
createRenderer $ js-object
:shader $ inject-shader-snippets (&map:get options :shader)
:topology $ turn-string (&map:get options :topology)
:attrsList $ to-js-data attrs-list
:verticesLength @*counter
:vertices buffers
:hitRegion nil
:indices $ if-let
indices $ &map:get options :indices
u32buffer $ let
*arr $ js-array
collect! $ fn (x) (.!push *arr x)
collect-array! indices collect!
, *arr
:getParams $ &map:get options :get-params
:textures $ js-array &
either (&map:get options :textures) ([])
:label $ &map:get options :label
:computeOptions $ &map:get options :compute-options
|wgsl-colors $ %{} :CodeEntry (:doc |)
:code $ quote
def wgsl-colors $ inline-shader "\"lagopus-colors"
Expand Down Expand Up @@ -681,26 699,26 @@
(:vertex position width mark)
if-let (prev @*prev)
let
older $ :older prev
older $ &map:get prev :older
reset! *prev $ {} (:position position) (:older older) (:mark mark)
:width $ :width prev
if (some? older)
let
p older
q $ :position prev
prev-mark $ :mark prev
q $ &map:get prev :position
prev-mark $ &map:get prev :mark
q2 position
direction $ &v- q p
direction2 $ &v- q2 q
p-width $ :width prev
p-width $ &map:get prev :width
q-width width
write! $ [] (:: :vertex q 0 direction p-width prev-mark) (:: :vertex q2 0 direction2 q-width mark) (:: :vertex q 1 direction2 p-width prev-mark) (:: :vertex q2 0 direction2 p-width mark) (:: :vertex q2 1 direction2 q-width mark) (:: :vertex q 1 direction p-width prev-mark)
let
q $ :position prev
prev-mark $ :mark prev
q $ &map:get prev :position
prev-mark $ &map:get prev :mark
q2 position
direction $ &v- q2 q
p-width $ :width prev
p-width $ &map:get prev :width
q-width width
write! $ [] (:: :vertex q 0 direction p-width prev-mark) (:: :vertex q2 0 direction q-width mark) (:: :vertex q 1 direction p-width prev-mark) (:: :vertex q2 0 direction p-width mark) (:: :vertex q2 1 direction q-width mark) (:: :vertex q 1 direction p-width prev-mark)
do $ reset! *prev
Expand Down Expand Up @@ -786,6 804,8 @@
&doseq (x p) (build-polyline-points *prev x write!)
build-polyline-points *prev p write!
chunk-writer! collect!
:get-params $ &map:get options :get-params
:compute-options $ &map:get options :compute-options
|comp-polylines-marked $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-polylines-marked (options)
Expand All @@ -805,6 825,7 @@
build-polyline-points-marked *prev p write!
chunk-writer! collect!
:get-params $ &map:get options :get-params
:compute-options $ &map:get options :compute-options
|count-hex $ %{} :CodeEntry (:doc |)
:code $ quote
defn count-hex (xs)
Expand Down Expand Up @@ -1277,11 1298,8 @@
if (.blank? bg) nil $ let
items $ -> (.split bg "\",")
map $ fn (piece) (js/parseFloat piece)
{}
:r $ nth items 0
:g $ nth items 1
:b $ nth items 2
:a $ either (nth items 3) 1
:: :rgba (nth items 0) (nth items 1) (nth items 2)
either (nth items 3) 1
|bloom? $ %{} :CodeEntry (:doc |)
:code $ quote
def bloom? $ = "\"true" (get-env "\"bloom" "\"false")
Expand Down Expand Up @@ -1371,8 1389,7 @@
context $ js-await (initializeContext)
js-await $ load-images! (.-device context) *global-textures
initializeCanvasTextures
reset-clear-color! $ either bg-color
{} (:r 0.18) (:g 0.2) (:b 0.36) (:a 1)
reset-clear-color! $ either bg-color (:: :rgba 0.18 0.2 0.36 1)
render-app!
renderControl
startControlLoop 10 onControlEvent
Expand Down Expand Up @@ -1495,7 1512,12 @@
|reset-clear-color! $ %{} :CodeEntry (:doc |)
:code $ quote
defn reset-clear-color! (color)
.!reset atomClearColor $ to-js-data color
.!reset atomClearColor $ if (tuple? color)
tag-match color
:rgba r g b a
js-object (:r r) (:g g) (:b b) (:a a)
_ $ raise (str "\"unknown color: " color)
to-js-data color
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns lagopus.util $ :require ("\"bottom-tip" :default hud!)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 1,9 @@
{
"version": "0.5.5",
"version": "0.5.8",
"dependencies": {
"@calcit/procs": "^0.9.6",
"@calcit/std": "^0.0.3",
"@triadica/lagopus": "0.1.1",
"@triadica/lagopus": "0.2.0",
"@triadica/touch-control": "^0.0.4-a1",
"ismobilejs": "^1.1.1"
},
Expand Down
6 changes: 5 additions & 1 deletion vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 7,11 @@ export default defineConfig({
// include: /wgsl/i,
}),
],

build: {
rollupOptions: {
treeshake: false,
},
},
optimizeDeps: {
exclude: ["@triadica/lagopus/lib/comp/bottom.mjs", "@triadica/lagopus"],
},
Expand Down
Loading

0 comments on commit 675783f

Please sign in to comment.