Shadow problem

on the plane shadow look good,

But on Terrain (terrain monkey) it just look like this:

http://img833.imageshack.us/img833/8889/shadowsa.gif



cant find solution

can someone help me fix it? :slight_smile:

Not to say I can solve your problem, but I think you’ll need to at least explain how you’re implementing your shadows. (Or better yet post a small code example.)

[java]



int ShadowQuality = 512;

int ShadowMapsQuality = 1;

public void initFilters() {

/////////////////////////////////////////////////

fade = new FadeFilter();

bloom = new BloomFilter(BloomFilter.GlowMode.Scene);

dof = new DepthOfFieldFilter();

rBlur = new RadialBlurFilter();

if (renderer.getCaps().contains(Caps.GLSL100)) {

fpp = new FilterPostProcessor(assetManager);

pssm = new PssmShadowRenderer(assetManager, ShadowQuality, ShadowMapsQuality);

pssm.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());

pssm.setShadowIntensity(0.4f);

pssm.setFilterMode(PssmShadowRenderer.FilterMode.Nearest);

viewPort.addProcessor(pssm);

viewPort.addProcessor(fpp);

}

fpp.addFilter(dof);

fpp.addFilter(fade);

fpp.addFilter(rBlur);

fpp.addFilter(bloom);

}



[/java]

its just prototype





nevermind of quality it just dont work properly



and about terrain i use example from:



https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_terrain

You should at least use 3 angles to create the shadows, try ShadowMapsQuality = 3; (and use lowercase variable names for conventions sake ^^)

yea i know conventions, just mistake :slight_smile: wait a bit i will try

Edit:

nope, shadowMapsQuality = 3 dont work

i tried many of values and nothin :confused:

Edit 2: This shadow “flashes” when character move… when it just stop and doing “wait animation” then it depend where character stop. in 1 place its ok and in second its all the time bugged

Try a different FilterMode too:



Ex.

pssmRenderer.setFilterMode(FilterMode.PCF4);



I’ve yet to see Nearest work well in any of my tests. Also you might want to change/tweak the direction vector a little, pssm shadows are picky about that.

  • tried all filters
  • tried change shadowQuality and shadowMapsQuality
  • tried change ShadowIntensity
  • tried some of vectors
  • tried compare modes
  • tried disable filters

    and nothin of this help…

    maybe its just a terrain problem? (on box this shadow is ok, on terrain not…)

    or maybe problem is becouse camera is following object? (but as i said when characters is waiting it depends on position character stop)

Terrain problem? Maybe, possibly :slight_smile: (pssm works for me but I’m not using jME terrain for my “land”.)

Is it just specific locations on the terrain this happens, or does it happen anywhere? Is the terrain flat or curvy in the area where the shadow doesn’t work?



What if you eliminate the other filters one by one to see if one of those is causing it? (Comment out viewPort.addProcessor(fpp); or the individual fpp.addFilter() lines, unless this is what you meant by ‘disable filters’)



Could it have something to do with your model? (i.e. multiple parts with shadow casting not enabled for some of them via setShadowMode(ShadowMode.Off)?)



Yup, I’m just throwing wild guesses out now… :wink: If you can reproduce it in a simple/small set of code/project, maybe you could provide a test case to look at?

“Is it just one or specific locations on the terrain this happens, or anywhere?”



just when terrain is almost “flat” then its ok, when terrain is more “curvy” it have output like this with flashing when moving on “curvy” terrain.



“What if you eliminate the other filters one by one to see if one of those is causing it?”



i removed all filters(as i said before) and it dont work. and one by one don’t work too…



“Could it have something to do with your model? (i.e. multiple parts with shadow casting not enabled for some of them via setShadowMode(ShadowMode.Off)?)”



i have just 2 Nodes here.

Both of them use setShadowMode(ShadowMode.Cast)



“Yup, I’m just throwing wild guesses out now… :wink: If you can reproduce it in a simple/small set of code/project, maybe you could provide a test case to look at?”



