glsl类型

本文详细介绍了GLSL中的基本数据类型(如void, bool, int, float, bvec2/bvec3/bvec4, ivec2/ivec3/ivec4, vec2/vec3/vec4, mat2/mat3/mat4等),以及如何使用它们进行初始化。还涵盖了结构体(struct)的定义和实例化,展示了如何创建自定义数据结构。

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

glsl类型

void

Declaration

void main(void);
int aFunction(void);
void bFunction(float);

Declaration

void is used when a function has no parameters or when a function does not return a value.

bool

Declaration

bool aBool = true;
bool bBool = bool(aInt);
bool cBool = bool(aFloat);

Description

bool data type is either true or false

int

Declaration

int aInt = 42;
int bInt = int(aBool);
int cInt = int(aFloat);

Description

int is used for integer values.

float

Declaration

float aFloat = 1.0;
float bFloat = float(aBool);
float cFloat = float(aInt);

Description

float is used for floating point values.

bvec2

Declaration

bvec2 aBvec2 = bvec2(true, true);
bvec2 bBvec2 = bvec2(true);

bvec2 cBvec2 = bvec2(aBvec3);
bvec2 dBvec2 = bvec2(aBvec3.x, aBvec3.y);

Description

bvec2 is a boolean vector with two components. It can be initialized by:
Providing a scalar value for each component.
Providing one scalar value. This value is used for all components.
Providing a vector of higher dimension. The respective values are used to initialize the components.

bvec3
bvec4
ivec2

Declaration

bvec2 aIvec2 = ivec2(1, 1);
bvec2 bIvec2 = ivec2(1);

bvec2 cIvec2 = ivec2(aIvec3);
bvec2 dIvec2 = ivec2(aIvec3.x, aIvec3.y);

Description

ivec2 is an integer vector with two components. It can be initialized by:

Providing a scalar value for each component.
Providing one scalar value. This value is used for all components.
Providing a vector of higher dimension. The respective values are used to initialize the components.

ivec3
ivec4
vec2

Declaration

vec2 aVec2 = vec2(1.0, 1.0);
vec2 bVec2 = vec2(1.0);

vec2 cVec2 = vec2(aVec3);
vec2 dVec2 = vec2(aVec3.x, aVec3.y);

Description

vec2 is a floating point vector with two components. It can be initialized by:

Providing a scalar value for each component.
Providing one scalar value. This value is used for all components.
Providing a vector of higher dimension. The respective values are used to initialize the components.

vec3
vec4
mat2

Declaration

mat2 aMat2 = mat2(1.0, 0.0, // 1. column
0.0, 1.0); // 2. column
mat2 bMat2 = mat2(1.0);
mat2 cMat2 = mat2(aVec2, bVec2);
mat2 dMat2 = mat2(aVec3, aFloat);

Description

mat2 data type is compose for a 2x2 matrix of floating point. As you can see above, can be initialize in different ways:
Providing a value for each component column by column.
Providing one value that is used for the components on the main diagonal.
Providing a combination of vectors and scalars.
In the same way data can be accessed component-wise or column by column:

mat2 aMat2;
aMat2[1][1] = 1.0;

float aFloat = aMat2[1][1];
aMat2[0] = vec2(1.0);
vec2 aVec2 = aMat2[0];
mat3
mat4
sampler2D
samplerCube
struct

Example

struct matStruct {
    vec4 ambientColor;
    vec4 diffuseColor;
    vec4 specularColor;
    float specularExponent;
} newMaterial;

newMaterial = matStruct(vec4(0.1, 0.1, 0.1, 1.0),
                        vec4(1.0, 0.0, 0.0, 1.0),
                        vec4(0.7, 0.7, 0.7, 1.0),
                        50.0);

Description

struct declare a custom data structures based on standard types. A constructor for the structure with the same name is created automatically. The declaration of a variable (in this case “newMaterial”) is optional.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值