top of page

Slightly better light intensity

Compare the two screenshots and ask yourself which looks more like what you see in bright daylight.


Let us start from the beginning. To apply sunlight to the object you need the shadow it is receiving, calculate the angle to the sun and multiply it by the colour of the sun:

float attenuation = dot(_WorldSpaceLightPos0.xyz, normal);
float3 sunlight = lightColor * shadow * attenuation ;

This gets you:

Then you add your ambient light, multiply by texture colour and produce the final image. Also specular if you so fancy.

Let's remember that we probably aren't using light's real value in our video games. Unless you actually do photorealistic renderings, in which case stop readings! This is for cheaters, who fake stuff.

Let's look closer. The light is just too sharp. But also too smooth. Sure, the ambient will take care of the darker areas, but that light just gives away the game.

Now, correct or not, I like to give myself a slider there, to remap the original "attenuation " value into this:

Or to this (ignore colour differences):

The code is a bit of a mess and is subject to change, but for completeness's sake, I'll post it here:

float attenuation = _qc_Sun_Atten;
float aoObscuring = smoothstep(1,0,attenuation) * ao * 0.5;
float angle = dot(_WorldSpaceLightPos0.xyz, normal);
angle = smoothstep(aoObscuring,1,angle);
attenuation = 1-pow(1-angle,1 + (1-ao) * 2 * attenuation);

For night scenes you would want that attenuation to be lower:

Higher for daytime:

And for cloudy days crank it up as high as possible to imitate the scattering by the clouds.

Now, none of the things mentioned above have anything to do with physically based rendering. These are artistic solutions designed to circumvent certain hardware limitations.


Your shaders can look slightly better now! Or worse, you judge.

Comments


bottom of page