# Rendering

VCStudio has an internal rendering system. It's not a render engine. It's not trying to compete with Cycles or EEVEE. It's a render helper. 

You may use what ever engine, you so desire. The VCStudio rendering system is there to give you assistance, analytics, possibly optimization and most notably, reliability. 

When we made [our movies](../../wiki/extra/Movies.md) rendering was a very problematic and headache inducing problem. Low powered machines we used were known to give up. Known to crash often. So a series of helping algorithms and protocols were needed to make the rendering more reliable. 

These protocols and algorithms are present to this day in VCStudio. And are improved constantly by our new projects. So you could also get your rendering done reliably.

### Chapters:

 - [User Guide](#user-guide)
 - [Protocol](#protocol)
 - [Source Code](#source-code)

# User Guide

From the [Script Writer](../../wiki/docs/Script-Writer.md) you can access the animation blender files ( .blend ) that can be rendered with the VCStudio rendering system. Those files will have 2 additional buttons.

![](https://notabug.org/jyamihud/update_manager/raw/master/vcstudio/38.png) 

As you can see this file has two buttons ![](../../settings/themes/OldSchool/icons/obj_link.png) and ![](../../settings/themes/OldSchool/icons/render.png). The first one is to [link assets](../../wiki/docs/LinkingAssets.md). But the recond one. The ![](../../settings/themes/OldSchool/icons/render.png) button is to set this file for rendering via the VCStudio rendering system.

When you click it you will have a settings window similar to this.

![](https://notabug.org/jyamihud/update_manager/raw/master/vcstudio/77.png)

This is a settings window for your render. Things that you can't set from here, you need to set in the blender file. Things like render engine ( Cycles, EEVEE ) resolution and samples should be set prior to this. These settings here are only the surface level managing settings. Like the output image format and the folder in which these images will be saved.

Note that you cannot select to output a video file. Only separate frames. Our experience had shown that rendering video is the worst type of mistake when it comes to frames that take more then a few seconds of rendering. Should any frame crash, you will lose the whole video file. Rather than just that one frame.

For image formats like PNG, JPG and EXR this window provides additional information. If you click the ![](../../settings/themes/OldSchool/icons/question.png) button beside each format, you will get broader technical and historical information about this format. To be more informed on the decision. 

On the other side you can see the ![](../../settings/themes/OldSchool/icons/ok.png) or ![](../../settings/themes/OldSchool/icons/cancel.png) icons. This indicate whether a given format is recommended to use. Since some formats can cause technical and even legal issues when used in some countries via some software. For example the infamous audio format `mp3` caused a great legal tension for the Free Software world since it used to be under a software patent in the US until 2017. Which made using Free Software to access `mp3` files potentially illegal.

![](../../settings/themes/OldSchool/icons/question.png) [What is Free Software?](../../wiki/extra/FreeSoftware.md)

The recommendation is judged solely on whether this format is a [Free Format](http://www.linfo.org/free_file_format.html). Meaning, implementing it in Free Software is possible and completely legal.

For a folder in which the render frames will be saved you can select one of 4 options. ![](../../settings/themes/OldSchool/icons/storyboard.png), ![](../../settings/themes/OldSchool/icons/opengl.png), ![](../../settings/themes/OldSchool/icons/test_rnd.png) or ![](../../settings/themes/OldSchool/icons/rendered.png). 

These icons represent 4 stages of making a shot. Storyboard, Animation Preview, Test Render and Final Render. But since VCStudio is backward compatible with old Blender-Organizer. The folder naming stayed the same since 2016. Meaning the names of the folders are:

![](../../settings/themes/OldSchool/icons/storyboard.png) - `storyboard`

![](../../settings/themes/OldSchool/icons/opengl.png) - `opengl`

![](../../settings/themes/OldSchool/icons/test_rnd.png) - `test_rnd`

![](../../settings/themes/OldSchool/icons/rendered.png) - `rendered`

Additionally from this window you can also set the start and the end frame for your animation. But this will be read from the blend file regardless. This is just an extra setting if you want to render a specific part of the animation without editing the frames in the blender file.

Also ![](../../settings/themes/OldSchool/icons/clean.png) option is there if you like the render system to delete the contents of the folder before starting rendering. Rendering **all frames** and not just those missing in the folder. By design the Protocol is going to only fill up missing frames. Meaning if you have all frames rendered, and press render. It will automatically finish the rendering since there are no frames missing. So you have to erase them before re-rendering.

![](https://notabug.org/jyamihud/update_manager/raw/master/vcstudio/42.png) 

To start the rendering you press ![](../../settings/themes/OldSchool/icons/right.png). Which will remove the settings from the current render and transform the window into an analytics view. So stop rendering you press ![](../../settings/themes/OldSchool/icons/stop.png). *You may need to press it multiple times. Since rendering is happening in a separate process from VCStudio. (see Protocol and Source Code below.)*

It will give an average time of one frame and an approximate time of how much you have to wait till the end of the whole shot.

Note that on this image you can also see another render waiting below the current one. This is what we call a "render list" similar to playlist in a music program. You can set up multiple renders and they will automatically start as soon as the previous will end. This will give you an ability to render more the one shot overnight, when going away for a few days, or using another machine. With the reliability protocol added to it, it will make your life so much simpler.

# Protocol

I'm mentioning this reliability protocol. But what is it, and how it works? Let's look at the problems this system is trying to solve and hopefully you can get an answer of why this system exists in the first place.

When we used to make "I'm Not Even Human" which is a 32 minute long animation film. We had a very hard rendering problem. Every two or three frames the rendering would crash. Meaning I could not leave it over night. I had to restart rendering every 2 or three rendered frames. If you make a quick calculation 32 minutes is about `1920` seconds. If you multiply it by 24 frames per second. It's `46080` frames. In the best case scenario when a crash happening every 3 frames, I would have to start a render a whopping `15360` times. Which is fifteen thousand thee hundred and sixty times. Not very reliable. 

It was way better then rendering each frame separately, but you may agree with us that it was a nightmare to say the least. At first we tried to fight with Blender and optimize the scenes. But cutting out quality of the project just because the third frame is failing seemed wrong. This third frame would render if we would start from this frame. It only would not render if there were two frames rendering before hand.

So a tiny python script was introduced into a very early version of the Organizer. That would start `blender -b` rendering (an ability to start rendering without loading blender's UI), but only for one frame. Then would start blender separately for the second frame. And then the third and so on. The script substituted me constantly restarting rendering. It was doing the tedious job for me.

Later we realized that this wasn't enough. Few frames would still crash. Much less frequently, but it still happened. This left an otherwise full folder with one or two random frames missing. Resulting in a hard to spot problem. You would see a list of files similar to ... `0023.png`, `0024.png`, `0026.png`, `0027.png` ... with `0025.png` missing. 

So in a later revision of this script, a change was made instead of running Blender for each number. Run Blender for the next missing frame in the folder. That made for a very reliable algorithm. If a crash would happen. The file would not appear. So the algorithm would start rendering this frame all over again. 

VCStudio implementation goes a bit further then that. As it's also records the times each frame took for analytics. And it's running as it's own separate process. Giving you ability to close VCStudio completely while keeping the render doing it's job on the background.

# Source Code

The best documentation is to read the code of the software directly. For the render I recommend:

- [studio/studio_renderLayer.py](../../studio/studio_renderLayer.py) The UI of the rendering window.
- [network/network_renders.py](../../network/network_renders.py) The functions that make all the UI updating. And interact with the rendering process.
- [network/during_render.py](../../network/during_render.py) The script that launches `blender -b` for each frame.

**I noticed Network in the title. What's up with this?**

In the legacy Blender-Organizer we also had a rendering system. But it had a constantly updating UI window. The UI would launch a `subprocess.Popen()` instance of `blender -b` and pipe all it's outputs to itself. Therefor reading the string that blender outputs and attempting to parse it in some way for analytics. The problem was that if I don't kill the blender instance when closing the window there was no way to catch it and cancel it later. So I was stuck with this UI no matter what.

This time [network/during_render.py](../../network/during_render.py) is working all by himself. Without any UI. And it's using UDP network protocol to talk to VCStudio. I'm using the `localhost` for it. So it's not using the Internet. It's just using the protocol developed for the internet, but locally.

This gives me ability to read the string that blender outputs and interact with the render script from VCStudio. But it also gives me the ability to close VCStudio completely. And still have the render running somewhere on the background. No UI nothing. 

I've included 2 scripts in order to talk to the renderer while it's rendering. For developers or just tinkerers.

- [network/read_messages.py](../../network/read_messages.py)
- [network/send_messages.py](../../network/send_messages.py)

Both scripts are terminal based.

# Help The Documentation

The documentation files are not perfect. And need maintenance.

*If you are reading it from the VCStudio build in Documentation:*

 - Press ![](../../settings/themes/OldSchool/icons/edit.png) to edit locally.
 - Press ![](../../settings/themes/OldSchool/icons/notabug.png) to commit in our NotABug repository.

*(C) J.Y.Amihud 2021. Under GPL v3 or later.*
