Advertisement
xxzxcuzxmxe

Untitled

Sep 27th, 2021
1,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CustomLit1.shader:
  2. Shader "Universal Render Pipeline/CustomLit1"
  3. {
  4.     Properties
  5.     {
  6.         // Specular vs Metallic workflow
  7.         [HideInInspector] _WorkflowMode("WorkflowMode", Float) = 1.0
  8.  
  9.         [MainTexture] _BaseMap("Albedo", 2D) = "white" {}
  10.         [MainColor] _BaseColor("Color", Color) = (1,1,1,1)
  11.  
  12.         _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
  13.  
  14.         _Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
  15.         _GlossMapScale("Smoothness Scale", Range(0.0, 1.0)) = 1.0
  16.         _SmoothnessTextureChannel("Smoothness texture channel", Float) = 0
  17.  
  18.         _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
  19.         _MetallicGlossMap("Metallic", 2D) = "white" {}
  20.  
  21.         _SpecColor("Specular", Color) = (0.2, 0.2, 0.2)
  22.         _SpecGlossMap("Specular", 2D) = "white" {}
  23.  
  24.         [ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
  25.         [ToggleOff] _EnvironmentReflections("Environment Reflections", Float) = 1.0
  26.  
  27.         _BumpScale("Scale", Float) = 1.0
  28.         _BumpMap("Normal Map", 2D) = "bump" {}
  29.  
  30.         _Parallax("Scale", Range(0.005, 0.08)) = 0.005
  31.         _ParallaxMap("Height Map", 2D) = "black" {}
  32.  
  33.         _OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0
  34.         _OcclusionMap("Occlusion", 2D) = "white" {}
  35.  
  36.         [HDR] _EmissionColor("Color", Color) = (0,0,0)
  37.         _EmissionMap("Emission", 2D) = "white" {}
  38.  
  39.         _DetailMask("Detail Mask", 2D) = "white" {}
  40.         _DetailAlbedoMapScale("Scale", Range(0.0, 2.0)) = 1.0
  41.         _DetailAlbedoMap("Detail Albedo x2", 2D) = "linearGrey" {}
  42.         _DetailNormalMapScale("Scale", Range(0.0, 2.0)) = 1.0
  43.  
  44.         //++++++++++++++++++++++++++++++++++++++++++++++++++++++=+++_+_+++++++++ЭТО ПРОПЕРТИ КОТОРЫЕ НУЖНЫ ДЛЯ ЛОГИКИ
  45.        
  46.         _Tint("Tint", Color) = (1,1,1,1)
  47.  
  48.         _wind_dir("Wind Direction", Vector) = (0.5,0.05,0.5,0)
  49.         _wind_size("Wind Wave Size", range(5,50)) = 15
  50.  
  51.         _tree_sway_stutter_influence("Tree Sway Stutter Influence", range(0,1)) = 0.2
  52.         _tree_sway_stutter("Tree Sway Stutter", range(0,10)) = 1.5
  53.         _tree_sway_speed("Tree Sway Speed", range(0,10)) = 1
  54.         _tree_sway_disp("Tree Sway Displacement", range(0,1)) = 0.3
  55.  
  56.         _branches_disp("Branches Displacement", range(0,0.5)) = 0.3
  57.  
  58.         _leaves_wiggle_disp("Leaves Wiggle Displacement", float) = 0.07
  59.         _leaves_wiggle_speed("Leaves Wiggle Speed", float) = 0.01
  60.  
  61.         _r_influence("Red Vertex Influence", range(0,1)) = 1
  62.         _b_influence("Blue Vertex Influence", range(0,1)) = 1
  63.         //========================================================================================
  64.  
  65.  
  66.         [Normal] _DetailNormalMap("Normal Map", 2D) = "bump" {}
  67.  
  68.         // SRP batching compatibility for Clear Coat (Not used in Lit)
  69.         [HideInInspector] _ClearCoatMask("_ClearCoatMask", Float) = 0.0
  70.         [HideInInspector] _ClearCoatSmoothness("_ClearCoatSmoothness", Float) = 0.0
  71.  
  72.             // Blending state
  73.             [HideInInspector] _Surface("__surface", Float) = 0.0
  74.             [HideInInspector] _Blend("__blend", Float) = 0.0
  75.             [HideInInspector] _AlphaClip("__clip", Float) = 0.0
  76.             [HideInInspector] _SrcBlend("__src", Float) = 1.0
  77.             [HideInInspector] _DstBlend("__dst", Float) = 0.0
  78.             [HideInInspector] _ZWrite("__zw", Float) = 1.0
  79.             [HideInInspector] _Cull("__cull", Float) = 2.0
  80.  
  81.             _ReceiveShadows("Receive Shadows", Float) = 1.0
  82.             // Editmode props
  83.             [HideInInspector] _QueueOffset("Queue offset", Float) = 0.0
  84.  
  85.             // ObsoleteProperties
  86.             [HideInInspector] _MainTex("BaseMap", 2D) = "white" {}
  87.             [HideInInspector] _Color("Base Color", Color) = (1, 1, 1, 1)
  88.             [HideInInspector] _GlossMapScale("Smoothness", Float) = 0.0
  89.             [HideInInspector] _Glossiness("Smoothness", Float) = 0.0
  90.             [HideInInspector] _GlossyReflections("EnvironmentReflections", Float) = 0.0
  91.  
  92.             [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {}
  93.             [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {}
  94.             [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {}
  95.     }
  96.  
  97.         SubShader
  98.     {
  99.         // Universal Pipeline tag is required. If Universal render pipeline is not set in the graphics settings
  100.         // this Subshader will fail. One can add a subshader below or fallback to Standard built-in to make this
  101.         // material work with both Universal Render Pipeline and Builtin Unity Pipeline
  102.         Tags{"RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "UniversalMaterialType" = "Lit" "IgnoreProjector" = "True" "ShaderModel" = "4.5"}
  103.         LOD 300
  104.  
  105.         // --------------------------------------------------------------------------------------------------------------------------------------вот тут листва исчезает если удалить
  106.         //  Forward pass. Shades all light in a single pass. GI + emission + Fog
  107.         Pass
  108.         {
  109.             // Lightmode matches the ShaderPassName set in UniversalRenderPipeline.cs. SRPDefaultUnlit and passes with
  110.             // no LightMode tag are also rendered by Universal Render Pipeline
  111.             Name "ForwardLit"
  112.             Tags{"LightMode" = "UniversalForward"}
  113.  
  114.             Blend[_SrcBlend][_DstBlend]
  115.             ZWrite[_ZWrite]
  116.             Cull[_Cull]
  117.  
  118.             HLSLPROGRAM
  119.             #pragma exclude_renderers gles gles3 glcore
  120.             #pragma target 4.5
  121.  
  122.         // -------------------------------------
  123.         // Material Keywords
  124.         #pragma shader_feature_local _NORMALMAP
  125.         #pragma shader_feature_local_fragment _ALPHATEST_ON
  126.         #pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON
  127.         #pragma shader_feature_local_fragment _EMISSION
  128.         #pragma shader_feature_local_fragment _METALLICSPECGLOSSMAP
  129.         #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
  130.         #pragma shader_feature_local_fragment _OCCLUSIONMAP
  131.         #pragma shader_feature_local _PARALLAXMAP
  132.         #pragma shader_feature_local _ _DETAIL_MULX2 _DETAIL_SCALED
  133.         #pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
  134.         #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
  135.         #pragma shader_feature_local_fragment _SPECULAR_SETUP
  136.         #pragma shader_feature_local _RECEIVE_SHADOWS_OFF
  137.  
  138.         // -------------------------------------
  139.         // Universal Pipeline keywords
  140.         #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  141.         #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  142.         #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  143.         #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  144.         #pragma multi_compile_fragment _ _SHADOWS_SOFT
  145.         #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  146.         #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  147.         #pragma multi_compile _ SHADOWS_SHADOWMASK
  148.  
  149.         // -------------------------------------
  150.         // Unity defined keywords
  151.         #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  152.         #pragma multi_compile _ LIGHTMAP_ON
  153.         #pragma multi_compile_fog
  154.         #pragma multi_compile _ LOD_FADE_CROSSFADE
  155.  
  156.         //--------------------------------------
  157.         // GPU Instancing
  158.         #pragma multi_compile_instancing
  159.         #pragma multi_compile _ DOTS_INSTANCING_ON
  160.  
  161.  
  162.         #pragma vertex LitPassVertex
  163.         #pragma vertex vert
  164.  
  165.  
  166.         #pragma fragment LitPassFragment
  167.  
  168.         #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
  169.         #include "CustomLitForwardPass.hlsl"
  170.        
  171.         #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  172.         ENDHLSL
  173.     }
  174.  
  175.     Pass
  176.     {
  177.         Name "ShadowCaster"
  178.         Tags{"LightMode" = "ShadowCaster"}
  179.  
  180.         ZWrite On
  181.         ZTest LEqual
  182.         ColorMask 0
  183.         Cull[_Cull]
  184.  
  185.         HLSLPROGRAM
  186.         #pragma exclude_renderers gles gles3 glcore
  187.         #pragma target 4.5
  188.  
  189.         // -------------------------------------
  190.         // Material Keywords
  191.         #pragma shader_feature_local_fragment _ALPHATEST_ON
  192.         #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
  193.  
  194.         //--------------------------------------
  195.         // GPU Instancing
  196.         #pragma multi_compile_instancing
  197.         #pragma multi_compile _ DOTS_INSTANCING_ON
  198.  
  199.            
  200.        
  201.         #pragma vertex ShadowPassVertex
  202.         #pragma vertex vert
  203.  
  204.            
  205.         #pragma fragment ShadowPassFragment
  206.  
  207.         #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
  208.         #include "CustomShadowCasterPass.hlsl"
  209.         #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  210.         ENDHLSL
  211.     }
  212.  
  213.         // This pass it not used during regular rendering, only for lightmap baking.
  214.        
  215.     }
  216.  
  217.         FallBack "Hidden/Universal Render Pipeline/FallbackError"
  218.         CustomEditor "UnityEditor.Rendering.Universal.ShaderGUI.LitShader"
  219. }
  220.  
  221. ==========================================================================================================================
  222. ==========================================================================================================================
  223. ==========================================================================================================================
  224. ==========================================================================================================================
  225. ==========================================================================================================================
  226. CustomLitForwardPass.hlsl:
  227. #ifndef UNIVERSAL_FORWARD_LIT_PASS_INCLUDED
  228. #define UNIVERSAL_FORWARD_LIT_PASS_INCLUDED
  229.  
  230. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  231.  
  232. // GLES2 has limited amount of interpolators
  233. #if defined(_PARALLAXMAP) && !defined(SHADER_API_GLES)
  234. #define REQUIRES_TANGENT_SPACE_VIEW_DIR_INTERPOLATOR
  235. #endif
  236.  
  237. #if (defined(_NORMALMAP) || (defined(_PARALLAXMAP) && !defined(REQUIRES_TANGENT_SPACE_VIEW_DIR_INTERPOLATOR))) || defined(_DETAIL)
  238. #define REQUIRES_WORLD_SPACE_TANGENT_INTERPOLATOR
  239. #endif
  240.  
  241. // keep this file in sync with LitGBufferPass.hlsl
  242.  
  243. struct Attributes
  244. {
  245.     float4 positionOS   : POSITION;
  246.     float3 normalOS     : NORMAL;
  247.     float4 tangentOS    : TANGENT;
  248.     float2 texcoord     : TEXCOORD0;
  249.  
  250.     float2 lightmapUV   : TEXCOORD1;
  251.  
  252.     float _tree_sway_speed : CustomLit1;
  253.     UNITY_VERTEX_INPUT_INSTANCE_ID
  254. };
  255.  
  256. struct Varyings
  257. {
  258.     float2 uv                       : TEXCOORD0;
  259.     DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, 1);
  260.  
  261. #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
  262.     float3 positionWS               : TEXCOORD2;
  263. #endif
  264.  
  265.     float3 normalWS                 : TEXCOORD3;
  266. #if defined(REQUIRES_WORLD_SPACE_TANGENT_INTERPOLATOR)
  267.     float4 tangentWS                : TEXCOORD4;    // xyz: tangent, w: sign
  268. #endif
  269.     float3 viewDirWS                : TEXCOORD5;
  270.  
  271.     half4 fogFactorAndVertexLight   : TEXCOORD6; // x: fogFactor, yzw: vertex light
  272.  
  273. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  274.     float4 shadowCoord              : TEXCOORD7;
  275. #endif
  276.  
  277. #if defined(REQUIRES_TANGENT_SPACE_VIEW_DIR_INTERPOLATOR)
  278.     float3 viewDirTS                : TEXCOORD8;
  279. #endif
  280.  
  281.    
  282.     float4 positionCS               : SV_POSITION;
  283.     UNITY_VERTEX_INPUT_INSTANCE_ID
  284.     UNITY_VERTEX_OUTPUT_STEREO
  285.  
  286. };
  287.  
  288. void InitializeInputData(Varyings input, half3 normalTS, out InputData inputData)
  289. {
  290.     inputData = (InputData)0;
  291.  
  292. #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
  293.     inputData.positionWS = input.positionWS;
  294. #endif
  295.  
  296.     half3 viewDirWS = SafeNormalize(input.viewDirWS);
  297. #if defined(_NORMALMAP) || defined(_DETAIL)
  298.     float sgn = input.tangentWS.w;      // should be either +1 or -1
  299.     float3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
  300.     inputData.normalWS = TransformTangentToWorld(normalTS, half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz));
  301. #else
  302.     inputData.normalWS = input.normalWS;
  303. #endif
  304.  
  305.     inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
  306.     inputData.viewDirectionWS = viewDirWS;
  307.  
  308. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  309.     inputData.shadowCoord = input.shadowCoord;
  310. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  311.     inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
  312. #else
  313.     inputData.shadowCoord = float4(0, 0, 0, 0);
  314. #endif
  315.  
  316.     inputData.fogCoord = input.fogFactorAndVertexLight.x;
  317.     inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
  318.     inputData.bakedGI = SAMPLE_GI(input.lightmapUV, input.vertexSH, inputData.normalWS);
  319.     inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
  320.     inputData.shadowMask = SAMPLE_SHADOWMASK(input.lightmapUV);
  321. }
  322.  
  323. ///////////////////////////////////////////////////////////////////////////////
  324. //                  Vertex and Fragment functions                            //
  325. ///////////////////////////////////////////////////////////////////////////////
  326.  
  327. // Used in Standard (Physically Based) shader
  328. Varyings LitPassVertex(Attributes input)
  329. {
  330.     Varyings output = (Varyings)0;
  331.  
  332.     UNITY_SETUP_INSTANCE_ID(input);
  333.     UNITY_TRANSFER_INSTANCE_ID(input, output);
  334.     UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  335.  
  336.  
  337.     float3 positionWS = TransformObjectToWorld(input.positionOS);
  338.  
  339.     positionWS.x += (cos(
  340.         _Time.z * _tree_sway_speed + (worldPos.x / _wind_size) + (sin(
  341.             _Time.z * _tree_sway_stutter * _tree_sway_speed + (worldPos.x / _wind_size)) *
  342.             _tree_sway_stutter_influence)) + 1) / 2 * _tree_sway_disp * _wind_dir.x * (positionWS.y /
  343.                 10) +
  344.         cos(_Time.w * positionWS.x * _leaves_wiggle_speed + (positionWS.x / _wind_size)) *
  345.         _leaves_wiggle_disp * _wind_dir.x * input.color.b * _b_influence;
  346.  
  347.     positionWS.z += (cos(
  348.         _Time.z * _tree_sway_speed + (positionWS.z / _wind_size) + (sin(
  349.             _Time.z * _tree_sway_stutter * _tree_sway_speed + (positionWS.z / _wind_size)) *
  350.             _tree_sway_stutter_influence)) + 1) / 2 * _tree_sway_disp * _wind_dir.z * (positionWS.y /
  351.                 10) +
  352.         cos(_Time.w * positionWS.z * _leaves_wiggle_speed + (positionWS.x / _wind_size)) *
  353.         _leaves_wiggle_disp * _wind_dir.z * input.color.b * _b_influence;
  354.  
  355.     positionWS.y += cos(_Time.z * _tree_sway_speed + (positionWS.z / _wind_size)) * _tree_sway_disp *
  356.         _wind_dir.y * (positionWS.y / 10);
  357.  
  358.     //Branches Movement
  359.     positionWS.y += sin(_Time.w * _tree_sway_speed + _wind_dir.x + (positionWS.z / _wind_size)) *
  360.         _branches_disp * input.color.r * _r_influence;
  361.  
  362.     output.positionCS = TransformWorldToHClip(positionWS);
  363.  
  364.  
  365.     // normalWS and tangentWS already normalize.
  366.     // this is required to avoid skewing the direction during interpolation
  367.     // also required for per-vertex lighting and SH evaluation
  368.     VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
  369.  
  370.     half3 viewDirWS = GetWorldSpaceViewDir(vertexInput.positionWS);
  371.     half3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS);
  372.     half fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
  373.  
  374.  
  375.     output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
  376.  
  377.     // already normalized from normal transform to WS.
  378.     output.normalWS = normalInput.normalWS;
  379.     output.viewDirWS = viewDirWS;
  380. #if defined(REQUIRES_WORLD_SPACE_TANGENT_INTERPOLATOR) || defined(REQUIRES_TANGENT_SPACE_VIEW_DIR_INTERPOLATOR)
  381.     real sign = input.tangentOS.w * GetOddNegativeScale();
  382.     half4 tangentWS = half4(normalInput.tangentWS.xyz, sign);
  383. #endif
  384. #if defined(REQUIRES_WORLD_SPACE_TANGENT_INTERPOLATOR)
  385.     output.tangentWS = tangentWS;
  386. #endif
  387.  
  388. #if defined(REQUIRES_TANGENT_SPACE_VIEW_DIR_INTERPOLATOR)
  389.     half3 viewDirTS = GetViewDirectionTangentSpace(tangentWS, output.normalWS, viewDirWS);
  390.     output.viewDirTS = viewDirTS;
  391. #endif
  392.  
  393.     OUTPUT_LIGHTMAP_UV(input.lightmapUV, unity_LightmapST, output.lightmapUV);
  394.     OUTPUT_SH(output.normalWS.xyz, output.vertexSH);
  395.  
  396.     output.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  397.  
  398. #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
  399.     output.positionWS = vertexInput.positionWS;
  400. #endif
  401.  
  402. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  403.     output.shadowCoord = GetShadowCoord(vertexInput);
  404. #endif
  405.  
  406.     output.positionCS = vertexInput.positionCS;
  407.  
  408.     return output;
  409. }
  410.  
  411. // Used in Standard (Physically Based) shader
  412. half4 LitPassFragment(Varyings input) : SV_Target
  413. {
  414.     UNITY_SETUP_INSTANCE_ID(input);
  415.     UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  416.  
  417. #if defined(_PARALLAXMAP)
  418. #if defined(REQUIRES_TANGENT_SPACE_VIEW_DIR_INTERPOLATOR)
  419.     half3 viewDirTS = input.viewDirTS;
  420. #else
  421.     half3 viewDirTS = GetViewDirectionTangentSpace(input.tangentWS, input.normalWS, input.viewDirWS);
  422. #endif
  423.     ApplyPerPixelDisplacement(viewDirTS, input.uv);
  424. #endif
  425.  
  426.     SurfaceData surfaceData;
  427.     InitializeStandardLitSurfaceData(input.uv, surfaceData);
  428.  
  429.     InputData inputData;
  430.     InitializeInputData(input, surfaceData.normalTS, inputData);
  431.  
  432.     half4 color = UniversalFragmentPBR(inputData, surfaceData);
  433.  
  434.     color.rgb = MixFog(color.rgb, inputData.fogCoord);
  435.     color.a = OutputAlpha(color.a, _Surface);
  436.  
  437.  
  438. #if defined(LOD_FADE_CROSSFADE)
  439.     float p = InterleavedGradientNoise(input.positionCS, 0);
  440.     float f = unity_LODFade.x - CopySign(p, unity_LODFade.x);
  441.     clip(f);
  442. #endif
  443.  
  444.     return color;
  445. }
  446.  
  447. #endif
  448.  
  449. ==========================================================================================================================
  450. ==========================================================================================================================
  451. ==========================================================================================================================
  452. ==========================================================================================================================
  453. ==========================================================================================================================
  454. CustomShadowCasterPass.hlsl:
  455. ifndef UNIVERSAL_SHADOW_CASTER_PASS_INCLUDED
  456. #define UNIVERSAL_SHADOW_CASTER_PASS_INCLUDED
  457.  
  458. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  459. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  460.  
  461. float3 _LightDirection;
  462.  
  463.  
  464.  
  465. struct Varyings
  466. {
  467.     float2 uv           : TEXCOORD0;
  468.     float4 positionCS   : SV_POSITION;
  469. };
  470.  
  471. float4 GetShadowPositionHClip(Attributes input)
  472. {
  473.     float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
  474.     float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
  475.  
  476.  
  477.     float3 positionWS = TransformObjectToWorld(input.positionOS);
  478.     positionWS.x += (cos(
  479.         _Time.z * _tree_sway_speed + (worldPos.x / _wind_size) + (sin(
  480.             _Time.z * _tree_sway_stutter * _tree_sway_speed + (worldPos.x / _wind_size)) *
  481.             _tree_sway_stutter_influence)) + 1) / 2 * _tree_sway_disp * _wind_dir.x * (positionWS.y /
  482.                 10) +
  483.         cos(_Time.w * positionWS.x * _leaves_wiggle_speed + (positionWS.x / _wind_size)) *
  484.         _leaves_wiggle_disp * _wind_dir.x * input.color.b * _b_influence;
  485.  
  486.     positionWS.z += (cos(
  487.         _Time.z * _tree_sway_speed + (positionWS.z / _wind_size) + (sin(
  488.             _Time.z * _tree_sway_stutter * _tree_sway_speed + (positionWS.z / _wind_size)) *
  489.             _tree_sway_stutter_influence)) + 1) / 2 * _tree_sway_disp * _wind_dir.z * (positionWS.y /
  490.                 10) +
  491.         cos(_Time.w * positionWS.z * _leaves_wiggle_speed + (positionWS.x / _wind_size)) *
  492.         _leaves_wiggle_disp * _wind_dir.z * input.color.b * _b_influence;
  493.  
  494.     positionWS.y += cos(_Time.z * _tree_sway_speed + (positionWS.z / _wind_size)) * _tree_sway_disp *
  495.         _wind_dir.y * (positionWS.y / 10);
  496.  
  497.     //Branches Movement
  498.     positionWS.y += sin(_Time.w * _tree_sway_speed + _wind_dir.x + (positionWS.z / _wind_size)) *
  499.         _branches_disp * input.color.r * _r_influence;
  500.  
  501.     output.positionCS = TransformWorldToHClip(positionWS);
  502.  
  503.  
  504.  
  505.     float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
  506.  
  507. #if UNITY_REVERSED_Z
  508.     positionCS.z = min(positionCS.z, positionCS.w * UNITY_NEAR_CLIP_VALUE);
  509. #else
  510.     positionCS.z = max(positionCS.z, positionCS.w * UNITY_NEAR_CLIP_VALUE);
  511. #endif
  512.  
  513.     return positionCS;
  514. }
  515.  
  516. Varyings ShadowPassVertex(Attributes input)
  517. {
  518.     Varyings output;
  519.     UNITY_SETUP_INSTANCE_ID(input);
  520.  
  521.     output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
  522.     output.positionCS = GetShadowPositionHClip(input);
  523.     return output;
  524. }
  525.  
  526. half4 ShadowPassFragment(Varyings input) : SV_TARGET
  527. {
  528.     Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff);
  529.     return 0;
  530. }
  531.  
  532. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement