// Forward pass. Shades all light in a single pass. GI + emission + Fog
Pass//前向渲染的Pass,所有光照效果都在该Pass中计算,包括全局光照、自发光和雾效
{
// Lightmode matches the ShaderPassName set in UniversalRenderPipeline.cs. SRPDefaultUnlit and passes with
// no LightMode tag are also rendered by Universal Render Pipeline
Name "ForwardLit"//Pass的名字,给Pass命名,方便复用
Tags{"LightMode" = "UniversalForward"}//光照模式标签一定要与UniversalRenderPipeline.cs中对应,如果先写Unlit shader,可以不用该标签
Blend[_SrcBlend][_DstBlend]//混合操作,参数的值来自于 Properties块中的定义
ZWrite[_ZWrite]
Cull[_Cull]
HLSLPROGRAM //Shader代码块不像内置渲染管线一样使用CGPROGRAM--ENDCG包裹,而使用HLSLPROGRAM--ENDHLSL包裹
//CG表示 C for Graphic,HLSL表示High Level Shader Language
//使用HLSL中引用任何内容都需要显式添加,而CG会隐式添加,会添加进不需要的东西,导致文件变大
#pragma only_renderers gles gles3 glcore d3d11 //图形API预编译指令,只为给定的图像API编译该Shader,包括OpenGL 3.x/4.x 、OpenGL ES 2.0/3.x 、D3D 11/12
#pragma target 2.0 //指定shader program应用的最低等级的shader model,2.0适用于 Unity 支持的所有平台。DX9 着色器模型 2.0。 有限数量的算术和纹理指令;8 个插值器;没有顶点纹理采样;片元着色器中没有衍生指令;没有显式的 LOD 纹理采样。
//
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing//着色器变体编译指令,使该Shader支持GPU Instancing功能,
#pragma instancing_options renderinglayer//指定所有实例化后的对象的渲染层级
// -------------------------------------
// Material Keywords
//#pragma shader_feature_local表示定义local keywords,后缀_fragment表示关键字用于片元着色器阶段,这些关键字与材质面板上的参数有关,遇到的时候再解释
//关键字的名字前一般要带下划线
#pragma shader_feature_local _NORMALMAP
#pragma shader_feature_local _PARALLAXMAP
#pragma shader_feature_local _RECEIVE_SHADOWS_OFF
#pragma shader_feature_local _ _DETAIL_MULX2 _DETAIL_SCALED
#pragma shader_feature_local_fragment _SURFACE_TYPE_TRANSPARENT
#pragma shader_feature_local_fragment _ALPHATEST_ON
#pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON
#pragma shader_feature_local_fragment _EMISSION
#pragma shader_feature_local_fragment _METALLICSPECGLOSSMAP
#pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature_local_fragment _OCCLUSIONMAP
#pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
#pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
#pragma shader_feature_local_fragment _SPECULAR_SETUP
// -------------------------------------
// Universal Pipeline keywords
// #pragma multi_compile表示global keywords,与shader_feature的区别是, Unity只为shader_feature中使用的关键字编译着色器变体shader variant
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN//一次声明多个关键字
#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
#pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile_fragment _ _SHADOWS_SOFT
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION
#pragma multi_compile_fragment _ _LIGHT_LAYERS
#pragma multi_compile_fragment _ _LIGHT_COOKIES
#pragma multi_compile _ _CLUSTERED_RENDERING
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
#pragma multi_compile _ SHADOWS_SHADOWMASK
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile_fog
#pragma multi_compile_fragment _ DEBUG_DISPLAY
//定义顶点和片元着色器
#pragma vertex LitPassVertex
#pragma fragment LitPassFragment
//添加引用文件,该Pass没有变量声明、顶点着色器函数、片元着色器函数,这些代码在引用的两个文件中
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl"
ENDHLSL
}
|