2026-04-16 오브젝트 그림자

This commit is contained in:
skrwns304@gmail.com
2026-04-16 04:58:10 +09:00
parent 0fe8b18872
commit 42646a636f
303 changed files with 54374 additions and 20 deletions

View File

@@ -0,0 +1,456 @@
Shader "BadDog/URP/BGAreaLit"
{
Properties
{
// Specular vs Metallic workflow
_WorkflowMode("WorkflowMode", Float) = 1.0
[MainTexture] _BaseMap("Albedo", 2D) = "white" {}
[MainColor] _BaseColor("Color", Color) = (1,1,1,1)
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
_SmoothnessTextureChannel("Smoothness texture channel", Float) = 0
_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" {}
_Parallax("Scale", Range(0.005, 0.08)) = 0.005
_ParallaxMap("Height Map", 2D) = "black" {}
_OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0
_OcclusionMap("Occlusion", 2D) = "white" {}
[HDR] _EmissionColor("Color", Color) = (0,0,0)
_EmissionMap("Emission", 2D) = "white" {}
_DetailMask("Detail Mask", 2D) = "white" {}
_DetailAlbedoMapScale("Scale", Range(0.0, 2.0)) = 1.0
_DetailAlbedoMap("Detail Albedo x2", 2D) = "linearGrey" {}
_DetailNormalMapScale("Scale", Range(0.0, 2.0)) = 1.0
[Normal] _DetailNormalMap("Normal Map", 2D) = "bump" {}
// SRP batching compatibility for Clear Coat (Not used in Lit)
[HideInInspector] _ClearCoatMask("_ClearCoatMask", Float) = 0.0
[HideInInspector] _ClearCoatSmoothness("_ClearCoatSmoothness", Float) = 0.0
// Blending state
_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] _BlendModePreserveSpecular("_BlendModePreserveSpecular", Float) = 1.0
[HideInInspector] _AlphaToMask("__alphaToMask", Float) = 0.0
[HideInInspector] _AddPrecomputedVelocity("_AddPrecomputedVelocity", Float) = 0.0
[HideInInspector] _XRMotionVectorsPass("_XRMotionVectorsPass", Float) = 1.0
[ToggleUI] _ReceiveShadows("Receive Shadows", Float) = 1.0
// Editmode props
_QueueOffset("Queue offset", Float) = 0.0
// ObsoleteProperties
[HideInInspector] _MainTex("BaseMap", 2D) = "white" {}
[HideInInspector] _Color("Base Color", Color) = (1, 1, 1, 1)
[HideInInspector] _GlossMapScale("Smoothness", Float) = 0.0
[HideInInspector] _Glossiness("Smoothness", Float) = 0.0
[HideInInspector] _GlossyReflections("EnvironmentReflections", 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" = "Lit"
"IgnoreProjector" = "True"
}
LOD 300
// ------------------------------------------------------------------
// Forward pass. Shades all light in a single pass. GI + emission + Fog
Pass
{
Name "ForwardLit"
Tags
{
"LightMode" = "UniversalForwardOnly"
}
// -------------------------------------
// Render State Commands
Blend[_SrcBlend][_DstBlend], [_SrcBlendAlpha][_DstBlendAlpha]
ZWrite[_ZWrite]
Cull[_Cull]
AlphaToMask[_AlphaToMask]
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex LitPassVertex
#pragma fragment LitPassFragment
// -------------------------------------
// Material Keywords
#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 _ALPHAMODULATE_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 _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
#pragma multi_compile _ EVALUATE_SH_MIXED EVALUATE_SH_VERTEX
#pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION
#if UNITY_VERSION >= 60000100
#pragma multi_compile_fragment _ _REFLECTION_PROBE_ATLAS
#endif
#pragma multi_compile_fragment _ _ENABLE_BG_AREA_LIGHTING
#pragma multi_compile_fragment _ _BG_AREALIGHT_SHADOWS_PCF2X2 _BG_AREALIGHT_SHADOWS_TENT5X5 _BG_AREALIGHT_SHADOWS_TENT7X7 _BG_AREALIGHT_SHADOWS_PCSS
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
#pragma multi_compile_fragment _ _LIGHT_COOKIES
#pragma multi_compile _ _LIGHT_LAYERS
#if UNITY_VERSION >= 60000100
#pragma multi_compile _ _CLUSTER_LIGHT_LOOP
#else
#pragma multi_compile _ _FORWARD_PLUS
#endif
#if UNITY_VERSION >= 60000000
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#endif
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
#pragma multi_compile _ SHADOWS_SHADOWMASK
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ LIGHTMAP_ON
#if UNITY_VERSION >= 60000100
#pragma multi_compile_fragment _ LIGHTMAP_BICUBIC_SAMPLING
#endif
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
#pragma multi_compile _ USE_LEGACY_LIGHTMAPS
#pragma multi_compile _ LOD_FADE_CROSSFADE
#pragma multi_compile_fragment _ DEBUG_DISPLAY
#if UNITY_VERSION >= 60000100
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Fog.hlsl"
#else
#pragma multi_compile_fog
#endif
#if UNITY_VERSION >= 60000000
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ProbeVolumeVariants.hlsl"
#endif
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#pragma instancing_options renderinglayer
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaLitForwardPass.hlsl"
ENDHLSL
}
Pass
{
Name "ShadowCaster"
Tags
{
"LightMode" = "ShadowCaster"
}
// -------------------------------------
// Render State Commands
ZWrite On
ZTest LEqual
ColorMask 0
Cull[_Cull]
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex ShadowPassVertex
#pragma fragment ShadowPassFragment
// -------------------------------------
// Material Keywords
#pragma shader_feature_local _ALPHATEST_ON
#pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
// -------------------------------------
// Universal Pipeline keywords
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ LOD_FADE_CROSSFADE
// This is used during shadow map generation to differentiate between directional and punctual light shadows, as they use different formulas to apply Normal Bias
#pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
ENDHLSL
}
Pass
{
Name "DepthOnly"
Tags
{
"LightMode" = "DepthOnly"
}
// -------------------------------------
// Render State Commands
ZWrite On
ColorMask R
Cull[_Cull]
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex DepthOnlyVertex
#pragma fragment DepthOnlyFragment
// -------------------------------------
// Material Keywords
#pragma shader_feature_local _ALPHATEST_ON
#pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ LOD_FADE_CROSSFADE
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
ENDHLSL
}
// This pass is used when drawing to a _CameraNormalsTexture texture
Pass
{
Name "DepthNormals"
Tags
{
"LightMode" = "DepthNormals"
}
// -------------------------------------
// Render State Commands
ZWrite On
Cull[_Cull]
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex DepthNormalsVertex
#pragma fragment DepthNormalsFragment
// -------------------------------------
// Material Keywords
#pragma shader_feature_local _NORMALMAP
#pragma shader_feature_local _PARALLAXMAP
#pragma shader_feature_local _ _DETAIL_MULX2 _DETAIL_SCALED
#pragma shader_feature_local _ALPHATEST_ON
#pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ LOD_FADE_CROSSFADE
// -------------------------------------
// Universal Pipeline keywords
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitDepthNormalsPass.hlsl"
ENDHLSL
}
// This pass it not used during regular rendering, only for lightmap baking.
Pass
{
Name "Meta"
Tags
{
"LightMode" = "Meta"
}
// -------------------------------------
// Render State Commands
Cull Off
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex UniversalVertexMeta
#pragma fragment UniversalFragmentMetaLit
// -------------------------------------
// Material Keywords
#pragma shader_feature_local_fragment _SPECULAR_SETUP
#pragma shader_feature_local_fragment _EMISSION
#pragma shader_feature_local_fragment _METALLICSPECGLOSSMAP
#pragma shader_feature_local_fragment _ALPHATEST_ON
#pragma shader_feature_local_fragment _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature_local _ _DETAIL_MULX2 _DETAIL_SCALED
#pragma shader_feature_local_fragment _SPECGLOSSMAP
#pragma shader_feature EDITOR_VISUALIZATION
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
ENDHLSL
}
Pass
{
Name "Universal2D"
Tags
{
"LightMode" = "Universal2D"
}
// -------------------------------------
// Render State Commands
Blend[_SrcBlend][_DstBlend]
ZWrite[_ZWrite]
Cull[_Cull]
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex vert
#pragma fragment frag
// -------------------------------------
// Material Keywords
#pragma shader_feature_local_fragment _ALPHATEST_ON
#pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/Universal2D.hlsl"
ENDHLSL
}
Pass
{
Name "MotionVectors"
Tags { "LightMode" = "MotionVectors" }
ColorMask RG
HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
#pragma multi_compile _ LOD_FADE_CROSSFADE
#pragma shader_feature_local_vertex _ADD_PRECOMPUTED_VELOCITY
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ObjectMotionVectors.hlsl"
ENDHLSL
}
Pass
{
Name "XRMotionVectors"
Tags { "LightMode" = "XRMotionVectors" }
ColorMask RGBA
// Stencil write for obj motion pixels
Stencil
{
WriteMask 1
Ref 1
Comp Always
Pass Replace
}
HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
#pragma multi_compile _ LOD_FADE_CROSSFADE
#pragma shader_feature_local_vertex _ADD_PRECOMPUTED_VELOCITY
#define APPLICATION_SPACE_WARP_MOTION 1
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ObjectMotionVectors.hlsl"
ENDHLSL
}
}
FallBack "Hidden/Universal Render Pipeline/FallbackError"
CustomEditor "UnityEditor.Rendering.Universal.ShaderGUI.LitShader"
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: deab2e321dbdc8a469635b200f36c496
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 346790
packageName: Realtime Area Light for URP
packageVersion: 1.3.0
assetPath: Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaLit.shader
uploadId: 884030

View File

@@ -0,0 +1,280 @@
#ifndef BADDOG_AREALIT_FORWARD_PASS_INCLUDED
#define BADDOG_AREALIT_FORWARD_PASS_INCLUDED
#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.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
#if defined(LOD_FADE_CROSSFADE)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl"
#endif
#if defined(_PARALLAXMAP)
#define REQUIRES_TANGENT_SPACE_VIEW_DIR_INTERPOLATOR
#endif
#if (defined(_NORMALMAP) || (defined(_PARALLAXMAP) && !defined(REQUIRES_TANGENT_SPACE_VIEW_DIR_INTERPOLATOR))) || defined(_DETAIL)
#define REQUIRES_WORLD_SPACE_TANGENT_INTERPOLATOR
#endif
// Include Area Light support
#include "Packages/com.baddog.rendering.arealight/Shaders/Include/BGAreaLighting.hlsl"
//-----------------------------------------------------------------------------
// Area Light Contribution Calculation
//-----------------------------------------------------------------------------
// Vertex and Fragment structures from URP Lit shader
struct Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
float4 tangentOS : TANGENT;
float2 texcoord : TEXCOORD0;
float2 staticLightmapUV : TEXCOORD1;
float2 dynamicLightmapUV : TEXCOORD2;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float2 uv : TEXCOORD0;
#if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
float3 positionWS : TEXCOORD1;
#endif
float3 normalWS : TEXCOORD2;
#if defined(REQUIRES_WORLD_SPACE_TANGENT_INTERPOLATOR)
half4 tangentWS : TEXCOORD3; // xyz: tangent, w: sign
#endif
float3 viewDirWS : TEXCOORD4;
#ifdef _ADDITIONAL_LIGHTS_VERTEX
half4 fogFactorAndVertexLight : TEXCOORD5; // x: fogFactor, yzw: vertex light
#else
half fogFactor : TEXCOORD5;
#endif
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
float4 shadowCoord : TEXCOORD6;
#endif
#if defined(REQUIRES_TANGENT_SPACE_VIEW_DIR_INTERPOLATOR)
half3 viewDirTS : TEXCOORD7;
#endif
DECLARE_LIGHTMAP_OR_SH(staticLightmapUV, vertexSH, 8);
#ifdef DYNAMICLIGHTMAP_ON
float2 dynamicLightmapUV : TEXCOORD9; // Dynamic lightmap UVs
#endif
#ifdef USE_APV_PROBE_OCCLUSION
float4 probeOcclusion : TEXCOORD10;
#endif
float4 positionCS : SV_POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
void InitializeInputData(Varyings input, half3 normalTS, out InputData inputData)
{
inputData = (InputData)0;
#if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
inputData.positionWS = input.positionWS;
#endif
half3 viewDirWS = GetWorldSpaceNormalizeViewDir(input.positionWS);
#if defined(_NORMALMAP) || defined(_DETAIL)
float sgn = input.tangentWS.w; // should be either +1 or -1
float3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
half3x3 tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz);
#if defined(_NORMALMAP)
inputData.tangentToWorld = tangentToWorld;
#endif
inputData.normalWS = TransformTangentToWorld(normalTS, tangentToWorld);
#else
inputData.normalWS = input.normalWS;
#endif
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
inputData.viewDirectionWS = viewDirWS;
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
inputData.shadowCoord = input.shadowCoord;
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
#else
inputData.shadowCoord = float4(0, 0, 0, 0);
#endif
#ifdef _ADDITIONAL_LIGHTS_VERTEX
inputData.fogCoord = InitializeInputDataFog(float4(input.positionWS, 1.0), input.fogFactorAndVertexLight.x);
inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
#else
inputData.fogCoord = InitializeInputDataFog(float4(input.positionWS, 1.0), input.fogFactor);
#endif
#if defined(DYNAMICLIGHTMAP_ON)
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.dynamicLightmapUV, input.vertexSH, inputData.normalWS);
inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
#elif !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
inputData.bakedGI = SAMPLE_GI(input.vertexSH,
GetAbsolutePositionWS(inputData.positionWS),
inputData.normalWS,
inputData.viewDirectionWS,
input.positionCS.xy,
input.probeOcclusion,
inputData.shadowMask);
#else
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.vertexSH, inputData.normalWS);
inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
#endif
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
#if defined(DEBUG_DISPLAY)
#if defined(DYNAMICLIGHTMAP_ON)
inputData.dynamicLightmapUV = input.dynamicLightmapUV;
#endif
#if defined(LIGHTMAP_ON)
inputData.staticLightmapUV = input.staticLightmapUV;
#else
inputData.vertexSH = input.vertexSH;
#endif
#if defined(USE_APV_PROBE_OCCLUSION)
inputData.probeOcclusion = input.probeOcclusion;
#endif
#endif
}
///////////////////////////////////////////////////////////////////////////////
// Vertex and Fragment functions //
///////////////////////////////////////////////////////////////////////////////
// Used in Standard (Physically Based) shader
Varyings LitPassVertex(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
// normalWS and tangentWS already normalize.
// this is required to avoid skewing the direction during interpolation
// also required for per-vertex lighting and SH evaluation
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
half3 viewDirWS = GetWorldSpaceViewDir(vertexInput.positionWS);
half3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS);
half fogFactor = 0;
#if !defined(_FOG_FRAGMENT)
fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
#endif
output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
// already normalized from normal transform to WS.
output.normalWS = normalInput.normalWS;
output.viewDirWS = viewDirWS;
#if defined(REQUIRES_WORLD_SPACE_TANGENT_INTERPOLATOR) || defined(REQUIRES_TANGENT_SPACE_VIEW_DIR_INTERPOLATOR)
real sign = input.tangentOS.w * GetOddNegativeScale();
half4 tangentWS = half4(normalInput.tangentWS.xyz, sign);
#endif
#if defined(REQUIRES_WORLD_SPACE_TANGENT_INTERPOLATOR)
output.tangentWS = tangentWS;
#endif
#if defined(REQUIRES_TANGENT_SPACE_VIEW_DIR_INTERPOLATOR)
half3 viewDirTS = GetViewDirectionTangentSpace(tangentWS, output.normalWS, viewDirWS);
output.viewDirTS = viewDirTS;
#endif
OUTPUT_LIGHTMAP_UV(input.staticLightmapUV, unity_LightmapST, output.staticLightmapUV);
#ifdef DYNAMICLIGHTMAP_ON
output.dynamicLightmapUV = input.dynamicLightmapUV.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
#endif
#if UNITY_VERSION >= 60000000
OUTPUT_SH4(vertexInput.positionWS, output.normalWS.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), output.vertexSH, output.probeOcclusion);
#else
OUTPUT_SH(output.normalWS.xyz, output.vertexSH);
#endif
#ifdef _ADDITIONAL_LIGHTS_VERTEX
output.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
#else
output.fogFactor = fogFactor;
#endif
#if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
output.positionWS = vertexInput.positionWS;
#endif
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
output.shadowCoord = GetShadowCoord(vertexInput);
#endif
output.positionCS = vertexInput.positionCS;
return output;
}
// Used in Standard (Physically Based) shader
half4 LitPassFragment(Varyings input) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
#if defined(_PARALLAXMAP)
#if defined(REQUIRES_TANGENT_SPACE_VIEW_DIR_INTERPOLATOR)
half3 viewDirTS = input.viewDirTS;
#else
half3 viewDirWS = GetWorldSpaceNormalizeViewDir(input.positionWS);
half3 viewDirTS = GetViewDirectionTangentSpace(input.tangentWS, input.normalWS, viewDirWS);
#endif
ApplyPerPixelDisplacement(viewDirTS, input.uv);
#endif
SurfaceData surfaceData;
InitializeStandardLitSurfaceData(input.uv, surfaceData);
#ifdef LOD_FADE_CROSSFADE
LODFadeCrossFade(input.positionCS);
#endif
InputData inputData;
InitializeInputData(input, surfaceData.normalTS, inputData);
#if UNITY_VERSION >= 60000000
SETUP_DEBUG_TEXTURE_DATA(inputData, UNDO_TRANSFORM_TEX(input.uv, _BaseMap));
#else
SETUP_DEBUG_TEXTURE_DATA(inputData, input.uv, _BaseMap);
#endif
#ifdef _DBUFFER
ApplyDecalToSurfaceData(input.positionCS, surfaceData, inputData);
#endif
// Standard URP lighting calculation
half4 color = UniversalFragmentPBR(inputData, surfaceData);
// Additional Area Light (only when enabled)
#if defined(_ENABLE_BG_AREA_LIGHTING)
color.rgb += EvaluateAreaLight(inputData, surfaceData);
#endif
color.rgb = MixFog(color.rgb, inputData.fogCoord);
color.a = OutputAlpha(color.a, IsSurfaceTypeTransparent(_Surface));
return color;
}
#endif // BADDOG_AREALIT_FORWARD_PASS_INCLUDED

