使用立方体贴图(不是反射贴图)对球体进行纹理化 [英] Texturing Spheres with Cubemaps (not reflection maps)

查看:74
本文介绍了使用立方体贴图(不是反射贴图)对球体进行纹理化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用立方体贴图对球体进行纹理化.到目前为止,我的研究已经在 Google 上提出了许多涉及使 OpenGL 自动生成纹理坐标的结果,但我想生成自己的坐标.

I want to texture a sphere with a cube map. So far my research has thrown up many many results on Google involving making OpenGL auto generate texture coordinates, but I want to generate my own coordinates.

给定一个坐标数组,其中包含以 0,0,0 为中心的不完美球体(高度映射但本质上是一个球体)的顶点,如何为立方体贴图生成纹理坐标?

Given an array of coordinates comprising the vertexes of an imperfect sphere (height mapped but essentially a sphere) centered on 0,0,0, how would one generate texture coordinates for a cube map?

推荐答案

您是通过 GLSL 进行的吗?在这种情况下,textureCube 接受一个 vec3 作为纹理坐标,它是球体上的单位向量.在您的情况下,您将获取片段相对于球体中心的坐标,对其进行标准化并将其作为坐标传递.无需担心内部表示为六个二维纹理.

Are you doing this via GLSL? In that case textureCube accepts a vec3 as texture coordinate, which is a unit vector on a sphere. In your case you would take the coordinate of your fragment with respect to the center of the sphere, normalize it and pass it as a coordinate. No need to worry about the internal representation as six two-dimensional textures.

uniform samplerCube cubemap;
varying vec3 pos; // position of the fragment w.r.t. the center of the sphere
/* ... */
vec4 color = textureCube(cubemap, normalize(pos).stp);

它在固定管道 OpenGL 中也是如此.

It works like that also in fixed-pipeline OpenGL.

顺便说一下,坐标在内部是如何使用的:绝对值中最大的坐标用于选择从六个纹理中的哪一个读取(符号选择正或负).其他两个坐标用于在选定地图中查找纹理像素,除以最大坐标后.

By the way, here is how the coordinates are used internally: the largest coordinate in absolute value is used to select which one of the six textures is read from (the sign selects positive or negative). The other two coordinates are used to lookup the texel in the selected map, after being divided by the largest coordinate.

这篇关于使用立方体贴图(不是反射贴图)对球体进行纹理化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