UnityShader基础效果-Surface Shader

匿名 (未验证) 提交于 2019-12-03 00:13:02

Ox00 Surface Shader Syntax

常用的三种输出数据格式:

//Standard output structure of surface shaders is this:

struct SurfaceOutput

{

fixed3 Albedo; // diffuse color

fixed3 Normal; // tangent space normal, if written

fixed3 Emission;

half Specular; // specular power in 0..1 range

fixed Gloss; // specular intensity

fixed Alpha; // alpha for transparencies

};

struct SurfaceOutputStandard

{

fixed3 Albedo; // base (diffuse or specular) color

fixed3 Normal; // tangent space normal, if written

half3 Emission;

half Metallic; // 0=non-metal, 1=metal

half Smoothness; // 0=rough, 1=smooth

half Occlusion; // occlusion (default 1)

fixed Alpha; // alpha for transparencies

};

struct SurfaceOutputStandardSpecular

{

fixed3 Albedo; // diffuse color

fixed3 Specular; // specular color

fixed3 Normal; // tangent space normal, if written

half3 Emission;

half Smoothness; // 0=rough, 1=smooth

half Occlusion; // occlusion (default 1)

fixed Alpha; // alpha for transparencies

};

 

0x01 Surface Shader compile directives

surfaceFunction

lightModel

Standard lighting

使用SurfaceOutputStandard

StandardSpecular lighting

Lambert and BlinnPhong

struct Input

{

    float2 uv_MainTex;

}

float3 viewDir

float4 color

float4 screenPos

float3 worldPos

float3 worldRefl

float3 worldNormal

float3 worldRefl;INTERNAL_DATA

float3 worldNormal;INTERNAL_DATA

Transparency and alpha testing

使用alpha and alphatest指令

 

alpha

alpha:auto

alpha:blend

alpha:fade

alpha:premul

alphatest:VariableName

keepalpha

decal:add

decal:blend

Custom modifier functions用于计算更改输入的顶点数据,或更改最终计算的片元色

vertex:VertexFunction

finalcolor:ColorFunction

 

finalgbuffer:ColorFunction

finalprepass:ColorFunction

在forward path生效。base path

Shadows and Tessellation 阴影和网格细分

addshadow

 

fullforwardshadows

tessellate:TessFunction

Code generation options

调整生成着色器代码选项,使得shader更小加载更快

 

exclude_path:deferred,

exclude_path:forward,

exclude_path:prepass

noshadow

noambient

novertexlights

nolightmap

nodynlightmap

nodirlightmap

nofog

nometa

noforwardadd

nolppv

noshadowmask

Miscellaneous options 各种其他选项

softvegetation

only be rendered Soft Vegetation

interpolateview

halfasview

approxview

dualforward

dithercrossfade

 

0x02 Surface Shader Light Model

Lighting.cginc

UnityLambertLight

LightingLambert

LightingLambert_Deferred

//..

LightingLambert_PrePass

//..

UnityBlinnPhongLight

LightingBlinnPhong

//..

LightingBlinnPhong_Deferred

//..

LightingBlinnPhong_PrePass

//..

LightingLambert_GI

//..

LightingBlinnPhong_GI

//..

 

half4 Lighting<Name>_Deferred (SurfaceOutput s, UnityGI gi, out half4 outDiffuseOcclusion, out half4 outSpecSmoothness, out half4 outNormal); deferred lighting paths

half4 Lighting<Name>_PrePass (SurfaceOutput s, half4 light); Use this in light prepass (legacy deferred) lighting paths. in light prepass (legacy deferred) lighting paths

自定义光照函数:

 

0x03 Example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!