c# - opengl 透明度无法按预期工作
问题描述
我想渲染一个带有一些透明对象的 3D 场景,这是我的输出示例(我在 c# 中使用 opentk)
但是透明度没有按我的意愿工作,我需要这样的东西:
这是我在代码中的设置:
// before draw transparent object
GL.Enable(EnableCap.Blend);
// after draw transparent object
GL.Disable(EnableCap.Blend);
// @ GLInit
GL.ClearColor(0.5f, 0.5f, 1f, 1f);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
GL.ClearDepth(1);
GL.Enable(EnableCap.DepthTest);
GL.DepthFunc(DepthFunction.Lequal);
GL.DisableClientState(ArrayCap.NormalArray);
GL.DisableClientState(ArrayCap.VertexArray);
GL.DisableClientState(ArrayCap.TextureCoordArray);
//GL.Enable(EnableCap.PolygonOffsetFill);
GL.PolygonOffset(0.01f, 0.01f);
GL.Enable(EnableCap.StencilTest);
GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Replace);
try
{
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.DstAlpha);
GL.BlendEquation(BlendEquationMode.FuncAdd);
//Gl.BlendEquation(BlendEquationMode.FuncAddExt);
}
catch { }
GL.Enable(EnableCap.LineSmooth);
GL.Enable(EnableCap.PointSmooth);
GL.Enable(EnableCap.PolygonSmooth);
GL.Disable(EnableCap.Dither);
GL.ShadeModel(ShadingModel.Smooth);
GL.Disable(EnableCap.Multisample);
GL.LineWidth(0.5f);
GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
GL.Hint(HintTarget.LineSmoothHint, HintMode.Nicest);
GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest);
GL.Hint(HintTarget.PolygonSmoothHint, HintMode.Nicest);
GL.Hint(HintTarget.FragmentShaderDerivativeHint, HintMode.Nicest);
解决方案
推荐阅读
- java - 如何通过 Angular 8 客户端程序 + CORS 问题使用 Spring Boot 应用程序的 REST API
- shopify - 将变体添加到 Shopify 购物车时的动态变体价格
- javascript - Jquery:如何在元素中隐藏元素?
- php - 在php中使用一个文件进行数据连接
- sql - 这个解决方案可以用case..when生成吗?
- ios - 广告 SDK 在没有应用程序 ID 的情况下初始化
- firebase - 如何过滤firebase cloud firestore上的id列表?
- reactjs - 将有效载荷从一个 saga 传递到另一个 saga
- .net - 如何成功地将 React 应用部署到 Azure
- c++ - 如何从模板类中重载创建的指针对象上的运算符?