-
-
Notifications
You must be signed in to change notification settings - Fork 48
docs: Rotating Triangle Tiles example #2048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
📊 Bundle Size Comparison
👀 Notable resultsStatic test results:No major changes. Dynamic test results:No major changes. 📋 All resultsClick to reveal the results table (331 entries).
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu. |
|
pkg.pr.new packages benchmark commit |
f658ee6 to
5086460
Compare
7b8d09b to
2ce6e6c
Compare
aleksanderkatan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great first example! 🦋
I tried to be educational in the comments, so many of them are not necessarily issues but stylistic preferences, nits or good practices.
If you have no time to address these comments, we can take over, no problem
| @@ -0,0 +1,49 @@ | |||
| // Generate by AI | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you find some human made implementation and reference the author instead? Or, if it's just some wikipedia formulas, just remove this line
| const shiftedColorsBuffer = root.createReadonly(d.arrayOf(d.vec4f, 3), [ | ||
| ...colors, | ||
| ]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vectors already are arrays (with some extra steps)
| const shiftedColorsBuffer = root.createReadonly(d.arrayOf(d.vec4f, 3), [ | |
| ...colors, | |
| ]); | |
| const shiftedColorsBuffer = root.createReadonly(d.arrayOf(d.vec4f, 3), colors); |
| "tags": ["experimental", "fragment shader", "instancing"], | ||
| "dev": false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "tags": ["experimental", "fragment shader", "instancing"], | |
| "dev": false | |
| "tags": ["experimental", "fragment shader", "instancing"] |
| function getCubicBezierControlPoints() { | ||
| return cubicBezierControlPoints; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this function be inlined?
| const GridParams = d.struct({ | ||
| tileDensity: d.f32, | ||
| userScale: d.f32, | ||
| trianglesPerRow: d.u32, | ||
| triangleCount: d.u32, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this struct is unused
| let calculatedPosition = rotate(vertexPosition, angle); | ||
| calculatedPosition = std.mul(calculatedPosition, scaleFactor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we support infix operators for +-*/
| let calculatedPosition = rotate(vertexPosition, angle); | |
| calculatedPosition = std.mul(calculatedPosition, scaleFactor); | |
| const calculatedPosition = rotate(vertexPosition, angle).mul(scaleFactor); |
| if ((e0 > 0 || e1 > 0 || e2 > 0) && drawOverNeighborsAccess.$ === 0) { | ||
| std.discard(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This drawOverNeighbors switch has made this shader a lot more complicated. Without this, we could probably simplify everything to only one straightforward pipeline.
I tried to come up with something to avoid passing so much flat interpolated data and without discard. We could theoretically create a static stencil like the following:
And use it for "odd" triangles, use a negative stencil for "even" triangles, and no stencil for the front layer. Maybe @reczkok can come up with something better.
| const stepRotationAccess = tgpu['~unstable'].accessor(d.f32); | ||
| const shiftedColorsAccess = tgpu['~unstable'].accessor(d.arrayOf(d.vec4f, 3)); | ||
| const animationProgressAccess = tgpu['~unstable'].accessor(d.f32); | ||
| const middleSquareScaleAccess = tgpu['~unstable'].accessor(d.f32); | ||
| const drawOverNeighborsAccess = tgpu['~unstable'].accessor(d.u32); | ||
| const scaleAccess = tgpu['~unstable'].accessor(d.f32); | ||
| const aspectRatioAccess = tgpu['~unstable'].accessor(d.f32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tip: There is a pretty small limit of buffers that can be used without bind groups, usually it's only 12 (because this is the minimum limit for a single bind group, and those are bound under the hood). A simple way to avoid it is to group those into structs. In this case, it is not necessary, though it might clean up the code a little bit.
| aspectRatioBuffer.write(aspectRatio); | ||
| } | ||
|
|
||
| let animationDuration = 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is kept between example switches (triangles -> sth else -> triangles). It's just a number so this probably does not matter.
| // Example controls | ||
|
|
||
| export const controls = { | ||
| 'Tile density': { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In examples we usually start controls' names with lowercase letters (exception: buttons)
Triangle tiles that rotate.