Light and shadows problem

I have a problem, or two actually.

  1. When I try to use lit material everything is black, even after I add lights.

    I guess I have missed something but what?


    AmbientLight al = new AmbientLight();



    DirectionalLight sun = new DirectionalLight();


    sun.setDirection(new Vector3f(FastMath.PI/3, FastMath.PI/3, 0).normalizeLocal());



    Material trackMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");




    trackMaterial.setFloat("Shininess", 5f);

    Node slope = new Node("slope");

    Track track = new Track();

    Mesh trackMesh = track.generateTrack(Level.analyze);

    Geometry trackGeo = new Geometry("Slope", trackMesh);






  2. When I try to use shadows it crashes, but this time it doesn’t feel like my fault.

    Nothing I can guarantee though :stuck_out_tongue:

    [java]PssmShadowRenderer pssmRenderer = new PssmShadowRenderer(assetManager, 1024, 3);

    pssmRenderer.setDirection(new Vector3f(0, FastMath.PI/3, FastMath.PI/3).normalizeLocal());


    crashes with the error
Jul 20, 2012 10:00:59 PM com.jme3.renderer.lwjgl.LwjglRenderer updateShaderSourceData
WARNING: Bad compile of:
1 #define FILTER_MODE 1
3 #define PCFEDGE 1.0
4 uniform mat4 m_LightViewProjectionMatrix0;
5 uniform mat4 m_LightViewProjectionMatrix1;
6 uniform mat4 m_LightViewProjectionMatrix2;
7 uniform mat4 m_LightViewProjectionMatrix3;
9 uniform mat4 g_WorldViewProjectionMatrix;
10 uniform mat4 g_WorldMatrix;
12 varying vec4 projCoord0;
13 varying vec4 projCoord1;
14 varying vec4 projCoord2;
15 varying vec4 projCoord3;
17 varying float shadowPosition;
19 varying vec2 texCoord;
21 attribute vec3 inPosition;
22 #ifdef DIFFUSEMAP) || defined(COLOR_MAP)
23 attribute vec2 inTexCoord;
24 #endif
26 const mat4 biasMat = mat4(0.5, 0.0, 0.0, 0.0,
27 0.0, 0.5, 0.0, 0.0,
28 0.0, 0.0, 0.5, 0.0,
29 0.5, 0.5, 0.5, 1.0);
32 void main(){
33 gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
35 shadowPosition = gl_Position.z;
36 // get the vertex in world space
37 vec4 worldPos = g_WorldMatrix * vec4(inPosition, 1.0);
39 #if defined(DIFFUSEMAP) || defined(COLOR_MAP)
40 texCoord = inTexCoord;
41 #endif
42 // populate the light view matrices array and convert vertex to light viewProj space
43 projCoord0 = biasMat * m_LightViewProjectionMatrix0 * worldPos;
44 projCoord1 = biasMat * m_LightViewProjectionMatrix1 * worldPos;
45 projCoord2 = biasMat * m_LightViewProjectionMatrix2 * worldPos;
46 projCoord3 = biasMat * m_LightViewProjectionMatrix3 * worldPos;
47 }

Jul 20, 2012 10:00:59 PM handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
com.jme3.renderer.RendererException: compile error in:ShaderSource[name=Common/MatDefs/Shadow/PostShadowPSSM.vert, defines, type=Vertex, language=GLSL100] error:0:22(18): preprocessor warning: extra tokens at end of directive
0:22(23): preprocessor error: syntax error, unexpected DEFINED, expecting NEWLINE
  1. you light is poiting up
  2. uh…there is a missing “(”… i committed a fix
1 Like
@nehon said:
1. you light is poiting up
2. uh...there is a missing "("... i committed a fix

I changed sun.setDirection(new Vector3f(FastMath.PI/3, FastMath.PI/3, 0).normalizeLocal());
to sun.setDirection(new Vector3f(-FastMath.PI/3, FastMath.PI/3, 0).normalizeLocal());
and now my model is lit on a single "wing" but not the rest and the track is lit on the first part
(the first (two?) triangles) but not the rest.

Does I need some kind of mapping or such just to show a model or a mesh with a single lit color?

2. Thanks :)

try with a negative y value. Y is the up vector in opengl

And you don’t need to use PI for directional vectors…that’s for radians… rotations…

Now I don’t understand :stuck_out_tongue:

How would I specify if I want it 60° up (where 90° is straight down)

and 60° from the right (where 90° is straight from the right)?

I have read the jME3 Math for Dummies but I can’t say it made me much smarter :confused:

@rasmuseneman said:
Now I don't understand :P

How would I specify if I want it 60° up (where 90° is straight down)
and 60° from the right (where 90° is straight from the right)?

I have read the jME3 Math for Dummies but I can't say it made me much smarter :/

And I'm not trying to be mean... but read it again. It's great stuff... keep reading it and exploring it until it makes sense.

The key to your solution is:,%20float,%20float)

It is not a direct answer but will get you started.

I guess my problem is that a Vector3f direction != a Quaternion rotation.

I tried to just flip the Y axis as @nehon said and it lit from upwards somewhere,

enough to see that a DirectionalLight doesn’t fit in so I removed it.

But thanks anyway guys! Without you I would know even less what I was doing.

@rasmuseneman said:
I guess my problem is that a Vector3f direction != a Quaternion rotation.

Yeah, it was just a hint. Between that and the math for dummies, I hoped you put together that you could rotate a vector by the quaternion to achieve the desired direction vector. That's why I said: "It is not a direct answer but will get you started."

Anyway... now you'll have something for next time.
1 Like