Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Scriptable camera position #56

Open
sebastien opened this issue Jan 7, 2019 · 5 comments
Open

Scriptable camera position #56

sebastien opened this issue Jan 7, 2019 · 5 comments

Comments

@sebastien
Copy link

I would like to run curv with an offscreen rendering target (like -o png) so that it works with all curv programs. For instance:

curv -o png -O aa=4 curv/examples/mandelbrot.curv

yields the following error:

ERROR: can't export an infinite 2D shape to PNG
at file "deps/curv/examples/mandelbrot.curv":
 1|>make_shape {
 2|>    dist : everything.dist,
 3|>    colour (x,y,_,_) :
 4|>        do  var z := [x,y];
 5|>            var color := [0,0,0];
 6|>            var i := 0;
 7|>            while (i < 100) (
 8|>                z := csqr(z) + [x,y];
 9|>                if (dot(z,z) > 4)
10|>                    let cr = (i-1)-log(log(dot(z,z))/log 2)/log 2;
11|>                    in (
12|>                        color := [0.95+.012*cr, 1, .2+.4*(1+sin(.3*cr))];
13|>                        i := 100;
14|>                    )
15|>                else
16|>                    i := i + 1;
17|>            );
18|>        in sRGB.HSV color,
19|>    is_2d : true,
20|>}

I suppose this could be solved by introducing new options/flags to specify what should be rendered:

  • width, height for the width/height of the resulting image
  • scale for 2d renders (ie, the zoom)
  • x,y,z camera position for 3d renders (not sure if we can set fov and up) -- or whatever parameters you already use for rendering the 3d shapes.

This will allow me to fallback to server-side rendering when shaders don't compile to working WebGL:

image

@doug-moen
Copy link
Member

I think this restriction against exporting an infinite shape only applies to 2D shapes. It's because the 2D shape is scaled to fill the image. For 3D shapes, you essentially get a screen dump of whatever normally appears in the viewer window.

Here is a quick workaround:

curv -o mandel.png -x 'intersection(file "examples/mandelbrot.curv", rect(10,10))'

This trick provides a lot of flexibility, and covers most of what you asked for. There is no accessible FOV parameter right now, however.

@sebastien
Copy link
Author

Smart! But what about camera position on a 3D shape and output image resolution? It's not super urgent, as I think the WebGL 2 fix that you suggested will solve this problem for now, and I can generate PNG from the canvas.

@doug-moen
Copy link
Member

Curv generates a PNG from the OpenGL viewport, and as you noted, it's just as easy for you to do that. In which case, you have direct control over camera and zoom.

From the Curv command line, you can simulate zoom and camera control by scaling, translating and rotating the object. It's a bit hacky; scriptable camera controls might be a good idea.

From the Curv command line, when exporting to PNG, you control output image resolution using -Oxsize= and -Oysize=. But, there is no command line control of the size of the viewer window, so that's another extension you might need.

@doug-moen doug-moen changed the title Offscreen rendering to PNG Scriptable camera position Sep 4, 2019
@doug-moen
Copy link
Member

Cleaning up old issues...
This now works: curv -o png -O aa=4 curv/examples/mandelbrot.curv.
What's left to do? Scriptable camera position, using -O camera=....
Updating title of issue.

@lf94
Copy link
Contributor

lf94 commented Sep 23, 2021

This would be cool for two reasons:

  1. Allows for generating nice previews for people
  2. Gives curv some exposure when sharing said previews :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants