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

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.
主站蜘蛛池模板: 吉木萨尔县| 洛浦县| 新邵县| 两当县| 泰来县| 福建省| 济宁市| 丹巴县| 舟曲县| 临高县| 原平市| 稻城县| 阿合奇县| 青浦区| 洪雅县| 韶山市| 南木林县| 成武县| 大洼县| 阳城县| 中西区| 柘城县| 马鞍山市| 大港区| 六枝特区| 慈利县| 永平县| 罗甸县| 丹江口市| 桑植县| 托克逊县| 江川县| 鹿邑县| 土默特右旗| 吉林省| 新巴尔虎左旗| 乌鲁木齐县| 方城县| 化州市| 西乌珠穆沁旗| 西畴县|