PSSM and Chase Cam

Hi everyone.



I’m having a little problem with the PSSM and the Chase Cam. I don’t know what I’m doing wrong, but I added a PssmShadowRenderer to the scene and a Chase Cam following a spatial.



Everything seems to work fine as the shadow is rendered perfectly, but as soon as I start moving my character and getting away from the “center” of the scene, the shadow starts looking uglier and uglier. As I start coming back to the center, the shadow quality improves a lot.



Is there something I’m missing?



Thanks.

You need at least 3 angles so they look good, did you specify “1” in the constructor?

@normen said:
You need at least 3 angles so they look good, did you specify "1" in the constructor?


No, I've set 3.

Here's my SimpleInitApp:

[java]public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);

Spatial scene = assetManager.loadModel("Scenes/Escena1.j3o");
rootNode.attachChild(scene);

player = rootNode.getChild("character-ogremesh");
terrain = rootNode.getChild("terrain-Escena1");

player.setShadowMode(RenderQueue.ShadowMode.Cast);
terrain.setShadowMode(RenderQueue.ShadowMode.Receive);

MainCharacterControl = player.getControl(CharacterControl.class);

bulletAppState.getPhysicsSpace().add(player);
bulletAppState.getPhysicsSpace().add(rootNode.getChild("terrain-Escena1"));
flyCam.setEnabled(false);

ChaseCamera chaseCam = new ChaseCamera(cam, player, inputManager);

/** Advanced shadows for uneven surfaces */
PssmShadowRenderer pssm = new PssmShadowRenderer(assetManager, 1024, 3);
pssm.setDirection(new Vector3f(-.5f,-.5f,-.5f).normalizeLocal());

chaseCam.setEnabled(true);

viewPort.addProcessor(pssm);

