Search Unity

How to disable a image effect for some materials

Discussion in 'Editor & General Support' started by PaxStyle, Nov 28, 2015.

  1. PaxStyle

    PaxStyle

    Joined:
    May 22, 2013
    Posts:
    63
    Hi to all, as the title says, I would like to disable an image effect (ambient occlusion) on a specific material, because It causes strange shadows on It.
    Is this possible? And how Can I do that? Thank you so much!
     
  2. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,906
    I don't think that's possible unless perhaps if you modify the shader of the material and apply some Offset or prevent it to write to zbuffer.
     
  3. PaxStyle

    PaxStyle

    Joined:
    May 22, 2013
    Posts:
    63
    I already tried all the shaders options, but the shadows are still there.. I don't understand the second part of your reply.. You said that is not possible to make a script that cancel a specific image effect? something like this?
    Code (JavaScript):
    1.  var gameObject : GameObject;
    2.  
    3.   var effect_script : ScreenSpaceAmbientOcclusion;
    4.  
    5. function Start () {
    6. gameObject.GetComponent(effect_script).enabled = false;
    7. }
     
  4. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,906
    No, that's not the way image effects work.

    Image effects are post-processing effects, which means they operate with rendered frames and with the data generated by the render process itself (depth, normals, ...). They take the input generated frame image and can act on it discarding or modifying individual pixels of the current frame.

    They can also forced to be called before transparent objects are rendered. So perhaps you could change your game object queue to Transparent and mark the image effect's OnRenderImage with the [ImageEffectOpaque] annotation. That will produce that all opaque objects gets rendered first, then the image effect and lastly the transparent objects will be drawn.

    As SSAO uses depth (and possibly normals) buffers, you could prevent your game object from writing to zbuffer as well, using ZWrite Off or using playing with Offset -x, -x looking to trick the image effect and avoid that shadow artefact. Of course these are long shots since you don't provide more details nor screenshots about your issue... but those are the options you have.