Author Topic: Acessing vertex color throught GLSL  (Read 444 times)

Offline Jakes

  • byte
  • *
  • Posts: 42
    • View Profile
Acessing vertex color throught GLSL
« on: October 28, 2019, 01:06:57 pm »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12061
    • View Profile
    • http://www.jpct.net
Re: Acessing vertex color throught GLSL
« Reply #1 on: October 28, 2019, 01:18:22 pm »
It will affect gl_FrontMaterial.ambient

Offline Jakes

  • byte
  • *
  • Posts: 42
    • View Profile
Re: Acessing vertex color throught GLSL
« Reply #2 on: October 28, 2019, 03:29:55 pm »
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.

Offline Jakes

  • byte
  • *
  • Posts: 42
    • View Profile
Re: Acessing vertex color throught GLSL
« Reply #3 on: October 30, 2019, 12:24:58 am »
I'm trying to change an object's color by setting "obj.setAdditionalColor(255, 0, 0)" and then setting a shader like bellow:

VERTEX:
Code: [Select]
varying vec2 vTexCoord;
varying vec4 vCol;

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

FRAGMENT:
Code: [Select]
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12061
    • View Profile
    • http://www.jpct.net
Re: Acessing vertex color throught GLSL
« Reply #4 on: October 31, 2019, 09:53:20 pm »
Try

Code: [Select]
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.

Offline Jakes

  • byte
  • *
  • Posts: 42
    • View Profile
Re: Acessing vertex color throught GLSL
« Reply #5 on: November 02, 2019, 12:57:35 am »
Great! many thanks