Yuval3210
Yuval3210

Reputation: 193

Combining 2 shaders in unity

I have a sphere in my game and I need to have a texture on its insides. For that I use a certail script. I also want to be able to fade textures in and out with a function I have in another script.

But I can not combine these script. No matter what I try, the image doesn't show inside the sphere.

The shaders are:

Flip Insides:

Shader "Flip Normals" {
      Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
     }
      SubShader {

        Tags { "RenderType" = "Opaque" }

        Cull Front

        CGPROGRAM

        #pragma surface surf Lambert vertex:vert
        sampler2D _MainTex;

         struct Input {
             float2 uv_MainTex;
             float4 color : COLOR;
         };


        void vert(inout appdata_full v)
        {
            v.normal.xyz = v.normal * -1;
        }

        void surf (Input IN, inout SurfaceOutput o) {
                  fixed3 result = tex2D(_MainTex, IN.uv_MainTex);
             o.Albedo = result.rgb;
             o.Alpha = 1;
        }

        ENDCG

      }

      Fallback "Diffuse"
 }

And the fader:

 Shader "Custom/AlphaBlendTransition" {
 Properties {
 _Blend ("Blend", Range (0, 1) ) = 0.0
 _BaseTexture ("Base Texture", 2D) = "" {}
 _OverlayTexture ("Texture 2 with alpha", 2D) = "" {}

 }
 SubShader {
     Pass {
         SetTexture[_BaseTexture]
         SetTexture[_OverlayTexture] {
             ConstantColor (0,0,0, [_Blend]) 
             combine texture Lerp(constant) previous
         }
     }
  }
}

Is it possible to combine these shaders while still viewing the texture from the spheres inside?

Upvotes: 2

Views: 1156

Answers (1)

Jansen
Jansen

Reputation: 356

There is a way to avoid needing both. You can use any 3D modeling software to export a sphere with flipped normals, and them import it to Unity to apply only one material with the AlphaBlendTransition shader.

Upvotes: 2

Related Questions