Search Unity

Question Tri-planar Texture Blend & Vertex Colors

Discussion in 'Shader Graph' started by Kellyrayj, Apr 12, 2019.

  1. Kellyrayj

    Kellyrayj

    Joined:
    Aug 29, 2011
    Posts:
    936
    I'm attempting to create a shader similar to how polybrush's vertex texture painter shader works. I've made no progress on this front.

    If anyone has been able to accomplish this, I'd love to hear your thoughts on it. Or even where to begin would be most appreciated!
     
  2. alexandral_unity

    alexandral_unity

    Unity Technologies

    Joined:
    Jun 18, 2018
    Posts:
    163
    Without knowing the desired output, it's very hard to help you with a shader graph equivalent. Perhaps linking the example would help?
     
  3. Kellyrayj

    Kellyrayj

    Joined:
    Aug 29, 2011
    Posts:
    936
    Hi @alexandral_unity

    Here is the demo image that is on the polybrush webpage. This is what I'd like to accomplish.

     
  4. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    504
    OK there's two parts to the question here.

    The first part is the triplanar setup. If you're going to be vertex painting, that typically means 4 texture blend (RGBA normalized). 5 if you're cunning (and use 0 + RGBA).

    I'm not sure how familiar you are with triplanar maping, but it uses position as UVs. You'll have position.xy, position.yz and position.xz as UV inputs, and blend between those based on angle. Watch out for flipped normal maps and reversed textures on the 'other side' of the object!

    For beginners, if you google an existing triplanar node setup, that's probably the best option. Look at how they flip one vector, for the back side, see that 99% of the graph is just being plugged into the UV slot. Also note the divide being used to scale the texture size.

    Now, for channel blending. As far as I know, Unity SGE has no node for it out of the box. However, the math is fairly simple. Assuming the channels are normalized (all individuals channels added up = 1) then it's:

    (TexA * R) + (TexB * G) + (TexC * B) + (TexD * A) for each diffuse, metallic, smoothness.
    With RGBA being taken from the vertex colour node.

    A trick here is to keep Metallic, Smoothness and AO (or whatever) packed into RGBA channels of a single texture for each grass/stone/dirt/etc.
    Then split them AFTER, just before they go into the master node. It'll save you a lot of space and means less nodes to deal with. No in-game performance advantage (still doing the same amount of vector math) but it's a quality-of-life thing you should try to get in the habit of.
     
    Kellyrayj likes this.
  5. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    and just like every thread ive read.. theres no answer..