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

Make two layers of materials?

Discussion in 'Editor & General Support' started by robin_pcity, Apr 15, 2021.

  1. robin_pcity

    robin_pcity

    Joined:
    Jun 26, 2020
    Posts:
    28
    I was wondering if it is possible two make a material which has two layers. That is, everything of the image in the foreground should be visible. However in the places in which it is transparent or in case it isn't filling up the whole plane/Gameobject the background image should be visible. Here's an example picture:

    The gray areas would be transparent.
     

    Attached Files:

    Last edited: Apr 15, 2021
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    You can easly create a new shader with shadergraph(if you use HDRP or URP) to do what you need.
     
  3. robin_pcity

    robin_pcity

    Joined:
    Jun 26, 2020
    Posts:
    28
    Could you show how exactly the code of the shader should look like?
     
  4. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    With the shadergraph you wount need to code.
    you can just connect multiple nodes with a easly ui

    upload_2021-4-15_10-12-36.png

    This would require the foreground layer has a alpha channel for controlling what to keep from the foreground
     
  5. robin_pcity

    robin_pcity

    Joined:
    Jun 26, 2020
    Posts:
    28
    Thank you for your answer.
    When I tried to set everything up I had to change my render pipeline which previously wasn't assigned. After I did that all of my objects in my scene turned purple.
    Now I am wondering:
    Does it cost more performance if I set the render pipeline?
     
  6. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    The different render pipelines do have different feature sets and performance costs.
    The URP is designed for low end / devices without compute shader compatibility.
    The HDRP is for High end visuals.

    If you change from the default pipeline to one of the script able ones you will need to change your materials to use the shaders apportiert for that render pipeline or they will all turn pink/purple.

    Performance wise the URP should be the same or faster then the default render pipeline.
    There is a upgrade to URP wizzard that should help you to change your project to URP in case that is what you ant to do.

    This is in the edit menu:
    upload_2021-4-15_12-19-12.png

    If you don't want that you many need to look into shader coding or take a look at tools like "amplify shader editor" the https://assetstore.unity.com/packages/tools/visual-scripting/amplify-shader-editor-68570
    it supports the default pipeline.
     
  7. robin_pcity

    robin_pcity

    Joined:
    Jun 26, 2020
    Posts:
    28
    Thank you for your ellaborate answer. I will probably go with URP since it is a mobile game