Alphaomega86

12-22-2013, 11:44 AM

Hallo,

i've tried all to generate an output with my tessellation shader. If i add the tessellation evaluation and tessellation control shader to my shader program,

the model to which i applied the shader is gone.

Here is my vertex, tessellation evaluation and tessellation control shader:

Vertex

#version 410

#import "assets/shaders/libraries/VertexCore.glsl"

//Varying variables out for tessellation control shader

out vec4 v_TexCoordCS;

out vec4 v_PositionCS;

out vec4 v_ColorCS;

out vec3 v_NormalCS;

void main(void) {

v_TexCoordCS = i_TexCoord;

v_NormalCS = normalize(m_ModelNormalMatrix * i_Normal);

v_ColorCS = i_Color;

v_PositionCS = i_Vertex;

}

Tessellation Control

#version 410

layout(vertices = 3) out;

//Varying variables in from vertex shader

in vec4[3] v_TexCoordCS;

in vec4[3] v_PositionCS;

in vec4[3] v_ColorCS;

in vec3[3] v_NormalCS;

//Varying variables out for tessellation evaluation shader

out vec4[3] v_TexCoordES;

out vec4[3] v_PositionES;

out vec4[3] v_ColorES;

out vec3[3] v_NormalES;

void main(void) {

v_TexCoordES[gl_InvocationID] = v_TexCoordCS[gl_InvocationID];

v_PositionES[gl_InvocationID] = v_PositionCS[gl_InvocationID];

v_ColorES[gl_InvocationID] = v_ColorCS[gl_InvocationID];

v_NormalES[gl_InvocationID] = v_NormalCS[gl_InvocationID];

gl_TessLevelInner[0] = 3.0;

gl_TessLevelOuter[0] = 10.0;

gl_TessLevelOuter[1] = 7.0;

gl_TessLevelOuter[2] = 3.0;

}

Tessellation Evaluation

#version 410

layout(triangles, equal_spacing, ccw) in;

//Matrices

uniform mat4 m_ModelMatrix;

uniform mat4 m_ViewMatrix;

uniform mat4 m_ProjectionMatrix;

mat4 m_ModelViewMatrix = m_ViewMatrix * m_ModelMatrix;

mat4 m_ModelViewProjectionMatrix = m_ProjectionMatrix * m_ModelViewMatrix;

mat4 m_ViewProjectionMatrix = m_ProjectionMatrix * m_ViewMatrix;

//Uniforms

uniform sampler2D m_DisplacementTexture;

uniform float m_DisplacementFactor;

//Varying variables in from tessellation control shader

in vec4[3] v_TexCoordES;

in vec4[3] v_PositionES;

in vec4[3] v_ColorES;

in vec3[3] v_NormalES;

//Varying variables out for fragment shader

out vec4 v_TexCoordFS;

out vec4 v_PositionFS;

out vec4 v_ColorFS;

out vec3 v_NormalFS;

vec2 interpolate(vec2 v0, vec2 v1, vec2 v2) {

return vec2(gl_TessCoord.x) * v0 + vec2(gl_TessCoord.y) * v1 + vec2(gl_TessCoord.z) * v2;

}

vec3 interpolate(vec3 v0, vec3 v1, vec3 v2) {

return vec3(gl_TessCoord.x) * v0 + vec3(gl_TessCoord.y) * v1 + vec3(gl_TessCoord.z) * v2;

}

void main(void) {

v_TexCoordFS = vec4(interpolate(v_TexCoordES[0].st, v_TexCoordES[1].st, v_TexCoordES[2].st), 0.0, 1.0);

v_NormalFS = interpolate(v_NormalES[0], v_NormalES[1], v_NormalES[2]);

v_NormalFS = normalize(v_NormalFS);

v_PositionFS = vec4(interpolate(v_PositionES[0].xyz, v_PositionES[1].xyz, v_PositionES[2].xyz), 1.0);

v_ColorFS = vec4(interpolate(v_ColorES[0].rgb, v_ColorES[1].rgb, v_ColorES[2].rgb), 1.0);

float displacement = texture(m_DisplacementTexture, v_TexCoordFS.st).x;

v_PositionFS += vec4(v_NormalFS, 1.0) * displacement * m_DisplacementFactor;

gl_Position = m_ModelViewProjectionMatrix * v_PositionFS;

}

And yes, i've set the number of vertices per patch:

glPatchParameteri(GL_PATCH_VERTICES, 3);

