【问题标题】:OpenTK - transparency issue on VBOOpenTK - VBO 的透明度问题
【发布时间】:2016-03-24 20:59:43
【问题描述】:

我只想创建一个 .obj 文件加载器,它将加载 3D 对象。一切都很顺利,但是当我尝试加载透明对象时出现问题。

所以,这是问题的图片。透明度正在起作用,但我不知道为什么,有三角形。我尝试加载不同的对象(也有纹理和没有纹理),但我总是遇到这个问题。

这是我的灯光设置:

class Light
{
    public static void SetLight()
    {
        GL.Enable(EnableCap.Lighting);
        GL.Enable(EnableCap.Light0);
        GL.Enable(EnableCap.ColorMaterial);

        Vector4 position = new Vector4(0.0f, 200.0f, 300.0f, 1.0f);
        Vector4 ambient = new Vector4(0.2f, 0.2f, 0.2f, 1.0f);
        Vector4 diffuse = new Vector4(0.7f, 0.7f, 0.7f, 1.0f);
        Vector4 specular = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);

        GL.Light(LightName.Light0, LightParameter.Position, position);
        GL.Light(LightName.Light0, LightParameter.Ambient, ambient);
        GL.Light(LightName.Light0, LightParameter.Diffuse, diffuse);
        GL.Light(LightName.Light0, LightParameter.Specular, specular);

    }

    public static void SetMaterial()
    {
        GL.Color4(1.0f, 1.0f, 1.0f, 0.5f);

        Vector4 ambient = new Vector4(0.3f, 0.3f, 0.3f, 0.5f);
        Vector4 diffuse = new Vector4(1.0f, 1.0f, 1.0f, 0.5f);
        Vector4 specular = new Vector4(0.0f, 0.0f, 0.0f, 0.5f);

        GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Ambient, ambient);
        GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, diffuse);
        GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Specular, specular);
        GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Shininess, 1.0f);
    }
}

在主加载函数中也有这些设置

GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

//GL.Enable(EnableCap.DepthTest);
//GL.Enable(EnableCap.CullFace);

我知道也许我的答案不是最好的,但我不知道这是什么问题,我什至在网上找不到类似的问题。

【问题讨论】:

    标签: c# opengl transparency opentk


    【解决方案1】:

    你的问题是这样的:

    在绘制透明面之前,您需要从最远到最近对它们进行排序。

    【讨论】:

    • 深度测试会拒绝更远的片段,但是在这里,你必须明确地对它们进行排序,所以深度缓冲区实际上是没有用的。
    • 对。现在我记得我为什么要避免使用透明卷。
    • 这就是为什么你在游戏中看不到太多透明度的原因。
    • 感谢答案,我想我以后会避免透明度:D
    • 好吧,如果你最终使用它,公式是距离 = Math.Sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+ (z1-z2)*(z1-z2)),计算每个面的值,将列表从最近到最远排序,然后按此顺序绘制。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-29
    • 2013-01-24
    • 2013-06-21
    • 2011-07-08
    相关资源
    最近更新 更多