【问题标题】:OpenGL cubemap reflections flipping with moving cameraOpenGL立方体贴图反射随移动相机翻转
【发布时间】:2014-07-13 11:40:54
【问题描述】:

我正在测试一个基本的立方体贴图实现,除了最后一个细节外它工作正常。 当我移动相机时,立方体贴图会在上/下轴上翻转。

当我移动相机时,请注意发生翻转时的视图矩阵:

------
 0.01,  0.13, -0.99,  0.00
 0.00,  0.99,  0.13,  0.00
 1.00, -0.00,  0.01,  0.00
-1.86, -0.28, -6.34,  1.00
------ 

给出以下图片:

------   
-0.01,  0.13, -0.99,  0.00
 0.00,  0.99,  0.13,  0.00
 1.00,  0.00, -0.01,  0.00
-1.95, -0.28, -6.31,  1.00
------

给出以下图片:

请注意第 1 列和第 3 列中 0.01 的符号变化。这告诉我什么?

对于 GLSL 中的正常计算,我执行以下操作:

顶点着色器:

mat4 model_view = view * m;
position_eye = vec3(model_view * vec4(vertex_position, 1.0));
mat3 normal_matrix = mat3(transpose(inverse(model_view)));
normal_eye = normalize(normal_matrix * vertex_normal);

片段着色器:

 vec3 func_cubemap_reflect()
 {
   vec3 incident_eye = normalize(position_eye);
   vec3 normal = normalize(normal_eye);
   vec3 reflected = reflect(incident_eye, normal);

   // convert from eye to world space
   reflected = vec3(inverse(view) * vec4(reflected, 0.0));
   return texture (cube_texture, reflected).rgb;
  }

知道如何调试或解决它,以便反射始终是“正确的方式”吗?

【问题讨论】:

    标签: opengl glsl texture-mapping


    【解决方案1】:

    我猜你在计算中的某个地方失去了精度,可能是矩阵求逆。

    一些选项:

    • 尝试在着色器中设置highp?
    • 如果您的 GLSL 版本支持它,您可以尝试将 view/model_view 矩阵定义为 dmat4(也可以提高精度)。

    【讨论】:

    • 我试过 highp 没有成功。但是,我正在测试一种我做reflected = vec3(inverse(view + mat4(1.0) * 0.01) * vec4(reflected, 0.0)); 的方法。那就是我在反演中添加一个阻尼因子来稳定它。结果现在看起来如预期。不知道这个黑客有多糟糕?有什么想法吗?
    猜你喜欢
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-15
    • 1970-01-01
    相关资源
    最近更新 更多