Starfield (in the background)

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
Ats
Posts: 617
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Starfield (in the background)

Post by Ats »

Hi everybody !

Today I was playing with particles to make a good old starfield, like the windows 95 screensaver.

In order to keep it fixed even if I move the camera around, I'm using two RenderPasses. One with a fixed camera where I only render the stars, and a second with a moving camera and flying 3D blocks.

But I have one main problem:
Why are the stars of the first renderpass are showing above the blocks of the second rendepass? I thought that renderpass was determining the order of the things to render.

Next, is that a good idea to use it like that? In my example, I'm testing the number of App.CurrentRenderPass on each models (starfield and cube) before rendering them. Do I have to do that for each and every models of the game? Or is there another method?

And last, I'm playing around with the camera position in the OnBeginRenderPass of the App. Is that how I should do it? Because I'm not sure about that for when I'll have several AppStates, or camera attached to models...

Thanks for your help !
Attachments
starfield.zgeproj
Starfield test
(4.49 KiB) Downloaded 400 times
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Re: Starfield (in the background)

Post by Kjell »

Hi Ats,
Ats wrote:Why are the stars of the first renderpass are showing above the blocks of the second rendepass? I thought that renderpass was determining the order of the things to render.
Using multiple render-passes simply executes the render "event" multiple times. So if you're drawing objects in your first pass that are closer to the camera ( or to be more accurate, have a lower z-buffer value ) than objects in your second pass ( using Materials with ZBuffer enabled obviously ), the objects from the first pass will overlap / appear-in-front-of the ones from the second pass.
Ats wrote:Next, is that a good idea to use it like that?
No, that's not what render passes are intended for. They are useful when you need to render the same scene multiple times .. so for example when you have multiple viewports, or need to render shadow / depth maps, or when you're using deferred rendering etc.
Ats wrote:In my example, I'm testing the number of App.CurrentRenderPass on each models (starfield and cube) before rendering them. Do I have to do that for each and every models of the game? Or is there another method?
The proper way of doing this kind of thing is to switch the camera mid-frame and clear the depth buffer. Unfortunately there are no ApplyCamera and ClearBuffer components, so you'd have to use OpenGL calls ( which means you can't use the Camera component either anymore ).

Anyway, to easily fix the problem in your current multi-pass setup .. simply disable the ZBuffer property of your StarMaterial :wink:

K
User avatar
Ats
Posts: 617
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Post by Ats »

Thanks Kjell. All right, so that was a bad idea then :)
So here's a different solution: the starfield is now far away, with new settings so that the particles are flying faster and farther.
And to avoid that the starfield moves with the camera, it is now attached to it.

One last question regarding the particles, I didn't find a way to make them appear with their alpha set to 0 and then lose transparency with time so that there will not be a mass of stars in the center of the screen. Is that possible?
Attachments
starfield.zgeproj
Starfield MARK II
(4.04 KiB) Downloaded 418 times
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Ats,
Ats wrote:One last question regarding the particles, I didn't find a way to make them appear with their alpha set to 0 and then lose transparency with time so that there will not be a mass of stars in the center of the screen. Is that possible?
Sure, follow these 3 easy steps.

- Set RenderParticles.OnEmitExpression to "this.PColor.A = 0;"
- Set RenderParticles.AnimateAlpha to 0.25 ( or some other positive value ).
- Set StarMaterial.Blend to Alpha/OneMinusSourceAlpha.

K
User avatar
Ats
Posts: 617
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Post by Ats »

Thanks, that's perfect !!!
(also I forgot to select FollowModel in the RenderParticles)

I'm adding this to the game. It's taking shape ;)
Post Reply