Shaders not working correctely

I have a problem with shaders: I’m trying to get a shader to work in jme, but when I create a material from it and apply it to a mesh, the mesh becomes invisible.

This is the scource of my shaders:

Vertex shader:[java]void main(void){

gl_Position = ftransform();

}[/java]

fragment shader:[java]void main(void){

gl_FragColor = vec4(1.0,0.0,0.0, 1.0);

}[/java]

j3md material definition:[java]MaterialDef Material {

MaterialParameters {

Vector4 Color

}

Technique {

VertexShader GLSL100: Shaders/Shader.vert

FragmentShader GLSL100: Shaders/Shader.frag

WorldParameters {

WorldViewProjectionMatrix

}

}

Technique FixedFunc {

}

}[/java]

I tried this in shaderMaker and it worked, but when I try jme, it doesn’t work the way it should work.

ftransform() is sort of “old school” I guess. It may only work in a fixed function style pipeline but I’m not an expert. I know that the JME shaders do it differently and I’ve emulated them when writing my own.



You might take a look at jme’s Unshaded.vert to see how it does its thing. Basically, the position of the vertex comes in as an attribute and then you multiply that by the world view matrix. Something like:



[java]

vec4 pos = vec4(inPosition, 1.0);

gl_Position = g_WorldViewProjectionMatrix * pos;

[/java]



Where:

uniform mat4 g_WorldViewProjectionMatrix;

attribute vec3 inPosition;

yeh it kinda sucks that ftransform(); is used by default when you create the vertex shader though :frowning:

I now have: [java]uniform mat4 g_WorldViewProjectionMatrix;

attribute vec3 inPosition;

void main(void){

vec4 pos = vec4(inPosition, 1.0);

gl_Position = g_WorldViewProjectionMatrix * pos;

}[/java]For the vertex shader, and it still has the same results.


wezrule said:
yeh it kinda sucks that ftransform(); is used by default when you create the vertex shader though :(

It is? It just started as an empty file on my comp, but the glsl plugin wasn't activated yet. Nov it's active becouse i thought that might solve the problem, but it didn't.

I assume your mesh shows up if you use Unshaded.j3md directly?

Yes, and also with lighting.j3md.

I’m at a loss. You are pretty much doing exactly what Unshaded.vert is doing. I start to wonder if it is even picking up the right shader definition.



…can intentionally put in a compile error in the .vert just to verify?

“RenderException:can not compile shader scource”

I think it does find the shader files.

btw: the IDE says every line of the vertex shader is wrong (IDENTIFIER expedted). Is that normal?

I don’t know… I don’t edit shaders in the IDE.



So now the only thing I see different between your shader and unshaded is that you have a void in main(void) and unshaded doesn’t.



After that, there is some piece of information we’re missing because if you remove all of the #ifdef’s from Unshaded.vert it’s nearly identical to yours except for the void.

Just tested using main(void) and without and it doesn’t make a difference in my basic shader…



As for ftransform(), it’s been deprecated in the newest implementations. :confused:



The GLSL plugin is not that reliable. It badly need updates. It does work for some thing though, but you can ignore most errors.



Out of curiosity, why use that?

[java]

void main(void){

gl_FragColor = vec4(1.0,0.0,0.0, 1.0);

}

[/java]



Aren’t you using a texture? The above should give you red and that’s pretty much it. Also, do you have a light in your scene?

I think he’s just testing. A light won’t matter in this case as he’s not doing any lighting calculations.

Yes, it’s just for testing. I made this very simple shader becouse I couldn’t get my texture+per pixel lighting+per pixel fog to work in JME3, And a shader like this would be much easyer to debug.

If it were me, at this point I’d copy Unshaded over into my own assets and slowly start changing it to be more like the broken one until it breaks.