Shadows not rendering

Hello all,



I've been working with jME for quite a bit now, and everything works great. Like a charm… except the shadows. I have two systems, a laptop and a desktop. On both, I can see the shadow volume, but I can only see the actual shadow on my laptop. I'm using a ShadowedRenderPass. My desktop has dual core and greatly surpasses my laptop in speed, memory, RAM, video memory, etc. Is dual core possibly causing the shadows to not show up properly? On the other hand, the Z-Pass Shadow Volumes demo works like a charm - so I'm assuming it's just my code, but why would it not work on my desktop and work on my laptop?



The specs for my laptop:

Pentium M 1.4GHz

512MB RAM

64MB ATI Video Memory

Windows XP Pro, Java 1.5, jME 0.11, LWJGL 0.99



The specs for my desktop:

AMD ATHLON 64 X2 6000+ Dual Core SKT AM2 CPU 3GHz

2GB DDR2 800MHz RAM

256MB nVidia GeForce 7600 GT Video Memory

Windows XP Home, Java 1.5, jME 0.11, LWJGL 0.99



I don't receive any errors or warnings in the console either. Here's the source:

import com.jme.util.*;
import com.jme.math.*;
import com.jme.scene.*;
import com.jme.input.*;
import com.jme.image.*;
import com.jme.light.*;
import com.jmex.game.*;
import com.jme.renderer.*;
import com.jme.bounding.*;
import com.jme.scene.shape.*;
import com.jme.scene.state.*;
import com.jme.renderer.pass.*;

public class Test extends StandardGame {
   private int fps = 60;
   private int gameW = 800;
   private int gameH = 600;

   private Node scene;
   private KeyBindingManager keyman;

   private ShadowedRenderPass pass;

   public Test() {
      super("game");

      getSettings().setWidth(gameW);
      getSettings().setHeight(gameH);
      getSettings().setFramerate(fps);
      getSettings().setFullscreen(false);

      start();
   }

   public void initGame() {
      scene = new Node("scene");

      TextureState bricks = getDisplay().getRenderer().createTextureState();
      bricks.setTexture(TextureManager.loadTexture(getClass().getResource("Bricks.png"), Texture.MM_LINEAR, Texture.FM_LINEAR));

      Box plane = new Box("plane", new Vector3f(-10, -0.05f, -10), new Vector3f(10, 0.05f, 10));
      plane.setModelBound(new BoundingBox());
      plane.updateModelBound();
      plane.setLocalTranslation(new Vector3f(0, -7, 0));
      plane.setRenderState(bricks);
      plane.updateRenderState();
      scene.attachChild(plane);

      Sphere ball = new Sphere("ball", 10, 10, 0.5f);
      ball.setModelBound(new BoundingSphere());
      ball.updateModelBound();
      ball.setLocalTranslation(new Vector3f(0, -5, 0));
      scene.attachChild(ball);

      LightState lState = getDisplay().getRenderer().createLightState();
      scene.setRenderState(lState);

      PointLight light = new PointLight();
      light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 0.1f));
      light.setLocation(new Vector3f(3, 0, 7));
      light.setShadowCaster(true);
      light.setEnabled(true);
      lState.attach(light);

      ZBufferState buf = getDisplay().getRenderer().createZBufferState();
      buf.setFunction(buf.CF_LEQUAL);
      scene.setRenderState(buf);

      CullState cull = getDisplay().getRenderer().createCullState();
      cull.setCullMode(cull.CS_BACK);
      scene.setRenderState(cull);

      scene.updateRenderState();

      pass = new ShadowedRenderPass();
      pass.add(scene);
      pass.addOccluder(ball);
      pass.setRenderShadows(true);
      pass.setLightingMethod(pass.MODULATIVE);

      keyman = KeyBindingManager.getKeyBindingManager();
      keyman.set("exit", KeyInput.KEY_ESCAPE);
   }

   public void update(float tpf) {
      pass.updatePass(tpf);

      if (keyman.isValidCommand("exit")) System.exit(-1);
   }

   public void render(float tpf) {
      Renderer r = getDisplay().getRenderer();
      r.clearBuffers();
      r.draw(scene);
      pass.renderPass(r);
   }

   public static void main(String args[]) {
      new Test();
   }
}



Thanks in advanced for your support,
Jamison

Looks like you do not manually set up a stencil buffer for your app.  Your laptop is probably creating one by default and the desktop probably doesn't, thus the difference.    If you are using a derivative of BaseSimpleGame you can add something like this to the app constructor:



stencilBits = 4;



If you are creating the window yourself, add display.setMinStencilBits( stencilBits ); before you call createWindow.

Thank you so much! Since I was using a StandardGame (multi-threaded), it didn't seem to work no matter where I put display.setMinStencilBits(4) but I changed my code to use a FixedFramerateGame (much better anyway…).

I was having the same problem with StandardGame. The solution was to set the stencilBits BEFORE calling the start() method.  :slight_smile: