Global MaruFight

Forgot to add actual project: here it is.

@UberGoober - what you could possibly do is have two spheres one inside the other with the outer transparent, then only update the Maru graphics file. Or am I missing the point?

@UberGoober You’re getting closer. Loaded your zip file and ran it. Noticed that some of the Maru would disappear as they left a cube edge. Not sure which edge they were reappearing on but you don’t have the code right when leaving an edge and appearing on the adjoining edge.

https://youtu.be/OUK2FWvKHnk

It runs better on my iPad with the planet’s number of facets turned down.

@dave1707 I know, that’s why I call it a demo. I don’t have that math worked out at all.

@UberGoober looking at your changes, the rendering is slow because it creates a new cubemap every time it updates the marus. Mapping them onto a cube map by drawing them on each face will cause some distortion around the cube edges as well as clipping when they don’t line up.

There is a special undocumented thing that could help you out: renderTarget. You can create a render target by giving it an existing craft.texture or craft.cubeTexture. You can then use camera:draw(target, cubeFace) to make a craft camera draw directly to a cube texture face. This would be much faster than creating a new cube texture from scratch every time but is a bit more tricky

The above might help but I think ultimately this is a case of trying to force a square peg into a round hole. You can’t really map a square texture map onto a sphere without some extra work to make your 2D entities line up with the edges or placing them in a 3D space

@John thank you for the secret sauce! That’s just what I was looking for, I think!

The deciding factor keeping the creatures in 2D, I think, is that if I ever want to make the marus aware of their environment, the simplest way to do that is to make them aware of the cube map, and if everything is going to go back to the cube map eventually, I might as well just draw to it too, no?

@John could you possibly provide an example of rendertarget in action? It does seem tricky.

https://youtu.be/BI2aQr15s-4

Attached is the project that attempts to use renderTarget and causes this amusing fail.

@UberGoober I a see. Well all it does it make a camera draw to a side of the cube texture. I’ll think about how it would need to work

@John, OK, I think I understand: it is drawing the current image that the camera sees to the target that is specified. So it doesn’t have to be turned on and off the way that drawing contexts are.

So it seems like the way this would have to work is to somehow position the camera so that it only sees the part of the Maru plane that corresponds to side one, and then set the render target to side one, and then position the camera so that it only sees side two, and set the render target to side two, and so forth, for each of the six sides, and then return the camera to its normal position.

Alternately, I guess, and what might be simpler, is to draw each square of the Maru fight with the right positioning and dimensions that it fills the camera in the camera’s existing position, so that the camera itself doesn’t have to be moved at all, and set the render target appropriately between drawing each Maru square.

I think the trick in both cases is positioning the Maru plane so that it precisely fills the camera’s field of view. Any tips on doing that?

https://youtu.be/A46gdr2Xjfs

@John:

Well, I tried the above and it kind of worked but not enough that it’s usable.

Why am I getting this weird effect where the texture is only visible from some angles?

This would be due to mipmapping I think. You could try calling generateMipmaps() on the cube texture after updating it?

https://youtu.be/66d3qOe-uu4

@John thanks for the tip!

so close!

Thoughts?

@John I reduced the planet radius to 1, which made it a cube, which gives us, I think, interesting information.

https://youtu.be/8yqccX52ilo

It looks like for some reason camera:draw is doing two weird things:

  • it only renders the image at exactly 1/4 the size of a cube face
  • it puts a thick black border on the bottom and right sides of the image

(Project attached)

@UberGoober - after playing a little, then pressing Generate, it crashed Codea.

@Bri_G yeah right now apparently the renderer can only handle really small images. If you try to increase the sizes of things it crashes pretty fast.

@John does one of the example projects use renderTarget so I can see an example of it working correctly?

I don’t have any examples on hand since render target is mostly used internally (for things like bloom). All it does it draw to a craft texture using a scene camera, which it looks like you got working?

@John it doesn’t apparently draw to the whole texture, just the upper left corner of it. The texture covers the whole cube face but renderTarget appears to only cover a corner.