Opengl How to get each quad/patch and shade them different colours after tessellation?

The image above shows what I have so far.
I have managed to tessellate a quad with 4 vertices each patch (although there are some small issues in places, which I will fix soon), but next I wanted to shade each patch(quad) a differently colour, or if I could get a single patch and shade it that would be good as well, is this possibly?
Does anyone have any ideas on how I would do this?
Tess Control Shader
#version 410 core
layout(vertices = 4) out;
void main(void)
{
gl_TessLevelOuter[0] = 2.0;
gl_TessLevelOuter[1] = 4.0;
gl_TessLevelOuter[2] = 6.0;
gl_TessLevelOuter[3] = 8.0;
gl_TessLevelInner[0] = 8.0;
gl_TessLevelInner[1] = 8.0;
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}
Tess Evaluation Shader
#version 410 core
layout(quads, equal_spacing, ccw) in;
// quad interpolate
vec4 interpolate(in vec4 v0, in vec4 v1, in vec4 v2, in vec4 v3)
{
vec4 a = mix(v0, v1, gl_TessCoord.x);
vec4 b = mix(v3, v2, gl_TessCoord.x);
return mix(a, b, gl_TessCoord.y);
}
void main()
{
gl_Position = interpolate(
gl_in[0].gl_Position,
gl_in[1].gl_Position,
gl_in[2].gl_Position,
gl_in[3].gl_Position);
}
Geo Shader
#version 410 core
layout(triangles, invocations = 1) in;
layout(triangle_strip, max_vertices = 4) out;
void main(void)
{
gl_Position = gl_in[0].gl_Position;
EmitVertex();
gl_Position = gl_in[1].gl_Position;
EmitVertex();
gl_Position = gl_in[2].gl_Position;
EmitVertex();
EndPrimitive();
}
opengl glsl
add a comment |

The image above shows what I have so far.
I have managed to tessellate a quad with 4 vertices each patch (although there are some small issues in places, which I will fix soon), but next I wanted to shade each patch(quad) a differently colour, or if I could get a single patch and shade it that would be good as well, is this possibly?
Does anyone have any ideas on how I would do this?
Tess Control Shader
#version 410 core
layout(vertices = 4) out;
void main(void)
{
gl_TessLevelOuter[0] = 2.0;
gl_TessLevelOuter[1] = 4.0;
gl_TessLevelOuter[2] = 6.0;
gl_TessLevelOuter[3] = 8.0;
gl_TessLevelInner[0] = 8.0;
gl_TessLevelInner[1] = 8.0;
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}
Tess Evaluation Shader
#version 410 core
layout(quads, equal_spacing, ccw) in;
// quad interpolate
vec4 interpolate(in vec4 v0, in vec4 v1, in vec4 v2, in vec4 v3)
{
vec4 a = mix(v0, v1, gl_TessCoord.x);
vec4 b = mix(v3, v2, gl_TessCoord.x);
return mix(a, b, gl_TessCoord.y);
}
void main()
{
gl_Position = interpolate(
gl_in[0].gl_Position,
gl_in[1].gl_Position,
gl_in[2].gl_Position,
gl_in[3].gl_Position);
}
Geo Shader
#version 410 core
layout(triangles, invocations = 1) in;
layout(triangle_strip, max_vertices = 4) out;
void main(void)
{
gl_Position = gl_in[0].gl_Position;
EmitVertex();
gl_Position = gl_in[1].gl_Position;
EmitVertex();
gl_Position = gl_in[2].gl_Position;
EmitVertex();
EndPrimitive();
}
opengl glsl
Would this form of tessellation be used for something like Radosity?
– Charlie Wheate
Aug 2 '18 at 12:59
add a comment |

