ProximityShadowPass

I’ve been working on a weird kind of AO-like shadow volume thing. Every object in the pass casts shadows on each other if they are close to each other.



A shadow volume is created for every object, by creating a clone and extruding it. Then shadows are created in kind of the same way as in ShadowRenderPass.



The shadows are then blurred with a modified variant of the bloom_blur shader that takes into account the z-buffer. The shadows are rendered on top of the scene with a fullscreen Quad with some transparency.



“Enjoy”:



http://www.lundstedt.biz/pmwiki/pmwiki.php?n=PmWiki.ProximityShadowPass

:-o looks cool. and a realy cool idea



Should the blurring also works for the normal stencil shadows?

wow rik dude… you have some cool stuff on your page. I had seen the first person builder… but i think you have not shown us your MorphableAnimatedModel yet… I must say it is even more interesting for me than the shadow pass :slight_smile:



Would it be possible to see it work on an animated model? Like a walk animation with the same model as a short/tall character? There have been numerous questions on this board on how to achieve something like what you have done, in the past. I am sure many people would like to pick your brain on how you did it…

.:emp...hellg:. said:

Should the blurring also works for the normal stencil shadows?


I'm afraid not, only if you make some changes to ShadowRenderPass. You would have to use a fullScreenQuad instead of the stencilBuffer, and render it on top of the scene.
Mindgamer said:

Would it be possible to see it work on an animated model?


Yes. Actually the character in the video is animated. If you look closely you will se that he is still jojoing while being melted.

BTW, Here is the src for the shadow pass:

http://www.lundstedt.biz/src/ProximityShadowPass.rar
Mindgamer said:

Would it be possible to see it work on an animated model?


I just realized that maybe I misunderstood and you might have meant this question for the shadow pass.

For the shadow pass, the answer is yes, but it would slow down incredibly, the way it is now, I would have to recreate every shadow volume every frame.

But it could be solved by doing something like this: While creating the shadow volume, associate each vertex to the correct bone or vertex in the model, and update them every frame. The shadow volume should have a flag deciding wether it is subject for update to filter out unnecessary updating.

Thank you for this explanation. I actually did mean the morphableAnimatedModel after all… btw do you plan to share that source also? 

I was trying to run MorphableAnimatedModel yesterday but I couldn't get it to work. I must have messed it up somehow.



I'll try to fix it and then post the source here.

Rik said:

Mindgamer said:

Would it be possible to see it work on an animated model?


Yes. Actually the character in the video is animated. If you look closely you will se that he is still jojoing while being melted.

BTW, Here is the src for the shadow pass:

http://www.lundstedt.biz/src/ProximityShadowPass.rar


Thanks for sharing under the BSD! Sounds quite interesting and fun. I bet it may be quite fast. I guess quad texture shadows cannot be solved with this as it is using volume stencil.

PS: The music on your page is cool!

wow, looks great.

i suggest it as a feature for jme2 if you are willing to contribute it…

Hi



I tried you posted code and it doesn't work on my machine. It constantly throws this exception:



java.lang.IllegalArgumentException: IntBuffer is not direct

at org.lwjgl.BufferChecks.checkDirect(BufferChecks.java:110)

at org.lwjgl.opengl.GL11.glDrawElements(GL11.java:1074)

at com.jme.renderer.lwjgl.LWJGLRenderer.draw(LWJGLRenderer.java:1010)

at com.jme.scene.TriMesh.draw(TriMesh.java:240)

at com.jme.scene.Spatial.onDrajava.lang.IllegalArgumentException: IntBuffer is not direct

at org.lwjgl.BufferChecks.checkDirect(BufferChecks.java:110)

at org.lwjgl.opengl.GL11.glDrawElements(GL11.java:1074)

at com.jme.renderer.lwjgl.LWJGLRenderer.draw(LWJGLRenderer.java:1010)

at com.jme.scene.TriMesh.draw(TriMesh.java:240)

at com.jme.scene.Spatial.onDraw(Spatial.java:475)

at com.jme.renderer.lwjgl.LWJGLTextureRenderer.doDraw(LWJGLTextureRenderer.java:1158)

at com.jme.renderer.lwjgl.LWJGLTextureRenderer.render(LWJGLTextureRenderer.java:651)

at rik.jme.pass.ProximityShadowPass.doRender(ProximityShadowPass.java:300)

at com.jme.renderer.pass.Pass.renderPass(Pass.java:96)

at com.jme.renderer.pass.BasicPassManager.renderPasses(BasicPassManager.java:90)

at com.jme.app.SimplePassGame.render(SimplePassGame.java:83)

at com.jme.app.BaseGame.start(BaseGame.java:87)

at rik.test.TestProximityShadowPass.main(TestProximityShadowPass.java:37)w(Spatial.java:475)

at com.jme.renderer.lwjgl.LWJGLTextureRenderer.doDraw(LWJGLTextureRenderer.java:1158)

at com.jme.renderer.lwjgl.LWJGLTextureRenderer.render(LWJGLTextureRenderer.java:651)

at rik.jme.pass.ProximityShadowPass.doRender(ProximityShadowPass.java:300)

at com.jme.renderer.pass.Pass.renderPass(Pass.java:96)

at com.jme.renderer.pass.BasicPassManager.renderPasses(BasicPassManager.java:90)

at com.jme.app.SimplePassGame.render(SimplePassGame.java:83)

at com.jme.app.BaseGame.start(BaseGame.java:87)

at rik.test.TestProximityShadowPass.main(TestProximityShadowPass.java:37)



but it never crashes (of course it does not draw shadows and is terribly slow because of the fast coming exceptions). Why does it fail? How can it be fixed?

I'm using the latest jme2-repository version.

By useing a direct buffer… as the exception tells us.

Empire Phoenix said:

By useing a direct buffer.... as the exception tells us.


Stating the obvious doesn't help much :)
I have no idea what a direct buffer is nor where to fix this. What buffer is this exception talking about? Maybe a jme developer can help.

Well google say, a direct buffer is one, that is not in heap space, but in osstack, so lwjgl can directly point to its adress instead of copying the data over to the gldriver.



On the point where the buffer is created probably a wrong Constructor/Factory is used.



Creat a direct bytebuffer with 4times the bytes than the intbuffer, and wrap it with a intbuffer, then you have a direct intbuffer.



hope this helps you tracking the source of the error-

I don't know if you see this, but I'm not the one that created this code :wink:

I tried to create a direct IntBuffer like this: (added in line 34 in ShadowVolumeMesh)



      IntBuffer sourceIntBuffer = source.getIndexBuffer();
      int length = sourceIntBuffer.capacity();
      ByteBuffer bb = ByteBuffer.allocateDirect(4 * length);
      for(int i = 0; i < length; i++) {
         bb.putInt(sourceIntBuffer.get(i));
      }
      IntBuffer buffer = bb.asIntBuffer();



Here I still get the same exception. If I write "bb.putInt(i, sourceIntBuffer.get(i));", I'll get an java.lang.ArrayIndexOutOfBoundsException later.
Am I on the right track, or must I build the direct IntBuffer in another way?

Try the isDirect method to test if it really is direct

Empire Phoenix said:

Try the isDirect method to test if it really is direct


And what shall I do if it's not? *g* That's the question!

You gotta find where an indirect buffer is created… I actually looked over the code and couldn't find it.