Skip to content

Conversation

eulertour
Copy link
Member

@eulertour eulertour commented Mar 5, 2021

Motivation

Allows rendering with OpenGL

Overview / Explanation for Changes

Adds an OpenGLRenderer, OpenGLCamera, OpenGL-enabled Mobjects, and a --use_opengl_renderer flag. When this flag is passed, you can pass the -p flag to preview animations, the -w flag to generate video, and the -q flag to specify render quality. If you don't pass either the -p or the -w flag, nothing will happen. Scenes rendered with the OpenGL renderer must only use OpenGL-enabled Mobjects.

Oneline Summary of Changes

- Added OpenGL rendering (:pr:`PR NUMBER HERE`)

Testing Status

None :/

Further Comments

Temp files are currently written to media/temp_x.mp4. This should be changed, but I wanted to focus on getting the rendering done properly. Latex and text also aren't implemented.

Acknowledgements

Reviewer Checklist

  • Newly added functions/classes are either private or have a docstring
  • Newly added functions/classes have tests added and (optional) examples in the docs
  • Newly added documentation builds, looks correctly formatted, and adds no additional build warnings
  • The oneline summary has been included in the wiki
SurfaceExample.mp4

@Darylgolden
Copy link
Member

It seems like most of the OpenGL mobjects are identical except for the parent class. Is it possible to detect which renderer is used, and dynamically switch the top level class (or wherever the classes differ)?

@eulertour
Copy link
Member Author

@Darylgolden That would be doable, but it'd introduce more complexity to an already complex change, so I'd rather not.

@eulertour
Copy link
Member Author

@naveen521kk In general your comments are looking for a level of polish that this PR isn't intended for. Changing the window title and logging with rich is fine, but documenting each of the mobjects is too much and making formatting changes without CI/automation won't last anyway.

@naveen521kk
Copy link
Member

documenting each of the mobjects is too much

I think someone needs to do that right? Essentially, it should be fine at least having typing (as in what type of arguments is accepted either in the docstring or using typing module should be fine.), because the Users (including myself ) aren't familiar with though new Objects, and have no docs seems to be worse. Maybe it can be done later in another PR but it needs to be done before the release.

making formatting changes without CI/automation won't last anyway.

We haven't implemented that, but locally you can use isort for sorting import, at least for the files you created and for line ending something using pre-commit can be used, but sadly requires extra configuration though. Maybe if you want I can push them for you.

Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @naveen521kk for the review! Obviously, your comments should be addressed -- but I agree with @eulertour that this PR probably isn't the right place for this level of detail. I'd also rather have this merged before further work (refactoring classes, adding documentation, general polishing ...) is added to it; right now it is very difficult to keep track of changes because this PR is already so big.

I've just tested the latest version of this PR on MacOS, the example scenes now work as advertised, and the embed feature is really great as well. I'd like to propose to merge this now as-is, and document open TODOs in new issues which we can collect in a new "OpenGL rendering" project board.

My two main concerns are documentation, and the fact that this duplicates lots of code. I don't know yet whether it is possible, but I would really like to have just one Mobject class for both Cairo and OpenGL rendering (and even if it is not possible / turns out to be a bad idea, we can certainly still find ways to reduce duplication).

@naveen521kk
Copy link
Member

I will at least do the formatting and the two comments about using rich and having a nice window title, before merging this PR.

@naveen521kk
Copy link
Member

naveen521kk commented Mar 13, 2021

@eulertour I don't have permissions to push to this branch. Anyway, I attach the patch
0001-Use-rich-for-printing-exceptions.zip
you can apply and then push, using

git am 0001-Use-rich-for-printing-exceptions.patch

and then push

Or simply merge https://github.com/naveen521kk/manim/tree/opengl-format

git pull https://github.com/naveen521kk/manim opengl-format 

@einarf
Copy link

einarf commented Mar 13, 2021

Also, I'm wondering whether it would be possible to use OpenGL renderer on Google Collab? They do provide GPU but are headless system, on 3b1b's manim, I had to do something like

