[英]GLSL: Move transformation from tessellation-evaluation shader to vertex shader
I am working in glsl with tessellation-shaders and I am trying to do displacement mapping. 我正在使用曲面细分着色器在glsl中工作,我正在尝试进行置换贴图。 It's working, but I want to move the matrix-transformation-code from the tessellation evaluation shader to the vertex shader. 它工作正常,但我想将矩阵变换代码从曲面细分评估着色器移动到顶点着色器。 Why I want to have this in the vertex-shader is because I do not want to do this calculation for every sub triangles vertices, and I want the vertices to be in screenspace in the vertex shader so I can decide how much every triangle should be subdivided in the tessellation control shader. 为什么我想在顶点着色器中使用它是因为我不想对每个子三角形顶点进行此计算,并且我希望顶点在顶点着色器中位于屏幕空间中,因此我可以决定每个三角形应该是多少细分为曲面细分控制着色器。
The version that do not work, is "almost" working, there is some issues when the triangles are rendered. 不起作用的版本“几乎”正常工作,渲染三角形时会出现一些问题。
I would really appreciate even the smallest hint of what may be wrong. 即使是可能出错的最小暗示,我也会非常感激。
// vertex shader
void main_(void)
{
gl_Position = VertexPosition;
VertexTexCoord1 = VertexTexCoord;
VertexNormal1 = VertexNormal;
}
// tessellation evaluation shader
void main_()
{
VertexTexCoord3 = interpolate(VertexTexCoord2);
vec3 normal = interpolate(VertexNormal2);
vec4 pos = interpolate(gl_in[0].gl_Position, gl_in[1].gl_Position, gl_in[2].gl_Position);
vec4 movement = vec4(normal * (texture2D(heigthMap,VertexTexCoord3).r), 0.0);
gl_Position = mvpMatrix * (pos + movement);
}
// vertex shader
void main(void)
{
gl_Position = mvpMatrix * VertexPosition;
VertexTexCoord1 = VertexTexCoord;
VertexNormal1 = mat3(mvpMatrix) * VertexNormal;
}
// tessellation evaluation shader
void main()
{
VertexTexCoord3 = interpolate(VertexTexCoord2);
vec3 normal = interpolate(VertexNormal2);
vec4 pos = interpolate(gl_in[0].gl_Position, gl_in[1].gl_Position, gl_in[2].gl_Position);
vec4 movement = vec4(normal * (texture2D(heigthMap,VertexTexCoord3).r), 0.0);
gl_Position = (pos + movement);
}
In the "non-working" version the last line in tesselation shader seems to be incorrect. 在“非工作”版本中,tesselation着色器中的最后一行似乎不正确。 You're forgetting that in the source variant you had 'movement' multiplied by the mvpMatrix. 您忘记了在源变体中,您的'移动'乘以mvpMatrix。
I would have tried to use this: 我会试着用这个:
// tessellation evaluation shader
void main()
{
VertexTexCoord3 = interpolate(VertexTexCoord2);
vec3 normal = interpolate(VertexNormal2);
vec4 pos = interpolate(gl_in[0].gl_Position, gl_in[1].gl_Position, gl_in[2].gl_Position);
vec4 movement = vec4(normal * (texture2D(heigthMap,VertexTexCoord3).r), 0.0);
/// This multiplication by mvpMatrix is inevitable
gl_Position = (pos + mvpMatrix * movement);
}
Sorry if I mixed the order of the stages, but the code above (two versions) is definitely non-equivalent. 对不起,如果我混合了阶段的顺序,但上面的代码(两个版本)绝对不相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.