Shared Functions in Shader Passes

Is it possible to define a function and call the same function from several passes?

My problem is as follows:
I have a specialized shader, blending a big series of textures together, according to some rules and calculations. As a single pass is limitted to 16 texture interpolators, I have to distribute stuff over several passes. However, underlying calculations are always the same, only dependent on uv and uniforms and could be extracted to a function. Now I want to avoid to copy-paste the same code fragment over and over to keep things maintainable.

Sounds wierd, but it’s a research project… :wink:

You can put shared code in a CGINCLUDE block that goes before your SubShader block:

CGINCLUDE
// Shared code goes here
ENDCG

SubShader
{
  ...

  Pass
  {
    ...

    CGPROGRAM
    // Pass specific code goes here
    ENDCG
  }
}
2 Likes

Works perfect! Thanks a lot!