http://intre.oxplay.net/testcase.zip



or just code(but maybe its object problem so better to download project with men.j3o):



[java]package mygame;

import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.renderer.Camera;

import com.jme3.renderer.queue.RenderQueue.ShadowMode;

import com.jme3.scene.Node;

import com.jme3.shadow.PssmShadowRenderer;

import com.jme3.terrain.geomipmap.TerrainLodControl;

import com.jme3.terrain.heightmap.AbstractHeightMap;

import com.jme3.terrain.geomipmap.TerrainQuad;

import com.jme3.terrain.heightmap.ImageBasedHeightMap;

import com.jme3.texture.Texture;

import com.jme3.texture.Texture.WrapMode;

import java.util.ArrayList;

import java.util.List;

import jme3tools.converters.ImageToAwt;

public class Main extends SimpleApplication {

private TerrainQuad terrain;

Material mat_terrain;

public static void main(String[] args) {

Main app = new Main();

app.start();

}

@Override

public void simpleInitApp() {

flyCam.setMoveSpeed(50);

/** 1. Create terrain material and load four textures into it. /

mat_terrain = new Material(assetManager, “Common/MatDefs/Terrain/Terrain.j3md”);

/
* 1.1) Add ALPHA map (for red-blue-green coded splat textures) /

mat_terrain.setTexture(“Alpha”,

assetManager.loadTexture(“Textures/Terrain/splat/alphamap.png”));

/
* 1.2) Add GRASS texture into the red layer (Tex1). /

Texture grass = assetManager.loadTexture(“Textures/Terrain/splat/grass.jpg”);

grass.setWrap(WrapMode.Repeat);

mat_terrain.setTexture(“Tex1”, grass);

mat_terrain.setFloat(“Tex1Scale”, 64f);

/
* 1.3) Add DIRT texture into the green layer (Tex2) /

Texture dirt = assetManager.loadTexture(“Textures/Terrain/splat/dirt.jpg”);

dirt.setWrap(WrapMode.Repeat);

mat_terrain.setTexture(“Tex2”, dirt);

mat_terrain.setFloat(“Tex2Scale”, 32f);

/
* 1.4) Add ROAD texture into the blue layer (Tex3) /

Texture rock = assetManager.loadTexture(“Textures/Terrain/splat/road.jpg”);

rock.setWrap(WrapMode.Repeat);

mat_terrain.setTexture(“Tex3”, rock);

mat_terrain.setFloat(“Tex3Scale”, 128f);

/
* 2. Create the height map /

final Texture heightMapImage =

assetManager.loadTexture(“Textures/Terrain/splat/mountains512.png”);

final AbstractHeightMap heightmap =

new ImageBasedHeightMap(

ImageToAwt.convert(

heightMapImage.getImage(), false, true, 0));

heightmap.load();

/
* 3. We have prepared material and heightmap. Now we create the actual terrain:

  • 3.1) We create a TerrainQuad and name it "my terrain".
  • 3.2) A good value for terrain tiles is 64x64 – so we supply 64+1=65.
  • 3.3) We prepared a heightmap of size 512x512 – so we supply 512+1=513.
  • 3.4) As LOD step scale we supply Vector3f(1,1,1).
  • 3.5) At last, we supply the prepared heightmap itself.

    /

    terrain = new TerrainQuad(“my terrain”, 65, 513, heightmap.getHeightMap());

    /
    * 4. We give the terrain its material, position & scale it, and attach it. /

    terrain.setMaterial(mat_terrain);

    terrain.setLocalTranslation(0, -100, 0);

    terrain.setLocalScale(2f, 1f, 2f);

    rootNode.attachChild(terrain);

    /
    * 5. The LOD (level of detail) depends on were the camera is: */

    List<Camera> cameras = new ArrayList<Camera>();

    cameras.add(getCamera());

    TerrainLodControl control = new TerrainLodControl(terrain, cameras);

    terrain.addControl(control);

    terrain.setShadowMode(ShadowMode.Receive);

    PssmShadowRenderer shadowProcessor = new PssmShadowRenderer(assetManager, 512, 3);

    shadowProcessor.setDirection(new Vector3f(-0.6f, -0.8f, -0.6f).normalizeLocal());

    shadowProcessor.setLambda(0.55f);

    shadowProcessor.setShadowIntensity(0.6f);

    shadowProcessor.setCompareMode(PssmShadowRenderer.CompareMode.Software);

    shadowProcessor.setFilterMode(PssmShadowRenderer.FilterMode.Nearest);

    viewPort.addProcessor(shadowProcessor);

    Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

    mat1.setColor(“Color”, ColorRGBA.Gray);

    Node spat = (Node) assetManager.loadModel(“Models/man.mesh.j3o”);

    rootNode.attachChild(spat);

    spat.setMaterial(mat1);

    spat.setLocalTranslation(new Vector3f(0, -20, 0));

    spat.setShadowMode(ShadowMode.Cast);

    }

    }[/java]



    testcase output:



    http://intre.oxplay.net/problem.gif

