Acessing vertex color throught GLSL

Started by Jakes, October 28, 2019, 01:06:57 PM

Previous topic - Next topic

Jakes

Hello,

I'm just wondering, when I set the Object3D.setAdditionalColor(), will it affect the gl_Color or any other variable in the Fragment shader?

If not, how can I access this color on the shader side?

Thanks

EgonOlsen

It will affect gl_FrontMaterial.ambient

Jakes

Great! many thanks, thats what I needed to know!
I'll ask you a tiny favour if thats okay by you, can you post that info on the javadoc on the setAdditionalColor() description?

and on another note, will gl_FrontMaterial.ambient have the 4 channels present rgb and a for alpha (Object3D.setTransparency()) if its transparent, if not where is this stored also?

Many thanks once more.

Jakes

I'm trying to change an object's color by setting "obj.setAdditionalColor(255, 0, 0)" and then setting a shader like bellow:

VERTEX:

varying vec2 vTexCoord;
varying vec4 vCol;

void main(void){
   vTexCoord   = gl_MultiTexCoord0.xy;
   vCol     = gl_FrontMaterial.ambient;
   gl_Position = ftransform();
}


FRAGMENT:

sampler2D myTexture;
varying vec2 vTexCoord;
varying vec4 vCol;
void main(){
vec4 color = texture2D(myTexture, vTexCoord);
gl_FragColor = color * vCol;
}


but no coloration change is happening, if I use a uniform, it will work, but I wanted to use the already existent color the object has.

can you give me a little help here?

EgonOlsen

Try

gl_FrontMaterial.emission

instead. I think I read my own code wrong. gl_FrontMaterial.ambient actually contains the world's global ambient color, not the object's additional color.