Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Spherical Camera

Author
Message
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 13th Nov 2008 23:09
This is something i knocked up today. I used a lot of guesswork, but it seems to work OK!

A spherical camera preserves angles, avoiding the wierd stretching you get with large fovs approaching 180 degrees with a standard perspective camera. As a result, spherical cameras don't always show straight lines as straight lines. It's kind of a security camera type effect.


The program takes an image using a standard camera. (top left) I have used quite a large FOV so the effect is obvious. The program then textures a matrix with this image. The matrix is shaped as a hyperbola, and a view of this matrix is shown on the screen. (right) A wireframe of the matrix as seen on the screen is shown (bottom left)

Here is the code. You will need the texture, which i will attach. Otherwise you can comment out the "texture object" line, but it won't look as cool!


This could probably be a lot faster if a object were used instead of the matrix, avoiding the prepare matrix texture and update matrix commands, which i believe are quite slow.

I hope someone finds this interesting.

You may also remember i once made a cylindrical camera. That used many cameras. Using a similar method to this a cylindrical camera could be made with far fewer cameras, which would presumably be a lot faster! Also, using extra cameras and matrices with the spherical camera would enable breaking the 180 deg fov barrier.

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 13th Nov 2008 23:13 Edited at: 13th Nov 2008 23:16
And of course i forgot to attatch the image!

edit: and i forgot again. I suck.

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 13th Nov 2008 23:14 Edited at: 13th Nov 2008 23:18
Image is attached:

Attachments

Login to view attachments
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 14th Nov 2008 12:37
Pretty cool

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 14th Nov 2008 22:54
Thanks dude. I had another play with this today. Have swapped matrix for object. Same function, but works faster. I'll post the code up in a sec. Here's another pic.



Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 15th Nov 2008 02:17 Edited at: 15th Nov 2008 02:19
Here's the code. Sorry if a tad messy, but i have things to be doing.



The screenshot in the post just above uses an aspect ratio 2 camera rendering to a 2048 by 1024 image. The code is for a circular view, ie a aspect ratio 1 camera rendering to a square image, with the circle cut out using camera range. If anybody wants to know the settings for the above cam or anything just say and i can sort it.

I'll probably leave this for the moment. Thinking about using more than one camera to generate a larger fov spherical camera is really baking my head! Might just make a cylindrical cam next.

draknir_
17
Years of Service
User Offline
Joined: 19th Oct 2006
Location: Netherlands
Posted: 15th Nov 2008 13:13 Edited at: 15th Nov 2008 13:18
This is really really awesome Mr. Tank! I love it. Fantastic work. I can think of a million applications for this camera! I'm even inspired to write a game for it, I just need to find the time.

One question: Why is it that in your screenshots everything looks nice and anti aliased, but in mine, its all jagged? Heres a pic:

Attachments

Login to view attachments
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 15th Nov 2008 13:39
Thanks dude. It'd be great to see a game using this.

As for the jaggies, i believe it has to do with display resolution. I notice your screenshot is 1280x1024. I am using a display resolution of 1024x768x32. If you set your monitor to this res you presumably should get the same result as me.

As for getting no jaggies at the resolution you are using: two suggestions:

At the start of the prog i set the display mode to 1024x768x32. I think if you set this to not your display resolution anyway it can produce wierdness. So i'd set it to the res you're using. If you don't set it at all i think it defaults to 800x600 or something.

After doing this, you may need to increase the resolution of the camera taking the image that is stretched over the matrix. ie change

set camera to image 1,1,1024,1024

to

set camera to image 1,1,2048,2048

I found that such a high resolution produced a very low framerate on my computer however.

Good luck!

draknir_
17
Years of Service
User Offline
Joined: 19th Oct 2006
Location: Netherlands
Posted: 15th Nov 2008 16:44
Hmmm. My displays native resolution is 1280x1024, thats why I changed it to that. I was getting the jagged edges on 1024x768 (the default in your example). Ill try the camera resolution thing.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 16th Nov 2008 01:03
If you can see the posted screenies clearly and cleanly on the internet from this board, I would guess it's not your monitor. You might check your direct x output for your video card. It may be set to performance versus quality... anything rendered may not be as nice and smooth as Mr. Tanks if the video card bells and whistles aren't engaged.

