# Using cube mapping to render planets

First question on this forum... I need to take a generated cube map then use it as a base texture onto a sphere in a material. It must have been done a gazillion times in blender but I just can't find the information of how to do it.

I want to use a cube map this way to texture a planet and get rid of the worst distortions around the poles as compared to using a single texture.

So what I want to do is:

1. Load a cube map texture
2. Use xyz coordinates as a texture lookup in this cube map to get the base color.

Anyone knows how to do it?

EDIT: I realized I was a bit unclear above.

Cube mapping is an established tech in computer graphics but requires the "engine" to support it.

https://en.wikipedia.org/wiki/Cube_mapping

If I only project a cube on the sphere I will have blending artifacts between the 12 seams of the textures which will especially bee noticeable when rotating the object.

Cube Mapping removes these artifacts by assuming the 6 faces are the same texture and kind of samples across the different faces to do i.e. trilinear mipmapping or whatever algorithm one have selected for zooming in.

The downside to this is that you need to use 3d-coordinates (u,v,w) instead of 2d (u,v). The sign and to the absolute value largest axis decides which face you will pick a sample from and the other two coordinates will denote the uv locally on that face. This has been in hardware for very many years (at least since the beginning of 2000 or so).

I can't find any places where you can upload a "real" cube map texture and use it in a material in blender.

Is this possible?

• A possibility can be transforming a cube to a sphere. No equation needed. – lemon Nov 9 '20 at 17:51
• Have you tried (cube with subdivision modifer, with sharp UVs, and cast to sphere)? If yes, could you indicate what is wrong with it? If you feel it not spherical enough, cast to sphere twice. – lemon Nov 10 '20 at 10:23
• The link to wikipedia includes a sample function to translate from xyz coordinates into per-face-uv and face coordinates. Isn't it just the case that you need to implement a similar re-mapping in material nodes? Can you provide a sample cube-map to demonstrate what's being worked with? – Rich Sedman Nov 10 '20 at 10:46
• Hello, thanks for the answers! I haven't tried to implement it myself although I assume it should be technically possible but would probably go deep into code which deals with texture sampling. The reason I ask is that it is about 100% covered by hardware these days so I just want to check if someone already have used it / implemented it. Maybe it's possible to only modify a small part of the code to get it to work, I don't know, but it basically has to work with mipmap levels etc as well and is for this reason a bit more complicated to implement than just to insert the code from wiki. – Decaf Sux Nov 10 '20 at 13:26