3D render to sprite?

I’m sure this is perfectly possible, I just don’t know where to start.

How can I ‘take a photo’ of a 3D tumbling object and render it to a Texture2D

This goes back to something I was working on a while ago where I would like 3D objects, but work on a 2D plane. I know I can go full 3D and use an Orthographic view, I that’s not what I want to do in this case.

Thanks.

To take a “photo”, you can rotate the object, and render it in a rendertarget at the right size with the right view :wink:
But I would not do this during runtime.

You can have a look at “impostors” (faking 3d objects with 2D pictures of 3d objects approximating an angle of view)

FarCry 1 use this with trees far from the camera to save polygons, but it can be done to produce sprites like it is done in Diablo1/2 for isometric rendering: 8 or 16 rotations, taking a “photo” of it each time.

Thanks Alkher

So you’re saying pre-render the objects and create 16 textures? I had thought of this but wandered is there was a more interesting way to do it. Plus I’d have more control over the spin speeds.

I’ve worked with Render Targets before when I wanted to leave rubber on a race track that didn’t disappear on the next lap. Are you saying that approach would be too expensive?

What exactly are you looking to do?

As explained before, you can simply store some output to a rendertarget and then use that rendertarget as a texture later on.

An example would be racing games - each frame they make a snapshot of the scene from the perspective of the car ( 6 textures in each direction - up down, left right forward backward) and then use that to create the reflections you can see on the car’s body.

Same goes for dynamic shadows. The scene is rendered from the perspective of the light and this information is later used to check if things are in shadow or not.

If that is too expensive or not depends on how much you render. If you only render one object to your rendertarget this will most likely have very very little impact on general rendering times. Of course it depends on many factors - how expensive is your rendering? How big is the resolution of the rendertarget? Etc.

1 Like

What is expensive is if you build these sprites at runtime. With a few this can be fast enough, but if you want a massive number of models rendered like this ( Diablo 2 Resurrected Best Builds, Guides, and News - Diablo 2 Resurrected - Icy Veins ), this way won’t be robust enough and not scalable. It could be a proof of concept but I would not advise to go this way for a production version.


If what you want is to render a 3D model and store the obtained image as a 2D sprite like this:
http://www.kevinbertel.com/diablo2/?char=AM&type=1HS&anim=A1&hd=LIT&tr=LIT&lg=LIT&ra=LIT&la=LIT&s1=LIT&s2=LIT&rh=0&lh=0&sh=0&&submit=Build ?

You should create a little application that generates the sprites from a 3D model: rotation and view are defined by the camera so you can have full control over it: 360 degrees around the model, 16 sprites: every 22.5 degrees you take a snapshot and save it.
If you want more, you can define as many as you want.

After all the sprites are done, you can build a spritesheet and this gives only 1 texture to load. There are many tools to do this, like this one which is very good:


The last but not the least solution, if you are planning to use an isometric od 2D render, it would be to use your 3D models without textures, and just rotate them the amount you need. On top of that, use a shader that renders them pixelated or toonshaded. :slight_smile: Less work and advantages of the 3D: shadows, reflection, etc at runtime.

The scenario is a bunch of space debris that flies through the scene, (2D top down) as yet I haven’t decided what their purpose will be! Only 10 or so sprites.

I have some lovely textures rendered from Blender which are being rotated at the moment and they look ok, but they give the game a very flat feel. The idea was to make them tumble in a 3D fashion, but staying with a Sprite batch so I didn’t have to re-write everything, it’s pretty complete. Apart from some logic. Some graphics. Oh, and an end goal!

So I thought I would tumble a 3D object, put a camera matrix on it, send the result to a RenderTarget and display it as a sprite. The sprites would be 128x128 pixels.

I could very easily pre-tumble and render the files, but I do want them to be smooth, so I’d probably want 36 pictures of each, so that would be 360 graphics in a sheet.

At the end of the day I can try both and see what the impact is. I’m only learning at the moment, there is no retail product in mind.

What I’m not sure of is how to get the snapshot from the camera matrix. And how to set that up without the item having a physical location.