Do UV maps affect how cube maps are drawn?

Blitz3D Forums/Blitz3D Programming/Do UV maps affect how cube maps are drawn?

gburgess(Posted 2011) [#1]
I'm getting really confused here, and I can't figure out the solution. I'm rendering a single cube map texture so I can reflect the environment onto a model.

I'm then taking this texture, and applying it as the last texture layer on all objects in my game (there aren't many)

The texture is correctly showing up on the objects, but is badly stretched and distorted over the skin of the model, like it's trying to adhere to a UV map.

Most (not all) of these objects have UV maps, but even the ones without don't seem to be displaying the texture quite right.

Am I taking the right approach here? Can I used one single cube map for all my objects like this?


Kryzon(Posted 2011) [#2]
Cube-maps don't use UV information in any instance. They use 3D vectors to sample a "surrounding cube" around the mesh (the cube-map).
This 3D vector can be the normal of each triangle in your mesh (the diffuse mode of SetCubeMode), it can also be a reflection vector (a vector going from the camera to a vertex, reflected against the triangle this vertex belongs to; this would be the specular SetCubeMode).

So the UV information you have shouldn't pose any difference. What you can do, though, is try changing the SetCubeMode value to see if there's any different mode that suits you; you can also try repairing your meshes' normals with your modelling software, using UpdateNormals() or even using an equivalent in the code archives.

In case the above doesn't work, please post a screenshot.
Cya.

Last edited 2011


gburgess(Posted 2011) [#3]
Thanks, that cube map explanation was brilliant.

I tried all the stuff you said, but unfortunately none of it helped. UpdateNormals() and the code archive snippet actually caused their own oddities: polygons that seemed to be anchored partially to 0,0 on the screen, connected to each model. I assume there's some invalid part of the meshes that UpdateNormals is stumbling on a bit, maybe some two-point polys. Still, I knew that what you said must be right - either my models' normals weren't right, or I was screwing up the cube map itself.

I eventually found that the problem seemed to lie in smoothed normals. If they were smoothed over quite sharp angles, the texture would distort into a banded portion of itself, stretched hard over the polygons. Using Ultimate Unwrap's autosmoothing option, I was able to alleviate this quite substantially. It's added another step to the pipeline, but hey, it works.

Thanks for setting me on the right track!


gburgess(Posted 2011) [#4]
Actually, I think I spoke too soon:

The banding effect is still happening no matter what I do to the models.

Here's an example. The underside of this model suffers quite badly, where as the top side has relatively little banding.




The cube map is intended to be a very low resolution (cheap blurring!) reflection of the background. The top image shows the texture being stretched into bands around certain vertices. The bottom image only shows this on a single polygon at the upper-right edge of the spacecraft as we look at it.

What do you think, are my normals just screwed, or is this an artifact of Blitz3D's/DirectX7's cubemapping?


Kryzon(Posted 2011) [#5]
If your model doesn't have any anormalities when looked at with a smooth shading then you can be sure your normals are correct.

Is your cubemap texture arranged properly? remember it must fit all 6 sides horizontally, and these sides are specifically ordered.
All of the 6 sides must have the same size, be square and power-of-two.
The width of the final texture holding them all will never be power-of-two, but that's correct.

You can also make a cube-map texture for debugging purposes with something like a checkered pattern just so you see if it's working correctly.

Last edited 2011


gburgess(Posted 2011) [#6]
Cube map's good. I made it cycle through each face with SetCubeFace, CopyRect'd it into an image, and saved. I get six different, correct images, all 16x16 (which is the right size).


Kryzon(Posted 2011) [#7]
Well, you can always use that checkered cubemap texture to see if it's behaving the right way.

As a last resort, remember you have the Spherical Environment texture (flag 64 when creating or loading one).
You can render what's behind the camera and CopyRect it onto that environment texture so it keeps varying as the camera moves, and acts like a simple reflection.
Satisfaction guaranteed :)

Last edited 2011


BIG BUG(Posted 2011) [#8]
I'm pretty sure this is due to faulty normals.
Just try to split all polygons from each other, so every polygon has its own vertices(normals are stored per vertex) and then use sswift's or mine(Click!) function to recalculate normals with hard edges.
Only if it still doesn't work, you could rule out wrong normals as cause.


gburgess(Posted 2011) [#9]
Kryzon - an interesting idea, although it would need an additional render each frame. Still, if it works, it works.

BIG BUG - I've pretty much done that by unwelding the model in Ultimate Unwrap, and then re-exporting. I've also used it's autosmoothing feature which seems to do the same as your nice function. So unless UU is outputting bad UVs itself...