1
\$\begingroup\$

I recently learned how to write shader in Unity and I'm trying to move the texture within one of my variable.

this is the texture I used on the model.

texture I used

I separated the texture into two shapes, which is texRound and texStar based on position. What I'm trying to do is to move the star texture stored in texStar variable without affecting the position of texRound.

moving the star texture

What comes to my mind right now is to use something like this code below, but it doesn't work as the texStar variable only save the color value without the position.

(texStar.x + posModifier).a = texUV.r;

What should I do to access the position of the texStar variable? Thank you so much in advance.

Here's my full code:

Shader "Custom/ASK RGB" {
    Properties {
        _UV ("UV", 2D) = "white" {}

        // variable I intend to use as modifier value to change the y position of the star texture
        _modifier ("Modifier" , float) = 0 
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Lambert

        sampler2D _UV;

        struct Input {
            float2 uv2_UV : texCOORD1;
        };

        void surf (Input IN, inout SurfaceOutput o) {
            // variable used to store the UV texRoundture mentioned
            half4 texUV = tex2D (_UV, IN.uv2_UV.xy); 

            // variables used to store the round texture and the star texture
            half4 texRound;
            half4 texStar;

            if (IN.uv2_UV.x > 0.7)
            {
                if (IN.uv2_UV.y > 0.5)
                {
                    texRound.a = texUV.r;
                    texStar.a = 0;
                }

                else
                {
                    texRound.a = 0;
                    texStar.a = texUV.r;
                }
            }
            else
            {
                texRound.a = 0;
                texStar.a = 0;
            }

            texRound.rgb = texUV.rgb;
            texStar.rgb = texUV.rgb;

            o.Albedo =  texRound.rgb * texRound.a + texStar.rgb * texStar.a;
        }
        ENDCG
    } 
    FallBack "Diffuse"
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.