Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Terrain 'Grass' Detail Mesh, Blender, and Vertex Color Alpha problem

Discussion in 'Asset Importing & Exporting' started by Setzer, May 12, 2012.

  1. Setzer

    Setzer

    Joined:
    May 5, 2012
    Posts:
    9
    Hello,

    I am currently working with the unity terrain engine, and am applying grass meshes (as detail meshes, rendered as 'grass') I have modeled within blender. Everything is working fine, until I turn on the terrain wind and see my grass floating a great distance from it's original position, not staying anchored to the terrain.

    I have done some reading on the subject and have found that Unity uses a mesh's Vertex Color Alpha to determine where / how wind forces are applied? So I would need to have an opaque value at the bottom of the mesh (to anchor the position), and gradually go transparent towards the top to apply wind force?

    This makes things difficult for me as I've found no way to modify and export a blender mesh's Vertex Color Alpha into unity....

    Any blender users find a work around for this problem yet? :confused:
     
    Last edited: May 12, 2012
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Have you seen that Terrain tutorial? I am not entirely sure if it answers your question.
     
  3. Setzer

    Setzer

    Joined:
    May 5, 2012
    Posts:
    9
    Thanks for the reply Dantus,

    Yep, I've seen that tutorial. It describes placement of grass detail mesh, but doesn't cover the wind problem I'm experiencing. The detail mesh grass I am placing is moving several feet away from the origin point when terrain wind is applied. I'm reasonably certain this can be solved by applying certain vertex color alpha values to my mesh, but as far as I can tell blender does not allow for that. So I'm a bit stuck :(
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Do you need the rgb color of the vertices for something else? An option would be to implement an importer for Unity that converts the rgb into an alpha value.
     
  5. Setzer

    Setzer

    Joined:
    May 5, 2012
    Posts:
    9
    No I don't, that would be a viable option in my case. How would I go about implementing an importer to do that?
     
  6. Setzer

    Setzer

    Joined:
    May 5, 2012
    Posts:
    9
    While looking for a solution I came across this:
    http://answers.unity3d.com/questions/172835/texture-blending-shader-using-vertex-coloring-with.html

    Getting Blender to export an object's vertex rgb as an alpha would be more useful than importing I think?

    In any case, I attempted to apply the code posted in the link above, and unity's console spat out an error when importing the .blend file:
    Back to researching!
     
  7. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    My idea is basically that you don't have to modify this file. If you import a .blend file, it automatically performs that modification, but within Unity. I'll have a look at it.
     
  8. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I made a quick script. It's untested!!!
    It takes the vertex color and applies the avarage value to the alpha channel of the vertex color.

    You have to do the following to get it working:
    - Import the attached package.
    - The .blend with the grass must contain 'vcta' in the file name.
    - Maybe you have to reimport the .blend file.

    And it should work...

    EDIT: It does not work!!! Download the package from the next post!
     

    Attached Files:

    Last edited: May 21, 2012
  9. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Had some time to test it on my own and it did not work :)
    Attached is a working version.

    What you need to do is:
    - Import the attached package.
    - The .blend with the grass must contain 'vcta' in the file name.
    - As you paint the vertices in Blender (Vertex Paint):
    -> Black means is not influenced by the wind
    -> White means is moved by wind
     

    Attached Files:

    PutridEx likes this.
  10. Setzer

    Setzer

    Joined:
    May 5, 2012
    Posts:
    9
    Sorry for the late reply,

    I just gave your script a try and it works like a charm! My grass mesh is no longer floating around! Thank you very much! :)
     
  11. Artwing

    Artwing

    Joined:
    Dec 29, 2014
    Posts:
    1
    Thanks much for this solution! This works in Unity 4.6.1.
    A few notes that might help Blender users:
    If your detail does not show up on the terrain, check under the terrain it might be there.
    To correct this, I set my 3D cursor at the top of my mesh then hit CTRL ALT SHIFT C, then select 'Origin to 3D cursor'.
    Also I seem to be having an upside down issue. In vertex paint mode, I painted the top vertices black and the bottom ones white. In Blender this appears to make the top darker and the bottom lighter while still showing the texture png I had attached. In Unity this gradient does not show.
    -Import Dantus' file into Unity,
    -Save your .blend file something like grassvcta.blend
    -In Blender(2.73) go to vertex paint mode (same place you select Object mode or Edit Mode)
    -Paint the top black and the bottom white (or visa-versa,experiment)
    -with more complex mesh, you may need to blend the gradient along your vertices.
    -In Unity, each time you save a new .blend, Edit>Remove your old mesh detail and create a new one or you changes might not show up.
    -In my Unity Asset folder I made a folder called Blender where I save all my .blend files. In the Blender folder I save materials to a folder called Materials.
     
  12. sara_conagher

    sara_conagher

    Joined:
    Jul 9, 2015
    Posts:
    8
    @Dantus
    I've checked this script on Unity 5.6.0f3 and it's working perfectly :)
    Thanks, it really helps :) You basically saved our development process.