GLSL Shader将六种纹理转换为等角投影 [英] GLSL Shader to convert six textures to Equirectangular projection

查看:109
本文介绍了GLSL Shader将六种纹理转换为等角投影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从六个二次纹理中创建一个 equirectangular投影,类似于转换三次投影图像转换成等角矩形图像,但将单独的面作为纹理,而不是三次投影中的一个纹理.

I want to create an equirectangular projection from six quadratic textures, similar to converting a cubic projection image to an equirectangular image, but with the separate faces as textures instead of one texture in cubic projection.

出于性能原因,我希望在图形卡上执行此操作,因此希望使用GLSL着色器.

I'd like to do this on the graphics card for performance reasons, and therefore want to use a GLSL Shader.

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

I've found a Shader that converts a cubic texture to an equirectangular one: link

推荐答案

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

Step 1: Copy your six textures into a cube map texture. You can do this by binding the textures to FBOs and using glBlitFramebuffer().

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

Step 2: Run the following fragment shader. You will need to vary the Coord attribute from (-1,-1) to (+1,+1) over the quad.

#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));
}

这篇关于GLSL Shader将六种纹理转换为等角投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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