How to change the color of a shape or add it a texture when using a 3D vertex displacement shader.

Gary Leyrn's icon

Hello,
I need help to change the color of this shape into white. I am using a shader from vade001, to displace vertex.

I tried to connect a jit.gl.texture object to the second inlet of jit.gl.mesh and it did not work.
I tried to change the glcolor attribute value in mesh, and it did not work.

I just can't figure out how to do it.

Max Patch
Copy patch and select New From Clipboard in Max.

v001.3d.sin.jxs
jxs 2.12 KB

Martin Beck's icon

Hello, I don't know if I understood the problem correctly, but when I change the sampler2D and texture2D in your fragment program to the rectangle version then I can apply a texture (e.g. jit.playlist with argument output texture 1).

Change
uniform sampler2D tex0;
to
uniform sampler2DRect tex0;

texel = texture2D(tex0,gl_TexCoord[0].st);
to
texel = texture2DRect(tex0,gl_TexCoord[0].st);

Gary Leyrn's icon

Thanks Martin, It worked. I can see the texture now!

However, when I don't use the texture, I cannot change the color of the shape using the gl_color attribute in mesh. ( When I change this the shape looks orange and only smooth shades are varying). I would like it to be white.

I tried also to give jit.gl.mesh a color array in its 4th inlet and it didn't work. Perhaps I'm missing something really basic since I'm new using shaders.

Any idea about how to change the color of the shape when the texture is off?

Thanks in advance.

Martin Beck's icon

The fragment program of your shader overwrites color Information. Maybe the tutorials on shader programming here help you unserstand whats happening

https://www.federicofoderaro.com/videoTutorials.html

Martin Beck's icon

Maybe this written tutorial is a good start

https://www.federicofoderaro.com/introduction_to_shaders.html

And what you may want to try is to set your fragment program to this:

gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)

Gary Leyrn's icon

Thank you!