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

Encapsulate WebGPU - 2D #96

Open
sholloway opened this issue Aug 27, 2023 · 3 comments
Open

Encapsulate WebGPU - 2D #96

sholloway opened this issue Aug 27, 2023 · 3 comments

Comments

@sholloway
Copy link
Owner

No description provided.

@sholloway sholloway converted this from a draft issue Aug 27, 2023
@sholloway sholloway moved this to Identified in Agent Playground - v0.2.0 Aug 27, 2023
@sholloway
Copy link
Owner Author

sholloway commented Sep 4, 2023

Create a 2D API backed by WebGPU and WGSL


Define an API for drawing in a 2D Context.

2D API Operations

Operation Description Supports
get_context Provides a canvas that can be drawn on.
clear Clears the canvas with a provided color. color
pan Moves the 2D camera. direction, distance
circle Draws a circle. center, radius, stroke, fill
square Draws an axis-aligned square. origin=(CENTER, UPPER_LEFT, UPPER_RIGHT, ...) , edge_size: float, stroke, fill
rect Draws an axis-aligned rectangle. origin=(CENTER, UPPER_LEFT, UPPER_RIGHT, ...) , edge_size: float, stroke, fill
poly Draws a polygon
line Draws a line
bézier Draws a curve.
spline Draws a spline curve.
text Draws text.
grid Draws a grid

Advanced Features

  • Parallax Rendering
  • Sprite Sheet based animation.
  • Rendering Text

Considerations

  • Representing shaders in a Python code project. I want syntax highlighting and code hints.

References

Resources

Rectangles

Lines

Curves

Engine Architecture

Text Rendering

Examples

WebGPU Information

Tooling

@sholloway
Copy link
Owner Author

sholloway commented Nov 9, 2023

Switching to a GPU based rendering is going to require making some changes to the overall architecture.

  • The way that renderers are currently declared will need to be replaced.
  • The default sims renderer is going to need to leverage instancing for having a large number of sims running around.
  • Panning and zooming should be easier with a camera model.
  • Will probably need to replace the current grid coordinate system.
    • Real-Time Rendering - Ray Tracing Chapter: "Hash tables can be employed to create an infinite virtual grid, where only the occupied cells store data in memory (Section 25.1.2). Another strategy is to store, in empty cells, the distance in grid units to the closest non-empty cell. This system is
      called proximity clouds [14]. During the traversal, these distances allow us to safely
      skip many cells in the line marching routine that are guaranteed to be empty. Recently,
      irregular grids [64] elaborate on the idea of skipping empty space efficiently."
  • I'd like to have architecture support swapping out rendering pipelines for a sim. For example, raster, real-time ray tracing, voxel.

Compute Shader Potential

What part of the pipeline can leverage compute shaders?

  • Perhaps the view frustum should shift to a compute shader.
  • Calculation of AABBs?
  • Construction of any spatial data structures (e.g. kd-trees, BVH).

@sholloway
Copy link
Owner Author

sholloway commented Nov 9, 2023

Debugging

Debugging shaders is a major pain in the Python ecosystem. The debug tools that work with Rust don't work with Python. I want a way to get debug information out of shaders.

Ideas

  • Have a debug buffer that is available to all shaders in a pipeline. Use this buffer to write debug information.
  • Option A: Write the debug buffer to the STDOUT. This can be directed to the terminal or a log file.
  • Option B: Have an additional render pipeline that writes the debug information into screen space.
  • Option C: Make the primary render pipeline be deferred. Each render pass writes to a temporary texture. An optional DEBUG texture can be used to overlay debug text over the frame.

Challenges

  • If each vert/frag shader can write to a debug buffer then the data generated could quickly get larger than what can be displaced on screen.
  • I haven't solved how to displaying text with WebGPU yet.
  • Deferred rendering has general complexities with dealing with shadows.
  • Deferred rendering is more memory hungry.
  • Writing a buffer to a file. The PPM format may be an easy option.
  • Shader Debug Example
  • WGPU PR #4297

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Identified
Development

No branches or pull requests

1 participant