View File

@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: 07e05dc2db65cc94db89c9e7ccfc9a2a
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 346790
packageName: Realtime Area Light for URP
packageVersion: 1.3.0
assetPath: Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaLitForwardPass.hlsl
uploadId: 884030

View File

@@ -0,0 +1,389 @@
Shader "BadDog/URP/BGAreaParticleLit"
{
Properties
{
[MainTexture] _BaseMap("Base Map", 2D) = "white" {}
[MainColor] _BaseColor("Base Color", Color) = (1,1,1,1)
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_MetallicGlossMap("Metallic Map", 2D) = "white" {}
[Gamma] _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
_BumpScale("Scale", Float) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
[HDR] _EmissionColor("Color", Color) = (0,0,0)
_EmissionMap("Emission", 2D) = "white" {}
[ToggleUI] _ReceiveShadows("Receive Shadows", Float) = 1.0
// -------------------------------------
// Particle specific
_SoftParticlesNearFadeDistance("Soft Particles Near Fade", Float) = 0.0
_SoftParticlesFarFadeDistance("Soft Particles Far Fade", Float) = 1.0
_CameraNearFadeDistance("Camera Near Fade", Float) = 1.0
_CameraFarFadeDistance("Camera Far Fade", Float) = 2.0
_DistortionBlend("Distortion Blend", Range(0.0, 1.0)) = 0.5
_DistortionStrength("Distortion Strength", Float) = 1.0
// -------------------------------------
// Hidden properties - Generic
_Surface("__surface", Float) = 0.0
_Blend("__mode", Float) = 0.0
_Cull("__cull", Float) = 2.0
[ToggleUI] _AlphaClip("__clip", Float) = 0.0
[HideInInspector] _BlendOp("__blendop", 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] _BlendModePreserveSpecular("_BlendModePreserveSpecular", Float) = 1.0
[HideInInspector] _AlphaToMask("__alphaToMask", Float) = 0.0
// Particle specific
_ColorMode("_ColorMode", Float) = 0.0
[HideInInspector] _BaseColorAddSubDiff("_ColorMode", Vector) = (0,0,0,0)
[ToggleOff] _FlipbookBlending("__flipbookblending", Float) = 0.0
[ToggleUI] _SoftParticlesEnabled("__softparticlesenabled", Float) = 0.0
[ToggleUI] _CameraFadingEnabled("__camerafadingenabled", Float) = 0.0
[ToggleUI] _DistortionEnabled("__distortionenabled", Float) = 0.0
[HideInInspector] _SoftParticleFadeParams("__softparticlefadeparams", Vector) = (0,0,0,0)
[HideInInspector] _CameraFadeParams("__camerafadeparams", Vector) = (0,0,0,0)
[HideInInspector] _DistortionStrengthScaled("Distortion Strength Scaled", Float) = 0.1
// Editmode props
_QueueOffset("Queue offset", Float) = 0.0
// ObsoleteProperties
[HideInInspector] _FlipbookMode("flipbook", Float) = 0
[HideInInspector] _Glossiness("gloss", Float) = 0
[HideInInspector] _Mode("mode", Float) = 0
[HideInInspector] _Color("color", Color) = (1,1,1,1)
}
HLSLINCLUDE
//Particle shaders rely on "write" to CB syntax which is not supported by DXC
#pragma never_use_dxc
ENDHLSL
SubShader
{
Tags
{
"RenderType" = "Opaque"
"IgnoreProjector" = "True"
"PreviewType" = "Plane"
"PerformanceChecks" = "False"
"RenderPipeline" = "UniversalPipeline"
"UniversalMaterialType" = "Lit"
}
// ------------------------------------------------------------------
// Forward 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"
Tags
{
"LightMode" = "UniversalForwardOnly"
}
// -------------------------------------
// Render State Commands
BlendOp[_BlendOp]
Blend[_SrcBlend][_DstBlend], [_SrcBlendAlpha][_DstBlendAlpha]
ZWrite[_ZWrite]
Cull[_Cull]
AlphaToMask[_AlphaToMask]
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex ParticlesLitVertex
#pragma fragment ParticlesLitFragment
// -------------------------------------
// Material Keywords
#pragma shader_feature_local _NORMALMAP
#pragma shader_feature_local _RECEIVE_SHADOWS_OFF
#pragma shader_feature_local_fragment _SURFACE_TYPE_TRANSPARENT
#pragma shader_feature_local_fragment _EMISSION
#pragma shader_feature_local_fragment _METALLICSPECGLOSSMAP
// -------------------------------------
// Particle Keywords
#pragma shader_feature_local _FLIPBOOKBLENDING_ON
#pragma shader_feature_local _SOFTPARTICLES_ON
#pragma shader_feature_local _FADING_ON
#pragma shader_feature_local _DISTORTION_ON
#pragma shader_feature_local_fragment _ _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON
#pragma shader_feature_local_fragment _ _ALPHATEST_ON
#pragma shader_feature_local_fragment _ _COLOROVERLAY_ON _COLORCOLOR_ON _COLORADDSUBDIFF_ON
// -------------------------------------
// Universal Pipeline keywords
#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 _ _REFLECTION_PROBE_BLENDING
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION
#if UNITY_VERSION >= 60000100
#pragma multi_compile_fragment _ _REFLECTION_PROBE_ATLAS
#endif
#pragma multi_compile_fragment _ _ENABLE_BG_AREA_LIGHTING
#pragma multi_compile_fragment _ _BG_AREALIGHT_SHADOWS_PCF2X2 _BG_AREALIGHT_SHADOWS_TENT5X5 _BG_AREALIGHT_SHADOWS_TENT7X7 _BG_AREALIGHT_SHADOWS_PCSS
#pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fragment _ _LIGHT_COOKIES
#if UNITY_VERSION >= 60000100
#pragma multi_compile _ _CLUSTER_LIGHT_LOOP
#else
#pragma multi_compile _ _FORWARD_PLUS
#endif
#pragma multi_compile _ EVALUATE_SH_MIXED EVALUATE_SH_VERTEX
#if UNITY_VERSION >= 60000000
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ProbeVolumeVariants.hlsl"
#endif
#if UNITY_VERSION >= 60000100
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Fog.hlsl"
#else
#pragma multi_compile_fog
#endif
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
#pragma multi_compile_instancing
#pragma multi_compile_fragment _ DEBUG_DISPLAY
#pragma instancing_options procedural:ParticleInstancingSetup
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
// -------------------------------------
// Includes
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
#include "Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaParticleLitForwardPass.hlsl"
ENDHLSL
}
// ------------------------------------------------------------------
// Depth Only pass.
Pass
{
Name "DepthOnly"
Tags
{
"LightMode" = "DepthOnly"
}
// -------------------------------------
// Render State Commands
ZWrite On
ColorMask R
Cull[_Cull]
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex DepthOnlyVertex
#pragma fragment DepthOnlyFragment
// -------------------------------------
// Material Keywords
#pragma shader_feature_local _ _ALPHATEST_ON
#pragma shader_feature_local _ _FLIPBOOKBLENDING_ON
#pragma shader_feature_local_fragment _ _COLOROVERLAY_ON _COLORCOLOR_ON _COLORADDSUBDIFF_ON
// -------------------------------------
// Unity defined keywords
#pragma multi_compile_instancing
#pragma instancing_options procedural:ParticleInstancingSetup
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
// -------------------------------------
// Includes
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesDepthOnlyPass.hlsl"
ENDHLSL
}
// This pass is used when drawing to a _CameraNormalsTexture texture
Pass
{
Name "DepthNormals"
Tags
{
"LightMode" = "DepthNormals"
}
// -------------------------------------
// Render State Commands
ZWrite On
Cull[_Cull]
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex DepthNormalsVertex
#pragma fragment DepthNormalsFragment
// -------------------------------------
// Material Keywords
#pragma shader_feature_local _ _NORMALMAP
#pragma shader_feature_local _ _FLIPBOOKBLENDING_ON
#pragma shader_feature_local _ _ALPHATEST_ON
#pragma shader_feature_local_fragment _ _COLOROVERLAY_ON _COLORCOLOR_ON _COLORADDSUBDIFF_ON
// -------------------------------------
// Unity defined keywords
#pragma multi_compile_instancing
#pragma instancing_options procedural:ParticleInstancingSetup
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
// -------------------------------------
// Includes
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesDepthNormalsPass.hlsl"
ENDHLSL
}
// ------------------------------------------------------------------
// Scene view outline pass.
Pass
{
Name "SceneSelectionPass"
Tags
{
"LightMode" = "SceneSelectionPass"
}
// -------------------------------------
// Render State Commands
BlendOp Add
Blend One Zero
ZWrite On
Cull Off
HLSLPROGRAM
#define PARTICLES_EDITOR_META_PASS
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex vertParticleEditor
#pragma fragment fragParticleSceneHighlight
// -------------------------------------
// Particle Keywords
#pragma shader_feature_local_fragment _ALPHATEST_ON
#pragma shader_feature_local _FLIPBOOKBLENDING_ON
// -------------------------------------
// Unity defined keywords
#pragma multi_compile_instancing
#pragma instancing_options procedural:ParticleInstancingSetup
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
// -------------------------------------
// Includes
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesEditorPass.hlsl"
ENDHLSL
}
// ------------------------------------------------------------------
// Scene picking buffer pass.
Pass
{
Name "ScenePickingPass"
Tags
{
"LightMode" = "Picking"
}
// -------------------------------------
// Render State Commands
BlendOp Add
Blend One Zero
ZWrite On
Cull Off
HLSLPROGRAM
#define PARTICLES_EDITOR_META_PASS
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex vertParticleEditor
#pragma fragment fragParticleScenePicking
// -------------------------------------
// Particle Keywords
#pragma shader_feature_local_fragment _ALPHATEST_ON
#pragma shader_feature_local _FLIPBOOKBLENDING_ON
// -------------------------------------
// Unity defined keywords
#pragma multi_compile_instancing
#pragma instancing_options procedural:ParticleInstancingSetup
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
// -------------------------------------
// Includes
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesEditorPass.hlsl"
ENDHLSL
}
Pass
{
Name "Universal2D"
Tags
{
"LightMode" = "Universal2D"
}
// -------------------------------------
// Render State Commands
Blend[_SrcBlend][_DstBlend]
ZWrite[_ZWrite]
Cull[_Cull]
HLSLPROGRAM
// -------------------------------------
// Shader Stages
#pragma vertex vert
#pragma fragment frag
// -------------------------------------
// Material Keywords
#pragma shader_feature_local_fragment _ALPHATEST_ON
#pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON
// -------------------------------------
// Includes
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/Universal2D.hlsl"
ENDHLSL
}
}
Fallback "Universal Render Pipeline/Particles/Simple Lit"
CustomEditor "UnityEditor.Rendering.Universal.ShaderGUI.ParticlesLitShader"
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 0b2516ca234061647a5b31ac12e5f6cc
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 346790
packageName: Realtime Area Light for URP
packageVersion: 1.3.0
assetPath: Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaParticleLit.shader
uploadId: 884030

