Sign in to follow this  
DJTN

Depth Sorting Issue DirectX

Recommended Posts

I’ve implemented object based depth sorting for objects with transparent materials. When running through my render list, if a material is flagged with transparency I set that object aside to be sorted and rendered with other transparent objects. I occasionally have some overlapping issues with some objects that always face the camera but nothing major. However, if an object is transparent, say for example a simple building with windows and a particle fire or smoke is inside the building, the fire and smoke doesn’t get rendered.

In my situation I do not have access to the artist- asking them to separate the transparent mesh (windows) as its own model. Do I have any other options?

Share this post


Link to post
Share on other sites
Well if you have a building that's part opaque brick and part transparent windows, then you're already going to be drawing those as two different draw calls because they're different materials and different blending modes. So typically you want to bin opaques/transparents at the the draw call level rather than at the object/mesh level, and then you can sort the transparent draw calls amongst themselves.

Share this post


Link to post
Share on other sites
[quote name='MJP' timestamp='1310873700' post='4836241']
Well if you have a building that's part opaque brick and part transparent windows, then you're already going to be drawing those as two different draw calls because they're different materials and different blending modes. So typically you want to bin opaques/transparents at the the draw call level rather than at the object/mesh level, and then you can sort the transparent draw calls amongst themselves.
[/quote]


Thanks MJP, my problem is that I sort based off depth- DOT product (distance from camera using view matrix and object position). So when the fire in the building moves from the camera -past the Z Vec in the object position (center of mesh object), it disappears. My rendering is done per subset so I could essentially move from object based depth sorting to subset depth sorting but how could I get the position of a subset in a mesh economically?


Another example would be a cubed like shaped shack. The walls are one texture that is transparent between the wood boards. This texture is duplicated for 3 walls as one subset. Any other transparent object or particle moving inside the mesh will have the same issue of disappearing after passing the objects depth position.

Hope this makes sense...


Share this post


Link to post
Share on other sites
Wow, what a nightmare this has turned into. To get the position of a subset I had to get the attribute table, load it up. Then I had to load up the index buffer and the vertex buffer. Using the attribute table for each face and each subset, I get the corresponding item in the index buffer for that face, which points me to the vertices in the vertex buffer. I collect them then I omit the duplicates for each subset, and then average the vertices into one for that subsets position.

I’ve still got a ways to go. I need to move my depth sorting algorithm to my subset render level and out of my object draw level. Then I have to figure out how I’m going to get my subsets model space vector for its position into world space so that I can measure depth, then sort. Let alone I haven’t figured out how all this will impact my forward light rendering where I do multiple passes for each light. It has an alpha blend already. (Crosses fingers)

Something as simple as handling transparency is ridiculously difficult to implement. The Z-Buffer and Vertex Buffer should allow me to tag vertices or subsets with a transparent flag in the vertex format. It’s capable of doing alpha test, how difficult would it be to build upon that concept for other transparency situations. Transparency is key to keeping poly counts down for real time rendering with a decent frame rate.

If anyone knows how to convert a vector from model space to world space it would be much appreciated.

Cheers,
Dj


Share this post


Link to post
Share on other sites
[quote name='DJTN' timestamp='1311013717' post='4836933']
Wow, what a nightmare this has turned into. To get the position of a subset I had to get the attribute table, load it up. Then I had to load up the index buffer and the vertex buffer. Using the attribute table for each face and each subset, I get the corresponding item in the index buffer for that face, which points me to the vertices in the vertex buffer. I collect them then I omit the duplicates for each subset, and then average the vertices into one for that subsets position.

I’ve still got a ways to go. I need to move my depth sorting algorithm to my subset render level and out of my object draw level. Then I have to figure out how I’m going to get my subsets model space vector for its position into world space so that I can measure depth, then sort. Let alone I haven’t figured out how all this will impact my forward light rendering where I do multiple passes for each light. It has an alpha blend already. (Crosses fingers)

Something as simple as handling transparency is ridiculously difficult to implement. The Z-Buffer and Vertex Buffer should allow me to tag vertices or subsets with a transparent flag in the vertex format. It’s capable of doing alpha test, how difficult would it be to build upon that concept for other transparency situations. Transparency is key to keeping poly counts down for real time rendering with a decent frame rate.

If anyone knows how to convert a vector from model space to world space it would be much appreciated.

Cheers,
Dj



[/quote]

Just transform the subset's position by the world matrix for the mesh it belongs to, and it will be in world space.

Transparency is very tricky since it's order dependent. Sorting can only take you so far, and there will always be cases where it completely fails or where it takes a lot of special-case handling to get the right result. Most games just sort as best they can with a few manual tweaks/overrides from the artists, and then live with the artifacts. True order-independent transparency is possible, but is generally too expensive to be practical for most games. However it's definitely an active area of research, and the situation should hopefully improve in the future. Recently there's been some interesting techniques making use of new DX11 features, which is pretty exciting.

Share this post


Link to post
Share on other sites
Thanks MJP, I'm almost home with this but I'm having an issue with the position of the subset in my depth test. Is there a better way of calculating the position? Right now I'm averaging the vertices into one vector3 and transforming the vector with its parent mesh's world matrix. Is there a better way? I realize it's always going to be a rough estimate but I've got subsets popping in and out when they shouldn't be.

Share this post


Link to post
Share on other sites

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

Sign in to follow this