I've had enough of straight lines.

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
luminarious
Posts: 4
Joined: Thu Sep 24, 2009 5:14 pm
Contact:

I've had enough of straight lines.

Post by luminarious »

I mean, seriously, why isn't more work done to get game engines to support proper 4- or 5-point perspective? I couldn't sleep last night, so I figured out one really artistic approach.

Basically, it's a form of raycasting. Camera location is the zero-point, O(0,0). A ray is cast for each pixel, in pre-calculated directions relative to the focus point in the middle of the screen. Since all screen resolutions are divisible by 2, I divide the resolution into quadrants and calculate the angles like this (horizontal example)

Code: Select all

horizontal_angle_unit = camera_angle/h_resolution
for (i=0; i<=h_resolution/2; i++){
  horizontal_alpha[0] = horizontal_angle_unit
  horizontal_alpha[1..n] = horizontal_angle_unit*(2*i+1)
}
These angles are then cosined to x, y and z coordinates of the other end of the ray.

All the rays are then cast. If a ray intersects a triangle that's facing the camera, the pixel is added to the array of the material that's assigned to that triangle.

At rendering, the material arrays are used as clipping masks for material bitmaps which are statically aligned with the viewport. These could be a colour, a pattern, an animation or even a video. Those pixels that did not hit any geometry remain transparent, allowing the background pattern to show.

What is thusly achieved is an interesting shadow puppet play of 3D geometry that has proper perspective in relation to the camera angle used. This system of calculating pixels allows even 360+degree fisheye views. Also, a realistic zoom effect is achieved where geometry changes according to camera angle.

All in all, what do you think? Can this be done? Can this be done with ZGameEditor or should this be done from scratch?

P.S. I am not a programmer, game- or otherwise. I'm an architecture student interested in architectural visualization. This is why I'm interested in a more realistic perspective. I also realize that real lighting with such a system is raytracing and thus too power intensive to consider at this point. Thus the shadow approach.
User avatar
Kjell
Posts: 1924
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Hardi ~

Agreed! These kinds of things should get integrated at the very core of API's .. but I can also understand why it hasn't happened yet.

Anyway, you can already do this in OpenGL :) Basically you first render your scene to a cubemap, and then sample the texture using the algorithm you described. This doesn't provide a completely constant pixel per fragment ratio ( unlike a raytracer ) .. but it's hardly noticeable when you use a texture that's somewhat bigger then your final resolution.

Unfortunately ZGE doesn't support cubemaps yet, but you can work around this with a little bit of effort. Attached is a screenshot of a quick 4-point 360° panorama setup ( no top / bottom, so there is some loss of data in the "corners" + couldn't get the horizontal distortion quite right yet ). Runs great though ( a solid 60fps ) :wink:

K
Attachments
360.jpg
360.jpg (64.22 KiB) Viewed 6623 times
luminarious
Posts: 4
Joined: Thu Sep 24, 2009 5:14 pm
Contact:

Post by luminarious »

Hey, this is looking quite interesting! What a crazy sky.. :) What resolution is it running at?

So real perspective waits for cubemaps. Got it. But what about the other part? About using clipmasked materials? I don't think there's any way of telling from the rendered cubemap what part of the geometry the pixel is from, so it would still need to be a raycasted.

I thought about it yesterday, and a really nice effect would be to render the cubemap as a shadow map and use this with the clipmasked material. This way the rendering of the cubemap would be faster as well, without textures.
User avatar
Kjell
Posts: 1924
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hello,

The screenshot was taken from a 1024x384 window ( but any other resolution would work as well ) and scaled down in photoshop to not destroy the forum :wink:

You can actually "project" any texture on the results with ease. As you mentioned, in that case you render the scene without any textures or lighting, and on top of any lens effects you simply replace the pixels of a specific color with the texture of your choice. Anything is possible.

And the sky texture is made with the BitmapCell Component. When trying out techniques like this I just use whatever gets me there quickest :)

K
Post Reply