Gray Shader? How to use Shaders inside jME2?

Inside jME there are some example shaders, which I really like :wink:

I used and modified them. Was a great time :wink:

Now I want to create my own shader!


void main() {
   gl_TexCoord[0] = gl_MultiTexCoord0;
   gl_Position = ftransform();


uniform sampler2D tex;
void main()
   vec4 color = texture2D(tex, gl_TexCoord[0].st);
   float grey = dot(color.rgb, vec3(0.299, 0.587, 0.114));
   color = vec4(grey, grey, grey, 0);
      gl_FragColor = color;

I found this example inside the forum.
My question is, how can I bind the shader inside jME2. The existing shaders are a little bit too "big" :|
I have no idea, which part of the code I have to use for this small example!

And I have no idea, which value I have to give the variable tex?
I there a way to modifie just the output with a shader? For example, invert the colors on the monitor, without modifying the texture? I believe this shader modifies the texture of the object? Am I right? :|
Seriously I have no clue!
For a gray style, a simple output filtering should be enough, or? :?

Take a look at the com.jmetest.renderer.state package specifically the tests that contain GLSL in them, they’ll fix ya up.

Look at it uses a shader with three textures as inputs.  Your just supposed to use an int to set which texture to point to by order in which they were added to the Node:

        so.setUniform("baseMap", 0);
        so.setUniform("normalMap", 1);
        so.setUniform("specularMap", 2);