Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

Swap shader based on shader API during build?

Discussion in 'Shaders' started by reissgrant, May 20, 2013.

  1. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    I want to use a directx shader while in the editor (if on windows), but swap it to an OpenGL ES 2 shader on build for mobile.

    The only thing I can think of so far, is to include a script which will change the shader on Awake() by checking the API. But, do not want to have to add a script every time I want this functionality.

    Please let me know if you have any suggestions.

    Thanks
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Thats what it does already actually. You can use the shader type pragma checks in the shader code to branch depending on DX9, DX11, OpenGL, OpenGL ES 2 and alike and then do fallbacks through that for example.

    OGL ES Shaders don't run on the desktop and vice versa so thats not going to be an issue anyway
     
  3. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Use subshaders within the same shader (or use shader fallbacks). That's what they're for :)
     
  4. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    I will try again using pragma, thanks guys!
     
    Last edited: May 20, 2013
unityunity