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

Editor view conditional?

Discussion in 'Shaders' started by cmberryau, Mar 7, 2016.

  1. cmberryau

    cmberryau

    Joined:
    Mar 6, 2013
    Posts:
    12
    I'm working on a shader that I would like to behave differently when being viewed in the 'Scene' to the 'Game' viewport.

    Is this possible? I've done some Googling and digging through the default shaders and could not find anything obvious enough.

    While I am at it, is there any compiler directive to notify whether it is being compiled for the Editor or standalone also?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    Not that I'm aware of, no.
     
  3. cmberryau

    cmberryau

    Joined:
    Mar 6, 2013
    Posts:
    12
    That's unfortunate! For the time being I've just compared the FOV between Unity's inbuilt uniform and my own uniform for the actual Scene camera, it's a disgusting hack but it'll do for now.

    A compiler directive would be great to disable it for standalone builds.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    Yep, I have some shaders that use global variables and have to put in if checks to ensure default values for first time startup of the editor. Don't need that for the game, but no way I've found to remove it. Script has #if UNITY_EDITOR as well as various defines for different versions. There are a couple of defines for platform / shader level which might be useful if you're building for non PC, but not much else.
     
  5. zotai

    zotai

    Joined:
    Jan 23, 2015
    Posts:
    6
    I found a solution for this in the end using the shader LOD system. In a PreRender callback the material in question has it's LOD value set to a very high value - and then reduced back to the previous in a PostRender callback.

    The shader has two subshader variants, one with a high LOD and one with a low LOD. It allows me to have completely different shaders running in the Editor scene view and the Editor game view.

    The original idea came from this thread: https://forum.unity3d.com/threads/separate-shader-for-scene-editor.172749/

    Edit: yes, it's a hack but it will do until there's an officially recommended method.