#rendering guidance

14 messages · Page 1 of 1 (latest)

gloomy grotto
#

long time programmer, first time rendering. I have an entity that is a concept rather than a concrete structure that can be modeled by polygonic primitives. I want to be able to apply various trigonometric functions that describe its shape, and to be able to draw and animate that shape to the screen in a custom manner.

The research I've done have pointed me to the rendering pipeline, particularly the examples "custom-phase-item", "custom-render-phase", and "mesh2d-manual". I am expecting some set of functions that lets me feed an array of numbers into a texture that can be rendered on screen. All of these examples utilize WGSL shaders. Are GPU shaders the only way to do this? I infer that using the GPU requires my data representation to be modeled as triangles, a level of abstraction I wasn't expecting.

I was hoping for a set of functions that I could send arbitrary data do, and have it return a texture of pixels representing my data.

I guess I could summarize my working idea as something akin to on-the-fly PNG sprite generation, then give that PNG to bevy to render.

I know nearly nothing when it comes to drawing on a screen programatically. I'm completely new to graphics programming and would appreciate some pointers, references, or documentation that can help educate me on the processes and terminology of the paradigm.

junior cosmos
#

An example I found using the CPU rather than GPU to draw: https://bevy.org/examples/2d-rendering/cpu-draw/
Other than that, I don't know of any built-in method to draw using what I believe you're looking for (set of greyscale or RGB values -> texture).
You also noted generating textures on-the-fly, which should be possible with render textures (https://bevy.org/examples/3d-rendering/render-to-texture/ can be applied in 2D).
If you want to draw with smooth, conceptual shapes rather than hard-data vertices, Parry (http://docs.rs/parry2d) can be used to query if points are inside of a shape, and thus you can loop over all the pixels in the shape's Axis-Aligned Bounding Box and detect if pixels are in the shape (and if so, color them).
With your custom shapes idea,
I'm not too experienced with non-polygonal rendering, but hopefully these are what you're looking for!

fiery spoke
#

I guess I could summarize my working idea as something akin to on-the-fly PNG sprite generation, then give that PNG to bevy to render.

AFAIK, there is no general purpose way to turn math into pixels except for writing your own shaders (or doing the equivalent with CPU code if you don't care about performance). If you want to turn it into pixels once and re-use it, you create an empty texture, render your stuff onto it, and then you have a Handle<Image> that you can put in a sprite

#

When you talk about using trig functions, does that mean, you want to start with a polygon and replace one or more of it's faces with a sine curve of some kind?

#

i think it should be do-able to approximate that using signed distance fields, but i've never tried that

junior cosmos
fiery spoke
junior cosmos
# fiery spoke have you got it working with sine curves as the faces instead of line segments? ...

No, I have not ever tried doing this myself.
It's definitely possible, it would just likely take a lot of vector math work to transform the sine curve and rasterize it (detect what pixels are shaded).
Likely we would have to abstract the sine curve into a spline curve or many small line segments (at a smaller resolution than the pixels) for efficient rendering, but I'm sure it can be implemented through straight-up rasterizing the sine itself.

fiery spoke
junior cosmos
fiery spoke
#

@gloomy grotto if you are still reading this, you are an inspiration to all of us!!!

lavish mauve
#

Note that the simplest way to draw onto an image is to use ResMut<Assets<Inage>>, use a handle to get image data from it, and modify it. You should take care that your image asset has RenderAssetUsages::all() so bevy doesn't remove it from the main world

gloomy grotto