Problems with lighting and shadows

Hi!

I have an issue setting up lighting and shadows with my project. I added a simle Directional Light and then a Directional Light Shadow Renderer, but I have no shadows.

Here is my code:

    ViewPort localvp = settings.getViewPort();
    AssetManager localam = settings.getAssetManager();
    
    DirectionalLight sun = new DirectionalLight();
    
    sun.setDirection(new Vector3f(0, 1, 0).normalizeLocal());
    sun.setColor(ColorRGBA.White);
    
    settings.getNode().addLight(sun);
    
    DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(localam, 1024, 2);
    dlsr.setLight(sun);

    localvp.addProcessor(dlsr);

Mesh normals generator:

private void addSquareNormals(List<Float> normals, float normalX, float normalY, float normalZ){
    for(int i=0;i<4;i++){
        normals.add(normalX);
        normals.add(normalY);
        normals.add(normalZ);
    }
}

Did you set any of your objects to cast or receive shadows?

also i belive you might have not desired light direction anyway.

No, how do I set this?

I want a light perpendicular to X-Z plane

geom.setShadowMode(ShadowMode.CastAndReceive);

or just Cast or just Receive, etc

1 Like

Thanks, I’ll try this in a moment

I want a light perpendicular to X-Z plane

im not 100% sure, but Vector3f(0, 1, 0) is up, while usually you want light go down,
it is Vector3f(0, -1, 0)

Yeah, you’re right!

Yeah, but it still looks pretty ugly.

Note: I changed directional light to X: -1, Y: -1, Z:0

dont realy see much with this screenshot. what this scene look like without shadow?

also i understand you still use .normalizeLocal() that is required

edit:

also try play arround config like:

    dlsf = new DirectionalLightShadowFilter(assetManager, 8192, 3);
    dlsf.setLight(sun);
    dlsf.setEnabledStabilization(true);
    dlsf.setShadowIntensity(0.4f);
    dlsf.setEdgesThickness(1);
    dlsf.setShadowCompareMode(CompareMode.Hardware);
    dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);

search what will give you better result.

btw. as i know default unit2meter is 1 unit = 1 meter in games. someone mentioned before.

You said you wanted it perpendicular to the X-Z plane so why do you make it parallel instead?

I can’t tell if there is confusion about what “perpendicular” means or what “direction” means.

If light is overhead then 0, -1, 0 is the light pointing straight down, ie: perpendicular to the x-z plane. -1, -1, 0 is not even a direction vector until normalized but will be parallel to the x-z plane as it has no y component at all (the definition of parallel to the x-z plane.)

Edit: also the tutorials are probably useful here: https://wiki.jmonkeyengine.org/jme3/advanced/light_and_shadow.html

Yes, I know that perpendicular light is X:0 Y:-1 Z:0 but I made a 45 degrees light with these parameters, right? I don’t think it’s parallel to the X-Z plane (it should be X:-1 Y:0 Z:0)

The original scene:

Now i’m trying your hints.

i really dont know what this scene is, but its hardly seen there is slope and looks like voxel terrain.

you use some ready2use voxel libs?

It’s a flying box on a voxel terrain

im not 100% sure, but if im correct white area is slope of voxel terrain, and it looks like it have broken texCoords. it might cause shadow issue too.

why cant you make it visible, its like

“guess what it is” :smiley:

It’s a chunk world, so I can’t hide terrain because i’ts connected with that box. Sorry for that, but I’ve not implemented textures yet.

wait, you write own voxel engine?

there are already a lot of them in JME, why not just use one.

Yeah, i know. But i wanted to make one from my own, and I learned a lot from this.