Starting to learn CG shader language

lambert-shaded-capsule Over the last few days, I have been learning about the CG shader language for Unity 3D. I started out following a tutorial to make a simple lambert shader, as pictured here. Shaders use trigonometry to calculate the lighting on each pixel or vertex or the mesh.  To find the brightness of a specific area, you can take the dot product of the surface’s normal direction, and the direction of the light you are calculating for.  The color of the area is then found by multiplying the light’s color ( _LightColor0.xyz ) by the calculated shadow.  In CG, this looks like

The attenuation value ( atten ) is used for light falloff, so as a point light gets further away from the surface, it provides fewer lumens.  The brightness variable is then added to UNITY_LIGHTMODEL_AMBIENT.xyz to account for the ambient light in the scene, and then returned as part of the vertex shader function’s output.

 

 

This new knowledge will be useful for the new game I will be working on over the last semester of my senior year in high school for the Computer Game Programming course at Fullerton College.

Posted in Programming, Projects, Sole Champion and tagged ,
Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL.



Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">