unity-game-engine - 统一组合 2 个着色器

标签 unity-game-engine textures shader transition alpha

我的游戏中有一个球体,我需要在其内部有纹理。 为此,我使用了一个特定的脚本。 我还希望能够使用另一个脚本中的函数使纹理淡入和淡出。

但我无法合并这些脚本。无论我如何尝试,图像都不会显示在球体内部。

着色器是:

翻转内部:

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"
 }

还有推子:

 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
         }
     }
  }
}

是否可以组合这些着色器,同时仍然从球体内部查看纹理?

最佳答案

有一种方法可以避免两者都需要。您可以使用任何 3D 建模软件导出具有翻转法线的球体,然后将其导入到 Unity 中,以便通过 AlphaBlendTransition 着色器仅应用一种 Material 。

关于unity-game-engine - 统一组合 2 个着色器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37365534/

相关文章:

ios - GLSL 着色器编译但不在 Windows 上绘制任何东西

unity-game-engine - 如何使用 Unity 和 ARCore 在现实世界对象(如瓶子)周围生成表面/平面?

c# - 在幸运之轮旋转轮中找到选定的部分

c++ - SFML 中的程序纹理

c - 为什么我的 openGL 纹理只覆盖了我的四边形的一半?包含来源

c++ - Linux下视频文件+片段着色器

c# - 是否可以使用 Bazel 构建 Unity3D 项目?

firebase - 在 Unity 上从 Firebase 远程配置获取广告 ID 时出现问题

opengl - 使用核心配置文件时出现 OpenGL 纹理问题

css - CSS 着色器的浏览器?