-
-
Notifications
You must be signed in to change notification settings - Fork 63
docs: Compute radiance cascades (fast) #1987
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
Draft
reczkok
wants to merge
26
commits into
main
Choose a base branch
from
docs/compute-gi-rc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
eac8d16
init
reczkok f75dd66
first pass of fixes and simplifications
reczkok 226589e
clean up and simlify
reczkok 05d254a
move to morton order and use hardware sampling
reczkok 69df43f
move to direction first
reczkok 59ee9dc
work
reczkok 9440c6b
more work
reczkok 77561ca
cleanup
reczkok a677387
more work
reczkok 98193b5
Merge branch 'main' into docs/compute-gi-rc
reczkok 351d7f3
remove post merge conflict
reczkok 96fec65
work work
reczkok eced493
Merge branch 'main' into docs/compute-gi-rc
reczkok 0f6b2f3
refine and simpligy
reczkok 15324e3
Merge branch 'main' into docs/compute-gi-rc
reczkok ea1ecac
Merge branch 'main' into docs/compute-gi-rc
reczkok 21e177d
fix ci
reczkok bbe3d5c
work
reczkok 2e35439
fixes&tweaks
reczkok 0cafd39
Merge branch 'main' into docs/compute-gi-rc
reczkok ab0d227
Merge branch 'main' into docs/compute-gi-rc
reczkok 2103feb
Merge branch 'main' into docs/compute-gi-rc
reczkok 225ff52
cleaner + tsovver
reczkok 1665fcb
improve
reczkok 24fb17c
typo
reczkok 49d0790
Merge branch 'main' into docs/compute-gi-rc
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
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
102 changes: 102 additions & 0 deletions
102
apps/typegpu-docs/src/examples/rendering/radiance-compute/drag-controller.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,102 @@ | ||
| import { sdBox2d, sdDisk } from '@typegpu/sdf'; | ||
| import type { AnySceneElement } from './scene.ts'; | ||
| import { sceneElements } from './scene.ts'; | ||
| import * as d from 'typegpu/data'; | ||
|
|
||
| type DragTarget = AnySceneElement; | ||
|
|
||
| export class DragController { | ||
| private isDragging = false; | ||
| private draggedElement: DragTarget | null = null; | ||
|
|
||
| constructor( | ||
| private canvas: HTMLCanvasElement, | ||
| private onDragMove: (id: string, position: d.v2f) => void, | ||
| private onDragEnd: (id: string, position: d.v2f) => void, | ||
| ) { | ||
| this.setupEventListeners(); | ||
| } | ||
|
|
||
| private canvasToUV(clientX: number, clientY: number): d.v2f { | ||
| const rect = this.canvas.getBoundingClientRect(); | ||
| const x = (clientX - rect.left) / rect.width; | ||
| const y = (clientY - rect.top) / rect.height; | ||
| return d.vec2f(x, y); | ||
| } | ||
|
|
||
| private hitTestDisk(uv: d.v2f, center: d.v2f, radius: number): boolean { | ||
| return sdDisk(uv.sub(center), radius) <= 0; | ||
| } | ||
|
|
||
| private hitTestBox(uv: d.v2f, center: d.v2f, size: d.v2f): boolean { | ||
| return sdBox2d(uv.sub(center), size) <= 0; | ||
| } | ||
|
|
||
| private hitTest(clientX: number, clientY: number): DragTarget | null { | ||
| const uv = this.canvasToUV(clientX, clientY); | ||
| for (const el of sceneElements) { | ||
| const hit = | ||
| el.type === 'disk' | ||
| ? this.hitTestDisk(uv, el.position, el.size) | ||
| : this.hitTestBox(uv, el.position, el.size); | ||
| if (hit) { | ||
| return el; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| private setupEventListeners() { | ||
| this.canvas.addEventListener('mousedown', this.onMouseDown); | ||
| this.canvas.addEventListener('mousemove', this.onMouseMove); | ||
| this.canvas.addEventListener('mouseup', this.onMouseUp); | ||
| this.canvas.addEventListener('mouseleave', this.onMouseLeave); | ||
| } | ||
|
|
||
| private onMouseDown = (e: MouseEvent) => { | ||
| const target = this.hitTest(e.clientX, e.clientY); | ||
| if (target) { | ||
| this.isDragging = true; | ||
| this.draggedElement = target; | ||
| this.canvas.style.cursor = 'grabbing'; | ||
| } | ||
| }; | ||
|
|
||
| private onMouseMove = (e: MouseEvent) => { | ||
| if (!this.isDragging || !this.draggedElement) { | ||
| const target = this.hitTest(e.clientX, e.clientY); | ||
| this.canvas.style.cursor = target ? 'grab' : 'default'; | ||
| return; | ||
| } | ||
|
|
||
| const newPos = this.canvasToUV(e.clientX, e.clientY); | ||
| this.onDragMove(this.draggedElement.id, newPos); | ||
| }; | ||
|
|
||
| private onMouseUp = (e: MouseEvent) => { | ||
| if (this.isDragging && this.draggedElement) { | ||
| const finalPos = this.canvasToUV(e.clientX, e.clientY); | ||
| this.onDragEnd(this.draggedElement.id, finalPos); | ||
| this.isDragging = false; | ||
| this.draggedElement = null; | ||
|
|
||
| const target = this.hitTest(e.clientX, e.clientY); | ||
| this.canvas.style.cursor = target ? 'grab' : 'default'; | ||
| } | ||
| }; | ||
|
|
||
| private onMouseLeave = () => { | ||
| if (this.isDragging) { | ||
| this.isDragging = false; | ||
| this.draggedElement = null; | ||
| this.canvas.style.cursor = 'default'; | ||
| } | ||
| }; | ||
|
|
||
| destroy() { | ||
| this.canvas.removeEventListener('mousedown', this.onMouseDown); | ||
| this.canvas.removeEventListener('mousemove', this.onMouseMove); | ||
| this.canvas.removeEventListener('mouseup', this.onMouseUp); | ||
| this.canvas.removeEventListener('mouseleave', this.onMouseLeave); | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
apps/typegpu-docs/src/examples/rendering/radiance-compute/index.html
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 @@ | ||
| <canvas></canvas> |
Oops, something went wrong.
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.
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.
Maybe we could expose constants like max, min, epsilon for each data type, like IEEE754 specifies?