0
\$\begingroup\$

first of all I'm sorry for asking noob-ish question. This is my fifth day trying to make a shader in Unity.

I'm trying to select an area within my UV image as shown below

the UV I use

and here's how it looks like on the mesh

How it looks like in unity

Basically I'm only selecting the red from the UV and apply it to the mesh. I encountered no problem when trying to select from the RGB, but when i try to use the XYZ for the coordinate position, it turns out that the value of x and r is the same, so is y and g, and z and b.

My question is, how to select by the coordinate position in the UV texture?

Thanks.

here's my code :

    Shader "Custom/ASK RGB" {
    Properties {
        _tex ("Tex", 2D) = "white" {}
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Lambert

        sampler2D _tex;

        struct Input {
            float2 uv2_tex : TEXCOORD1;
            float4 pos : TEXCOORD1;
        };

        void surf (Input IN, inout SurfaceOutput o) {
            // my variable used to store the UV texture mentioned
            half4 tex = tex2D (_tex, IN.uv2_tex.xy); 

            // my attempt to use position which doesn't work
            half4 texPos = half4(IN.pos);

            half4 tryUV = tex2D(_tex, IN.uv2_tex.xy);

            tex.a = 1 - tex.b - tex.r - tex.g;

            tryUV.a = tex.r;

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

1 Answer 1

0
\$\begingroup\$

.xyz is just the same as .rgb, the idea is that you use whichever makes the most sense in the context you are using it.

I think the values you want are in IN.uv_tex.x and IN.uv_tex.y

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Thanks so much for the fast reply! It works perfectly as I intended! :D \$\endgroup\$
    – Alf
    Commented Aug 3, 2016 at 10:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .