GLSL 初级教程 – Vertex Processor

本文介绍OpenGL中顶点处理器的功能与顶点着色器的运作方式,包括顶点位置变换、法线变换等任务,并解释了使用顶点着色器时需要考虑的因素。

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

The vertex processor is responsible for running the vertex shaders. The input for a vertex shader is the vertex data, namely its position, color, normals, etc, depending on what the OpenGL application sends.

The following OpenGL code would send to the vertex processor a color and a vertex position for each vertex.

	glBegin(...);
		glColor3f(0.2,0.4,0.6);
		glVertex3f(-1.0,1.0,2.0);
		glColor3f(0.2,0.4,0.8);
		glVertex3f(1.0,-1.0,2.0);
	glEnd();

In a vertex shader you can write code for tasks such as:

  • Vertex position transformation using the modelview and projection matrices
  • Normal transformation, and if required its normalization
  • Texture coordinate generation and transformation
  • Lighting per vertex or computing values for lighting per pixel
  • Color computation

There is no requirement to perform all the operations above, your application may not use lighting for instance. However, once you write a vertex shader you are replacing the full functionality of the vertex processor, hence you can’t perform normal transformation and expect the fixed functionality to perform texture coordinate generation. When a vertex shader is used it becomes responsible for replacing all the needed functionality of this stage of the pipeline.

As can be seen in the previous subsection the vertex processor has no information regarding connectivity, hence operations that require topological knowledge can’t be performed in here. For instance it is not possible for a vertex shader to perform back face culling, since it operates on vertices and not on faces. The vertex processor processes vertices individually and has no clue of the remaining vertices.

The vertex shader is responsible for at least writing a variable: gl_Position, usually transforming the vertex with the modelview and projection matrices.

A vertex processor has access to OpenGL state, so it can perform operations that involve lighting for instance, and use materials. It can also access textures (only available in the newest hardware). There is no access to the frame buffer.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值