I really hope that someone can tell me the mistake in my code!

i've tried all to generate an output with my tessellation shader. If i add the tessellation evaluation and tessellation control shader to my shader program,

the model to which i applied the shader is gone.

Here is my vertex, tessellation evaluation and tessellation control shader:

Vertex

#version 410

#import "assets/shaders/libraries/VertexCore.glsl"

//Varying variables out for tessellation control shader

out vec4 v_TexCoordCS;

out vec4 v_PositionCS;

out vec4 v_ColorCS;

out vec3 v_NormalCS;

void main(void) {

v_TexCoordCS = i_TexCoord;

v_NormalCS = normalize(m_ModelNormalMatrix * i_Normal);

v_ColorCS = i_Color;

v_PositionCS = i_Vertex;

}

Tessellation Control

#version 410

layout(vertices = 3) out;

//Varying variables in from vertex shader

in vec4[3] v_TexCoordCS;

in vec4[3] v_PositionCS;

in vec4[3] v_ColorCS;

in vec3[3] v_NormalCS;

//Varying variables out for tessellation evaluation shader

out vec4[3] v_TexCoordES;

out vec4[3] v_PositionES;

out vec4[3] v_ColorES;

out vec3[3] v_NormalES;

void main(void) {

v_TexCoordES[gl_InvocationID] = v_TexCoordCS[gl_InvocationID];

v_PositionES[gl_InvocationID] = v_PositionCS[gl_InvocationID];

v_ColorES[gl_InvocationID] = v_ColorCS[gl_InvocationID];

v_NormalES[gl_InvocationID] = v_NormalCS[gl_InvocationID];

gl_TessLevelInner[0] = 3.0;

gl_TessLevelOuter[0] = 10.0;

gl_TessLevelOuter[1] = 7.0;

gl_TessLevelOuter[2] = 3.0;

}

Tessellation Evaluation

#version 410

layout(triangles, equal_spacing, ccw) in;

//Matrices

uniform mat4 m_ModelMatrix;

uniform mat4 m_ViewMatrix;

uniform mat4 m_ProjectionMatrix;

mat4 m_ModelViewMatrix = m_ViewMatrix * m_ModelMatrix;

mat4 m_ModelViewProjectionMatrix = m_ProjectionMatrix * m_ModelViewMatrix;

mat4 m_ViewProjectionMatrix = m_ProjectionMatrix * m_ViewMatrix;

//Uniforms

uniform sampler2D m_DisplacementTexture;

uniform float m_DisplacementFactor;

//Varying variables in from tessellation control shader

in vec4[3] v_TexCoordES;

in vec4[3] v_PositionES;

in vec4[3] v_ColorES;

in vec3[3] v_NormalES;

//Varying variables out for fragment shader

out vec4 v_TexCoordFS;

out vec4 v_PositionFS;

out vec4 v_ColorFS;

out vec3 v_NormalFS;

vec2 interpolate(vec2 v0, vec2 v1, vec2 v2) {

return vec2(gl_TessCoord.x) * v0 + vec2(gl_TessCoord.y) * v1 + vec2(gl_TessCoord.z) * v2;

}

vec3 interpolate(vec3 v0, vec3 v1, vec3 v2) {

return vec3(gl_TessCoord.x) * v0 + vec3(gl_TessCoord.y) * v1 + vec3(gl_TessCoord.z) * v2;

}

void main(void) {

v_TexCoordFS = vec4(interpolate(v_TexCoordES[0].st, v_TexCoordES[1].st, v_TexCoordES[2].st), 0.0, 1.0);

v_NormalFS = interpolate(v_NormalES[0], v_NormalES[1], v_NormalES[2]);

v_NormalFS = normalize(v_NormalFS);

v_PositionFS = vec4(interpolate(v_PositionES[0].xyz, v_PositionES[1].xyz, v_PositionES[2].xyz), 1.0);

v_ColorFS = vec4(interpolate(v_ColorES[0].rgb, v_ColorES[1].rgb, v_ColorES[2].rgb), 1.0);

float displacement = texture(m_DisplacementTexture, v_TexCoordFS.st).x;

v_PositionFS += vec4(v_NormalFS, 1.0) * displacement * m_DisplacementFactor;

gl_Position = m_ModelViewProjectionMatrix * v_PositionFS;

}

And yes, i've set the number of vertices per patch:

glPatchParameteri(GL_PATCH_VERTICES, 3);

I really hope that someone can tell me the mistake in my code!