inputManager.addMapping("CharLeft", new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping("CharRight", new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping("CharForward", new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping("CharBackward", new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping("CharJump", new KeyTrigger(KeyInput.KEY_RETURN));
inputManager.addMapping("CharAttack", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(this, "CharLeft", "CharRight");
inputManager.addListener(this, "CharForward", "CharBackward");
inputManager.addListener(this, "CharJump", "CharAttack");
}
[/java]

Can you make a test case of this? Could it be you accidentally modify one of the constants in your other code? Like Vector3f.UNIT_Y.multLocal(.5) or so?

Here. I used the same code as TestChaseCamera, but added the PSSM.



[java]import com.jme3.app.SimpleApplication;

import com.jme3.input.ChaseCamera;

import com.jme3.input.controls.ActionListener;

import com.jme3.input.controls.AnalogListener;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.material.Material;

import com.jme3.math.FastMath;

import com.jme3.math.Quaternion;

import com.jme3.math.Vector3f;

import com.jme3.renderer.queue.RenderQueue;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Quad;

import com.jme3.shadow.PssmShadowRenderer;



/** A 3rd-person chase camera orbits a target (teapot).

  • Follow the teapot with WASD keys, rotate by dragging the mouse. /

    public class TestChaseCamera extends SimpleApplication implements AnalogListener, ActionListener {



    private Geometry teaGeom;

    private ChaseCamera chaseCam;



    public static void main(String[] args) {

    TestChaseCamera app = new TestChaseCamera();

    app.start();

    }



    public void simpleInitApp() {

    // Load a teapot model

    teaGeom = (Geometry) assetManager.loadModel(“Models/Teapot/Teapot.obj”);

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

    teaGeom.setMaterial(mat_tea);

    rootNode.attachChild(teaGeom);



    // Load a floor model

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

    mat_ground.setTexture(“ColorMap”, assetManager.loadTexture(“Interface/Logo/Monkey.jpg”));

    Geometry ground = new Geometry(“ground”, new Quad(500, 500));

    ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));

    ground.setLocalTranslation(-25, -1, 25);

    ground.setMaterial(mat_ground);

    rootNode.attachChild(ground);



    // Disable the default first-person cam!

    flyCam.setEnabled(false);

    /
    * Advanced shadows for uneven surfaces */

    PssmShadowRenderer pssm = new PssmShadowRenderer(assetManager, 1024, 3);

    pssm.setDirection(new Vector3f(-.5f,-.5f,-.5f).normalizeLocal());

    viewPort.addProcessor(pssm);



    // Enable a chase cam

    chaseCam = new ChaseCamera(cam, teaGeom, inputManager);



    //Uncomment this to invert the camera’s vertical rotation Axis

    //chaseCam.setInvertVerticalAxis(true);



    //Uncomment this to invert the camera’s horizontal rotation Axis

    //chaseCam.setInvertHorizontalAxis(true);



    //Comment this to disable smooth camera motion

    chaseCam.setSmoothMotion(true);



    teaGeom.setShadowMode(RenderQueue.ShadowMode.Cast);

    ground.setShadowMode(RenderQueue.ShadowMode.Receive);



    //Uncomment this to disable trailing of the camera

    //WARNING, trailing only works with smooth motion enabled. It is true by default.

    //chaseCam.setTrailingEnabled(false);



    //Uncomment this to look 3 world units above the target

    //chaseCam.setLookAtOffset(Vector3f.UNIT_Y.mult(3));



    //Uncomment this to enable rotation when the middle mouse button is pressed (like Blender)

    //WARNING : setting this trigger disable the rotation on right and left mouse button click

    //chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));



    //Uncomment this to set mutiple triggers to enable rotation of the cam

    //Here spade bar and middle mouse button

    //chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE),new KeyTrigger(KeyInput.KEY_SPACE));



    //registering inputs for target’s movement

    registerInput();



    }



    public void registerInput() {

    inputManager.addMapping(“moveForward”, new KeyTrigger(keyInput.KEY_UP), new KeyTrigger(keyInput.KEY_W));

    inputManager.addMapping(“moveBackward”, new KeyTrigger(keyInput.KEY_DOWN), new KeyTrigger(keyInput.KEY_S));

    inputManager.addMapping(“moveRight”, new KeyTrigger(keyInput.KEY_RIGHT), new KeyTrigger(keyInput.KEY_D));

    inputManager.addMapping(“moveLeft”, new KeyTrigger(keyInput.KEY_LEFT), new KeyTrigger(keyInput.KEY_A));

    inputManager.addMapping(“displayPosition”, new KeyTrigger(keyInput.KEY_P));

    inputManager.addListener(this, “moveForward”, “moveBackward”, “moveRight”, “moveLeft”);

    inputManager.addListener(this, “displayPosition”);

    }



    public void onAnalog(String name, float value, float tpf) {

    if (name.equals(“moveForward”)) {

    teaGeom.move(0, 0, -5 * tpf);

    }

    if (name.equals(“moveBackward”)) {

    teaGeom.move(0, 0, 5 * tpf);

    }

    if (name.equals(“moveRight”)) {

    teaGeom.move(5 * tpf, 0, 0);

    }

    if (name.equals(“moveLeft”)) {

    teaGeom.move(-5 * tpf, 0, 0);



    }



    }



    public void onAction(String name, boolean keyPressed, float tpf) {

    if (name.equals(“displayPosition”) && keyPressed) {

    teaGeom.move(10, 10, 10);



    }

    }



    @Override

    public void simpleUpdate(float tpf) {

    super.simpleUpdate(tpf);



    // teaGeom.move(new Vector3f(0.001f, 0, 0));

    // pivot.rotate(0, 0.00001f, 0);

    // rootNode.updateGeometricState();

    }

    // public void update() {

    // super.update();

    //// render the viewports

    // float tpf = timer.getTimePerFrame();

    // state.getRootNode().rotate(0, 0.000001f, 0);

    // stateManager.update(tpf);

    // stateManager.render(renderManager);

    // renderManager.render(tpf);

    // }

    }[/java]





    As you can see, as you get closer to the edge, the shadows start lossing quality and getting pixelated.
1 Like

Did anyone try the code?

I can’t run it as jme doesn’t work on my computer atm.

I think the problem is around this:


setShadowZextend() – distance how far away from camera shadows will still be computed


Is computing the camera position from the chase cam or from the flycam? I'll try using the flycam and see how it works.
@gonzalofarias1 said:
Here. I used the same code as TestChaseCamera, but added the PSSM.

As you can see, as you get closer to the edge, the shadows start lossing quality and getting pixelated.

mhh I don't have the issue could you post a screenshot?



@gonzalofarias1 said:
Is computing the camera position from the chase cam or from the flycam? I'll try using the flycam and see how it works.

You are misunderstanding. ChaseCamera and FlyCamera are handles over the scene camera. They define how the camera moves around. They are not camera by themselves.
There is only one camera for a viewport.
SetShadowZextend define the distance in viewSpace how far the shadows should be computed.
It's handy when you have baked shadows in a scene and that you want to compute dynamic shadows only for nearby objects and not for the whole camera frustum.

How it looks like when I start the game:



http://2.bp.blogspot.com/-EFZ-fPmJU4I/UIdBjKmsjhI/AAAAAAAAARE/uhy5h58TWq4/s1600/Dibujo1.JPG





After getting closer to the edge of the square, leaving the center:



http://2.bp.blogspot.com/-Z0D8ku1XOA8/UIdBjwZl1EI/AAAAAAAAARQ/Qu7LtHVMeGk/s1600/Dibujo2.JPG

mhh… what kind of hardware do you have?

does it supports opengl 3.0?

I’m trying to figure what shader is used in your case (we have a ogl2 shader and an ogl3)

I’m using a Geforce GTS 250:



http://www.geforce.com/hardware/desktop-gpus/geforce-gts250/specifications



It does support OpenGL 3.0 according to this page.



Maybe it’s a driver issue. I’m still using Windows XP.

Windows XP is well supported by NVidia as far as I know, specially the ones before the 400 VGAs and models x50 and lower (250, 240, 230 etc).

Hey
I know this is a old topic, but i’m having this same problem. Someone has figured out how to solve it?