Search Unity

Cut hole though centre of shader on camera

Discussion in 'Shaders' started by Griffo, Aug 11, 2014.

  1. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Hi,

    Is it possible to cut/put a hole through the centre of a shader effect applied to the camera so I can see through?

    I purchased the Camera Filter Pack from the asset store while its on sale and I'm using theCameraFilterPack_FX_Hexagon_Black effect and would like to put a hole through it faded at the edges if possible, as I have no clue about writing shaders any help, advice would be appreciated, thanks.
     
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    I recommend talking to the person who wrote the original.
     
  3. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Thanks for the reply, I've tried but he's not responding .. :(
     
  4. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    OK I'm really stuck on this one ..

    I'm using a post processing effect shader on the camera that requires the Render Texture function of Unity Pro, post processing shaders are different from regular shaders as there is no model to stick the material on.

    So cannot use a depth mask , alpha shader or at least I think I cannot, as I said before I'm no shader programmer so was looking for some advice.

    Thats why I'd like to know if I could add/code into the shader to see through the centre .. or use another post processing shader to mask the centre.

    Thanks.
     
  5. drudiverse

    drudiverse

    Joined:
    May 16, 2013
    Posts:
    218
    you should be able to use alpha values and set the shader to transparent. try

    if (uv.y < 0.5){color.a = 0} to make half of the shader transparent, if that works you can make a hole.
     
    Last edited: Aug 15, 2014
  6. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    drudiverse thanks for the input ..

    OK, I've managed to get a blank square in the middle but can't get it transparent ..

    Screen Shot 2014-08-15 at 17.02.44.png
     
  7. drudiverse

    drudiverse

    Joined:
    May 16, 2013
    Posts:
    218
    what a cool shader!!!

    try this at the top of the shader:
    Code (csharp):
    1.  
    2.     }
    3.     SubShader {
    4.         Tags {"Queue"="Transparent" "RenderType"="Transparent"}
    5.         LOD 200
    6.         //ZWrite On
    7.        // Cull Off
    8.         Blend OneMinusSrcAlpha One
    9.         CGPROGRAM
    10.  
    and then to make a round zone do something like if(x*x + y*y -0.5 <= 0){color.a = 0}
    http://stackoverflow.com/questions/1906511/how-to-find-the-distance-between-two-cg-points to find all point smaller than distance from centre.
     
    Last edited: Aug 15, 2014
  8. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    If it's a full-screen effect then standard blending won't work: it's expected to produce 100% of the final output. You'll need to add a bit to the end of the fragment shader to blend in the original input over the resampled result.
     
  9. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
  10. drudiverse

    drudiverse

    Joined:
    May 16, 2013
    Posts:
    218
    what's going on in that shader, is that a complex effect is being applied on top of a regular render texture. in the image effect code it will have the raw render texture code, incolor.rgb prior to the distortions and outcolor.rgb after the distortions, at the very beggining and end of the pixel shader/surface shader function... so you can probably go in the code and add 2-3 lines at the end merge the two rgb values, try "if y > 0 use incolor.rgb else use outcolor.rgb

    have fun with the pixel shader and go up the signal chain of rgb values going from the end, find the output rgb, and then go up the maths code and see how the rgb values change over time, until you find the original in one at top of code. it should all be inside a single fragment shader with in rgb and out rgb and perhaps functions and maths in the middle.
     
    Last edited: Aug 16, 2014
  11. vetasoft

    vetasoft

    Joined:
    Nov 15, 2013
    Posts:
    432
    And here we are. Thanks for the suggestion.

    AAA Super Hexagon now available on Camera Filter Pack v1.3
     
    Griffo likes this.