Infanite shadow volume-glsl


lightmaps, I make a texture out of what is projected on the static geomtry


i think you should read a paper on shadowmaps and one on stencilshadows...
the beauty of shadowmaps is that they are easy to do, since you _don't_ have to extrude any geometry at all, only render the scene from another view
the beauty of stencil shadows is that you _don't_ have to mess with multitexturing and tricky texturecoordinates, you only extrude geometry, and render a huge quad with the shadowcolor over the whole scene...

forget about it i found a site with tutorials on directional,point,and spot(all per-pixel) still looking for one on ambient.

In the world of computer shadows, shadow volumes are high level only problem is that they are hard shadows unless you do a cluster but thats no good.  I'm hoping to use the shadow volume way of doing shadows to create a soft shadow map or a cluster of shadow volumes during a compile stage and a soft shadow map texture for realtime rendering.  Is this possible?

if your result are going to be used in a shadowmap texture anyways, I would go with the shadowmap technique all the way…putting shadow values into the stencil buffer cost you a rendering of the object(+extrusion) for every part of the cluster(as well as a quad for shadow color)…a shadowmap is also one rendering, but without extrusion and all that, same thing can be done there, rendering from multiple views and creating a soft cluster(and you can do pixelshader postprocesses like blur on the map right away)…



also, I don't understand how you are going to get the stencilshadow into a shadowmap?

I need help with my code i wrote for jme.  I used the depth fail method because of camera reasons and because if I'm extruding existing geometry it's already capped.  I didn't didn't create extra vertex's I just wanted to see it work regardless oh how it looks.  Right now it draw just a black screen.  I went over the code word for word 3 times and don't see what is wrong so I'll probably never see it.  On to jme-jogl only have to convert render texture and I guess input since nobody else offered to help.


import com.jme.app.*;
import com.jme.scene.*;
import com.jme.scene.state.*;
import com.jme.scene.shape.*;
import com.jme.math.*;
import com.jme.light.*;
import com.jmex.model.XMLparser.Converters.*;
import com.jmex.model.XMLparser.*;
import com.jme.renderer.*;
import java.io.*;
import java.net.*;
import java.nio.*;
import org.lwjgl.opengl.GL11;
public class ISV extends SimpleGame
{
   CullState cs;
   StencilState ss;
   GLSLShaderObjectsState so;
   ZBufferState zs;
   public static void main(String args[])
   {
      ISV app = new ISV();
        app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
        app.start();
   }
   protected void simpleInitGame()
   {
      GL11.glPushAttrib(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT
      | GL11.GL_POLYGON_BIT | GL11.GL_STENCIL_BUFFER_BIT);
      lightState.setEnabled(false);
      rootNode.setRenderState(lightState);
      Box b = new Box("Box",new Vector3f(0,0,0),new Vector3f(10,10,10));
      Node box = new Node("box");
      box.attachChild(b);
      Node model = new Node("kight");
      model.attachChild(loadModelMilk("Knight.ms3d"));
      rootNode.attachChild(model);
      rootNode.attachChild(box);
      display.getRenderer().draw(rootNode);
      enableLight();
      GL11.glPushAttrib(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT |
      GL11.GL_POLYGON_BIT | GL11.GL_STENCIL_BUFFER_BIT);
       shadowInit();
       passOne();
      drawShadowVolume();
      display.getRenderer().draw(rootNode);
      passTwo();
      display.getRenderer().draw(rootNode);
      so.setEnabled(false);
      finalPass();
      display.getRenderer().draw(rootNode);
      GL11.glPopAttrib();      
   }
   private void enableLight()
   {
      PointLight light = new PointLight();
        light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
       light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
       light.setLocation(new Vector3f(100, 100, 100));
       light.setEnabled(true);
       lightState.setEnabled(true);
       lightState.attach(light);
       rootNode.setRenderState(lightState);
   }
   private Node loadModelMilk(String fn)
   {
      URL urlfn=test.class.getClassLoader().getResource(fn);
      FormatConverter converter=new MilkToJme();
       ByteArrayOutputStream BO=new ByteArrayOutputStream();
        JmeBinaryReader jbr=new JmeBinaryReader();
        BinaryToXML btx=new BinaryToXML();
        try {
       converter.convert(urlfn.openStream(), BO);
       btx.sendBinarytoXML(
       new ByteArrayInputStream(BO.toByteArray()),
       new OutputStreamWriter(System.out));
       Node model=jbr.loadBinaryFormat(
       new ByteArrayInputStream(BO.toByteArray()));
       return model;
         }
      catch (IOException e) { // Just in case anything happens
           System.out.println("Damn exceptions!" + e);
           e.printStackTrace();
           System.exit(0);}
      return null;
      
   }
   //init disables color and z buffer writing
   private void shadowInit()
   {
      GL11.glColorMask(false,false,false,false);
      GL11.glDepthMask(false);      
   }
   //passOne sets stencil to 0 and increases on Z fail of back faces
   private void passOne()
   {
      ss = display.getRenderer().createStencilState();
      cs =display.getRenderer().createCullState();
      ss.setStencilFunc(ss.SF_ALWAYS);
      ss.setStencilRef(0);
      ss.setStencilMask(~0);
      ss.setStencilOpFail(ss.SO_KEEP);
      ss.setStencilOpZPass(ss.SO_KEEP);
      ss.setStencilOpZFail(ss.SO_INCR);
      cs.setCullMode(cs.CS_FRONT);
      ss.setEnabled(true);
      cs.setEnabled(true);
      rootNode.setRenderState(ss);
      rootNode.setRenderState(cs);
   }
   //passTwo decreases on ZFail of front faces
   public void passTwo()
   {
      cs =display.getRenderer().createCullState();
      ss = display.getRenderer().createStencilState();
      ss.setStencilOpFail(ss.SO_KEEP);
      ss.setStencilOpZPass(ss.SO_KEEP);
      ss.setStencilOpZFail(ss.SO_DECR);
      cs.setCullMode(cs.CS_BACK);
      ss.setEnabled(true);
      cs.setEnabled(true);
      rootNode.setRenderState(ss);
      rootNode.setRenderState(cs);
   }
   //shader the extrudes back faces and takes care of lighting
   public void drawShadowVolume()
   {
      URL vertProg = test.class.getClassLoader().getResource("vp0.vert");
         URL fragProg = test.class.getClassLoader().getResource("fp0.frag");
      so = display.getRenderer().createGLSLShaderObjectsState();
        if (!so.isSupported()) {display.close();System.exit(0);}
       so.load(vertProg,fragProg);
       rootNode.setRenderState(so);
   }
   //updates only where stencil value is 0
   public void finalPass()
   {
      zs=display.getRenderer().createZBufferState();
      ss = display.getRenderer().createStencilState();
      zs.setFunction(zs.CF_EQUAL);
      ss.setStencilFunc(ss.SF_EQUAL);
      ss.setStencilMask(~0);
      ss.setStencilRef(0);
      ss.setStencilOpFail(ss.SO_KEEP);
      ss.setStencilOpZPass(ss.SO_KEEP);
      ss.setStencilOpZFail(ss.SO_KEEP);
      ss.setEnabled(true);
      cs.setEnabled(true);
      rootNode.setRenderState(zs);
      rootNode.setRenderState(ss);
            
   }   
}


