Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Help generating procedural paint splatters!

Discussion in '2D' started by edaw22, Sep 30, 2017.

  1. edaw22

    edaw22

    Joined:
    Aug 20, 2012
    Posts:
    14
    Hey everyone, firstly if this is in the wrong board I apologise, I wasn't sure which to put it in as I'm currently not sure how to go about solving my issue. Anyway, onward!

    Basically I am looking for some pointers or suggestions on what way to go about procedurally generating splatters of paint for a game prototype I'm working on. Any help mucho appreciated!

    Criteria:
    -The splatter shapes should be relative round (not too uniform obviously, but not crazy shapes).
    - I need to be able to work out the approximate area of the splatter. Does not need to be exact, but close. So if I used a grid system initially then applied a shader or used bezier curves or something to smooth it out, just knowing the initial grid area of the splat before curving would be fine.
    - I need to be able to work out what portion of the screen the splatter covers.
    - If a new splatter of a different color (say blue) is generated and overlaps the red splatter I need to be able to work out what portion of the screen area is now blue and what is still left as red.

    I know this is a very specific problem, but I have no idea how to go about it and I thought it might be a fun one for a few veterans.

    My current thought process is to break the screen space up into some kind of grid at the lowest reasonable resolution for the splatter to be generated at (before smoothing/curving). Then generate a "low res" splatter shape using grid squares. I use the number of grid squares that the splatter takes up as the area. Then somehow send that grid shape as a height map to a color splat map after somehow smoothing/rounding the edges and corners of it. The only thing is I have no idea how to do that.

    As far as generating the initial splatter. I managed to get an algorithm working that produced a decent splatter out of squares. At the moment I am just spawning a heap of sprite renderers as it was just to see if it looked alright. The issue with it is that while I know the size and therefore area of each inidividual square that makes it up, many of them overlap so I don't know how to work out the final area.

    This is one such splatter. Its just a whole heap of different size sprite renderers on top of each other at the moment as you can see.



    As a really quick idea of how I would want the final curving to look. the following image is the same square splatter array with a quick curved outline. I don't know how to achieve this, but I guess my options would depend on what method I end up using to generate the initial grid splatter shape.



    Given the complexity of this problem, I'm sure there are many things I have left unclear, and I'm super happy to clarify how I would need it to operate if anyone has any questions. Thanks!
     
  2. hlw

    hlw

    Joined:
    Aug 12, 2017
    Posts:
    250
    (So just know that i'm a total newb and right now, for almot 90% of what i'm talking about, i'm not even sure what the thing i'm talking about really is).

    You may create your cubes, then try to create a polygon from that, then smooth the edges of that polygon (some curves maths stuff : http://catlikecoding.com/unity/tutorials/curves-and-splines/ ( i don't know if it is up to date)

    Usually, i believe poeple use some "already done" splatters, they create something like 15 different possible splatters, and randomly spawn it (like blood splatters when you kill a monster in a game like diablo2).

    Instead of using cubes, you have some mathematical shapes you spawn randomly with random sizes and rotation instead of cubes, and just draw one texture from that.

    Actually, i believe, based on the uses, the ways to create it will be differents. What is the actual use of this?
     
    Last edited: Sep 30, 2017
  3. edaw22

    edaw22

    Joined:
    Aug 20, 2012
    Posts:
    14
    Right, so that's kinda what I wanted to avoid doing (pre-designed splatters). Mainly due to storage of those textures and the lack of complete uniqueness. However if having pre-designed patterns is necessary I will.

    However from there, I still dont know the best way to curve them (Will look into the link you posted), nor how to apply a finished splat to the splat map. Lots to learn. Was just hoping for some pointers in which direction I should be going with this. A place to start if you will.

    Thanks for the reply though!
     
  4. hlw

    hlw

    Joined:
    Aug 12, 2017
    Posts:
    250
    Actually, i'm a total noob when it comes to the kind of things you are searching for. i don't even understand what a splat map is.
    (I edited my post, asking what is the exact use of your feature, based on the use, it can help those having real understanding of what you need to find)