knightcrawler25 / GLSL-PathTracer

A toy physically based GPU path tracer (C++/OpenGL/GLSL)
MIT License
1.87k stars 176 forks source link

Density / Fog Integration #88

Open markusmoenig opened 1 year ago

markusmoenig commented 1 year ago

Hi,

any plans to integrate volumetric fog / general density support in the tracer ? The new Aerolod beta from ephtracy has great looking terrain fog, would love to achieve something similar.

knightcrawler25 commented 1 year ago

Hey,

Adding fog should be relatively straightforward as its just a homogeneous volume with some special handling for distant lights and maybe a better sampling technique to reduce noise.

I'll have a go at adding it once I get some free time :)

markusmoenig commented 1 year ago

Great! But the fog would not be uniform but could be defined via a bounding box or something right ? That's how it looks with Aerolod (see the screenshots of ephtracies Twitter).

Raymarched varying densities would be fantastic 😅

knightcrawler25 commented 1 year ago

I had a look at this demo of Aerialod: https://twitter.com/ephtracy/status/1663836379078356998 and it looks like a constant/uniform fog bound by the extents of the map and with a height decay control.

This looks similar to how other renderers handle global fog:

In the video, Aerialod doesn't appear to have any options to assign a texture to the fog (which would allow for varying densities and requires raymarching). This V-Ray example shows ray marched fog volume confined to geometry, but for global fog, a simple bounding box would make sense. Right now, I'm not quite sure how this would be implemented but would be a fun thing to work on :)

image

markusmoenig commented 1 year ago

Do you have function pointers on GLSL ? I am on Metal or Rust / CPU and have them on both. So could create a callback to either read fog from a texture or calculate from height or ray march a texture or procedural noise.

If varying density is supported one could also create clouds with it like in https://www.shadertoy.com/view/MdGfzh. Then it would be a full featured terrain renderer with fog / atmosphere and clouds.

But of course course constant fog with a height decay is also already great :)