let down again by forum support for anybody that digs this up if you dig this up I got a weird problem it might help you first the picture



it made the model transparent and you can’t tell but I am getting 500 fps  I don’t know if this really counts it is doing all the calculations per frame just not displaying showing a shadow at all and can put anything in for kight.ms3d i got it from the nvidia infinate shadow volume thingy.

the code only changes being in final pass i made the Z buffer state update on greater or equal to and disabled all the states after final render.  You also might notice I use bits of lwjgl code here and there and that is just for ease and I don’t know the jme equivalent.  Also I didn’t split outlining verts 1 because i couldn’t get the leaf node of the model

                    2 I wanted to see it work

Code that I got the transparent model with

import com.jme.app.*;
import com.jme.scene.*;
import com.jme.scene.state.*;
import com.jme.scene.shape.*;
import com.jme.math.*;
import com.jme.light.*;
import com.jmex.model.XMLparser.Converters.*;
import com.jmex.model.XMLparser.*;
import com.jme.renderer.*;
import java.io.*;
import java.net.*;
import java.nio.*;
import org.lwjgl.opengl.GL11;
public class ISV extends SimpleGame
{
   CullState cs;
   StencilState ss;
   GLSLShaderObjectsState so;
   ZBufferState zs;
   public static void main(String args[])
   {
      ISV app = new ISV();
        app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
        app.start();
   }
   protected void simpleInitGame()
   {
      Box b = new Box("Box",new Vector3f(-50,-50,-10),new Vector3f(100,100,0));
      Node box = new Node("box");
      box.attachChild(b);
      
      Node model = new Node("kight");
      model.attachChild(loadModelMilk("Knight.ms3d"));
      
      
      GL11.glPushAttrib(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT
      | GL11.GL_POLYGON_BIT | GL11.GL_STENCIL_BUFFER_BIT);
      
      lightState.setEnabled(false);
      rootNode.attachChild(model);
      rootNode.attachChild(box);      
      display.getRenderer().draw(rootNode);
      
      GL11.glPushAttrib(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT |
      
      GL11.GL_POLYGON_BIT | GL11.GL_STENCIL_BUFFER_BIT);
      
      lightState.setEnabled(true);
      
       shadowInit();
      
       passOne();
      
      drawShadowVolume();
      
      display.getRenderer().draw(rootNode);
      
      passTwo();
      
      so.setEnabled(false);
      
      display.getRenderer().draw(rootNode);
      
      finalPass();
      
      display.getRenderer().draw(rootNode);
      cs.setEnabled(false);ss.setEnabled(false);so.setEnabled(false);zs.setEnabled(false);
      
      GL11.glPopAttrib();      
   }

