"Normal Shader" Uniforms
This shader has no uniforms. But if it did, this is where you could experiment with their values!
Favorite This Shader

Normal Shader

Compose Edit source
Export…

Description

An unlit shader program that renders the normals of an object in rgb. This shader program introduces several new concepts over our previous shader, https://shaderfrog.com/app/view/3150. First, we request addition information from the GPU to use in the vertex shader, the modelMatrix and the normal. Second, we declare a variable, vNormal, that we will use to store custom information that will be passed from our vertex shader to the fragment shader. Third, we perform an additional calculation in our vertex shader, namely, we multiply the normal (which is in model space) by the model to world space matrix to get the normal in world space. To do this, notice several things. First, we add a w component to the three dimensional normal, but we force that w to be 0. This effectively removes the translation effects of the model to world space transformation. This is what we want since normals are vectors and don't have a sense of position. Second, we normalize the result, we assures us that the result is of length one. This will important later when we calculate lighting with these normals. Third, we call ".xyz" at the end of the line to get the xyz values of the result as a vec3. You can call the components of a vector in any order, for example ".zyx" This is called swizzling and can be very useful. Lastly, we use this as the color for our fragment shader. Note that this can be a useful shader for debugging the normals of a model you have created when something isn't rendering right. You can find a similar shader for Unity here: https://github.com/bricksSeeds/unity/tree/master/DebuggingShaders Created for Computer Graphics 4620, a course offered at the University of Nebraska at Omaha. @bricksphd

Tags

This shader has no tags.

Comments

No comments

Add a comment

Markdown is supported in comments. Learn more.
Please respect our Code of Conduct! Be cool like Snoop Shady Frog.