best way to do this ?

Monkey Forums/Monkey Programming/best way to do this ?

Paul - Taiphoz(Posted 2016) [#1]


Nobuyuki suggested stencils via the drawExt2 module but that would then remove support for Html5 which I would like to avoid if possible as its my primary build target when working.

Another option is to draw black tiles over the screen, and then where a light/object is dont draw them, filling in curved tiles at the edges to give it a rounded effect but that would look blocky.

I was thinking that taking a solid screen size black image and then blending in or using write pixel to write in alpha values for the circles might be quick enough but unsure, does anyone have any suggestions ? opinions? or thoughts. ?


tiresius(Posted 2016) [#2]
I assume you're using Mojo and not Mojo2.

Can you "render to image" in Mojo (i.e. DrawImage() that will draw on an image) ?
I think that type of thing is needed in order to do image/alpha masking as far as I know.
Doing some kind of Tile-based thing wouldn't look very good, I think. :(

[EDIT]
WritePixel could work but I think it is very slow...


Sicilica(Posted 2016) [#3]
You really, really don't want to do that with WritePixel. Unless it's faster since last I checked, it's far too slow to use on a fullscreen per-frame basis.

The scenario you have there is really the job of a shader. If you're using mojo1, you might be in trouble. If you're in mojo2 (or just writing it in opengl for some reason?), then it should be simple enough, but I don't have time to put up an example (maybe someone else can?). You could actually use the built-in light uniforms that mojo2's renderer uses, then write a simple frag shader that cuts off pixels unless they are within some distance to at least one light.

Do you really not have access to the stencil buffer on HTML5? Huh, I thought it was supported....

EDIT: I'm almost 100% certain that you can use the stencil buffer. It's technically supported in WebGL, at least. I don't think mojo allocates one though, so you'd probably have to create one yourself, aaaand then you're either hacking up the graphics module or writing it yourself using the opengl module.