View File

@@ -0,0 +1,162 @@
#ifndef BADDOG_AREA_PARTICLES_FORWARD_LIT_PASS_INCLUDED
#define BADDOG_AREA_PARTICLES_FORWARD_LIT_PASS_INCLUDED
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
// Include Area Light support
#include "Packages/com.baddog.rendering.arealight/Shaders/Include/BGAreaLighting.hlsl"
void InitializeInputData(VaryingsParticle input, half3 normalTS, out InputData inputData)
{
inputData = (InputData)0;
inputData.positionWS = input.positionWS.xyz;
#ifdef _NORMALMAP
half3 viewDirWS = half3(input.normalWS.w, input.tangentWS.w, input.bitangentWS.w);
inputData.tangentToWorld = half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz);
inputData.normalWS = TransformTangentToWorld(normalTS, inputData.tangentToWorld);
#else
half3 viewDirWS = input.viewDirWS;
inputData.normalWS = input.normalWS;
#endif
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
viewDirWS = SafeNormalize(viewDirWS);
inputData.viewDirectionWS = viewDirWS;
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
inputData.shadowCoord = input.shadowCoord;
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
#else
inputData.shadowCoord = float4(0, 0, 0, 0);
#endif
inputData.fogCoord = InitializeInputDataFog(float4(input.positionWS.xyz, 1.0), input.positionWS.w);
inputData.vertexLighting = half3(0.0h, 0.0h, 0.0h);
#if !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
inputData.bakedGI = SAMPLE_GI(input.vertexSH,
GetAbsolutePositionWS(inputData.positionWS),
inputData.normalWS,
inputData.viewDirectionWS,
input.clipPos.xy,
input.probeOcclusion,
inputData.shadowMask);
#else
inputData.bakedGI = SampleSHPixel(input.vertexSH, inputData.normalWS);
#endif
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.clipPos);
inputData.shadowMask = half4(1, 1, 1, 1);
#if defined(DEBUG_DISPLAY) && defined(USE_APV_PROBE_OCCLUSION)
inputData.probeOcclusion = input.probeOcclusion;
#endif
#if defined(DEBUG_DISPLAY) && !defined(PARTICLES_EDITOR_META_PASS)
inputData.vertexSH = input.vertexSH;
#endif
}
///////////////////////////////////////////////////////////////////////////////
// Vertex and Fragment functions //
///////////////////////////////////////////////////////////////////////////////
VaryingsParticle ParticlesLitVertex(AttributesParticle input)
{
VaryingsParticle output = (VaryingsParticle)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
half3 viewDirWS = GetWorldSpaceNormalizeViewDir(vertexInput.positionWS);
half3 vertexLight = VertexLighting(vertexInput.positionWS, half3(normalInput.normalWS));
half fogFactor = 0.0;
#if !defined(_FOG_FRAGMENT)
fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
#endif
#ifdef _NORMALMAP
output.normalWS = half4(normalInput.normalWS, viewDirWS.x);
output.tangentWS = half4(normalInput.tangentWS, viewDirWS.y);
output.bitangentWS = half4(normalInput.bitangentWS, viewDirWS.z);
#else
output.normalWS = half3(normalInput.normalWS);
output.viewDirWS = viewDirWS;
#endif
#if UNITY_VERSION >= 60000000
OUTPUT_SH4(vertexInput.positionWS, output.normalWS.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), output.vertexSH, output.probeOcclusion);
#else
OUTPUT_SH(output.normalWS.xyz, output.vertexSH);
#endif
output.positionWS.xyz = vertexInput.positionWS;
output.positionWS.w = fogFactor;
output.clipPos = vertexInput.positionCS;
output.color = GetParticleColor(input.color);
#if defined(_FLIPBOOKBLENDING_ON)
#if defined(UNITY_PARTICLE_INSTANCING_ENABLED)
GetParticleTexcoords(output.texcoord, output.texcoord2AndBlend, input.texcoords.xyxy, 0.0);
#else
GetParticleTexcoords(output.texcoord, output.texcoord2AndBlend, input.texcoords, input.texcoordBlend);
#endif
#else
GetParticleTexcoords(output.texcoord, input.texcoords.xy);
#endif
#if defined(_SOFTPARTICLES_ON) || defined(_FADING_ON) || defined(_DISTORTION_ON)
output.projectedPosition = vertexInput.positionNDC;
#endif
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
output.shadowCoord = GetShadowCoord(vertexInput);
#endif
return output;
}
half4 ParticlesLitFragment(VaryingsParticle input) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
ParticleParams particleParams;
InitParticleParams(input, particleParams);
SurfaceData surfaceData;
InitializeParticleLitSurfaceData(particleParams, surfaceData);
InputData inputData;
InitializeInputData(input, surfaceData.normalTS, inputData);
#if UNITY_VERSION >= 60000000
SETUP_DEBUG_TEXTURE_DATA_FOR_TEX(inputData, input.texcoord, _BaseMap);
#else
SETUP_DEBUG_TEXTURE_DATA(inputData, input.texcoord, _BaseMap);
#endif
// Standard URP PBR lighting calculation
half4 color = UniversalFragmentPBR(inputData, surfaceData);
// Additional Area Light (only when enabled)
#if defined(_ENABLE_BG_AREA_LIGHTING)
color.rgb += EvaluateAreaLight(inputData, surfaceData);
#endif
color.rgb = MixFog(color.rgb, inputData.fogCoord);
color.a = OutputAlpha(color.a, IsSurfaceTypeTransparent(_Surface));
return color;
}
#endif // BADDOG_AREA_PARTICLES_FORWARD_LIT_PASS_INCLUDED

View File

@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: e808e29fa69a12f4592e75201b077d20
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 346790
packageName: Realtime Area Light for URP
packageVersion: 1.3.0
assetPath: Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaParticleLitForwardPass.hlsl
uploadId: 884030

View File

