Jump to content
  • Advertisement
Sign in to follow this  
s_akhtar

Separating alpha polygons from an obj file

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I want to render a model. The model information is coming from an obj file, exported from Maya. Now the model can contain some opaque polygons & some alpha polygons. As you ppl must be aware that the alpha polygons should be rendered after the opaque ones & that too in back to front sorted order, to aviod the z-buffer problems. Now my problem is that both the alpha & opaque polygons r lying mixed in the obj file. How can i separate them, to be rendered in the correct order? One vague possible way is to preprocess the obj file by rendering each polygon separately & checking for its alpha component. In this way we can form two separations, one for alpha polygons & the other one for opaque polygons... but i dont know how to implement this. Any One with Any Bright Ideas?

Share this post


Link to post
Share on other sites
Advertisement
I don't know maya file format, but since there is the front to back rendering and transparency setting, i suppose that the file format flags this kind of special polygons and triangles, so you should check for this flag and filter the model mesh accordingly.

Share this post


Link to post
Share on other sites
No unfortunately to the best of my information, obj file format doesn't support a flag for the alpha polygons :(

Share this post


Link to post
Share on other sites
You said you know what kind of polygon you have, by the time you render the polygons...
Why don't you iterate through the list of polygons right after you loaded the model. Check each polygon for transparency and if it is push it into another array, where only transparent polygons are stored. Make also sure to erase the polygon from the initial array so that this one only has opaque primitives in the end.

std::vector might be really helpful in this case, though you might also find a way to reallocate you memory on the fly, but as I said, std::vector makes everything easier.

As for the back to front order: Try to disable writes to the depth buffer when rendering the transparent polygons, that should in most cases do the job very well...

Hope this helps...

Share this post


Link to post
Share on other sites
No that is the main problem. I dont know wat kind of polygon i have. I just know the vertex locations, texture coordinates & the normals of each polygon.

Share this post


Link to post
Share on other sites
Don't you know a four-component color value for each vertex? I thought .obj has this information?

If you have color values: an Alpha of 1.0f is opaque, everything < 1.0f is translucent. But I'm sure you know this :-)

Share this post


Link to post
Share on other sites
No obj doesnot have the vertex color information :(....... it just gives u the texture coordinates for each vertex & its the texture that decides whether the polygon will be opaque or alpha......the texture offcourse is 32 bit with 8 bit alpha channel

Share this post


Link to post
Share on other sites
Hmm... I didn't know that.
Then have you tried rendering everything as if it were translucent, with depth writes disabled?
Alpha 1.0 fragments should then appear opaque, if you use the corrent blending mode.

Share this post


Link to post
Share on other sites
What GFX API are you using?

You might also want to try to render your model with alpha test (not blending) enabled. Leave depth writes enabled. In OpenGL: glEnable(GL_ALPHA_TEST) and glAlphaFunc(GL_LESS, 0.5f). An advantage is, that you don't need to sort your polygons, because the pixels that have an alpha value less than 0.5 are not even written into the depth buffer. But the disadvantage is, that you can't have blending with this approach. It's either "write pixel" or "do not write the pixel at all". In DirectX this might work similiar.

This is actually my last idea :-) Sorry, but you can also try another file format like 3DS. 3DS has blending support...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!