🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

What is a Sun in game engines?

Started by
15 comments, last by Gnollrunner 3 years, 3 months ago

Toastmastern said:

Right now it seems that where the sun disk is supose to be I see the skybox texture, but all other places it is just pitch black

Looking at your code:

I'm not familiar with the “distance” function--I'm guessing that it returns the angle between two vectors?

Presuming as much, I take it that you're measuring the angle between the sun-direction and the view-direction, and then applying smooth-step to have that fade from 0 to 1. Or something to similar effect.

But since you're using “sunAmount” in calculating “sun”, why apply it again when you calculate the final colour?

Otherwise, the issue that you're seeing suggests that the value of “sunAmount” is inverted: you're getting zero where the sun should be and one where it shouldn't be. I'm guessing that this is related to the use of the “distance" function, but since I am, as mentioned, not familiar with it, I'm not sure of what the problem might be.

The fact that you're seeing blackness outside of the expected sun-area further suggests that the line that includes the smooth-step is producing zero, or close to it. Why this might be I'm not sure, I'm afraid--have you checked the value of “radiance”, perhaps?

All this, however, is largely conjecture I'm afraid.

It might be worth outputting some of the values that you're taking as inputs, and the values that you're calculating along the way, to see whether they're as you expect them to be.

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

Advertisement

@swiftcakez I feel like everyone is giving you advanced answers without making sure that you know the basics. I would like to link you to a tutorial on basic cubemaps: https://learnopengl.com/Advanced-OpenGL/Cubemaps​​ . It show a basic skybox and deals with problems such as view distance. In this case the sun is just hardcoded onto the texture, but the basic idea of “how to draw something that should be ridiculously far away like the sky/sun” is useful. In short, you draw it separately from everything else, so you can make a scale model of the sky and it still looks "large and far away" in the final result. When you want to make your own sun/sky/clouds, you can render them on the cubemap texture, with no regards for scale, distance or the rest of your world, and then you slap the finished texture on your skybox. Or a skydome, as a more modern version of it. For googling I would suggest terms like “cubemap”, “skybox”, “skydome”.

Maybe you already knew all this, but it's worth including it imho, for completeness sake ?

There is no “sun” in game engine.
There are a few separate concepts that create scene that looks (feels) like a scene with sun:

- there is a white spot drawn on the background,
for 3d background is usually a skybox - a cube drawn at max Z so that it cannot obstruct any models

- lightning on scene matches what background suggests
generally main directional light matches where image of sun is drawn
you might need some extra lights to create proper shadows, occlusion effects, etc.
often different for baked static elements that can have light precomputed using more complex offline methods
and dynamic elements that will use simpler illusions
as this will not be simulated “correctly” (maybe one day with raytracing…)
Global illumination (GI) is one more advanced lightning improvement category
that might be worth exploring for some scenes

- extra FX elements to create better illusion, e.g.
“sun rays” as glowing sprites that will simulate light bouncing of dust
“halo” effect that simulates camera pointing at sun and creating aberrations

- HDR i.e. using more bits per color to compute “more detailed” colors
then simulate eye adapting to lightning and changing
what part is overexposed and white and
what is underexposed and black
really nice for any scenarios when camera is pointing directly at sun and everything is overexposed
then goes to a dark place and eyes need some time to adapt
(same scene is initially black but once eye adapts detail starts popping out, but the lighter part starts being pure white)

Much details depend on particular scene, is it noon, sunset, sunrise, sunrise with a pool of water?
Cloudy day? Clear sky? Winter, Summer etc. etc.
And most importantly what type of details are needed and what can be ignored to keep target effect.

As an engine guy you will not be creating “a sun”, you will be implementing tools for some subset of above
and possibly some integration. Like based on some config you draw some extra texture on skybox and setup main directional light.
To help setup those effects in coherent way.

NamespaceV said:

There is no “sun” in game engine.

I would think it depends on the game engine and game. I mean I plan to have an actual sun object, and have even written the code for it. Of course there are also the lighting effects but I also want an object you can fly up to. It even has LOD.

In cosmic games you will definitely have a “sun” or other star object in the center of each planetary system.

By There is no “sun” in game engine. I mean that its not a single engine feature, but a specific set of different engine featured configured to match specific project requirements.

I.e. UE4 has “sun configuration” lighting related actor, that has multiple different params mostly affecting shading and GI.
But also procedurally generating sky dome with sun depicted on it in location matching declared lighting angle and changing based on other params.

But from engine creator perspective it is a group of vastly different technical features that combined creates realistic visualization for given type of scene and graphics style, and actor is there to configure all of them coherently.

@gnollrunner What type of game and graphics style are you creating. Sun with actual 3d geometry and LOD sounds pretty weird.
Sun is so far away for any realistic like scenes i don't see how LOD would help…
Or even geometry as sun is quite flat when you take distance into account.
The only case where I see this is a cosmic game where you fly around solar system.
I'm intrigued.
Even more if its not a cosmic game.

NamespaceV said:

In cosmic games you will definitely have a “sun” or other star object in the center of each planetary system.

By There is no “sun” in game engine. I mean that its not a single engine feature, but a specific set of different engine featured configured to match specific project requirements.

In my “engine” (loosely defined as such) there is: CDLSunObject_View ?, but then nobody has ever accused me of doing things in the accepted way. The “light” itself is actually attached to it as a separate entity.


What type of game and graphics style are you creating. Sun with actual 3d geometry and LOD sounds pretty weird.

Well the eventual goal is an MMORPG. As for the sun, I wanted ships that are rated for the chromosphere like in some SciFi stories. So when you get close it still should look like a sphere (hence the LOD), and I wanted animated procedural effects which also means it should be a sphere or it won't look right.

This topic is closed to new replies.

Advertisement