Enjoy your day.
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 16th Nov 2008 01:10
@MrTank,

I must say very nice!!! I wasn't feeling the first post, but seeing the revamped second pics got my attention. Nice work!!!

"When I look at that square... I wish FPSC noobs would stay on their side of the forums and stop polluting these boards." - Benjamin
draknir_
17
Years of Service
User Offline
Joined: 19th Oct 2006
Location: Netherlands
Posted: 16th Nov 2008 03:27
Even with a ridiculously high image size (4096x4096) and when I set my nvidia control panel to force quality over performance, I get jaggies with this code.. I'm starting to think it may be a problem with Vista/my hardware. I'll try it out on an XP machine monday.
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 16th Nov 2008 14:34
Thanks zenassem. Glad you like it.

draknir_
I tried running it on my machine with your settings - 1280x1024 resolution of desktop and of the program. It seems to work fine for me so i agree your problem might be to do with your computer.

It seems that from your screenshot, your mipmapping might not be working- the background wall looks especially jaggy.

Perhaps it could also be your version of DBP that is different to mine (i'm still on 1.066), but seeing as others have said it's OK i guess it's not this.

You can save a pic of the standard camera to the folder the .exe is in by pressing the control key. If this is all jaggy then something this rules out the special camera as the problem.

draknir_
17
Years of Service
User Offline
Joined: 19th Oct 2006
Location: Netherlands
Posted: 16th Nov 2008 14:58
You're probably right about the mip mapping.

I'm using 1.069 at the moment. I haven't updated to the latest version because I'm in the middle of a big project and I don't want to break anything. Once it's done I'll try again with the latest version.

Still, great work on this.
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 21st Nov 2008 02:28
Good luck sorting out your comp mate. I'm on an older version of DBP than you BTW. Same boat- don't want to recode all my projects! I'll get one done first.

I've been working on this some more. Here is a cylindrical camera. It basically achieves the same effect as an old code snippet i made, except it requires a few cameras instead of around 20!





I haven't really experimented with number of cameras, texture resolution etc. Just educated guesses. I think fewer cameras is better, but use too few and the wavy effect at the top and bottom becomes greater, and you need to cut off more stuff so you can't see the waviness.

This is pretty cool for a game where you're mostly looking horizontally, and the camera is the right way up. If you look up or down or roll the camera it can get kind of disorientating. You can go to as many degrees fov as you want to the left/right. Up/down is limited to approaching 180, like with the standard camera.

I'm still working on a spherical camera using views of more than one perspective camera joined together. This allows approaching 360deg fov in all directions, and avoids some of the wierdness with the cylindrical cam. However, it's proving quite difficult, and i might just leave it for the mo and come back to it later.

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 25th Nov 2008 01:45
Still pottering away on this. Have realised there is a bug of sorts in above code (spherical cam) The cam viewing the matrix/hyperbola object should be positioned differently. Currently it's not angle and circle preserving like i thought- maybe for first order. Anyway i've fixed it and it works, and seems a little less disorientating. Here's some working code. Bit messy but anyway. Holding the "shift" key shows how the old version looked.



I came to find this whilst thinking about the multicam spherical camera. I have solved for 1 axis. Hopefully can get it running soon. Then i'll hopefully produce a tidier, more understandable/usable version with variables etc so people can hopefully use this in their games.

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 28th Nov 2008 02:40 Edited at: 28th Nov 2008 02:52
OK i've got multiple cams working for the angle/circle preserving "spherical" cam. Here's an example where I have used three perspective cameras to achieve a greater than 180 degree field of view:



Here is the code:


It still has some shortcomings. For large FOVs, the scale of the texture from the perspective camera images when mapped onto the screen changes greatly, and so a high resolution original image is required, which can lead to low framerates. Adding cameras reduces the field of view you need with each, and therefore the image sizes required, but then obviously you need to render more images.

The shapes i am rendering onto are like matrices - grids when viewed from above. I had originally thought that these shapes might happen to achieve perspective texture mapping- so the square part of texture mapped onto a square of the matrix was undistorted. I believe this is not actually so. With a not seamless mesh this would be easy, but might lead to "stitching" artifacts. I may work on this yet.

The multicam thing requires quite a bit of tinkering to choose the best fovs for each camera, and that's for each aspect ratio you'd want to run the game in etc.

Anyway i still think it's cool. Probably will concentrate on the single cam version now and just see if i can minimise distortions. It won't be able to exceed 180 deg, but it's still a cool thing for large fovs.

draknir_
17
Years of Service
User Offline
Joined: 19th Oct 2006
Location: Netherlands
Posted: 28th Nov 2008 17:16
Looks awesome, both the cylindrical and high fov cams, but it makes me wonder if it wouldn't be much more efficient to do this directly with a dll... or even better, Lee should implement it XD
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 6th Dec 2008 16:57
Looks great. If you think about it you could do this with any weird;y-shaped objects as well. You could get some cool photobooth effects if you modelled objects that pinch in the centre or stretch in the upper corner. Actually, come to think of it you could get this effect with a plain object, and just alter the UV coordinates to give the effect. Might be worth looking into, speedwise.

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 7th Dec 2008 23:20 Edited at: 7th Dec 2008 23:33
Quote: "Looks awesome, both the cylindrical and high fov cams, but it makes me wonder if it wouldn't be much more efficient to do this directly with a dll... or even better, Lee should implement it XD"

Thanks dude. I expect it could be made quite a bit more efficient. You can toy with the uvs like Ruccus says. I don't really know that much about dlls, but i guess if you had some mad skills and a lot of time there are loads of things you can do to make it better. For example, when you render the final display, everything bar the special object is hidden. Thus you can avoid any culling checks etc. In my experience, if objects are hidden you don't get the same speed boost as when objects are excluded, but when you include and exclude every frame, you can get slowdown- presumably to do with object lists or something like that. A command to exclude or include an object in a given camera would be cool, but i digress. A dedicated thing could maybe sort this. It could also sort out the "perspective mapping" thing i expect.
However, like i say below, the rendering of the "scene" seems to be a much bigger job for the computer, so the inefficiency of the other bit isn't too important.
I should continue to tinker and try and document this and if someone else can make it faster or more acessible or whatever then that would be totally sweet.

Quote: "Looks great. If you think about it you could do this with any weird;y-shaped objects as well. You could get some cool photobooth effects if you modelled objects that pinch in the centre or stretch in the upper corner. Actually, come to think of it you could get this effect with a plain object, and just alter the UV coordinates to give the effect. Might be worth looking into, speedwise."

Cheers. Yes you could use other shapes to get cool effects. Even dynamic effects. Could also manipulate the normals and use lights. Lots of possibilities. I think the overhead in changing the shape in real time is not that great, and it is quite feasible. Simpler to do with matrix, or memblock for more speed. I'd like to look into using vertexdata commands which i haven't played with yet.

You are right about using uv coords. I initially used the "matrix" style object for convenience, but now believe this actually results in nicer mapping of texture with less distortion. I should make a diagram to illustrate. There may be a better solution using uvs not on a simple grid though. Also would be cool to have polys more evenly distributed across the screen. Basically though, the gains will not be that significant i think. The slow part seems to be rendering the image(s) to use as the texture(s). Rendering the final image to the screen seems to be relatively quick. I should give this some more thought though.

Jetherit
15
Years of Service
User Offline
Joined: 18th Dec 2008
Location:
Posted: 3rd Jan 2009 07:09
I'm sorry if this was already discussed above, as I only briefly scanned the previous posts, but is this practical for rendering, say, 60 frames per second?

From JASS to Q-BASIC to Java to C++
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 8th Mar 2009 02:22 Edited at: 8th Mar 2009 02:24
Jetherit - Basically you are rendering a camera view twice per frame, so it will slow things down to some extent. On my fairly dated machine, if you look at the last screeny, it's running at 55 fps. That's actually with 4 cameras, although the total pixels rendered is maybe more like twice the resolution of the final image. This is with a simple scene with a few objects and not much else going on. But basically yes it could run at ~60 fps. Probably easily on a newer computer.

Login to post a reply

Server time is: 2024-05-02 01:30:56
Your offset time is: 2024-05-02 01:30:56