> For the complete documentation index, see [llms.txt](https://docs.tenten.co/awesome/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tenten.co/awesome/webgl/awesome-threejs-playground/docs/glsl/glsl-syntax.md).

# OpenGL GLSL 语法和函数详解

## 变量和数据类型

可用的数据类型只有4种：有符号整数，无符号整数，浮点数，布尔值。 OpenGL着色语言中没有指针和字符串或字符。返回值可以为void。

## 向量类型

所有4种基本数据类型都可以存储在二维、三维或者四维向量中：

OpenGL着色语言向量数据类型

| GLSL 类型           |                 描述 |
| ----------------- | -----------------: |
| vec2,vec3,vec4    |    2分量、3分量和4分量浮点向量 |
| ivec2,ivec3,ivec4 |    2分量、3分量和4分量整数向量 |
| uvec2,uvec3,uvec4 | 2分量、3分量和4分量无符号整数向量 |
| bvec2,vbec3,bvec4 |    2分量、3分量和4分量布尔向量 |

## 矩阵类型

矩阵类型只支持浮点数

OpenGL着色语言矩阵数据类型

| GLSL 类型     |   描述 |
| ----------- | ---: |
| mat2,mat2x2 | 两行两列 |
| mat3,mat3x3 | 三行三列 |
| mat4,mat4x4 | 四行四列 |
| mat2x3      | 三行两列 |
| mat2x4      | 四行两列 |
| mat3x2      | 两行三列 |
| mat3x4      | 四行三列 |
| mat4x2      | 两行四列 |
| mat4x3      | 三行四列 |

## 存储限定符

限定符用于将变量标记为输入变量、输出变量或常量。

变量存储限定符

| 限定符     |                              描述 |
| ------- | ------------------------------: |
| const   |       一个编译时常量，或者说是一个队函数来说为只读的参数 |
| in      |                 一个从以前的截断传递过来的变量 |
| in      | centroid 一个从以前的截断传递过来的变量，使用质心插值 |
| out     |       传递到下一个处理阶段或者在一个函数中指定一个返回值 |
| out     |      centroid 传递到下一个处理阶段，使用质心插值 |
| inout   |              一个读/写变量，只能用于局部函数参数 |
| uniform |       一个从客户端代码传递过来的变量，在顶点之间不做改变 |

## 着色器统一值

属性是每个顶点位置、表面法线和纹理坐标等都需要的，而统一值则用于为整个图元批次向保持不变的（统一（uniform）的）着色器传递数据。 创建一个统一值只需在变量声明开始时放置一个uniform关键词：

```
uniform float u_time; // 总是只读的
```

***

> [OpenGL GLSL 语法和函数详解](https://blog.csdn.net/jeffasd/article/details/78209965)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.tenten.co/awesome/webgl/awesome-threejs-playground/docs/glsl/glsl-syntax.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
