163 lines
6.4 KiB
GLSL
163 lines
6.4 KiB
GLSL
Shader "NLD_URP/NLD_SimpleLit"
|
|
{
|
|
Properties
|
|
{
|
|
[MainTexture] _BaseMap("Base Map", 2D) = "white" {}
|
|
[MainColor] _BaseColor("Base Color", Color) = (1, 1, 1, 1)
|
|
|
|
_Cutoff("Alpha Clipping", Range(0.0, 1.0)) = 0.5
|
|
|
|
[HDR] _EmissionColor("Emission Color", Color) = (0, 0, 0, 0)
|
|
[NoScaleOffset] _EmissionMap("Emission Map", 2D) = "white" {}
|
|
_EmissionEnabled("Emission", Float) = 0.0
|
|
|
|
_Surface("__surface", Float) = 0.0
|
|
_Blend("__blend", Float) = 0.0
|
|
_Cull("__cull", Float) = 2.0
|
|
[ToggleUI] _AlphaClip("__clip", Float) = 0.0
|
|
[HideInInspector] _SrcBlend("__src", Float) = 1.0
|
|
[HideInInspector] _DstBlend("__dst", Float) = 0.0
|
|
[HideInInspector] _SrcBlendAlpha("__srcA", Float) = 1.0
|
|
[HideInInspector] _DstBlendAlpha("__dstA", Float) = 0.0
|
|
[HideInInspector] _ZWrite("__zw", Float) = 1.0
|
|
[HideInInspector] _AlphaToMask("__alphaToMask", Float) = 0.0
|
|
_QueueOffset("Queue offset", Float) = 0.0
|
|
|
|
[HideInInspector] _MainTex("BaseMap", 2D) = "white" {}
|
|
[HideInInspector] _Color("Base Color", Color) = (1, 1, 1, 1)
|
|
[HideInInspector] _Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
|
|
[HideInInspector] _SpecColor("Specular Color", Color) = (0.5, 0.5, 0.5, 0.5)
|
|
[HideInInspector] _SpecGlossMap("Specular Map", 2D) = "white" {}
|
|
[HideInInspector] _SmoothnessSource("Smoothness Source", Float) = 0.0
|
|
[HideInInspector] _SpecularHighlights("Specular Highlights", Float) = 0.0
|
|
[HideInInspector] _BumpScale("Scale", Float) = 1.0
|
|
[HideInInspector] [NoScaleOffset] _BumpMap("Normal Map", 2D) = "bump" {}
|
|
[HideInInspector] _BlendModePreserveSpecular("_BlendModePreserveSpecular", Float) = 1.0
|
|
[HideInInspector] _Shininess("Smoothness", Float) = 0.0
|
|
[HideInInspector] _GlossinessSource("GlossinessSource", Float) = 0.0
|
|
[HideInInspector] _SpecSource("SpecularHighlights", Float) = 0.0
|
|
|
|
[HideInInspector] [NoScaleOffset] unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {}
|
|
[HideInInspector] [NoScaleOffset] unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {}
|
|
[HideInInspector] [NoScaleOffset] unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {}
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags
|
|
{
|
|
"RenderType" = "Opaque"
|
|
"RenderPipeline" = "UniversalPipeline"
|
|
"UniversalMaterialType" = "SimpleLit"
|
|
"IgnoreProjector" = "True"
|
|
}
|
|
LOD 100
|
|
|
|
Pass
|
|
{
|
|
Name "ForwardLit"
|
|
Tags
|
|
{
|
|
"LightMode" = "UniversalForward"
|
|
}
|
|
|
|
Blend [_SrcBlend] [_DstBlend], [_SrcBlendAlpha] [_DstBlendAlpha]
|
|
ZWrite [_ZWrite]
|
|
Cull [_Cull]
|
|
AlphaToMask [_AlphaToMask]
|
|
|
|
HLSLPROGRAM
|
|
#pragma target 2.0
|
|
#pragma vertex Vert
|
|
#pragma fragment Frag
|
|
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
|
|
#pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
|
|
struct Attributes
|
|
{
|
|
float3 positionOS : POSITION;
|
|
half3 normalOS : NORMAL;
|
|
float2 texcoord : TEXCOORD0;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 positionHCS : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
half3 normalWS : TEXCOORD1;
|
|
half3 bakedGI : TEXCOORD2;
|
|
float4 shadowCoord : TEXCOORD3;
|
|
};
|
|
|
|
TEXTURE2D(_BaseMap);
|
|
SAMPLER(sampler_BaseMap);
|
|
TEXTURE2D(_EmissionMap);
|
|
SAMPLER(sampler_EmissionMap);
|
|
|
|
CBUFFER_START(UnityPerMaterial)
|
|
float4 _BaseMap_ST;
|
|
half4 _BaseColor;
|
|
half4 _EmissionColor;
|
|
half _Cutoff;
|
|
half _AlphaClip;
|
|
half _EmissionEnabled;
|
|
CBUFFER_END
|
|
|
|
half3 SampleSimpleSH(half3 normalWS)
|
|
{
|
|
real4 shCoefficients[7];
|
|
shCoefficients[0] = unity_SHAr;
|
|
shCoefficients[1] = unity_SHAg;
|
|
shCoefficients[2] = unity_SHAb;
|
|
shCoefficients[3] = unity_SHBr;
|
|
shCoefficients[4] = unity_SHBg;
|
|
shCoefficients[5] = unity_SHBb;
|
|
shCoefficients[6] = unity_SHC;
|
|
return max(half3(0.0h, 0.0h, 0.0h), SampleSH9(shCoefficients, normalWS));
|
|
}
|
|
|
|
Varyings Vert(Attributes input)
|
|
{
|
|
Varyings output;
|
|
VertexPositionInputs positionInputs = GetVertexPositionInputs(input.positionOS);
|
|
output.positionHCS = positionInputs.positionCS;
|
|
half3 normalWS = TransformObjectToWorldNormal(input.normalOS);
|
|
output.normalWS = normalWS;
|
|
output.bakedGI = SampleSimpleSH(normalWS);
|
|
output.shadowCoord = GetShadowCoord(positionInputs);
|
|
output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
|
|
return output;
|
|
}
|
|
|
|
half4 Frag(Varyings input) : SV_Target
|
|
{
|
|
half4 color = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv) * _BaseColor;
|
|
|
|
if (_AlphaClip > 0.5h)
|
|
{
|
|
clip(color.a - _Cutoff);
|
|
}
|
|
|
|
half3 emission = 0.0h;
|
|
if (_EmissionEnabled > 0.5h)
|
|
{
|
|
emission = SAMPLE_TEXTURE2D(_EmissionMap, sampler_EmissionMap, input.uv).rgb * _EmissionColor.rgb;
|
|
}
|
|
|
|
Light mainLight = GetMainLight(input.shadowCoord);
|
|
half3 normalWS = normalize(input.normalWS);
|
|
half ndotl = saturate(dot(normalWS, mainLight.direction));
|
|
half3 directLight = mainLight.color.rgb * (mainLight.distanceAttenuation * mainLight.shadowAttenuation * ndotl);
|
|
half3 lighting = input.bakedGI + directLight;
|
|
return half4(color.rgb * lighting + emission, color.a);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
|
|
CustomEditor "PhxhSDK.Editor.ShaderTools.NldSimpleLitUltraShaderGUI"
|
|
}
|