Search Unity

[Free]Random Distribution Tool

Discussion in 'Assets and Asset Store' started by Lars-Kristian, Oct 31, 2014.

  1. Lars-Kristian

    Lars-Kristian

    Joined:
    Jun 26, 2013
    Posts:
    64
    Random Distribution Tool
    This tool can be used for creating random distribution or random scatters of game objects.
    The interface is clean and easy to use, while the user have access to a wide warranty of options. Use textures to describe different properties like color, scale, masking and density. It also support multiple objects with weighted distribution. Scroll down for a more detail description of the tool. :)

    Overview:
    Demo2.png

    Inspector:
    Inspector.png



    How to use
    When using this tool, think of it like pixel art. Do not try to cover a big area with one script, instead divide it up into smaller chunks. This will increase performance while reducing the memory needed.

    Object pool
    Add prefabs to the list for the script to distribute. Every prefab can be weighted individually so that some object occurs more often than others.

    Amount
    The number of objects to be distributed by the script. The algorithm uses a "fail and retry" approach for the placement of objects. This means it can fail in some very special cases. Do not worry though, the script lets you know why and how to solve this. The reason for this is to make the script fast and simple.

    Bound
    Describes a cube volume in which the distribution happens. If selected, Surface projection is done from the top of the cube towards the bottom. Every surface with a collision component is detected by the projection.
    To do a projection in different directions, simply rotate the parented game object.

    Distribution Map
    A texture 2D that describes the distribution. Every color channel is used separately to allow more creative freedom. Use filter type to select between point and bilinear filtering. This allows smooth transitions with very small maps. Use the invert option so invert the values from the distribution map.
    Recommended texture sizes are from 4x4 to 128x128 pixels.

    Optimization
    The "apply vertex color" option makes the colors be applied to the actual vertices instead of the material color. This will reduce the number of draw calls used to render the scene. Remember to use shaders that can use the vertex color, or else the effect will not appear.
    The "Combine meshes" option, groups distributed objects and combine them into a single object and mesh. This will reduce the number of draw calls. Colliders and other component will not be effected by this operation. Only use this option if the objects are static and do not move in the scene.

    Distribution Type
    Describes the type of algorithm used to distribute objects. Select between random and Halton sequence.
    Random uses unity's internal random function. Halton sequence creates a non-random distribution that appear random but more even. Use the seed option to seed the random function or set it to "-1" for a random seed every time the script is run.

    Mask Type - (none, mask, density)
    None -> Does not use a mask.
    Mask -> Apply a mask.
    Density -> Apply a mask and density map.
    Select a color channel to use from the distribution map and use the threshold to adjust the relation between masked and unmasked area.

    Color Type - (none, random, map)
    None -> Does not change color of objects.
    Random -> Apply a random color to objects.
    Map -> Apply a distribution map based color to objects.
    Select a color channel to use from the distribution map and use the min and max option to set the desired colors.

    Scale Type - (none, random, map)
    None -> Does not change the scale of objects.
    Random -> Apply a random scale to objects.
    Map -> Apply a distribution map based scale to the objects.
    Select a color channel to use from the distribution map and use the min and max option to set the desired scale.

    Rotation Type - (none, local up, world up, normal up)
    Select a desired initial rotation and apply the amount of delta on the given axis. If every axis is set to zero, no rotation is made and the initial rotation is used.

    Update 1: You can now populate the distribution with more than one prefab.
    Update 2: Added support for project to surface option.
    Update 3: Added support for projection onto surface in all direction.
    Update 4: Features added:
    • More rotation options
    • Custom inspector
    • Weighted distribution
    • Apply vertex color
    • Grouping
    • Combine distributed meshes
     

    Attached Files:

    Last edited: Feb 24, 2015
    Flavelius, Hamzah-Khan, SAOTA and 4 others like this.
  2. RUBILYN

    RUBILYN

    Joined:
    Jun 22, 2013
    Posts:
    54
    @Lars-Kristian

    Hi hi hi !!! Dear Lars !
    Thank you deeply so much for sharing such crazy amazing Script For free With all us ! <3


    You are Amazing !! Thank you deeply so much !

    Hey i got some questions and features i would like to propose !


    0 - Is it possible to Select more than 1 Object, like Hundreds or unlimitedly select and add selected objects to object pool ?

    1 - Is it possible to Have a Option to Make the Random colors out put to Vertex RGB Colors ?

    2 - If its possible Would be amazing if we could Select a Custom Object and populate Around its normals !
    2.1 - Also if we could chose to have 360º Degrees population or Just on top of it ...

    3 - Would be cool if we could Draw a Spline and Populate inside of it ..
    3.1 - Would be cool if we have a "drop Scattered meshes to Object bellow" option

    4 - Would be amazing To have integration of this script with the free Prefab Brush
    https://www.assetstore.unity3d.com/en/#!/content/21321
    4.1 - That way we would be able to scater above a object / then remove exedents / resize or paint some more by hand ... even who knows "paint with the Prefab Brush with your scater algorithm" Mixing both Hand Painting & Procedural Scattering, much like Vue ...


    I see so many possibilities to this amazing script . Thanks so much for sharing for free it with us !

    Anyway im a customer of megascatter ... but seriously having a amazing Scatter script like this "Available for free" for everyone reaaly kicks buts! And with those 4 implementations above im sure alot more ...

    Thanks so much for all your kindness !
     
    Last edited: Oct 31, 2014
  3. Breyer

    Breyer

    Joined:
    Nov 10, 2012
    Posts:
    412
    Really interesting. I wonder this distro script could check collider of prefab? So prefab never intersect with other spawned prefab...
     
  4. Lars-Kristian

    Lars-Kristian

    Joined:
    Jun 26, 2013
    Posts:
    64
    Hi, 3DLABS and Brayer. Thanks for your enthusiasm. :)

    @3DLABS
    0. I can add support for a simple object pool.

    1. If I understand this question correctly. The script changes the material color which then again changes the vertex color.
    So my answer is yes? :confused:

    2.. If the question was to not populate an area covered by other objects, you can subtract them from the distribution map and spawned objects would not be placed there.
    2.1 No the script can only populate in one direction / axis.

    3. You can use a distribution map (Texture) to tell the script where it can place object.
    3.1 No, but this is a feature I want to add.

    4. Talk to the creators of the Prefab Brush asset. This script is very simple, just 200 lines of actual code. Anyone can take it a part and reuse it.

    @Breyer
    It does not check for collisions with other objects.
     
  5. vanecelina

    vanecelina

    Joined:
    Nov 7, 2018
    Posts:
    1
    Hey! I'm using Unity 2019.2.8 HDRP. Currently the terrain tool for hdrp does not support grass, and polybrush is to slow to work with on a large scale. I was really happy to find your tool but it doesn't seem to be working for me. Any idea what might be wrong? Only thing i get in the console is "some or all public variables are null, with yellow. Also, is this supposed to also work in the scene view or just in the game view?