GLSL 初级教程 – Fragment Processor

本文深入探讨了片段处理器在渲染管线中的关键角色,包括颜色计算、纹理坐标、光照计算等操作,并解释了其输入来源及与片段着色器的关系。同时,强调了片段处理器的操作特点和限制,如不能改变像素坐标以及输出选项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The fragment processor is where the fragment shaders run. This unit is responsible for operations like:

  • Computing colors, and texture coordinates per pixel
  • Texture application
  • Fog computation
  • Computing normals if you want lighting per pixel

The inputs for this unit are the interpolated values computed in the previous stage of the pipeline such as vertex positions, colors, normals, etc…

In the vertex shader these values are computed for each vertex. Now we’re dealing with the fragments inside the primitives, hence the need for the interpolated values.

As in the vertex processor, when you write a fragment shader it replaces all the fixed functionality. Therefore it is not possible to have a fragment shader texturing the fragment and leave the fog for the fixed functionality. The programmer must code all effects that the application requires.

The fragment processor operates on single fragments, i.e. it has no clue about the neighboring fragments. The shader has access to OpenGL state, similar to the vertex shaders, and therefore it can access for instance the fog color specified in an OpenGL application.

One important point is that a fragment shader can’t change the pixel coordinate, as computed previously in the pipeline. Recall that in the vertex processor the modelview and projection matrices can be used to transform the vertex. The viewport comes into play after that but before the fragment processor. The fragment shader has access to the pixels location on screen but it can’t change it.

A fragment shader has two output options:

  • to discard the fragment, hence outputting nothing
  • to compute either gl_FragColor (the final color of the fragment), orgl_FragData when rendering to multiple targets.

Depth can also be written although it is not required since the previous stage already has computed it.

Notice that the fragment shader has no access to the frame buffer. This implies that operations such as blending occur only after the fragment shader has run.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值