Jump to content
  • Advertisement
Sign in to follow this  
fread

how to send RGBA unsigned byte color to GLSL shader?

This topic is 1663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi,

as a vertex attrib, 4 bytes color (each color component as 8 bits, RGBA).

How to send it and receive it in shader? 

I can't find any info on this.

Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement

one defines the vertex attributes layout for a bound stream  into a shader by:

 

... bind vertex buffer

int attribute=glGetAttribLocation(program, 'vx_color');

 glenableVertexAttribArray(attribute);
    glvertexAttribPointer(attribute, 4, gl.UNSIGNED_BYTE, false, 32, 12);

 

so if in GLSL you have declared an

 

"attribute vec4 vx_color;"

 

then the shader will be fed a 4 component floating vector from bound stream , in which you declared how to feed the vector by glvertexAttribPointer function. parameters are:

 

attribute location, components count, component data type in stream, normalized?, size of  vertex in bytes, offset to the beginning of attribute in bytes

 

 

  in advanced versions of glsl you can define the layout in the very GLSL code by layout keyword.

Share this post


Link to post
Share on other sites

 

    glvertexAttribPointer(attribute, 4, gl.UNSIGNED_BYTE, false, 32, 12);

 

 

 

 

Wouldn't the 'normalized' parameter be set to 'true' so that the resulting byte value is scaled from 0-255 to 0.0-1.0 ?

Share this post


Link to post
Share on other sites

C code:

 glenableVertexAttribArray(at_color);
    glvertexAttribPointer(at_color, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(MyVertex), offsetof(MyVertex,colorField));

Shader:

attribute vec4 at_color;"

gives me all black... what's wrong? Stride is OK, "normalized" is GL_TRUE, component type is GL_UNSIGNED_BYTE, component count is 4 because its R G B A color...

 

EDIT: fixed, working, thanks for all! especially radioteeth and JohnnyCode  

Edited by fread

Share this post


Link to post
Share on other sites

 


Wouldn't the 'normalized' parameter be set to 'true' so that the resulting byte value is scaled from 0-255 to 0.0-1.0 ?

 

depends on wheather you want the floating vector in GLSL be 0.0-1.0 clamped or reflect the very byte valyes such as (128.0,0.0,56.0,255.0)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!