1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. Unity 2017.1 beta is now available for download.
    Dismiss Notice
  5. Unity 5.6 is now released.
    Dismiss Notice
  6. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  8. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice

Real time lighting in custom shaders

Discussion in 'Shaders' started by scottharber, Mar 14, 2017.

  1. scottharber

    scottharber

    Joined:
    May 14, 2014
    Posts:
    38
    Hi,

    I've got a set of entirely custom shaders (custom vert, custom frag). If I wanted to have Unity's real time lighting model working within them, is there a way to do that? e.g. is there a function I can #include into my existing shaders that would enable the real time lighting?

    Apologies if this is a dumb question btw; I couldn't find any info in the usual places.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    2,683
  3. scottharber

    scottharber

    Joined:
    May 14, 2014
    Posts:
    38
    Thanks @bgolus :)

    I knew about that page, but the examples only seem to support one directional light and vertex-based ambient from lightprobes. Is there a way to support multiple light sources and real time GI?
     
  4. Lost-in-the-Garden

    Lost-in-the-Garden

    Joined:
    Nov 18, 2015
    Posts:
    134
    What we did was to start with a simple surface shader and then in the editor click the "show generate shader" button in the inspector. This spits out the result of all the macro and code generation magic that happens under the hood. We then took a large crowbar and a hammer, to rip out all the features we did not use and only left the stuff in we use.

    It's dirty work, but it works.

    For multiple light sources you would have to also read up on how unity can render them in multiple additive passes.
     
    bgolus likes this.
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    2,683
    It's good to understand that Surface shaders are just vertex fragment shader generators, so there's nothing a surface shader can do that a custom shader can't. Surface shaders are kind of ugly to look at, but they were designed to be somewhat modular which makes starting with them instead of going straight to the actual standard.shader a little easier to convert into something custom.
     
  6. scottharber

    scottharber

    Joined:
    May 14, 2014
    Posts:
    38