Skip to content

Commit

Permalink
Merge pull request #22 from Triadica/import-syntax
Browse files Browse the repository at this point in the history
switch to bevy import syntax
  • Loading branch information
NoEgAm authored Dec 18, 2023
2 parents 5a70ba7 + 129164a commit 7d5a027
Show file tree
Hide file tree
Showing 20 changed files with 356 additions and 448 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/upload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ jobs:

- uses: supplypike/setup-bin@v3
with:
uri: 'https://github.com/calcit-lang/calcit/releases/download/0.8.9/cr'
uri: 'https://github.com/calcit-lang/calcit/releases/download/0.8.14/cr'
name: 'cr'
version: '0.8.9'
version: '0.8.14'

- uses: supplypike/setup-bin@v3
with:
uri: 'https://github.com/calcit-lang/calcit/releases/download/0.8.9/caps'
uri: 'https://github.com/calcit-lang/calcit/releases/download/0.8.14/caps'
name: 'caps'
version: '0.8.9'
version: '0.8.14'

- name: "compiles to js"
run: >
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,28 +267,28 @@ Math functions in `lagopus.math`

### Shader functions

`{{perspective}}`
`#import lagopus::perspective`

- `fn transform_perspective(p: vec3f) -> PointResult`

`{{colors}}`
`#import lagopus::colors`

- `fn hsl2rgb(hsl: vec3f) -> vec3f`
- `fn hsl(h: f32, s: f32, l: f32) -> vec3f`

`{{rand}}`
`#import lagopus::rand`

- `fn rand(n: f32) -> f32`
- `fn rand_balanced(n: f32) -> f32`
- `fn noise(p: f32) -> f32`
- `fn rand2(n: vec2<f32>) -> f32`
- `fn noise2(n: vec2<f32>) -> f32`

`{{simplex}}`
`#import lagopus::simplex`

- `fn simplexNoise2(v: vec2<f32>) -> f32`

`{{hsluv}}`
`#import lagopus::hsluv`

- `fn hsluvToRgb(tuple: vec3f) -> vec3f` based on 360 and 100

Expand Down
26 changes: 13 additions & 13 deletions calcit.cirru

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 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.4.3)
:configs $ {} (:init-fn |lagopus.main/main!) (:reload-fn |lagopus.main/reload!) (:version |0.5.1)
:modules $ [] |memof/ |quaternion/
:entries $ {}
:files $ {}
Expand Down Expand Up @@ -79,7 +79,7 @@
|inject-shader-snippets $ %{} :CodeEntry (:doc |)
:code $ quote
defn inject-shader-snippets (code)
-> code (.!replace "\"{{simplex}}" wgsl-simplex) (.!replace "\"{{perspective}}" wgsl-perspective) (.!replace "\"{{colors}}" wgsl-colors) (.!replace "\"{{rand}}" wgsl-rand) (.!replace "\"{{rotation}}" wgsl-rotation) (.!replace "\"{{hsluv}}" wgsl-hsluv)
-> 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)
|object $ %{} :CodeEntry (:doc |)
:code $ quote
defn object (options)
Expand Down Expand Up @@ -119,7 +119,7 @@
collect! $ fn (x) (.!push *arr x )
collect-array! indices collect!
, *arr
&map:get options :add-uniform
&map:get options :get-params
|object-writer $ %{} :CodeEntry (:doc |)
:code $ quote
defn object-writer (options)
Expand Down Expand Up @@ -169,7 +169,7 @@
collect! $ fn (x) (.!push *arr x)
collect-array! indices collect!
, *arr
&map:get options :add-uniform
&map:get options :get-params
|wgsl-colors $ %{} :CodeEntry (:doc |)
:code $ quote
def wgsl-colors $ inline-shader "\"lagopus-colors"
Expand Down Expand Up @@ -760,7 +760,7 @@
&doseq (x p) (build-polyline-points-marked *prev x write!)
build-polyline-points-marked *prev p write!
chunk-writer! collect!
:add-uniform $ &map:get options :add-uniform
:get-params $ &map:get options :get-params
|count-hex $ %{} :CodeEntry (:doc |)
:code $ quote
defn count-hex (xs)
Expand Down Expand Up @@ -868,7 +868,7 @@
&< (&+ idx j) (dec iteration)
[] (:: :vertex ps3 c1) (:: :vertex ps1 c1) (:: :vertex ps2 c1)
[]
:add-uniform $ fn () (js-array & color chromatism)
:get-params $ fn () (js-array & color chromatism)
|sqrt-3 $ %{} :CodeEntry (:doc |)
:code $ quote
def sqrt-3 $ sqrt 3
Expand Down Expand Up @@ -925,7 +925,7 @@
:data $ -> unit-triangles
map $ fn (xs)
build-sphere-triangles base radius iteration *counter (nth xs 0) (nth xs 1) (nth xs 2)
:add-uniform $ fn () (js-array & color 1)
:get-params $ fn () (js-array & color 1)
|pick-radian-middle $ %{} :CodeEntry (:doc |)
:code $ quote
defn pick-radian-middle (p0 p1)
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "0.4.3",
"version": "0.5.1",
"dependencies": {
"@calcit/procs": "^0.8.9",
"@calcit/procs": "^0.8.14",
"@calcit/std": "^0.0.3",
"@triadica/lagopus": "^0.0.18",
"@triadica/lagopus": "^0.0.19",
"@triadica/touch-control": "^0.0.4-a1",
"ismobilejs": "^1.1.1"
},
"devDependencies": {
"bottom-tip": "^0.1.5",
"vite": "^4.5.0",
"vite-plugin-glsl": "^1.1.2"
"vite": "^5.0.10",
"vite-plugin-glsl": "^1.2.1"
}
}
22 changes: 4 additions & 18 deletions shaders/axis.wgsl
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
struct UBO {
cone_back_scale: f32,
viewport_ratio: f32,
look_distance: f32,
scale: f32,
forward: vec3f,
// direction up overhead, better unit vector
upward: vec3f,
rightward: vec3f,
camera_position: vec3f,
};

