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

Object on top of another?

Discussion in 'Shaders' started by dmennenoh, May 9, 2017.

  1. dmennenoh

    dmennenoh

    Joined:
    Jul 1, 2015
    Posts:
    379
    I have a video being played on a Quad that I want to render always in front of one other object. Just that one other object though. And then rendering should be as normal - I want both of those objects behind others as normal...
    So, I think I need to use a shader(s) for this, but I am a total newb to shaders. Have tried to do some Googling but am not having a lot of luck.
     
  2. dmennenoh

    dmennenoh

    Joined:
    Jul 1, 2015
    Posts:
    379
    OK I found the render queue setting in the shader - however I'm unclear how it works. If I set my ground material to geometry and then change the 2000 to 1980 it says Geometry-20 in the dropdown. Now if I click to another material and then go back to my ground material that Render Queue option says From Shader again - not the Geometry-20 like it should?
     
  3. dmennenoh

    dmennenoh

    Joined:
    Jul 1, 2015
    Posts:
    379
    Could really use a hand with this. Here's an image of my problem:


    It's a quad that plays a video. I need it to play in front of the "pitchers mound" only but not in front of other objects.
     
  4. LukasCh

    LukasCh

    Unity Technologies

    Joined:
    Mar 9, 2015
    Posts:
    102
    Really strange, could you make a bug report with repro project in it?
     
  5. dmennenoh

    dmennenoh

    Joined:
    Jul 1, 2015
    Posts:
    379
    I don't think it's a bug - it must be me. Do I have to use a custom shader to use render queue? I am using the Standard shader. I just made a test project - a sphere and a cube. Made two new materials, sphere and cube. Assigned to the objects. I change sphere from "From Shader" to "Geometry. Then box the same and then change the 2000 to 1980 so it says Geometry-20. Click sphere material - it says "From Shader" - click Box material - it also says "From Shader" and 2000
     
  6. dmennenoh

    dmennenoh

    Joined:
    Jul 1, 2015
    Posts:
    379
    Anyone? Can I get this to work using a shader instead of render queue?
     
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Changing the render queue won't really do much for you. It'll change the order the objects are rendered in, but for opaque objects the order doesn't change the final image rendered. This because of the depth buffer and depth testing; opaque pixels are effectively sorted by depth so that only the closest one is shown.

    If you truly only want the video to show where the mound is, then you'll likely want to investigate stencil masking.

    If you want it to also appear over the ground behind the mound, you probably want to just apply an offset on the quad towards the camera.
     
  8. dmennenoh

    dmennenoh

    Joined:
    Jul 1, 2015
    Posts:
    379
    OK thanks, that makes sense.
    I started reading a bit on stencil masks and it looks like it should work, however i've never really done any shader work. I find a tutorial that had shaders that essentially should do what I need but they are just simple diffuse and not the standard shader that my objects have now. Do I make copies of the standard shader and add the stencil code to those?
     
  9. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329