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

Surface shader default lighting

Discussion in 'Shaders' started by karurosu, Jan 13, 2015.

  1. karurosu

    karurosu

    Joined:
    Jan 13, 2015
    Posts:
    2
    Hi,
    I am writing a surface shader that renders fake lighting whenever there is shadow. I am seeing some weird behaviour when there are no lights in the scene. Basically the shader is being called with a lightDir parameter that is a semi random vector (usually along the Y axis), but it can be pretty much anything.

    Any idea what could be causing this? How to disable?
    I can add a directional lighting, but then the shader will have to ignore that particular light.

    Thanks.
     
  2. specterdragon

    specterdragon

    Joined:
    Dec 30, 2013
    Posts:
    21
    Someone else may be better suited to answer the question, but I'm trying to wrap my head around what you're trying to do. Am I getting this correctly that you want to light the object in the shader rather than using an external/unity light object - such as baking a lightmap? Or is there a different goal? Any pics that might be able to help clarify?

    Stab in the dark - There may be additional useful info in this thread:
    http://answers.unity3d.com/questions/272749/how-to-write-unlit-surface-shader.html
     
  3. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Yeah, the base pass will get given a light direction, but it will be gibberish (usually the last used light that's been passed in).

    You can multiply it by the lightColour (which will always be black if there is no light).
     
  4. karurosu

    karurosu

    Joined:
    Jan 13, 2015
    Posts:
    2
    Thanks for the replies.
    Multiplying by the light color did remove the extra light. In the end, I ignored directional lights, since the effect I am interested in achieving only applies when using spots/point lights.

    The idea is that unlit areas get sort of a shine, kinda like specular highlights caused by indirect light.

    I am still working on a better way to handle things, since my solution completely removes directional lights, but I'll figure something out, thanks!