Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Kind of shadow casting.  (Read 315 times)
0 Members and 1 Guest are viewing this topic.
Offline marcuiulian13

Senior Member


Medals: 3



« Posted 2013-02-24 18:13:30 »

Hello everyone!

Here i am, working at a new project.
I need some advice about this:


Is there any way (like shaders) to achive this effect in libGDX? (the shadow having the same shape as a sprite that is casted at 45°)
The way i set up it in above picture is trivial: i draw the shadow in GIMP and then draw it before the sprite.

Thanks.

Check out my current project: http://cube3dev.blogspot.com/
Please comment/review/suggest.
Offline Jimmt
« Reply #1 - Posted 2013-02-24 18:19:27 »

Quick search turned this up: https://code.google.com/p/box2dlights/
JGO link on dynamic lighting resources: http://www.java-gaming.org/topics/2d-dynamic-lighting/27012/view.html
Offline marcuiulian13

Senior Member


Medals: 3



« Reply #2 - Posted 2013-02-24 18:26:27 »

I already searched and read about dynamic lighting, but this isn't what i want.
I want static lighting.

Check out my current project: http://cube3dev.blogspot.com/
Please comment/review/suggest.
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline davedes
« Reply #3 - Posted 2013-02-24 20:40:43 »

If you want static lighting, what is wrong with your current approach, painting the shadows in GIMP?

Offline marcuiulian13

Senior Member


Medals: 3



« Reply #4 - Posted 2013-02-24 21:15:43 »

I think that if i make the shadows by code, it will be easier to me to avoid things like this:

(notice the shadow rendered under the wall and intensifying the wall's shadow)

Also, it would be easier than drawing and positioning the shadow for every entity i make.

Check out my current project: http://cube3dev.blogspot.com/
Please comment/review/suggest.
Offline davedes
« Reply #5 - Posted 2013-02-24 22:44:07 »

What you are looking for is dynamic shadows.

To achieve dynamic shadows like that for arbitrary shapes (e.g. a tree), you would need 3D representations of your sprites modeled in Blender or Maya. Then you would render a depth pass from the light's perspective and use the technique here to cast shadows. The amount of work for such a simple feature would be astounding.

If you plan all of your sprites to be very primitive (e.g. boxes), then you can do something like what box2dlights does. This still requires pretty heavy math and probably won't be easy.

Another idea: don't blend shadows together. You could do this by rendering all your shadows to an offscreen buffer at 100% opacity, and then blending the shadows atop your scene at 50%. There might also be another way of achieving this without FBOs (for better Android performance).

Offline marcuiulian13

Senior Member


Medals: 3



« Reply #6 - Posted 2013-02-24 22:49:22 »

Oh, so my ideea of getting the sprite's image, distorting it (flip it vertically and skew (:-??) until it gets 45 degrees) and then making it only black + decreasing it's opacity (tehniques that i use in photoshop to do the shadow) isn't so good. Is it practical? Sad

Check out my current project: http://cube3dev.blogspot.com/
Please comment/review/suggest.
Offline davedes
« Reply #7 - Posted 2013-02-24 23:06:52 »

That will work if all of your sprites are box-shaped. For arbitrary shapes (e.g. tree branches, character's limbs, etc) it won't work accurately.

However, if you are OK with all of your shadows just being boxes, you could apply a transform matrix to your "shadow batch" and use Color.BLACK as your vertex color. You can remove overlapping shadows like I said with an FBO (or perhaps some other solution fit for Android). To "properly" remove the shadows (i.e. based on occluders), you need to get into more complex territory (true dynamic shadows).

Offline marcuiulian13

Senior Member


Medals: 3



« Reply #8 - Posted 2013-02-24 23:32:46 »

I understand. Thank you very much for help!  Grin

Check out my current project: http://cube3dev.blogspot.com/
Please comment/review/suggest.
Offline sproingie
« Reply #9 - Posted 2013-02-24 23:53:19 »

The basic non-shader trick for rendering planar shadows that you don't want to "stack" is to use the stencil buffer.  Something like this will do it:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
glDisable(GL_DEPTH_TEST);
drawBackground();
// Increment the stencil buffer on every draw, don't draw where it's already set.
glEnable(GL_STENCIL_TEST);
glStencilOp(GL_INCR, GL_INCR, GL_INCR);
glClearStencil(0);
glStencilFunc(GL_EQUAL, 0, 1);
glPushMatrix();
// shadowTransform is a simple scale+shear affine transform
glMultMatrix(shadowTransform);
// draw objects in the shadow color (no textures)    
drawObjectsWithShadows();
glPopMatrix();
glDisable(GL_STENCIL_TEST);
glEnable(GL_DEPTH_TEST);
// draw objects normally
drawAllObjects();



Pages: [1]
  ignore  |  Print  
 
 

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (76 views)
2013-05-17 21:29:12

alaslipknot (89 views)
2013-05-16 21:24:48

gouessej (119 views)
2013-05-16 00:53:38

gouessej (113 views)
2013-05-16 00:17:58

theagentd (125 views)
2013-05-15 15:01:13

theagentd (112 views)
2013-05-15 15:00:54

StreetDoggy (156 views)
2013-05-14 15:56:26

kutucuk (178 views)
2013-05-12 17:10:36

kutucuk (178 views)
2013-05-12 15:36:09

UnluckyDevil (186 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.132 seconds with 21 queries.