تقديم نماذج ثلاثية الأبعاد مع القوام التي تحتوي على ألفا في OpenGL

StackOverflow https://stackoverflow.com//questions/9643415

سؤال

لذلك أنا أحاول معرفة أفضل طريقة لتقديم نموذج ثلاثي الأبعاد في OpenGL عندما يتم تطبيق بعض القوام على أنها تحتوي على قنوات ألفا.

عندما يكون لدي عمق المخزن المؤقت الذي تم تمكينه، والبدء في رسم جميع المثلثات في نموذج ثلاثي الأبعاد، إذا كان يسحب مثلثا أمام مثلث آخر في النموذج، فلن يقوم ببساطة بعدم تقديم مثلث الظهر عندما يحصل عليه هو - هي. المشكلة هي عندما يكون للمثلث الجبهة شفافية ألفا، ويجب أن نكون قادرين على رؤيته إلى المثلث وراءها، لكن المثلث وراءه لا يزال غير مصدق.

تعطيل المخزن المؤقت عمق يزيل هذه المشكلة، ولكنه يخلق القضية الواضحة التي إذا كان المثلث غير مبهمة، فسيظل يجعل من المثلثات وراءه في الأعلى إذا تم تقديمه بعد.

على سبيل المثال، أحاول تقديم شجرة صنوبرية هي أساسا مكدسة بعض المخاريط أعلى بعضها البعض لديها قاعدة شفافة. تظهر الصورة التالية المشكلة التي تنشأ عند تمكين المخزن المؤقت عميق:

عمق المخزن المؤقت تمكين

يمكنك أن ترى كيف لا يزال بإمكانك رؤية الخطوط العريضة للمثلثات الشفافة.

الصورة التالية توضح ما يبدو عليه عندما يتم تعطيل المخزن المؤقت عمق.

عمق المخزن المؤقت المعوقين

هنا يمكنك أن ترى كيف يتم تقديم بعض المثلثات الموجودة في الجزء الخلفي من الشجرة أمام بقية الشجرة.

أي أفكار كيفية معالجة هذه المشكلة، وتقديم شجرة الصنوبر بشكل صحيح؟

p.s. أنا أستخدم التظليل لتقديم كل شيء.

هل كانت مفيدة؟

المحلول

If you're not using any partial transparency (everything is either 0 or 255), you can glEnable(GL_ALPHA_TEST) and that should help you. The problem is that if you render the top cone first, it deposits the whole quad into the z-buffer (even the transparent parts), so the lower branches underneath get z-rejected when its their time to be drawn. Enabling alpha testing doesn't write pixels to the z buffer if they fail the alpha test (set with glAlphaFunc).

If you want to use partial transparency, you'll need to sort the order of rendering objects from back to front, or bottom to top in your case.

You'll need to leave z-buffer enabled as well.

[edit] Whoops I realized that those functions I don't believe work when you're using shaders. In the shader case you want to use the discard function in the fragment shader if the alpha value is close to zero.

if(color.a < 0.01) {
   discard;
} else {
   outcolor = color;
}

نصائح أخرى

You needs to implement a two-pass algorithm.

The first pass render only the back faces, while the second pass render only the front faces.

In this way you don't need to order the triangles, but some artifacts may occour depending whether your geometry is convex or not.

I may be wrong, but this is because when you render in 3d you do no render the backside of triangles using Directx's default settings, when the Z is removed - it draws them in order, with the Z on it doesnt draw the back side of the triangles anymore. It is possible to show both sides of the triangle, even with Z enabled, however I'm thinking there might be a reason its normally enabled.. such as speed..

Device->SetRenderState(D3DRS_CULLMODE, Value);

value can equal

D3DCULL_NONE - Shows both sides of triangle
D3DCULL_CW - Culls Front side of triangle
D3DCULL_CCW - Default state
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top