Shader "CTI/URP Billboard" { Properties { [Header(Surface Inputs)] [Space(5)] _HueVariation ("Color Variation", Color) = (0.9,0.5,0.0,0.1) [NoScaleOffset] _BaseMap ("Albedo (RGB) Smoothness (A)", 2D) = "white" {} _Cutoff ("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 _AlphaLeak ("Alpha Leak Suppression", Range(0.5,1.0)) = 0.6 _Smoothness ("Smoothness", Range(0.0, 1.0)) = 1.0 _SpecColor ("Specular", Color) = (0.2, 0.2, 0.2) _OcclusionStrength ("Occlusion Strength", Range(0,1)) = 1 [Space(5)] [Toggle(_NORMALMAP)] _ApplyNormal ("Enable Normal Map", Float) = 1.0 [NoScaleOffset] _BumpSpecMap (" Normal (AG) Translucency(R) Smoothness(B)", 2D) = "white" {} _BumpScale (" Normal Scale", Float) = 1.0 [Header(Transmission)] [Space(5)] [CTI_LWRPTransDrawer] _Translucency ("Strength (X) Power (Y)", Vector) = (1, 8, 0, 0) [Header(Wind)] [Space(3)] _WindStrength ("Wind Strength", Float) = 1.0 [Header(Ambient)] [Space(5)] _AmbientReflection ("Ambient Reflection", Range(0, 1)) = 1 [Header(Legacy)] [Space(5)] _BillboardScale ("Billboard Scale", Float) = 2 } SubShader { Tags { "RenderPipeline" = "LightweightPipeline" "RenderType" = "Opaque" "Queue"="AlphaTest" "IgnoreProjector" = "True" } // Base ----------------------------------------------------- Pass { Name "ForwardLit" Tags {"LightMode" = "LightweightForward"} ZWrite On // LWRP billboardNormal Orientation is flipped? Cull Off //AlphaToMask On 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 #define _ALPHATEST_ON 1 #pragma shader_feature _NORMALMAP #define CTIBILLBOARD #define _SPECULAR_SETUP // ------------------------------------- // Lightweight Pipeline keywords #pragma multi_compile _ _MAIN_LIGHT_SHADOWS #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS #pragma multi_compile _ _SHADOWS_SOFT #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE // ------------------------------------- // Unity defined keywords //#pragma multi_compile _ DIRLIGHTMAP_COMBINED //#pragma multi_compile _ LIGHTMAP_ON #pragma multi_compile_fog #pragma multi_compile _ LOD_FADE_CROSSFADE //-------------------------------------- // GPU Instancing #pragma multi_compile_instancing #include "Includes/CTI URP Inputs.hlsl" #include "Includes/CTI URP Billboard.hlsl" #include "Includes/CTI URP Lighting.hlsl" #pragma vertex LitPassVertex #pragma fragment LitPassFragment /// -------- void InitializeInputData(CTIVertexBBOutput input, half3 normalTS, out InputData inputData) { inputData = (InputData)0; #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR) inputData.positionWS = input.positionWS; #endif #ifdef _NORMALMAP half3 viewDirWS = half3(input.normalWS.w, input.tangentWS.w, input.bitangentWS.w); inputData.normalWS = TransformTangentToWorld(normalTS, half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz)); #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 = input.fogFactorAndVertexLight.x; inputData.vertexLighting = input.fogFactorAndVertexLight.yzw; inputData.bakedGI = SAMPLE_GI(input.texcoord1, input.vertexSH, inputData.normalWS); } CTIVertexBBOutput LitPassVertex(CTIVertexBBInput input) { CTIVertexBBOutput output = (CTIVertexBBOutput)0; UNITY_SETUP_INSTANCE_ID(input); UNITY_TRANSFER_INSTANCE_ID(input, output); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); CTIBillboardVert(input, 0); // Set color variation output.colorVariation = input.color.r; VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz); VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS); half3 viewDirWS = GetCameraPositionWS() - vertexInput.positionWS; half3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS); half fogFactor = ComputeFogFactor(vertexInput.positionCS.z); output.uv.xy = input.texcoord.xy; #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 = NormalizeNormalPerVertex(normalInput.normalWS); output.viewDirWS = viewDirWS; #endif //OUTPUT_LIGHTMAP_UV(input.lightmapUV, unity_LightmapST, output.lightmapUV); OUTPUT_SH(output.normalWS.xyz, output.vertexSH); output.fogFactorAndVertexLight = half4(fogFactor, vertexLight); #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; } half4 LitPassFragment(CTIVertexBBOutput IN) : SV_Target { UNITY_SETUP_INSTANCE_ID(IN); UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); #if defined(LOD_FADE_CROSSFADE) && !defined(SHADER_API_GLES) LODDitheringTransition(IN.positionCS.xyz, unity_LODFade.x); #endif SurfaceDescriptionLeaves surfaceData; // Get the surface description / defined in "Includes/CTI LWRP Inputs.hlsl" InitializeStandardLitSurfaceData(IN.colorVariation, IN.uv.xy, surfaceData); // Add ambient occlusion from alpha surfaceData.occlusion = (surfaceData.occlusion <= _AlphaLeak) ? 1 : surfaceData.occlusion; // Eliminate alpha leaking into ao surfaceData.occlusion = lerp(1, surfaceData.occlusion * 2 - 1, _OcclusionStrength); InputData inputData; InitializeInputData(IN, surfaceData.normalTS, inputData); // Apply lighting //half4 color = LightweightFragmentPBR(inputData, surfaceData.albedo, surfaceData.metallic, surfaceData.specular, surfaceData.smoothness, surfaceData.occlusion, surfaceData.emission, surfaceData.alpha); half4 color = CTILightweightFragmentPBR( inputData, surfaceData.albedo, surfaceData.metallic, surfaceData.specular, surfaceData.smoothness, surfaceData.occlusion, surfaceData.emission, surfaceData.alpha, _Translucency * half3(surfaceData.translucency, 1, 1), _AmbientReflection); // Add fog color.rgb = MixFog(color.rgb, inputData.fogCoord); return color; } ENDHLSL } // Shadows ----------------------------------------------------- Pass { Name "ShadowCaster" Tags{"LightMode" = "ShadowCaster"} ZWrite On 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 #define _ALPHATEST_ON 1 #define CTIBILLBOARD //-------------------------------------- // GPU Instancing #pragma multi_compile_instancing #pragma multi_compile _ LOD_FADE_CROSSFADE #pragma vertex ShadowPassVertex #pragma fragment ShadowPassFragment #include "Includes/CTI URP Inputs.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" #include "Includes/CTI URP Billboard.hlsl" float3 _LightDirection; CTIVertexBBOutput ShadowPassVertex(CTIVertexBBInput input) { CTIVertexBBOutput output = (CTIVertexBBOutput)0; UNITY_SETUP_INSTANCE_ID(input); UNITY_TRANSFER_INSTANCE_ID(input, output); CTIBillboardVert(input, _LightDirection); output.uv = input.texcoord.xy; float3 positionWS = TransformObjectToWorld(input.positionOS.xyz); float3 normalWS = TransformObjectToWorldDir(input.normalOS); output.positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection)); #if UNITY_REVERSED_Z output.positionCS.z = min(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE); #else output.positionCS.z = max(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE); #endif return output; } half4 ShadowPassFragment(CTIVertexOutput IN) : SV_TARGET { #if defined(LOD_FADE_CROSSFADE) && !defined(SHADER_API_GLES) LODDitheringTransition(IN.positionCS.xyz, unity_LODFade.x); #endif half alpha = SampleAlbedoAlpha(IN.uv.xy, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a; clip(alpha - _Cutoff); return 1; } ENDHLSL } // Depth ----------------------------------------------------- Pass { Name "DepthOnly" Tags {"LightMode" = "DepthOnly"} ZWrite On ColorMask 0 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 #pragma vertex DepthOnlyVertex #pragma fragment DepthOnlyFragment // ------------------------------------- // Material Keywords #define _ALPHATEST_ON 1 #define CTIBILLBOARD //-------------------------------------- // GPU Instancing #pragma multi_compile_instancing #pragma multi_compile _ LOD_FADE_CROSSFADE #define DEPTHONLYPASS #include "Includes/CTI URP Inputs.hlsl" #include "Includes/CTI URP Billboard.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" CTIVertexBBOutput DepthOnlyVertex(CTIVertexBBInput input) { CTIVertexBBOutput output = (CTIVertexBBOutput)0; UNITY_SETUP_INSTANCE_ID(input); UNITY_TRANSFER_INSTANCE_ID(input, output); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); CTIBillboardVert(input, 0); VertexPositionInputs vertexPosition = GetVertexPositionInputs(input.positionOS.xyz); output.uv.xy = input.texcoord.xy; output.positionCS = vertexPosition.positionCS; return output; } half4 DepthOnlyFragment(CTIVertexBBOutput IN) : SV_TARGET { UNITY_SETUP_INSTANCE_ID(IN); UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); #if defined(LOD_FADE_CROSSFADE) && !defined(SHADER_API_GLES) // enable dithering LOD transition if user select CrossFade transition in LOD group LODDitheringTransition(IN.positionCS.xyz, unity_LODFade.x); #endif half alpha = SampleAlbedoAlpha(IN.uv.xy, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a; clip(alpha - _Cutoff); return 1; } ENDHLSL } // Meta ----------------------------------------------------- } FallBack "Hidden/InternalErrorShader" }