Search Unity

► Vertex Ambient Occlusion Generator ◄

Discussion in 'Assets and Asset Store' started by Arkhivrag, Sep 23, 2015.

  1. RiccardoAxed

    RiccardoAxed

    Joined:
    Aug 29, 2017
    Posts:
    119
    Hi, I'm working on a VR project involving a very large scale environment, that is a city created with Fantastic City Generator (https://assetstore.unity.com/packages/3d/environments/urban/fantastic-city-generator-157625).

    Given that I can't do a full lightmaps GI bake (i need only indirect light) on such a huge environment, I was thinking to rather do some less expensive, per-vertex precalculation, so I would ask you if your plugin, other than per-vertex AO, can also be used to do a GI per-vertex bake too, as that "Indirect Lighting Generator" in the plugin description seems to suggest.

    Moreover, since I've to manage an entire city environment - where by the way the buildings are instances of the same prefabs - can your plugin work with many objects at a time, also generating different per-vertex values sets for every building instance?

    Of course, I also need that the baked object can receive a directional, realtime light too, casting and receiving shadows.
     
    Last edited: Feb 24, 2020
  2. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    "Indirect Lighting Generator" bakes environment lighting from scene or custom skybox.
    Quality of Indirect Lighting and Ambient Occlusion depends on mesh vertex density.
    Generated data is saved inside mesh vertex color and it is not obstacle for receiving realtime and directional lightning.
    Plugin works with one prefab at the time and if it is necessary to generate several variations of the prefab, it can be done from plugin editor window by changing generated file name.



    Amazing Assets - YouTube Facebook Twitter
     
    Last edited: Mar 3, 2020
    RiccardoAxed likes this.
  3. RiccardoAxed

    RiccardoAxed

    Joined:
    Aug 29, 2017
    Posts:
    119
    Thank you for your answers.

    In general, that's exactly what I need for my project, that is a simplified environment + AO bake, to be combined with realtime lighting. However, I still don't understand if that per-vertex bake can be used together with textures and, more generally, with more complex shaders than a vertex-lit one.

    I read the previous thread pages but I noticed that all the examples always concern just shaded meshes with only a vertex-lit shader. So, does your package provide a specific version of the standard shader that also supports per-vertex contributes? Or maybe that's left to the user?

    Of course my final goal is to use the per-vertex contributes (AO + environment lighting) without giving up the standard channels (albedo, specular, normal,...).
     
  4. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    Package includes Unlit, One Directional Light, Legacy and Physically Based shaders.
    If those will not be enough you can use almost any kind of shader that includes vertex color support.



    Amazing Assets - YouTube Facebook Twitter
     
    Last edited: Mar 3, 2020
    RiccardoAxed likes this.
  5. nik3hks

    nik3hks

    Joined:
    Aug 10, 2019
    Posts:
    2
    Hello!
    I have few questions regarding of the product:
    I am planning to make a environment with lots of buildings and roads.
    Buildings are textured inside modeling app using multiple materials assigned per separated faces.
    Let's say 5 textures per house, one for walls, concrete, door, windows and one for small details.
    These textures are shared with other houses and buildings of environment.

    With this plugin per vertex ambient occlusion is blending with assigned textures?
    The vertex is assigned per material or per object?

    Thank you!
     
  6. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    Vertex color is part of a mesh like UV, Normal, Tangent. You can access it from any shader and use it for your needs.



    Amazing Assets - YouTube Facebook Twitter
     
  7. nik3hks

    nik3hks

    Joined:
    Aug 10, 2019
    Posts:
    2
    Ok, thank you!
     
  8. florianalexandru05

    florianalexandru05

    Joined:
    Mar 31, 2014
    Posts:
    1,806
    I'm having an issue, I'm using Unity 2017.1.0f3 (64-bit) and it seems to work but your baking tool doesn't want to bake anything I get this error. Am I doing something wrong?

    Screenshot_2.png
     
  9. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    At least Unity 2017.4 is required. Otherwise you automatically get asset designed for Unity 5.6



    Amazing Assets - YouTube Facebook Twitter
     
    florianalexandru05 likes this.
  10. florianalexandru05

    florianalexandru05

    Joined:
    Mar 31, 2014
    Posts:
    1,806
    I tried it in 2017.4 and I get the same message. Maybe I'll try again tomorrow.
     
  11. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    There are 3 packages of this asset on the Asset Store for different Unity versions:
    • Unity 5.6.4
    • Unity 2017.4.10
    • Unity 2018.3.0
    You need to download asset using the same Unity version or newer, otherwise will be downloaded asset for previous Unity version. In your case if you got version for Unity 5.6, just importing it in Unity 2017.4.10 will not have effect. Remove it completely from your project, clear Asset Store cache folder and re-download asset using Unity 2017.4.10



    Amazing Assets - YouTube Facebook Twitter
     
    florianalexandru05 likes this.
  12. zagreekie

    zagreekie

    Joined:
    Nov 20, 2017
    Posts:
    29
    does this asset work with modern unity versions 2020 for example?

    also, does it work with URP?

    also what about your thickness baker asset? does that work in URP and 2020?
     
  13. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    Those two plugins are not updated for URP and currently support only Built-in (Standard) render pipeline only.


    Amazing Assets - YouTube Facebook Twitter
     
  14. zagreekie

    zagreekie

    Joined:
    Nov 20, 2017
    Posts:
    29
    I grabbed it anyway to see if I could get it working, seems to work pretty well honestly. great tool.

    I do have a question, is it possible to bake 2 different sets of AO into the mesh vertex at the same time? say one on the green channel and one on the red channel? or would the only way to do it being, baking the first, then changing the settings and baking the second while preserving "original vertex color"

    Also, in the documentation the description of "save channel" makes it sound like you can pick to save in a specific color channel i.e. save AO only on the red channel. however, i cannot seem to figure out how to do that? in the editor, I only see an RGB, or Alpha option under save channel, no individual options.
     
    Last edited: Nov 15, 2020
  15. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    With using editor tool - No, as it bakes AO results in RGB or Alpha channels of a vertex color.
    Using run-time API - it is possible, as result is just a color array and you can manually modify it for your needs.

    [EDIT]
    If you need source code, contact me using support e-mail (support@amazingassets.world).



    Amazing Assets - YouTube Facebook Twitter
     
  16. Sholms

    Sholms

    Joined:
    Nov 15, 2014
    Posts:
    85
    Hi, I was using this asset on the editor and works fine but when I compile it to android it just doesn't work, do you know why? I'm using unity 2020.3
     
  17. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    Plugin has not been updated for Unity 2020.3 yet. It still uses Unity 2019.1 API.

    [Edit]
    New version for Unity 2019.4 - 2020.3 will be released somewhere by the end of May.



    Amazing Assets - YouTube Facebook Twitter
     
    Last edited: Apr 23, 2021
  18. Sholms

    Sholms

    Joined:
    Nov 15, 2014
    Posts:
    85
    Thanks!
     
  19. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
  20. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    This looks like an amazing asset, and I had some good results with the demo.

    Can I choose which vertex channel to bake the AO to?

    I am currently creating my own shaders and I add AO or dirt via the alpha channel, while using the RGB channels for other info or colour.

    I have the same question about your Vertex Thickness Generator.
     
  21. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    Yes, generated results can be saved anywhere inside any mesh vertex buffers: uv0 - uv7, normal, tangent or color.



    Amazing Assets - YouTube Facebook Twitter
     
  22. IgorCitric

    IgorCitric

    Joined:
    May 28, 2021
    Posts:
    2
    Hello! :)

    I'm always getting those two errors every time I try to use the asset. A new object is generated, but it shows up all white. No visible AO. Do you have any idea of what could I be doing wrong? The errors are:

    1) [Vertex Ambient Occlusion Generator] 'Self Isolation' layer is not defined.

    2) A game object can only be in one layer. The layer needs to be in the range [0...31]
    UnityEngine.StackTraceUtility:ExtractStackTrace ()
    (UnityEngine.GameObject,int)
    (int)
    ()
    OnGUI ()


    Thank you very much!
     

    Attached Files:

    Last edited: Oct 4, 2021
  23. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    Tool needs temporary object layer with name 'Self Isolation'. It should be created automatically but it looks like tool fails to do it.
    Do your project already uses all available object layer slots?
    Try to create it manually.



    Amazing Assets - YouTube Facebook Twitter
     
    Last edited: Oct 4, 2021
  24. IgorCitric

    IgorCitric

    Joined:
    May 28, 2021
    Posts:
    2
    Yes, my project uses almost all available layer slots. But I added one manually and looks like the problem is solved! I'll run a few more tests. Thanks a lot!
     
  25. davidotcom

    davidotcom

    Joined:
    Apr 6, 2013
    Posts:
    2
    Hi, I was wondering if there is a way I can call GenerateVertexAO via a script.

    I was looking for a way to get just the raw vertex color values. Is that possible?
     
  26. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    Yes. Package even includes example scene demonstrating AO calculation using script.
    Run-time API are explained in Manual file (page 9).



    Amazing Assets - YouTube Facebook Twitter
     
  27. davidotcom

    davidotcom

    Joined:
    Apr 6, 2013
    Posts:
    2
    I totally missed that. This is awesome. Thanks!!

    Would this work if I have a custom srp that I built?
     
  28. JavierAlvarez

    JavierAlvarez

    Joined:
    Oct 6, 2015
    Posts:
    8
    Hello there. I purchased the asset and works as expected, great work.

    I just need it to do one extra thing :)

    I am generating a random scene with intersecting rock meshes, I am using the runtime API to bake the AO but the results for some of the vertices that are inside another mesh are lighter than it should be expected.

    I tried to change the frag of the Ray shader in order to detect backfaces and return a darker result if so, but it is not working very good...

    I would like to have the option to make a second pass per vertex to detect vertices inside another mesh by using another ray shader that renders the backfaces also. This pass would have its own ray length way higher than the normal pass but also with way less samples, if enough samples did hit a backface, the vertex will be black, it will be white if the number backfaces hits are below a certain threshold. Then the vertex would get whichever is the darker result from both passes.

    For the price I paid I would not expect for you to go and just add the feature, but do you think I could get my hands on the source code to try and implement a feature like that?

    Thanks!

    PS: I think if the Runtime API could take as an argument which ray shader you want to use I could make that second pass to detect inside vertices.

    [UPDATE]

    I tweaked the ray shader by adding a shader feature keyword so same shader can operate different to detect also the backfaces better. Then, from script, I first do the normal pass, I set a global value to activate the keyword, and do a second pass for backfaces. And it works! Now all vertices that are inside other meshes are mostly black while other vertices remain practically the same, second pass is just about 20% faster than the first pass even though the ray shader is way less complex then, but hey, it works.

    Now I would like to ask some stuff to see if I can improve the quality of the result:

    I see that the ray shader can output either value from these two:

    Code (CSharp):
    1. float4(0, 1, 0, .8)
    2. float4(1, 0, 0, .8)
    What does those values mean, why you use .8 on the alpha? Is [0, 1, 0, .8] the non-occluded ray result ? How does the code later calculates from those values a final float result for 0 to 1?

    Thanks again!
     
    Last edited: Oct 3, 2022
  29. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    Tool does not use any Raycast methods. It is based on a method of rendering a scene from a camera that has position of the current vertex and is oriented towards this vertex normal. Method doesn't (and cannot) check if vertex is inside or outside of a mesh (self or any other).

    Ray shader that you are trying to modify is used only by the editor view, that helps visually represent Ray Length property:
    upload_2022-10-4_14-12-43.png

    float4(0, 1, 0, .8) - green ray
    float4(1, 0, 0, .8) - red ray
     
  30. JavierAlvarez

    JavierAlvarez

    Joined:
    Oct 6, 2015
    Posts:
    8
    oh, ok I see, how silly of me. I though you were rendering a few pixels per sample with the ray shader XD. Thanks for the explanation.

    I am having another issue, if baking while running VR, the results are different than when not running VR and they are ugly. I think it is due to Unity XR changing certain default camera parameters that were taken for granted, like target display, target eye, orthographic projections... Is this something you can look into?

    Cheers!
     
  31. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    Unity version?
    Render pipeline?
    OS?
    Editor or run-time build?
    Can you share VR and non VR baking results (screenshots) to compare?
     
  32. JavierAlvarez

    JavierAlvarez

    Joined:
    Oct 6, 2015
    Posts:
    8
    Yep, of course, sorry, I think I am very bad at reporting issues.

    Unity version: 2020.3.38
    Render Pipeline: Built-in
    OS: Windows, Android, both Oculus with Open XR
    Editor play mode on Windows, and on Android build for Meta Quest 2.

    Sometimes I get a warning saying that:

    Code (CSharp):
    1. Cannot set field of view on camera with name 'New Game Object' while VR is enabled.
    2. UnityEngine.StackTraceUtility:ExtractStackTrace ()
    3. AmazingAssets.VertexAmbientOcclusionGenerator.VertexAmbientOcclusionGenerator:‭‏‎‭‎‏‫‎‫‌‫‮‍‭‌‍‮‭‫‮‮ (UnityEngine.Camera,single)
    4. AmazingAssets.VertexAmbientOcclusionGenerator.VertexAmbientOcclusionGenerator: ...
    There is a similar asset on the store that I am also testing and had exactly the same issue, it was fixed by setting the eye target of the camera to none before attempting to set the FOV as cameras have set StereoTargetEyeMask.Both as default:

    cam.stereoTargetEye = StereoTargetEyeMask.None;


    These are the different results:

    Normal and expected result:
    Vertex_AO.png

    Result when in VR:
    Vertex_AO_VR.png


    And maybe it's worth saying that I am baking these using a modified version of the shader, which is distance-aware to have a nicer gradient on wider gaps and indoor spaces.

    Code (CSharp):
    1. Shader "Hidden/Amazing Assets/Vertex Ambient Occlusion Generator/Culling"
    2. {
    3.     SubShader
    4.     {
    5.         Cull Off
    6.         Fog {Mode Off}
    7.    
    8.         Pass
    9.         {
    10.               CGPROGRAM
    11.             #pragma vertex vert
    12.             #pragma fragment frag
    13.        
    14.             struct v2f_AO
    15.             {
    16.                 half3 worldPos : COLOR0;
    17.                 float4 vertex : SV_POSITION;
    18.             };
    19.  
    20.             v2f_AO vert(float4 v:POSITION)
    21.             {
    22.                 v2f_AO o;
    23.                 o.worldPos =  mul (unity_ObjectToWorld, v);
    24.                 o.vertex = UnityObjectToClipPos (v);
    25.                 return o;
    26.             }
    27.  
    28.             fixed4 frag(v2f_AO i) : SV_TARGET
    29.             {
    30.                fixed l = clamp(0.05, 1, ((length(i.worldPos - _WorldSpaceCameraPos) - 2) * 0.25) );
    31.                 return fixed4(l, l, l, 1);
    32.             }
    33.  
    34.             ENDCG
    35.      
    36.             /*
    37.             float4 vert(float4 v:POSITION) : SV_POSITION
    38.             {
    39.                 return UnityObjectToClipPos (v);
    40.             }
    41.  
    42.             fixed4 frag() : SV_TARGET
    43.             {
    44.                 return fixed4(0, 0, 0, 1);
    45.             }
    46.  
    47.             ENDCG*/
    48.         }
    49.     }
    50. }
     
    Last edited: Oct 5, 2022
  33. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    Unity_07Yv5Vt5O7.png

    Any tips on avoiding brightness around creases? I've tried a bunch of different meshes and they all suffer around the inside of corners.
     
  34. JavierAlvarez

    JavierAlvarez

    Joined:
    Oct 6, 2015
    Posts:
    8
    That could be fixed with a sampling position bias option that displaces the position of the sampling camera a small distance on the direction of the vertex normal. But source code is not accessible...

    Other option you have is to place meshes destined to occlude the vertex, eg. A set of rectangular prisms a bit less thick than your sampling distance that go along the cove joints and concave corners. Bake with those and then remove.
     
    Last edited: Oct 5, 2022
  35. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    Try new update v2022.3. It contains several bug fixes. Not tested on VR.


    Try small Details size. Calculating AO on perpendicular faces may be a little bit problematic.
    VAOG.gif
     
  36. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    Ah, that's pretty disappointing because my game is all perpedicular faces. Your fixed example with 0.001 loses all the nice qualities of AO across the surface. Thanks for the reply. I hope you can consider a fix for this in the future, as AO baking doesn't have these problems when baked in other software.
     
  37. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    Next week update will include new Volumetric AO calculation method (solver) that should work with such 'boxy' meshes without decreasing details parameter:
    Untitled-2.png
    Untitled-1.png


    And additional Standard 2 Pass solver for better detecting close surfaces.
    Untitled-3.png
     
    dock likes this.
  38. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    @Arkhivrag Wow, that's a fantastic improvement!! Thank you for considering my feedback.
     
  39. Liminal-Ridges

    Liminal-Ridges

    Joined:
    Oct 21, 2015
    Posts:
    256
    any idea what this is?

    [Vertex Ambient Occlusion Generator] Encountered an error with object 'R00m (UnityEngine.GameObject)'.
    An item with the same key has already been added. Key: Plane (UnityEngine.Mesh)
     
  40. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    What Unity version are you using and render pipeline?
    And what is VAOG version?
    upload_2022-12-2_10-31-58.png
     
  41. Liminal-Ridges

    Liminal-Ridges

    Joined:
    Oct 21, 2015
    Posts:
    256
    Both latest (LTS)
     
  42. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    Unable to confirm.
    Send me on support e-mail(support@amazingassets.world) screenshot of VAUG settings you are using and mesh prefab file that generates that error (with asset purchase invoice). I'll test it.
     
  43. Dragonslash42

    Dragonslash42

    Joined:
    Aug 27, 2018
    Posts:
    3
    Will this work on an FBX which is made up of many different separate cubes, and not a single mesh? The preview doesn't seem to work for this
     
  44. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    Any mesh hierarchy can be used.
    upload_2023-4-6_16-54-59.png

    After AO generating, all used meshes can be combined into one mesh or kept separately.
    Generated meshes are saved in Unity .asset format.
     
    Last edited: Apr 6, 2023
  45. Dragonslash42

    Dragonslash42

    Joined:
    Aug 27, 2018
    Posts:
    3
    Thanks for your quick reply, this work well, although the colour doesn't seem to work, is this something to do with my chosen settings? The issue is that some areas are a bit too dark and I wanted to limit how dark they can be.
     

    Attached Files:

  46. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,978
    Fixed color baking. Download new update v2023.2