Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Pixel extrusion shader?

Discussion in 'Shaders' started by Bionicle_fanatic, Apr 17, 2018.

  1. Bionicle_fanatic

    Bionicle_fanatic

    Joined:
    Jun 8, 2013
    Posts:
    368
    Hi there, I'm trying to figure out a way to create this effect on my water shader:

    https://i.imgur.com/Vd17msx.gifv

    The surface of the water is a vertical plane with a 12x12 pixelated texture on it. My aim is to use the shader somehow extrude the pixels to create the above effect. Is there any method of doing so, or am I going to have to create a "cube" for each individual pixel?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Sure, you could do in shader raytracing / raymarching. But a 12x12 grid of cube meshes is going to be way, way faster. Both in the time to get it working and to actually render.
     
  3. Bionicle_fanatic

    Bionicle_fanatic

    Joined:
    Jun 8, 2013
    Posts:
    368
    Are you sure it would be faster? There's going to be thousands of each 12x12 grid. I was under the impression that shaders generally performed a lot better than usual scripts.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    It's it's just a 12x12 grid it would be. If you want something that repeats into the distance, then no.

    If you want to go the raytraced route, you can look at this:
    https://www.shadertoy.com/view/Msl3Rr

    Alternatively you can look at a more "straight forward" parallax occlusion mapping shader.


    Also, even in the 12x12 grid of boxes, I'd still have used a shader to move them, just a vertex shader that moves the geometry rather than doing it from script.

    edit: One note of warning. Any pixel shader (aka fragment shader) based technique cannot go outside of the bounds of the pixel area the original geometry covers. So you can't really "extrude" as much as cut into geometry with a pixel shader.
     
    Last edited: Apr 17, 2018
  5. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,539
    Depending on your target platforms (you need #pragma target 4.6 or higher), you could technically extrude the faces by using a geometry shader. Your game would not be mobile compatible though.



    Geometry shaders are quiet efficient for generating geometry at runtime. But the approaches bgolus suggested would likely be the easiest and most optimal to implement (well, hard to say how performant that shadertoy approach would be versus geo or parallax shader, it looks like a lot of instructions haha)
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Or MacOS Metal compatible either.
     
  7. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,539
    Yeah, that's more an API than a platform though, it's still OpenGL 4.1, which MacOS has thankfully (wish they'd update their OGL version though :C ).
     
  8. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    Wait is geometry shader not available to metal on iOS / Mac? Can we at least do tessellate yet?
     
  9. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,539
    Support for tessellation on Metal seems to have been added in Unity 2018, but no, not in 2017.3 or earlier.
     
    MadeFromPolygons likes this.
  10. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    Thankyou!