I think that should be a different task/PR. Just need to clean up the window situation (not hardcoding pyglet!). moderngl-window do have a window backend for headless. If the window type was configurable this is easy enough to sort out.

points, du_points, dv_points = uv_surface.get_surface_points_and_nudged_points()
normals = uv_surface.get_unit_normals()
nudge = 1e-2
nudged_points = points + nudge * normals

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ignores the normal_nudge variable which is set in the init and sets it to a constant value

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some may call it a bug, I call it faithful to the original. Anyway I fixed it.

jupyterlab = { version = "^3.0", optional = true }
moderngl = "^5.6.3"
moderngl-window = "^2.3.0"
mapbox-earcut = "^0.12.10"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please bump manimpango to latest version 0.2.4, because it will cause SegFaults or will not work with moderngl with wheels in place.
REF:

@naveen521kk
Copy link
Member

Also, when I run

python -m manim example_scenes/opengl.py --use_opengl_renderer -p

it opens a window which is fine
image

if I run

python -m manim example_scenes/opengl.py --use_opengl_renderer

nothing happens, it neither opened a windows, nor wrote to a file, media dir was empty

when I run

python -m manim example_scenes/opengl.py --use_opengl_renderer -w

only then it write to a File in media directory and there were temp_*.mp4 files also, which I think you already mentioned.

when I run

python -m manim example_scenes/opengl.py --use_opengl_renderer -wp

a windows pops up, write to a file but the rendered file didn't open in vlc or something, which means, -p works differently when using opengl renderer which shouldn't happen.

Another thing I notices when running

python -m manim example_scenes/opengl.py --use_opengl_renderer -wp

and resizing the window, I get a warning from ffmpeg, and the video looked weird see below

$ python -m manim example_scenes/opengl.py --use_opengl_renderer -wp
Manim Community v0.4.0
1: InteractiveDevelopment
2: SurfaceExample

Choose number corresponding to desired scene/arguments.
(Use comma separated list for multiple entries)
Choice(s):  2
[rawvideo @ 0000000001a35240] Invalid buffer size, packet size 8016976 < expected frame_size 8294400
Error while decoding stream #0:0: Invalid argument
[03/14/21 08:51:09] INFO     Animation 0 : Partial     scene_file_writer.py:395
                             movie file written in
                             {'media/temp_0.mp4'}
[03/14/21 08:51:24] INFO     Animation 1 : Partial     scene_file_writer.py:395
                             movie file written in
                             {'media/temp_1.mp4'}
[03/14/21 08:51:40] INFO     Animation 2 : Partial     scene_file_writer.py:395
                             movie file written in
                             {'media/temp_2.mp4'}
[03/14/21 08:51:57] INFO     Animation 3 : Partial     scene_file_writer.py:395
                             movie file written in
                             {'media/temp_3.mp4'}
[03/14/21 08:52:24] INFO     Animation 4 : Partial     scene_file_writer.py:395
                             movie file written in
                             {'media/temp_4.mp4'}
[03/14/21 08:52:52] INFO     Animation 5 : Partial     scene_file_writer.py:395
                             movie file written in
                             {'media/temp_5.mp4'}
                    INFO                               scene_file_writer.py:579
                             File ready at H:/manim-py
                             /manim/media/videos/openg
                             l/1080p60/SurfaceExample.
                             mp4

                    INFO     Rendered SurfaceExample               scene.py:176
                             Played 6 animations

and the temp_0.mp4 file was like this

temp_0.mp4

sudo apt update
sudo apt install -y ffmpeg
sudo apt-get -y install texlive texlive-latex-extra texlive-fonts-extra texlive-latex-recommended texlive-science texlive-fonts-extra tipa
sudo apt-get -y install texlive texlive-latex-extra texlive-fonts-extra texlive-latex-recommended texlive-science texlive-fonts-extra tipa freeglut3-dev python-opengl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sudo apt-get -y install texlive texlive-latex-extra texlive-fonts-extra texlive-latex-recommended texlive-science texlive-fonts-extra tipa freeglut3-dev python-opengl
sudo apt-get -y install libpango1.0-dev texlive texlive-latex-extra texlive-fonts-extra texlive-latex-recommended texlive-science texlive-fonts-extra tipa freeglut3-dev python-opengl

