- Home /
Distant object won't render in 'distance camera'
I'm making a space exploration game which deals with huge distances, so to avoid that annoying render-flickering caused by not having enough world-space z-distance 'resolution', I've split my render between 2 cameras; one for objects 0.1 to 1000 units, the other for objects greater than 1000 units distant. This mostly works fine...
....Apart from the 'sun' in my game. I've written a custom surface shader for my sun object, which has white fade to 0 alpha at the edge of the sphere to simulate a glow. The problem is, when alpha is included in the shader, the sun fails to render in the 'distance camera'. As a test, I tried extending the 'close' camera's far plane to match the distance camera and the sun - with fading edges, as intended - rendered fine.
What is it about my near camera that lets it 'see' the sun, but my distance camera doesn't? I have not set up any layers in the game, so that isn't the problem. The only difference I can see is that the near camera's 'clear flags' parameter is set to 'Depth only' and the distance camera's is set to 'Skybox'. When I set the distance camera to 'Depth only' the sun renders alright, but nothing gets cleared each frame so the screen rapidly looks like the end of 2001: A Space Odyssey (very psychedelic).
So, is there some way of setting the distance camera so it displays the Skybox and renders the sun correctly?
Here's the shader for my sun. I have tried all manner of Tags and ZWrite, ZTest settings. If anyone has any ideas, I'd appreciate it.
Shader "Unlit/sun shader"
{
Properties {
_Color ("Color", Color) = (1,1,1,1)
}
SubShader {
CGPROGRAM
#pragma surface surf Lambert alpha
struct Input {
float3 viewDir;
};
float4 _Color;
void surf (Input IN, inout SurfaceOutput o) {
half rim = saturate(dot (normalize(IN.viewDir), o.Normal));
rim = (rim * rim) * 2;
o.Albedo = _Color.rgb;
o.Alpha = rim;
o.Emission = 1;
}
ENDCG
}
Fallback "Diffuse"
}
On a side note, how the heck to you get the ' character to display correctly in question titles?
I'd like to have a real answer to this also, but here is a workaround: Create yet another camera, as a child of your distant camera. Set your distant camera to "don't clear' and your new camera to "skybox". That allowed it to display and move normally, for me..
Your answer
![](https://koobas.hobune.stream/wayback/20220612065623im_/https://answers.unity.com/themes/thub/images/avi.jpg)