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

How to create an Image Effect?

Discussion in 'Shaders' started by AlexFormoso, Apr 24, 2015.

  1. AlexFormoso

    AlexFormoso

    Joined:
    Aug 12, 2012
    Posts:
    25
    Hello and good evening fellow Unity developers. Today I come here with a simple yet complex question.
    The thing is, I have a grid made of cubes, yes, simple colored cubes, and when I look at them from above I get a good view of the grid. I need to distort the view following a Stereographic Projection, or Wulff Net as you may have heard it. (Links at the end for the curious).

    Now I now that I need to make it via an Image Effect, but in the Unity Docs appears really low documentation on how to MAKE my owns. I know this is hard, I don't expect to get results this afternoon, I just want to be pointed in the right direction. I tried to modify the Standard Assets shaders (fisheye) but broke it, since its a shader and a script, and don't understand the interaction too well...

    Can someone point me on what should I be doing? I mean, should I create a shader for the Stereography first, then a script to handle it? Should I keep taking apart the Image Effects bundled with Unity and keep figuring things out? Thanks in advance to all and good luck in your projects!

    Stereographic Projection: http://en.wikipedia.org/wiki/Stereographic_projection
     
  2. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Ok, lets see if I can explain how an image effect works: (Here is a link with an example, I could have sworn there were some in the docs, but either they are gone post Unity 5, or my memory is incorrect.)
    As you noticed it's in 2 parts,
    The "Controller" that decides what shader to run on what area of the screen, what texture to read and what texture to write to. Also it is the place where you get a call from unity that the camera is done rendering and has provided it's rendered texture for use. (This is the "Image effect" monobehavior).
    Then you have the shader, (need vertex + fragment shader), this is where you will actually DO something. For your case in the pixel shader you supply would need to re-calculate the co-ordinates based on where (in screen space) it is, then sample a pixel to cause the distortion.

    However I do not fully understand this Wulff Net so I can't supply you with how to solve that.
     
  3. AlexFormoso

    AlexFormoso

    Joined:
    Aug 12, 2012
    Posts:
    25
    Ok so I was on the right track, the Wullf net calculations for X and Y points go into the Shader (vertex apparently since im editing the vertex positions) and the Monobehaviour one its basically the same as the Fisheye.

    Thanks, will keep researching
     
  4. echo4papa

    echo4papa

    Joined:
    Mar 26, 2015
    Posts:
    158
    And image effect can't manipulate the vertices of the geometry in your scene. A post process image effect basically just draws a big quad over your whole scene, and it's those verts you'll get in the image effect shader.

    The script is used to call the post process shader(and set it's settings), and you can do that by using Graphics.blit
    More info on that here: http://docs.unity3d.com/ScriptReference/Graphics.Blit.html