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

Draw circles/particles with different radii in GGUI #6999

Closed
YouJiacheng opened this issue Dec 28, 2022 · 3 comments · Fixed by #7003 or #8121
Closed

Draw circles/particles with different radii in GGUI #6999

YouJiacheng opened this issue Dec 28, 2022 · 3 comments · Fixed by #7003 or #8121
Assignees
Labels
feature request Suggest an idea on this project

Comments

@YouJiacheng
Copy link

Concisely describe the proposed feature
Currently canvas.circles and scene.particles only supports a single scalar radius, prevent users drawing many circles/particles with different radii in batch. I would like to draw many circles/particles with different radii efficiently, using one canvas.circles or scene.particles call.

Describe the solution you'd like (if any)
Allow parameter radius to be a taichi field.

Additional comments
ti.GUI.circles allows parameter radius to be a numpy ndarray. BTW, the documentation seems outdated:

def circles(self,
pos,
radius=1,
color=0xFFFFFF,
palette=None,
palette_indices=None):
"""Draws a list of circles on canvas.
Args:
pos (numpy.array): The positions of the circles.
radius (Number, optional): The radius of the circles in pixel. Default is 1.

if isinstance(radius, np.ndarray):
assert radius.shape == (n, )
radius = np.ascontiguousarray(radius.astype(np.float32))
radius_array = int(radius.ctypes.data)
radius_single = 0

It should be radius (Union[Number, np.array], optional) like ti.GUI.arrows.

@YouJiacheng
Copy link
Author

Hmmm. I don't think this issue should be closed by a docstring fix.

  1. Does the canvas.circles really support array radius? And I afraid it should be taichi field instead of numpy array in GGUI.
  2. What about scene.particles?

@ailzhang ailzhang reopened this Jan 5, 2023
@ailzhang
Copy link
Contributor

ailzhang commented Jan 5, 2023

cc: @neozhaoliang

ailzhang pushed a commit that referenced this issue Jan 6, 2023
Issue: #6999

GGUI's `circles` method does not allow passing NumPy array as radius;
this PR fixes this error.
lin-hitonami pushed a commit to lin-hitonami/taichi that referenced this issue Jan 9, 2023
Issue: taichi-dev#6999

GGUI's `circles` method does not allow passing NumPy array as radius;
this PR fixes this error.
lin-hitonami pushed a commit to lin-hitonami/taichi that referenced this issue Jan 12, 2023
Issue: taichi-dev#6999

GGUI's `circles` method does not allow passing NumPy array as radius;
this PR fixes this error.
@bobcao3
Copy link
Collaborator

bobcao3 commented Jan 12, 2023

Duplicate of #3888 ?

bobcao3 added a commit that referenced this issue Jan 13, 2023
Related: #6999

<img width="479" alt="image"
src="https://user-images.githubusercontent.com/11663476/212043697-c72cd730-d5f9-4dd5-ae8a-1352251b5956.png">

### Brief Summary

Change particle rendering from point rasterization to point instanced
quads, so that there's no longer a size limit. Screenshot came from
macOS.

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
Issue: taichi-dev#6999

GGUI's `circles` method does not allow passing NumPy array as radius;
this PR fixes this error.
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
Related: taichi-dev#6999

<img width="479" alt="image"
src="https://user-images.githubusercontent.com/11663476/212043697-c72cd730-d5f9-4dd5-ae8a-1352251b5956.png">

### Brief Summary

Change particle rendering from point rasterization to point instanced
quads, so that there's no longer a size limit. Screenshot came from
macOS.

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
feisuzhu pushed a commit that referenced this issue Jun 3, 2023
Fixes #6999

### Brief Summary
<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 3c3086e</samp>

This pull request adds support for per-vertex radius for circles and
particles in the GGUI system. It modifies the Python API, the
documentation, the shaders, the renderable classes, and the renderable
info struct to enable this feature. It also adds and updates some unit
tests and fixes some aspect ratio issues.

### Walkthrough

<!--
copilot:walkthrough
-->
### <samp>🤖 Generated by Copilot at 3c3086e</samp>

* Add per-vertex radius feature for circles and particles in GGUI system
([link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-93e8a55f5f76faf09c1aa36f3cf920a9a3e6c9aea87d5a55e7429ad5947221daL185-R185),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-4bfa2e9d83fc1fef45b46d471f7417cbf69fccb34b75d9fd025918619ca9daf5L6-R9),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-049645341deac2ede4da8d26c47379fcd7fb3f9ec2c46ad87c612f6ea11954e0L11-R14),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-049645341deac2ede4da8d26c47379fcd7fb3f9ec2c46ad87c612f6ea11954e0L33-R38),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-18cdc733625a6414455d5eb47436defc529344b33bd82f88fc5127860e51ebabL2-R3),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-be52d30510564cf2668f034e71574fdbc5efa7912dc383157df21f88c18b70a9L1-R4),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-748fab2d6b877ed75056bfc43c374554e601d480dbd59c92ab1b282c67c1e41eR15),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-748fab2d6b877ed75056bfc43c374554e601d480dbd59c92ab1b282c67c1e41eR38),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-748fab2d6b877ed75056bfc43c374554e601d480dbd59c92ab1b282c67c1e41eL79-R81),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-748fab2d6b877ed75056bfc43c374554e601d480dbd59c92ab1b282c67c1e41eL85-R87),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-5f50826807b6844d3edd1da547e9bbced4665c22ed1b97c8f18990ee3b4dd6e1R21),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-5f50826807b6844d3edd1da547e9bbced4665c22ed1b97c8f18990ee3b4dd6e1R32),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-5f50826807b6844d3edd1da547e9bbced4665c22ed1b97c8f18990ee3b4dd6e1L44-R53),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-8fbb121c18d247f5b17b27167ac054bbce713effa50414a2fe5e171ce589a3bfL1-R3),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-1dbae60bade8b58827db9c981f1cea243fd837481a9df0453f160084094d858bL1-R5),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-4f7ced603627bc0dac36eae499062271ca7f5b0f3724c688f758950802d7136dL141-R166),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-3db65eaf8189bc001eef73837950994805c91751c2ab9d0d2423a4cc61ebfa21R367),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-3db65eaf8189bc001eef73837950994805c91751c2ab9d0d2423a4cc61ebfa21L384-R404),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-fd7dee80cc57fcef55c9bedc67a63a5aee4f20ac0375921bebec55beeb5bf928R82-R103),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-de0a9a1fb6c6210ac5653025b79a982b6721b1c66e17d2dca1db90fa82613bddR212),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-de0a9a1fb6c6210ac5653025b79a982b6721b1c66e17d2dca1db90fa82613bddR221),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-de0a9a1fb6c6210ac5653025b79a982b6721b1c66e17d2dca1db90fa82613bddR348),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-de0a9a1fb6c6210ac5653025b79a982b6721b1c66e17d2dca1db90fa82613bddR354),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-d9835169258dab7b24944260c4402e5c03f31207fb15c5166aff466a968fff7eL15-R21),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-7a6b554446188ef6b17b4649720b4359fb7c69da989537eec3aac163e9d25c10L39-R42),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-cfad5db6c53643971b9c8a40ad082ea715de90bb5327e0f186fe94e5b45d2572R50),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-d54f4426461756f88ef5bc0a4f14f0b6c0704aeadc5c37d804fee447bab32e50R41),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-05323183591466b0512c64e13562bb7b6dc8a2efba19da6254f8fb94b4f2c131R13))
* Add `per_vertex_radius` parameter to `scene.particles` and
`canvas.circles` methods in Python, and pass it to C++ layer
([link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-93e8a55f5f76faf09c1aa36f3cf920a9a3e6c9aea87d5a55e7429ad5947221daL185-R185),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-4f7ced603627bc0dac36eae499062271ca7f5b0f3724c688f758950802d7136dL141-R166),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-3db65eaf8189bc001eef73837950994805c91751c2ab9d0d2423a4cc61ebfa21R367),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-3db65eaf8189bc001eef73837950994805c91751c2ab9d0d2423a4cc61ebfa21L384-R404),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-de0a9a1fb6c6210ac5653025b79a982b6721b1c66e17d2dca1db90fa82613bddR212),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-de0a9a1fb6c6210ac5653025b79a982b6721b1c66e17d2dca1db90fa82613bddR348))
* Add `has_per_vertex_radius` field to `RenderableInfo` struct and
assign it from Python parameter
([link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-de0a9a1fb6c6210ac5653025b79a982b6721b1c66e17d2dca1db90fa82613bddR221),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-de0a9a1fb6c6210ac5653025b79a982b6721b1c66e17d2dca1db90fa82613bddR354),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-05323183591466b0512c64e13562bb7b6dc8a2efba19da6254f8fb94b4f2c131R13))
* Add `use_per_vertex_radius` field to `UniformBufferObject` struct for
circles and particles, and assign it from `RenderableInfo` field
([link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-d9835169258dab7b24944260c4402e5c03f31207fb15c5166aff466a968fff7eL15-R21),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-7a6b554446188ef6b17b4649720b4359fb7c69da989537eec3aac163e9d25c10L39-R42),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-cfad5db6c53643971b9c8a40ad082ea715de90bb5327e0f186fe94e5b45d2572R50),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-d54f4426461756f88ef5bc0a4f14f0b6c0704aeadc5c37d804fee447bab32e50R41))
* Add `use_per_vertex_radius` field to `ubo` structure in shader code
for circles and particles, and use it to select radius source
([link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-4bfa2e9d83fc1fef45b46d471f7417cbf69fccb34b75d9fd025918619ca9daf5L6-R9),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-049645341deac2ede4da8d26c47379fcd7fb3f9ec2c46ad87c612f6ea11954e0L11-R14),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-748fab2d6b877ed75056bfc43c374554e601d480dbd59c92ab1b282c67c1e41eR15),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-5f50826807b6844d3edd1da547e9bbced4665c22ed1b97c8f18990ee3b4dd6e1R21))
* Add `selected_radius` variable to vertex and fragment shaders for
circles and particles, and use it to calculate position, normal, and
depth
([link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-049645341deac2ede4da8d26c47379fcd7fb3f9ec2c46ad87c612f6ea11954e0L33-R38),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-748fab2d6b877ed75056bfc43c374554e601d480dbd59c92ab1b282c67c1e41eR38),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-748fab2d6b877ed75056bfc43c374554e601d480dbd59c92ab1b282c67c1e41eL79-R81),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-748fab2d6b877ed75056bfc43c374554e601d480dbd59c92ab1b282c67c1e41eL85-R87),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-5f50826807b6844d3edd1da547e9bbced4665c22ed1b97c8f18990ee3b4dd6e1R32),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-5f50826807b6844d3edd1da547e9bbced4665c22ed1b97c8f18990ee3b4dd6e1L44-R53))
* Update binary files for shader code for circles and particles
([link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-18cdc733625a6414455d5eb47436defc529344b33bd82f88fc5127860e51ebabL2-R3),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-be52d30510564cf2668f034e71574fdbc5efa7912dc383157df21f88c18b70a9L1-R4),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-8fbb121c18d247f5b17b27167ac054bbce713effa50414a2fe5e171ce589a3bfL1-R3),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-1dbae60bade8b58827db9c981f1cea243fd837481a9df0453f160084094d858bL1-R5))
* Add `copy_all_to_vbo_particle` function to copy data from taichi
fields to vbo array, and use it in `scene.particles` and
`canvas.circles` methods
([link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-4f7ced603627bc0dac36eae499062271ca7f5b0f3724c688f758950802d7136dL4-R8),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-3db65eaf8189bc001eef73837950994805c91751c2ab9d0d2423a4cc61ebfa21R11),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-3db65eaf8189bc001eef73837950994805c91751c2ab9d0d2423a4cc61ebfa21L384-R404),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-fd7dee80cc57fcef55c9bedc67a63a5aee4f20ac0375921bebec55beeb5bf928R82-R103))
* Modify radius calculation in shader code and `update_data` method to
use window size instead of hard-coded aspect ratio
([link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-049645341deac2ede4da8d26c47379fcd7fb3f9ec2c46ad87c612f6ea11954e0L33-R38),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-d9835169258dab7b24944260c4402e5c03f31207fb15c5166aff466a968fff7eL15-R21),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-7a6b554446188ef6b17b4649720b4359fb7c69da989537eec3aac163e9d25c10L39-R42))
* Fix typos and inaccuracies in documentation of `scene.particles`
method
([link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-93e8a55f5f76faf09c1aa36f3cf920a9a3e6c9aea87d5a55e7429ad5947221daL120-R120),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-3db65eaf8189bc001eef73837950994805c91751c2ab9d0d2423a4cc61ebfa21L373-R383))
* Add type annotations for numpy arrays in `staging_buffer.py`
([link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-fd7dee80cc57fcef55c9bedc67a63a5aee4f20ac0375921bebec55beeb5bf928R2))
* Add unit tests for per-vertex radius feature for circles and particles
in `test_ggui.py`
([link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-7f78177ffeb214e2e6edde3b288143eb941d514aaf0d1471e4038b5ddf11538eR85-R92),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-7f78177ffeb214e2e6edde3b288143eb941d514aaf0d1471e4038b5ddf11538eR115-R116),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-7f78177ffeb214e2e6edde3b288143eb941d514aaf0d1471e4038b5ddf11538eL113-R123),
[link](https://github.com/taichi-dev/taichi/pull/8121/files?diff=unified&w=0#diff-7f78177ffeb214e2e6edde3b288143eb941d514aaf0d1471e4038b5ddf11538eR625-R683))

---------

Co-authored-by: AntonioFerreras <antfs10@gmail.coms>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Suggest an idea on this project
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants