我在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