Home Game Development c# – Custom Unity shader makes mesh look totally different

c# – Custom Unity shader makes mesh look totally different

0
c# – Custom Unity shader makes mesh look totally different

[ad_1]

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

So I turned to shaders and I appeared up a really primary shader implementation. Once this shader is utilized to the fabric, I’m capable of set the alpha channel fairly simply whereas sustaining the final look of the mesh.

However, simply altering from the Standard shader to this primary one, causes the mesh to look totally different. I assumed it was lighting associated, however I’ve tried to seek for extra info and I’m arising quick. I additionally questioned whether or not it was the Blend a part of it beneath however I’ve tried a number of mixtures and none appear to work.

Shader problem

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

Shader "Custom/ClearShader"
{
    Properties
    {
        _Color("Color", Color) = (1,1,1,1)
        _MainTex("Texture", 2D) = "white" {}
    }
        SubShader
    {
        Blend SrcAlpha OneMinusSrcAlpha

        Pass {
            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 totally different with this primary shader?

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here