Unity Shader Overview

Thanks to these posts and blogs: Michael Sanders Catike Coding Alan Zucconi Unity has 3 types of shader: surface shader, fragment and vertex shader, and the obsolete fixed function shader. They all have the same anatomy. Catlike Coding Shader "MyShader" { Properties { // The properties of your shaders // - textures // - colours // - parameters // ... _MyTexture ("My texture", 2D) = "white" {} _MyNormalMap ("My normal map", 2D) = "bump" {} // Grey _MyInt ("My integer", Int) = 2 _MyFloat ("My float", Float) = 1....

November 30, 2019 · Kyle Fang

Unity Physically Based Render

Lambertian and Blinn-Phong Lambertian Model Lambertian model is based on lambertian reflectance, is the property that defines an ideal “matte” or diffusely reflecting surface. The reflected quantity is equal to the vertical component of the incident light ray. Shader "Custom/LambertianShader" { Properties { _MainTex ("Texture", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM #pragma surface surf SimpleLambert struct Input { float2 uv_MainTex; }; sampler2D _MainTex; void surf (Input IN, inout SurfaceOutput o) { o....

Kyle Fang

Unity Surface Shader

Shader "Example/Diffuse Simple" { SubShader { Tags { "RenderType" = "Opaque" } CGPROGRAM #pragma surface surf Lambert struct Input { float4 color : COLOR; }; void surf (Input IN, inout SurfaceOutput o) { o.Albedo = 1; // 1 = (1,1,1,1) = white } ENDCG } Fallback "Diffuse" } #pragma surface surf Lambert specify the shader is surface and use Lambertian Lighting Model. SurfaceOutput has several properties to determine the final aspect of a material....

Kyle Fang