@eulertour
Copy link
Member Author

None of the text mobjects are ported in this PR so there's no need to worry about pango. I added it to the CI anyway since there were some dependencies I only added for testing.

The way the flags work is detailed in the commit description. Using -wp works for me, but then again I never did it while resizing windows. Using both flags at the same time doesn't make much sense anyway, since the rendering speed would be throttled to keep the frame rate constant. It makes sense that resizing the window while writing to a video would ruin the video, since the number of pixels in each frame isn't constant.

@naveen521kk
Copy link
Member

Using both flags at the same time doesn't make much sense anyway

I expected to render the video and then open in the media player, anyway that can be fixed later :).

None of the text mobjects are ported in this PR so there's no need to worry about pango. I added it to the CI anyway since there were some dependencies I only added for testing.

Locally run poetry lock, there do exists problems even when Text objects aren't ported because everything happens because of Pango included in ManimPango wheels gets loaded first which creates problem.

The way the flags work is detailed in the commit description.

I wasn't following this initially. I expected just running python -m manim example_scenes/opengl.py --use_opengl_renderer without any flags should render a video, but on the other hand nothing happened, it just rendering but no video nor a window.

Copy link
Member

@naveen521kk naveen521kk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm,
the flags had some problems but that can fixed in a later PR.

@eulertour
Copy link
Member Author

I expected to render the video and then open in the media player, anyway that can be fixed later :).

The -p flag displays the live preview with the OpenGL renderer, it doesn't make much sense to preview with the mp4 when the window is available.

Pango included in ManimPango wheels gets loaded first which creates problem.

Pango continues to cause bugs despite not being central to the library's use and even when it isn't used. Code like this should be delegated to a plugin, even if it's still included in the pip package.

I wasn't following this initially. I expected just running python -m manim example_scenes/opengl.py --use_opengl_renderer without any flags should render a video, but on the other hand nothing happened

This is mentioned in the commit description, it's intentional.

@eulertour eulertour merged commit bc16210 into ManimCommunity:master Mar 14, 2021
@naveen521kk
Copy link
Member

The -p flag displays the live preview with the OpenGL renderer, it doesn't make much sense to preview with the mp4 when the window is available.

I would like to have an option to see the video after rendering, and we were using -p in other places for that, so we should think of an other flag for previewing window.

This is mentioned in the commit description, it's intentional.

👍
but still I think that needs to be changed.

Pango continues to cause bugs despite not being central to the library's use and even when it isn't used. Code like this should be delegated to a plugin, even if it's still included in the pip package.

Wheels were removed in the latest release, so that shouldn't be a problem, that's why I asked you to have it as the minimum version. Also, there were no reports of installation failure or any other bugs, that caused them to not able to use Manim, other than that of SegFaults in Manimgl, see ManimCommunity/ManimPango#27. Also, does it bothers you anywhere else?

Also, Manim should have at least one Text rendering either latex or pango's, and we are encouraging in our docs that LaTeX are optional so Pango, should be included in the Core of Manim.

@eulertour
Copy link
Member Author

I'll start a new issue about it.

@jsonvillanueva jsonvillanueva added new feature Enhancement specifically adding a new feature (feature request should be used for issues instead) highlight For contributions that should be highlighted explicitly in the next changelog labels Mar 23, 2021
@behackl behackl added this to the Release v0.5.0 milestone Mar 24, 2021
@jsonvillanueva jsonvillanueva removed the new feature Enhancement specifically adding a new feature (feature request should be used for issues instead) label Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

highlight For contributions that should be highlighted explicitly in the next changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants