Advertisement

Ambient lighting post processing

Started by August 29, 2024 07:19 AM
4 comments, last by MagnusWootton 3ย months, 1ย week ago

Got a cool day time effect as a post process on ordinary dot product lighting.

I use a log fall off on the brightness of the pixels increasing the lightness dark pixels increasing the most using the normalized colour of the pixel and modifying it with a little ambient colour change. It helps if you use a deferred hdr texture to render on, cause when u normalize it you can lose the near 0 values and the colours go bad when lighting up from night to day. Sort of looks like I cast a billion rays to get the global illumination effect, but its all just done with a small amount of arith in the shader, so u get it for virtually no cost to gpu. ๐Ÿ™‚ (or cpu.)

Anyhow I thought it was cool, and its easier to learn than physically correct BRDFS by a mile!

here I did it again, this time without the extensive brightness, and comes out a really nice rough material! ๐Ÿ™‚

Advertisement

One trick that i use is to add lighting even when the dot product is zero, leaving it black only when the dot product is -1. This way i get smooth gradients everywhere from just one directional light, helping with debug visualizations.

If i would do it correctly, half of the sphere would be black and i would not see much.

	static float Light (const vec &normal)
	{
		vec lightDir = vec(0.436f, -0.872f, -0.218f); // hardcoded direction of a global light
		float d = lightDir.Dot( normal );
		if (d>=0) d*=d;
		else d = -sqrt(-d);
		return pow(d * 0.5f + 0.5f, 2.2f); // gives a number between 0 and 1, 
which i use to multiply material color
	}

MagnusWootton said:
Sort of looks like I cast a billion rays to get the global illumination effect

Maybe, but ofc. those tricks break if you put the model into a real environment, especially indoors.
Your environment is empty, so those million rays would not hit anything, and thus results are ok.

For the same reason all those PBR model viewers can look quite foto-realistic. Their environment is modeled with an environment image, meant to show scenery at infinite distance, e.g. a skymap.
So if your model is mostly convex, preventing self occlusion and reflection, we get realistic results without a need to calculate global illumination.

But once we put the model into a room, or a street surrounded by buildings, the trick becomes obvious and we feel something is wrong.

Nice trick with the dot product! Ill definitely try it! because getting rid of the zero pixels is good for the system.

Maybe if u did an indoor shot, you mask the effect with screen space ambient occlusion and it might turn out a little better.

I'm adding a terrain to it now, so I'll post here with the SSAO if I get it done, but I'm in a sea of bugs right now so might be delays. :P

Here it is with the ambient occlusion mask, I guess it looks pretty nice with the shadows taken off, its like dirt on your screen that u dont want. ๐Ÿ™‚

in this first one, I first had it activated and I thought the occlusions were on but they arent, but I have it here cause it sorta looks nice just with the ambient light by itself, and its a billion times quicker.

here it is on the gtx 980

here it is on the rtx 3080 (ultra speed muscle mode)

This topic is closed to new replies.

Advertisement