GLSL Shader 将六种纹理转换为等距柱状投影

Cru*_*xel 0 opengl shader glsl

我想从六个二次纹理创建一个等距柱状投影,类似于将立方投影图像转换为等距柱状投影图像,但使用单独的面作为纹理,而不是立方投影中的一个纹理。

出于性能原因,我想在显卡上执行此操作,因此想要使用 GLSL 着色器。

我找到了一个将立方体纹理转换为等距矩形纹理的着色器:链接

Die*_*Epp 5

第 1 步:将六个纹理复制到立方体贴图纹理中。您可以通过将纹理绑定到 FBO 并使用glBlitFramebuffer().

步骤 2:运行以下片段着色器。您需要将Coord四边形的属性从 (-1,-1) 更改为 (+1,+1)。

#version 330
// X from -1..+1, Y from -1..+1
in vec2 Coord;
out vec4 Color;
uniform samplercube Texture;

void main() {
    // Convert to (lat, lon) angle
    vec2 a = Coord * vec2(3.14159265, 1.57079633);
    // Convert to cartesian coordinates
    vec2 c = cos(a), s = sin(a);
    Color = sampler(Texture, vec3(vec2(s.x, c.x) * c.y, s.y));
}
Run Code Online (Sandbox Code Playgroud)