Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Drawing diffuse over post processing effect?

Discussion in 'Shaders' started by Detocroix, Mar 10, 2011.

  1. Detocroix

    Detocroix

    Joined:
    Jul 2, 2010
    Posts:
    75
    I'm using greyscale image effect (stock post processing shader) to turn my image in to a greyscale and "forcefully" adjust contrasts, but I don't want everything to be black and white as I need someway to give player non-ui pointers such as enemy insignia.

    What I'm trying to figure out is: How can I draw diffuse of CERTAIN objects over the post processing effects? I tried with secondary camera that had different layer set and tried with different "clear flags" but its then drawing the whole mesh over everything else and thats not what I want. Flying insignia isn't cool.

    I could also just greyscale all my textures manually, but the contrast enchance using ramp texture is a must for me.. I tried dissecting the GreyscaleEffect.shader but everything I do results in crazy magenda.
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    use GUI, its always drawn last and over the post process
     
  3. Detocroix

    Detocroix

    Joined:
    Jul 2, 2010
    Posts:
    75
    Yeah, I'll use GUI and different camera for HUD elements, but these insignias and markers I need as 3D planes aligned on ships :)
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Then it will be more complex, will require multiple cameras and that you explicitely enable the post fx only during the "3D camera" not the "3d hud camera" through the OnPreRender and OnPostRender functions for monobehaviours sitting on a gameobject with camera etc
     
  5. Detocroix

    Detocroix

    Joined:
    Jul 2, 2010
    Posts:
    75
    With double camera I can easily "override" the special effects, but I'm unable to get proper depth and the objects in that render layer appear over objects in the main camera layer resulting in floating objects which I don't want (or can't use!).

    Here's a picture to better visualize it:

    http://dl.dropbox.com/u/238567/S***ret/x/issue.jpg
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    sounds like the HUD camera clears a bit too much of the backbuffer, what is it currently set up to clear?
     
  7. Detocroix

    Detocroix

    Joined:
    Jul 2, 2010
    Posts:
    75
    Hmm, so with OnPostRender I could "re-color" items in different layer?
     
  8. Detocroix

    Detocroix

    Joined:
    Jul 2, 2010
    Posts:
    75
    Its set to "don't clear" but both neither that or "depth only" do anything differently. Is there someway to control it better?
     
  9. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    if you seperate the objects by layer and set the clearing flag right and use corresponding post fx, sure, nothing speaks against it aside of the performance impact of all these seperate post fx / replacement shaders
     
  10. Detocroix

    Detocroix

    Joined:
    Jul 2, 2010
    Posts:
    75
    Hmm, then next option:

    Can I disable the grayscaling from the stock image effect GreyscaleEffect.shader? I need to keep the contrast tweak it causes, but with my lack of shader editing skills I can only barely adjust it as I have no idea what does it.

    edit: Well, the shader probably doesn't actually do constrast adjusting with the ramped texture, but rather just inserts its values to the image.. but thats what I'd like, contrast with ramp :)
     
    Last edited: Mar 11, 2011
  11. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    look at the contrast enhancer shader that also comes along to see how it does it and then mix it up to do the contrast raising / lowering basing on the ramp
     
  12. Detocroix

    Detocroix

    Joined:
    Jul 2, 2010
    Posts:
    75
    Ah well, looks like I was exploring way too difficult solutions to a simple problem. Thanks for the aid, I explored the other shaders a bit further and worked it out :)

    Simply put, I multiply the original (unramped, not greyscaled) with original + 1.25 and multiply that pile with the ramping. Few colored details are lost, as greys etc get brownified, but doesn't matter to me.

    Now everything is as I wanted. Brown, dirty, ugly with flags flying red :)

    Thank you!