Search Unity

Can't get Unlit shader to work

Discussion in 'Shaders' started by JonPQ, May 5, 2017.

  1. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    120
    Hi, I've made various shaders, have a reasonable understanding, but can't get Unlit working inside
    SubShader{
    #pragma surface surf Lambert
    Gives the standard lighting..... which works ok

    I've tried replacing the 'Lambert' part with....
    "nothing at all" -> magenta error render
    "Unlit" -> Gets ERROR -> #pragma surface needs function name and lighting model:

    I tried adding "Lighting Off" underneath SubShader{ ....but its still lit.

    UNity describes models here.. but doesn't say how to do Unlit / flat color
    https://docs.unity3d.com/Manual/SL-SurfaceShaderLighting.html

    How do you turn off the lighting please ?
     
    Last edited: May 5, 2017
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Surface shaders (shaders using #pragma surface) are explicitly for lit shaders. If you want an unlit shader use a vertex fragment shader, which is what's created if you right click in the project window and select Create > Shader > Unlit Shader.
     
    JonPQ likes this.
  3. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    120
    Thanks much. yep that was the problem. Sorted it out ! :)
     
  4. LukasCh

    LukasCh

    Unity Technologies

    Joined:
    Mar 9, 2015
    Posts:
    102
    Just wanted to add more info to bgolus answer.
    So as u already have understanding about vertex/fragment shaders, its worth to mention that surface shader in unity is just a parametric wrapper of fragment and vertex shader. So you can even investigate the actual fragment and vertex functions in surface shader by selecting shader and click "show generated code".
     
    JonPQ likes this.