@@ -0,0 +1,408 @@
// Shader targeted for low end devices. Single Pass Forward Rendering with Area Light Support.
Shader "BadDog/URP/BGAreaSimpleLit"
{
// Keep properties of StandardSpecular shader for upgrade reasons.
Properties
{
[MainTexture] _BaseMap("Base Map (RGB) Smoothness / Alpha (A)", 2D) = "white" {}
[MainColor] _BaseColor("Base Color", Color) = (1, 1, 1, 1)
_Cutoff("Alpha Clipping", Range(0.0, 1.0)) = 0.5
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
_SpecColor("Specular Color", Color) = (0.5, 0.5, 0.5, 0.5)
_SpecGlossMap("Specular Map", 2D) = "white" {}
_SmoothnessSource("Smoothness Source", Float) = 0.0
_SpecularHighlights("Specular Highlights", Float) = 1.0
[HideInInspector] _BumpScale("Scale", Float) = 1.0
[NoScaleOffset] _BumpMap("Normal Map", 2D) = "bump" {}
[HDR] _EmissionColor("Emission Color", Color) = (0,0,0)
[NoScaleOffset]_EmissionMap("Emission Map", 2D) = "white" {}
// Blending state
_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] _BlendModePreserveSpecular("_BlendModePreserveSpecular", Float) = 1.0
[HideInInspector] _AlphaToMask("__alphaToMask", Float) = 0.0
[HideInInspector] _AddPrecomputedVelocity("_AddPrecomputedVelocity", Float) = 0.0
[HideInInspector] _XRMotionVectorsPass("_XRMotionVectorsPass", Float) = 1.0
[ToggleUI] _ReceiveShadows("Receive Shadows", Float) = 1.0
// Editmode props
_QueueOffset("Queue offset", Float) = 0.0
// ObsoleteProperties
[HideInInspector] _MainTex("BaseMap", 2D) = "white" {}
[HideInInspector] _Color("Base Color", Color) = (1, 1, 1, 1)
[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 300
Pass
{
Name "ForwardLit"
Tags
{
"LightMode" = "UniversalForwardOnly"
}
// -------------------------------------
// Render State Commands
// Use same blending / depth states as Standard shader
Blend[_SrcBlend][_DstBlend], [_SrcBlendAlpha][_DstBlendAlpha]
ZWrite[_ZWrite]
Cull[_Cull]
AlphaToMask[_AlphaToMask]
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex LitPassVertexSimple
#pragma fragment LitPassFragmentSimple
// -------------------------------------
// Material Keywords
#pragma shader_feature_local _NORMALMAP
#pragma shader_feature_local_fragment _EMISSION
#pragma shader_feature_local _RECEIVE_SHADOWS_OFF
#pragma shader_feature_local_fragment _SURFACE_TYPE_TRANSPARENT
#pragma shader_feature_local_fragment _ALPHATEST_ON
#pragma shader_feature_local_fragment _ _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON
#pragma shader_feature_local_fragment _ _SPECGLOSSMAP _SPECULAR_COLOR
#pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA
// -------------------------------------
// Universal Pipeline keywords
#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 _ EVALUATE_SH_MIXED EVALUATE_SH_VERTEX
#pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
#pragma multi_compile _ SHADOWS_SHADOWMASK
#pragma multi_compile _ _LIGHT_LAYERS
#if UNITY_VERSION >= 60000100
#pragma multi_compile _ _CLUSTER_LIGHT_LOOP
#else
#pragma multi_compile _ _FORWARD_PLUS
#endif
#pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile_fragment _ _ENABLE_BG_AREA_LIGHTING
#pragma multi_compile_fragment _ _BG_AREALIGHT_SHADOWS_PCF2X2 _BG_AREALIGHT_SHADOWS_TENT5X5 _BG_AREALIGHT_SHADOWS_TENT7X7 _BG_AREALIGHT_SHADOWS_PCSS
#pragma multi_compile_fragment _ _SHADOWS_SOFT
#pragma multi_compile_fragment _ _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
#pragma multi_compile_fragment _ _LIGHT_COOKIES
#if UNITY_VERSION >= 60000000
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ProbeVolumeVariants.hlsl"
#endif
#if UNITY_VERSION >= 60000100
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Fog.hlsl"
#else
#pragma multi_compile_fog
#endif
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ LIGHTMAP_ON
#if UNITY_VERSION >= 60000100
#pragma multi_compile_fragment _ LIGHTMAP_BICUBIC_SAMPLING
#endif
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
#pragma multi_compile _ USE_LEGACY_LIGHTMAPS
#pragma multi_compile_fragment _ DEBUG_DISPLAY
#pragma multi_compile _ LOD_FADE_CROSSFADE
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#pragma instancing_options renderinglayer
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
//--------------------------------------
// Defines
#define BUMP_SCALE_NOT_SUPPORTED 1
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"
#include "Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaSimpleLitForwardPass.hlsl"
ENDHLSL
}
Pass
{
Name "ShadowCaster"
Tags
{
"LightMode" = "ShadowCaster"
}
// -------------------------------------
// Render State Commands
ZWrite On
ZTest LEqual
ColorMask 0
Cull[_Cull]
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex ShadowPassVertex
#pragma fragment ShadowPassFragment
// -------------------------------------
// Material Keywords
#pragma shader_feature_local _ALPHATEST_ON
#pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ LOD_FADE_CROSSFADE
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
// This is used during shadow map generation to differentiate between directional and punctual light shadows, as they use different formulas to apply Normal Bias
#pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
ENDHLSL
}
Pass
{
Name "DepthOnly"
Tags
{
"LightMode" = "DepthOnly"
}
// -------------------------------------
// Render State Commands
ZWrite On
ColorMask R
Cull[_Cull]
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex DepthOnlyVertex
#pragma fragment DepthOnlyFragment
// -------------------------------------
// Material Keywords
#pragma shader_feature_local _ALPHATEST_ON
#pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ LOD_FADE_CROSSFADE
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
ENDHLSL
}
// This pass is used when drawing to a _CameraNormalsTexture texture
Pass
{
Name "DepthNormals"
Tags
{
"LightMode" = "DepthNormals"
}
// -------------------------------------
// Render State Commands
ZWrite On
Cull[_Cull]
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex DepthNormalsVertex
#pragma fragment DepthNormalsFragment
// -------------------------------------
// Material Keywords
#pragma shader_feature_local _NORMALMAP
#pragma shader_feature_local _ALPHATEST_ON
#pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ LOD_FADE_CROSSFADE
// Universal Pipeline keywords
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitDepthNormalsPass.hlsl"
ENDHLSL
}
// This pass it not used during regular rendering, only for lightmap baking.
Pass
{
Name "Meta"
Tags
{
"LightMode" = "Meta"
}
// -------------------------------------
// Render State Commands
Cull Off
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex UniversalVertexMeta
#pragma fragment UniversalFragmentMetaSimple
// -------------------------------------
// Material Keywords
#pragma shader_feature_local_fragment _EMISSION
#pragma shader_feature_local_fragment _SPECGLOSSMAP
#pragma shader_feature EDITOR_VISUALIZATION
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitMetaPass.hlsl"
ENDHLSL
}
Pass
{
Name "Universal2D"
Tags
{
"LightMode" = "Universal2D"
"RenderType" = "Transparent"
"Queue" = "Transparent"
}
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex vert
#pragma fragment frag
// -------------------------------------
// Material Keywords
#pragma shader_feature_local_fragment _ALPHATEST_ON
#pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/Universal2D.hlsl"
ENDHLSL
}
Pass
{
Name "MotionVectors"
Tags { "LightMode" = "MotionVectors" }
ColorMask RG
HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
#pragma multi_compile _ LOD_FADE_CROSSFADE
#pragma shader_feature_local_vertex _ADD_PRECOMPUTED_VELOCITY
#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ObjectMotionVectors.hlsl"
ENDHLSL
}
Pass
{
Name "XRMotionVectors"
Tags { "LightMode" = "XRMotionVectors" }
ColorMask RGBA
// Stencil write for obj motion pixels
Stencil
{
WriteMask 1
Ref 1
Comp Always
Pass Replace
}
HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
#pragma multi_compile _ LOD_FADE_CROSSFADE
#pragma shader_feature_local_vertex _ADD_PRECOMPUTED_VELOCITY
#define APPLICATION_SPACE_WARP_MOTION 1
#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ObjectMotionVectors.hlsl"
ENDHLSL
}
}
Fallback "Hidden/Universal Render Pipeline/FallbackError"
CustomEditor "UnityEditor.Rendering.Universal.ShaderGUI.SimpleLitShader"
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 944f87dd0be44d4438c1ee0fb085c7fa
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 346790
packageName: Realtime Area Light for URP
packageVersion: 1.3.0
assetPath: Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaSimpleLit.shader
uploadId: 884030

View File

@@ -0,0 +1,247 @@
#ifndef BADDOG_AREA_SIMPLE_LIT_PASS_INCLUDED
#define BADDOG_AREA_SIMPLE_LIT_PASS_INCLUDED
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#if defined(LOD_FADE_CROSSFADE)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl"
#endif
// Include Area Light support
#include "Packages/com.baddog.rendering.arealight/Shaders/Include/BGAreaLighting.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
float4 tangentOS : TANGENT;
float2 texcoord : TEXCOORD0;
float2 staticLightmapUV : TEXCOORD1;
float2 dynamicLightmapUV : TEXCOORD2;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float2 uv : TEXCOORD0;
float3 positionWS : TEXCOORD1; // xyz: posWS
#ifdef _NORMALMAP
half4 normalWS : TEXCOORD2; // xyz: normal, w: viewDir.x
half4 tangentWS : TEXCOORD3; // xyz: tangent, w: viewDir.y
half4 bitangentWS : TEXCOORD4; // xyz: bitangent, w: viewDir.z
#else
half3 normalWS : TEXCOORD2;
#endif
#ifdef _ADDITIONAL_LIGHTS_VERTEX
half4 fogFactorAndVertexLight : TEXCOORD5; // x: fogFactor, yzw: vertex light
#else
half fogFactor : TEXCOORD5;
#endif
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
float4 shadowCoord : TEXCOORD6;
#endif
DECLARE_LIGHTMAP_OR_SH(staticLightmapUV, vertexSH, 7);
#ifdef DYNAMICLIGHTMAP_ON
float2 dynamicLightmapUV : TEXCOORD8; // Dynamic lightmap UVs
#endif
#ifdef USE_APV_PROBE_OCCLUSION
float4 probeOcclusion : TEXCOORD9;
#endif
float4 positionCS : SV_POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
void InitializeInputData(Varyings input, half3 normalTS, out InputData inputData)
{
inputData = (InputData)0;
inputData.positionWS = input.positionWS;
#if defined(DEBUG_DISPLAY)
inputData.positionCS = input.positionCS;
#endif
#ifdef _NORMALMAP
half3 viewDirWS = half3(input.normalWS.w, input.tangentWS.w, input.bitangentWS.w);
inputData.tangentToWorld = half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz);
inputData.normalWS = TransformTangentToWorld(normalTS, inputData.tangentToWorld);
#else
half3 viewDirWS = GetWorldSpaceNormalizeViewDir(inputData.positionWS);
inputData.normalWS = input.normalWS;
#endif
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
viewDirWS = SafeNormalize(viewDirWS);
inputData.viewDirectionWS = viewDirWS;
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
inputData.shadowCoord = input.shadowCoord;
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
#else
inputData.shadowCoord = float4(0, 0, 0, 0);
#endif
#ifdef _ADDITIONAL_LIGHTS_VERTEX
inputData.fogCoord = InitializeInputDataFog(float4(inputData.positionWS, 1.0), input.fogFactorAndVertexLight.x);
inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
#else
inputData.fogCoord = InitializeInputDataFog(float4(inputData.positionWS, 1.0), input.fogFactor);
inputData.vertexLighting = half3(0, 0, 0);
#endif
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
#if defined(DEBUG_DISPLAY)
#if defined(DYNAMICLIGHTMAP_ON)
inputData.dynamicLightmapUV = input.dynamicLightmapUV.xy;
#endif
#if defined(LIGHTMAP_ON)
inputData.staticLightmapUV = input.staticLightmapUV;
#else
inputData.vertexSH = input.vertexSH;
#endif
#if defined(USE_APV_PROBE_OCCLUSION)
inputData.probeOcclusion = input.probeOcclusion;
#endif
#endif
}
void InitializeBakedGIData(Varyings input, inout InputData inputData)
{
#if defined(DYNAMICLIGHTMAP_ON)
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.dynamicLightmapUV, input.vertexSH, inputData.normalWS);
inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
#elif !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
inputData.bakedGI = SAMPLE_GI(input.vertexSH,
GetAbsolutePositionWS(inputData.positionWS),
inputData.normalWS,
inputData.viewDirectionWS,
input.positionCS.xy,
input.probeOcclusion,
inputData.shadowMask);
#else
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.vertexSH, inputData.normalWS);
inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
#endif
}
///////////////////////////////////////////////////////////////////////////////
// Vertex and Fragment functions //
///////////////////////////////////////////////////////////////////////////////
// Used in Standard (Simple Lighting) shader
Varyings LitPassVertexSimple(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
#if defined(_FOG_FRAGMENT)
half fogFactor = 0;
#else
half fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
#endif
output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
output.positionWS.xyz = vertexInput.positionWS;
output.positionCS = vertexInput.positionCS;
#ifdef _NORMALMAP
half3 viewDirWS = GetWorldSpaceViewDir(vertexInput.positionWS);
output.normalWS = half4(normalInput.normalWS, viewDirWS.x);
output.tangentWS = half4(normalInput.tangentWS, viewDirWS.y);
output.bitangentWS = half4(normalInput.bitangentWS, viewDirWS.z);
#else
output.normalWS = NormalizeNormalPerVertex(normalInput.normalWS);
#endif
OUTPUT_LIGHTMAP_UV(input.staticLightmapUV, unity_LightmapST, output.staticLightmapUV);
#ifdef DYNAMICLIGHTMAP_ON
output.dynamicLightmapUV = input.dynamicLightmapUV.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
#endif
#if UNITY_VERSION >= 60000000
OUTPUT_SH4(vertexInput.positionWS, output.normalWS.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), output.vertexSH, output.probeOcclusion);
#else
OUTPUT_SH(output.normalWS.xyz, output.vertexSH);
#endif
#ifdef _ADDITIONAL_LIGHTS_VERTEX
half3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS);
output.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
#else
output.fogFactor = fogFactor;
#endif
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
output.shadowCoord = GetShadowCoord(vertexInput);
#endif
return output;
}
// Used for StandardSimpleLighting shader with Area Light support
void LitPassFragmentSimple(
Varyings input
, out half4 outColor : SV_Target0
#ifdef _WRITE_RENDERING_LAYERS
, out uint outRenderingLayers : SV_Target1
#endif
)
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
SurfaceData surfaceData;
InitializeSimpleLitSurfaceData(input.uv, surfaceData);
#ifdef LOD_FADE_CROSSFADE
LODFadeCrossFade(input.positionCS);
#endif
InputData inputData;
InitializeInputData(input, surfaceData.normalTS, inputData);
#if UNITY_VERSION >= 60000000
SETUP_DEBUG_TEXTURE_DATA(inputData, UNDO_TRANSFORM_TEX(input.uv, _BaseMap));
#else
SETUP_DEBUG_TEXTURE_DATA(inputData, input.uv, _BaseMap);
#endif
#if defined(_DBUFFER)
ApplyDecalToSurfaceData(input.positionCS, surfaceData, inputData);
#endif
InitializeBakedGIData(input, inputData);
// Standard URP SimpleLit lighting calculation (Blinn-Phong)
half4 color = UniversalFragmentBlinnPhong(inputData, surfaceData);
// Additional Area Light (only when enabled)
#if defined(_ENABLE_BG_AREA_LIGHTING)
color.rgb += EvaluateAreaLight(inputData, surfaceData);
#endif
color.rgb = MixFog(color.rgb, inputData.fogCoord);
color.a = OutputAlpha(color.a, IsSurfaceTypeTransparent(_Surface));
outColor = color;
#ifdef _WRITE_RENDERING_LAYERS
outRenderingLayers = EncodeMeshRenderingLayer();
#endif
}
#endif

View File

@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: 31e39004ca00d8d489eb5985b35f6f2f
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 346790
packageName: Realtime Area Light for URP
packageVersion: 1.3.0
assetPath: Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaSimpleLitForwardPass.hlsl
uploadId: 884030

View File

