【UnityShader】学习笔记 灯光


官网教程地址:https://docs.unity3d.com/Manual/SL-Material.html

Material Block

This contains settings for how the material reacts to the light. Any of these properties can be left out, in which case they default to black (i.e. have no effect).

Diffuse color漫反射: The diffuse color component. This is an object’s base color.

Ambient color环境光: The ambient color component. This is the color the object has when it’s hit by the ambient light set in the Lighting Window.

Specular color镜面反射: The color of the object’s specular highlight.

Shininess number: The sharpness of the highlight, between 0 and 1. At 0 you get a huge highlight that looks a lot like diffuse lighting, at 1 you get a tiny speck.

Emission color自发光: The color of the object when it is not hit by any light.

The full color of lights hitting the object is:

Ambient * Lighting Window’s Ambient Intensity setting + (Light Color * Diffuse + Light Color * Specular) + Emission

The light parts of the equation (within parenthesis) is repeated for all lights that hit the object.

Typically you want to keep the Diffuse and Ambient colors the same (all built-in Unity shaders do this).

 漫反射:对应的是镜面反射,表面光滑的物体在反射的时候会有光斑,是镜面反射;表面粗糙的物体反射的时候角度是不固定的,会出现漫反射的效果。

 镜面反射和漫反射的最大区别是:镜面反射的物体表面比较光滑,有一个高光效果

Shader "Custom/NewSurfaceShader" {
	Properties{
		_Color("Main Color", Color) = (1,1,1,0)
		_SpecColor("Spec Color", Color) = (1,1,1,1)
		_Emission("Emmisive Color", Color) = (0,0,0,0)
		_Shininess("Shininess", Range(0.01, 1)) = 0.7
		_MainTex("Base (RGB)", 2D) = "white" {}
	}
		SubShader{
		Pass{
		Material{
		Diffuse[_Color]
		Ambient[_Color]
		Shininess[_Shininess]
		Specular[_SpecColor]
		Emission[_Emission]
	}
		Lighting On
		SeparateSpecular On
		SetTexture[_MainTex]{
		Combine texture * primary DOUBLE, texture * primary
	}
	}
	}
}