Sign in to follow this  
gchewood

Rendering models with transparent parts

Recommended Posts

gchewood    236

Bit of a weird problem that I feel I should know the answer to.

 

I have a number of models that have transparent areas (e.g torn cloth, hair). I'm rendering them all with the same shader in XNA. Some of them appear correctly, others don't: the transparent areas 'overwrite' the pixels beneath them (like when you don't sort the depths of models with transparency). But given that it is within the same model (all uses a single texture), I'm not sure how to solve it. Why do some models render correctly and others don't?

I'm guessing it's just an accident that those polys happen to be rendered in a bad order.

Thoughts and solutions?

 

Thanks a lot. 

Share this post


Link to post
Share on other sites
Ivan Ivanovski    194

For sure this happens because of bad render order.

 

Usually if I want to make a transparent part of a model, I add it to a different subset, i.e., with a different texture. I think in this way you won't have a problem. If you add the parts with alpha and the opaque parts in the same texture probably you will have to reorder the polys each time you draw depending on the view which I don't think is a good idea.

 

And as you already mentioned you should sort the objects with alpha by depth and always remember to render them after the objects which are opaque.

 

Hopefully this helps you.

 

BGH

Share this post


Link to post
Share on other sites
gchewood    236

Thanks for the quick reply BigGiantHead (nice name)

 

I was hoping to find a solution that wouldn't need different textures. You suggested that on the same texture you'd have to constantly reorder the polys each time but this doesn't seem to be necessary with those models that are already working. I assume that just means that on those models, the transparent parts are in a different ModelMeshPart that is rendered later than the others (are they grouped like that?) If that's the case, how do you arrange them so they're rendered in the correct order?

 

Worst case scenario I might just be lazy and model polys around the transparent edges. I'm fairly low poly so it'd be manageable.

Share this post


Link to post
Share on other sites
Ivan Ivanovski    194

Actually I don't know if it is even possible to order the polys with a reasonable computational overhead.

 

If you want to get good and robust results you render everything with alpha after the opaque models, and of course ordered by depth.

That's the way to be sure that your models are ordered in the right way. Even then. there might be some problems with particles for example, or with instanced objects.

 

I don't think you'll get good results if you render the whole model in one go. 

 

I'm curious, is it possible to see a screenshot from the model you are having problems with.

 

BGH

Share this post


Link to post
Share on other sites
gchewood    236

Well I've solved it. Not entirely sure what was going on but the behaviour of these transparent parts made had me speculating that there was just some simple material options that could fix it (and I was right).

I'm working in 3ds max. Separated the model into opaque and transparent models. Applied the same texture (in 2 dif instances) to each model and then recombined them. Problem solved, works fine.

I'm guessing this forced XNA to interpret the model as having 2 ModelMeshParts instead of 1?

Thanks for the input all the same!

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