Jump to content

[SOLVED] cylindrical capture


photo

Recommended Posts

We are currently looking into a solution that involves extending appPanorama but I would like to figure out where my assumptions for my first attempt were wrong.

 

 

 

namespace Cylinder {
    int num_sections = 32; // number of separate captures to make our 360 degree screenshot.
 
    void capture ( string filename, float height, Player player) {
        float delta_angle = 360.f / num_sections;
        float width = height * 2 * PI;
        float capture_width = width / num_sections;
        float aspect = capture_width / height;
        Mat4 capture_perspective = perspective( delta_angle*aspect, aspect, player.getZNear(), player.getZFar() );
        Vec3 pos = player.getWorldPosition();
 
        Image output = new Image();
       output.create2D(width,height,IMAGE_FORMAT_RGB8,1,1,1);
       Image slice = new Image();
 
       forloop (int i=0; num_sections) {
           Mat4 capture_transform = translate(pos) * rotateZ(-delta_angle * i) * rotateX(90.f);
           player.setWorldTransform(capture_transform);
           engine.render.renderImage2D(capture_projection,player.getModelview(),slice,capture_width,height,getPostMaterials(player),RENDER_HDR_DISABLED);
           slice.convertToFormat(IMAGE_FORMAT_RGB8);
           
           float xpos =i*slice_width;
           image.copy(slice,xpos,0,0,0,capture_width,height);
       }
       image.save(filename);
      
    }
}

I don't seem to be getting either the fov or the aspect ratio to line up - any ideas what I am doing wrong?
Link to comment

Hi Danni,

 

I think it's better to modify AppPanorama (if you have binary license) and add support of 360 cylinder projection. It's easy — all you need to do is to capture images from all sides (front, back, left and right) and then compose them via shader just like curved panorama or fisheye.

Link to comment
float width = height * 2 * PI;

smells a bit funny to me.

 

from the 2*pi*r "width" seems to be cylinder circumference (or total image width), with height doubling as radius. But that seems a bit arbitrary?

 

Taking (2*height) * pi * r seems just as arbitrary (and thus equally correct) but results in different numbers for width and aspect.

 

I assume you're taking height so the cylinder is 1 unit high and has 1 unit radius?

 

Also, your total number of horizontal pixels is less than 2*pi*r. Your 'projection surfaces' are flat, not curved. Ie. for 8 sections, you have an octagon, not a cylinder. The two have different circumferences. If you assume them equal, the projection surface is at >1 (height) radius, which makes your vertical angle / aspect incorrect.

 

 

The second thing that smells funny to me is:

Mat4 capture_perspective = perspective( delta_angle*aspect, aspect, player.getZNear(), player.getZFar() );

function prototype is:

mat4 perspective (float fov,float aspect,float znear,float zfar) 

Why the multiplication with aspect for the fov parameter?

 

if aspect is greater than 1 you will end up with more than 360 fov, if smaller less than 360.

 

Should be just delta_angle?

Edited by esger.abbink
Link to comment

function prototype is:

mat4 perspective (float fov,float aspect,float znear,float zfar) 

Why the multiplication with aspect for the fov parameter?

 

 

 

My understanding is that unigine specifies vertical fov angles - I am calculating a horizontal fov and converting it to vertical.

Link to comment

seems counter intuitive to me but just looked at the source, and you are correct. fov is vertical there.

 

However, then you should divide by aspect to go from horizontal to vertical:

 

aspect = width / height  =>  aspect * height = width  =>  height = width / aspect

Link to comment

Seems you already have cylindrical projection working, Danni.

 

To those who might be interested: we rendered scene four times from different angles (45,-45,225,-225) to square textures so we get the 360 horizontal panorama. Then we pass that images to compose shader and it calculated color of each pixel as it was a 3d point on a cylinder. Aaaaand done! :)

Link to comment
×
×
  • Create New...