[SOLVED] leaving footprints and wheel-tracks

I’m looking for a way to draw to a transparent canvas dynamically… And then super-impose that canvas onto my scene.

I would be drawing skid-marks, footsteps, wheel-tracks, etc.

I thought I could start with a scene-sized transparent render-target, and simply stamp sprites on there, and never clear it…
But that doesn’t work… The render-target comes out totally black.

How do I stamp permanent sprites without loads of instances?

uh your idea should work, just don’t clear the rendertarget before drawing to it.

There is no big trick really, just draw your decals onto that rendertarget (you can use spritebatch) and draw that rendertarget on a texture / a seperate channel for your ground in the scene.

There shouldn’t be a reason why this doesnt work, but it may be inpractical in very large scenes obviously.

I would have thought so too…

I can draw to the rendertarget, and then draw the render target…

Problem arises when I want to do dynamic changes… I have to Clear() the render target for each frame, or it comes out black…

So all I can do is contruct a single static frame… thus losing all previous frames…

I got a work-around running…

I use 2 render-targets, and alternate drawing one on top of the other, plus any new changes…

This way I can clear my render-targets without losing data…

It seems dumb, but its simple and it works.

What do you mean dynamic changes? Isn’t everything dynamic (spawn new footprints etc.) Why do you need to clear?

I’m sorry I don’t exactly understand the problem. Use Alphablending for putting new layers on top of old stuff. Make sure that the rendertarget has no depth map.

You can simply draw new stuff on top of each and you can erase or fade out parts by drawing more transparent pixels on top instead.

Maybe there is a problem I am not seeing. I don’t understand why it would come out black when not clearing.

Note: You cannot write to a rendertarget that is also a texture input in the same shader, maybe that’s a problem?

Sorry for my bad explanations… I’m not using shaders, or depth maps, or any blending… Only simple render-targets and sprites.

What I mean by dynamic, is ability to change between frames… I can set up the render-target and draw to it ONCE, to create a static image ONLY, where unfortunately I need to edit it in real-time…

Every time I want to update the render-target (add new foot-prints etc), I MUST clear it first, or it becomes all black…

-My problem, basically, seems to be that I cant add to a render-target without clearing it first…

K, let me try to make a sample program

Have you set the ‘Preserve Contents’ flag when you create your render target?

If not you’ll need to use one of the overloads of 'new RenderTarget2D() that contains ‘RenderTargetUsage’ and use ‘PreserveContents’, that should stop it going black after each frame.

Thank you… Will try this now, and report back… sheesh…

Thanks Avan… That did the trick… I would have never found that overload :slight_smile:

And thanks for the effort kosmonautgames…!

Actually I just made a small test file, unfortunate timing

http://www.xup.in/dl,80555974/RenderTargetTest.zip/

In this case I can draw to the rendertarget with left click.

This rendertarget is then drawn each frame after the clear and then some white physicalized balls are drawn in front (to simulate some foreground)

1 Like