jPCT - a 3d engine for Java > Support

Acessing vertex color throught GLSL

(1/2) > >>

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:

--- Code: ---varying vec2 vTexCoord;
varying vec4 vCol;

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

--- End code ---

FRAGMENT:

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

--- End code ---

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


--- Code: ---gl_FrontMaterial.emission
--- End code ---

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.

Navigation

[0] Message Index

[#] Next page

Go to full version