PDA

View Full Version : Cubemap to Fisheye



kospanak
05-12-2008, 10:00 AM
Hi. I am writing a program that converts cubemap to fisheye. The problem that i face is that i cann't (or more correct i don't know how to) make the bordering pieces of the cubemap (that are mapped on the sphere) look attached completely and instead i use :

glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP);


but then the bordering sides are like dark lines which is not nice as an effect. Can anyone help how can i make it look solid and not broken?

PS: Any help is good!!!

Relic
05-12-2008, 01:10 PM
The dark lines come from filtering in the texture border color which defaults to black.
You need to do
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
to keep texture filtering from accessing the texture border color and you don't need to setup the WRAP_R component because the cubemap's final texture lookup is actually only 2D.

kospanak
05-14-2008, 07:24 AM
I tried it. The results are indeed better, but still the bordering sides of the 6 cubic sides are coloured . Is there any way to make it disappear?

Relic
05-14-2008, 07:39 AM
Sorry, that should have completely solved the issue of accessing the texture border color.
If you still see problems they are something different and you need to provide more precise descriptions or better an image of what the remaining problem is. => Input and output images, rendering calls, etc. (OS, hardware, driver versions, in case it's a bug.)

kospanak
05-14-2008, 09:46 AM
Summary of my system:

Computer Type: ACPI Uniprocessor PC
Operating System: Microsoft Windows XP
OS Service Pack: Service Pack 2
DirectX: 4.09.00.0904 (DirectX 9.0c)
CPU Type: AMD Athlon 64, 2000 MHz (10 x 200) 3200+
Motherboard Name: MSI K8T Neo2-F v2.0 (MS-7094)
Video Adapter: NVIDIA GeForce 6600 GT (128 MB)
3D Accelerator: nVIDIA GeForce 6600 GT AGP
System Memory: 1024 MB (PC3200 DDR SDRAM)

Could you send me your email? So that i can send you the images?

Relic
05-14-2008, 11:05 AM
The way people present images here is to put them onto some web page (your own or a free image server) and post the link.
The full reply form has a button for "Enter an image" which opens a http address dialog.
If it is 80*80 pixels or smaller you could upload it as user icon. ;)

kospanak
05-14-2008, 11:38 AM
cubemap: http://www.2and2.net/files/482b1e3f4b4b6.jpg
fisheye: http://www.2and2.net/files/482b1e9be1afb.jpg

PS: I magnified the fisheye, so that you can see the lines. Although a bit difficult, to see perhaps they still exit.

kospanak
05-14-2008, 11:38 AM
I meant, they still exist

Relic
05-15-2008, 03:18 AM
The cubemap cross image has those lines as well!?
How did you render that one?
Or is that the input image? Then it's broken from the start.
Check your upload routine.
Watch your PixelStore alignments.
Use another cubemap.

More debugging:
Do you use mipmaps?
How did you generate them?
Do you get more corruption the smaller you render your fisheye?

If you explicitly set your texture border color with glTexParameter to a fancy color like magenta or green for your image, does the resulting rendering show any of that?
It shouldn't and the default border color is black, your lines are white so I really would blame the upload.

You could do a glGetTexImage and look at the data OpenGL has.

Use a tiny handmade cubemap texture, like six 1x1 images with the base colors red, green, blue for the positive and the inverse colors cyan, magenta, yellow for the negative faces.
There shouldn't be any white or black artifacts between the faces.

kospanak
05-15-2008, 10:12 AM
Sorry for being late. Well the cubemap cross is the input image. I tried other cubemaps and yet the results are pretty much the same. What i can not understand is what the difference between glGetTexImage and glReadPixels is

Relic
05-15-2008, 02:01 PM
With glGetTexImage you can read out the texture directly and look if what you think you uploaded matches exactly what OpenGL has in its texture to verify that there isn't a problem in your loader.
If other cubemaps have the same problem that still doesn't mean your loader is right.
If you actually grabbed the six cubemap faces from that cross image, it looks like you simply picked up white pixels from around the textures as well. That should be totally simple to verify and debug.

I asked the right questions. You just need to go through them one by one.

I know that cubemap from other demos and that exists as six individual faces and works.
BTW, for lots of other working cubemaps, just go to http://wadfather.planethalflife.gamespy.com/new/

