Unity shader入门之数据类型

 2023-09-18 阅读 24 评论 0

摘要:包括基本数据类型 向量 数组 结构体 一.基本数据类型 float half fixed float 32位 half 16 位 fixed 8位 其中颜色 使用fixedint 整数 按照float处理,很少使用bool 类型 true 和false 支持 bool istrue=true; float c =istrue?1:2; 二. 向量 主要包括float2 f

包括基本数据类型 向量 数组 结构体

一.基本数据类型

  1. float half fixed
    float 32位 half 16 位 fixed 8位
    其中颜色 使用fixed
  2. int 整数
    按照float处理,很少使用
  3. bool 类型
    true 和false
    支持
    bool istrue=true;
    float c =istrue?1:2;

二. 向量

主要包括float2 float3 float4 fixed 2 fixed3 fixed4
例如:

float4 fl4 = float(1.0,1.0,1.0,1.0)

unity shader编程?重点介绍swizzle语法
作用:将一个向量提取组成一个新的向量
支持:xyzw和rgba两种模式,不能混合使用
例如:

float2 f2 = float2(1,2);
float3 fl3=float3(f2.xy,1);
//或 float3 fl3=float3(f2.rg,1);

三. 矩阵

float2x2 f2x2={1,2,3,4};
float2 f2 = f2x2[0];

四.数组

float arr[4] ={1,2,3,4};
数组不支持swizzle操作,支持角标

五.结构体

shader入门教程,struct a2v{
float4 pos;
}
a2v.pos=float4(1,2,3,4);

CG语言支持类型别名
typedef float3 FL3;
CG语言支持宏定义:
#define FL3DEF typedef float3 FL3;

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/72676.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息