2017-07-17 21 views
1

私は正常に動作カスタムノーマルマップされた+鏡面スプライトシェーダーをしましたrendertexture。しかし、レンダーテクスチャに描画しようとすると、私のスプライトは見えなくなります。 Unityのデフォルトのシェーダを使って他のスプライトと同じようにアルファが0に設定されていると思います。

どうすればこの問題を解決できますか?

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

答えて

1

EDIT:だから、私は問題を発見しました!

#pragma surface surf BlinnPhongTransparent keepalpha // <= here 

と私は、「レイヤー」で他の問題を発見したが、多分あなたはこのことを知っ:最初の惑星は、カメラに最も近い最初の座標ではなく、第2遊星後ろにレンダリングします。

RT_lowres = new RenderTexture(width_rt, height_rt, 1, RenderTextureFormat.ARGB32);// if 0 bad "layers" 

ヒント:シェーダでグローバル変数を使用してパフォーマンスを向上させることができます。シェーダで

void Start(){ 
    //.... 
    lowresCam.targetTexture = RT_lowres; 
    Shader.SetGlobalTexture("_LowResTexture", RT_lowres); 
} 

void OnRenderImage(RenderTexture src, RenderTexture dest){ 
    Graphics.Blit(src, dest, compositionMaterial); 
} 

笑:

Properties 
{ 
    _MainTex ("Texture", 2D) = "white" {} 
} 
//..... 
sampler2D _MainTex; 
sampler2D _LowResTexture; 
fixed4 frag (v2f i) : SV_Target 
{ 
    //... 
    fixed4 lowres = tex2D(_LowResTexture, i.uv); 
    //... 
} 
+0

巨大な感謝。レンダリング・テクスチャの透明性にもかかわらず、私はこれがうまくいくかどうかを知らせますが、シェーダはバットから外れます。 –

+0

それは働いていません。私はポストエフェクトでアルファブレンドされた2つのレンダリングターゲット、クォータレスではバックグラウンド、ゲームプレイオブジェクトではメインカメラを持っています。 3Dオブジェクトと従来のスプライトが描画されますが、シェーダを持つ私の船は見えません。私の船の図面をUnityのMobile/Particles/Alpha Blendedに変更すると、通常のマップライティングは行われません。あなたは 'それは通常の仕事になりますSpriteRenderer'にこの材料を置けば –

+0

@DavidCoombesはそう、あなたの船は、シーン内の可視および/またはカメラのでしょうか?または何?いくつかのスクリーンショットをつけたり、何かを描けますか? **このシェーダは私のプロジェクトで動作しますが、私はあなたの中でどのように動作しなければならないのか分かりません。** – nipercop