片段着色器如何确定来自顶点着色器输出的片段数? [英] How fragment shader determines the number of fragments from vertex shader output?

查看:102
本文介绍了片段着色器如何确定来自顶点着色器输出的片段数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉顶点和片段着色器,但对于片段着色器如何从顶点着色器的输出确定片段的数量仍然感到困惑.

如果我有3个顶点并在GLSL中绘制一个三角形图元,则顶点着色器将为每个顶点运行3次,然后片段着色器将运行多次(取决于片段的数量,每个片段一次). /p>

我想知道片段着色器如何确定片段?它使用gl_Position吗?如果我未在我的顶点着色器中设置gl_Position,那么片段着色器是否仍然能够生成片段?

每次在顶点着色器中都必须设置gl_Position吗?

解决方案

您正在谈论的是光栅化的步骤,即扫描转换. GPU会获取您的顶点着色器生成的位置并对其属性进行插值,以生成传递到片段着色器的片段.因此,是的,对于您而言,在顶点着色器中设置gl_Position至关重要.

将三角形的坐标转换为窗口坐标后,扫描转换将三角形取下并根据三角形覆盖的输出图像上的窗口像素排列将其分解. 来源.

I'm familiar with vertex and fragment shaders but still confused about how a fragment shader determines the amount of fragments from the output of vertex shader.

If I have 3 vertices and I draw a triangle primitive in GLSL, then vertex shader will run three times for every vertex and then fragment shader will run many times (depending upon the number of fragments, once for each fragment).

I want to know how fragment shader determines the fragments? Does it use gl_Position? If I don't set gl_Position in my vertex shader does fragment shader still be able to generate fragments or not?

Is gl_Position is compulsory to set every time in vertex shader?

解决方案

You're talking about the step in rasterization known as scan-conversion. The GPU takes the positions generated by your vertex shader and interpolates their attributes to produce the fragments that are passed to your fragment shader. So yes, it is essential for you to set gl_Position in the vertex shader.

After converting the coordinates of a triangle to window coordinates, scan conversion takes the triangle and breaks it up based on the arrangement of window pixels over the output image that the triangle covers. Source.

这篇关于片段着色器如何确定来自顶点着色器输出的片段数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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