Adsgouraud. VP

Source: Internet
Author: User
// Ads point lighting shader // vertex shader # version 330in vec4 vvertex; // The vertex position [world coordinates] In vec3 vnormal; // vertex normal [world coordinates] smooth out vec4 vvaryingcolor; Uniform vec4 ambientcolor; // ambient light uniform vec4 diffusecolor; // diffuse light uniform vec4 specularcolor; // mirror reflected light uniform vec3 lightposition; // The Position of the light source [world coordinates] uniform mat4 mvpmatrix; // Model-View-projection matrix uniform mat4 mvmatrix; // Model-View matrix uniform mat3 normalmatrix; // model without translation-view matrix void main (void) {// obtain the position of the vertex in the camera coordinate system. vec4 vec4temp = mvmatrix * vvertex; // offset the possible scaling of vec3 vvertexinview = vec4temp. XYZ/vec4temp. w; // calculate the unit vector vec3 vlightdirection = normalize (lightposition-vvertexinview) from the vertex to the light source; // obtain the position of the vertex normal in the camera coordinate vec3 vnormalinview = normalmatrix * vnormal; float fdiffusecolorweight = max (0, dot (vlightdirection, vnormalinview); // calculate the diffuse color vvaryingcolor = diffusecolor * fdiffusecolorweight; // overlay the ambient light, this cannot be placed after the calculation of the mirror reflection vvaryingcolor + = ambientcolor; // calculate the mirror reflection color if (fdiffusecolorweight> 0) {// calculate the reflected ray vector vec3 relectiondirection ction = normalize (reflect (-lightposition, vnormalinview); float ftemp = max (0, dot (relectiondirection ction, vnormalinview )); if (ftemp> 0) {float vspecularcolorweight = POW (ftemp, 128); // overlay the mirror highlight vvaryingcolor. RGB + = vec3 (vspecularcolorweight, vspecularcolorweight, vspecularcolorweight);} // projects the vertex from the world coordinate system to the cropped cube gl_position = mvpmatrix * vvertex ;}

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.