Posts

Showing posts with the label phong

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...

Lighting models other than Lambert - BlinnPhong, Standard, StandardSpecular

So far we've just been using the Lambert lighting model in our shaders. This is all well and good for simple non-shiny surfaces - but if we do want proper specular highlights, or more physical accuracy we'll want to use some other lighting models. Blinn Phong First up is BlinnPhong. To use it, change the usual #pragma statement to     #pragma surface surf BlinnPhong Also, in the Properties block we now will be using a few more variables -  Properties{     _Color("Colour",color)=(1,1,1,1)     _SpecColor("Specular Colour",color)=(1,1,1,1)     _Spec("Specular",Range(0,1))=0.5     _Gloss("Gloss",Range(0,1))=0.5 } The _Spec/Specular controls the coverage of the highlight & the _Gloss/Gloss controls the strength of the highlight. We do not have to define the _SpecColor within the SubShader block -Unity already has this built in for some reason & might complain if you do redefine it. Datatypes are - Float4/...