本文介绍了带有gl_ModelViewProjectionMatrix的GLSL 4.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个glsl着色器程序,作为在封闭源"应用程序中运行的插件的一部分.该应用程序(maya)使用opengl 2.1编写,但是我们的图形卡支持opengl/glsl 4.1,我想在程序中使用镶嵌和几何着色器.该应用程序设置了opengl视口和传统的模型/视图矩阵堆栈,但是我无法控制那部分代码.

I am working on a glsl shader program as part of a plugin that runs inside a "closed source" application. The application (maya) is written using opengl 2.1, but our graphics cards support opengl/glsl 4.1 and I want to use tessellation and geometry shaders in my program. The application sets up the opengl viewport and the traditional model/view matrix stack and I do not have control over that part of the code.

我的直通顶点着色器使用GLSL 1.2并运行良好:

My pass-through vertex shader uses GLSL 1.2 and works fine:

// GLSL VERTEX SHADER
#version 120

void main ()
{
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

我的直通式Geomery着色器使用glsl 4.1,并且在应用程序中也可以正常运行:

My pass-through geomery shader uses glsl 4.1 and also works fine inside the application:

// GLSL GEOMETRY SHADER
#version 410

layout (lines_adjacency) in;
layout (line_strip, max_vertices = 2) out;

void main ()
{
    gl_Position = gl_in[1].gl_Position;
    EmitVertex();
    gl_Position = gl_in[2].gl_Position;
    EmitVertex();
    EndPrimitive();
}

但这只是通过测试.在我真正的几何着色器中,我需要在世界空间中进行一些计算,但是几何着色器点在视图空间中. 我的问题是:我可以在4.1几何着色器中访问gl_ModelViewProjectionMatrix吗?我知道在glsl 4.1中不赞成使用传统的矩阵堆栈,而是使用统一变量,但是我不能更改应用程序.我无法在几何着色器中使用glsl 1.2,因为我需要lines_adjacency输入类型.我是否需要将矩阵复制到插件的C ++源代码中的统一变量中?还是有直接从glsl 4.1来解决的后门"?还是我没有想到的其他东西?

But this is just a pass-through test. In my real geometry shader I need to do some calculations in world-space but the geometry shader points are in view-space. My question is: can I access the gl_ModelViewProjectionMatrix inside a 4.1 geometry shader? I understand that the traditional matrix stack has been deprecated in glsl 4.1 in favor of uniform variables, but I cannot change the application. I cannot use glsl 1.2 in my geometry shader because I need the lines_adjacency input type. Do I need to copy the matrix into a uniform variable in my plugin's C++ source? Or is there a "back door" to get at it directly from glsl 4.1? Or something else I'm not thinking of?

推荐答案

您可以使用兼容模式(如果您的GL实现支持):

You can use compatibility mode (if your GL implementation supports it) by saying:

#version 410 compatibility

着色器中的

.这将重新启用所有已弃用的全局状态(除其他外)

in the shader. This will reenable all the deprecated global uniform state (among other things)

这篇关于带有gl_ModelViewProjectionMatrix的GLSL 4.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 02:11