Missing some files I think:

com.jme3.asset.AssetNotFoundException: Textures/materials/rock2.jpg (Flipped) (Mipmaped)



(could be my env, I use Eclipse, but it doesn’t seem to be a jME common asset that I can find)

hmmm i have no rock2.jpg in code and no error as you get o.o.





sorry, true i had same error but its strange…

I did download it, actually. Hmm



man.mesh.j3o definitely has a reference to that ‘rock’ file in it.

its nevermind…

becouse as you see:

[java]spat.setMaterial(mat1);[/java]

so just leave it :)’



its becouse i used material rock as example on normal project to test it. But here it just replace material so its nevermind. if u want just edit in scenecomposer and change material of men.j3o :slight_smile:



but: just tell me, have you the same problem with shadow?(or maybe its some problem with my graphic card/opengl ;p)

Well I tried replacing it with a simple Box with ShadowMode.Cast at the same location, but the shadow looks fine to me:



http://postimage.org/image/1qxxqordw/



Have you tried using any other models? I think it’s more likely related to something going on in the model .j3o file, but I’m not familiar with that format (mostly use .obj right now). Maybe you could try replicating it with a common jME asset? If you can’t do that, I’d say it’s the j3o. If you can replicate, I can see if I see it here too.

1 Like

but if you dont replace it with box, then it work or not?

this object was creating by me in blender and exporting to ogre, and then i created j3o from it

BTW: try move camera arround



shadow of men.j3o work fine on flat box.



but true, it can be object problem. What to do then? Its low poly object, what i do wrong?



loading it to game via ogre.mesh(not j3o) have the same result

It still won’t run if I don’t replace it with something else–I’m getting that exception saying rock2.jpg is missing. I did move the camera around, but shadows looked fine. There was one odd effect where I had the shadow disappear entirely at one point, but it was hard to reproduce (and not the same issue).



Can you export an .obj, or see if you can remove that reference to ‘rock2’?

Can’t you just edit in scenecomposer this j3o by removing rock2 material?

yes or not, here is not compiled object:



http://intre.oxplay.net/men.zip



so try with it, compiled or not i have always shadow problem

A fully-working standalone test case would be best. I don’t currently use the jME platform IDE (only Eclipse), so actually I’ll have to install that first when I find the time. :frowning:

here is project with model without this material Rock2

http://intre.oxplay.net/testcase_fixed.zip

Didn’t work as is (was missing character/man/) but I got it working using files from the other zip you uploaded.



But… I’m not seeing a problem at all. See screens:



http://imgur.com/a/wFt3Z#jPtxv



The worst I was able to get it was like this, but that’s because of the bumpy slope of the terrain.



http://imgur.com/a/wFt3Z#NewoM



I’m not really sure where to go from here, if this isn’t working for you.

If we can’t reproduce the problem, finding a cause is tough…



All I can suggest, if nobody else has any other ideas, is maybe look into implementing some kind of alternative shadow algorithm.

1 Like