Extract Texture From Shader After Pass

Hey folks,

I’m trying to extract a texture from a shader after the final pass of that shader, so I can get a texture with lighting applied to it.

Something like this:

Textured Object => Shader applies lighting => Shader outputs final texture with lighting

I’ve tried doing this in the Shader with

SetTexture[_OutputTex] { combine texture }

I’ve also tried { combine primary } and using GrabPass { } to get the last pass.

Then in a script attached to the object I have this, which waits until the rendering has finished before copying the pixel data over to a texture I make at runtime.

IEnumerator AfterRender ()
    {
        while (true)
        {
            yield return new WaitForEndOfFrame();
            Color32[] pixels = (rend.material.GetTexture("_OutputTex") as Texture2D).GetPixels32();
            outputTex.SetPixels32(pixels);
            outputTex.Apply();
        }
    }

The outputTex does not change though.

Ultimately I want to be able to take the texture of from a character with lighting applied to it, including any shadows being cast.

What is the best way to do this?

Thanks!!
~Jake

Hey Bob did you ever figure this out?

No go sir. I think it could be done with a custom rendering solution.

I believe what you’re looking for is RenderTexture: Unity - Scripting API: RenderTexture