Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
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 660 times)
0 Members and 1 Guest are viewing this topic.
Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« 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.

Getting a project done is by far the most hard thing in game development.
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 114
Projects: 4
Exp: 3 years



« 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: 5
Exp: 3 years



« 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.

Getting a project done is by far the most hard thing in game development.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
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: 5
Exp: 3 years



« 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.

Getting a project done is by far the most hard thing in game development.
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: 5
Exp: 3 years



« 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

Getting a project done is by far the most hard thing in game development.
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: 5
Exp: 3 years



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

I understand. Thank you very much for help!  Grin

Getting a project done is by far the most hard thing in game development.
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  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (24 views)
2014-04-15 18:08:23

BurntPizza (19 views)
2014-04-15 03:46:01

UprightPath (33 views)
2014-04-14 17:39:50

UprightPath (17 views)
2014-04-14 17:35:47

Porlus (33 views)
2014-04-14 15:48:38

tom_mai78101 (59 views)
2014-04-10 04:04:31

BurntPizza (117 views)
2014-04-08 23:06:04

tom_mai78101 (217 views)
2014-04-05 13:34:39

trollwarrior1 (184 views)
2014-04-04 12:06:45

CJLetsGame (191 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!