@group(0) @binding(0)
var<uniform> uniforms: UBO;

{{perspective}}
#import lagopus::perspective

{{colors}}
#import lagopus::colors

{{hsluv}}
#import lagopus::hsluv

// main

Expand Down Expand Up @@ -46,7 +32,7 @@ fn vertex_main(
next = -next;
}
let brush_direction = normalize(next);
if brush == 1 {
if brush == 1u {
p1 += brush_direction * width * 0.5;
} else {
p1 -= brush_direction * width * 0.5;
Expand Down
24 changes: 4 additions & 20 deletions shaders/bubbles.wgsl
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@

struct UBO {
cone_back_scale: f32,
viewport_ratio: f32,
look_distance: f32,
scale: f32,
forward: vec3f,
// direction up overhead, better unit vector
upward: vec3f,
rightward: vec3f,
camera_position: vec3f,
_pad: u32,
};

@group(0) @binding(0)
var<uniform> uniforms: UBO;

{{perspective}}
#import lagopus::perspective

{{rand}}
#import lagopus::rand

{{colors}}
#import lagopus::colors

// main

Expand Down Expand Up @@ -51,7 +35,7 @@ fn vertex_main(

@fragment
fn fragment_main(vtx_out: VertexOut) -> @location(0) vec4f {
let dim = min(1, (1 / pow(vtx_out.s, 1.6)) + 0.02);
let dim = min(1., (1. / pow(vtx_out.s, 1.6)) + 0.02);
let l = (cos(vtx_out.radian * 1.8 - 1.8) * 0.3 + 0.76);
return vec4f(l, l, l, l * dim);
}
20 changes: 3 additions & 17 deletions shaders/city.wgsl
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
struct UBO {
cone_back_scale: f32,
viewport_ratio: f32,
look_distance: f32,
scale: f32,
forward: vec3f,
// direction up overhead, better unit vector
upward: vec3f,
rightward: vec3f,
camera_position: vec3f,
};

@group(0) @binding(0)
var<uniform> uniforms: UBO;

const ALL_HEIGHT: f32 = 2000.0;
#import lagopus::perspective

{{perspective}}
#import lagopus::simplex

{{simplex}}
const ALL_HEIGHT: f32 = 2000.0;

// main

Expand Down
18 changes: 2 additions & 16 deletions shaders/cube.wgsl
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
struct UBO {
cone_back_scale: f32,
viewport_ratio: f32,
look_distance: f32,
scale: f32,
forward: vec3f,
// direction up overhead, better unit vector
upward: vec3f,
rightward: vec3f,
camera_position: vec3f,
};

@group(0) @binding(0)
var<uniform> uniforms: UBO;

{{perspective}}
#import lagopus::perspective

{{simplex}}
#import lagopus::simplex

// main

Expand Down
22 changes: 4 additions & 18 deletions shaders/curves.wgsl
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
struct UBO {
cone_back_scale: f32,
viewport_ratio: f32,
look_distance: f32,
scale: f32,
forward: vec3f,
// direction up overhead, better unit vector
upward: vec3f,
rightward: vec3f,
camera_position: vec3f,
};

@group(0) @binding(0)
var<uniform> uniforms: UBO;

{{perspective}}
#import lagopus::perspective

{{colors}}
#import lagopus::colors

// main

Expand Down Expand Up @@ -45,7 +31,7 @@ fn vertex_main(
next = -next;
}
let brush_direction = normalize(next);
if brush == 1 {
if brush == 1u {
p1 += brush_direction * width * 0.5;
} else {
p1 -= brush_direction * width * 0.5;
Expand All @@ -67,5 +53,5 @@ const limit: f32 = 48.0;
@fragment
fn fragment_main(vtx_out: VertexOut) -> @location(0) vec4f {
// return vec4f(vtx_out.color, 1.0);
return vec4(0.7, 0.7, 0.7, 1);
return vec4(0.7, 0.7, 0.7, 1.);
}
Loading

0 comments on commit 7d5a027

Please sign in to comment.