Search Unity

Creative [RELEASED] PaintZ - Splatoon like paint system

Discussion in 'Tools In Progress' started by bocs, Oct 8, 2017.

  1. ColeChittim

    ColeChittim

    Joined:
    Aug 11, 2011
    Posts:
    59
    Thanks for the quick response!
    Tried this on Xbox as that seemed to have this issue most prominently and that fixed it!
    I assume its the same for Android/iOS but will test that another day.
    Thanks again. :D
     
  2. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    I fininaly uploaded 1.7.1 to the asset store to fix all issues reported
    VR/XR issues, Mobile, and Obi Fluid 6

    Thank you all for the support
     
    Last edited: Nov 9, 2022
  3. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    as always it's one of the most impressive libraries!
     
  4. mocha_frappe

    mocha_frappe

    Joined:
    Jul 25, 2019
    Posts:
    11
    Hey!
    I'm not sure if this is the place to post this, but is it possible to support more than 4 colors/splatChannels on a single PaintTarget/on a single Paint Shader? And also to support scoring with TallyScore() with these extra colors/splatchannels?
    If not, would there be a workaround?
    Thanks in advance!
    -Mocha
     
  5. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    I've been asked so many times about this, so I'll copy one of my responses:

    -----------------------------------
    the asset stores a 8bit signed distance field value into an RGBA texture.
    1 value for each texture channel.
    Each texture channel can be assigned a color in the inspector.

    simple answer, 4 texture channels (RGBA) = 4 colors per object.
    sorry, no simple solution, the entire asset would have to be completely re-coded.

    4 colors Max
    -----------------------------------

    I'll expand some on why using SDF was used

    1. Paint will have smooth edges no matter what texture resolution is used
    2. Paint layers can have a bump/edge between them

    I found a blog series that explains them very well
    https://shaderfun.com/2018/03/23/signed-distance-fields-part-1-unsigned-distance-fields/

    -----------------------------------

    If I make a new asset Paintz 2/Pro...more colors will be high priority since it's been asked for so many times.
     
  6. mocha_frappe

    mocha_frappe

    Joined:
    Jul 25, 2019
    Posts:
    11
    Thank you for the quick response. I did notice that, and I suppose perhaps recoding it to support more channels is no easy task. Can you recommend another asset that does support more than 4 colors that does something similar with the paint splats/could be repurposed with its scoring system but still use the splat texture? Perhaps used in conjunction with Paintz?
    And is there a potential workaround for my situation? The way I am using this asset is to, rather than create new materials or rename the materials of everything in my scene, I simply use the PaintOnly, transparent material and create a flat plane for the traversable, paintable ground right above the actual terrain. The traversable terrain is almost entirely flat, so this works well.
    The game involves players who shoot paint splats (I've already programmed the shot particle system to match each team's color) and score whose paint covers the most ground. I'm hoping for more than 3 AI players, even 5 would be enough. Would there be a workaround with perhaps two planes with two different PaintOnly materials containing 8 colors total? I think I could probably reprogram a new scoring system to accommodate this change if necessary, the most immediate issue (I'm sure there's more) I see is that repainting colors would only work for painting over colors on the same plane. But do you think there's a potential workaround along these lines, perhaps in conjunction with another asset like Paint in 3D for example.
    Again, thank you so much for the help!
    -Mocha
     
  7. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    @mocha_frappe I tested your idea of 2 planes, and it kinda works, but nothing I would include in the offical version. (image below)

    You sound like a coder, so I'll give some tips on how I'd hack it.

    this would require another var in the PaintTarget and Brush..maybe called Layer

    If PaintTarget.Layer == Brush.Layer....Paint
    If PaintTarget.Layer != Brush.Layer....Erase

    You would need to change the PaintObject function since it handles the random splats
    and to keep in sync, they would need to have the same values
    *My quick test I just set any random values to none/0

    The idea is to paint on 1 layer and erase on all the others.

    Again, this is a bad work around since it doubles any drawcalls and texture memory
    *Also this would only work with the PaintOnly versions

    upload_2022-12-16_17-59-29.png
     
    Last edited: Dec 17, 2022
    mocha_frappe likes this.
  8. mocha_frappe

    mocha_frappe

    Joined:
    Jul 25, 2019
    Posts:
    11
    @bocs Thank you so much! No worries, I've only used the PaintOnly materials thus far, and I understand the drawbacks from a performance standpoint. But otherwise this approach would suit my specific needs, I'll take a closer look at the asset code and attempt to implement your tips. I hope I can come back to you if I have any major issues in my attempt.
    Thanks again :).
     
  9. mocha_frappe

    mocha_frappe

    Joined:
    Jul 25, 2019
    Posts:
    11
    @bocs Hey again!
    This solution works well, and all teams automatically have their Layer property set to the correct plane to draw on according to their color. Those who's Brush's layer does not match the PaintTarget's layer instead paint "paintChannel = 4", or erasing on that particular layer.
    The issue is that only one layer/plane is interact-able, or even visible, at a time. For reference, I am using the ParticlePainter, since the game has players/NPCs painting with a paint gun. I layer both plane's in the same position, but regardless all of this logic only seems to apply to one layer. The other layer isn't even rendered (painting on it shows nothing in-game, checking the inspector shows that no paint splats were ever made). Is there a way for ParticlePainter to paint both planes, I think this solution is complete otherwise. This is likely not a programming issue, more likely a problem with the way I set the scene up in the Unity Scene.
    Thanks in advance!
    -Mocha
     
  10. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    @mocha_frappe

    The particle painter would need to be modified some to get multible layers, check the void PaintRaycast function in PaintTarget.

    I would use the Physics.SphereCastAll for each particle collision, which would return all the layers then.

    Untested, but may work for you:
    Code (CSharp):
    1.     private void OnParticleCollision(GameObject other)
    2.     {
    3.         PaintTarget paintTarget = other.GetComponent<PaintTarget>();
    4.         if (paintTarget != null)
    5.         {
    6.             if (RandomChannel) brush.splatChannel = Random.Range(0, 4);
    7.  
    8.             int numCollisionEvents = part.GetCollisionEvents(other, collisionEvents);
    9.             for (int i = 0; i < numCollisionEvents; i++)
    10.             {
    11.                 RaycastHit[] hits = Physics.SphereCastAll(collisionEvents[i].intersection, brush.splatScale, collisionEvents[i].normal);
    12.                 for (int h = 0; h < hits.Length; h++)
    13.                 {
    14.                     PaintTarget paintTarget2 = hits[h].collider.gameObject.GetComponent<PaintTarget>();
    15.                     if (paintTarget2 != null)
    16.                     {
    17.                         PaintTarget.PaintObject(paintTarget, collisionEvents[i].intersection, hits[h].normal, brush);
    18.                     }
    19.                 }
    20.             }
    21.         }
    22.     }
     
  11. mocha_frappe

    mocha_frappe

    Joined:
    Jul 25, 2019
    Posts:
    11
    @bocs Thank you for the response and code! Unfortunately, the new OnParticleCollision you sent doesn't seem to affect either Layer.
    To give a bit more detail, I create two separate planes of the same size and in the same location (just above the visible, traversable terrain) with different materials (PaintOnly and PaintOnly(1)). The only difference are the splatColors stored in their colorChannels. On additional testing of the original ParticlePainter, only one Layer is paintable (and players whose Layer doesn't match erase instead). Disabling this plane allows the reverse, those whose Layer matches the other, now only, Layer can paint their colors and the previous players now erase on that Layer. I can't seem to combine both behaviors.
    Lastly, reenabling both layers allows only one plane to be interactable, but the painted materials on both layers are visible.
    I'll take a closer look at ParticlePainter. As you say, I want both Layers to be hit by the ParticlePainter. Additionally, correct me if I'm mistaken, but ParticlePainter doesn't seem to use the void PaintRaycast function, either in its current iteration or in the new version you sent. I don't use the cursor to directly paint on the PaintTarget via PaintCursor, or anything else that seems to use PaintRaycast.

    Thanks again for taking the time to help! I feel like I'm quite close to getting this workaround to work, I just need to have the ParticlePainter/OnParticleCollision behavior affect both Layers somehow.

    -Mocha
     
    Last edited: Dec 23, 2022
  12. mocha_frappe

    mocha_frappe

    Joined:
    Jul 25, 2019
    Posts:
    11
    @bocs Oh and if there's any more details I could provide that could help, please let me know. Thank you so much once again in advance!
     
    Last edited: Dec 23, 2022
  13. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    Since I don't know what code changes you have made, I'll see if I can code up a sample package that I suggest you import into a new project for testing and maybe you can pull info from it.
     
  14. mocha_frappe

    mocha_frappe

    Joined:
    Jul 25, 2019
    Posts:
    11
    @bocs That would be amazing, much appreciated!
     
  15. mocha_frappe

    mocha_frappe

    Joined:
    Jul 25, 2019
    Posts:
    11
    @bocs
    EDIT: Please disregard the original message! After more testing the issue continues to persist. Improved, the AI are now interacting with the first layer, but still only one layer at a time. Still looking for a way for both Layers/PaintTargets to be interacted with at once (with different shaders).

    ORIGINAL: Ah, actually I believe I got it to work! The issue was with the ParticleSystem settings, changing the CollisionModule type from "World" to "Planes", then defining the two planes/PaintTargets with which the ParticlePainter should interact, seems to allow interaction with both Layers! And, as you suggested and as I implemented, the Brush Paints if its Layer var matches the PaintTarget's and Erases otherwise, from my brief testing this seems to emulate the behavior I had hoped for!
    I still need to set these target planes for the Prefab AI enemies via script to test further, and of course I'll need to write a cumulative TallyScore class for the both paint materials. But I think this solved the issue of interactions with both PaintTargets, thanks again! If you've already made the sample package, I'd be more than happy to see what I could glean from it (I'm sure it'll be insightful), but otherwise I think (fingers crossed) that my problem has been resolved for now, so no need to go out of your way to create such a sample package!
    Thanks for the great support, I'll be sure to leave a review. Happy Holidays! :)
    -Mocha
     
    Last edited: Dec 23, 2022
  16. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    @mocha_frappe

    Here is a quick hacked version with your method....Suggest importing into a new project and look at what I have done.
    I did not fix scores, find color etc, hopefully you can figure that out as I really can't spend alot more time on this.

    upload_2022-12-23_19-28-35.png


    Everyone else, this is not a suggested method and will break if you import a newer version of Paintz.
    This is a very specific version for mocha_frappe! using 1 specific shader
     

    Attached Files:

    Last edited: Dec 24, 2022
  17. mocha_frappe

    mocha_frappe

    Joined:
    Jul 25, 2019
    Posts:
    11
    @bocs Thank you so much, the new ParticlePainter works perfectly! More thoroughly tested this time, the new OnParticleCollision behavior now hits both Layers and works for all characters' ParticlePainters in my use case.
    No worries about the other stuff, I have a means of getting/setting the proper color splat for each character, and I don't think rewriting the Scoring scripts will be too difficult. You've done more than enough, thanks for being so accommodating, and once more Happy Holidays!
    -Mocha
     
  18. mocha_frappe

    mocha_frappe

    Joined:
    Jul 25, 2019
    Posts:
    11
    @bocs
    Thanks again for the help, just wanted to suggest a quick fix. The TallyScore method seems to take each PaintTarget in the scene and add their RGBA values weighted equally, not accounting for the relative size of each PaintTarget. This can be seen in the "PlanePaintDemo" scene, the sphere is disproportionately represented in the scores compared to the plane below it. Maybe when adding to the scores, scoresColors could be divided by the area of the current PaintTarget? Or a similar idea accounting for the surface area of each PaintTarget.

    And of course please let me know if you do make the fix/how you implement it, since I need it as well. My paintable geometry is going going to be all planes, very easy to calculate the surface area, but it'd be nice to have a more general solution if you come up with one.
    -Mocha
     
    Last edited: Mar 9, 2023
  19. FissicsPeep

    FissicsPeep

    Joined:
    Jan 14, 2014
    Posts:
    80
    I'm interested in this asset to paint walls, but my level will be procedurally generated. Will this still work? I looked at the original blog post this asset was based on and it uses the uv2 coordinates to generate a world position texture. Does this mean that the level geometry must be fixed/static and "lightmapped" to generate the uv2 coordinates?

    Thanks!
     
  20. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    It does require UV2, and the easiest way is to import with generate lightmaps. (don't have to use lightmaps, just need the UV's)
    The world position texture is created/updated as needed so objects don't need to be static.
    procedurally generated content should work fine.
    If you decide to buy and have issues, just email and I will do my best to resolve any problems.
     
    FissicsPeep likes this.
  21. brunno159

    brunno159

    Joined:
    Oct 24, 2014
    Posts:
    23
    @bocs im using your free version. can you share the vr fix. im using it on quest. your domain expired. so im hitting you here.
     
  22. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    Yeah, i'm switching domains, still setting up and need to update my posts and store listings.
    until then the new email is support@bocs.software

    anyway, i'll attach the package for the free version (haven't tested in awhile so hope it still works)
     

    Attached Files:

  23. GamerNZnick

    GamerNZnick

    Joined:
    Jan 9, 2019
    Posts:
    6
    Hi, Just purchased and downloaded Paintz. Going through the manual it says to install the Obi package,. First there's two versions in the Extensions folder. So which is best to use. Secondly when I import either of these I get a compile error:

    Assets/Paintz/Obi/Scripts/ObiParticlePainter.cs(4,7): error CS0246: The type or namespace name 'Obi' could not be found (are you missing a using directive or an assembly reference?)

    This is using Unity 2022.3.10f1

    Cheers
     
  24. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
  25. rnpdrl12

    rnpdrl12

    Joined:
    Jul 6, 2023
    Posts:
    1
    Hello. I'm using the free version of PaintZ. When I paint a thin Object, the paint reaches the back side. Is there only a way to solve this by reducing the scale?
     
  26. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    Size is also depth, best way is to split the object so back is not a paintable object.
     
  27. MaxwellCI

    MaxwellCI

    Joined:
    Jul 29, 2021
    Posts:
    1
    Hi there! Just purchased Paints and am loving it. I currently have it implemented in a way that the splatter shoots out of a ink gun, and "splats" on an object using the collision painter. Question for you - My ideal gameplay is that I have object that are non collidable, until they are "painted" at which point they become collidable, but only in the area that the splat appears if that makes sense. So if I have a giant cube, you can walk through it, but if you hit it with a splat, I want that splat area to be collidable.

    The only way I can think to do this is to use a raytrace to detect a "splat" texture and add a collider. Does Paintz produce a texture that is ray traceable upon collision that I could use for this use case? Hope that makes sense. I'll send an email as well. Thank you!
     
  28. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    @MaxwellCI replied to your email with some suggestions
     
  29. Archi_16

    Archi_16

    Joined:
    Apr 7, 2017
    Posts:
    87
    Hello. Im trying to migrate my game to visionOS. but it shader is not working properly.

    At first it just displayed color, ignoring base texture. checked that part and saw that ScaleOffset(Custom Function) has issue - Unknown operator. so disconnected that part and now that part got fixed.
    But still can't figure out the exact problem why the paint is not visible on Vision OS. Could you help me with that @bocs ?

    Here is the link where you can see current VisionOS Support. It almost supports everything.
    https://docs.unity3d.com/Packages/com.unity.polyspatial.visionos@1.1/manual/ShaderGraph.html

    [UPDATE]
    tried to convert all custom script to the nodes, and found the issue (I think main issue),
    "ShaderGraph.DDXNode" are not supported for MaterialX conversion.

    Couldn't find what that function exactly do, to map it with nodes. Any idea?
     
    Last edited: Mar 13, 2024
  30. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    @Archi_16


    Sorry, I can't help with VisionOS issues. (no plan to purchase)

    Quick peek assuming DDX is the issue, maybe this will put you in the general direction.

    Assets > Paintz > URP > Graphs > ShaderCode
    PaintCG.hlsl

    fun2 uses DDX

    and Assets > Paintz > URP > Graphs > ShaderCode
    Clip Distance uses fun2, that uses DDX

    Not sure why a basic math function would cause issues, or NOT be converted.
     
  31. Archi_16

    Archi_16

    Joined:
    Apr 7, 2017
    Posts:
    87
    Thanks for quick reply. I did all that conversion. converted custom function to nodes. but the problem is that ddx/y (there are nodes for them) are not able to be converted to MaterialX (something like shader type (or maybe shader graph) that is used natively by visionOS)).
    I don't know either what can be the reason for it, maybe they will update it later.
    However if you could help to understand what ddx/y do behind the scene, I could create that functionality with other simple nodes. Thanks.

    P.S. going to post about this issue on shader graph general topic.
     
  32. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    My understanding is the GPU caches the values, which may explain the VisionOS issue, no hardware support (guess).

    As for the math behind them, I suggest google ;) I don't know off hand.

    Found a good video that may help?

     
  33. cyberhuman000

    cyberhuman000

    Joined:
    Sep 11, 2023
    Posts:
    2
    Hello, I have a question, is it possible to use it together with the toon shader? Please tell me if it is good.
     
  34. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    If it's a post processing toon shader, that should work.
    If it's a per object shader, won't work out of the box, and would require adding toon shading to the current paintz shaders.
     
  35. cyberhuman000

    cyberhuman000

    Joined:
    Sep 11, 2023
    Posts:
    2
    Hello, thank you for your reply.

    I'm a beginner, so I'd like to know more. Please tell me if it is good.

    For example, if I use the shader below for a simple cube object, how should I install it?

    https://unity-chan.com/download/releaseNote.php?id=UTS2_0&lang=en

    Please tell me if it is good. Thank you.