What about downloading a simple cubemap reflection example which works to compare that with what you did?
You're using a GeForce and this is the first hit when searching for "simple cubemap" on NVIDIA's developer site:
http://developer.nvidia.com/object/cube_map_ogl_tutorial.html
(Boy, that's from 1999! :D Means your stuff simply needs to work and is not really an advanced topic.)
That should answer almost all about cubemaps you ever wanted to know. Sources at the bottom.

kospanak
05-18-2008, 10:20 AM
i use the theory that is in the site of nvidia that you gave me. Though it works perfectly when it comes to the use of 6 seperate pictures, there is still the problem when it comes to the use of a single image. Although i had (manually at least for each image) solved the problem of the unwanted white pixels, the bordering lines remain.

see this: http://www.2and2.net/my.php?image=http://www.2and2.net/files/48305220c46a0.jpg

Soth
05-18-2008, 10:42 AM
Try using different texture address modes, i`ve had a similar problem and it was solved with GL_CLAMP_TO_EDGE

kospanak
05-18-2008, 11:27 AM
i did try that. The bordering lines are (sort of) more homogenous in colour (compared at least with the colour of the rest), bust still the lines are a bit different.

Relic
05-19-2008, 02:59 AM
Though it works perfectly when it comes to the use of 6 seperate pictures,

Means your rendering and texture parameter setup is ok.


there is still the problem when it comes to the use of a single image.

Still means, either the input image is wrong from the start and has those white lines already (=> Use a correct input image then!),
or your loader which separates the horizontal or vertical cross image to individual cubemap texture faces is defective (=> Fix it!)
You never explained or showed any code how you handled the input image.
It is trivial to take a horizontal or vertical cross image with a cubemap and separate the individial faces for the upload as the six level of detail 0 cubemap textures if the input data is correct

kospanak
05-19-2008, 07:08 AM
here is the code that i use in order to load the cubemap (in order to take the 6 faces):

void fisheye_projection_2(){
int i=0;



w=(int)image->width/4;
h=(int)image->height/3;


glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei (GL_UNPACK_SWAP_BYTES, 0);
glPixelStorei (GL_PACK_ALIGNMENT, 1);
glPixelStorei (GL_PACK_ROW_LENGTH, image->width/4 );

for(i=0;i<6;i++){
data2[i]=(unsigned char*)malloc (image->components*image->width/4*image->height/2*sizeof(unsigned char));
}


glReadPixels(w,h,w,h,image->format,GL_UNSIGNED_BYTE,data2[4]);

glReadPixels(0,h,w,h,image->format,GL_UNSIGNED_BYTE,data2[1]);

glReadPixels(w,0,w,h,image->format,GL_UNSIGNED_BYTE,data2[2]);

glReadPixels(w,2*h,w,h,image->format,GL_UNSIGNED_BYTE,data2[3]);

glReadPixels(2*w,h,w,h,image->format,GL_UNSIGNED_BYTE,data2[0]);

glReadPixels(3*w,h,w,h,image->format,GL_UNSIGNED_BYTE,data2[5]);
}

of course there is still the problem that every time i use a different input cubemap picture i may pick up pixels outside the 6 cube faces.

Relic
05-19-2008, 07:57 AM
Just look at the cubemap you presented as input image.
If that is the original, the faces are neither correctly aligned nor power-of-two.
And your code above allocates 1/3 too much data per face, but that shouldn't matter after you read in crap data.
Garbage in, garbage out. Fix your input image(s).

kospanak
05-19-2008, 08:48 AM
i checked the image and the dimensions are 800x600 (therefore not power of 2). In this case, what should be done?

Changing the parameters in glReadPixels or even something else?

Relic
05-19-2008, 10:58 AM
Your input image is a horizontal cross cubemap, so a 800x600 input image means six 200x200 cubemap faces.
The non-power-of-two issue is just a problem on hardware which doesn't support NPOT textures. Since your rendering works, and GeForce 6 supports NPOT that is not an issue on your system.

Again, I looked at your input image in a paint program and used a crop tool on the center image to see how big it is and noticed that for example the bottom image is too far to the right compared to the top image, and the left is also not matching the right in vertical placement. Means your input image is garbage. Period.
No wonder that you captured white borders if that is your original data.
I don't know where you got that image from or why you use a horizontal cross layout at all. From demos I know that same cubemap comes as six 256x256 images. You said yourself that individual images worked perfectly so either use that or a correct input image to match your (correct) glReadPixels coordinates.

kospanak
05-19-2008, 01:13 PM
Which crop tool did you use to find all that information? It seems pretty useful.

ZbuffeR
05-19-2008, 02:13 PM
The Gimp has now a very good "crop" tool.

Relic
05-20-2008, 02:28 AM
Hmm, I somehow get the weird feeling this thread is a Turing test. I explain something, you pick the wrong thing to ask back!
=> You're a machine. :D
The correct question would have been "Which paint program did you use?"
Paint Shop Pro 7, but that doesn't matter. You can see that your input image is wrong even by overlapping it with another window aligned to the edges of some of the cubemap faces and see that they are misaligned.
This gets less and less "OpenGL coding advanced", please stop it.

kospanak
05-20-2008, 02:31 AM
ok

kospanak
05-24-2008, 08:24 AM
I tried to convert cubemap to fisheye by using 6 seperate pictures that form the original fisheye. The probrlem remains

Relic
05-25-2008, 03:30 PM
You do something else you didn't say or you do something wrong. There are not enough informations to tell.
This simply should work if the cubemap data is matching at the borders, your upload routine is right, and you set the texture parameter wrap modes to clamp_to_edge.
If you're still working on that broken input image, the light white lines were in the image before, probably due to incorrect sampling when sizing it down to thie 800x600 image.

Again, DEBUG!!!
Do you see any artefacts when using 6 times 1x1 images of pure white, pure black, or the debug color I proposed before?
Maybe you start with a working program from the samples I pointed you to and exchange the texture data.

It's not like this hasn't been done before.