【Unity5.x Shaders】最基本的Surface Shader-Diffuse shader以及Surface中的三种输出结构
2016-10-17 22:33
288 查看
某些物体可能具有均匀的颜色和光滑的表面,但光滑程度不足以照射反射光。
这些哑光材料最好用Diffuse Shader。 在现实世界中,不存在纯diffuse materials
Diffuse shader经常出现在游戏中,下面就是一个简单的Diffuse shader代码
这是一个从Standard Shader改装的的Shader,它将使用基于物理的渲染去模仿灯光在模型上的行为。
如果你想实现一个非真实感(non-photorealistic)的外观,可以改变第一个预处理指令使用Lambert光照模型。
如果使用了这个模型,surf函数中的输出结构SurfaceOutputStandard需要改成SurfaceOutput。
不同的Surface光照模型需要不同的Surface输出结构
在Unity5中,有三种主要的输出结构:
注意:这里的Specular完全不同于SurfaceOutput中的Specular
它允许指定一个颜色而不是一个单值。
正确使用Surface Shader,是使Surface输出结构输出正确的值
这些哑光材料最好用Diffuse Shader。 在现实世界中,不存在纯diffuse materials
Diffuse shader经常出现在游戏中,下面就是一个简单的Diffuse shader代码
Shader "Custom/DiffuseShader" { 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" }
这是一个从Standard Shader改装的的Shader,它将使用基于物理的渲染去模仿灯光在模型上的行为。
如果你想实现一个非真实感(non-photorealistic)的外观,可以改变第一个预处理指令使用Lambert光照模型。
#pragma surface surf Lambert
如果使用了这个模型,surf函数中的输出结构SurfaceOutputStandard需要改成SurfaceOutput。
Surface输出结构
Shader允许你通过Surface的输出结构将材质的渲染属性传递给光照模型。不同的Surface光照模型需要不同的Surface输出结构
在Unity5中,有三种主要的输出结构:
SurfaceOutput
一般的光照模型例如Lambert光照模型struct SurfaceOutput { fixed3 Albedo; //对光源的反射率 fixed3 Normal; //对应切线空间法线方向 fixed3 Emission; //自发光 half Specular; //高光反射中的指数部分的系数。 fixed Gloss; //高光反射中的强度系数 half Alpha; //透明通道
SurfaceOutputStandard
标准光照模型 使用此结构输出struct SurfaceOutputStandard { fixed3 Albedo; //材质的基础颜色(无论是漫反射还是高光) fixed3 Normal; half3 Emission; //类型被声明为half3,注意在SurfaceOutput中被定义为fixed3 half Alpha; half Occlusion; //遮挡(默认为1) half Smoothness;//光滑程度(0=粗糙, 1=光滑) half Metallic; //0=非金属, 1=金属
SurfaceOutputStandardSpecular
标准镜面光照模型 使用此结构输出struct SurfaceOutputStandardSpecular { fixed3 Albedo; fixed3 Specular; // 镜面反射颜色 fixed3 Normal; half3 Emission; half Smoothness; half Occlusion; fixed Alpha; };
注意:这里的Specular完全不同于SurfaceOutput中的Specular
它允许指定一个颜色而不是一个单值。
正确使用Surface Shader,是使Surface输出结构输出正确的值
相关文章推荐
- 数据结构之顺序表增、删、查找、初始化以及顺序表输出基本相关操作
- C语言程序设计 第三章 三种基本程序结构
- 疑惑:程序基本结构以及流程控制
- B树(B-Tree)的由来、数据结构、基本操作以及数据库索引的应用
- PHP第二课 了解PHP的基本语法以及目录结构
- Shader学习之旅:RenderMonkey初体验以及基本使用方法
- OLAP三种基本实现结构
- Android项目结构以及各个控件基本属性
- 【Unity Shaders】Diffuse Shading——创建一个基本的Surface Shader
- 【Unity Shaders】Diffuse Shading——创建一个基本的Surface Shader
- PHP学习笔记(二) 了解PHP的基本语法以及目录结构
- ubuntu11.10安装tomcat7以及基本的目录结构和使用方法
- 黑马程序员-c#的三种最基本结构
- objective-c(四)-基本数据类型以及循环和选择结构
- 程序的三种基本结构
- 第01章 CORE C++_C++ 基本结构_注释_输出语句_输入语句_初始化_条件控制_ASCII码值_转义字符_常量_变量_类型长度_运算符
- 定义一个不受计算机字长限制的整数类INT,要求INT与INT以及INT与C++基本数据类型int之间能进行+、-、×、÷和=运算,并且能通过cout输出INT类型的值。(持续添加)
- HTML笔记1 - 编辑器、基本概念以及基础结构
- 结构化程序的三种基本逻辑结构
- Linux系统基本结构之一 内核的组成以及运行原理