Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (707)
Games in Android Showcase (208)
games submitted by our members
Games in WIP (781)
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 1488 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

« JGO Bitwise Duke »

Medals: 920
Projects: 4
Exp: 8 years

« 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  
You cannot reply to this message, because it is very, very old.

Galdo (480 views)
2017-01-12 13:44:09

Archive (634 views)
2017-01-02 05:31:41

0AndrewShepherd0 (1105 views)
2016-12-16 03:58:39

0AndrewShepherd0 (1031 views)
2016-12-15 21:50:57

Lunch (1160 views)
2016-12-06 16:01:40

ral0r2 (1394 views)
2016-11-23 16:08:26

ClaasJG (1490 views)
2016-11-10 17:36:32

CoffeeChemist (1462 views)
2016-11-05 00:46:53

jay4842 (1544 views)
2016-11-01 19:04:52

theagentd (1261 views)
2016-10-24 17:51:53
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 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!