www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: Jakes on October 28, 2019, 01:06:57 pm

Title: Acessing vertex color throught GLSL
Post by: Jakes 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
Title: Re: Acessing vertex color throught GLSL
Post by: EgonOlsen on October 28, 2019, 01:18:22 pm
It will affect gl_FrontMaterial.ambient
Title: Re: Acessing vertex color throught GLSL
Post by: Jakes 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.
Title: Re: Acessing vertex color throught GLSL
Post by: Jakes 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?
Title: Re: Acessing vertex color throught GLSL
Post by: EgonOlsen 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.
Title: Re: Acessing vertex color throught GLSL
Post by: Jakes on November 02, 2019, 12:57:35 am
Great! many thanks