[OpenGL] How to draw shadow

Source: Internet
Author: User
Background

Shadow is a shadow. It is a dark area generated when the light is blocked by an opaque object. It is opposite to the light source.

There is no shadow during the blender editing process and it can only be displayed after being rendered. Currently, there is a blender-based project that requires shadow to be displayed during editing.

Shadow Algorithm

The popular shadow algorithms are Shadow Mapping and shadow volumn.

Because there is a block between the object and the light source, the object will be in the shadow. This isShadow Mapping. No matter how the viewpoint changes, the shadow map can be used repeatedly as long as the positions of the light source and the object remain unchanged. The procedure is as follows:

  1. Render the entire scene in the light source coordinates to obtainDepth MapIn this figure, each pixel value represents the scenarioDepth of the pixel closest to the light source.
  2. Restore to the normal position to render the entire scene, calculate the distance from each pixel to the light source, and thenCompare this value with the value corresponding to depth mapTo determine whether the pixel is in the shadow.
  3. For shadowed fragment and lighted FragmentPerform different illumination calculations respectivelyIn this way, you can get the shadow effect.

  Shadow volumeThe basic principle is to calculate the shadow area in the scene based on the relationship between the light source and the Shelter location, and then detect all objects to determine whether they are affected by the shadow.

Because blender-based projects are static scenarios and shadow ing is relatively simple, you can use the Shadow Mapping algorithm.

[OpenGL] How to draw shadow

Related Article

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.