Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

TD GLSL, 'gl_VertexID' odd behavior

Still a little green? Ask your beginner's questions here

TD GLSL, 'gl_VertexID' odd behavior

Postby php0614 » Fri Jun 14, 2019 4:56 pm

Hello,

I'm a beginner that doesn't understand GLSL so well.

I've tried to draw the basic (probably famous) 'colorful triangle' OpenGL example in a GLSL TOP

//vertex shader
out vec4 vs_color;

void main(void)
{
const vec4 vertices[3] = vec4[3](vec4(0.25, -0.25, 0.5, 1.0),
vec4(-0.25, -0.25, 0.5, 1.0),
vec4(0.25, 0.25, 0.5, 1.0));
const vec4 colors[3] = vec4[3](vec4(1.0, 0.0, 0.0, 1.0),
vec4(0.0, 1.0, 0.0, 1.0),
vec4(0.0, 0.0, 1.0, 1.0));

int vertID = gl_VertexID;

vertID = vertID;

gl_Position = vertices[vertID] ;

vs_color = colors[gl_VertexID];

}

result:
triangleFailed.png
triangleFailed.png (15.81 KiB) Viewed 542 times


but there's a glitch, it seems like the original triangle is rotated and duplicated.
I guess the 'gl_VertexID' goes beyond 3 in this case, unlike non-TouchDesigner GLSL versions.
I applied %3 to the 'gl_VertexID' and now it looks good (the picture below).

vertID = vertID; -> vertID = vertID %3;

newresult:
triangle.png
triangle.png (12.28 KiB) Viewed 542 times


It would be great if anybody can explain what causes this glitch. Thanks.
php0614
 
Posts: 5
Joined: Sun Jul 31, 2016 1:32 pm

Re: TD GLSL, 'gl_VertexID' odd behavior

Postby malcolm » Sat Jun 15, 2019 11:19 am

The GLSL TOP draws quad, which is why you are seeing your vertex shader run 4 times and creating 4 vertices
User avatar
malcolm
Staff
 
Posts: 4423
Joined: Tue Nov 13, 2007 1:11 am


Return to Beginners

Who is online

Users browsing this forum: Google [Bot] and 23 guests