Using simple technique to improve your Lighting Effect

Source: Internet
Author: User

 Using simple technique to improve your Lighting Effect

For personal use only, do not reprint, do not use for any commercial purposes.

Well, I haven't written anything related to rendering for a long time. For those advanced and complex rendering technologies, let's take a look.ShaderxRightJ. The following describes how to slightly modify the most basic illumination equation to significantly improve the illumination effect. In mathematics, the formula for describing the basic illumination model is as follows:

Surfacecolor = emissive + ambient + diffuset + specular.

Here we will only discuss Ambient And Diffuse . Ambient It is actually the most complex and difficult-to-calculate element in the equation. More realistic simulation methods need to be calculated Environment map , Radiance , Spherical Harmonic (SH) And so on. The simplest way is to directly Ambient As a constant. This is the best evidence that people like to go to extremes. Most high-end games use the former, while most online games still use the simplest method. Because Sh So far, I have no courage to implement it myself. I just want to slightly modify the most basic method to make it look a little better.

As shown in the model on the left, constantAmbientThe result is very"Ugly"In addition to the object contour, all details are lost, and even the rendered3DModel. If you map the environment, orHemiphere LightingIf we have some theoretical knowledge, we should know that we generally assume that the ambient light of an object comes from the semi-spherical area indicated by the object's normal. Here we do not care about the distribution of light on this hemisphere, and assume that all light directions in the scene are vertical downward, and the environmental light of the object is determined by the normal and vertical angles.CodeVery simple:

Float3 light3 = lerp (ambientcolor * 0.5f, ambientcolor, saturate (normal. y * 0.5 + 0.5f ));

If the normal is perpendicular to the top, it is the part that obtains the Most ambient light, while the vertical down part is the least absorbing light. From the model on the right, we can see that the effect is very obvious and it can be said that a qualitative change has taken place.

Next let's take a lookDiffuseThe most common calculation formula is probably

Diffusecolor = lightcolor * max (dot (n, l), 0)

The two leftmost models are rendered using this method. If the positive effect is not bad, the effect of the backlights is terrible.DOT (n, l)Negative values are black and constant.AmbientSimilarly, all details are lost, and the picture looks veryFlat. However, in a real environment, even on the backlight side, even the objects with a back-to-light source are illuminated by the scattering reflection of the fabric and the surrounding objects.

Let's make some modifications to the formula so thatDOT (n, l)When the value is negative, the brightness also changes:

Diffuse = (dot (n, l) * 0.5 + 0.5) * lightcolor;

We map the brightness in all directions of the normal0,1Instead of simply intercepting some of them. Intermediate result2As shown in the following figure, we can see that the backlight has a much better effect and all the details are retained. But it seems a little too bright, or even difficult to identify the direction of the light. In this case, the light is reduced.

Diffuse = (dot (n, l) * 0.5 + 0.5) * lightcolor;
Diffuse * = diffuse;

Here we do a square operation. From the rightmost2Model, we can see that the front side of the Light brightness not only back to the normal level, the light and shade is also more smooth, and the back, all the important details (waist belt, leggings) no.

NowAmbientAndDiffuseMerged, left2Models use traditional methods, while2The version we modified. Obviously, the light on the right side is not only smooth, but also stereoscopic. In particular, the illumination of the backlight is greatly improved.


 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.