您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
172 行
5.3 KiB
172 行
5.3 KiB
Pass
|
|
{
|
|
Tags{"LightMode" = "UniversalForward"}
|
|
|
|
// Material options generated by graph
|
|
${Tags}
|
|
${Blending}
|
|
${Culling}
|
|
${ZTest}
|
|
${ZWrite}
|
|
HLSLPROGRAM
|
|
// Required to compile gles 2.0 with standard srp library
|
|
#pragma prefer_hlslcc gles
|
|
#pragma exclude_renderers d3d11_9x
|
|
#pragma target 2.0
|
|
|
|
// -------------------------------------
|
|
// Universal Pipeline keywords
|
|
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
|
|
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
|
|
#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
|
|
#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
|
|
#pragma multi_compile _ _SHADOWS_SOFT
|
|
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
|
|
|
|
// -------------------------------------
|
|
// Unity defined keywords
|
|
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
|
|
#pragma multi_compile _ LIGHTMAP_ON
|
|
#pragma multi_compile_fog
|
|
|
|
//--------------------------------------
|
|
// GPU Instancing
|
|
#pragma multi_compile_instancing
|
|
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
|
|
// Defines generated by graph
|
|
${Defines}
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
|
|
|
|
${Graph}
|
|
struct GraphVertexOutput
|
|
{
|
|
float4 clipPos : SV_POSITION;
|
|
DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, 0);
|
|
half4 fogFactorAndVertexLight : TEXCOORD1; // x: fogFactor, yzw: vertex light
|
|
float4 shadowCoord : TEXCOORD2;
|
|
|
|
// Interpolators defined by graph
|
|
${VertexOutputStruct}
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
|
|
GraphVertexOutput vert (GraphVertexInput v)
|
|
{
|
|
GraphVertexOutput o = (GraphVertexOutput)0;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_TRANSFER_INSTANCE_ID(v, o);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
|
|
// Vertex transformations performed by graph
|
|
${VertexShader}
|
|
VertexDescriptionInputs vdi = (VertexDescriptionInputs)0;
|
|
|
|
// Vertex description inputs defined by graph
|
|
${VertexShaderDescriptionInputs}
|
|
VertexDescription vd = PopulateVertexData(vdi);
|
|
v.vertex.xyz = vd.Position;
|
|
|
|
// Vertex shader outputs defined by graph
|
|
${VertexShaderOutputs}
|
|
float3 lwWNormal = TransformObjectToWorldNormal(v.normal);
|
|
|
|
VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
|
|
|
|
// We either sample GI from lightmap or SH.
|
|
// Lightmap UV and vertex SH coefficients use the same interpolator ("float2 lightmapUV" for lightmap or "half3 vertexSH" for SH)
|
|
// see DECLARE_LIGHTMAP_OR_SH macro.
|
|
// The following funcions initialize the correct variable with correct data
|
|
OUTPUT_LIGHTMAP_UV(v.texcoord1, unity_LightmapST, o.lightmapUV);
|
|
OUTPUT_SH(lwWNormal, o.vertexSH);
|
|
|
|
half3 vertexLight = VertexLighting(vertexInput.positionWS, lwWNormal);
|
|
half fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
|
|
o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
|
|
o.clipPos = vertexInput.positionCS;
|
|
|
|
#ifdef _MAIN_LIGHT_SHADOWS
|
|
o.shadowCoord = GetShadowCoord(vertexInput);
|
|
#endif
|
|
return o;
|
|
}
|
|
|
|
half4 frag (GraphVertexOutput IN ${FaceSign}) : SV_Target
|
|
{
|
|
UNITY_SETUP_INSTANCE_ID(IN);
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
|
|
|
|
// Pixel transformations performed by graph
|
|
${PixelShader}
|
|
SurfaceDescriptionInputs surfaceInput = (SurfaceDescriptionInputs)0;
|
|
|
|
// Surface description inputs defined by graph
|
|
${PixelShaderSurfaceInputs}
|
|
SurfaceDescription surf = PopulateSurfaceData(surfaceInput);
|
|
|
|
float3 Albedo = float3(0.5, 0.5, 0.5);
|
|
float3 Specular = float3(0, 0, 0);
|
|
float Metallic = 1;
|
|
float3 Normal = float3(0, 0, 1);
|
|
float3 Emission = 0;
|
|
float Smoothness = 0.5;
|
|
float Occlusion = 1;
|
|
float Alpha = 1;
|
|
float AlphaClipThreshold = 0;
|
|
|
|
// Surface description remap performed by graph
|
|
${PixelShaderSurfaceRemap}
|
|
InputData inputData;
|
|
inputData.positionWS = WorldSpacePosition;
|
|
|
|
#ifdef _NORMALMAP
|
|
inputData.normalWS = normalize(TransformTangentToWorld(Normal, half3x3(WorldSpaceTangent, WorldSpaceBiTangent, WorldSpaceNormal)));
|
|
#else
|
|
#if !SHADER_HINT_NICE_QUALITY
|
|
inputData.normalWS = WorldSpaceNormal;
|
|
#else
|
|
inputData.normalWS = normalize(WorldSpaceNormal);
|
|
#endif
|
|
#endif
|
|
|
|
#if !SHADER_HINT_NICE_QUALITY
|
|
// viewDirection should be normalized here, but we avoid doing it as it's close enough and we save some ALU.
|
|
inputData.viewDirectionWS = WorldSpaceViewDirection;
|
|
#else
|
|
inputData.viewDirectionWS = normalize(WorldSpaceViewDirection);
|
|
#endif
|
|
|
|
inputData.shadowCoord = IN.shadowCoord;
|
|
|
|
inputData.fogCoord = IN.fogFactorAndVertexLight.x;
|
|
inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw;
|
|
inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.vertexSH, inputData.normalWS);
|
|
|
|
half4 color = UniversalFragmentPBR(
|
|
inputData,
|
|
Albedo,
|
|
Metallic,
|
|
Specular,
|
|
Smoothness,
|
|
Occlusion,
|
|
Emission,
|
|
Alpha);
|
|
|
|
// Computes fog factor per-vertex
|
|
color.rgb = MixFog(color.rgb, IN.fogFactorAndVertexLight.x);
|
|
|
|
#if _AlphaClip
|
|
clip(Alpha - AlphaClipThreshold);
|
|
#endif
|
|
return color;
|
|
}
|
|
|
|
ENDHLSL
|
|
}
|