Using Part Texture, Part Solid Color

Hey everyone, been banging my head against that wall and have realized I need to go about learning shaders in a different way. But in the meantime I’ve decided to seek help to get a bit of guidance.

What I am trying to do is create a surface shader (Assuming its surface shader) that would draw the texture on the bottom half of the mesh, and a solid color on the top, based on a percent pass by from a script.
Based on my paint skills hopefully the image gives a representation of what I’m hoping to do. What should I be researching (terms, type of shader etc) for me to achieve this effect? As much as I’d love to straight out ask for someone to write a shader, I won’t learn anything.

Thanks In Advance!

You need to define a float to use as your mask. Probably vertex world position. Once you have that you’ll lerp between your texture and your color.

Slices Via World Space Position is a good example of world position for you:

1 Like

Well for the most part it’s coming along, using the world position got me off on the right foot anyways and a bit of research.

So, with the lerp I’m going to be getting that blended fade into the color, which I’m looking for a solid straight line with its height being determined by a float that’s passed to the shader from script (In a sense a range of 0-1 for percent)

Shader "Custom/Buildings"
{
    Properties
    {
        _MainTex("Texture", 2D) = "white" {}
        _Color("Color", Color)  = (0.0, 0.0, 1.0, 1.0)
        _Percent("Percent", Range(0,1)) = 0.5
    }
   
    SubShader
    {
        Tags { "RenderType" = "Opaque" }
        Cull Off
        CGPROGRAM
        #pragma surface surf Lambert
       
        struct Input
        {
            float2 uv_MainTex;
            float3 worldPos;
        };

        sampler2D _MainTex;
        sampler2D _BumpMap;
        fixed4 _Color;
        float _Percent;
        float minHeight = 0;
        float maxHeight = 1;
       
        float inverseLerp(float a, float b, float value) {
            return saturate((value - a) / (b - a));
        }

        void surf(Input IN, inout SurfaceOutput o)
        {
            float heightPercent = inverseLerp(minHeight, maxHeight, IN.worldPos.y);
            half3 c = tex2D(_MainTex, IN.uv_MainTex);
            half3 t = inverseLerp(_Color, c.rgb, heightPercent - _Percent);
            o.Albedo = _Color.rgb;
            o.Albedo *= c.rgb + t.rgb;
        }
        ENDCG
    }
        Fallback "Diffuse"
}

Now I’m looking to base this off of local coordinates so I will have to figure out how to find the min height and max height of the model in world coordinates. World to local is simple enough, but as for figuring out the maxHeight I’m not to sure.

The desired effect I’m going for is a “building” in an RTS to be filled with its required resources. The amount of resources is represented by a percent (Which is passed to the shader to show the blue color as representation of how much is left to go) Hope that use case makes sense.

PS thanks for the reply brownboot67!

And thanks in advance for any help on this!

You’ll want to either sharpen the lerp transition, or just use an if conditional.