291 lines
11 KiB
Plaintext
291 lines
11 KiB
Plaintext
Shader "Lux URP/Lit Extended"
|
|
{
|
|
Properties
|
|
{
|
|
|
|
_Rim("Enable Rim Lighting", Float) = 0
|
|
_RimColor("Rim Color", Color) = (0.5,0.5,0.5,1)
|
|
_RimPower("Rim Power", Float) = 2
|
|
_RimMinPower("Rim Min Power", Float) = 1
|
|
_RimFrequency("Rim Frequency", Float) = 0
|
|
_RimPerPositionFrequency("Rim Per PositionFrequency", Range(0.0, 1.0)) = 1
|
|
|
|
|
|
[Enum(UnityEngine.Rendering.CompareFunction)] _ZTest ("ZTest", Int) = 4
|
|
|
|
_Stencil ("Stencil ID", Int) = 2
|
|
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("Stencil Comparison", Int) = 8 // always
|
|
[Enum(UnityEngine.Rendering.StencilOp)] _StencilOp ("Stencil Operation", Int) = 2 // 2 = replace
|
|
[Enum(UnityEngine.Rendering.StencilOp)] _StencilFail ("Stencil Fail", Int) = 0
|
|
[Enum(UnityEngine.Rendering.StencilOp)] _StencilZFail ("Stencil ZFail", Int) = 2
|
|
[IntRange] _ReadMask ("Read Mask", Range (0, 255)) = 255
|
|
[IntRange] _WriteMask ("Write Mask", Range (0, 255)) = 255
|
|
|
|
|
|
// Specular vs Metallic workflow
|
|
[HideInInspector] _WorkflowMode("WorkflowMode", Float) = 1.0
|
|
|
|
[MainColor] _BaseColor("Color", Color) = (1,1,1,1)
|
|
[MainTexture] _BaseMap("Albedo", 2D) = "white" {}
|
|
|
|
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
|
|
|
|
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
|
|
_GlossMapScale("Smoothness Scale", Range(0.0, 1.0)) = 1.0
|
|
_SmoothnessTextureChannel("Smoothness texture channel", Float) = 0
|
|
|
|
[Gamma] _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
|
|
_MetallicGlossMap("Metallic", 2D) = "white" {}
|
|
|
|
_SpecColor("Specular", Color) = (0.2, 0.2, 0.2)
|
|
_SpecGlossMap("Specular", 2D) = "white" {}
|
|
|
|
[ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
|
|
[ToggleOff] _EnvironmentReflections("Environment Reflections", Float) = 1.0
|
|
|
|
_BumpScale("Scale", Float) = 1.0
|
|
_BumpMap("Normal Map", 2D) = "bump" {}
|
|
|
|
_OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0
|
|
_OcclusionMap("Occlusion", 2D) = "white" {}
|
|
|
|
_EmissionColor("Color", Color) = (0,0,0)
|
|
_EmissionMap("Emission", 2D) = "white" {}
|
|
|
|
// Blending state
|
|
[HideInInspector] _Surface("__surface", Float) = 0.0
|
|
[HideInInspector] _Blend("__blend", Float) = 0.0
|
|
[HideInInspector] _AlphaClip("__clip", Float) = 0.0
|
|
[HideInInspector] _SrcBlend("__src", Float) = 1.0
|
|
[HideInInspector] _DstBlend("__dst", Float) = 0.0
|
|
[HideInInspector] _ZWrite("__zw", Float) = 1.0
|
|
[HideInInspector] _Cull("__cull", Float) = 2.0
|
|
|
|
_ReceiveShadows("Receive Shadows", Float) = 1.0
|
|
// Editmode props
|
|
[HideInInspector] _QueueOffset("Queue offset", Float) = 0.0
|
|
|
|
// ObsoleteProperties
|
|
[HideInInspector] _MainTex("BaseMap", 2D) = "white" {}
|
|
[HideInInspector] _Color("Base Color", Color) = (0.5, 0.5, 0.5, 1)
|
|
[HideInInspector] _GlossMapScale("Smoothness", Float) = 0.0
|
|
[HideInInspector] _Glossiness("Smoothness", Float) = 0.0
|
|
[HideInInspector] _GlossyReflections("EnvironmentReflections", Float) = 0.0
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
// Lightweight Pipeline tag is required. If Lightweight render pipeline is not set in the graphics settings
|
|
// this Subshader will fail. One can add a subshader below or fallback to Standard built-in to make this
|
|
// material work with both Lightweight Render Pipeline and Builtin Unity Pipeline
|
|
Tags{
|
|
"RenderType" = "Opaque"
|
|
"RenderPipeline" = "UniversalPipeline"
|
|
"IgnoreProjector" = "True"
|
|
}
|
|
LOD 300
|
|
|
|
// ------------------------------------------------------------------
|
|
// Forward pass. Shades all light in a single pass. GI + emission + Fog
|
|
Pass
|
|
{
|
|
// Lightmode matches the ShaderPassName set in LightweightRenderPipeline.cs. SRPDefaultUnlit and passes with
|
|
// no LightMode tag are also rendered by Lightweight Render Pipeline
|
|
Name "ForwardLit"
|
|
Tags{"LightMode" = "UniversalForward"}
|
|
|
|
Stencil {
|
|
Ref [_Stencil]
|
|
ReadMask [_ReadMask]
|
|
WriteMask [_WriteMask]
|
|
Comp [_StencilComp]
|
|
Pass [_StencilOp]
|
|
Fail [_StencilFail]
|
|
ZFail [_StencilZFail]
|
|
//replace
|
|
}
|
|
|
|
Blend[_SrcBlend][_DstBlend]
|
|
ZTest [_ZTest]
|
|
ZWrite[_ZWrite]
|
|
Cull[_Cull]
|
|
|
|
HLSLPROGRAM
|
|
// Required to compile gles 2.0 with standard SRP library
|
|
// All shaders must be compiled with HLSLcc and currently only gles is not using HLSLcc by default
|
|
#pragma prefer_hlslcc gles
|
|
#pragma exclude_renderers d3d11_9x
|
|
#pragma target 2.0
|
|
|
|
// -------------------------------------
|
|
// Material Keywords
|
|
#pragma shader_feature _NORMALMAP
|
|
#pragma shader_feature _ALPHATEST_ON
|
|
#pragma shader_feature _ALPHAPREMULTIPLY_ON
|
|
#pragma shader_feature _EMISSION
|
|
#pragma shader_feature _METALLICSPECGLOSSMAP
|
|
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
|
|
#pragma shader_feature _OCCLUSIONMAP
|
|
|
|
#pragma shader_feature _SPECULARHIGHLIGHTS_OFF
|
|
#pragma shader_feature _ENVIRONMENTREFLECTIONS_OFF
|
|
#pragma shader_feature _SPECULAR_SETUP
|
|
#pragma shader_feature _RECEIVE_SHADOWS_OFF
|
|
|
|
#pragma shader_feature_local _RIMLIGHTING
|
|
|
|
// -------------------------------------
|
|
// Lightweight 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 LitPassVertex
|
|
#pragma fragment LitPassFragmentRim
|
|
|
|
#include "Includes/Lux URP Lit Extended Inputs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl"
|
|
|
|
half4 LitPassFragmentRim(Varyings input) : SV_Target
|
|
{
|
|
UNITY_SETUP_INSTANCE_ID(input);
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
|
|
|
SurfaceData surfaceData;
|
|
InitializeStandardLitSurfaceData(input.uv, surfaceData);
|
|
|
|
InputData inputData;
|
|
InitializeInputData(input, surfaceData.normalTS, inputData);
|
|
|
|
#if defined(_RIMLIGHTING)
|
|
half rim = saturate(1.0h - saturate( dot(inputData.normalWS, inputData.viewDirectionWS)));
|
|
half power = _RimPower;
|
|
UNITY_BRANCH if(_RimFrequency > 0 ) {
|
|
half perPosition = lerp(0.0h, 1.0h, dot(1.0h, frac(UNITY_MATRIX_M._m03_m13_m23) * 2.0h - 1.0h ) * _RimPerPositionFrequency ) * 3.1416h;
|
|
power = lerp(power, _RimMinPower, (1.0h + sin(_Time.y * _RimFrequency + perPosition) ) * 0.5h );
|
|
}
|
|
surfaceData.emission += pow(rim, power) * _RimColor.rgb * _RimColor.a;
|
|
#endif
|
|
|
|
half4 color = LightweightFragmentPBR(inputData, surfaceData.albedo, surfaceData.metallic, surfaceData.specular, surfaceData.smoothness, surfaceData.occlusion, surfaceData.emission, surfaceData.alpha);
|
|
|
|
color.rgb = MixFog(color.rgb, inputData.fogCoord);
|
|
return color;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
|
|
Pass
|
|
{
|
|
Name "ShadowCaster"
|
|
Tags{"LightMode" = "ShadowCaster"}
|
|
|
|
ZWrite On
|
|
//ZTest LEqual
|
|
ZTest [_ZTest]
|
|
Cull[_Cull]
|
|
|
|
HLSLPROGRAM
|
|
// Required to compile gles 2.0 with standard srp library
|
|
#pragma prefer_hlslcc gles
|
|
#pragma exclude_renderers d3d11_9x
|
|
#pragma target 2.0
|
|
|
|
// -------------------------------------
|
|
// Material Keywords
|
|
#pragma shader_feature _ALPHATEST_ON
|
|
|
|
//--------------------------------------
|
|
// GPU Instancing
|
|
#pragma multi_compile_instancing
|
|
|
|
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
|
|
|
|
#pragma vertex ShadowPassVertex
|
|
#pragma fragment ShadowPassFragment
|
|
|
|
#include "Includes/Lux URP Lit Extended Inputs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
|
|
ENDHLSL
|
|
}
|
|
|
|
Pass
|
|
{
|
|
Name "DepthOnly"
|
|
Tags{"LightMode" = "DepthOnly"}
|
|
|
|
ZWrite On
|
|
ZTest [_ZTest]
|
|
ColorMask 0
|
|
Cull[_Cull]
|
|
|
|
HLSLPROGRAM
|
|
// Required to compile gles 2.0 with standard srp library
|
|
#pragma prefer_hlslcc gles
|
|
#pragma exclude_renderers d3d11_9x
|
|
#pragma target 2.0
|
|
|
|
#pragma vertex DepthOnlyVertex
|
|
#pragma fragment DepthOnlyFragment
|
|
|
|
// -------------------------------------
|
|
// Material Keywords
|
|
#pragma shader_feature _ALPHATEST_ON
|
|
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
|
|
|
|
//--------------------------------------
|
|
// GPU Instancing
|
|
#pragma multi_compile_instancing
|
|
|
|
#include "Includes/Lux URP Lit Extended Inputs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
|
|
ENDHLSL
|
|
}
|
|
|
|
// This pass it not used during regular rendering, only for lightmap baking.
|
|
Pass
|
|
{
|
|
Name "Meta"
|
|
Tags{"LightMode" = "Meta"}
|
|
|
|
Cull Off
|
|
|
|
HLSLPROGRAM
|
|
// Required to compile gles 2.0 with standard srp library
|
|
#pragma prefer_hlslcc gles
|
|
#pragma exclude_renderers d3d11_9x
|
|
|
|
#pragma vertex UniversalVertexMeta
|
|
#pragma fragment UniversalFragmentMeta
|
|
|
|
#pragma shader_feature _SPECULAR_SETUP
|
|
#pragma shader_feature _EMISSION
|
|
#pragma shader_feature _METALLICSPECGLOSSMAP
|
|
#pragma shader_feature _ALPHATEST_ON
|
|
#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
|
|
|
|
#pragma shader_feature _SPECGLOSSMAP
|
|
|
|
#include "Includes/Lux URP Lit Extended Inputs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
|
|
|
|
ENDHLSL
|
|
}
|
|
|
|
}
|
|
FallBack "Hidden/InternalErrorShader"
|
|
CustomEditor "UnityEditor.Rendering.URP.ShaderGUI.LitExtendedShader"
|
|
} |