Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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  
  Drawing Order for correct Transparency - Alternatives? (and related stuff)  (Read 1720 times)
0 Members and 1 Guest are viewing this topic.
Offline RongoMatane

Junior Newbie

« Posted 2012-10-03 10:16:31 »

i am programming an isometric game with a 3D map and objects on it that are 2D Sprites. These sprites also contain the shadow of the object, als partly transparent black area. I finally stumbled upon the problem of transparent regions blocking the view to objects behind them. I guess you are familiar with the problem, but i can give some screenshots if needed.
As i read one can solve this problem by drawing the objects in the right order. I don't really like this idea because avoiding this was half the reason to use 3D maps instead of pure 2D. So i wonder if there are alternatives to this. I enumerate some things i thought about and would really appreciate some feedback on this.

1. One thing i thought about was drawing the objects without any shadowing and after that draw all the shadows. For this i'd need seperate Shadow Textures and would basically need to draw twice as many sprites. Is this in general a bad idea?

2. One issue that comes with the 2D sprites is that i can't really create shadows and correct lighting on the object, for example in a days cycle. If i'd seperate the shadows, i could for example create 24 different shadowmaps for each hour, for each object, what sounds like a lot of effort. Does anyone have expereince with this, or knows any other methods to cast (good) shadows from 2D objects?

3. The lighting on the sprite itself should also change - a wall could be directly hit by light in the morning and be bright, and could be hidden from the sun in the noon and be dark. I thought about using another texture that basically encodes the normals of the surface of the object in color. With this i could directly calculate the brightness of the different parts of the object with a shader and render it correctly. Did anyone try this? Would this even work? Cheesy

These questions aim at unanimated objects, like buildings. I also have animated objects, but i think i could live with worse lighting there, also because it sounds like a ton of work to create all shadows for all hours for all animations (or "normalmaps").

It would be awesome to get some feedback and opinions, hints or links.


Offline theagentd
« Reply #1 - Posted 2012-10-04 00:24:26 »

1. That's a good idea. How would you do it otherwise anyway? Look at this:

2. I did this once. I basically rendered a normal sprite colored black on the ground away from the shadow caster. I just picked from the 4 directions available, which did indeed cause a rather ugly change pop when at all four 45 degree angles when I changed the direction, but overall it looked great and was relatively easy to implement. With only 8 directions of shadow sprites and some smart blending between them it'll look great. 3D textures can be used to easily achieve that.

3. This is the trickiest part. Normal mapping is awesome and gives an incredible amount of depth, but I never had the skills/resources to try it out myself, but it'll surely look incredible. Note that normal maps have nothing to do with shadows, it's just how lighting interacts with the sprite surface. For static objects and static lights you can precompute shadows using some slow ray casting or so. For dynamic objects/lights you could either do some ray casts, which is pretty cheap since you only have to do it for the x axis since it's 2D meaning that it's only 8 or so per sprite. It's hard to make sprites cast shadows on other sprites though for the same reason, since the actual 3D information isn't there...

Offline RongoMatane

Junior Newbie

« Reply #2 - Posted 2012-10-04 08:11:42 »

Awesome, thanks for your answer.
Then i think i'll go for seperate shadows with the option to expand it later into a 3D Texture and simulating the day cycle. The other option would have been to put the shadow and the image into one texture, not being able to simulate lighting and needing to draw in the correct order.

The ray casting won't wirk this way because i'm not really 2D. At the moment i don't have sprites for all 4 directions if you can rotate with 90° (which i can't right now) and i'm not sure if i'll even implement this. Otherwise i maybe could use the different rotated sprites to cast shadows.

I post some screenshots to make it more clear:
Normal look:

If i fly around in 3D, it's visible that the objects are only 2D:

And there can be heights:
The heights further complicate the problem, if i'd want to make really good shadows. I guess i couldn't avoid shadow volumes or shadow mapping then.
Pages: [1]
  ignore  |  Print  

EgonOlsen (79 views)
2018-06-10 19:43:48

EgonOlsen (59 views)
2018-06-10 19:43:44

EgonOlsen (78 views)
2018-06-10 19:43:20

DesertCoockie (261 views)
2018-05-13 18:23:11

nelsongames (159 views)
2018-04-24 18:15:36

nelsongames (158 views)
2018-04-24 18:14:32

ivj94 (901 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (813 views)
2018-03-24 14:43:53

Solater (177 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!