ShaderLab: can I specify a portion of a texture?

Greetings,

I’m writing a custom shader. Currently, my shader accepts several materials, layered on top of one another to create an interesting 2D play on light and shadow.

_MainTex ("Main Diffuse", 2D) = "white" {}
_SubTex ("Secondary Diffuse", 2D) = "white" {} 
_ShadowTex ("Shadow Texture", 2D) = "white" {}

However, this requires 3 separate images.

What I’d like to do, is place all three textures on one bigger texture, with one sub-texture in each quadrant. The shader would then use three quadrants of the bigger texture, instead of three separate, smaller textures.

This would theoretically be accomplished with three texture fields (extreme pseudo code, dunno if this is possible):

// Quadrant samples
_MainTex ("Main Diffuse", 2D) = "white" { 0,0,0.5,0.5 }
_SubTex ("Secondary Diffuse", 2D) = "white" { 0,.5,.5,1 } 
_ShadowTex ("Shadow Texture", 2D) = "white" { .5,0,1,.5 }

Or, it could be accomplished through sub-shader code:

SetTexture [_MainTex]{
    quadrant (0,0,.5,.5)  // Doesn't exist
    combine constant lerp (constant) texture
}

This may require a fragment shader, which I’m trying to avoid for compatability reasons.

I’m continuing to research it myself, but any advice would be appreciated. Thanks!

You can do it as long as your UVs are in 0-1 range.

If you want to do it in fixed pipeline shaders you ahve to use texture UV matrix (Unity - Manual: ShaderLab: legacy texture combining) to scale and offset texture UVs.