The image above shows what I have so far.
I have managed to tessellate a quad with 4 vertices each patch (although there are some small issues in places, which I will fix soon), but next I wanted to shade each patch(quad) a differently colour, or if I could get a single patch and shade it that would be good as well, is this possibly?
Does anyone have any ideas on how I would do this?
Tess Control Shader
#version 410 core
layout(vertices = 4) out;
void main(void)
{
gl_TessLevelOuter[0] = 2.0;
gl_TessLevelOuter[1] = 4.0;
gl_TessLevelOuter[2] = 6.0;
gl_TessLevelOuter[3] = 8.0;
gl_TessLevelInner[0] = 8.0;
gl_TessLevelInner[1] = 8.0;
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}
Tess Evaluation Shader
#version 410 core
layout(quads, equal_spacing, ccw) in;
// quad interpolate
vec4 interpolate(in vec4 v0, in vec4 v1, in vec4 v2, in vec4 v3)
{
vec4 a = mix(v0, v1, gl_TessCoord.x);
vec4 b = mix(v3, v2, gl_TessCoord.x);
return mix(a, b, gl_TessCoord.y);
}
void main()
{
gl_Position = interpolate(
gl_in[0].gl_Position,
gl_in[1].gl_Position,
gl_in[2].gl_Position,
gl_in[3].gl_Position);
}
Geo Shader
#version 410 core
layout(triangles, invocations = 1) in;
layout(triangle_strip, max_vertices = 4) out;
void main(void)
{
gl_Position = gl_in[0].gl_Position;
EmitVertex();
gl_Position = gl_in[1].gl_Position;
EmitVertex();
gl_Position = gl_in[2].gl_Position;
EmitVertex();
EndPrimitive();
}
opengl glsl

The image above shows what I have so far.
I have managed to tessellate a quad with 4 vertices each patch (although there are some small issues in places, which I will fix soon), but next I wanted to shade each patch(quad) a differently colour, or if I could get a single patch and shade it that would be good as well, is this possibly?
Does anyone have any ideas on how I would do this?
Tess Control Shader
#version 410 core
layout(vertices = 4) out;
void main(void)
{
gl_TessLevelOuter[0] = 2.0;
gl_TessLevelOuter[1] = 4.0;
gl_TessLevelOuter[2] = 6.0;
gl_TessLevelOuter[3] = 8.0;
gl_TessLevelInner[0] = 8.0;
gl_TessLevelInner[1] = 8.0;
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}
Tess Evaluation Shader
#version 410 core
layout(quads, equal_spacing, ccw) in;
// quad interpolate
vec4 interpolate(in vec4 v0, in vec4 v1, in vec4 v2, in vec4 v3)
{
vec4 a = mix(v0, v1, gl_TessCoord.x);
vec4 b = mix(v3, v2, gl_TessCoord.x);
return mix(a, b, gl_TessCoord.y);
}
void main()
{
gl_Position = interpolate(
gl_in[0].gl_Position,
gl_in[1].gl_Position,
gl_in[2].gl_Position,
gl_in[3].gl_Position);
}
Geo Shader
#version 410 core
layout(triangles, invocations = 1) in;
layout(triangle_strip, max_vertices = 4) out;
void main(void)
{
gl_Position = gl_in[0].gl_Position;
EmitVertex();
gl_Position = gl_in[1].gl_Position;
EmitVertex();
gl_Position = gl_in[2].gl_Position;
EmitVertex();
EndPrimitive();
}
opengl glsl
opengl glsl
edited Nov 24 '18 at 11:05
Rabbid76
34.9k113146
34.9k113146
asked Aug 2 '18 at 12:39
Charlie WheateCharlie Wheate
336
336
Would this form of tessellation be used for something like Radosity?
– Charlie Wheate
Aug 2 '18 at 12:59
add a comment |
Would this form of tessellation be used for something like Radosity?
– Charlie Wheate
Aug 2 '18 at 12:59
Would this form of tessellation be used for something like Radosity?
– Charlie Wheate
Aug 2 '18 at 12:59
Would this form of tessellation be used for something like Radosity?
– Charlie Wheate
Aug 2 '18 at 12:59
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51653899%2fopengl-how-to-get-each-quad-patch-and-shade-them-different-colours-after-tessell%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51653899%2fopengl-how-to-get-each-quad-patch-and-shade-them-different-colours-after-tessell%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Would this form of tessellation be used for something like Radosity?
– Charlie Wheate
Aug 2 '18 at 12:59