@@ -0,0 +1,229 @@
Shader "BadDog/URP/BGAreaSpineLit"
{
Properties
{
_Cutoff("Shadow alpha cutoff", Range(0, 1)) = 0.1
[NoScaleOffset] _MainTex("Main Texture", 2D) = "black" {}
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
[Toggle(_ZWRITE)] _ZWrite("Depth Write", Float) = 0.0
[Toggle(_RECEIVE_SHADOWS)] _ReceiveShadows("Receive Shadows", Int) = 0
[Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0
[MaterialToggle(_LIGHT_AFFECTS_ADDITIVE)] _LightAffectsAdditive("Light Affects Additive", Float) = 0
[MaterialToggle(_TINT_BLACK_ON)] _TintBlack("Tint Black", Float) = 0
_Color(" Light Color", Color) = (1, 1, 1, 1)
_Black(" Dark Color", Color) = (0, 0, 0, 0)
[MaterialToggle(_ADAPTIVE_PROBE_VOLUMES_PER_PIXEL)] _AdaptiveProbeVolumesPerPixel("APV per Pixel", Float) = 1
[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Compare", Float) = 8
}
SubShader
{
Tags
{
"RenderPipeline" = "UniversalPipeline"
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
}
LOD 100
Cull Off
ZWrite[_ZWrite]
Blend One OneMinusSrcAlpha
Stencil
{
Ref[_StencilRef]
Comp[_StencilComp]
Pass Keep
}
Pass
{
Name "ForwardLit"
Tags { "LightMode" = "UniversalForward" }
ZWrite[_ZWrite]
Cull Off
Blend One OneMinusSrcAlpha
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
// -------------------------------------
// Universal Pipeline keywords
#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 _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile _ _SHADOWS_SOFT
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
#pragma multi_compile _ _LIGHT_AFFECTS_ADDITIVE
#pragma multi_compile_fragment _ _LIGHT_COOKIES
#pragma shader_feature _TINT_BLACK_ON
#pragma multi_compile_fragment _ _ENABLE_BG_AREA_LIGHTING
#pragma multi_compile _ _LIGHT_LAYERS
#if UNITY_VERSION >= 60000100
#pragma multi_compile _ _CLUSTER_LIGHT_LOOP
#else
#pragma multi_compile _ _FORWARD_PLUS
#endif
// -------------------------------------
// Unity defined keywords
#if UNITY_VERSION >= 60000000
#pragma multi_compile_fragment _ DEBUG_DISPLAY
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ProbeVolumeVariants.hlsl"
#endif
#if UNITY_VERSION >= 60000100
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Fog.hlsl"
#else
#pragma multi_compile_fog
#endif
// -------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#pragma instancing_options renderinglayer
// -------------------------------------
// Spine related keywords
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
#pragma shader_feature _ _DOUBLE_SIDED_LIGHTING
#pragma shader_feature _RECEIVE_SHADOWS_OFF _RECEIVE_SHADOWS
#pragma vertex vert
#pragma fragment frag
#undef LIGHTMAP_ON
#define USE_URP
#define fixed4 half4
#define fixed3 half3
#define fixed half
#define BGAREA_SPINE_PASS_FORWARDLIT
#include "Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaSpineLitForwardPass.hlsl"
#undef BGAREA_SPINE_PASS_FORWARDLIT
ENDHLSL
}
Pass
{
Name "ShadowCaster"
Tags { "LightMode" = "ShadowCaster" }
ZWrite On
ColorMask 0
ZTest LEqual
Cull Off
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 shader_feature _ _DOUBLE_SIDED_LIGHTING
#pragma vertex ShadowPassVertexSkeletonLit
#pragma fragment ShadowPassFragmentSkeletonLit
#define USE_URP
#define fixed4 half4
#define fixed3 half3
#define fixed half
#define BGAREA_SPINE_PASS_SHADOWCASTER
#include "Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaSpineLitForwardPass.hlsl"
#undef BGAREA_SPINE_PASS_SHADOWCASTER
ENDHLSL
}
Pass
{
Name "DepthOnly"
Tags { "LightMode" = "DepthOnly" }
ZWrite On
ColorMask R
Cull Off
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#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
#define USE_URP
#define fixed4 half4
#define fixed3 half3
#define fixed half
#define BGAREA_SPINE_PASS_DEPTHONLY
#include "Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaSpineLitForwardPass.hlsl"
#undef BGAREA_SPINE_PASS_DEPTHONLY
ENDHLSL
}
// This pass is used when drawing to a _CameraNormalsTexture texture
Pass
{
Name "DepthNormals"
Tags { "LightMode" = "DepthNormals" }
ZWrite On
HLSLPROGRAM
#pragma vertex DepthNormalsVertex
#pragma fragment DepthNormalsFragment
// -------------------------------------
// Material Keywords
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _ _DOUBLE_SIDED_LIGHTING
// -------------------------------------
// Universal Pipeline keywords
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"
// -------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#define USE_URP
#define fixed4 half4
#define fixed3 half3
#define fixed half
#define BGAREA_SPINE_PASS_DEPTHNORMALS
#include "Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaSpineLitForwardPass.hlsl"
#undef BGAREA_SPINE_PASS_DEPTHNORMALS
ENDHLSL
}
}
FallBack "Universal Render Pipeline/Unlit"
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: f879e5cab3db4519a757f17400a9de49
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 346790
packageName: Realtime Area Light for URP
packageVersion: 1.3.0
assetPath: Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaSpineLit.shader
uploadId: 884030

View File

@@ -0,0 +1,601 @@
#ifndef BADDOG_AREA_SPINE_LIT_PASSES_INCLUDED
#define BADDOG_AREA_SPINE_LIT_PASSES_INCLUDED
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#undef LIGHTMAP_ON
CBUFFER_START(UnityPerMaterial)
float4 _MainTex_ST;
half _Cutoff;
half4 _Color;
half4 _Black;
CBUFFER_END
sampler2D _MainTex;
inline half3 BGSpine_GammaToTargetSpace(half3 gammaColor)
{
#if UNITY_COLORSPACE_GAMMA
return gammaColor;
#else
return SRGBToLinear(gammaColor);
#endif
}
inline half4 BGSpine_PMAGammaToTargetSpace(half4 gammaPMAColor)
{
#if UNITY_COLORSPACE_GAMMA
return gammaPMAColor;
#else
return gammaPMAColor.a == 0
? half4(SRGBToLinear(gammaPMAColor.rgb), gammaPMAColor.a)
: half4(SRGBToLinear(gammaPMAColor.rgb / gammaPMAColor.a) * gammaPMAColor.a, gammaPMAColor.a);
#endif
}
float4 BGSpine_fragTintedColor(float4 texColor, float3 darkTintColor, float4 lightTintColorPMA, float lightColorAlpha, float darkColorAlpha)
{
float a = texColor.a * lightTintColorPMA.a;
#if !defined(_STRAIGHT_ALPHA_INPUT)
float3 texDarkColor = texColor.a - texColor.rgb;
#else
float3 texDarkColor = (1 - texColor.rgb);
#endif
float3 darkColor = texDarkColor * darkTintColor.rgb * lightColorAlpha;
float3 lightColor = texColor.rgb * lightTintColorPMA.rgb;
float4 fragColor = float4(darkColor + lightColor, a);
#if defined(_STRAIGHT_ALPHA_INPUT)
fragColor.rgb *= texColor.a;
#endif
#if defined(_DARK_COLOR_ALPHA_ADDITIVE)
fragColor.a = a * (1 - darkColorAlpha);
#endif
return fragColor;
}
#if defined(_WRITE_RENDERING_LAYERS) || defined(_LIGHT_LAYERS)
uint BGSpine_GetMeshRenderingLayerBackwardsCompatible()
{
// URP 14+ exposes GetMeshRenderingLayer(). Older: GetMeshRenderingLightLayer().
// We prefer the 14+ API when present.
#if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)
// No reliable version macro on all targets; best-effort fallback.
return 0;
#else
#if defined(UNIVERSAL_REALTIME_LIGHTS_INCLUDED)
// In URP 17 this exists.
return GetMeshRenderingLayer();
#else
return 0;
#endif
#endif
}
#else
uint BGSpine_GetMeshRenderingLayerBackwardsCompatible()
{
return 0;
}
#endif
// -----------------------------------------------------------------------------
// ShadowCaster pass (names kept to match existing shader pragmas)
// -----------------------------------------------------------------------------
#if defined(BGAREA_SPINE_PASS_SHADOWCASTER)
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
float3 _LightDirection;
struct AttributesSpine
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
float4 vertexColor : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct VaryingsSpine
{
float4 positionCS : SV_POSITION;
float4 texcoordAndAlpha : TEXCOORD0;
};
float4 GetShadowPositionHClip(float3 positionOS, half3 normalWS)
{
float3 positionWS = TransformObjectToWorld(positionOS);
float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
#if UNITY_REVERSED_Z
positionCS.z = min(positionCS.z, positionCS.w * UNITY_NEAR_CLIP_VALUE);
#else
positionCS.z = max(positionCS.z, positionCS.w * UNITY_NEAR_CLIP_VALUE);
#endif
return positionCS;
}
VaryingsSpine ShadowPassVertexSkeletonLit(AttributesSpine input)
{
VaryingsSpine output;
UNITY_SETUP_INSTANCE_ID(input);
output.texcoordAndAlpha.xyz = float3(TRANSFORM_TEX(input.texcoord, _MainTex).xy, 0);
half3 fixedNormalOS = half3(0, 0, -1);
half3 normalWS = normalize(TransformObjectToWorldNormal(fixedNormalOS));
#ifdef _DOUBLE_SIDED_LIGHTING
half3 viewDirWS = UNITY_MATRIX_V[2].xyz;
half faceSign = sign(dot(viewDirWS, normalWS));
normalWS *= faceSign;
#endif
output.positionCS = GetShadowPositionHClip(input.positionOS.xyz, normalWS);
output.texcoordAndAlpha.a = input.vertexColor.a;
return output;
}
half4 ShadowPassFragmentSkeletonLit(VaryingsSpine input) : SV_TARGET
{
fixed4 texureColor = tex2D(_MainTex, input.texcoordAndAlpha.xy);
clip(texureColor.a * input.texcoordAndAlpha.a - _Cutoff);
return 0;
}
#endif // BGAREA_SPINE_PASS_SHADOWCASTER
// -----------------------------------------------------------------------------
// DepthOnly pass
// -----------------------------------------------------------------------------
#if defined(BGAREA_SPINE_PASS_DEPTHONLY)
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct AttributesSpine
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
float4 vertexColor : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct VaryingsSpine
{
float4 positionCS : SV_POSITION;
float4 texcoordAndAlpha : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
VaryingsSpine DepthOnlyVertex(AttributesSpine input)
{
VaryingsSpine output = (VaryingsSpine)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
output.texcoordAndAlpha.xyz = float3(TRANSFORM_TEX(input.texcoord, _MainTex).xy, 0);
output.texcoordAndAlpha.a = input.vertexColor.a;
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
return output;
}
half4 DepthOnlyFragment(VaryingsSpine input) : SV_TARGET
{
fixed4 texureColor = tex2D(_MainTex, input.texcoordAndAlpha.xy);
clip(texureColor.a * input.texcoordAndAlpha.a - _Cutoff);
return input.positionCS.z;
}
#endif // BGAREA_SPINE_PASS_DEPTHONLY
// -----------------------------------------------------------------------------
// DepthNormals pass
// -----------------------------------------------------------------------------
#if defined(BGAREA_SPINE_PASS_DEPTHNORMALS)
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct AttributesSpine
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
float4 vertexColor : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct VaryingsSpine
{
float3 normalWS : NORMAL;
float4 positionCS : SV_POSITION;
float4 texcoordAndAlpha : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
VaryingsSpine DepthNormalsVertex(AttributesSpine input)
{
VaryingsSpine output = (VaryingsSpine)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
half3 fixedNormal = half3(0, 0, -1);
half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal));
#ifdef _DOUBLE_SIDED_LIGHTING
half3 viewDirWS = UNITY_MATRIX_V[2].xyz;
half faceSign = sign(dot(viewDirWS, normalWS));
normalWS *= faceSign;
#endif
output.normalWS = normalWS;
output.texcoordAndAlpha.xyz = float3(TRANSFORM_TEX(input.texcoord, _MainTex).xy, 0);
output.texcoordAndAlpha.a = input.vertexColor.a;
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
return output;
}
void DepthNormalsFragment(
VaryingsSpine input,
out half4 outNormalWS : SV_Target0
#ifdef _WRITE_RENDERING_LAYERS
, out float4 outRenderingLayers : SV_Target1
#endif
)
{
fixed4 texureColor = tex2D(_MainTex, input.texcoordAndAlpha.xy);
clip(texureColor.a * input.texcoordAndAlpha.a - _Cutoff);
float3 normalWS = input.normalWS;
#if defined(_GBUFFER_NORMALS_OCT)
float2 octNormalWS = PackNormalOctQuadEncode(normalWS);
float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5);
half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS);
outNormalWS = half4(packedNormalWS, 0.0);
#else
outNormalWS = half4(normalWS, 0.0);
#endif
#ifdef _WRITE_RENDERING_LAYERS
uint renderingLayers = BGSpine_GetMeshRenderingLayerBackwardsCompatible();
outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);
#endif
}
#endif // BGAREA_SPINE_PASS_DEPTHNORMALS
// -----------------------------------------------------------------------------
// ForwardLit pass
// -----------------------------------------------------------------------------
#if defined(BGAREA_SPINE_PASS_FORWARDLIT)
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
#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.universal/ShaderLibrary/Shadows.hlsl"
// Unity 6 / URP 17: _FORWARD_PLUS keywords/macros were deprecated in favor of _CLUSTER_LIGHT_LOOP.
// Keep the existing Spine-derived code path compiling by mapping the deprecated macro to the new one.
#if USE_CLUSTER_LIGHT_LOOP && !defined(FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK)
#define FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK CLUSTER_LIGHT_LOOP_SUBTRACTIVE_LIGHT_CHECK
#endif
// Area light include (arealight package)
#include "Packages/com.baddog.rendering.arealight/Shaders/Include/BGAreaLighting.hlsl"
// Receive shadows for main light when requested
#if (defined(_MAIN_LIGHT_SHADOWS) || defined(MAIN_LIGHT_CALCULATE_SHADOWS)) && !defined(_RECEIVE_SHADOWS_OFF)
#define BGAREA_SPINE_RECEIVE_SHADOWS
#endif
// Fog keyword guard (mirrors your modified file)
#if !(defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2))
#undef _FOG
#endif
// Adaptive Probe Volumes (keep behavior close to Spine)
#if !defined(DYNAMICLIGHTMAP_ON) && !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)) && defined(__PROBEVOLUME_HLSL__)
#define BGAREA_SPINE_USE_ADAPTIVE_PROBE_VOLUMES
#endif
struct appdata
{
float3 pos : POSITION;
float3 normal : NORMAL;
half4 color : COLOR;
float2 uv0 : TEXCOORD0;
#if defined(_TINT_BLACK_ON)
float2 tintBlackRG : TEXCOORD1;
float2 tintBlackB : TEXCOORD2;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct VertexOutput
{
half4 color : COLOR0;
#if defined(_FOG)
float3 uv0AndFog : TEXCOORD0;
#else
float2 uv0 : TEXCOORD0;
#endif
float4 pos : SV_POSITION;
#if defined(BGAREA_SPINE_RECEIVE_SHADOWS)
float4 shadowCoord : TEXCOORD1;
half3 shadowedColor : TEXCOORD2;
#endif
// Always provide position/normal for per-pixel area light and (optional) Forward+/APV.
float3 positionWS : TEXCOORD3;
half3 normalWS : TEXCOORD4;
#if defined(_TINT_BLACK_ON)
float3 darkColor : TEXCOORD5;
#endif
#if defined(BGAREA_SPINE_USE_ADAPTIVE_PROBE_VOLUMES) && defined(_ADAPTIVE_PROBE_VOLUMES_PER_PIXEL)
float3 positionCS : TEXCOORD6;
#endif
UNITY_VERTEX_OUTPUT_STEREO
};
#if defined(_FOG)
#define BGSpine_PackedUV0(i) (i.uv0AndFog.xy)
#define BGSpine_PackedFog(i) (i.uv0AndFog.z)
#else
#define BGSpine_PackedUV0(i) (i.uv0.xy)
#endif
half3 BGSpine_ProcessLight(float3 positionWS, half3 normalWS, uint meshRenderingLayers, int lightIndex)
{
Light light = GetAdditionalLight(lightIndex, positionWS);
#ifdef USE_LIGHT_LAYERS
if (!IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
return half3(0, 0, 0);
#endif
half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
return LightingLambert(attenuatedLightColor, light.direction, normalWS);
}
half3 BGSpine_LightweightLightVertexSimplified(float3 positionWS, half3 normalWS, out half3 shadowedColor)
{
Light mainLight = GetMainLight();
half3 attenuatedLightColor = mainLight.color * (mainLight.distanceAttenuation * mainLight.shadowAttenuation);
half3 mainLightColor = LightingLambert(attenuatedLightColor, mainLight.direction, normalWS);
half3 additionalLightColor = half3(0, 0, 0);
// Note: we don't add any lighting in the fragment shader in non-Forward+ case.
#if defined(_ADDITIONAL_LIGHTS) || defined(_ADDITIONAL_LIGHTS_VERTEX)
uint meshRenderingLayers = BGSpine_GetMeshRenderingLayerBackwardsCompatible();
#if USE_FORWARD_PLUS || USE_CLUSTER_LIGHT_LOOP
for (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++)
{
FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
additionalLightColor += BGSpine_ProcessLight(positionWS, normalWS, meshRenderingLayers, (int)lightIndex);
}
#else
uint pixelLightCount = GetAdditionalLightsCount();
for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex)
{
additionalLightColor += BGSpine_ProcessLight(positionWS, normalWS, meshRenderingLayers, (int)lightIndex);
}
#endif
#endif
shadowedColor = additionalLightColor;
return mainLightColor + additionalLightColor;
}
#if defined(_ADDITIONAL_LIGHTS) && (USE_FORWARD_PLUS || USE_CLUSTER_LIGHT_LOOP)
half3 BGSpine_LightweightLightFragmentSimplified(float3 positionWS, float2 positionCS, half3 normalWS, out half3 shadowedColor)
{
half3 additionalLightColor = half3(0, 0, 0);
shadowedColor = half3(0, 0, 0);
// LIGHT_LOOP_BEGIN needs these fields.
InputData inputData;
inputData.positionWS = positionWS;
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(positionCS);
uint meshRenderingLayers = BGSpine_GetMeshRenderingLayerBackwardsCompatible();
uint pixelLightCount = GetAdditionalLightsCount();
LIGHT_LOOP_BEGIN(pixelLightCount)
additionalLightColor += BGSpine_ProcessLight(positionWS, normalWS, meshRenderingLayers, (int)lightIndex);
LIGHT_LOOP_END
return additionalLightColor;
}
#endif
VertexOutput vert(appdata v)
{
VertexOutput o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
half4 color = BGSpine_PMAGammaToTargetSpace(v.color);
float3 positionWS = TransformObjectToWorld(v.pos);
half3 fixedNormal = half3(0, 0, -1);
half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal));
o.pos = TransformWorldToHClip(positionWS);
#if defined(_FOG)
half fogFactor = ComputeFogFactor(o.pos.z);
BGSpine_PackedFog(o) = fogFactor;
#endif
BGSpine_PackedUV0(o) = v.uv0;
#ifdef _DOUBLE_SIDED_LIGHTING
// Match Spine behavior: flip normal based on view direction.
half3 viewDirWS = UNITY_MATRIX_V[2].xyz;
half faceSign = sign(dot(viewDirWS, normalWS));
normalWS *= faceSign;
#endif
o.positionWS = positionWS;
o.normalWS = normalWS;
#if defined(_TINT_BLACK_ON)
color *= _Color;
o.darkColor = BGSpine_GammaToTargetSpace(half3(v.tintBlackRG.r, v.tintBlackRG.g, v.tintBlackB.r)) + (_Black.rgb * v.color.a);
#endif
half3 shadowedColor;
#if !defined(_LIGHT_AFFECTS_ADDITIVE)
if (color.a == 0)
{
o.color = color;
#if defined(BGAREA_SPINE_RECEIVE_SHADOWS)
o.shadowedColor = color.rgb;
o.shadowCoord = float4(0, 0, 0, 0);
#endif
return o;
}
#endif
color.rgb *= BGSpine_LightweightLightVertexSimplified(positionWS, normalWS, shadowedColor);
// Ambient light via SH / APV / Lightmap macro (mirrors Spine; safe even if v.lightmapUV doesn't exist).
half3 vertexSH;
float4 ignoredProbeOcclusion;
#if defined(OUTPUT_SH4)
OUTPUT_SH4(positionWS, normalWS.xyz, GetWorldSpaceNormalizeViewDir(positionWS), vertexSH, ignoredProbeOcclusion);
#else
OUTPUT_SH(normalWS.xyz, vertexSH);
#endif
#if defined(BGAREA_SPINE_USE_ADAPTIVE_PROBE_VOLUMES)
#if !defined(_ADAPTIVE_PROBE_VOLUMES_PER_PIXEL)
half4 shadowMask = 1.0;
half3 bakedGI = SAMPLE_GI(vertexSH,
GetAbsolutePositionWS(positionWS),
normalWS.xyz,
GetWorldSpaceNormalizeViewDir(positionWS),
o.pos.xy,
ignoredProbeOcclusion,
shadowMask) * v.color.a;
#else
half3 bakedGI = half3(0.0, 0.0, 0.0);
o.positionCS = o.pos;
#endif
#else
half3 bakedGI = SAMPLE_GI(v.lightmapUV, vertexSH, normalWS) * v.color.a;
#endif
color.rgb += bakedGI;
o.color = color;
#if defined(BGAREA_SPINE_RECEIVE_SHADOWS)
shadowedColor += bakedGI;
o.shadowedColor = shadowedColor;
VertexPositionInputs vertexInput;
vertexInput.positionWS = positionWS;
vertexInput.positionCS = o.pos;
o.shadowCoord = GetShadowCoord(vertexInput);
#endif
return o;
}
half4 frag(VertexOutput i
#ifdef USE_WRITE_RENDERING_LAYERS
, out float4 outRenderingLayers : SV_Target1
#endif
) : SV_Target0
{
half4 tex = tex2D(_MainTex, BGSpine_PackedUV0(i));
#if !defined(_TINT_BLACK_ON) && defined(_STRAIGHT_ALPHA_INPUT)
tex.rgb *= tex.a;
#endif
// Optional per-pixel APV contribution (mirrors Spine pattern).
#if defined(BGAREA_SPINE_USE_ADAPTIVE_PROBE_VOLUMES) && defined(_ADAPTIVE_PROBE_VOLUMES_PER_PIXEL)
half3 vertexSH;
float4 ignoredProbeOcclusion;
OUTPUT_SH4(i.positionWS, i.normalWS.xyz, GetWorldSpaceNormalizeViewDir(i.positionWS), vertexSH, ignoredProbeOcclusion);
half4 shadowMask = 1.0;
half3 bakedGI = SAMPLE_GI(vertexSH,
GetAbsolutePositionWS(i.positionWS),
i.normalWS.xyz,
GetWorldSpaceNormalizeViewDir(i.positionWS),
i.positionCS.xy,
ignoredProbeOcclusion,
shadowMask) * i.color.a;
i.color.rgb += bakedGI;
#endif
if (i.color.a == 0)
{
#if defined(_TINT_BLACK_ON)
return BGSpine_fragTintedColor(tex, i.darkColor, i.color, _Color.a, _Black.a);
#else
return tex * i.color;
#endif
}
// Forward+/Cluster additional lights are processed in fragment.
#if defined(_ADDITIONAL_LIGHTS) && (USE_FORWARD_PLUS || USE_CLUSTER_LIGHT_LOOP)
half3 shadowedColor;
i.color.rgb += BGSpine_LightweightLightFragmentSimplified(i.positionWS, i.pos.xy, i.normalWS, shadowedColor);
#if defined(BGAREA_SPINE_RECEIVE_SHADOWS)
i.shadowedColor += shadowedColor;
#endif
#endif
// Area light contribution (matches BadDog arealight design: independent loop over compact area buffer).
#if defined(_ENABLE_BG_AREA_LIGHTING)
half3 viewDirWS = GetWorldSpaceNormalizeViewDir(i.positionWS);
half3 areaRadiance = EvaluateAreaLight(
i.positionWS,
i.normalWS,
viewDirWS,
half3(1.0, 1.0, 1.0), // brdfDiffuse: treat as radiance term, will be multiplied by tex later.
half3(0.0, 0.0, 0.0), // brdfSpecular: Spine lit is diffuse-only by default.
1.0, // perceptualRoughness
float3(0.0, 0.0, 0.0), // fresnel0
true // specularHighlightsOff
);
i.color.rgb += areaRadiance;
#if defined(BGAREA_SPINE_RECEIVE_SHADOWS)
i.shadowedColor += areaRadiance;
#endif
#endif
#if defined(BGAREA_SPINE_RECEIVE_SHADOWS)
half shadowAttenuation = MainLightRealtimeShadow(i.shadowCoord);
i.color.rgb = lerp(i.shadowedColor, i.color.rgb, shadowAttenuation);
#endif
#ifdef USE_WRITE_RENDERING_LAYERS
uint renderingLayers = BGSpine_GetMeshRenderingLayerBackwardsCompatible();
outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);
#endif
#if defined(_TINT_BLACK_ON)
half4 pixel = BGSpine_fragTintedColor(tex, i.darkColor, i.color, _Color.a, _Black.a);
#else
half4 pixel = tex * i.color;
#endif
#if defined(_FOG)
pixel.rgb = MixFogColor(pixel.rgb, unity_FogColor.rgb * pixel.a, BGSpine_PackedFog(i));
#endif
return pixel;
}
#endif // BGAREA_SPINE_PASS_FORWARDLIT
#endif // BADDOG_AREA_SPINE_LIT_PASSES_INCLUDED

