Volumetric lights / fog

Published December 05, 2020
Advertisement

The wife was up really late last night with some of her projects, so I sat myself up and programmed all night. I barely even remember it, but I went on an absolute tear. So up until last night, the further away something was from the camera, the darker it became. This mimicked the behavior of DOOM. This was meant to be a temporary solution because I had something much more ambitious in mind.

Ah yes, this is familiar

One of the advantages that a ray caster has over a polygon rasterizer, is that the ray has to actually travel through the space in order to reach whatever gets drawn. This allows the ray to gather information about everything that it's passed through, not only the distance from the camera. So the code that took the distance and calculated the darken was removed, as well as a bunch of other complications in the shader, and an rgb fog value was added to the ray itself, altering itself as it travels through space. Each sector can have it's own fade function, which is now in a dynamically loaded library and easily modded or added to by anyone who knows C. Raycasting provides free volumetric effects. I realized that by making different functions for varying densities, I could simulate fluids very realistically. I can also very realistically create god rays or other volumetric lighting effects. The fog is constrained by a floor/ceiling pair so you can even have a layer of fog different than others. Since the fog functions are very simple, I was able to create a C++ macro for most common cases, and made several dozen functions for different colors, darknesses, and densities. Right now I haven't implemented a way ta assign them to individual sectors yet, so it's all one type, but the magic will really happen when the can be mixed and matched.

How about some glowing red Hell fog?
Fancy a swim under water?

Not only did I write all the code to do this, but I also did all of the algebra I needed for another related feature: refraction. I had intended to have refraction be a material property, and already actually have it in the JSON, but hadn't implemented it yet. I started while I finished up the alpha and reflection, but realized that putting it in the material properties made absolutely no sense for my purposes. Having it be a material properly only makes sense if you are trying to rasterize polygons. In the real world, surfaces don't have refraction indexes, volumes do. Light changes direction at the boundary between to volumes of different refractive index, not because it hit a specific type of surface. Wait a minute… raycasting literally moves across boundaries of different types of volume, the refraction index belongs in the sector. Having a concept of volume is giving me all sorts of benefits that defining only polygonal shells doesn't get. I will implement refraction today and post a picture of a glass barrel of water sometime tonight.

0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement