Shader trip to the plane shadow (planar shadow)

Source: Internet
Author: User

According to the derivation in the second chapter of the book "Real-time Shadow", the simplest shadow technique is realized.
Planar shadow a projection matrix to project the vertices of an object illuminated by the light in the direction of the light to the plane that receives the shadow.

The key question is how the projection matrix gets.
The shadow plane is represented by the following formula: where n is the normal, D is constant, and X is the point on the plane.
The light and the line in which the vertex is projected are represented by the following formula: where L is the position of the light source, V is the vertex being projected, and T is the coefficient.
Derivation process:

So finally the vertex coordinates that are projected onto the plane are written in the form of homogeneous coordinates:

The form of a matrix is

In order to implement in code, I added two new classes, namely mesh and program, because in the destruction involves the removal of OpenGL internal resources, so if you do not handle the copy construction and copy assignment will cause problems, So before you think about a good solution, they both become classes that can't be copied.
Code has been updated HTTP://WWW.EYESOURCECODE.COM/T/58005/1/1

Shader trip to the plane shadow (planar shadow)

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.