OpenGL: Rendering a model with a lot of texture tr

2019-09-15 07:59发布

I have low-poly character models that make heavy use of textures to define shape using the alpha channel. (An example would be glasses, which are only 3 solid large quads, but the alpha channel of the texture defines the shape of the glasses)

So there's a tonne of transparency/translucency goin' on, I estimate that one quarter of every tri drawn, will have at least a little transparency in it's texture needing blending.
Most of the transparency occurs in the hair, which layers up geometry very close and intersects itself sometimes.

My question, is there any way to get reasonable alpha blending behavior, without ordering which tris are drawn according to depth? Most (old) opengl documentation I've read says ordering is required to blend any kind of transparency, but I feel ordering every tri every frame, in this case, would be too costly. (or at least, beyond my ability to code without spending weeks on it)

There is no lighting or vertex coloring, if it's important. The results don't have to be accurate, but I would like them to be visually pleasing and consistant, if possible.

2条回答
我命由我不由天
2楼-- · 2019-09-15 08:18

When working with alphas before I have found that one way around this problem is to render the alphas in whichever order, but simply displacing them slightly in a recursive fashion towards the camera. i.e each successive triangle is rendered slightly translated towards the camera with respect to the previous one (very slightly such that objects still look like they are in the same place). Although this might not be sufficient for your needs depending on setup, It certainly got rid of alpha overlap problems rendering leaves and stuff for me and it isn't very resource intensive as you don't need to order anything at all. It might not work in your specific situation but it might be worth a try, good luck!

查看更多
Fickle 薄情
3楼-- · 2019-09-15 08:27
  1. you could reorder your tri's by the distance from sub-axises

    axises

    so as first are rendered layers closer to the axis and as last the most outer layers.

  2. On top of this you put the transparent tri's

    unless you have whole parts transparent it should be OK. The order problems will cause glitches like sometimes you will not see transparent object behind transparent object correctly (from some angles) and also this can be corrected by multi pass rendering and proper CULL_FACE front switching. Beware that this will not solve 100% of the artifacts ... The more complex shapes you have the more glitches there will be.

    For example I render transparent glass with solid machine around and inside like this:

    1. render solid part (CW+CCW)
    2. render back-side transparent part (CCW)
    3. render solid part (CW+CCW)
    4. render front-side transparent part (CW)

(my models are defined with CW winding rule)

Here OpenGL example:

查看更多
登录 后发表回答