Real time lighting in custom shaders

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.

Thanks @bgolus :slight_smile:

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?

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.

1 Like

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.

In case anyone else gets stuck on this, I found a blog online that explains (to an extent) how to get the GI and shadows into a custom shader. It doesn’t seem to handle multiple light sources though, but I’ll update the thread with details if I figure it out.