Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ats Snow Suite

Discussion in 'Assets and Asset Store' started by larsbertram1, Aug 15, 2012.

  1. s050107511

    s050107511

    Joined:
    Sep 21, 2012
    Posts:
    9
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899

    i guess this is caused by a "bug" in the tree leaf lighting function as the calcualtion of the specualr part misses * dot(n,l);

    find:
    half nl = dot (s.Normal, lightDir);
    half nh = max (0, dot (s.Normal, h));
    half spec = pow (nh, s.Specular * 128.0) * s.Gloss;

    and replace the last line by:
    half spec = pow (nh, s.Specular * 128.0) * s.Gloss * nl;
     
  3. s050107511

    s050107511

    Joined:
    Sep 21, 2012
    Posts:
    9
    View attachment 116433 Thank you for fast answer, but this partially helped((. This "bug" remained on bark always. And he manifested on leaf at a greater distance. Please me help still!
    I replace string
    "half spec = pow (nh, s.Specular * 128.0) * s.Gloss;"
    on string
    "half spec = pow (nh, s.Specular * 128.0) * s.Gloss * nl"
    in 2 scipts:
    Terrain Snow\atsV3 UnityTerrainSnow Package\Shaders\Trees\Tree.cginc
    Terrain Snow\atsV3 UnityTerrainSnow Package\Shaders\Trees\TreeSnow.cginc
    Unity 4.3.4

    On Unity 4.5.2 terrain is pink, and tree good
     

    Attached Files:

    Last edited: Oct 23, 2014
  4. s050107511

    s050107511

    Joined:
    Sep 21, 2012
    Posts:
    9
    I has received good result, set true flag "Use Direct3D 11"
     
  5. SazanOFF

    SazanOFF

    Joined:
    Oct 20, 2014
    Posts:
    11
    Hello friend. I very like your asset, but i have very big problem if i am restart Unity Editor, i need reimport Shaders folder, else i see snow only on objects. Terrain lost Snow, Please Sorry my english. My Unity 4.5.1f3
     
  6. CugotaEric

    CugotaEric

    Joined:
    Nov 2, 2014
    Posts:
    3
    hello, i have a problem, everything looks pink after importing.
     
  7. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    Hi, I tried this asset but everything comes up pink! Is this because of Unity 4.6 and DX11 not being supported ?
     
  8. o1o101

    o1o101

    Joined:
    Jan 19, 2014
    Posts:
    639
    ^^^^^^^any help?
     
  9. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,932
    Ooo, I am tempted to try this but I bet it will send RTP into fits. :) Anyone try it with RTP? I know it doesn't play well with other shaders.
     
  10. knight2601

    knight2601

    Joined:
    Dec 12, 2013
    Posts:
    8
    is there any reason why it wont work in unity 5?
    i've tried it with and without upgrading the shader on import into unity 5 with no joy...
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
  12. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Are you getting an error message or it simply doesn't work?

    Honestly I'd love upgrading to unity5 but if these shader do not work it's too much of a deal breaker for me..
     
  13. knight2601

    knight2601

    Joined:
    Dec 12, 2013
    Posts:
    8
    it just doesn't work...

    i've purchased RTP3.2 anyway so switching to that, once i get round some errors in my scenes :D
     
  14. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    For anyone wondering, I managed to get the tree shader working with snow on Unity 5, simply replace all calls to "include Tree.cgin" to include "TreeSnow.cgin", all calls to "TreeVertLeaf(v)" to "TreeVertLeafSnow(v)"

    And in the TreeSnow.cgin simply comment out the lines involving _Scale. And don't forget to assing an alpha value to c before returning it.

    The trees seem to be working now but I can't get the terrain to work.

    Full code below:

    Code (CSharp):
    1. Shader "Hidden/Nature/Tree Creator Leaves Optimized Snow-Pine" {
    2. Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _TranslucencyColor ("Translucency Color", Color) = (0.73,0.85,0.41,1) // (187,219,106,255)
    5.     _Cutoff ("Alpha cutoff", Range(0,1)) = 0.3
    6.     _TranslucencyViewDependency ("View dependency", Range(0,1)) = 0.7
    7.     _ShadowStrength("Shadow Strength", Range(0,1)) = 0.8
    8.     _ShadowOffsetScale ("Shadow Offset Scale", Float) = 1
    9.    
    10.     _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
    11.     _ShadowTex ("Shadow (RGB)", 2D) = "white" {}
    12.     _BumpSpecMap ("Normalmap (GA) Spec (R) Shadow Offset (B)", 2D) = "bump" {}
    13.     _TranslucencyMap ("Trans (B) Gloss(A)", 2D) = "white" {}
    14.    
    15.     // These are here only to provide default values
    16.     _Scale ("Scale", Vector) = (1,1,1,1)
    17.     _SquashAmount ("Squash", Float) = 1
    18. }
    19.  
    20. SubShader {
    21.     Tags {
    22.         "IgnoreProjector"="True"
    23.         "RenderType"="TreeLeaf"
    24.     }
    25.     LOD 200
    26.    
    27. CGPROGRAM
    28. #pragma surface surf TreeLeaf alphatest:_Cutoff vertex:TreeVertLeafSnow nolightmap
    29. #pragma exclude_renderers flash
    30. #pragma glsl_no_auto_normalization
    31. #pragma target 3.0
    32.  
    33. #include "TreeSnow.cginc"
    34.  
    35. sampler2D _MainTex;
    36. sampler2D _BumpSpecMap;
    37. sampler2D _TranslucencyMap;
    38.  
    39. // all these have to be send via script = CustomTerrainScriptAtsV3Snow.cs
    40. sampler2D _SnowTexture;
    41. float _snowShininess;
    42. float _SnowAmount;
    43. float _SnowStartHeight;
    44.  
    45.  
    46. struct Input {
    47.     float2 uv_MainTex;
    48.     fixed4 color : COLOR; // color.a = AO
    49.     float3 worldPos;
    50. };
    51.  
    52. void surf (Input IN, inout LeafSurfaceOutput o) {
    53.     fixed4 col = tex2D(_MainTex, IN.uv_MainTex);
    54.     fixed4 trngls = tex2D (_TranslucencyMap, IN.uv_MainTex);
    55.     o.Translucency = trngls.b;
    56.     o.Alpha = col.a;
    57.    
    58.     // get snow texture
    59.     half3 snowtex = tex2D( _SnowTexture, IN.uv_MainTex).rgb;
    60.    
    61.     // lerp = allows snow even on orthogonal surfaces // (1-col.g) = take the blue channel to get some kind of heightmap // worldNormal is stored in IN.color
    62.     float snowAmount = lerp(_SnowAmount * IN.color.y, 1, _SnowAmount) * (1-col.g) * .65 + o.Normal.y * _SnowAmount *.25 * IN.color.a * trngls.b;
    63.    
    64.     // clamp snow to _SnowStartHeight
    65.     // billboards do not get effected by snowStartHeight anyway...
    66.     snowAmount = snowAmount * clamp((IN.worldPos.y - _SnowStartHeight)*.0125, 0, 1);
    67.    
    68.     // sharpen snow mask
    69.     snowAmount = clamp( pow(snowAmount,6)*256, 0, 0.63);
    70.    
    71.     // mix all together
    72.     o.Gloss = trngls.a * _Color.r * (1-snowAmount) + ((1-snowtex) * snowAmount);
    73.     o.Albedo = (col.rgb * (1-snowAmount) + snowtex.rgb*snowAmount) * IN.color.a;
    74.     half4 norspc = tex2D (_BumpSpecMap, IN.uv_MainTex);
    75.     o.Specular = norspc.r * (1-snowAmount) + _snowShininess * snowAmount;
    76.     o.Normal = UnpackNormalDXT5nm(norspc);
    77.  
    78.     // smooth normal
    79.     o.Normal = normalize(lerp(o.Normal, float3(0,0,1), snowAmount*.50));
    80. }
    81. ENDCG
    82. }
    83.     SubShader {
    84.     Tags {
    85.         "IgnoreProjector"="True"
    86.         "RenderType"="TreeLeaf"
    87.     }
    88.    
    89.     ColorMask RGB
    90.     Lighting On
    91.     // Pass to render object as a shadow caster
    92.     Pass {
    93.         Name "ShadowCaster"
    94.         Tags { "LightMode" = "ShadowCaster" }
    95.        
    96.         Fog {Mode Off}
    97.         ZWrite On ZTest LEqual Cull Off
    98.         Offset 1, 1
    99.  
    100.         CGPROGRAM
    101.         #pragma vertex vert_surf
    102.         #pragma fragment frag_surf
    103.         #pragma exclude_renderers noshadows flash
    104.         #pragma glsl_no_auto_normalization
    105.         #pragma fragmentoption ARB_precision_hint_fastest
    106.         #pragma multi_compile_shadowcaster
    107.         #include "HLSLSupport.cginc"
    108.         #include "UnityCG.cginc"
    109.         #include "Lighting.cginc"
    110.  
    111.         #define INTERNAL_DATA
    112.         #define WorldReflectionVector(data,normal) data.worldRefl
    113.  
    114.         #include "TreeSnow.cginc"
    115.  
    116.         sampler2D _ShadowTex;
    117.  
    118.         struct Input {
    119.             float2 uv_MainTex;
    120.         };
    121.  
    122.         struct v2f_surf {
    123.             V2F_SHADOW_CASTER;
    124.             float2 hip_pack0 : TEXCOORD1;
    125.         };
    126.         float4 _ShadowTex_ST;
    127.         v2f_surf vert_surf (appdata_full v) {
    128.             v2f_surf o;
    129.             TreeVertLeafSnow (v);
    130.             o.hip_pack0.xy = TRANSFORM_TEX(v.texcoord, _ShadowTex);
    131.             TRANSFER_SHADOW_CASTER(o)
    132.             return o;
    133.         }
    134.         fixed _Cutoff;
    135.         float4 frag_surf (v2f_surf IN) : COLOR {
    136.             half alpha = tex2D(_ShadowTex, IN.hip_pack0.xy).r;
    137.             clip (alpha - _Cutoff);
    138.             SHADOW_CASTER_FRAGMENT(IN)
    139.         }
    140.         ENDCG
    141.     }  
    142. }
    143.  
    144. SubShader {
    145.     Tags {
    146.         "IgnoreProjector"="True"
    147.         "RenderType"="TreeLeaf"
    148.     }
    149.    
    150.     ColorMask RGB
    151.     Lighting On
    152.    
    153.     Pass {
    154.         CGPROGRAM
    155.         #pragma vertex TreeVertLit
    156.         #pragma exclude_renderers shaderonly
    157.        
    158.         #include "UnityCG.cginc"
    159.         #include "Tree.cginc"
    160.        
    161.         struct v2f {
    162.             float4 pos : SV_POSITION;
    163.             fixed4 color : COLOR;
    164.             float4 uv : TEXCOORD0;
    165.         };
    166.        
    167.         v2f TreeVertLit (appdata_full v) {
    168.             v2f o;
    169.             TreeVertLeaf(v);
    170.  
    171.             o.color.rgb = ShadeVertexLights (v.vertex, v.normal);
    172.                
    173.             o.pos = mul (UNITY_MATRIX_MVP, v.vertex);  
    174.             o.uv = v.texcoord;
    175.             o.color.a = 1.0f;
    176.             return o;
    177.         }
    178.         ENDCG
    179.  
    180.         AlphaTest Greater [_Cutoff]
    181.         SetTexture [_MainTex] { combine texture * primary DOUBLE, texture }
    182.         SetTexture [_MainTex] {
    183.             ConstantColor [_Color]
    184.             Combine previous * constant, previous
    185.         }
    186.     }
    187. }
    188.  
    189. SubShader {
    190.     Tags { "RenderType"="TreeLeaf" }
    191.     Pass {
    192.         ColorMask RGB
    193.        
    194.         Material {
    195.             Diffuse (1,1,1,1)
    196.             Ambient (1,1,1,1)
    197.         }
    198.         Lighting On
    199.        
    200.         AlphaTest Greater [_Cutoff]
    201.         SetTexture [_MainTex] { Combine texture * primary DOUBLE, texture }
    202.         SetTexture [_MainTex] {
    203.             ConstantColor [_Color]
    204.             Combine previous * constant, previous
    205.         }
    206.     }
    207. }
    208.  
    209. Dependency "BillboardShader" = "Hidden/Nature/Tree Creator Leaves Rendertex Snow"
    210. }
    211.  
    And the TreeSnow.cgin

    Code (CSharp):
    1. #ifndef TREE_CG_INCLUDED
    2. #define TREE_CG_INCLUDED
    3.  
    4. #include "TerrainEngine.cginc"
    5.  
    6. void TreeVertLeafSnow (inout appdata_full v)
    7. {
    8.     ExpandBillboard (UNITY_MATRIX_IT_MV, v.vertex, v.normal, v.tangent);
    9.     //v.vertex.xyz *= _Scale.xyz;
    10.     v.vertex = AnimateVertex (v.vertex,v.normal, float4(v.color.xy, v.texcoord1.xy));
    11.    
    12.     v.vertex = Squash(v.vertex);
    13.    
    14.     v.color = float4 (1, 1, 1, v.color.a);
    15.     v.normal = normalize(v.normal);
    16.     v.tangent.xyz = normalize(v.tangent.xyz);
    17.    
    18.     // add worldnormal to color
    19.     v.color.g = normalize(mul((float3x3)_Object2World, v.normal)).y; // g - world up vector  
    20. }
    21.  
    22. void TreeVertBarkSnow (inout appdata_full v)
    23. {
    24. //    v.vertex.xyz *= _Scale.xyz;
    25.     v.vertex = AnimateVertex(v.vertex, v.normal, float4(v.color.xy, v.texcoord1.xy));
    26.    
    27.     v.vertex = Squash(v.vertex);
    28.    
    29.     v.color = float4 (1, 1, 1, v.color.a);
    30.     v.normal = normalize(v.normal);
    31.     v.tangent.xyz = normalize(v.tangent.xyz);
    32.    
    33.     // add worldnormal to color
    34.     v.color.g = normalize(mul((float3x3)_Object2World, v.normal)).y; // g - world up vector
    35. }
    36.  
    37.  
    38.  
    39. fixed4 _Color;
    40. fixed3 _TranslucencyColor;
    41. fixed _TranslucencyViewDependency;
    42. half _ShadowStrength;
    43.  
    44. struct LeafSurfaceOutput {
    45.     fixed3 Albedo;
    46.     fixed3 Normal;
    47.     fixed3 Emission;
    48.     fixed Translucency;
    49.     half Specular;
    50.     fixed Gloss;
    51.     fixed Alpha;
    52. };
    53.  
    54. inline half4 LightingTreeLeaf (LeafSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
    55. {
    56.     half3 h = normalize (lightDir + viewDir);
    57.    
    58.     half nl = dot (s.Normal, lightDir);
    59.    
    60.     half nh = max (0, dot (s.Normal, h));
    61.     half spec = pow (nh, s.Specular * 128.0) * s.Gloss;
    62.    
    63.     // view dependent back contribution for translucency
    64.     fixed backContrib = saturate(dot(viewDir, -lightDir));
    65.    
    66.     // normally translucency is more like -nl, but looks better when it's view dependent
    67.     backContrib = lerp(saturate(-nl), backContrib, _TranslucencyViewDependency);
    68.    
    69.     fixed3 translucencyColor = backContrib * s.Translucency * _TranslucencyColor;
    70.    
    71.     // wrap-around diffuse
    72.     nl = max(0, nl * 0.6 + 0.4);
    73.    
    74.     fixed4 c;
    75.     c.rgb = s.Albedo * (translucencyColor * 2 + nl);
    76.     c.rgb = c.rgb * _LightColor0.rgb + spec * _LightColor0.rgb;
    77.    
    78.     // For directional lights, apply less shadow attenuation
    79.     // based on shadow strength parameter.
    80.     #if defined(DIRECTIONAL) || defined(DIRECTIONAL_COOKIE)
    81.     c.rgb *= lerp(2, atten * 2, _ShadowStrength);
    82.     #else
    83.     c.rgb *= 2*atten;
    84.     #endif
    85.     c.a = 1;
    86.     return c;
    87. }
    88. #endif
     
    odival and twobob like this.
  15. Jean-Michel585

    Jean-Michel585

    Joined:
    Dec 9, 2014
    Posts:
    7
    Thanks ensiferum888

    Same for TreeVertBark -> TreeVertBarkSnow

    In Camera-DepthNormalTexture and Camera-DepthTexture :
    Add : #include "../../../Trees/TreeSnow.cginc" when using TreeVertLeafSnow(v) and TreeVertBarkSnow(v)

    Shader "snowShaderBumpedDiffuse" :
    Line 37 :
    void snow (inout appdata_full v, out Input o) {
    UNITY_INITIALIZE_OUTPUT(Input,o);
    o.MyWorldNormal = normalize(mul((float3x3)_Object2World, v.normal));
    }

    Line 65 (66) :
    o.Gloss = (half)(snowAmount * (1 - snowtex.rgb));

    Enjoy !
     
    odival likes this.
  16. odival

    odival

    Joined:
    Jun 11, 2014
    Posts:
    57
    Thanks @Jean Michel and @ensiferum888 for the suggestions, they work very well! =)

    I kinda made the terrain work on Unity 5.2.3f1. I uncommented lines
    63
    80, 81
    87,88
    94,95
    101,102

    and added UNITY_INITIALIZE_OUTPUT(Input,o); in line 41, below "void snow (inout appdata_full v, out Input o) { ".

    But what really made it work was creating a new material with the TerrainReplacementAtsV3Snow.shader, and then on the Terrain Settings I choose "Custom Material" and assign said material.

    *Note: The terrain is now kinda glossy, so you may want to leave the mentioned lines commented out!
     
  17. lanrosta

    lanrosta

    Joined:
    Oct 11, 2014
    Posts:
    26
    @odival - Could you PM me with a working Unity 5 prefab/ code sample please? Or perhaps provide specific instructions on which files and lines need to be changed? What are those line numbers you commented out (what file)? Can you explain the process where you create the new material with TerrainReplacementAtsV3Snow.shader a little more? I have tried walking through the changes mentioned above but haven't had any luck with it. Would really love to get this working along with Unistorm for a decent realistic snow scene. Thanks for any info you or anyone else can provide.
     
  18. AndreiFlo

    AndreiFlo

    Joined:
    Dec 15, 2016
    Posts:
    1
    Anyone who did it on unity 5?
     
    CloudyVR likes this.
  19. partaukko

    partaukko

    Joined:
    Jun 17, 2017
    Posts:
    4
    Doesn't seem to work in Unity 2017.3.0f. Terrain is pink. Anyway to fix?
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    it is a unity 3.x asset. but maybe someone here has ported it to 2017?
     
  21. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Is this updated for latest editor? I see the is ATS v5 and so on. But they don't have the snow trees using the unity tree editor.