• Advertisement
  • entries
    232
  • comments
    1463
  • views
    959861

Shadow mapping & misc. work

Sign in to follow this  

425 views

In the past days, i've implemented a nice little feature: automatic reloading of texture maps. The engine uses a texture manager, which checks every N seconds (currently, N=1) if a file image has changed ( i compare the size and the last modification date ). If this is the case, the texture is automatically reloaded on-the-fly. It's funny to load the viewer, open photoshop, modify a texture, and when alt-tabing back to the running viewer, see the changes take place without having to reload the viewer.

This week end, i started to work on dynamic shadow maps for the station. It's been really exhausting. I found two nice bugs:

- shadow mapping involves a texture projection from light space to world space. When applying the transformation to a vertex in world coordinates, i forgot to divide the projection result by the w component. The x,y and z components were invalid, and i didn't understand why, until.. too late.

- the second bug was a typo in the code. I applied a transpose() operation to a matrix, thinking it would act as selfTranspose(). In the first case, the matrix is untouched and the function results the transposed matrix, while in the second case, the matrix is erased by its transposed part.

Now, shadow mapping is more or less working. The results aren't very good yet, i'm afraid.. lots of artifacts everywhere. I still have to tweak them and to match the light frustum to the object frustum ( at the moment some resolution is lost in the shadow maps ). Each object ( the station is composed of 7 objects ) gets its own 1024^2 shadow map. It's funny to move the light in circles around the station, and see the shadows running around.


Sign in to follow this  


16 Comments


Recommended Comments

Sounds terribly complex @.@

Keep up the great work though, Your prior journal entries have amazed me with the amount of detail your putting into every crevice of the game.

-Dave

Share this comment


Link to comment
Is it only the station that gets shadows, or do ships flying around it get shadowed as well? Regardless of that fact though, it looks pretty good. Are you going to be doing shadows from planets as well (e.g. interplanetary shadows between the ringed planet and its moon)?

Share this comment


Link to comment
ffx: the idea is the same than for MT, but the implementation is different (it's no longer a "hack", it's integrated into the engine. Namely, i now have a Shadow Map Pipe).

Cypher19: everything gets shadowed. The engine determines for every object, every light and every frame, what are the objects potentially occluding the light. If a light has moved, or the object set has changed or been dirtied (one object moved), the shadow map is flagged as "updatable".

Yeah i'm going to do planetary shadows, but these will be handled differently (probably with a projected lightmap).

Share this comment


Link to comment
Quote:
The engine uses a texture manager, which checks every N seconds (currently, N=1) if a file image has changed ( i compare the size and the last modification date ).

A better, albeit Win32 only, method would be to use ReadDirectoryChangesW. Check this nifty wrapper.

Share this comment


Link to comment
Did you consider using stencil shadows or is it infeasible for some reason?

The reason why I ask is that shadows in space are usually very hard since the sun is quite a point-light and there is no scattering distributing the light. Stencil shadows are always nicely sharp, even if you zoom in very closely. I doubt that shadow maps do a very good job here since the scales of a space station are still very different.

Share this comment


Link to comment
Quote:
A better, albeit Win32 only, method would be to use ReadDirectoryChangesW. Check this nifty wrapper.


Looks nice, maybe a bit overkill for what i do, but thanks for the link.

Quote:
Did you consider using stencil shadows or is it infeasible for some reason?


Well, stencil shadows have their own issues. For once, they consume a lot of fill-rate. Also they don't scale up very well with the polycount, and my stations/ships will be pretty high poly. They require all the objects to be closed and 2-manifold. However, if i can't find a shadow map technique good enough to fix my quality problems, i'll likely switch to stencil shadows.

Share this comment


Link to comment
Guest Anonymous Poster

Posted

7 1024x1024 depth textures consume a lot of fill rate too :)

I would put money on shadow volumes running a few X faster in this scenario with better results.

Share this comment


Link to comment
Why don't you just use a global shadow map? Because if you use a shadowmap/object then I imagine you'll have to render the whole scene for each object shadow map, right? Because otherwise some other objects will get in the way (sun, object, target object).
And what will you do when you will have like 100 ships near a space station?

Share this comment


Link to comment
AP: you're forgetting that i do not have to update the shadow maps each frame. The only per-frame cost i have is, per-object, to sample a single 1024x1024 texture. That's orders of magnitudes faster than rendering fillrate-intensive shadow volumes for a high-poly scene, and i'm not even speaking of the CPU processing required to process all the silhouettes.

Raduprv: I did not use a global shadow map, because with standard shadow maps, given the size of the frustums i have, i'd get an horrible resolution. This per-object shadow map method allows me to do two optimizations:

1. The shadow map resolution can be dependant of the camera distance (ie. i'll reduce the resolution for objects that are far away).

2. I do not have to render the whole scene, but only the part of the scene that is intersecting the object "looking at the light" frustum.

Share this comment


Link to comment
Just a random thought. Is your station visitable, that is, can you board on it and walk around in RPG or FPS style?

Share this comment


Link to comment
Some inside huge rooms/tunnels will be modeled, but only to allow ships to dock. No FPS view.

Share this comment


Link to comment
Ok, so say you have this set up:

O o o o o o o o S
(O is the Sun, o are small objects such as ships, asteroids, etc. and the S is the station, all of them being colinear with the sun and with eachother). Then for the space stations you will need to render 7 objects+ the station objects (4?). Then for the closest object to the station you'd need to render 7 objects, for the next oen 6, and so on. Right?

Share this comment


Link to comment
Yes, that's right. Of course there's only so many objects that can be occluding the sun, since it's a space game, even the biggest ships become "invisible" after a couple thousand kilometers (from the station's point of view).

Share this comment


Link to comment
I see now.
BTW, do you plan to have smaller shadow maps, such as 256x256 for smaller objects like small ships and asteroids? Or all of them will be 1024x1024?

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement