• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

3D Best way to draw background gradient to use as sky

Bart

WiseBart
Hi all.

I've been playing around with the application surface recently and, while doing so, tried to code a gradient that acts as the sky for a day and night cycle.

While I originally used a half sphere model for the sky, I figured that it could be more interesting to draw a gradient (draw_rectangle_color) in the Pre-Draw event for this. By changing the colors, it's quite easy to get a convincing day-night cycle.
Visually, this is the effect I'm after.

But it required a few 'tricks' to get this working right. The application surface needs to be cleared with an alpha value of 0 in a Draw Begin event for the things drawn in Pre-Draw to still be visible on screen. In that Draw Begin event, it's not possible to draw the rectangle, since all transformations are already being applied.
Also, it appears that you have to draw the application surface manually in the Post-Draw event so it blends correctly with the back buffer.
But this slows down the thing quite a bit, since in Pre-Draw, all rendering is done to the back buffer, which doesn't appear to work out so well on a 4K monitor in fullscreen... Also, the alpha blending of the application surface with the back buffer probably takes place 3840x2160 times.

In a second attempt, to solve the above issues, I switched to rendering to a view surface of 1920x1080 that is then scaled up to fit the actual window size. This seems to work fine, but it requires disabling the application surface completely, since there's no use using it when I have a custom surface to render to.

I'm wondering if there are better ways to achieve the effect I'm after that don't require the use of a custom view surface or ways that are more efficient.

Has anyone done something similar or have experience with this?
 

samspade

Member
You might be able to accomplish it with blendmodes depending on what you're after. You can definitely accomplish it with a shader.
 

Bart

WiseBart
Thanks for the idea.
But I'm trying to avoid using blending altogether in this case, it's more of an optimization issue.

I am now using a simple skydome with a shader that results in the same effect. For some reason, this is a lot more efficient.
But it's working fine now.
 

samspade

Member
Thanks for the idea.
But I'm trying to avoid using blending altogether in this case, it's more of an optimization issue.

I am now using a simple skydome with a shader that results in the same effect. For some reason, this is a lot more efficient.
But it's working fine now.
Shaders are very, very fast. Blendmodes are also very fast. Or at least not much if any slower than normal drawing. But a shader does seem like the best way to accomplish something like this.
 
Top