官术网_书友最值得收藏!

How to do it...

Open up the SimpleDiffuse shader you've created and make the following changes: 

  1. In the Properties section, remove all of the variables except for  _Color:
  Properties 
{
_Color ("Color", Color) = (1,1,1,1)
}
  1. From the SubShader{} section, remove the _MainTex, _Glossiness, and _Metallic variables. You should not remove the reference to uv_MainTex as Cg does not allow the Input struct to be empty. The value will simply be ignored.
  2. Also, remove the UNITY_INSTANCING_BUFFER_START/END macros and the comments used with them.
  1. Remove the content of the surf() function and replace it with the following:
void surf (Input IN, inout SurfaceOutputStandard o) 
{
o.Albedo = _Color.rgb;
}
  1. Your shader should look as follows:
Shader "CookbookShaders/Chapter03/SimpleDiffuse" {
Properties
{
_Color ("Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200

CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows

// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0


struct Input
{
float2 uv_MainTex;
};

fixed4 _Color;

void surf (Input IN, inout SurfaceOutputStandard o)
{
o.Albedo = _Color.rgb;
}

ENDCG
}
FallBack "Diffuse"
}

The two lines below CGPROGRAM is actually one line and is cut off due to the size of the book.

  1. As this shader has been refitted with a Standard Shader, it will use physically-based rendering to simulate how light behaves on your models.

If you are trying to achieve a non-photorealistic look, you can change the first #pragma directive so that it uses Lambert rather than Standard. If you do so, you should also replace the  SurfaceOutputStandard parameter of the surf function with SurfaceOutput. For more information on this and the other lighting models that Unity supports, Jordan Stevens put together a very nice article about it, which you can see here: http://www.jordanstevenstechart.com/lighting-models

  1. Save the shader and pe back into Unity. Using the same instructions as in the Creating a basic Standard Surface Shader recipe located in  Chapter 2Creating Your First Shader, create a new material called SimpleDiffuseMat and apply our newly created shader to it. Change the color to something different, such as red, by clicking on the window next to the Color property in the Inspector window while selected.
  2. Then, go into the Models folder of this book's example code and bring the bunny object into our scene by dragging and dropping it from the Project window into the Hierarchy window. From there, assign the SimpleDiffuseMat material to the object:
  1. You can double-click on an object in the Hierarchy tab in order to center the camera on the object that's been selected.
主站蜘蛛池模板: 宜黄县| 五家渠市| 大名县| 泽库县| 永修县| 大足县| 贵州省| 武陟县| 五河县| 沙河市| 开封县| 鄂托克旗| 萝北县| 三河市| 丰宁| 怀集县| 西畴县| 澜沧| 开江县| 青浦区| 故城县| 永清县| 瓮安县| 绵竹市| 宁津县| 香港 | 泌阳县| 阳东县| 霍城县| 荃湾区| 双柏县| 安多县| 巫山县| 长沙市| 绿春县| 靖宇县| 双流县| 美姑县| 辉南县| 顺平县| 大城县|