Sunday, August 28, 2022
HomeGame Developmentc# - Customized Unity shader makes mesh look completely different

c# – Customized Unity shader makes mesh look completely different


I’m very a lot new to customized shaders. My precise downside is that I wish to fade a mesh out and in through C# in Unity. Nonetheless, the supplies on the mesh I’m utilizing are opaque and setting them to clear was inflicting me complications with how the mesh seems (components of the mesh have been displaying by the entrance / dealing with the digital camera in bizarre methods).

So I turned to shaders and I seemed up a really primary shader implementation. As soon as this shader is utilized to the fabric, I will set the alpha channel fairly simply whereas sustaining the overall look of the mesh.

Nonetheless, simply altering from the Normal shader to this primary one, causes the mesh to look completely different. I believed it was lighting associated, however I’ve tried to seek for extra data and I am arising brief. I additionally puzzled whether or not it was the Mix a part of it beneath however I’ve tried a couple of mixtures and none appear to work.

Shader problem

Here is the shader I am utilizing … I imagine that is simply probably the most primary they are often:

Shader "Customized/TransparentShader"
{
    Properties
    {
        _Color("Coloration", Coloration) = (1,1,1,1)
        _MainTex("Texture", 2D) = "white" {}
    }
        SubShader
    {
        Mix SrcAlpha OneMinusSrcAlpha

        Go {
            CGPROGRAM

            #embrace "UnityCG.cginc"

            #pragma vertex vert
            #pragma fragment frag

            sampler2D _MainTex;
            float4 _MainTex_ST;

            fixed4 _Color;

            struct appdata {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f {
                float4 place : SV_POSITION;
                float2 uv : TEXCOORD0;
            };

            v2f vert(appdata v) {
                v2f o;
                o.place = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                return o;
            }

            fixed4 frag(v2f i) : SV_TARGET{
                fixed4 col = tex2D(_MainTex, i.uv);
                col *= _Color;
                return col;
            }

            ENDCG
        }
    }
}

Is there an apparent (noobie) motive the mesh seems so completely different with this primary shader?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments