PDA

View Full Version : Layer concept


pixelshader
23-Jul-2007, 16:48
How does game programmers approach layered concept in directx.
I mean if i have 10 different layers at various depths and what i see on the screen at any moment is each of these 10 layers merged together.
My doubt is do they draw each of the 10 layers one over the other each time one layer changes???
One way i can imagine is drawing each layers in to seperate rendertargets and combine using a pixel shader.
Is there any method so that we dont have to redraw every layer each time?:?: ??

Simon F
24-Jul-2007, 09:18
Layers? Are you describing a 2D game?

pixelshader
24-Jul-2007, 10:02
Yess am talking about 2D games. My example would be like one layer will have some text written on it and i dont want to draw those text each frame. I want the text as overly to my game. This is one example layer.. i will have lots of such overlays. Ideal case will be i will have to draw only the changed overlays.

Xmas
24-Jul-2007, 10:11
Then you draw each layer to an off-screen surface, redraw when necessary, and combine the layers for final output every time at least one of them changed.

vindos
24-Jul-2007, 10:42
But the problem is i got large number of overlays like 10-15 in number. Creating so many offscreen surfaces is my problem :(
I was looking for some feature where i write each overlay at various depth of the same offscreen rendertarget. Updation for one overlay occurs at its corresponding depth value and other overlays dont get modified.

Xmas
24-Jul-2007, 13:49
But the problem is i got large number of overlays like 10-15 in number. Creating so many offscreen surfaces is my problem :(
I don't see the problem here.

I was looking for some feature where i write each overlay at various depth of the same offscreen rendertarget. Updation for one overlay occurs at its corresponding depth value and other overlays dont get modified.
That way you could only add opaque pixels properly, but never remove them/make the layers in the background visible again.

pixelshader
24-Jul-2007, 15:00
I don't see the problem here.

U mean it isnt a big deal to have 10-20 rendertarget targets of the screen size??
So i should render each overlay to different rendertargets and then combine using pixel shader??

Xmas
24-Jul-2007, 19:04
U mean it isnt a big deal to have 10-20 rendertarget targets of the screen size??
Depends on the target hardware and resolution. Maybe you can reduce the resolution and/or color depth on some layers. But if it's a problem then your layer idea is not feasible.

So i should render each overlay to different rendertargets and then combine using pixel shader??
Yes.

Davros
24-Jul-2007, 23:28
you mention the layers are mainly for text would that be score, ammo count ect ?

is doing the text as sprites a silly idea ?

Sc4freak
25-Jul-2007, 12:54
I assume its a way of saving draw calls and state changes. It could also reduce GPU usage, too, if there's a lot of overdraw.