1
我有一個自定義的法線貼圖+鏡面精靈着色器,可以正常工作。但是,當我嘗試繪製一個Rendertexture時,我的精靈是不可見的。我猜他們的Alpha設置爲0,因爲使用Unity的默認着色器的其他精靈會被繪製好。爲什麼我的精靈(自定義CG着色器)繪製在Unity rendertexture
我該如何解決這個問題?
Shader "SG/_ShipSurfaceShader" {
Properties {
_MainTex ("Main texture", 2D) = "white" {}
_NormalTex ("Normal map", 2D) = "bump" {}
_SpecColor ("Specular colour", Color) = (1,1,1,1)
_SpecPower ("Specular power", Range (0.0,2.0)) = 0.5
}
SubShader {
Tags { "Queue"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
LOD 200
CGPROGRAM
#pragma surface surf BlinnPhongTransparent alpha
inline fixed4 LightingBlinnPhongTransparent (SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten) {
half3 h = normalize (lightDir + viewDir);
fixed diff = max (0, dot (s.Normal, lightDir));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, s.Specular*32.0) * s.Gloss;
fixed4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * spec) * (atten);
c.a = s.Alpha;
return c;
}
sampler2D _MainTex;
sampler2D _NormalTex;
half _SpecPower;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
o.Normal = UnpackNormal(tex2D (_NormalTex, IN.uv_MainTex));
o.Specular = _SpecPower;
o.Gloss = 1;
}
ENDCG
}
FallBack "Diffuse"
}
巨大的感謝。仍然與rendertexture透明度摔跤,所以會讓你知道如果我得到這個工作,但着色器工作。 –
它沒有工作。我有兩個渲染目標在後期效果中進行了alpha混合,在四分之一res中的背景星雲以及帶有遊戲對象的主要相機。 3D物體和傳統的精靈被畫出來,但是我的船和你的着色器是不可見的。如果我將我的船的繪圖更改爲Unity的Mobile/Particles/Alpha混合,它會繪製,但沒有正常的地圖照明。 –
@DavidCoombes所以,如果你把這個材料放在'SpriteRenderer'上,它將正常工作,你的船在Scene和/或Camera中是可見的?或者是什麼?你可以把一些screensshots或繪製一些sсheme。 **這個着色器在我的項目上工作,但我不知道它是如何在你的工作。** – nipercop