Posts

Showing posts with the label lambert

Custom lighting models

Don't think I want to cover writing actual custom lighting models just yet. However, here is how you might implement the Lambert lighting model within your shader. Blinn is done below, with a brief explanation. Essentially they are like mini functions. They must begin with the word "Lighting" and match the name of the lighting model that you specify in the #pragma surface surf ______ Lambert works by taking the dot product of the surface normal and light direction vectors. Where the light is aligned to the surface normal, the surface will seem brighter. As it gets closer to 90degrees/perpendicular the surface will be darker. This value NdotL is multiplied by the surface colour (albedo) ,the colour of any lights (_LightColor0, a built in variable) and the attenuation, which is how intense the light is.  Shader "Dave/customLightingmodel" {     Properties{         _Color("Color",color) = (1,1,1,1)     }     Sub...

simple CG surface shader breakdown

 A simple shader in Unity has a certain structure.. It starts with the main block: shader("folder/name") { //everything in here } We have the word "shader" that tells Unity we're writing a shader. The "folder" part will create a folder in the shader drop down menu of the Unity Material. The "name" will be the name of your shader that sits in that folder. Next comes the Properties - these are the exposed properties that the user will see in the Unity inspector. These sit inside the shader block, as does everything else we're going to add. shader("folder/name") { Properties {     _myColor("My Color",color)=(1,1,1,1)     _myTex("My Texture",2D)="White"{}     _myFloat("My Float Value",float)=1.3 } }  So this is our first sub block of the shader. It seems like a lot of coders like to put the underscore in front of their defined _names. I guess this is good for identifying user-created variable ...