我在Unity中製作了一個太空探索遊戲,我遇到了半透明問題。在Unity5中正確渲染半透明球體
每個行星都由兩個球體組成:一個是組合表面和雲層,另一個(半徑稍大)通過剔除正面和衰落alpha到外邊緣來描述地平線'發光'領域。這主要是做工精細,但有以下兩個問題:
1)在我定製的表面材質,當我使用Alpha關鍵字在#pragma定義,阿爾法被計入呈現球面,但「光暈」球體在幾千個單位的距離消失。如果我不包含alpha關鍵字,則球體不會向邊緣褪色,但會在距離處呈現。 2)儘管嘗試所有的RenderType,Queue,ZWrite和ZDepth選項,表面球體和'發光'球體是z戰鬥;遊戲似乎無法確定哪個多邊形更近 - 儘管事實上發光球面上的近面應該被淘汰。我甚至試圖將發光球從球員相機中推開,並以相同的比例擴大其半徑,但我仍然莫名其妙地獲得了球體之間的z戰鬥!
有沒有辦法,我失蹤,這將使該「光暈」領域的任何設置總是被畫後面的表面球(因爲我已經試過ZWrite,ZDepth的所有組合如上所詳述),是有辦法有一個啓用alpha的對象不會在距離消失?
我似乎無法弄清楚這一點,所以任何幫助將不勝感激!
編輯
這裏是我的'輝光球'的着色器代碼。正面被剔除。我甚至嘗試使用Offset關鍵字將任何繪製的多邊形從相機中「推出」。我已經嘗試了所有我能找到的Tag,ZWrite和ZTest選項。着色器被傳遞色調的顏色,氣氛密度浮子和太陽方向矢量...
Shader "Custom/planet glow" {
Properties {
_glowTint ("Glow Tint", Color) = (0.5,0.8,1,1)
_atmosphereMix ("Atmosphere Mix", float) = 0
_sunDirection ("Sun Direction", Vector) = (0, 0, 0, 0)
}
SubShader {
Tags { "RenderType" = "Opaque" "Queue" = "Geometry" }
Cull Front // I want only the far faces to render (behind the actual planet surface)
Offset 10000, 10000
ZWrite On // Off also tried
ZTest LEqual // I have tried various other options here, incombination with changing this setting in the planet surface shader
CGPROGRAM
#pragma surface surf Lambert alpha
#pragma target 4.0
struct Input {
float3 viewDir;
};
fixed4 _glowTint;
float _atmosphereMix;
float4 _sunDirection;
void surf (Input IN, inout SurfaceOutput o) {
_sunDirection = normalize(_sunDirection);
o.Albedo = _glowTint;
float cameraNormalDP = saturate(dot(normalize(IN.viewDir), -o.Normal) * 4.5);
float sunNormalDP = saturate(dot(normalize(-_sunDirection), -o.Normal) * 2);
o.Alpha = _atmosphereMix * sunNormalDP * (cameraNormalDP * cameraNormalDP * cameraNormalDP); // makes the edge fade 'faster'
o.Emission = _glowTint;
}
ENDCG
}
FallBack "Diffuse"
}
你使用LOD嗎?像LOD 250一樣?如果是刪除它。 –
不包含LOD。感謝指針,但。 – moosefetcher
你可以在這裏包含着色器的代碼嗎?我想不出任何會導致這種影響的事情。另外,ZTest Off是一個有效的選擇,儘管沒有在官方的Unity手冊中列出。 – HalpPlz