[SOLVED] PointLight shadows not visible

Hello everyone :smiley: !

I’m a newbie here and so far - despite some minor difficulties - I like JMonkey a lot! I’ve been playing with tutorials and got the basic concepts (or so I think…) but I have got stuck recently :pensive:

In short words: shadows from PointLight are not visible in my app. I haven’t tried others, as I believe I’m missing something (and don’t really believe they would work anyway).

This example works just fine: Point light shadows at last

In my case, I’d expect a shadow below the sphere, but as you can see, it doesn’t appear.

And here is my code:

package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.light.PointLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
import com.jme3.shadow.EdgeFilteringMode;
import com.jme3.shadow.PointLightShadowFilter;
import com.jme3.shadow.PointLightShadowRenderer;

public class NoShadowsExample extends SimpleApplication {
    
    public static void main(String[] args) {
        new NoShadowsExample().start();
    }

    @Override
    public void simpleInitApp() {               
        final Material material;        
        final Geometry floor;
        final Geometry sphere;
        final PointLight light;
        final PointLightShadowRenderer plsr;
        
        //Setting up cam and its controls
        {
            flyCam.setEnabled(false);
            flyCam.setMoveSpeed(30);
            cam.setFrame(new Vector3f(0f,1f,6f), new Vector3f(-1f,0f,0f), new Vector3f(0f,1f,0f), new Vector3f(0f, 0f, -1f));             
        }
        
        //LightGray material for floor and sphere
        {
            material=new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
            material.setColor("Ambient", ColorRGBA.LightGray);
        }
            
        //Floor, 20x20 at 0,0,0
        {                              
            floor=new Geometry("Floor",new Box(10, 0.001f, 10));
            floor.setMaterial(material);
            floor.setShadowMode(RenderQueue.ShadowMode.Receive);
            rootNode.attachChild(floor);
        }
        
        //Sphere
        {
            sphere=new Geometry("Sphere", new Sphere(50, 50, 0.5f));
            sphere.move(0f, 1f, 0f);
            sphere.setMaterial(material);
            sphere.setShadowMode(RenderQueue.ShadowMode.Cast);
            rootNode.attachChild(sphere);
        }
        
        //White PointLight at (0,5,0)
        {
            light=new PointLight();
            light.setColor(ColorRGBA.White);
            light.setPosition(new Vector3f(0f, 5f, 0f));                                
            rootNode.addLight(light);
        }
        
        //PointLightShadowRenderer
        {
            plsr = new PointLightShadowRenderer(assetManager, 1024);
            plsr.setLight(light);    
            viewPort.addProcessor(plsr);
        }
        
        //PointLightShadowFilter (commented out, but doesn't work either)
        {/*
            PointLightShadowFilter plsf = new PointLightShadowFilter(assetManager, 1024);
            plsf.setLight(light);
            plsf.setEnabled(true);
            FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
            fpp.addFilter(plsf);
            viewPort.addProcessor(fpp);
        */}
    }   
}

Can you see anything I don’t? Any help would be greatly appreciated, thanks!

the code looks fine at first glance.

Not sure it’s the problem but why do you need this?

cam.setFrame(new Vector3f(0f,1f,6f), new Vector3f(-1f,0f,0f), new Vector3f(0f,1f,0f), new Vector3f(0f, 0f, -1f));

It shouldn’t but it could screw up the rendering of the shadows.

I’ll test your code tonight and see if I have the issue.

1 Like

Hi @nehon, I’m happy that my problem got your attention :grinning: Your work is awesome.

The code you cited just sets the camera in the exact position in which screenshot was taken. Removing it doesn’t change anything (just checked it).

Thank you!

Which video card are you using?

I’ve tried it, and I don’t see it either on my intel HD 2000. But again, my “card” don’t work properly with shadows… :frowning:

Well, this is something I shoud’ve written in the first place, I think.
I use NVidia GTX 970 on Linux Mint (3.13.0-37, 64-bit). GPU drivers 343.36.

Somehow, however, I doubt it’s a hardware issue: the example linked in the first post works perfectly fine.

Is this a big issue on your GPU? If I (ever) make a game, I’d like it to work on integrated GPU’s as well…

try with (fixed the issue on my test):

            light.setRadius(100);

EDIT: by default radius is 0 and ShadowRenderer use it

            shadowCams[i].setFrustumPerspective(90f, 1f, 0.1f, light.getRadius());
4 Likes

@david_bernard_31

Yes, it helped indeed! Thank you very much!
After reading javadoc I even understood why does it work that way :wink: Now I feel somewhat silly, as radius has actualy been mentioned in tutorial… but the light was falling on a “floor” so I assumed the radius is OK. Wasn’t aware of the attenuation thing set by default.

Setting light radius works both for renderer and filter.

edit: how did you make those fancy white and green lines and what do they mean?

the lines are the frustum of the light. To create shadowmap, a point light create 6 shadowmap. each has a frustum like a camera to see what the light enlight.

        plsr.displayFrustum();
        plsr.displayDebug();
1 Like

Thanks @David :wink: