Search Unity

Advanced foliage shader [released]

Discussion in 'Assets and Asset Store' started by larsbertram1, Apr 24, 2012.

  1. tequyla

    tequyla

    Joined:
    Jul 22, 2012
    Posts:
    335
    asset concerned: Advanced Foliage Shaders v.4

    unity 2020.3.29f1


    3 errors with old code. Below a first try to fix on 2 files.


    error type:

    assets\advanced foliage shader v4\scripts\foliage tool afs v4\afsfoliagetool.cs(185,14): error cs0117: 'handles' does not contain a definition for 'circlecap'


    SetupAdvancedFoliageShader.cs
    Code (CSharp):
    1. if(SyncWindDir) {
    2.             //Handles.ArrowCap(0, transform.position, transform.rotation, hsize);
    3.             Handles.ArrowHandleCap(0, transform.position, transform.rotation, hsize, EventType.Repaint);
    4.  
    5.         }
    6.         else {
    7.             Quaternion rotation = Quaternion.LookRotation(new Vector3(Wind.x, Wind.y, Wind.z));
    8.             //Handles.ArrowCap(0, transform.position, rotation, hsize);
    9.             Handles.ArrowHandleCap(0, transform.position, rotation, hsize, EventType.Repaint);
    10.         }
    11.  
    AfsFoliageTool.cs
    Code (CSharp):
    1. Handles.color = Color.green;
    2.                     //Handles.CircleCap(0, offset, rotation, size);
    3.                     Handles.CircleHandleCap(0, offset, rotation, size, EventType.Repaint);
    4.  
    let me know if the asset works now.

    ++

    Teq.
     
    Last edited: May 13, 2022
  2. Unity2033

    Unity2033

    Joined:
    Aug 5, 2022
    Posts:
    2
    Wondering is this asset gonna get some update, especially for urp support or this will get depreciated soon? Definitely gonna buy this asset even the price is getting higher.
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    cu
    rrently i do not plan any urp version. my Lux URP Essentials package contains grass, foliage and tree creator shaders. if you are only looking for a grass solution you might be interested in the advanced terrain grass.
     
    lacas8282 likes this.
  4. lacas8282

    lacas8282

    Joined:
    Apr 25, 2015
    Posts:
    139
    Hello,
    How can I do this?

    https://www.ghostofatale.com/dynamic-vegetation-system

    With your asset pack?
     
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    not really seithcg uses dynamic bone.
     
  6. cratica

    cratica

    Joined:
    Dec 11, 2016
    Posts:
    59
    Hello, I have added various trees/grass/plants in my scene and it works fine in the editor. Version 2022.3.9f1.

    However, when I try to build to Android/Oculus, I get quite a few errors.

    Shader error in 'Hidden/Lux Personal Internal-DeferredShading': undeclared identifier 'sampler_CameraDepthTexture' at Library.cginc(160) (on gles3)

    Shader error in 'AFS/Foliage Shader': Non system-generated input signature parameter () cannot appear after a system generated value. at line 314 (on gles3)

    Shader error in 'AFS/Foliage Shader': Non system-generated input signature parameter () cannot appear after a system generated value. at line 382 (on gles3)

    Shader error in 'Hidden/WS_BlurNormals': syntax error: unexpected token 'float4' at line 32 (on d3d11)

    Shader error in 'Afs_Internal-DeferredShading': undeclared identifier 'sampler_CameraDepthTexture' at v5/Shaders/Resources/Afs_DeferredLibrary.cginc(158) (on gles3)

    Shader error in 'Particles/Standard Surface': Internal error communicating with the shader compiler process. Please report a bug including this shader and the editor log.

    Can you please help me resolve these?

    Thank you
     
    Last edited: Sep 25, 2023
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    do you use deferred shading with vr? that should look jaggy like hell!
    if you use forward rendering just remove the shader form your project.

    which version do you use? 4 or 5?
     
  8. cratica

    cratica

    Joined:
    Dec 11, 2016
    Posts:
    59
    Thank you for responding. I am using version 5. Do you have a shader that lets the foliage bend in the wind but is compatible with forward rendering?
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    all shaders should work in forward as well?!

    however:
    In case your camera uses forward rendering and you have any depth based image effects applied (like ssao) you have to assign the Afs_Camera-DepthNormalTexture shader in Edit -> Project Settings -> Graphics.
     
  10. cratica

    cratica

    Joined:
    Dec 11, 2016
    Posts:
    59
    "all shaders should work in forward as well?!"

    Hmm, ok well that is great news. I just assumed they would not because after I changed my project from deferred to forward rendering, the shaders started giving me errors. So I looked at the AFS v5 asset in the store again and only saw references to deferred rendering so again, I assumed that's what was required.

    Here are the errors the project gives me. Can you please tell me what I need to do to fix this? I'm sure it's not your asset, its something I've done wrong, just don't know what it is. Thank you very much!

    Shader error in 'AFS/VegetationStudio/Foliage Shader': Non system-generated input signature parameter () cannot appear after a system generated value. at line 289 (on gles3)

    Shader error in 'AFS/VegetationStudio/Foliage Shader': Non system-generated input signature parameter () cannot appear after a system generated value. at line 314 (on gles3)

    Shader error in 'AFS/VegetationStudio/Foliage Shader': Non system-generated input signature parameter () cannot appear after a system generated value. at line 382 (on gles3)

    Compiling Subshader: 0, Pass: FORWARD, Vertex program with DIRECTIONAL FAR_CULL_ON INSTANCING_ON LOD_FADE_CROSSFADE STEREO_MULTIVIEW_ON TOUCH_BEND_ON
    Platform defines: SHADER_API_GLES30 SHADER_API_MOBILE UNITY_ENABLE_REFLECTION_BUFFERS UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HARDWARE_TIER1 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_NO_CUBEMAP_ARRAY UNITY_NO_DXT5nm UNITY_NO_FULL_STANDARD_SHADER UNITY_NO_RGBM UNITY_NO_SCREENSPACE_SHADOWS UNITY_PASS_FORWARDBASE UNITY_PBS_USE_BRDF3
    Disabled keywords: AFS_PRESERVELENGTH DIRLIGHTMAP_COMBINED DYNAMICLIGHTMAP_ON EFFECT_BUMP FOG_EXP FOG_EXP2 FOG_LINEAR GPU_FRUSTUM_ON LIGHTMAP_ON LIGHTMAP_SHADOW_MIXING LIGHTPROBE_SH PROCEDURAL_INSTANCING_ON SHADOWS_SCREEN SHADOWS_SHADOWMASK UNITY_ASTC_NORMALMAP_ENCODING UNITY_COLORSPACE_GAMMA UNITY_ENABLE_DETAIL_NORMALMAP UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_FULL_HDR UNITY_LIGHTMAP_RGBM_ENCODING UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_PBS_USE_BRDF1 UNITY_PBS_USE_BRDF2 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_VIRTUAL_TEXTURING VERTEXLIGHT_ON
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    this is the shader for vegegtation studio. and it uses some instancing code from vs - which might not be supported on gles3. if you do not need it just remove that shader from your project. if you use vegetation studio you may ask lennard for some advice.
     
  12. cratica

    cratica

    Joined:
    Dec 11, 2016
    Posts:
    59
    yes, I use that shader in the game. It's for the most prominent objects in the game that the game is about. Who is lennard? thx
     
  13. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
  14. cratica

    cratica

    Joined:
    Dec 11, 2016
    Posts:
    59
    Ok thanks. For what its worth, it also gives the same errors when using Vulcan.
     
  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    can you send me the compiled version of the shader so i can look into line 289?you can also just post line 289 here :)
     
  16. cratica

    cratica

    Joined:
    Dec 11, 2016
    Posts:
    59
    I changed to Vulcan and removed the deferred shader so I only have the issues with the foliage shader. This same error appears on line 314 and 382. There is no line 314 or 382. The last line in the code is 245.

    Shader error in 'AFS/Foliage Shader': Non system-generated input signature parameter () cannot appear after a system generated value. at line 314 (on gles3)
    Compiling Subshader: 0, Pass: DEFERRED, Vertex program with INSTANCING_ON LIGHTPROBE_SH STEREO_MULTIVIEW_ON UNITY_HDR_ON
    Platform defines: SHADER_API_GLES30 SHADER_API_MOBILE UNITY_ENABLE_REFLECTION_BUFFERS UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HARDWARE_TIER1 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_NO_CUBEMAP_ARRAY UNITY_NO_DXT5nm UNITY_NO_FULL_STANDARD_SHADER UNITY_NO_RGBM UNITY_NO_SCREENSPACE_SHADOWS UNITY_PASS_DEFERRED UNITY_PBS_USE_BRDF3
     

    Attached Files:

  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you have to press "show generated code" to view the source of the shader created by unity. it is a surface shader. so unity takes over when it comes to creating the real code.
     
  18. cratica

    cratica

    Joined:
    Dec 11, 2016
    Posts:
    59
    Did some searching on the internet and one person gave his workaround and oddly, it works for me. If I compile again after it compiles with errors, the 2nd time it will compile without errors. It takes 2x as long of course but at least I can get it to build while waiting for a proper fix. Here is the generated code of the two problem areas. (the entire length of the generated code is 214,000 lines which is insane so can't post the whole thing of course)

    line 314 is #ifndef LIGHTMAP_ON


    // vertex-to-fragment interpolation data
    // no lightmaps:
    #ifndef LIGHTMAP_ON
    // half-precision fragment shader registers:
    #ifdef UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS
    #define FOG_COMBINED_WITH_TSPACE
    struct v2f_surf {
    UNITY_POSITION(pos);
    float2 pack0 : TEXCOORD0; // _MainTex
    float4 tSpace0 : TEXCOORD1;
    float4 tSpace1 : TEXCOORD2;
    float4 tSpace2 : TEXCOORD3;
    fixed4 color : COLOR0;
    #if UNITY_SHOULD_SAMPLE_SH
    half3 sh : TEXCOORD4; // SH
    #endif
    UNITY_LIGHTING_COORDS(5,6)
    #if SHADER_TARGET >= 30
    float4 lmap : TEXCOORD7;
    #endif
    UNITY_VERTEX_INPUT_INSTANCE_ID
    UNITY_VERTEX_OUTPUT_STEREO
    };
    #endif



    The 2nd error is line 382, which is "float4 tSpace1 :TEXCOORD2;


    struct v2f_surf {
    UNITY_POSITION(pos);
    float2 pack0 : TEXCOORD0; // _MainTex
    float4 tSpace0 : TEXCOORD1;
    float4 tSpace1 : TEXCOORD2;
    float4 tSpace2 : TEXCOORD3;
    fixed4 color : COLOR0;
    float4 lmap : TEXCOORD4;
    UNITY_FOG_COORDS(5)
    UNITY_SHADOW_COORDS(6)
    UNITY_VERTEX_INPUT_INSTANCE_ID
    UNITY_VERTEX_OUTPUT_STEREO
    };
     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
  20. cratica

    cratica

    Joined:
    Dec 11, 2016
    Posts:
    59
    So yea, first time through it gives those errors. Recompile again and it will compile without errors. If I make any changes to project, have to do it all again, double compile to get it to build.
     
  21. Y07A

    Y07A

    Joined:
    May 12, 2019
    Posts:
    4
    Hi, I bought your Advanced Foliage Shaders v.5 asset, expecting it to improve unity's built-in terrain tree billboard system. The asset seems to use his own cginc to manage billboard instead of using TerrainEngine.cginc and his own BillboardTree shader, which is great, but there is still this built-in "Imposter" texture on the billboard that Unity made very bad.
    So my question: Is there anyway to correct this effect, or to provide a flat texture of the tree to the billboard to avoid using those imposters, with your asset ?

    I made a post on reddit showing those weird billboards I'm having:
    https://www.reddit.com/r/Unity3D/comments/17ff0s6/how_to_prevent_these_trees_billboards_to_rotate/

    Edit: I managed to setup the Afs setup script and now I have a nice grass bending, and this also improved billboards rotations, but now they are stretching when the camera is looking down or up, and the imposter effect still rotate a little.
     
    Last edited: Oct 26, 2023
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    in your video it looks as if the afs billboard correction is not activated.
    you have to enable it in the afs setup script.
    it corrects the billboards to a certain degree (adjustable). but if you go crazy they may look odd.

    from the docs:

    Tree and Billboard Settings

    Billboard Start The distance (from camera) at which 3D tree objects will be replaced by billboard images. Must fit "Billboard Start" in your “Terrain Settings”.

    Fade Length Distance over which trees will transition between 3D objects and billboards which must fit the "Billboard Start" in your “Terrain Settings”.
    If a tree has fully transitioned to 3D shadows casted by the tree, specular lighting and translucency will fade in over a distance which equals the specified “Fade Length”.
    Find out more >

    Tint Color Usually trees are simply tinted with black if you set the “Color Variation” > 0.0 while painting trees. You may replace this color by any one you like using this color field.

    Align Billboards to Camera Check this to get camera aligned billboards. If unchecked you will get back the "always upright oriented" billboards. All enhanced fading features for mesh trees (wind, shadows, light) still will be present.
    Please note: Using perspectively aligned billboards might look pretty strange within the editor as the script has to pass some parameters from the "current" camera to the shader. In order to give you a correct preview in the "game view" the script will only look for a camera tagged as "MainCamera". All other cameras will be ignored. So if you need a second camera (e. g. for rendering reflections) you will have to update the shader parameters according to the second camera before rendering. Look for the block:

    Shader.SetGlobalVector("_AfsBillboardCameraForward", Vector4( CameraForward.x, CameraForward.y, CameraForward.z, 1));

    to find out how to set up the needed parameters correctly.

    Angle Limit Defines the angle (when viewed from above) the billboard shader will fade to the "classical" upright oriented billboards in order to reduce distortion artifacts. The standard value is "30".

    Billboard Fadeout Length Instead of simply culling the billboards beyond the "Tree distance" specified in the terrain settings you may define a length over which the billboards will be smoothly faded out.
    Please note: This feature needs the “AfsBillboardTree Transparent” shader to be be activated. Do so by removing the “AfsBillboardTree CutOut v5.shader” from the project (or renaming it to “._shader”) and renaming “AfsBillboardTree Transparent._shader” to “AfsBillboardTree Transparent.shader”. You will have to restart Unity to make it pick up the new shader.
     
  23. Y07A

    Y07A

    Joined:
    May 12, 2019
    Posts:
    4
    Thanks, Unfortunately, even with the correction it still look bad in my game, by displaying the bounds of the billboard (removing clip() in tree shader) I can see that the billboard is correctly rotated, but there is still this "rotating texture" or "impostor effect" inside it. Is there a way to prevent this impostor effect in the billboard? Or is it a Unity unchangeable thing.
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    not that i know: billboard textures will be recreated if the camera rotates for more than a certain threshold.
    billboards in vr do not suffer from this as they use a different technique but i do not know how to make unity use these instead...
    you could go with relativly slow LOD trees instead. grab the free "Conifer" asset (https://assetstore.unity.com/packages/3d/vegetation/trees/conifers-botd-142076) to get a proper billboard shader. all you have to do then is to create the billboard atlas...
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    btw. i did a quick test with a fov of 90°: the billboards get stretched within their quad. but the quad at least is properly aligned.

    billboards.png
     
  26. Y07A

    Y07A

    Joined:
    May 12, 2019
    Posts:
    4
    This is exactly what I was looking for, It was a bit of pain to make those atlas, but after a bit of coding and
    adaptation, I can now automatically generate them.
    Plus, this doesn't impact my game performances much more than the terrain billboard system, and is working with lighting.

    Thank you very much for this !