View File

@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: 1c85c4cb232c5354cb762679c2f757db
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 346790
packageName: Realtime Area Light for URP
packageVersion: 1.3.0
assetPath: Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaSpineLitForwardPass.hlsl
uploadId: 884030

View File

@@ -0,0 +1,257 @@
Shader "BadDog/URP/BGAreaTerrainLit"
{
Properties
{
[HideInInspector] [ToggleUI] _EnableHeightBlend("EnableHeightBlend", Float) = 0.0
_HeightTransition("Height Transition", Range(0, 1.0)) = 0.0
// Layer count is passed down to guide height-blend enable/disable, due
// to the fact that heigh-based blend will be broken with multipass.
[HideInInspector] [PerRendererData] _NumLayersCount ("Total Layer Count", Float) = 1.0
// set by terrain engine
[HideInInspector] _Control("Control (RGBA)", 2D) = "red" {}
[HideInInspector] _Splat3("Layer 3 (A)", 2D) = "grey" {}
[HideInInspector] _Splat2("Layer 2 (B)", 2D) = "grey" {}
[HideInInspector] _Splat1("Layer 1 (G)", 2D) = "grey" {}
[HideInInspector] _Splat0("Layer 0 (R)", 2D) = "grey" {}
[HideInInspector] _Normal3("Normal 3 (A)", 2D) = "bump" {}
[HideInInspector] _Normal2("Normal 2 (B)", 2D) = "bump" {}
[HideInInspector] _Normal1("Normal 1 (G)", 2D) = "bump" {}
[HideInInspector] _Normal0("Normal 0 (R)", 2D) = "bump" {}
[HideInInspector] _Mask3("Mask 3 (A)", 2D) = "grey" {}
[HideInInspector] _Mask2("Mask 2 (B)", 2D) = "grey" {}
[HideInInspector] _Mask1("Mask 1 (G)", 2D) = "grey" {}
[HideInInspector] _Mask0("Mask 0 (R)", 2D) = "grey" {}
[HideInInspector][Gamma] _Metallic0("Metallic 0", Range(0.0, 1.0)) = 0.0
[HideInInspector][Gamma] _Metallic1("Metallic 1", Range(0.0, 1.0)) = 0.0
[HideInInspector][Gamma] _Metallic2("Metallic 2", Range(0.0, 1.0)) = 0.0
[HideInInspector][Gamma] _Metallic3("Metallic 3", Range(0.0, 1.0)) = 0.0
[HideInInspector] _Smoothness0("Smoothness 0", Range(0.0, 1.0)) = 0.5
[HideInInspector] _Smoothness1("Smoothness 1", Range(0.0, 1.0)) = 0.5
[HideInInspector] _Smoothness2("Smoothness 2", Range(0.0, 1.0)) = 0.5
[HideInInspector] _Smoothness3("Smoothness 3", Range(0.0, 1.0)) = 0.5
// used in fallback on old cards & base map
[HideInInspector] _MainTex("BaseMap (RGB)", 2D) = "grey" {}
[HideInInspector] _BaseColor("Main Color", Color) = (1,1,1,1)
[HideInInspector] _TerrainHolesTexture("Holes Map (RGB)", 2D) = "white" {}
[ToggleUI] _EnableInstancedPerPixelNormal("Enable Instanced per-pixel normal", Float) = 1.0
}
HLSLINCLUDE
#pragma multi_compile_fragment __ _ALPHATEST_ON
ENDHLSL
SubShader
{
Tags { "Queue" = "Geometry-100" "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "UniversalMaterialType" = "Lit" "IgnoreProjector" = "False" "TerrainCompatible" = "True"}
Pass
{
Name "ForwardLit"
Tags { "LightMode" = "UniversalForwardOnly" }
HLSLPROGRAM
#pragma target 3.0
#pragma vertex SplatmapVert
#pragma fragment SplatmapFragment
#define _METALLICSPECGLOSSMAP 1
#define _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 1
// -------------------------------------
// Universal Pipeline keywords
#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 _ LIGHTMAP_SHADOW_MIXING
#pragma multi_compile _ SHADOWS_SHADOWMASK
#pragma multi_compile _ _LIGHT_LAYERS
#if UNITY_VERSION >= 60000100
#pragma multi_compile _ _CLUSTER_LIGHT_LOOP
#else
#pragma multi_compile _ _FORWARD_PLUS
#endif
#pragma multi_compile _ EVALUATE_SH_MIXED EVALUATE_SH_VERTEX
#pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
#if UNITY_VERSION >= 60000100
#pragma multi_compile_fragment _ _REFLECTION_PROBE_ATLAS
#endif
#pragma multi_compile_fragment _ _ENABLE_BG_AREA_LIGHTING
#pragma multi_compile_fragment _ _BG_AREALIGHT_SHADOWS_PCF2X2 _BG_AREALIGHT_SHADOWS_TENT5X5 _BG_AREALIGHT_SHADOWS_TENT7X7 _BG_AREALIGHT_SHADOWS_PCSS
#pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
#pragma multi_compile_fragment _ _LIGHT_COOKIES
#if UNITY_VERSION >= 60000000
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#endif
#if UNITY_VERSION >= 60000100
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Fog.hlsl"
#else
#pragma multi_compile_fog
#endif
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ LIGHTMAP_ON
#if UNITY_VERSION >= 60000100
#pragma multi_compile_fragment _ LIGHTMAP_BICUBIC_SAMPLING
#endif
#if UNITY_VERSION >= 60000000
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ProbeVolumeVariants.hlsl"
#endif
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
#pragma multi_compile_fragment _ DEBUG_DISPLAY
#pragma multi_compile_instancing
#pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap
#pragma shader_feature_local_fragment _TERRAIN_BLEND_HEIGHT
#pragma shader_feature_local _NORMALMAP
#pragma shader_feature_local_fragment _MASKMAP
// Sample normal in pixel shader when doing instancing
#pragma shader_feature_local _TERRAIN_INSTANCED_PERPIXEL_NORMAL
#if USE_DYNAMIC_BRANCH_FOG_KEYWORD && SHADER_API_VULKAN && SHADER_API_MOBILE
#define SKIP_SHADOWS_LIGHT_INDEX_CHECK 1
#endif
#include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl"
#include "Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaTerrainLitForwardPasses.hlsl"
ENDHLSL
}
Pass
{
Name "ShadowCaster"
Tags{"LightMode" = "ShadowCaster"}
ZWrite On
ColorMask 0
HLSLPROGRAM
#pragma target 2.0
#pragma vertex ShadowPassVertex
#pragma fragment ShadowPassFragment
#pragma multi_compile_instancing
#pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap
// -------------------------------------
// Universal Pipeline keywords
// This is used during shadow map generation to differentiate between directional and punctual light shadows, as they use different formulas to apply Normal Bias
#pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW
#include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl"
#include "Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaTerrainLitForwardPasses.hlsl"
ENDHLSL
}
Pass
{
Name "DepthOnly"
Tags{"LightMode" = "DepthOnly"}
ZWrite On
ColorMask R
HLSLPROGRAM
#pragma target 2.0
#pragma vertex DepthOnlyVertex
#pragma fragment DepthOnlyFragment
#pragma multi_compile_instancing
#pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap
#include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl"
#include "Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaTerrainLitForwardPasses.hlsl"
ENDHLSL
}
// This pass is used when drawing to a _CameraNormalsTexture texture
Pass
{
Name "DepthNormals"
Tags{"LightMode" = "DepthNormals"}
ZWrite On
HLSLPROGRAM
#pragma target 2.0
#pragma vertex DepthNormalOnlyVertex
#pragma fragment DepthNormalOnlyFragment
#pragma shader_feature_local _NORMALMAP
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"
#pragma multi_compile_instancing
#pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap
#include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitDepthNormalsPass.hlsl"
ENDHLSL
}
Pass
{
Name "SceneSelectionPass"
Tags { "LightMode" = "SceneSelectionPass" }
HLSLPROGRAM
#pragma target 2.0
#pragma vertex DepthOnlyVertex
#pragma fragment DepthOnlyFragment
#pragma multi_compile_instancing
#pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap
#define SCENESELECTIONPASS
#include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl"
#include "Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaTerrainLitForwardPasses.hlsl"
ENDHLSL
}
// This pass it not used during regular rendering, only for lightmap baking.
Pass
{
Name "Meta"
Tags{"LightMode" = "Meta"}
Cull Off
HLSLPROGRAM
#pragma vertex TerrainVertexMeta
#pragma fragment TerrainFragmentMeta
#pragma multi_compile_instancing
#pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap
#pragma shader_feature EDITOR_VISUALIZATION
#define _METALLICSPECGLOSSMAP 1
#define _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 1
#include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitMetaPass.hlsl"
ENDHLSL
}
UsePass "Hidden/Nature/Terrain/Utilities/PICKING"
}
Dependency "AddPassShader" = "Hidden/Universal Render Pipeline/Terrain/Lit (Add Pass)"
Dependency "BaseMapShader" = "Hidden/Universal Render Pipeline/Terrain/Lit (Base Pass)"
Dependency "BaseMapGenShader" = "Hidden/Universal Render Pipeline/Terrain/Lit (Basemap Gen)"
CustomEditor "UnityEditor.Rendering.Universal.TerrainLitShaderGUI"
Fallback "Hidden/Universal Render Pipeline/FallbackError"
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: a2f4843136c5e7c4f945fd88fa9b82de
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 346790
packageName: Realtime Area Light for URP
packageVersion: 1.3.0
assetPath: Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaTerrainLit.shader
uploadId: 884030

View File

@@ -0,0 +1,614 @@
#ifndef BADDOG_AREA_TERRAIN_LIT_PASSES_INCLUDED
#define BADDOG_AREA_TERRAIN_LIT_PASSES_INCLUDED
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl"
// Include Area Light support
#include "Packages/com.baddog.rendering.arealight/Shaders/Include/BGAreaLighting.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 uvMainAndLM : TEXCOORD0; // xy: control, zw: lightmap
#ifndef TERRAIN_SPLAT_BASEPASS
float4 uvSplat01 : TEXCOORD1; // xy: splat0, zw: splat1
float4 uvSplat23 : TEXCOORD2; // xy: splat2, zw: splat3
#endif
#if defined(_NORMALMAP) && !defined(ENABLE_TERRAIN_PERPIXEL_NORMAL)
half4 normal : TEXCOORD3; // xyz: normal, w: viewDir.x
half4 tangent : TEXCOORD4; // xyz: tangent, w: viewDir.y
half4 bitangent : TEXCOORD5; // xyz: bitangent, w: viewDir.z
#else
half3 normal : TEXCOORD3;
half3 vertexSH : TEXCOORD4; // SH
#endif
#ifdef _ADDITIONAL_LIGHTS_VERTEX
half4 fogFactorAndVertexLight : TEXCOORD6; // x: fogFactor, yzw: vertex light
#else
half fogFactor : TEXCOORD6;
#endif
float3 positionWS : TEXCOORD7;
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
float4 shadowCoord : TEXCOORD8;
#endif
#if defined(DYNAMICLIGHTMAP_ON)
float2 dynamicLightmapUV : TEXCOORD9;
#endif
#ifdef USE_APV_PROBE_OCCLUSION
float4 probeOcclusion : TEXCOORD10;
#endif
float4 clipPos : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
void InitializeInputData(Varyings IN, half3 normalTS, out InputData inputData)
{
inputData = (InputData)0;
inputData.positionWS = IN.positionWS;
inputData.positionCS = IN.clipPos;
#if defined(_NORMALMAP) && !defined(ENABLE_TERRAIN_PERPIXEL_NORMAL)
half3 viewDirWS = half3(IN.normal.w, IN.tangent.w, IN.bitangent.w);
inputData.tangentToWorld = half3x3(-IN.tangent.xyz, IN.bitangent.xyz, IN.normal.xyz);
inputData.normalWS = TransformTangentToWorld(normalTS, inputData.tangentToWorld);
half3 SH = 0;
#elif defined(ENABLE_TERRAIN_PERPIXEL_NORMAL)
half3 viewDirWS = GetWorldSpaceNormalizeViewDir(IN.positionWS);
float2 sampleCoords = (IN.uvMainAndLM.xy / _TerrainHeightmapRecipSize.zw + 0.5f) * _TerrainHeightmapRecipSize.xy;
half3 normalWS = TransformObjectToWorldNormal(normalize(SAMPLE_TEXTURE2D(_TerrainNormalmapTexture, sampler_TerrainNormalmapTexture, sampleCoords).rgb * 2 - 1));
half3 tangentWS = cross(GetObjectToWorldMatrix()._13_23_33, normalWS);
inputData.normalWS = TransformTangentToWorld(normalTS, half3x3(-tangentWS, cross(normalWS, tangentWS), normalWS));
half3 SH = IN.vertexSH;
#else
half3 viewDirWS = GetWorldSpaceNormalizeViewDir(IN.positionWS);
inputData.normalWS = IN.normal;
half3 SH = IN.vertexSH;
#endif
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
inputData.viewDirectionWS = viewDirWS;
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
inputData.shadowCoord = IN.shadowCoord;
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
#else
inputData.shadowCoord = float4(0, 0, 0, 0);
#endif
#ifdef _ADDITIONAL_LIGHTS_VERTEX
inputData.fogCoord = InitializeInputDataFog(float4(IN.positionWS, 1.0), IN.fogFactorAndVertexLight.x);
inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw;
#else
inputData.fogCoord = InitializeInputDataFog(float4(IN.positionWS, 1.0), IN.fogFactor);
#endif
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.clipPos);
#if defined(DEBUG_DISPLAY)
#if defined(DYNAMICLIGHTMAP_ON)
inputData.dynamicLightmapUV = IN.dynamicLightmapUV;
#endif
#if defined(LIGHTMAP_ON)
inputData.staticLightmapUV = IN.uvMainAndLM.zw;
#else
inputData.vertexSH = SH;
#endif
#if defined(USE_APV_PROBE_OCCLUSION)
inputData.probeOcclusion = IN.probeOcclusion;
#endif
#endif
}
void InitializeBakedGIData(Varyings IN, inout InputData inputData)
{
#if defined(_NORMALMAP) && !defined(ENABLE_TERRAIN_PERPIXEL_NORMAL)
half3 SH = 0;
#else
half3 SH = IN.vertexSH;
#endif
#if defined(DYNAMICLIGHTMAP_ON)
inputData.bakedGI = SAMPLE_GI(IN.uvMainAndLM.zw, IN.dynamicLightmapUV, SH, inputData.normalWS);
inputData.shadowMask = SAMPLE_SHADOWMASK(IN.uvMainAndLM.zw);
#elif !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
inputData.bakedGI = SAMPLE_GI(SH,
GetAbsolutePositionWS(inputData.positionWS),
inputData.normalWS,
inputData.viewDirectionWS,
inputData.positionCS.xy,
IN.probeOcclusion,
inputData.shadowMask);
#else
inputData.bakedGI = SAMPLE_GI(IN.uvMainAndLM.zw, SH, inputData.normalWS);
inputData.shadowMask = SAMPLE_SHADOWMASK(IN.uvMainAndLM.zw);
#endif
}
#ifndef TERRAIN_SPLAT_BASEPASS
void NormalMapMix(float4 uvSplat01, float4 uvSplat23, inout half4 splatControl, inout half3 mixedNormal)
{
#if defined(_NORMALMAP)
half3 nrm = half(0.0);
nrm += splatControl.r * UnpackNormalScale(SAMPLE_TEXTURE2D(_Normal0, sampler_Normal0, uvSplat01.xy), _NormalScale0);
nrm += splatControl.g * UnpackNormalScale(SAMPLE_TEXTURE2D(_Normal1, sampler_Normal0, uvSplat01.zw), _NormalScale1);
nrm += splatControl.b * UnpackNormalScale(SAMPLE_TEXTURE2D(_Normal2, sampler_Normal0, uvSplat23.xy), _NormalScale2);
nrm += splatControl.a * UnpackNormalScale(SAMPLE_TEXTURE2D(_Normal3, sampler_Normal0, uvSplat23.zw), _NormalScale3);
// avoid risk of NaN when normalizing.
#if !HALF_IS_FLOAT
nrm.z += half(0.01);
#else
nrm.z += 1e-5f;
#endif
mixedNormal = normalize(nrm.xyz);
#endif
}
void SplatmapMix(float4 uvMainAndLM, float4 uvSplat01, float4 uvSplat23, inout half4 splatControl, out half weight, out half4 mixedDiffuse, out half4 defaultSmoothness, inout half3 mixedNormal)
{
half4 diffAlbedo[4];
diffAlbedo[0] = SAMPLE_TEXTURE2D(_Splat0, sampler_Splat0, uvSplat01.xy);
diffAlbedo[1] = SAMPLE_TEXTURE2D(_Splat1, sampler_Splat0, uvSplat01.zw);
diffAlbedo[2] = SAMPLE_TEXTURE2D(_Splat2, sampler_Splat0, uvSplat23.xy);
diffAlbedo[3] = SAMPLE_TEXTURE2D(_Splat3, sampler_Splat0, uvSplat23.zw);
// This might be a bit of a gamble -- the assumption here is that if the diffuseMap has no
// alpha channel, then diffAlbedo[n].a = 1.0 (and _DiffuseHasAlphaN = 0.0)
// Prior to coming in, _SmoothnessN is actually set to max(_DiffuseHasAlphaN, _SmoothnessN)
// This means that if we have an alpha channel, _SmoothnessN is locked to 1.0 and
// otherwise, the true slider value is passed down and diffAlbedo[n].a == 1.0.
defaultSmoothness = half4(diffAlbedo[0].a, diffAlbedo[1].a, diffAlbedo[2].a, diffAlbedo[3].a);
defaultSmoothness *= half4(_Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3);
#ifndef _TERRAIN_BLEND_HEIGHT // density blending
if(_NumLayersCount <= 4)
{
// 20.0 is the number of steps in inputAlphaMask (Density mask. We decided 20 empirically)
half4 opacityAsDensity = saturate((half4(diffAlbedo[0].a, diffAlbedo[1].a, diffAlbedo[2].a, diffAlbedo[3].a) - (1 - splatControl)) * 20.0);
opacityAsDensity += 0.001h * splatControl; // if all weights are zero, default to what the blend mask says
half4 useOpacityAsDensityParam = { _DiffuseRemapScale0.w, _DiffuseRemapScale1.w, _DiffuseRemapScale2.w, _DiffuseRemapScale3.w }; // 1 is off
splatControl = lerp(opacityAsDensity, splatControl, useOpacityAsDensityParam);
}
#endif
// Now that splatControl has changed, we can compute the final weight and normalize
weight = dot(splatControl, 1.0h);
#ifdef TERRAIN_SPLAT_ADDPASS
clip(weight <= 0.005h ? -1.0h : 1.0h);
#endif
#ifndef _TERRAIN_BASEMAP_GEN
// Normalize weights before lighting and restore weights in final modifier functions so that the overal
// lighting result can be correctly weighted.
splatControl /= (weight + HALF_MIN);
#endif
mixedDiffuse = 0.0h;
mixedDiffuse += diffAlbedo[0] * half4(_DiffuseRemapScale0.rgb * splatControl.rrr, 1.0h);
mixedDiffuse += diffAlbedo[1] * half4(_DiffuseRemapScale1.rgb * splatControl.ggg, 1.0h);
mixedDiffuse += diffAlbedo[2] * half4(_DiffuseRemapScale2.rgb * splatControl.bbb, 1.0h);
mixedDiffuse += diffAlbedo[3] * half4(_DiffuseRemapScale3.rgb * splatControl.aaa, 1.0h);
NormalMapMix(uvSplat01, uvSplat23, splatControl, mixedNormal);
}
#endif
#ifdef _TERRAIN_BLEND_HEIGHT
void HeightBasedSplatModify(inout half4 splatControl, in half4 masks[4])
{
// heights are in mask blue channel, we multiply by the splat Control weights to get combined height
half4 splatHeight = half4(masks[0].b, masks[1].b, masks[2].b, masks[3].b) * splatControl.rgba;
half maxHeight = max(splatHeight.r, max(splatHeight.g, max(splatHeight.b, splatHeight.a)));
// Ensure that the transition height is not zero.
half transition = max(_HeightTransition, 1e-5);
// This sets the highest splat to "transition", and everything else to a lower value relative to that, clamping to zero
// Then we clamp this to zero and normalize everything
half4 weightedHeights = splatHeight + transition - maxHeight.xxxx;
weightedHeights = max(0, weightedHeights);
// We need to add an epsilon here for active layers (hence the blendMask again)
// so that at least a layer shows up if everything's too low.
weightedHeights = (weightedHeights + 1e-6) * splatControl;
// Normalize (and clamp to epsilon to keep from dividing by zero)
half sumHeight = max(dot(weightedHeights, half4(1, 1, 1, 1)), 1e-6);
splatControl = weightedHeights / sumHeight.xxxx;
}
#endif
void SplatmapFinalColor(inout half4 color, half fogCoord)
{
color.rgb *= color.a;
#ifndef TERRAIN_GBUFFER // Technically we don't need fogCoord, but it is still passed from the vertex shader.
#ifdef TERRAIN_SPLAT_ADDPASS
color.rgb = MixFogColor(color.rgb, half3(0,0,0), fogCoord);
#else
color.rgb = MixFog(color.rgb, fogCoord);
#endif
#endif
}
void SetupTerrainDebugTextureData(inout InputData inputData, float2 uv)
{
#if defined(DEBUG_DISPLAY)
#if defined(TERRAIN_SPLAT_ADDPASS)
if (_DebugMipInfoMode != DEBUGMIPINFOMODE_NONE)
{
discard; // Layer 4 & beyond are done additively, doesn't make sense for the mipmap streaming debug views -> stop.
}
#endif
switch (_DebugMipMapTerrainTextureMode)
{
case DEBUGMIPMAPMODETERRAINTEXTURE_CONTROL:
SETUP_DEBUG_TEXTURE_DATA_FOR_TEX(inputData, TRANSFORM_TEX(uv, _Control), _Control);
break;
case DEBUGMIPMAPMODETERRAINTEXTURE_LAYER0:
SETUP_DEBUG_TEXTURE_DATA_FOR_TEX(inputData, TRANSFORM_TEX(uv, _Splat0), _Splat0);
break;
case DEBUGMIPMAPMODETERRAINTEXTURE_LAYER1:
SETUP_DEBUG_TEXTURE_DATA_FOR_TEX(inputData, TRANSFORM_TEX(uv, _Splat1), _Splat1);
break;
case DEBUGMIPMAPMODETERRAINTEXTURE_LAYER2:
SETUP_DEBUG_TEXTURE_DATA_FOR_TEX(inputData, TRANSFORM_TEX(uv, _Splat2), _Splat2);
break;
case DEBUGMIPMAPMODETERRAINTEXTURE_LAYER3:
SETUP_DEBUG_TEXTURE_DATA_FOR_TEX(inputData, TRANSFORM_TEX(uv, _Splat3), _Splat3);
break;
default:
break;
}
// TERRAIN_STREAM_INFO: no streamInfo will have been set (no MeshRenderer); set status to "6" to reflect in the debug status that this is a terrain
// also, set the per-material status to "4" to indicate warnings
inputData.streamInfo = TERRAIN_STREAM_INFO;
#endif
}
///////////////////////////////////////////////////////////////////////////////
// Vertex and Fragment functions //
///////////////////////////////////////////////////////////////////////////////
// Used in Standard Terrain shader
Varyings SplatmapVert(Attributes v)
{
Varyings o = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
TerrainInstancing(v.positionOS, v.normalOS, v.texcoord);
VertexPositionInputs Attributes = GetVertexPositionInputs(v.positionOS.xyz);
o.uvMainAndLM.xy = v.texcoord;
o.uvMainAndLM.zw = v.texcoord * unity_LightmapST.xy + unity_LightmapST.zw;
#ifndef TERRAIN_SPLAT_BASEPASS
o.uvSplat01.xy = TRANSFORM_TEX(v.texcoord, _Splat0);
o.uvSplat01.zw = TRANSFORM_TEX(v.texcoord, _Splat1);
o.uvSplat23.xy = TRANSFORM_TEX(v.texcoord, _Splat2);
o.uvSplat23.zw = TRANSFORM_TEX(v.texcoord, _Splat3);
#endif
#if defined(DYNAMICLIGHTMAP_ON)
o.dynamicLightmapUV = v.texcoord * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
#endif
#if defined(_NORMALMAP) && !defined(ENABLE_TERRAIN_PERPIXEL_NORMAL)
half3 viewDirWS = GetWorldSpaceNormalizeViewDir(Attributes.positionWS);
float4 vertexTangent = float4(cross(float3(0, 0, 1), v.normalOS), 1.0);
VertexNormalInputs normalInput = GetVertexNormalInputs(v.normalOS, vertexTangent);
o.normal = half4(normalInput.normalWS, viewDirWS.x);
o.tangent = half4(normalInput.tangentWS, viewDirWS.y);
o.bitangent = half4(normalInput.bitangentWS, viewDirWS.z);
#else
o.normal = TransformObjectToWorldNormal(v.normalOS);
#if UNITY_VERSION >= 60000000
OUTPUT_SH4(Attributes.positionWS, o.normal.xyz, GetWorldSpaceNormalizeViewDir(Attributes.positionWS), o.vertexSH, o.probeOcclusion);
#else
OUTPUT_SH(o.normal.xyz, o.vertexSH);
#endif
#endif
half fogFactor = 0;
#if !defined(_FOG_FRAGMENT)
fogFactor = ComputeFogFactor(Attributes.positionCS.z);
#endif
#ifdef _ADDITIONAL_LIGHTS_VERTEX
o.fogFactorAndVertexLight.x = fogFactor;
o.fogFactorAndVertexLight.yzw = VertexLighting(Attributes.positionWS, o.normal.xyz);
#else
o.fogFactor = fogFactor;
#endif
o.positionWS = Attributes.positionWS;
o.clipPos = Attributes.positionCS;
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
o.shadowCoord = GetShadowCoord(Attributes);
#endif
return o;
}
void ComputeMasks(out half4 masks[4], half4 hasMask, Varyings IN)
{
masks[0] = 0.5h;
masks[1] = 0.5h;
masks[2] = 0.5h;
masks[3] = 0.5h;
#ifdef _MASKMAP
masks[0] = lerp(masks[0], SAMPLE_TEXTURE2D(_Mask0, sampler_Mask0, IN.uvSplat01.xy), hasMask.x);
masks[1] = lerp(masks[1], SAMPLE_TEXTURE2D(_Mask1, sampler_Mask0, IN.uvSplat01.zw), hasMask.y);
masks[2] = lerp(masks[2], SAMPLE_TEXTURE2D(_Mask2, sampler_Mask0, IN.uvSplat23.xy), hasMask.z);
masks[3] = lerp(masks[3], SAMPLE_TEXTURE2D(_Mask3, sampler_Mask0, IN.uvSplat23.zw), hasMask.w);
#endif
masks[0] *= _MaskMapRemapScale0.rgba;
masks[0] += _MaskMapRemapOffset0.rgba;
masks[1] *= _MaskMapRemapScale1.rgba;
masks[1] += _MaskMapRemapOffset1.rgba;
masks[2] *= _MaskMapRemapScale2.rgba;
masks[2] += _MaskMapRemapOffset2.rgba;
masks[3] *= _MaskMapRemapScale3.rgba;
masks[3] += _MaskMapRemapOffset3.rgba;
}
// Used in Standard Terrain shader with Area Light support
#ifdef TERRAIN_GBUFFER
GBufferFragOutput SplatmapFragment(Varyings IN)
#else
void SplatmapFragment(
Varyings IN
, out half4 outColor : SV_Target0
#ifdef _WRITE_RENDERING_LAYERS
, out uint outRenderingLayers : SV_Target1
#endif
)
#endif
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
#ifdef _ALPHATEST_ON
ClipHoles(IN.uvMainAndLM.xy);
#endif
half3 normalTS = half3(0.0h, 0.0h, 1.0h);
#ifdef TERRAIN_SPLAT_BASEPASS
half3 albedo = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uvMainAndLM.xy).rgb;
half smoothness = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uvMainAndLM.xy).a;
half metallic = SAMPLE_TEXTURE2D(_MetallicTex, sampler_MetallicTex, IN.uvMainAndLM.xy).r;
half alpha = 1;
half occlusion = 1;
#else
half4 hasMask = half4(_LayerHasMask0, _LayerHasMask1, _LayerHasMask2, _LayerHasMask3);
half4 masks[4];
ComputeMasks(masks, hasMask, IN);
float2 splatUV = (IN.uvMainAndLM.xy * (_Control_TexelSize.zw - 1.0f) + 0.5f) * _Control_TexelSize.xy;
half4 splatControl = SAMPLE_TEXTURE2D(_Control, sampler_Control, splatUV);
half alpha = dot(splatControl, 1.0h);
#ifdef _TERRAIN_BLEND_HEIGHT
// disable Height Based blend when there are more than 4 layers (multi-pass breaks the normalization)
if (_NumLayersCount <= 4)
HeightBasedSplatModify(splatControl, masks);
#endif
half weight;
half4 mixedDiffuse;
half4 defaultSmoothness;
SplatmapMix(IN.uvMainAndLM, IN.uvSplat01, IN.uvSplat23, splatControl, weight, mixedDiffuse, defaultSmoothness, normalTS);
half3 albedo = mixedDiffuse.rgb;
half4 defaultMetallic = half4(_Metallic0, _Metallic1, _Metallic2, _Metallic3);
half4 defaultOcclusion = half4(_MaskMapRemapScale0.g, _MaskMapRemapScale1.g, _MaskMapRemapScale2.g, _MaskMapRemapScale3.g) +
half4(_MaskMapRemapOffset0.g, _MaskMapRemapOffset1.g, _MaskMapRemapOffset2.g, _MaskMapRemapOffset3.g);
half4 maskSmoothness = half4(masks[0].a, masks[1].a, masks[2].a, masks[3].a);
defaultSmoothness = lerp(defaultSmoothness, maskSmoothness, hasMask);
half smoothness = dot(splatControl, defaultSmoothness);
half4 maskMetallic = half4(masks[0].r, masks[1].r, masks[2].r, masks[3].r);
defaultMetallic = lerp(defaultMetallic, maskMetallic, hasMask);
half metallic = dot(splatControl, defaultMetallic);
half4 maskOcclusion = half4(masks[0].g, masks[1].g, masks[2].g, masks[3].g);
defaultOcclusion = lerp(defaultOcclusion, maskOcclusion, hasMask);
half occlusion = dot(splatControl, defaultOcclusion);
#endif
InputData inputData;
InitializeInputData(IN, normalTS, inputData);
SetupTerrainDebugTextureData(inputData, IN.uvMainAndLM.xy);
#if defined(_DBUFFER)
half3 specular = half3(0.0h, 0.0h, 0.0h);
ApplyDecal(IN.clipPos,
albedo,
specular,
inputData.normalWS,
metallic,
occlusion,
smoothness);
#endif
InitializeBakedGIData(IN, inputData);
#ifdef TERRAIN_GBUFFER
BRDFData brdfData;
InitializeBRDFData(albedo, metallic, /* specular */ half3(0.0h, 0.0h, 0.0h), smoothness, alpha, brdfData);
// Baked lighting.
half4 color;
Light mainLight = GetMainLight(inputData.shadowCoord, inputData.positionWS, inputData.shadowMask);
MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI, inputData.shadowMask);
color.rgb = GlobalIllumination(brdfData, (BRDFData)0, 0, inputData.bakedGI, occlusion, inputData.positionWS,
inputData.normalWS, inputData.viewDirectionWS, inputData.normalizedScreenSpaceUV);
color.a = alpha;
SplatmapFinalColor(color, inputData.fogCoord);
// Dynamic lighting: emulate SplatmapFinalColor() by scaling gbuffer material properties. This will not give the same results
// as forward renderer because we apply blending pre-lighting instead of post-lighting.
// Blending of smoothness and normals is also not correct but close enough?
brdfData.albedo.rgb *= alpha;
brdfData.diffuse.rgb *= alpha;
brdfData.specular.rgb *= alpha;
brdfData.reflectivity *= alpha;
inputData.normalWS = inputData.normalWS * alpha;
smoothness *= alpha;
return PackGBuffersBRDFData(brdfData, inputData, smoothness, color.rgb, occlusion);
#else
// Standard URP PBR lighting calculation
half4 color = UniversalFragmentPBR(inputData, albedo, metallic, /* specular */ half3(0.0h, 0.0h, 0.0h), smoothness, occlusion, /* emission */ half3(0, 0, 0), alpha);
// Additional Area Light (only when enabled)
#if defined(_ENABLE_BG_AREA_LIGHTING)
// Create SurfaceData for area light evaluation
SurfaceData surfaceData;
surfaceData.albedo = albedo;
surfaceData.metallic = metallic;
surfaceData.specular = half3(0.0h, 0.0h, 0.0h);
surfaceData.smoothness = smoothness;
surfaceData.occlusion = occlusion;
surfaceData.emission = half3(0, 0, 0);
surfaceData.alpha = alpha;
surfaceData.normalTS = normalTS;
surfaceData.clearCoatMask = 0.0h;
surfaceData.clearCoatSmoothness = 0.0h;
color.rgb += EvaluateAreaLight(inputData, surfaceData);
#endif
SplatmapFinalColor(color, inputData.fogCoord);
outColor = half4(color.rgb, 1.0h);
#ifdef _WRITE_RENDERING_LAYERS
outRenderingLayers = EncodeMeshRenderingLayer();
#endif
#endif
}
// Shadow pass
// Shadow Casting Light geometric parameters. These variables are used when applying the shadow Normal Bias and are set by UnityEngine.Rendering.Universal.ShadowUtils.SetupShadowCasterConstantBuffer in com.unity.render-pipelines.universal/Runtime/ShadowUtils.cs
// For Directional lights, _LightDirection is used when applying shadow Normal Bias.
// For Spot lights and Point lights, _LightPosition is used to compute the actual light direction because it is different at each shadow caster geometry vertex.
float3 _LightDirection;
float3 _LightPosition;
struct AttributesLean
{
float4 position : POSITION;
float3 normalOS : NORMAL;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct VaryingsLean
{
float4 clipPos : SV_POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
VaryingsLean ShadowPassVertex(AttributesLean v)
{
VaryingsLean o = (VaryingsLean)0;
UNITY_SETUP_INSTANCE_ID(v);
TerrainInstancing(v.position, v.normalOS, v.texcoord);
float3 positionWS = TransformObjectToWorld(v.position.xyz);
float3 normalWS = TransformObjectToWorldNormal(v.normalOS);
#if _CASTING_PUNCTUAL_LIGHT_SHADOW
float3 lightDirectionWS = normalize(_LightPosition - positionWS);
#else
float3 lightDirectionWS = _LightDirection;
#endif
float4 clipPos = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, lightDirectionWS));
#if UNITY_REVERSED_Z
clipPos.z = min(clipPos.z, UNITY_NEAR_CLIP_VALUE);
#else
clipPos.z = max(clipPos.z, UNITY_NEAR_CLIP_VALUE);
#endif
o.clipPos = clipPos;
o.texcoord = v.texcoord;
return o;
}
half4 ShadowPassFragment(VaryingsLean IN) : SV_TARGET
{
#ifdef _ALPHATEST_ON
ClipHoles(IN.texcoord);
#endif
return 0;
}
// Depth pass
VaryingsLean DepthOnlyVertex(AttributesLean v)
{
VaryingsLean o = (VaryingsLean)0;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
TerrainInstancing(v.position, v.normalOS);
o.clipPos = TransformObjectToHClip(v.position.xyz);
o.texcoord = v.texcoord;
return o;
}
half4 DepthOnlyFragment(VaryingsLean IN) : SV_TARGET
{
#ifdef _ALPHATEST_ON
ClipHoles(IN.texcoord);
#endif
#ifdef SCENESELECTIONPASS
// We use depth prepass for scene selection in the editor, this code allow to output the outline correctly
return half4(_ObjectId, _PassValue, 1.0, 1.0);
#endif
return IN.clipPos.z;
}
#endif

View File

@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: f0bd0b7090b9f174e9b5acef11b36f94
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 346790
packageName: Realtime Area Light for URP
packageVersion: 1.3.0
assetPath: Packages/com.baddog.rendering.arealight/Shaders/BadDog/BGAreaTerrainLitForwardPasses.hlsl
uploadId: 884030