Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CustomLit1.shader:
- Shader "Universal Render Pipeline/CustomLit1"
- {
- Properties
- {
- // Specular vs Metallic workflow
- [HideInInspector] _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
- _GlossMapScale("Smoothness Scale", Range(0.0, 1.0)) = 1.0
- _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
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++=+++_+_+++++++++ЭТО ПРОПЕРТИ КОТОРЫЕ НУЖНЫ ДЛЯ ЛОГИКИ
- _Tint("Tint", Color) = (1,1,1,1)
- _wind_dir("Wind Direction", Vector) = (0.5,0.05,0.5,0)
- _wind_size("Wind Wave Size", range(5,50)) = 15
- _tree_sway_stutter_influence("Tree Sway Stutter Influence", range(0,1)) = 0.2
- _tree_sway_stutter("Tree Sway Stutter", range(0,10)) = 1.5
- _tree_sway_speed("Tree Sway Speed", range(0,10)) = 1
- _tree_sway_disp("Tree Sway Displacement", range(0,1)) = 0.3
- _branches_disp("Branches Displacement", range(0,0.5)) = 0.3
- _leaves_wiggle_disp("Leaves Wiggle Displacement", float) = 0.07
- _leaves_wiggle_speed("Leaves Wiggle Speed", float) = 0.01
- _r_influence("Red Vertex Influence", range(0,1)) = 1
- _b_influence("Blue Vertex Influence", range(0,1)) = 1
- //========================================================================================
- [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
- [HideInInspector] _Surface("__surface", Float) = 0.0
- [HideInInspector] _Blend("__blend", Float) = 0.0
- [HideInInspector] _AlphaClip("__clip", Float) = 0.0
- [HideInInspector] _SrcBlend("__src", Float) = 1.0
- [HideInInspector] _DstBlend("__dst", Float) = 0.0
- [HideInInspector] _ZWrite("__zw", Float) = 1.0
- [HideInInspector] _Cull("__cull", Float) = 2.0
- _ReceiveShadows("Receive Shadows", Float) = 1.0
- // Editmode props
- [HideInInspector] _QueueOffset("Queue offset", Float) = 0.0
- // ObsoleteProperties
- [HideInInspector] _MainTex("BaseMap", 2D) = "white" {}
- [HideInInspector] _Color("Base Color", Color) = (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
- {
- // Universal Pipeline tag is required. If Universal render pipeline is not set in the graphics settings
- // this Subshader will fail. One can add a subshader below or fallback to Standard built-in to make this
- // material work with both Universal Render Pipeline and Builtin Unity Pipeline
- Tags{"RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "UniversalMaterialType" = "Lit" "IgnoreProjector" = "True" "ShaderModel" = "4.5"}
- LOD 300
- // --------------------------------------------------------------------------------------------------------------------------------------вот тут листва исчезает если удалить
- // Forward pass. Shades all light in a single pass. GI + emission + Fog
- 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" = "UniversalForward"}
- Blend[_SrcBlend][_DstBlend]
- ZWrite[_ZWrite]
- Cull[_Cull]
- HLSLPROGRAM
- #pragma exclude_renderers gles gles3 glcore
- #pragma target 4.5
- // -------------------------------------
- // Material Keywords
- #pragma shader_feature_local _NORMALMAP
- #pragma shader_feature_local_fragment _ALPHATEST_ON
- #pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_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 _PARALLAXMAP
- #pragma shader_feature_local _ _DETAIL_MULX2 _DETAIL_SCALED
- #pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
- #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
- #pragma shader_feature_local_fragment _SPECULAR_SETUP
- #pragma shader_feature_local _RECEIVE_SHADOWS_OFF
- // -------------------------------------
- // Universal 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_fragment _ _ADDITIONAL_LIGHT_SHADOWS
- #pragma multi_compile_fragment _ _SHADOWS_SOFT
- #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
- #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
- #pragma multi_compile _ SHADOWS_SHADOWMASK
- // -------------------------------------
- // 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
- #pragma multi_compile _ DOTS_INSTANCING_ON
- #pragma vertex LitPassVertex
- #pragma vertex vert
- #pragma fragment LitPassFragment
- #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
- #include "CustomLitForwardPass.hlsl"
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
- ENDHLSL
- }
- Pass
- {
- Name "ShadowCaster"
- Tags{"LightMode" = "ShadowCaster"}
- ZWrite On
- ZTest LEqual
- ColorMask 0
- Cull[_Cull]
- HLSLPROGRAM
- #pragma exclude_renderers gles gles3 glcore
- #pragma target 4.5
- // -------------------------------------
- // Material Keywords
- #pragma shader_feature_local_fragment _ALPHATEST_ON
- #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
- //--------------------------------------
- // GPU Instancing
- #pragma multi_compile_instancing
- #pragma multi_compile _ DOTS_INSTANCING_ON
- #pragma vertex ShadowPassVertex
- #pragma vertex vert
- #pragma fragment ShadowPassFragment
- #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
- #include "CustomShadowCasterPass.hlsl"
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
- ENDHLSL
- }
- // This pass it not used during regular rendering, only for lightmap baking.
- }
- FallBack "Hidden/Universal Render Pipeline/FallbackError"
- CustomEditor "UnityEditor.Rendering.Universal.ShaderGUI.LitShader"
- }
- ==========================================================================================================================
- ==========================================================================================================================
- ==========================================================================================================================
- ==========================================================================================================================
- ==========================================================================================================================
- CustomLitForwardPass.hlsl:
- #ifndef UNIVERSAL_FORWARD_LIT_PASS_INCLUDED
- #define UNIVERSAL_FORWARD_LIT_PASS_INCLUDED
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
- // GLES2 has limited amount of interpolators
- #if defined(_PARALLAXMAP) && !defined(SHADER_API_GLES)
- #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
- // keep this file in sync with LitGBufferPass.hlsl
- struct Attributes
- {
- float4 positionOS : POSITION;
- float3 normalOS : NORMAL;
- float4 tangentOS : TANGENT;
- float2 texcoord : TEXCOORD0;
- float2 lightmapUV : TEXCOORD1;
- float _tree_sway_speed : CustomLit1;
- UNITY_VERTEX_INPUT_INSTANCE_ID
- };
- struct Varyings
- {
- float2 uv : TEXCOORD0;
- DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, 1);
- #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
- float3 positionWS : TEXCOORD2;
- #endif
- float3 normalWS : TEXCOORD3;
- #if defined(REQUIRES_WORLD_SPACE_TANGENT_INTERPOLATOR)
- float4 tangentWS : TEXCOORD4; // xyz: tangent, w: sign
- #endif
- float3 viewDirWS : TEXCOORD5;
- half4 fogFactorAndVertexLight : TEXCOORD6; // x: fogFactor, yzw: vertex light
- #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
- float4 shadowCoord : TEXCOORD7;
- #endif
- #if defined(REQUIRES_TANGENT_SPACE_VIEW_DIR_INTERPOLATOR)
- float3 viewDirTS : TEXCOORD8;
- #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 = SafeNormalize(input.viewDirWS);
- #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);
- inputData.normalWS = TransformTangentToWorld(normalTS, half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz));
- #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
- inputData.fogCoord = input.fogFactorAndVertexLight.x;
- inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
- inputData.bakedGI = SAMPLE_GI(input.lightmapUV, input.vertexSH, inputData.normalWS);
- inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
- inputData.shadowMask = SAMPLE_SHADOWMASK(input.lightmapUV);
- }
- ///////////////////////////////////////////////////////////////////////////////
- // 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);
- float3 positionWS = TransformObjectToWorld(input.positionOS);
- positionWS.x += (cos(
- _Time.z * _tree_sway_speed + (worldPos.x / _wind_size) + (sin(
- _Time.z * _tree_sway_stutter * _tree_sway_speed + (worldPos.x / _wind_size)) *
- _tree_sway_stutter_influence)) + 1) / 2 * _tree_sway_disp * _wind_dir.x * (positionWS.y /
- 10) +
- cos(_Time.w * positionWS.x * _leaves_wiggle_speed + (positionWS.x / _wind_size)) *
- _leaves_wiggle_disp * _wind_dir.x * input.color.b * _b_influence;
- positionWS.z += (cos(
- _Time.z * _tree_sway_speed + (positionWS.z / _wind_size) + (sin(
- _Time.z * _tree_sway_stutter * _tree_sway_speed + (positionWS.z / _wind_size)) *
- _tree_sway_stutter_influence)) + 1) / 2 * _tree_sway_disp * _wind_dir.z * (positionWS.y /
- 10) +
- cos(_Time.w * positionWS.z * _leaves_wiggle_speed + (positionWS.x / _wind_size)) *
- _leaves_wiggle_disp * _wind_dir.z * input.color.b * _b_influence;
- positionWS.y += cos(_Time.z * _tree_sway_speed + (positionWS.z / _wind_size)) * _tree_sway_disp *
- _wind_dir.y * (positionWS.y / 10);
- //Branches Movement
- positionWS.y += sin(_Time.w * _tree_sway_speed + _wind_dir.x + (positionWS.z / _wind_size)) *
- _branches_disp * input.color.r * _r_influence;
- output.positionCS = TransformWorldToHClip(positionWS);
- // 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 = ComputeFogFactor(vertexInput.positionCS.z);
- 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.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;
- }
- // 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 viewDirTS = GetViewDirectionTangentSpace(input.tangentWS, input.normalWS, input.viewDirWS);
- #endif
- ApplyPerPixelDisplacement(viewDirTS, input.uv);
- #endif
- SurfaceData surfaceData;
- InitializeStandardLitSurfaceData(input.uv, surfaceData);
- InputData inputData;
- InitializeInputData(input, surfaceData.normalTS, inputData);
- half4 color = UniversalFragmentPBR(inputData, surfaceData);
- color.rgb = MixFog(color.rgb, inputData.fogCoord);
- color.a = OutputAlpha(color.a, _Surface);
- #if defined(LOD_FADE_CROSSFADE)
- float p = InterleavedGradientNoise(input.positionCS, 0);
- float f = unity_LODFade.x - CopySign(p, unity_LODFade.x);
- clip(f);
- #endif
- return color;
- }
- #endif
- ==========================================================================================================================
- ==========================================================================================================================
- ==========================================================================================================================
- ==========================================================================================================================
- ==========================================================================================================================
- CustomShadowCasterPass.hlsl:
- ifndef UNIVERSAL_SHADOW_CASTER_PASS_INCLUDED
- #define UNIVERSAL_SHADOW_CASTER_PASS_INCLUDED
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
- float3 _LightDirection;
- struct Varyings
- {
- float2 uv : TEXCOORD0;
- float4 positionCS : SV_POSITION;
- };
- float4 GetShadowPositionHClip(Attributes input)
- {
- float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
- float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
- float3 positionWS = TransformObjectToWorld(input.positionOS);
- positionWS.x += (cos(
- _Time.z * _tree_sway_speed + (worldPos.x / _wind_size) + (sin(
- _Time.z * _tree_sway_stutter * _tree_sway_speed + (worldPos.x / _wind_size)) *
- _tree_sway_stutter_influence)) + 1) / 2 * _tree_sway_disp * _wind_dir.x * (positionWS.y /
- 10) +
- cos(_Time.w * positionWS.x * _leaves_wiggle_speed + (positionWS.x / _wind_size)) *
- _leaves_wiggle_disp * _wind_dir.x * input.color.b * _b_influence;
- positionWS.z += (cos(
- _Time.z * _tree_sway_speed + (positionWS.z / _wind_size) + (sin(
- _Time.z * _tree_sway_stutter * _tree_sway_speed + (positionWS.z / _wind_size)) *
- _tree_sway_stutter_influence)) + 1) / 2 * _tree_sway_disp * _wind_dir.z * (positionWS.y /
- 10) +
- cos(_Time.w * positionWS.z * _leaves_wiggle_speed + (positionWS.x / _wind_size)) *
- _leaves_wiggle_disp * _wind_dir.z * input.color.b * _b_influence;
- positionWS.y += cos(_Time.z * _tree_sway_speed + (positionWS.z / _wind_size)) * _tree_sway_disp *
- _wind_dir.y * (positionWS.y / 10);
- //Branches Movement
- positionWS.y += sin(_Time.w * _tree_sway_speed + _wind_dir.x + (positionWS.z / _wind_size)) *
- _branches_disp * input.color.r * _r_influence;
- output.positionCS = TransformWorldToHClip(positionWS);
- 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;
- }
- Varyings ShadowPassVertex(Attributes input)
- {
- Varyings output;
- UNITY_SETUP_INSTANCE_ID(input);
- output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
- output.positionCS = GetShadowPositionHClip(input);
- return output;
- }
- half4 ShadowPassFragment(Varyings input) : SV_TARGET
- {
- Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff);
- return 0;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement