#How do I use a shader with different textures and other variables on different objects?

1 messages · Page 1 of 1 (latest)

hasty gazelle
#

I have a shader that gets a texture, and then just changes pure red and green to other color that I want to be customizable with each individual object:

// This is an Image Effect Shader with transparency enabled
fixed4 frag (v2f i) : SV_Target
{
    fixed4 col = tex2D(_MainTex, i.uv);

    [branch] if (col.r == 1 && col.g == 0) // If pixel color is Red (or magenta, but this will never be the case)
    {
        fixed br_fc = 6; // Controls how dark the darker shade is
        fixed4 new_color = _Color / br_fc; // Get darker shade
        new_color.a = 1; // Set transparency to 1
        return new_color; // Return new color
    }

    [branch] if (col.r == 0 && col.g == 1) // If pixel color is Green (or cyan, but again, this will never be the case)
    {
        // Just return the desired color
        return _Color;
    }

    // Else dont change anything
    return col;
}

How do I use this so the _MainTex and _Color variables aren't shared between different objects, without creating a million materials?

west heath
#

Million materials

#

Or you get creative with how you're packing the textures, and perhaps leaving some color attributes in the mesh data