使用GL_POINT_SMOOTH等效于ES 1.0圈子的OpenGL ES 2.0? [英] OpenGL ES 2.0 Equivalent for ES 1.0 Circles Using GL_POINT_SMOOTH?

查看:388
本文介绍了使用GL_POINT_SMOOTH等效于ES 1.0圈子的OpenGL ES 2.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OpenGL ES 2.0没有ES 1.0所具有的GL_POINT_SMOOTH定义.这意味着我用来绘制圆圈的代码不再起作用:

OpenGL ES 2.0 doesn't have the GL_POINT_SMOOTH definition which ES 1.0 does. This means code I was using to draw circles no longer works:

glEnable(GL_POINT_SMOOTH);
glPointSize(radius*2);
glDrawArrays(GL_POINTS,0,nPoints);

ES 2.0中是否存在等效项,也许在顶点着色器中要添加一些东西,还是必须对每个圆使用多边形?

Is there an equivalent in ES 2.0, perhaps something to go in the vertex shader, or must I use polygons for each circle?

推荐答案

您可以使用点精灵对此进行仿真.只需启用点精灵,您就会获得一个特殊的变量gl_PointCoord,您可以在片段着色器中读取它.这样可以在当前点的平方中为片段提供坐标.您可以使用它们读取包含圆圈的纹理(不在圆圈中的像素的颜色为0),然后丢弃纹理值为0的每个片段:

You can use point sprites to emulate this. Just enable point sprites and you get a special variable gl_PointCoord that you can read in the fragment shader. This gives you the coordinates of the fragment in the square of the current point. You can just use these to read a texture that contains a circle (pixels not in circle have color of 0) and then discard every fragment, whose texture value is 0:

if(texture2d(circle, gl_PointCoord).r < 0.1)
   discard;

编辑:或者您可以在不使用纹理的情况下完成此操作,方法是将纹理访问延迟换为计算复杂性,然后仅评估圆方程:

Or you can do it without a texture, by trading texture access latency for computational complexity and just evaluating the circle equation:

if(length(gl_PointCoord-vec2(0.5)) > 0.5)
    discard;

可以通过删除平方根(用于length函数中)并与平方半径进行比较来进一步优化:

This might be further optimized by dropping the square root (used in the length function) and comparing against the squared radius:

vec2 pt = gl_PointCoord - vec2(0.5);
if(pt.x*pt.x+pt.y*pt.y > 0.25)
    discard;

但是内置的length函数可能比此函数更快,可以针对长度计算进行优化,并且可以直接在硬件中实现.

But maybe the builtin length function is even faster than this, being optimized for length computation and maybe implemented directly in hardware.

这篇关于使用GL_POINT_SMOOTH等效于ES 1.0圈子的OpenGL ES 2.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