Search Unity

Advanced foliage shader [released]

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

  1. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I got the error to go away by adding Setup AFS to the scene first. But rendering seems all wrong. Here is rendring in your demo scene:

    upload_2017-12-28_14-9-1.png

    and Here is what I get in VS scene:

    upload_2017-12-28_14-9-22.png

    Looks all washed out.
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    no. they use the regular afs shaders – but for vs you need the specially tweaked vs shader from the afs package.
    and as written in the documentation: these shaders do not support instanced drawing but only instanced indirect drawing. so please make sure that you have selected the proper render mode in vs.
     
  3. Marcurios

    Marcurios

    Joined:
    Nov 19, 2012
    Posts:
    88
    I can't get the tree creator to accept the deferred optimized shaders, or any other tree shader for that matter.
    I simply get the red circle with exclamation poit warning and the tree won't render with the new shaders, it just refuses them.

    My project has linear lighting, deferred rendering, i looked at how to use them in the readme's, did what it said, but tree creator doesn't like them.

    I remeber i tried a few years ago, when i actually bought these shaders, also searched for days with google to see if i could find a way to make them work, but never could, so i just considered it lost money, but i desparately need some good shaders, otherwise my project will always look like it's made in 2004.

    You know why tree creator is so damn stubborn ?
    I noticed that the shaders have the word Leaves in it and i see that others CAN use it with tree creator, so i assume the neccesary lines in the shader for the tree creator to accept them are there too, so why on earth is tree creator messing with me ?

    I tried with multiple Unity versions, outcome is always the same, it does render something when i apply them, but tree creator ceases to function, nothing works anymore cause it wants me to first reapply the standard tree or bark shaders, i tried exactly as is explained in the readme to no avail.
     
    Last edited: Jan 1, 2018
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you do not assign the optimized shaders manually – at least not to the nodes of your tree.
    from the docs:

    Assign the shaders
    The recommended way is to assign the "AfsTreeCreatorBark" and "AfsTreeCreatorLeaves" shader to the base materials of your trees—so the tree creator will automatically assign the corresponding "optimized" shaders as soon as you hit "update tree".
    Base materials are the materials you e.g. assign to the branch nodes (“Branch Material” and “Break Material”) within the tree creator inspector or which are assigned to the leaf meshes you use as prototypes for adding mesh based leaves like shown in the screenshot.



    Tip: Please have a look at the “Conifer [TreeCreator]” tree which ships with the package to find out more.
     
    hopeful likes this.
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    the afs tree shaders are not supposed to work with vs. they are focused on smooth blending between mesh tree and unity billboard – which is a bit worthless as vs uses its own billboards. i might consider writing a vs compatible version though.
     
    blitzvb likes this.
  6. blitzvb

    blitzvb

    Joined:
    Mar 20, 2015
    Posts:
    284
    it would be great cause VS billboard is not as good as AFS (based on video)
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    oh, that will not work... afs billboards are based on the built in ones – which need unity to render the trees.
    in case you use vs to render the trees vs will also have to render the billboards.
     
  8. blitzvb

    blitzvb

    Joined:
    Mar 20, 2015
    Posts:
    284
    bummer. Any plan to add that to ATG? (As far as I understood is a bit like VS but only for grass) so more a ATTree ;)
     
    Last edited: Jan 1, 2018
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    atg is all about grass. it does not handle trees – and it will not as trees need a completely different approach.
    there are already 3 systems which handle trees: vegetation studio, alttrees and critias foliage. who needs a forth system?
     
    blitzvb likes this.
  10. Marcurios

    Marcurios

    Joined:
    Nov 19, 2012
    Posts:
    88
    OK, i found it, and you should update the Tree Readme to be more readable actually, cause somewhere between all the info there is this line "To do so assign the "AfsTreeCreatorBarkDeferred" shader to your bark base material so that the optimized material will use the "AfsTreeCreatorBarkDeferredOptimized" shader."

    That is actually the info that is very important in this section;
    "
    2.2. Assign the shaders

    The regular way would be to assign the "AfsTreeCreatorBark" / "AfsTreeCreatorBarkDeferred" and "AfsTreeCreatorLeaves" Shader to the base materials of your trees—so the tree creator will automatically assign the "Afs Optimized" shaders as soon as you hit "update tree".

    In case you want to assign the shaders manually please follow the instructions below:

    - Create 2 new materials and using the "AfsTreeCreatorBarkOptimized" / "AfsTreeCreatorBarkDeferredOptimized" respectively the "AfsTreeCreatorLeavesOptimized" shader.
    - Find and assign the textures of your tree which are generated by the tree creator.
    - Find the prefab of your tree, click on the root node and replace "Optimized Bark Material" and "Optimized Leaves Material" with the new materials."

    So if anyone wants to install the shaders manually from your description, or has been reading the notification sections casually, he will not get them to work with your manual unless he reads the entire manual twenty times probably to notice that one very important line, cause you need to make 4 materials, not 2, 2 with the Bark & Leaves deferred for the branches and leaves, and 2 for the base/root of the tree with Bark & Leaves deferred Optimized, or it will not work.

    That has literally gave me headaches to find that, cause if i would simply do what you said in your reply, i would still not have them working, so when you reply to people, be sure to tell them precisely how it's done, or update your manual.
     
    Last edited: Jan 2, 2018
  11. Marcurios

    Marcurios

    Joined:
    Nov 19, 2012
    Posts:
    88
    Another question, is it possible to make the atlas render at 2048px ?
    Or do you just pass the textures on to the built-in restricted Unity Tree Creator atlas making routine ?
    If i use large fronds on branches to make cedar trees, the quality is horrible cause it rezises my 1024 base texture to 384x512 texturespace.
    Ofcourse not your shaders that are responsible for this, also not their purpose, i understand that, cause it's just how tree creator works, but if you could pull that off, quality of the trees from Tree Creator would be sublime.
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    sorry, but i think i have been very precise. and actually the workflow simply matches the one of the tree creator.

    not that i know... but you can manually "rebuild" the atlas in photoshop at any resolution you want.
    doing it by script would be somehow cumbersome as the tree creator might combine your textures in a lot of different ways...
    btw.
    this sounds as if you were using 3 textures which in case you do not rescale the atlas manually really gives you horrible results at least on the leaves. so i always use manually modeled leaf geometry and a custom 1024x1024 texture atlas for the leaves (e.g. green and dry).
     
  13. Marcurios

    Marcurios

    Joined:
    Nov 19, 2012
    Posts:
    88
    Well, since i know now, it doesn't matter to me, i was only trying to get you to see that you where inprecise when it comes to writing manuals, but nevermind, it's your work, if you want to have to explain multiple times to people because the manual could be written better, then that's your thing, not mine.

    I know, that's what i'm doing right now, but that won't work in Unity as far as i know, since i export the trees as fbx and model them further in Maya and 3DSMax and retex them in Photoshop, it's not a problem, but if i ever want to use them in Unity, they look like poop, cause Unity rezises and rearranges them whenever you change a slider.
    It might probably work when you consider the tree ready and never touch it again, i don't know, cause i never tried that.
    I was kinda hoping your shader use a better resolution from the get go, but they don't, so at this point they're useless to me, cause i export the trees and use them in another engine.

    Oh? i use meshes too, but Unity tree creator simply includes the mesh textures into it's atlas, if i use 1024 or 2048, doesn't matter whaty size, the tree creator makes a 1024px atlas from all the parts in the tree, so if i use fronds, branches, meshes, and regular leaves combined to make up 1 tree, you're left with a 1024px atlas, from which 80% is bark, and the remaining 20% holds leaves, meshes, and fronds textures, and they arent even recognizable anymore.
    So i'm again assuming that you rebuild those textures and only use them on a tree you'll consider ready and never touch again, cause with me it simply get's resized with every change i make.
     
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    do you mean i should add the section starting with "In case you want to assign the shaders manually please follow the instructions below:
    - Create 2 new materials and using the "AfsTreeCreatorBarkOptimized" / "AfsTreeCreatorBarkDeferredOptimized" respectively the "AfsTreeCreatorLeavesOptimized" shader.
    ... "
    if you think this helps a can do that of course.

    we are talking about shaders. in order to calculate a high res atlas you need additional scripts – or just a simple photoshop template and a few mouse clicks.

    unfortunately the tree creator always produces an atlas of 1024x1024. but in case you have 2 leaf textures which fit into one single 1024x1024 texture and only use custom meshes for the leaf planes you can create one single leaf material and control the textures the different meshes will pick up just by the uvs. this way you will get 2 512*1024 textures to be placed on the atlas (1 bark + 1 leaf texture) – and not 3 (1 bark + 2 leaf textures).
    actually you can place even more leaf textures into one single atlas like one main texture covering 75% of the available space using the rest to place some smaller dry twigs, a small branch, mushrooms for the tunk, small blossoms and some ivy leaves.
    if all this is fixed in your custom atlas you will never have to rework it after any change – because for the tree creator it is just 2 textures that it combines: one for the bark and one for all "leaves".
     
  15. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    501
    hi

    Since I'm using Map Magic to place vegetation, I'm wondering:
    1) Does AFS in any way improve/modify standard terrain grass? Performance wise or visually?
    2) Same question, but for Speedtree

    Thanks
     
  16. Marcurios

    Marcurios

    Joined:
    Nov 19, 2012
    Posts:
    88
    I know you must be thinking what an ass, but it would indeed be 100 times better if you include that info into the 2.2 manual install section, and not somewhere hidden 2 pages earlier in a tip section, that knowledge should be together, and it would assure that it works immediately if they follow that, and i assure you that i read the manual multiple times, but just read over that one sentence, and when i asked you, you didn't gave me precise info, aside from the tip to study your own made tree creator conifer mesh, cause that did the trick, and then i noticed that there where 2x2 materials used, and not just two like you said, and after that i noticed it in the manual, so yeah, i'm sure it would be better for new users, especially since i have a reasonable amount of experience and could not get it to work cause i was fed wrong info on multiple occasions (by searching on google and even out of this forum).

    Well i'm no shader virtuoso, that's you, if i where, i would have wrote my own and have that knowledge, but i do not, i'm a modeler and texture artist, not a scripter or shader writer, i can script reasonable, but not well enough to call myself a scripter, i could probably adapt a script to my prefs if i had it though, not a total noob.

    Do you know which script renders the atlas by any chance ?
     
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    visually yes (by adding translucency), performance wise not as it is just a shader... if you are looking for "faster" rendered grass you may have a look into the advanced terrain grass or vegetation studio.
    afs does not handle speedtrees at all. alttrees, critias foliage and vegetation studio do.
     
    iddqd likes this.
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    it took a while but now i am pretty sure that you are referring to the documentation of version 4 – not 5, right?
    regarding the tree materials: the easiest way is to assign the afs NON optimized shaders to the base materials you use to create the tree. then unity will automatically create optimized materials using the afs optimized shaders.
    unfortunately these optimized materials are not editable – which is the reason why i made the optimized shaders not to be hidden (like the original ones) so you can create the optimized materials manually and e.g. use high res textures.

    some script deep inside the unity engine which does not have any public api...
     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    they work perfectly for me using dx9. what is your problem?
     
  20. totrider

    totrider

    Joined:
    Jul 25, 2014
    Posts:
    13
    Not sure how this happened, but after after i realized i had some missing links in my AFS setup for the terrain plate, i added the terrainplate and all my trees look like ass now.

    Furthermore, i earlier had this issue: https://i.imgur.com/7AhTG3H.png which i tackled by deleting the associated script as it seemed to be non-dependant to the actual shader.
    This is what the trees looked like just before i did the aforementioned: https://i.imgur.com/o7Aglba.jpg

    What it looks like, is that there is some ghost-like/translucency on top of the original mesh, causing the flickering as it moves asynchronous to the main mesh. You can see it a bit better in this screen: https://i.imgur.com/k77Pkmt.png

    I recently upgraded from AFS 4 to AFS 5, which could indicate something in the new features might be messing with my stuff?

    For reference, this is what my models look like in Blender: https://i.imgur.com/VOSyTpn.png

    EDIT: i just tried something really simple which i thought might cause the problem.... and it worked. Can you add support for light cookies applied to directional lights? we are using a noise light cookie to simulate clouds, which apparently causes the ugly artifacts... Also still have the editor issue though.

    EDIT 2: after fiddling around a bit, turns out that error in the console is due to a conflict with my own asset importer script. I am not good at programming, so some help in resolving this would be neat.

    Code (CSharp):
    1.  using UnityEngine;
    2. using UnityEditor;
    3.  
    4. public class AssetImporter : AssetPostprocessor
    5. {
    6.      void OnPreprocessTexture()
    7.      {
    8.          TextureImporter textureimporter = assetImporter as TextureImporter;
    9.          Object texture = AssetDatabase.LoadAssetAtPath(textureimporter.assetPath, typeof(Texture2D));
    10.          if (!texture)
    11.          {
    12.             //textureimporter.textureFormat = TextureImporterFormat.AutomaticTruecolor; // deprecated
    13.             textureimporter.maxTextureSize = 1024;
    14.             textureimporter.compressionQuality = 100;
    15.          }      
    16.      }
    17.     public void OnPreprocessModel()
    18.     {
    19.         //ModelImporter modelImporter = (ModelImporter)assetImporter;
    20.         ModelImporter modelimporter = assetImporter as ModelImporter;
    21.  
    22.         Object mesh = AssetDatabase.LoadAssetAtPath(modelimporter.assetPath, typeof(Mesh));
    23.         if (!mesh)
    24.         {
    25.             modelimporter.importLights = false;
    26.             modelimporter.importCameras = false;
    27.             modelimporter.importVisibility = false;
    28.             modelimporter.generateSecondaryUV = true;
    29.             modelimporter.importMaterials = true;
    30.             modelimporter.materialName = ModelImporterMaterialName.BasedOnMaterialName;
    31.         }
    32.     }
    33. }
     
    Last edited: Jan 6, 2018
  21. Marcurios

    Marcurios

    Joined:
    Nov 19, 2012
    Posts:
    88
    Correct, i am talking about the version 4 shaders.
    I clicked at the go to forum on the v4 page, so i assumed this was a thread for v4, but from your answer i derive that it's a thread for both version probably.

    Got it all working now, one thing i find a bit unneccesary and hindering from Unity treecreator is the double sided geometry, if i export them to maya they look like crap, i always have to take the double faces out, is rendering double sided through shaders more GPU intensive then double faced geometry or something like that ?
    And can i alter the shader to render double sided ?
     
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    double sided rendering was not available when the tree creator was introduced.
    you may have a look at the foliage shader: you will need vface --> IN.facingSign to get proper normals.
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    unity claimed to have unified all transform matrices as far as instanced rendering is concerned – but unfortunately that does not seem to be the case which causes that ghosting effect: unity 5.4. and 5.5 are fine, 5.6. may bug, but i am unsure about 2017.
    so in case you have multiple lights in forward the rendered geometry might slightly be off in the different passes.
    the foliage shader addresses this by letting you disable "preserve length" in the setup script.

    i haven't noticed any problems using light cookies. i only get artifacts if there are multiple lights. are you sure that there are no multiple lights in your scene?
     
  24. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    562
    I have multiple scenes in one project and not all of them use AFS for rendering vegetation. The problem is AFS takes over all aspects of the grass and detail mesh wind movements. Without an AFS prefab in the scene regardless if its being used or not still is required for wind movement. If it's not in the scene you will get no wind movement for unity grass and detail meshes.

    Is there a way in the scene's that do not use AFS to let unity's legacy wind for grass and detail meshes be left alone and not require an AFS prefab just for the wind to happen?
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    unity's grass shader unfortunately can't be replaced – it has to be overwritten.
    that is what happens if the corresponding afs shader is present in your project.

    you can either remove it from your project. then grass and details using the grass shader on the terrain will always be rendered using the built in shader.

    or you could edit the afs grass shader, make it multi compile and add a version that takes the original inputs from the terrain engine... then you would have to enable a global shader keyword in the scenes that do not have the afs set up script to make the shader fall back to the built in wind animation. cumbersome.

    the easiest way however is just to add the afs setup script to all your scenes – as i do not see any reason why you can't or should not do so.

    is there any reason why you have not added to all your scenes?
     
  26. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    562
    Ok so if I drag in the AFS prefab and only use it so that the grass and detail meshes have wind that doesn't eat up any uneeded resources on the cpu?

    I was figuring if all I needed was wind then having the AFS prefab in there with all it's other options is a waste of resources or calculations that is not doing anything.
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    not really, maybe 0.1ms on the cpu. you may however create a stripped off version of the script which does not update the sh lighting for the billboards e.g. but only calculates the wind for the grass and details.
     
  28. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    562
    Good to know. Thanks for the info.
     
  29. boysenberry

    boysenberry

    Joined:
    Jul 28, 2014
    Posts:
    365
    Hello,

    I am planning on using this with Vegetation Studio (thanks for the dedicated shader), UniStorm and multiple terrains. Are there any issues with using UniStorm or multiple terrains that I should be aware of, in particular, wind and multiple terrains. I am hoping to use AFS with MapMagic as well, so if there is anything you know of with that as well I'd be grateful for a heads up.


    Edit:
    It would seem Unistorm has it's own wind zones, one for normal and one for wind. If nothing else I could try to create an interface between the two using a script. I will ask over on that thread for advice as well.

    Is it possible to add the Setup Afs script to two wind zones that exist already (the Unistorm wind zones)? Only one is active at a time. They are standard unity wind zones like the GO the Setup Afs prefab uses. To me that would seem to be the simplest solution if it will work.

    Thanks in advance,
    Boysenberry
     
    Last edited: Jan 17, 2018
  30. zmaxz

    zmaxz

    Joined:
    Sep 26, 2012
    Posts:
    143
    Unity5.65 AFS5.075

    As i click the tree(Conifer [TreeCreator]),i get this error.

    Material doesn't have a float or range property '_TranslucencyViewDependency'
    UnityEngine.Material:GetFloat(String)
    TreeEditor.TreeEditor:GUIMaterialSlider(Material, String, String) (at C:/buildslave/unity/build/Extensions/TreeEditor/TreeEditor/TreeEditor.cs:1997)
    TreeEditor.TreeEditor:InspectorRoot(TreeData, TreeGroupRoot) (at C:/buildslave/unity/build/Extensions/TreeEditor/TreeEditor/TreeEditor.cs:2116)
    TreeEditor.TreeEditor:OnInspectorGUI() (at C:/buildslave/unity/build/Extensions/TreeEditor/TreeEditor/TreeEditor.cs:2437)
    UnityEditor.DockArea:OnGUI()
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    f**k!
    sorry, i will fix this as soon as possible.
    meanwhile you may edit the "AfsTreeCreatorLeavesOptimized (instanced) shader and add:
    _TranslucencyViewDependency ("View dependency", Range(0,1)) = 0.7
    to the properties.
     
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    having 2 afs setup scripts in your scenes sounds quite complicated – as you will have to keep them in sync somehow... but it might work.
     
    boysenberry likes this.
  33. AntonBertelsen

    AntonBertelsen

    Joined:
    Oct 13, 2014
    Posts:
    37
    Hi there. I'm just curious as to what the new SRP will mean for AFS, ATG and your other packages.
    Cheers.
     
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    we will see, when the hd render pipeline is published.
    translucent lighting already runs in the current lw srp.
     
  35. boysenberry

    boysenberry

    Joined:
    Jul 28, 2014
    Posts:
    365
    Thanks, I will let you know if I can get it working. I'll see if the UniStorm devs can help a little with getting hooks into the wind zones. Basically one zone for normal winds one for storms with the values ramped up. I think they switch one to the other as storms ramp up or diminish.
     
  36. ibbybn

    ibbybn

    Joined:
    Jan 6, 2017
    Posts:
    193
    Anyone using this with Psychose Next Gen Soft Shadows ? ( Unity 2017.3.0f3 )
    Since the last 2 versions of NGSS the foliage shaders don't compile correctly.
    Since all the other shaders compile correctly I think it' must be something which these shaders do differently.
    I found a way of compiling correctly by taking out quite some stuff in the UnityShadowLibrary.cginc but that makes the shadows look crap. Anyone else have the same problem or is it on my side?

    EDIT: Seems Unity stills tries compiling d3d9 even in 2017.3 causing the problem even with 3.5 shader target.
     
    Last edited: Jan 20, 2018
  37. totrider

    totrider

    Joined:
    Jul 25, 2014
    Posts:
    13
    Sorry for the late response to your reply, been busy lately. I can confirm that i am still having issues with light cookies with the latest version of AFS5 with Unity 2017.3.0f3

    Tried to single out the problem in a new scene with the bare minimum, making sure that the preserve length option is disabled.



    I am also having issues with the vertex paint not behaving anymore, after i updated from AFS4 to AFS5, my trees trunks started fluttering as if they had edge fluttering. My guess is that it is because Blender is unable to use alpha for vertex paint (something about it being used for something else internally), thus creating mediocre results with your shaders. So if i understand the documentation, it is not possible to paint the secondary bend with Blender. Due to how our whole model pipeline works, it is also not possible to paint the vertex colors in a separate program. It is also extremely difficult to do vertex paint in the first place, you need to use a value of 0.001 increments for the vertex paint, so you can't see what you are doing with the main bend as it just looks like black. Using the built in tool is possible, but i would rather be able to have full control of where the trees should bend.

    So it is not because it looks too bad, from a distance (when not using light cookie), but it would be nice if it worked as intended.
     
  38. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    sorry if i do not really get your point.
    of course i get the point concerning light cookies and will have a look into it.
    but when it comes to vertex colors – well, i am not a blender user. i did it once (many years ago) when there was a gradient plugin for blender. but i do not think thta it works in he current version.
    in order to paint gradient it use modo which gives you super fine control over the gradient, fall off etc. – i use the foliage tool for primary and secondary bending or i use the custom tree – which officially supports afs since the last update and probably gives you best control.

    what would it need to make it work wth your pipeline/blender? and importer script wich would let you scale down vertex colors? so you can have nice contrasts in blender and smooth bending in unity?
    or just 2 sliders in the shaders which would allow you to fine tune primary and secondary bending?

    actually you already have these possibilities as the multiply factors in the afs set up script might be used just to mimic this. simply apply high contrast vertex colors in blender, then adjust main strength and turbulence strength for the foliage shader in the set up script.

    edit: i just tested light cookies in 2017.3. using forward and deferred. both without disabling "preserve length": i did not get any ghosting using the "cast" demo scene and quite strong wind – even with 2nd point light casting real time shadows.
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    that is how it looks like for me, if i enable light cookies.

    afs_noghosting.PNG
     
  40. totrider

    totrider

    Joined:
    Jul 25, 2014
    Posts:
    13
    To start, yes, being able to simply scale the effect of the vertex colors within the shader as a slider would be super neat, i use this method myself in most of my own shaders created with Shader Forge, as it enables the user to make adjustments a lot faster, and see results right away. Naturally, having a streamlined pipeline is still key, as well as keeping everything consistent. Not sure what is best performance/quality-wise though. I suspect that it is always better to bake it down when possible, especially in this case, as you need the mesh with the vertex colors regardless. I think being able to apply a keyword to a folder/file-name and let a custom export script take over, could make it easier/faster to make adjustments, instead of having to set up temporary meshes in another scene just to adjust the vertex colors.

    Now, sorry if i haven't been thorough enough, let me try to expand upon the situation then with some more images and gifs.

    vertex paint on "pine_01a" mesh. You can see that the tree trunk is practically black, so it shouldn't sway a lot. I used very slight increments towards the tip of the tree, so you can't see any color transition with the naked eye, only if you know that the vertices are painted. This makes it impossible to see if a tree trunk has been vertex painted correctly, if at all.


    left: "pine_01a" mesh with no modifications via AFS tools.
    right: "pine_01a_modified" mesh, using the "set bending" tool.
    both vertex paint methods produce a tree trunk that warps horribly.
    low value increments.gif

    vertex paint on a test mesh "pine_01_TESTING". the values on the trunk go from 0 to 0.2 in only the blue channel towards the tip. Values on the "leaves" go from a value relative to where they are closest to the trunk, with a small increment towards the outer ends.


    left: "pine_01_TESTING" mesh with no modifications via AFS tools.
    right: "pine_01_TESTING_modified" mesh, using the "adjust vertex colors" tool.
    Still horrible warping is created because it isn't possible to paint alpha vertex colors in Blender (is my understanding). If i use the "adjust vertex colors" tool, and adjust the secondary bending to 0, no bending occurs at all. (which i assume is expected).
    workable value increments.gif

    reference tree that was vertex colored and was working properly with AFS4 without having to use any tools within Unity.


    reference tree creates horrible warping as well.


    warping quickly becomes extreme when adjusting wind speed above 1


    at increased wind speed, i don't get a proper bend with either of my methods either, just horrible warping.


    warping with increased wind speed
    higher wind speeds.gif


    So to clarify on how our pipeline works:
    All the tree meshes exist together within a Blender "master" file. Each tree mesh is then linked to from an individual Blender file, that then only contains a given tree. What i would like to avoid, is the lack of control associated with some of the tools provided within AFS, not to mention the extra time required to set up and store the modified meshes, then also bug-hunt any weird bending by going all the way back in the pipeline to the master file.
    Preferably it would be: master -> child -> set up prefab with colliders, materials, scripts etc. if a change has to happen for a set of meshes, they are changed in the master file, then we just have to re-import the children to get the updated meshes in our prefabs. This is a lot more consistent and faster than having to manually export each individual tree whenever a change has to happen. This pipeline also goes for other stuff like houses made of modular pieces and such. There are many more benefits to this approach, and since we can't change how it works, i would like to see if another solution is possible.


    regarding the secondary bend:
    I don't know if there is any other solution than to have a variation of the legacy bend (for instance) that doesn't use the alpha color for anything. I am not even sure exactly what secondary bending does differently than edge fluttering. I can only read that it affects an up and down movement? The optimal solution for Blender users, would be the ability to actually paint alpha, no doubt about that. But seeing as that has nothing to do with your shaders, we would have to rely on other users making a hacky solution.

    regarding ghosting:
    Still experiencing it myself ofc. Tried to open the "cast" scene and insert the light source. I didn't experience ghosting on anything... apart from the conifer.


    texture setup for light cookie. It is literally just a cloud noise created in PS, then saved as a .png and set up in Unity as a cookie.


    directional light setup


    new created directional light source with no settings changed and applied a standard asset flashlight cookie


    could the ghosting be caused by some global project setting maybe? wouldn't know which one could do it though... also, doesn't seem to make a difference if you look through game camera or scene view camera.

    current usability of the shaders:
    we can still use the AFS5 shaders because you don't see the tree trunks in our game that much. It is a top down tower defence, but if you zoom in, it canges the orientation of the camera so you can see further, and hence, also underneath the canopy of trees. We also cannot do any interesting weather effects regarding stronger winds, as it distorts the trees too much. So basicly, we can't make use of all the nice features provided in the scripts hooked up to affect the shaders, which is a shame.

    Hope some of this info has shed some light on the situation :)

    EDIT: found this today: https://forum.unity.com/threads/vertex-rgba-blender-2-5x.254038/
    going to give it a try when i have time for it.

    Also, forgot to address the issues i have with using my own custom asset importer script, as you seem to have something withing AFS5 that also does something with a custom import? Is it possible to disable it without breaking the AFS5 somehow? removing my script resolves the problem, but then i have to manually set all the material and model import settings, then re-import.

    For reference, here is the error:


    And the simple script i am using myself:

    Code (CSharp):
    1.  using UnityEngine;
    2. using UnityEditor;
    3.  
    4. public class AssetImporter : AssetPostprocessor
    5. {
    6.      void OnPreprocessTexture()
    7.      {
    8.          TextureImporter textureimporter = assetImporter as TextureImporter;
    9.          Object texture = AssetDatabase.LoadAssetAtPath(textureimporter.assetPath, typeof(Texture2D));
    10.          if (!texture)
    11.          {
    12.             //textureimporter.textureFormat = TextureImporterFormat.AutomaticTruecolor; // deprecated
    13.             textureimporter.maxTextureSize = 1024;
    14.             textureimporter.compressionQuality = 100;
    15.          }        
    16.      }
    17.     public void OnPreprocessModel()
    18.     {
    19.         //ModelImporter modelImporter = (ModelImporter)assetImporter;
    20.         ModelImporter modelimporter = assetImporter as ModelImporter;
    21.  
    22.         Object mesh = AssetDatabase.LoadAssetAtPath(modelimporter.assetPath, typeof(Mesh));
    23.         if (!mesh)
    24.         {
    25.             modelimporter.importLights = false;
    26.             modelimporter.importCameras = false;
    27.             modelimporter.importVisibility = false;
    28.             modelimporter.generateSecondaryUV = true;
    29.             modelimporter.importMaterials = true;
    30.             modelimporter.materialName = ModelImporterMaterialName.BasedOnMaterialName;
    31.         }
    32.     }
    33. }
     
    Last edited: Jan 27, 2018
  41. Bomshi

    Bomshi

    Joined:
    Jan 17, 2014
    Posts:
    14
    Hello!
    Can anybody help me out for the problem.
    The Billboarding is not working in correct way:


    The billboards look like they are standard unity's.
    What I can do because they also glow in dark...
    Thanks
     
  42. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    what are the known limitation of compatibility between AFS and Vegetation Studio. What do you win for having both and what do you loose.

    I heard bending is a problem, so you have to use the one you prefer or you can use both both on different things ?
    I heard billboarding is a problem because they use different tree system. Will having both in the same scene will be noticed ? will it decrase overall performance having two system running at the same time ?
    I see people on the forum talking about a vegetation studio update, what is that ? is it included in the most recent version of the asset ?

    please help me out
     
    Flurgle likes this.
  43. Mark_T

    Mark_T

    Joined:
    Apr 25, 2011
    Posts:
    303
    Hi,
    I purchased last week the Advanced Foliage shaders to use them with Critias vegetation system (paid version). I was really happy when I saw that on the Critias AS page. Unfortunately the trees start to warp inside the critias system.
    I read the entire documentation, I managed to convert the Unity trees to your shaders and in the end I was pretty happy with the result. Decent wind movement as they are meant to be placed in bulk as forest trees. Not as convincing and nice looking as the CTI Jatoba made by Baldinoboy (I was very impressed by the wind behavior and texturing, the entire tree it`s a nice believable one, no doubt. Very nice).
    How can I fix this warping movement that is affecting the entire tree, trunk and leaves altogether?

    P.S. - Many thanks for the great Unity tree tutorial you made. It really helped me to make nicer trees. Thank you!
     
    Flurgle likes this.
  44. SniperED007

    SniperED007

    Joined:
    Sep 29, 2013
    Posts:
    345
    Trying to do a build for UWP and I'm getting this error:

    Running AFS 5.075:

    Shader error in 'Hidden/AfsCamera-DepthNormalTexture': semantic 'VFACE' unsupported on ps_4_0_level_9_3 at line 330 (on d3d11_9x)
    Compiling Fragment program with AFS_PRESERVELENGTH
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_NO_CUBEMAP_ARRAY UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF3 SHADER_API_MOBILE UNITY_HARDWARE_TIER1 UNITY_COLORSPACE_GAMMA UNITY_LIGHTMAP_RGBM_ENCODING
     
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    the foliage tool does things which are pretty difficult to mimic just using a shader like giving you control using curves.

    regarding the secondary bending
    in case you use the foliage tool and can't mask secondary bending (which causes the warping) by radius (Along XZ-Axes) due to the models geometry you may do it by adding vertex color blue: make sure that the trunk is black and only add vertex color blue = 1 to the leaf planes. then choose "mask secondary bending by vertex color blue" when setting it all up in the foliage tool.

    regarding ghosting
    i was able to reproduce the problem in unity 2017.3 – but actually ghosting only happens in edit mode. as soon as i hit play everything looks fine.
    can you confirm this?
    i can only assume that unity's tree script does not pass any wind to the depth shader when in edit mode while it does for the final shading pass... which is nothing i could fix.
    so as a quick workaround to set up your lighting in edit mode: set main and turbulence strength in "wind settings for tree creator shaders" to 0.0 to get a proper preview.

    you should be safe to remove or disable the GrassMeshPostprocessor – in case you do not need it to import grass meshes.
     
    totrider likes this.
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    make sure that you do not have multiple billboard shaders in your project as unity will pick the latest it has found.
     
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you will win nice bending and advanced vegetation lighting on foliage drawn pretty fast by vegetation studio.
    when using the foliage shader bending just should be fine.
    billboarding in fact works completely differently – just like the whole tree system. right now i do not recommend to use afs tree creator shaders within vegetation studio.
    first and foremost it will look odd i guess.
     
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i guess you will have to add the set u script your scene and set the "billboard start" to something very high.
    but the afs tree shaders are not ment to be used outside the terrain engine. afs officially only supports models using the foliage shader to be rendered by critias foliage.
     
    Last edited: Feb 13, 2018
  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i just tested AFS 5.076 and Unity 2017.3. – which worked fine.

    in case you still get errors you may add:
    #pragma exclude_renderers d3d11_9x
    after line 260 which is "#pragma target 3.0"
     
  50. AlexanderElert

    AlexanderElert

    Joined:
    May 31, 2017
    Posts:
    37
    Hello. How are you?

    I'd like to know what I'm doing wrong here.

    I have a prefab with AFS material / foliage shader

    I try to use it with the detail paint (render mode: vertex lit) of unity ground but incorrect shadows appear.

    screenshots (on the left detail paint - to the original right prefab) increasing the environment lighting but the problem persists:
    1.jpg 2.jpg

    *Its doest happend with the tree paint on terrain

    Thanks!