- Home /
How to render severals cameras at differents Frame Rate ?
Hi everybody !
I work on a project that require to target a good fps amount. In my scene I have two Cameras: The main camera need to be rendered with a maximum fps whereas the second one is display on a renderTexture and can just be set to 30fps. I just want to know if it's possible and if it can really increase the overall fps in the game. I hope this is clear. Don't hesitate to ask questions.
Thank you.
Answer by MariuszKowalczyk · Sep 29, 2015 at 11:43 AM
Hello @Tiras69
The solution is to disable the camera component and use the Render() function at the rate you need.
This solution works, but for some reason it decreases the FPS for me, I am trying to find the reason at the moment.
The solution for the fps drop for me was not to use the Render() function but just to disable and enable the camera at the desired rate.
Hi thank you I tried something with the Render that look like this:
private Camera cam;
void Start () {
cam = GetComponent<Camera> ();
StartCoroutine (DelayedRendering ());
}
public IEnumerator DelayedRendering(){
while (true) {
cam.Render();
yield return new WaitForSeconds(0.0466667f);
}
}
I'm quite happy with that because I increase my overall fps for about 5-10fps.
But I still need to optimize my project (but it's not in the Question field).
Can you tell me how you managed to activate and desactivate the camera component at a precise rate without manualy render the camera ?
Thank you I accept your reply.
Answer by dongiorgi · Oct 21, 2016 at 12:54 PM
This might help
[RequireComponent(typeof(Camera))]
public float FPS = 5f;
public Camera renderCam;
// Use this for initialization
void Start () {
InvokeRepeating ("Render", 0f, 1f / FPS);
}
void OnDestroy(){
//CancelInvoke ();
}
void Render(){
renderCam.enabled = true;
}
void OnPostRender(){
renderCam.enabled = false;
}
I tried the approach that Dongiorgi posted and it works great, improved performance by 5 to 10 frames per second. I've also tried to use renderCam.Render() to manually tell the camera to render but this did not yield any noticable improvements.
I tried attaching this to camera but the camera just says "No cameras rendering". Is there anything else I have to do to get this to work?
thank you so much. now, completely off topic; i'm curious why you would cancel invoke in destroy? does the function go on the heap?
Thank you :)
works great, my 300 fps game runs at 1800 fps now :)), tnx
Your answer
Follow this Question
Related Questions
VSync won't disable 3 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
My object is not reappearing 1 Answer
How to disable position and rotation measurement from VR headset gyroscope? 2 Answers