Getting access to shaderLab passes

I’m learning unity shaders now, and stuck with a few questions that I can’t solve on my own.

1. Is there a way to use some passes from CG surface shader?
As it’s described in reference, surface shader automatically generates all the passes and combines them. Can I get access to some pass from existing surface shader in my own simple ShaderLab shader?

2. Is there a way to add custom pass to CG surface shader?
Or I need to completely rewrite CG surface shader to CG vertex/fragment shader?

3. Is there a way to get access to custom pass from image effect script?
I need to get main pass (render), then get a custom pass, modify it in some way, and then combine them to final image by simple adding.

Here’s a short explanation of what I’m trying to accomplish:
There’s no natural glow effect in Unity. Under “natural” I mean that we can specify texture which represents amount of light. So if you have a droid with a lot of glowing displays on it, than you have 2 textures (let’s imagine we don’t have any normal/specular/light-mapping):
Main texture, containing base droid color with black spots where displays supposed to be.
Glow texture, which contains displays only on top of black background.

Natural glow effect is then accomplished by:

  1. First of all, adding glow texture to the main texture right inside shader.
  2. Then, getting a render of entire frame, representing glow pass only. So all the objects need to be black and there are only some color where glow supposed to be (in our example it would be only displays on black background).
  3. Then, this glow pass is blurred.
  4. Finally, this blurred glow pass is added to the main render.

For now, i see the only way to do that by:

  1. adding custom “GLOW” pass to the shader itself. Use only this shader for all the objects in the scene.
  2. doing all the rest by image effect which gets glow pass for entire frame, blurres it and adds result to the main render.

P.S.: sorry for my bad english, I’ve tried to explain as best as I can. I can add some illustrations, if my post isn’t clear enough.

  1. Not without writing the pass as a CG shader yourself (or copy/pasting from the compiled shader).

  2. Yes, simply stick an extra Pass {} either before or after you put the Surface Shader in.

  3. Yes, check out render textures or Camera.RenderWithShader / Camera.SetReplacementShader .

For the glow effect you want,
first render the whole screen with a custom replacement shader which only renders alpha channel(any channel you want as long as it represents the glowmap) to the screen
and then on the second pass add the above render to the normal screen colors to achieve the tron glow.

Farfarer,
1, 2 - Thanks a lot! As usually, the solution was so simple… I tried to add surface shader’s code into Pass {} block and obviously it didn’t work. Thank you one more time.
3. As I understand, we can replace all the shaders in the scene to one we specified using Camera.RenderWithShader / Camera.SetReplacementShader. But how we then combine this pass (where all the shaders are replaced to our “Glow only” shader) with original render (which contains main textures, lighting color etc)?

Aubergine,
first of all, we need “true” glow. That is, we need to have color data in glow pass. Because we can have both blue and red objects glowing at the same frame.
Then, what do you mean under “on the second pass add the above render to the normal screen colors”? Do you mean that all the “glow” job should be done right inside shader with no image effect script? If so, than 1) how we can blur image inside shader; 2) how can you make glow to go outside of object’s boundaries while blurring?

Sorry if my questions look too “nooby”. If so, I’ll appreciate if you redirect me to manual.

You can have blue, red, orange, yellow, or any kind objects to glow.
sorry english is not my native language but i will try to be clearer.

First of all, this is tron glow.

1-You render your screen with a replacement shader and its job is to render the objects with the glow texture only. Glow texture can be something like a specular map (grayscale)

2-And you save the outcome and pass it to your image effect as a glow mask (grayscale), that is the parts where it should glow is rendered in this texture.

3-Optionally you can blur this image in your image effect now, to bleed the glowing outside of its boundaries and make it look smoother.

4-finally in your image effect, you combine the normal scene with this glow buffer.

thats it.

and another approach,

You can have the whole glow thing through image effects, but it wont be as nice as the above. Still it may have advantages.
You can have an image effect to sharpen colors on your screen (light parts to lightest, dark parts to darkest) like a bleach shader in nvidia library. And you can use the result as glow texture.
[ADVERTISEMENT]
Or, you can try my shader pack which there is a godray glow shader in it, which is not exactly what you want but it glows things :stuck_out_tongue:
[/ADVERTISEMENT]

A picture would explain much better i guess.
Top photo is without effect
middle photo is with effect (Not blurred, its possible to blur the glow pass to spread it around and soften it)
bottom photo is the render texture of the glow parts only.

Sorry for that I didn’t answer immediately.

  1. Currently I’ve added my own “Glow” pass to the default unity shader with “Blend One One”. And created separate shader which renders only this pass with “UsePass” command. Now I need to render entire frame with 2nd shader using Camera.RenderWithShader / Camera.SetReplacementShader, right?
    2-4 Didn’t understand what you mean under “you save the outcome”. Could you please point me into the reference/manual where this process of sending some custom passes (you named it mask) to image effect is described? For now, I can’t understand how I can get acces to the main render and to my glow pass at the same time. It either renders the scene in it’s normal state or with “glow” shader applied.