Search Unity

Question Can I use "shader_feature" instead of "multi_compile" on built-in Unity keywords?

Discussion in 'Shaders' started by adamgryu, Nov 30, 2022.

  1. adamgryu

    adamgryu

    Joined:
    Mar 1, 2014
    Posts:
    188
    For example, say that I know a shader will never be used in a scene without shadows.

    Can I replace
    #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
    with
    #pragma shader_feature _MAIN_LIGHT_SHADOWS
    to cut down on shader variants?

    Is the shader feature system able to detect this case?

    If it matters, I'm on URP.
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    Hi!
    shader_feature
    keywords are driven by materials; you'll need to enable the keyword on all materials for this to work.
    multi_compile
    keywords are switcheable at runtime and produce multiple variants; we use stripping to remove the ones we know are not needed.
    If your shadows are always enabled, make sure all URP assets assigned in Quality settings have the main light shadows enabled. This way the stripping system will know it can remove the variants without shadows.
     
    adamgryu likes this.
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    You could also just not have either, and use:
    #define _MAIN_LIGHT_SHADOWS 1
     
    Propagant and adamgryu like this.
  4. Pand0x_075

    Pand0x_075

    Joined:
    Nov 8, 2022
    Posts:
    1
    I finally found a staff member that can help me with this please. I don’t know how to upload this bug onto the main section however I can reply to you at least with a bug. Could you please help?
    I keep on getting the same bug. Let me start from when I first tried to get unity. I got the most recent unity hub and when I went into it I couldn’t download an editor. Every available one had an error every time it tried to download. I soon found a video on YouTube explaining to go onto unity archives and download a certain unity there. I even tried the newest beta and even that didn’t work. I found a certain one however. 2021.3.14f1. That worked and I could finally start a new project. I was trying to fix this issue for hours and when I finally got that to work I turned off my PC and left it there. I took a break and then went back on. I thought it would work however It wasn’t that simple. I could only download templates and that’s it. I’m fairly new to unity and so I wanted to get into the learning section to see how that could help me start to learn coding and everything else. Whenever I would try download a template it would look like it would work and would automatically appear in my projects section even letting me name it. When I tried to open it however it would tell me that no valid unity editor license found. Please active your license. I already had an active license when I first got unity hub and so I was confused and so I went into manage licenses and on the top it told me. Please log in to manage your licenses and then a sign in button right next to it. I clicked sign in and it would open a new link to google and then instead of logging me onto a page where I could sign in even though I did earlier it got me a random white screen with black letters on the top stating.
    {
    “message” : “Error Calling Identity”,
    “code” : “132.126” ,
    “details” : [ {
    “reason” : “Error happened while calling the identity”
    } ]
    }
     
  5. adamgryu

    adamgryu

    Joined:
    Mar 1, 2014
    Posts:
    188
    Ah, thanks for the clarification! Good to know those variants should be stripped automatically.

    Thanks for this too - somehow I didn't think about this obvious but good option!