Search Unity

Inner Glow Shader Like The Photoshop Effect

Discussion in 'Shaders' started by felixpk, Jul 23, 2016.

  1. felixpk

    felixpk

    Joined:
    Nov 7, 2013
    Posts:
    17
    Hello,
    I made an image that will make further explanation hopefully unnecessary:


    I would be glad if someone could tell me if this is possible or not.
    Edit: Maybe I should mention that the 2. shader/mesh is something I already achieved but isn't what I want

    Felix
     
    Last edited: Jul 23, 2016
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    The answer is both yes and no. Yes in that it's totally possible, but you either have to pass a texture that's in the shape of the mesh mapped to itself for the shader to sample, at which point you're better off just having a texture with that inner glow gradient already in it... which kind of defeats the purpose of doing it in the shader. That really is the best option though as crazy as that sounds.

    An alternative is to generate interior vertices for doing the gradient with vertex colors, but that'll make it inefficient for the mesh collider if you want to reuse the mesh.
    Another is to use an camera image effect like bloom, but that means you can't easily use it as part of the shader when rendering the object which is when I assume you want it.

    The problem is shaders only have knowledge of a single vertex, triangle, or pixel at a time depending on what part of the shader you're in. It has no way to know how close or far from an edge of the mesh that is since even in the case of knowing a whole triangle it has no knowledge of neighboring triangles.

    So as silly as the first option sounds it is actually the best one. The basic implementation would be to generate the mesh, then render the mesh into a rendertexture and apply a blur shader of some kind on it and save the resulting texture.
     
  3. felixpk

    felixpk

    Joined:
    Nov 7, 2013
    Posts:
    17
    First of all thank you for your reply :)
    I like the idea of getting a "screenshot" of the mesh, maybe just displaying the edges with a 20px border and then blurring it. I thought a minute about it and have no idea how to do that. Do you think it is somehow possible with grabpass?

    I thought of that with the interior vertices too, but if I extrude the vertices in- or outward it'll be possible that they intersect other vertices because it isn't necessarily a convex mesh.

    Again thank you for your ideas! :)

    Felix
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    Not with a grab pass, no. You'll want to do it with an "off screen" camera and render texture, and likely Graphics.DrawMeshNow()

    I'll be honest I haven't worked out exactly how to do it with Unity either if these are meshes you're generating at run time. In the editor it might be a little easier since you don't have to worry about keeping framerate. I've worked on similar stuff in custom engines, just not yet with Unity.