WebGL 渲染抗锯齿 [英] WebGL render antialias
问题描述
我正在使用带有 javascript 的 webgl.有没有办法在没有抗锯齿的情况下进行渲染?我需要每个像素都是纯色.
I am using webgl with javascript. Is there a way to render without antialias? I need every pixel to be of a solid color.
我当前的片段着色器非常简单:
my current fragment shader is very simple:
precision mediump float;
varying highp vec3 lighting;
void main(void)
{
gl_FragColor = vec4(lighting, 1.0);
}
更新
基于@Moormanly 的回答,我通过在 getContext 中设置 antialias 属性实现了以下目标:
Based on @Moormanly's answer, I have achieved the following by setting the antialias attribute in the getContext:
默认别名:
抗锯齿 = false:
Antialias = false:
推荐答案
您可以在使用 getContext 方法的(可选)第二个参数创建上下文时设置属性.
You can set attributes when creating a context using the ( optional ) second parameter of the getContext method.
代码:
var context = canvas.getContext('webgl', {antialias: false});
查看 WebGL 规范的第 5.2 章了解更多信息.
Check out chapter 5.2 of the WebGL specification for more information.
这篇关于WebGL 渲染抗锯齿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!