- Home /
Camera rendering help.
I'm not sure if this is possible without pro for maybe some kind of camera effect, but I want it where I can see through the camera at a far distance but I can only see certain layers at closer distances for better fps. For example if I wanted to make it where a certain layer could be seen so far and then a different layer be seen at a different distance So I choose the layer and higher or lower the float value for the distance rendering. I know it has to be done through a script, but I only know some basic stuff. Can somebody please help me? And if you guys can provide me with a script on how to do this than can you guys put like five different layer variables, that way I can choose how many different things I can see. Please help me I really need this.
Answer by Cains · Nov 05, 2013 at 04:41 PM
You'll want to use the cullingMask variable of the camera and adjust it to include certain layers depending on their distance from the camera, which you can calculate through the distance formula where you can compare the position of the camera and some position variable that represents where the layer is. I'd run this calculation for all layers in a Coroutine that runs every few seconds or so since doing it every frame is kind of overkill.
If point to point distance doesn't work for you, you might want to look up distance between a point and a plane which would probably work better for this case.
If you need me to write up an example I can but I recommend you try it out yourself first.
could you provide a example script for what to do. I'm only know a little bit of scripting nothing this advanced. The way I wanted it though is where in the script there would be layers I could choose and then below the layer I chose there would be a float value that I could change. And when I change that the gameobjects in that layer would fade. I hope you know what I'm trying to say. But if you could provide a example that would be great.
It actually sounds like you're trying to create fog, which Unity can do for you. If you read that link it'll also tell you that though a GameObject may be hidden through fog it will still be rendered.
To stop the rendering for better performance you can edit your camera'a clipping plane in its inspector which controls the distance from the camera where GameObjects are no longer rendered. This distance should be set according to the distance when you can no longer see an object due to fog.
no it's not fog that I want. It's like in most games where some objects such as the terrain can be seen at a very far distance but with no fog. But yet other objects such as buildings or light poles etc... can only be seen at shorter distances. Do you know what I'm trying to say now?
If you could find a game with this effect, it'd be clearer, but to do what I think you want you can set the shaders for your objects to Transparent/Diffuse. Then you could measure the distance from your camera/player to every GameObject and adjust its alpha accordingly.
This will make objects more see through the further they are from you, until they're so far they're invisible, except for things you don't want to do this such as terrain. If this is what you want I can script something for you pretty easily.
Yes please do that. That would be helpfull, and thank you.