Files
beyond/Assets/ThirdParty/Lux URP Essentials/Shaders/Tree Creator/Lux URP Tree Creator Leaves.shader
2024-11-20 15:21:28 +01:00

242 lines
9.3 KiB
Plaintext

// Shader uses custom editor to set double sided GI
// Needs _Culling to be set properly
Shader "Lux URP/Nature/Tree Creator Leaves"
{
Properties
{
[Header(Surface Inputs)]
[Space(5)]
_Color ("Main Color", Color) = (1,1,1,1)
[PowerSlider(5.0)] _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
_MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0.0, 1.0)) = 0.5
[Space(5)]
[NoScaleOffset]
_BumpMap ("Normalmap", 2D) = "bump" {}
[NoScaleOffset]
_GlossMap ("Gloss (A)", 2D) = "black" {}
[NoScaleOffset]
_TranslucencyMap ("Translucency (A)", 2D) = "white" {}
[HideInInspector] _TreeInstanceColor ("TreeInstanceColor", Vector) = (1,1,1,1)
[HideInInspector] _TreeInstanceScale ("TreeInstanceScale", Vector) = (1,1,1,1)
[HideInInspector] _SquashAmount ("Squash", Float) = 1
// Lightmapper and outline selection shader need _MainTex, _Color and _Cutoff
}
SubShader
{
Tags
{
"RenderPipeline" = "UniversalPipeline"
"RenderType" = "TransparentCutout"
"IgnoreProjector" = "True"
"Queue"="AlphaTest"
}
LOD 100
Pass
{
Name "ForwardLit"
Tags{"LightMode" = "UniversalForward"}
ZWrite On
Cull Back
HLSLPROGRAM
// Required to compile gles 2.0 with standard SRP library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
// Shader target needs to be 3.0 due to tex2Dlod in the vertex shader and VFACE
#pragma target 2.0
// -------------------------------------
// Material Keywords
// #define _SPECULAR_SETUP 1
#define DUMMYSHADER
#define _ALPHATEST_ON
#define _NORMALMAP
// -------------------------------------
// 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
// Trees do not support lightmapping
// #pragma multi_compile _ DIRLIGHTMAP_COMBINED
// #pragma multi_compile _ LIGHTMAP_ON
// #pragma multi_compile_fog
// Include base inputs and all other needed "base" includes
#include "Includes/Lux URP Tree Creator Inputs.hlsl"
#include "Includes/Lux URP Tree Creator Library.hlsl"
#pragma vertex LitPassVertex
#pragma fragment LitPassFragment
//--------------------------------------
// Vertex shader
VertexOutput LitPassVertex(VertexInput input)
{
VertexOutput output = (VertexOutput)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
TreeVertLeaf(input);
VertexPositionInputs vertexInput; //
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 = TRANSFORM_TEX(input.texcoord, _MainTex);
output.normalWS = half4(normalInput.normalWS, viewDirWS.x);
output.tangentWS = half4(normalInput.tangentWS, viewDirWS.y);
output.bitangentWS = half4(normalInput.bitangentWS, viewDirWS.z);
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;
output.color = input.color;
#if defined(BILLBOARD_FACE_CAMERA_POS) && defined(_ENABLEDITHERING)
output.screenPos = ComputeScreenPos(output.positionCS);
#endif
return output;
}
//--------------------------------------
// Fragment shader and functions
inline void InitializeSurfaceData(
float2 uv,
out SurfaceDescription outSurfaceData)
{
half4 albedoAlpha = SampleAlbedoAlpha(uv.xy, TEXTURE2D_ARGS(_MainTex, sampler_MainTex));
outSurfaceData.alpha = Alpha(albedoAlpha.a, half4(1,1,1,1), _Cutoff);
outSurfaceData.albedo = albedoAlpha.rgb; // * _Color.rgb;
// Normal
outSurfaceData.normalTS = SampleNormal(uv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), 5);
outSurfaceData.specular = _Shininess;
outSurfaceData.occlusion = 1;
// Transmission
half4 maskSample = SAMPLE_TEXTURE2D(_TranslucencyMap, sampler_TranslucencyMap, uv);
outSurfaceData.translucency = maskSample.b;
// Gloss
outSurfaceData.gloss = SAMPLE_TEXTURE2D(_GlossMap, sampler_GlossMap, uv).a;
}
void InitializeInputData(VertexOutput input, half3 normalTS, out InputData inputData)
{
inputData = (InputData)0;
#if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
inputData.positionWS = input.positionWS;
#endif
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));
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.lightmapUV, input.vertexSH, inputData.normalWS);
}
half4 LitPassFragment(VertexOutput input) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
// Get the surface description
SurfaceDescription surfaceData;
InitializeSurfaceData(input.uv, surfaceData);
// Apply tree color and occlusion
surfaceData.albedo *= input.color.rgb;
surfaceData.occlusion = input.color.a;
// Prepare surface data (like bring normal into world space and get missing inputs like gi)
InputData inputData;
InitializeInputData(input, surfaceData.normalTS, inputData);
// Apply lighting
half4 color = LuxURPTreeLeafFragmentPBR (
inputData,
surfaceData.albedo,
surfaceData.specular,
surfaceData.gloss,
surfaceData.occlusion,
surfaceData.alpha,
half2(surfaceData.translucency, _TranslucencyViewDependency),
_TranslucencyColor,
UNITY_ACCESS_INSTANCED_PROP(Props, _SquashAmount),
1.0h // ShadowStrength
);
// Add fog
color.rgb = MixFog(color.rgb, inputData.fogCoord);
return color;
}
ENDHLSL
}
// End Passes -----------------------------------------------------
}
FallBack "Hidden/InternalErrorShader"
Dependency "OptimizedShader" = "Lux URP/Nature/Tree Creator Leaves Optimized"
}