   private void enableLight()
   {
      PointLight light = new PointLight();
        light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
       light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
       light.setLocation(new Vector3f(100, 100, 100));
       light.setEnabled(true);
       lightState.setEnabled(true);
       lightState.attach(light);
       rootNode.setRenderState(lightState);
   }
   private Node loadModelMilk(String fn)
   {
      URL urlfn=test.class.getClassLoader().getResource(fn);
      FormatConverter converter=new MilkToJme();
       ByteArrayOutputStream BO=new ByteArrayOutputStream();
        JmeBinaryReader jbr=new JmeBinaryReader();
        BinaryToXML btx=new BinaryToXML();
        try {
       converter.convert(urlfn.openStream(), BO);
       btx.sendBinarytoXML(
       new ByteArrayInputStream(BO.toByteArray()),
       new OutputStreamWriter(System.out));
       Node model=jbr.loadBinaryFormat(
       new ByteArrayInputStream(BO.toByteArray()));
       return model;
         }
      catch (IOException e) { // Just in case anything happens
           System.out.println("Damn exceptions!" + e);
           e.printStackTrace();
           System.exit(0);}
      return null;
      
   }
   //init disables color and z buffer writing
   private void shadowInit()
   {
      zs=display.getRenderer().createZBufferState();
      GL11.glColorMask(true,true,true,true);
      zs.setWritable(true);
      zs.setEnabled(true);
      rootNode.setRenderState(zs);      
   }
   //passOne sets stencil to 0 and increases on Z fail of back faces
   private void passOne()
   {
      ss = display.getRenderer().createStencilState();
      cs =display.getRenderer().createCullState();
      ss.setStencilFunc(ss.SF_ALWAYS);
      ss.setStencilRef(0);
      ss.setStencilMask(~0);
      ss.setStencilOpFail(ss.SO_KEEP);
      ss.setStencilOpZPass(ss.SO_KEEP);
      ss.setStencilOpZFail(ss.SO_INCR);
      cs.setCullMode(cs.CS_FRONT);
      ss.setEnabled(true);
      cs.setEnabled(true);
      rootNode.setRenderState(ss);
      rootNode.setRenderState(cs);
   }
   //passTwo decreases on ZFail of front faces
   public void passTwo()
   {
      cs = display.getRenderer().createCullState();
      ss = display.getRenderer().createStencilState();
      
      so.setEnabled(false);
   
      ss.setStencilOpFail(ss.SO_KEEP);
      ss.setStencilOpZPass(ss.SO_KEEP);
      ss.setStencilOpZFail(ss.SO_DECR);
      
      cs.setCullMode(cs.CS_BACK);
      
      ss.setEnabled(true);
      cs.setEnabled(true);
      
      rootNode.setRenderState(ss);
      rootNode.setRenderState(cs);
      rootNode.setRenderState(so);
   }
   //shader the extrudes back faces and takes care of lighting
   public void drawShadowVolume()
   {
      URL vertProg = test.class.getClassLoader().getResource("vp0.vert");
         URL fragProg = test.class.getClassLoader().getResource("fp0.frag");
      so = display.getRenderer().createGLSLShaderObjectsState();
        if (!so.isSupported()) {display.close();System.exit(0);}
       so.load(vertProg,fragProg);
       rootNode.setRenderState(so);
   }
   //updates only where stencil value is 0
   public void finalPass()
   {
      zs=display.getRenderer().createZBufferState();
      ss = display.getRenderer().createStencilState();
      zs.setFunction(zs.CF_LEQUAL);
      ss.setStencilFunc(ss.SF_GEQUAL);
      ss.setStencilMask(~0);
      ss.setStencilRef(0);
      ss.setStencilOpFail(ss.SO_KEEP);
      ss.setStencilOpZPass(ss.SO_KEEP);
      ss.setStencilOpZFail(ss.SO_KEEP);
      ss.setEnabled(true);
      zs.setEnabled(true);
      rootNode.setRenderState(zs);
      rootNode.setRenderState(ss);
            
   }   
}

wakeboardin said:

let down again by forum support


???

If you post huge amounts of code then tell people to debug it for you, don't expect to get a whole lot of help, no matter what forum you are on. Quickest way to help is to ask succinct questions about a specific problem.

sorry there really isn't any question for me to ask I looked at like 20 algorithums and followed them all to the point.  Guess it's just a failed project