Unity3d 简单的双面自定义着色器看起来很奇怪
我对着色器编程非常陌生,我尝试创建一个着色器,该着色器: 允许使用2个对应的法线贴图更改2个纹理淡入/淡出 双面显示曲面两侧的网格 以下是我的结论:Unity3d 简单的双面自定义着色器看起来很奇怪,unity3d,3d,shader,Unity3d,3d,Shader,我对着色器编程非常陌生,我尝试创建一个着色器,该着色器: 允许使用2个对应的法线贴图更改2个纹理淡入/淡出 双面显示曲面两侧的网格 以下是我的结论: Shader "Custom/TextureBlend" { Properties { _Color ("Color", Color) = (1,1,1,1) _Blend ("Texture Blend", Range(0,1)) = 0.0 _M
Shader "Custom/TextureBlend" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_Blend ("Texture Blend", Range(0,1)) = 0.0
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_MainTex2 ("Albedo 2 (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_BumpMap ("Bumpmap", 2D) = "bump" {}
_BumpMap2 ("Bumpmap", 2D) = "bump" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Cull Off
ZTest LEqual
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _MainTex2;
sampler2D _BumpMap;
sampler2D _BumpMap2;
struct Input {
float2 uv_MainTex;
float2 uv_MainTex2;
float2 uv_BumpMap;
float2 uv_BumpMap2;
};
half _Blend;
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = lerp (tex2D (_MainTex, IN.uv_MainTex), tex2D (_MainTex2, IN.uv_MainTex2), _Blend) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
fixed4 n = lerp (tex2D (_BumpMap, IN.uv_BumpMap), tex2D (_BumpMap2, IN.uv_BumpMap2), _Blend) * _Color;
o.Normal = n.rgb;
}
ENDCG
}
FallBack "Diffuse"
}
它可以工作,但由于某些原因,曲面上的纹理在网格的另一侧看起来很暗,而网格的另一侧通常不可见,甚至更暗,法线贴图反射几乎不可见
在这里,在左侧可以看到带有“我的着色器”的平面,在右侧-标准着色器:
此外,反射看起来非常奇怪,如果我将金属滑块向右移动,您将看到它:
法线贴图存储矢量信息,而常规纹理不带符号,因此需要使用UnpackNormal辅助对象方法。你也不需要乘以颜色 最终代码将大致如下: fixed4 n0=tex2D_凹凸贴图,IN.uv_凹凸贴图; fixed4 n1=tex2D_BumpMap2,IN.uv_BumpMap2; o、 Normal=解压normallerpn0,n1,_Blend.xyz;