Hi everyone!
Currently I had tried to make the more simplest shader: a gouraud per-pixel illumination
I have a simple problem: the light is always in front of my camera; when I turn around my object, light turn with me…
Here my code:
public static void main(String[] args) throws Exception {
final StandardGame game = new StandardGame("Test Planete");
if (GameSettingsPanel.prompt(game.getSettings())) {
game.start();
game.executeInGL(new Callable<Integer>() {
public Integer call() {
DebugGameState state = new DebugGameState();
//Enable mouse input:
MouseInput.get().setCursorVisible(true);
Sphere s = new Sphere("sphere", Vector3f.ZERO, 16, 16, 10);
CullState cs = DisplaySystem.getDisplaySystem().getRenderer().createCullState();
cs.setEnabled(true);
cs.setCullMode(CullState.CS_BACK);
GLSLShaderObjectsState glsl = DisplaySystem.getDisplaySystem().getRenderer().createGLSLShaderObjectsState();
glsl.load(getClass().getResource("test.vert.glsl"),
getClass().getResource("test.frag.glsll"));
glsl.setEnabled(true);
s.setRenderState(glsl);
s.setRenderState(cs);
s.updateRenderState();
DirectionalLight dl = new DirectionalLight();
dl.setEnabled(true);
dl.setDirection(new Vector3f(1500 , 1500, 2500));
state.getLightState().attach( dl );
s.setLocalTranslation(0, 0, -100);
//Disable mouse input:
MouseInput.get().setCursorVisible(false);
state.getRootNode().attachChild(s);
// Add it to the manager
GameStateManager.getInstance().attachChild(state);
// Activate the game state
state.setActive(true);
return 0;
}
});
}
}
And here my shaders code:
Vertex program...
varying vec3 normal;
varying vec3 lightDirection;
void main() {
gl_Position = ftransform();
normal = gl_NormalMatrix * gl_Normal;
lightDirection = gl_LightSource[0].position.xyz;
}
...and fragment
varying vec3 normal;
varying vec3 lightDirection;
void main() {
gl_FragColor = vec4(dot(normalize(normal), normalize(lightDirection)));
}
I want to fix this for more complicated shaders based on light position, and I've make this sample application just for fix this :o/
Thanks to you ;)