Skip to content
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

v0.9.0 #95

Merged
merged 36 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
67e763f
- Added a `Raycaster` extra class.
martinlaxenaire Nov 15, 2024
b4deba2
- Raycaster throw warning only when not on production mode
martinlaxenaire Nov 18, 2024
5693e8d
Merge pull request #87 from martinlaxenaire/raycaster
martinlaxenaire Nov 18, 2024
ef8ba09
- basic render bundle implementation
martinlaxenaire Nov 19, 2024
5fba922
- first working version with special scene bundle stacks
martinlaxenaire Nov 25, 2024
3b794a1
- render bundles implementation
martinlaxenaire Nov 26, 2024
1174595
- fixed shadow rendering when a mesh has a render bundle
martinlaxenaire Nov 26, 2024
de9f1d7
- updated website, examples, tests
martinlaxenaire Nov 29, 2024
83a3b5d
- fixed render bundle size change performance issue
martinlaxenaire Nov 29, 2024
3bfae00
- updated render bundle stress test
martinlaxenaire Dec 2, 2024
17b94a9
Merge pull request #88 from martinlaxenaire/render-bundles-test
martinlaxenaire Dec 2, 2024
abb6a91
- added WebGPU bitwise flags fallbacks
martinlaxenaire Dec 2, 2024
3916f97
Merge pull request #89 from martinlaxenaire/fix-webgpu-bitwise-flags
martinlaxenaire Dec 2, 2024
871ed7d
First draft for a better lights and shadows renderer management:
martinlaxenaire Dec 3, 2024
b19f132
- added a new `setRenderer` method to the material classes (materials…
martinlaxenaire Dec 3, 2024
e07fce2
- updated test
martinlaxenaire Dec 3, 2024
fbcd7bf
- add a `setRenderer` method to `ComputePass` as well.
martinlaxenaire Dec 3, 2024
ec174fd
- updated test / website
martinlaxenaire Dec 4, 2024
170894b
- improved WebGPU push / pop debug groups
martinlaxenaire Dec 4, 2024
19279b9
- updated shadows shaders to use `if` statements instead of `select` …
martinlaxenaire Dec 6, 2024
2b8bcce
Merge pull request #90 from martinlaxenaire/lights-set-renderer-runtime
martinlaxenaire Dec 6, 2024
805d1cd
- refactored `BufferBinding`: changed `bindings` param to `childrenBi…
martinlaxenaire Dec 9, 2024
e05c3a8
- removed `BufferBindingOffsetChild` class and handle parent binding …
martinlaxenaire Dec 9, 2024
994b740
- ability to disable `lights` for a renderer to improve memory footprint
martinlaxenaire Dec 10, 2024
c99cf86
Merge pull request #91 from martinlaxenaire/buffer-binding-parent-chi…
martinlaxenaire Dec 10, 2024
09bbdba
chore(deps): updated dev dependencies
martinlaxenaire Dec 10, 2024
1d3e28d
Merge pull request #92 from martinlaxenaire/security-update-12-2024
martinlaxenaire Dec 10, 2024
40d37e5
- new `EnvironmentMap` class that uses `HDRLoader` to load .hdr files…
martinlaxenaire Dec 13, 2024
e9492ba
- cleaned up test
martinlaxenaire Dec 13, 2024
4ad565a
- fixed `EnvironmentMap` max `diffuseTexture` size
martinlaxenaire Dec 14, 2024
1513758
- updated stress tests to allow configure nb meshes in url
martinlaxenaire Dec 14, 2024
f3d3799
Merge pull request #93 from martinlaxenaire/hdr-loader-compute
martinlaxenaire Dec 16, 2024
a0ec371
- Added a new `context` parameter to the `GPURenderer` and other rend…
martinlaxenaire Dec 16, 2024
9b2ca7c
Merge pull request #94 from martinlaxenaire/renderer-context
martinlaxenaire Dec 16, 2024
5e46507
v0.9.0
martinlaxenaire Dec 16, 2024
60fc7d6
v0.9.0
martinlaxenaire Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

### DOM 2 WebGPU rendering engine

gpu-curtains is a small, lightweight WebGPU rendering engine library.
gpu-curtains is a small, lightweight 3D WebGPU rendering engine library.

Although it can theoretically be used as a genuine 3D engine, its main purpose is to turn HTML elements into textured planes, allowing you to animate them via WGSL shaders.
It can be used as a standalone 3D engine, but also includes extra classes designed to turn HTML elements into textured planes or meshes, allowing you to animate them via WGSL shaders.

The project was initially conceived as a WebGPU port of [curtains.js](https://github.com/martinlaxenaire/curtainsjs). It turned out to be a complete rewrite of the library instead, but with a very similar API.

Expand Down Expand Up @@ -168,9 +168,9 @@ window.addEventListener('load', async () => {

## Limitations

gpu-curtains is mostly made to create quads based on HTML elements, it may lack some common 3D engines features (even tho it is slowly evolving towards a real 3D engine).
gpu-curtains is a slowly evolving 3D engine and may lack some common features.

If you need a more robust 3D engine that could handle complex geometries or advanced rendering mechanics, then you should probably go with another library like [three.js](https://github.com/mrdoob/three.js) or [Babylon.js](https://github.com/BabylonJS).
If you need a more robust 3D engine that could handle complex glTF or advanced lighting, shading or rendering mechanics, then you should probably go with another library like [three.js](https://github.com/mrdoob/three.js) or [Babylon.js](https://github.com/BabylonJS).

## Contributing

Expand Down
15 changes: 9 additions & 6 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
- Camera
- Geometries
- Materials (Material, RenderMaterial, ComputeMaterial)
- Buffer & Bindings & BindGroups
- Buffers & Bindings & BindGroups
- Render + Compute Pipelines (async by default)
- PipelineManager to cache RenderPipeline + set only needed BindGroup
- PipelineManager to cache RenderPipelineEntry and ComputePipelineEntry + set only needed BindGroup
- Meshes (Mesh, DOMMesh, FullscreenPlane, Plane)
- Compute passes
- Texture (including storage & depth) & DOMTexture classes
Expand All @@ -20,12 +20,14 @@
- Lights & Shadows
- Shader passes
- PingPongPlane
- Plane raycasting
- RenderBundle
- Basic CacheManager
- Scroll + resize, frustum culling check
- GPUCurtains
- OrbitControls
- Raycaster
- GLTFLoader + GLTFScenesManager
- HDRLoader + EnvironmentMap

## Work in progress

Expand All @@ -34,9 +36,10 @@
## TODO / possible improvements

- Add/improve GLTFScenesManager features (sparse accessors, animations, morphing, skinning...)
- Mesh raycasting
- Add more lights (SpotLight...)
- MSDF fonts
- Better shader chunks system and/or custom preprocessor
- Implement different lit extras RenderMaterial (i.e. RenderLambertMaterial, RenderPhongMaterial, RenderPBRMaterial, etc.)?
- Implement indirect draw calls?
- Improve typedoc documentation?
- Use render bundles? Probably not suited to the library tho
- Use indirect draw calls?
- More examples & tests?
26 changes: 22 additions & 4 deletions dist/esm/core/DOM/DOMFrustum.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class DOMFrustum {
this.modelViewProjectionMatrix = modelViewProjectionMatrix;
this.containerBoundingRect = containerBoundingRect;
this.DOMFrustumMargins = { ...defaultDOMFrustumMargins, ...DOMFrustumMargins };
this.clipSpaceBoundingRect = {
top: 0,
left: 0,
width: 0,
height: 0
};
this.projectedBoundingRect = {
top: 0,
right: 0,
Expand Down Expand Up @@ -82,6 +88,12 @@ class DOMFrustum {
*/
setDocumentCoordsFromClipSpaceOBB() {
this.computeClipSpaceOBB();
this.clipSpaceBoundingRect = {
top: this.clipSpaceOBB.max.y,
left: this.clipSpaceOBB.min.x,
width: this.clipSpaceOBB.max.x - this.clipSpaceOBB.min.x,
height: this.clipSpaceOBB.max.y - this.clipSpaceOBB.min.y
};
const minX = (this.clipSpaceOBB.min.x + 1) * 0.5;
const maxX = (this.clipSpaceOBB.max.x + 1) * 0.5;
const minY = 1 - (this.clipSpaceOBB.min.y + 1) * 0.5;
Expand All @@ -103,15 +115,21 @@ class DOMFrustum {
* @param boundingSphere - bounding sphere in clip space.
*/
setDocumentCoordsFromClipSpaceSphere(boundingSphere = { center: new Vec3(), radius: 0 }) {
this.clipSpaceBoundingRect = {
top: boundingSphere.center.y + boundingSphere.radius,
left: boundingSphere.center.x - boundingSphere.radius,
width: boundingSphere.radius * 2,
height: boundingSphere.radius * 2
};
const centerX = (boundingSphere.center.x + 1) * 0.5;
const centerY = 1 - (boundingSphere.center.y + 1) * 0.5;
const { width, height, top, left } = this.containerBoundingRect;
this.projectedBoundingRect.width = boundingSphere.radius * height * 0.5;
this.projectedBoundingRect.height = boundingSphere.radius * height * 0.5;
this.projectedBoundingRect.width = boundingSphere.radius * height;
this.projectedBoundingRect.height = boundingSphere.radius * height;
this.projectedBoundingRect.left = centerX * width + left - this.projectedBoundingRect.width * 0.5;
this.projectedBoundingRect.x = centerX * width + left - this.projectedBoundingRect.width * 0.5;
this.projectedBoundingRect.x = this.projectedBoundingRect.left;
this.projectedBoundingRect.top = centerY * height + top - this.projectedBoundingRect.height * 0.5;
this.projectedBoundingRect.y = centerY * height + top - this.projectedBoundingRect.height * 0.5;
this.projectedBoundingRect.y = this.projectedBoundingRect.top;
this.projectedBoundingRect.right = this.projectedBoundingRect.left + this.projectedBoundingRect.width;
this.projectedBoundingRect.bottom = this.projectedBoundingRect.top + this.projectedBoundingRect.height;
}
Expand Down
44 changes: 34 additions & 10 deletions dist/esm/core/bindGroups/BindGroup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class BindGroup {
this.consumers = /* @__PURE__ */ new Set();
for (const binding of this.bufferBindings) {
if ("buffer" in binding) {
binding.buffer.consumers.add(this.uuid);
if (binding.parent) {
binding.parent.buffer.consumers.add(this.uuid);
} else {
binding.buffer.consumers.add(this.uuid);
}
}
if ("resultBuffer" in binding) {
binding.resultBuffer.consumers.add(this.uuid);
Expand All @@ -57,8 +61,13 @@ class BindGroup {
addBindings(bindings = []) {
bindings.forEach((binding) => {
if ("buffer" in binding) {
this.renderer.deviceManager.bufferBindings.set(binding.cacheKey, binding);
binding.buffer.consumers.add(this.uuid);
if (binding.parent) {
this.renderer.deviceManager.bufferBindings.set(binding.parent.cacheKey, binding.parent);
binding.parent.buffer.consumers.add(this.uuid);
} else {
this.renderer.deviceManager.bufferBindings.set(binding.cacheKey, binding);
binding.buffer.consumers.add(this.uuid);
}
}
});
this.bindings = [...this.bindings, ...bindings];
Expand All @@ -81,6 +90,13 @@ class BindGroup {
if (!binding.buffer.consumers.size) {
binding.buffer.destroy();
}
if (binding.parent) {
binding.parent.buffer.consumers.delete(this.uuid);
if (!binding.parent.buffer.consumers.size) {
this.renderer.removeBuffer(binding.parent.buffer);
binding.parent.buffer.destroy();
}
}
}
if ("resultBuffer" in binding) {
this.renderer.removeBuffer(binding.resultBuffer);
Expand Down Expand Up @@ -230,6 +246,9 @@ class BindGroup {
this.resetEntries();
for (const binding of this.bufferBindings) {
binding.buffer.reset();
if (binding.parent) {
binding.parent.buffer.reset();
}
if ("resultBuffer" in binding) {
binding.resultBuffer.reset();
}
Expand Down Expand Up @@ -258,12 +277,13 @@ class BindGroup {
);
}
/**
* Creates binding GPUBuffer with correct params
* @param binding - the binding element
* Creates binding GPUBuffer with correct params.
* @param binding - The binding element.
* @param optionalLabel - Optional label to use for the {@link GPUBuffer}.
*/
createBindingBuffer(binding) {
createBindingBuffer(binding, optionalLabel = null) {
binding.buffer.createBuffer(this.renderer, {
label: this.options.label + ": " + binding.bindingType + " buffer from: " + binding.label,
label: optionalLabel || this.options.label + ": " + binding.bindingType + " buffer from: " + binding.label,
usage: [...["copySrc", "copyDst", binding.bindingType], ...binding.options.usage]
});
if ("resultBuffer" in binding) {
Expand All @@ -284,7 +304,9 @@ class BindGroup {
binding.visibility = GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT | GPUShaderStage.COMPUTE;
}
if ("buffer" in binding) {
if (!binding.buffer.GPUBuffer) {
if (binding.parent && !binding.parent.buffer.GPUBuffer) {
this.createBindingBuffer(binding.parent, binding.parent.options.label);
} else if (!binding.buffer.GPUBuffer && !binding.parent) {
this.createBindingBuffer(binding);
}
}
Expand Down Expand Up @@ -393,10 +415,12 @@ class BindGroup {
for (const binding of bindingsRef) {
bindGroupCopy.addBinding(binding);
if ("buffer" in binding) {
if (!binding.buffer.GPUBuffer) {
if (binding.parent && !binding.parent.buffer.GPUBuffer) {
this.createBindingBuffer(binding.parent, binding.parent.options.label);
binding.parent.buffer.consumers.add(bindGroupCopy.uuid);
} else if (!binding.buffer.GPUBuffer && !binding.parent) {
this.createBindingBuffer(binding);
}
binding.buffer.consumers.add(bindGroupCopy.uuid);
if ("resultBuffer" in binding) {
binding.resultBuffer.consumers.add(bindGroupCopy.uuid);
}
Expand Down
Loading