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?

    [java]

    AmbientLight al = new AmbientLight();

    al.setColor(ColorRGBA.White);

    Level.rootNode.addLight(al);



    DirectionalLight sun = new DirectionalLight();

    sun.setColor(ColorRGBA.White);

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

    Level.rootNode.addLight(sun);



    Level.rootNode.setShadowMode(ShadowMode.Off);



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

    trackMaterial.setBoolean("UseMaterialColors",true);

    trackMaterial.setColor("Specular",ColorRGBA.White);

    trackMaterial.setColor("Diffuse",ColorRGBA.White);

    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);

    trackGeo.setMaterial(trackMaterial);

    trackGeo.setShadowMode(ShadowMode.Receive);

    slope.attachChild(trackGeo);

    slope.setCullHint(CullHint.Never);



    Level.rootNode.attachChild(slope);[/java]


  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());

    app.getViewPort().addProcessor(pssmRenderer);[/java]

    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
2 #define HARDWARE_SHADOWS 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;
8
9 uniform mat4 g_WorldViewProjectionMatrix;
10 uniform mat4 g_WorldMatrix;
11
12 varying vec4 projCoord0;
13 varying vec4 projCoord1;
14 varying vec4 projCoord2;
15 varying vec4 projCoord3;
16
17 varying float shadowPosition;
18
19 varying vec2 texCoord;
20
21 attribute vec3 inPosition;
22 #ifdef DIFFUSEMAP) || defined(COLOR_MAP)
23 attribute vec2 inTexCoord;
24 #endif
25
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);
30
31
32 void main(){
33 gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
34
35 shadowPosition = gl_Position.z;
36 // get the vertex in world space
37 vec4 worldPos = g_WorldMatrix * vec4(inPosition, 1.0);
38
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 com.jme3.app.Application 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:
http://hub.jmonkeyengine.org/javadoc/com/jme3/math/Quaternion.html#fromAngles(float,%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