-
-
Notifications
You must be signed in to change notification settings - Fork 43
docs/fix: Add point light shadow example #1937
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5035c4e
temp not working
reczkok 5ef2920
first working version kinda
reczkok 08a9bce
temp
reczkok 9c2d5cf
working (for some reason)
reczkok 8d7dff9
cleanup
reczkok afc1f47
sane coordinate system and msaa
reczkok b69593a
move to instancing
reczkok 998cae7
mucho trabajo
reczkok 47930cb
Merge branch 'main' into docs/point-light-shadow
reczkok 976e823
add thumbnail
reczkok 9b3ab17
add test
reczkok 932240a
performance improvements (move some alu work to precomputed memory re…
reczkok b216583
update test
reczkok 62b9a27
review fixes
reczkok 7f568a6
update test
reczkok b907b06
nicities and fixes
reczkok 9db4a2a
Update packages/typegpu/tests/examples/individual/point-light-shadow.…
reczkok a938753
last fix
reczkok dcc8770
Merge branch 'main' into docs/point-light-shadow
reczkok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reczkok marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
apps/typegpu-docs/src/examples/rendering/point-light-shadow/box-geometry.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import type { IndexFlag, TgpuBuffer, TgpuRoot, VertexFlag } from 'typegpu'; | ||
| import * as d from 'typegpu/data'; | ||
| import type { GeometryData } from './types.ts'; | ||
| import { InstanceData, VertexData } from './types.ts'; | ||
|
|
||
| export class BoxGeometry { | ||
| static #vertexBuffer: | ||
| | (TgpuBuffer<d.WgslArray<VertexData>> & VertexFlag) | ||
| | null = null; | ||
| static #indexBuffer: (TgpuBuffer<d.WgslArray<d.U16>> & IndexFlag) | null = | ||
| null; | ||
| static #indexCount = 0; | ||
|
|
||
| #modelMatrix = d.mat4x4f.identity(); | ||
| #position = d.vec3f(0, 0, 0); | ||
| #scale = d.vec3f(1, 1, 1); | ||
| #rotation = d.vec3f(0, 0, 0); | ||
|
|
||
| constructor(root: TgpuRoot) { | ||
| if (!BoxGeometry.#vertexBuffer || !BoxGeometry.#indexBuffer) { | ||
| this.#initBuffers(root); | ||
| } | ||
| } | ||
|
|
||
| #initBuffers(root: TgpuRoot) { | ||
| const vertices: GeometryData = []; | ||
| const indices: number[] = []; | ||
| let vertexOffset = 0; | ||
|
|
||
| const addFace = ( | ||
| u: number, | ||
| v: number, | ||
| w: number, | ||
| udir: number, | ||
| vdir: number, | ||
| depth: number, | ||
| ) => { | ||
| for (let iy = 0; iy < 2; iy++) { | ||
| for (let ix = 0; ix < 2; ix++) { | ||
| const pos = [0, 0, 0]; | ||
| pos[u] = (ix - 0.5) * udir; | ||
| pos[v] = (iy - 0.5) * vdir; | ||
| pos[w] = 0.5 * Math.sign(depth); | ||
|
|
||
| const norm = [0, 0, 0]; | ||
| norm[w] = Math.sign(depth); | ||
|
|
||
| vertices.push( | ||
| { | ||
| position: d.vec3f(pos[0], pos[1], pos[2]), | ||
| normal: d.vec3f(norm[0], norm[1], norm[2]), | ||
| uv: d.vec2f(ix, 1 - iy), | ||
| }, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| indices.push( | ||
| vertexOffset, | ||
| vertexOffset + 1, | ||
| vertexOffset + 2, | ||
| vertexOffset + 1, | ||
| vertexOffset + 3, | ||
| vertexOffset + 2, | ||
| ); | ||
| vertexOffset += 4; | ||
| }; | ||
|
|
||
| addFace(2, 1, 0, -1, 1, 1); // +X | ||
| addFace(2, 1, 0, 1, 1, -1); // -X | ||
| addFace(0, 2, 1, 1, 1, 1); // +Y | ||
| addFace(0, 2, 1, 1, -1, -1); // -Y | ||
| addFace(0, 1, 2, 1, 1, 1); // +Z | ||
| addFace(0, 1, 2, -1, 1, -1); // -Z | ||
|
|
||
| BoxGeometry.#vertexBuffer = root | ||
| .createBuffer(d.arrayOf(VertexData, vertices.length), vertices) | ||
| .$usage('vertex'); | ||
| BoxGeometry.#indexBuffer = root | ||
| .createBuffer(d.arrayOf(d.u16, indices.length), indices) | ||
| .$usage('index'); | ||
| BoxGeometry.#indexCount = indices.length; | ||
| } | ||
|
|
||
| set position(value: d.v3f) { | ||
| this.#position = value; | ||
| this.#updateModelMatrix(); | ||
| } | ||
|
|
||
| get position() { | ||
| return this.#position; | ||
| } | ||
|
|
||
| set scale(value: d.v3f) { | ||
| this.#scale = value; | ||
| this.#updateModelMatrix(); | ||
| } | ||
|
|
||
| get scale() { | ||
| return this.#scale; | ||
| } | ||
|
|
||
| set rotation(value: d.v3f) { | ||
| this.#rotation = value; | ||
| this.#updateModelMatrix(); | ||
| } | ||
|
|
||
| get rotation() { | ||
| return this.#rotation; | ||
| } | ||
|
|
||
| get instanceData(): d.Infer<InstanceData> { | ||
| return InstanceData({ | ||
| column1: this.#modelMatrix.columns[0], | ||
| column2: this.#modelMatrix.columns[1], | ||
| column3: this.#modelMatrix.columns[2], | ||
| column4: this.#modelMatrix.columns[3], | ||
| }); | ||
| } | ||
|
|
||
| static get vertexBuffer() { | ||
| if (!BoxGeometry.#vertexBuffer) { | ||
| throw new Error('BoxGeometry buffers not initialized'); | ||
| } | ||
| return BoxGeometry.#vertexBuffer; | ||
| } | ||
|
|
||
| static get indexBuffer() { | ||
| if (!BoxGeometry.#indexBuffer) { | ||
| throw new Error('BoxGeometry buffers not initialized'); | ||
| } | ||
| return BoxGeometry.#indexBuffer; | ||
| } | ||
|
|
||
| static get indexCount() { | ||
| return BoxGeometry.#indexCount; | ||
| } | ||
|
|
||
| static clearBuffers() { | ||
| BoxGeometry.#vertexBuffer = null; | ||
| BoxGeometry.#indexBuffer = null; | ||
| } | ||
reczkok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #updateModelMatrix() { | ||
| this.#modelMatrix = d.mat4x4f | ||
| .translation(this.#position) | ||
| .mul(d.mat4x4f.rotationZ(this.#rotation.z)) | ||
| .mul(d.mat4x4f.rotationY(this.#rotation.y)) | ||
| .mul(d.mat4x4f.rotationX(this.#rotation.x)) | ||
| .mul(d.mat4x4f.scaling(this.#scale)); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.