unity shader 学习一

本文介绍了Shader编程中需要注意的问题,如大小写敏感性、subshader中pass的重要性等,并详细解释了Unity内置变量的作用,包括矩阵变换、光照处理、时间控制等方面的内容。

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

shader中注意的问题
1大小写,例如:
#pragma vertex vert
#pragma fragment frag
2、subshader 中pass不可或缺

SV_POSITION 顶点着色器输出的定点位置,裁剪空间中的坐标

SV_Target 描述片元着色器的输出颜色,输出的值将会存储到渲染目标

#pragma 指令告诉unity我们定义的定点着色器和片元着色器的名字

_World2Object  模型空间到世界空间的逆转矩阵

_LightColor0 unity提供的内置变量来处理光源的颜色和强度信息以及光源的方向

saturatge 把参数截取到0--1范围内


a2v 在unity中 常用的语义
POSITION   float4类型
NORMAL    float3类型
TANGENT   float4类型
TEXCOORD0到TEXCOORDN float2或者float4类型
COLOR float4或者fixed4类型

v2f 在unity中常用的语义
SV_POSTION  
COLOR0  
COLOR1  
TEXCOORD0--TEXCOORD7






 
Name Type Value
UNITY_MATRIX_MVP float4x4 Current model * view * projection matrix.模型视图投影矩阵
UNITY_MATRIX_MV float4x4 Current model * view matrix.模型视图矩阵
UNITY_MATRIX_V float4x4 Current view matrix.视图矩阵
UNITY_MATRIX_P float4x4 Current projection matrix.投影矩阵
UNITY_MATRIX_VP float4x4 Current view * projection matrix.视图投影矩阵
UNITY_MATRIX_T_MV float4x4 Transpose of model * view matrix.
UNITY_MATRIX_IT_MV float4x4 Inverse transpose of model * view matrix.模型视图矩阵逆转
UNITY_MATRIX_TEXTURE0 to UNITY_MATRIX_TEXTURE3 float4x4 Texture transformation matrices.
_Object2World float4x4 Current model matrix.
_World2Object float4x4 Inverse of current world matrix.
_WorldSpaceCameraPos float3 World space position of the camera.
unity_Scale float4 xyz components unused; w contains scale for uniformly scaled objects.


Name Type Value
_ModelLightColor float4 Material’s Main * Light color
_SpecularLightColor float4 Material’s Specular * Light color
_ObjectSpaceLightPos float4 Light’s position in object space. w component is 0 for directional lights, 1 for other lights
_Light2World float4x4 Light to World space matrix
_World2Light float4x4 World to Light space matrix
_Object2Light float4x4 Object to Light space matrix


Name
Type Value
_Time float4 Time (t/20, t, t*2, t*3), use to animate things inside the shaders.
_SinTime float4 Sine of time: (t/8, t/4, t/2, t).
_CosTime float4 Cosine of time: (t/8, t/4, t/2, t).
unity_DeltaTime float4 Delta time: (dt, 1/dt, smoothDt, 1/smoothDt).
_ProjectionParams float4 x is 1.0 (or –1.0 if currently rendering with a flipped projection matrix), y is the camera’s near plane, z is the camera’s far plane and w is 1/FarPlane.
_ScreenParams float4 x is the current render target width in pixels, y is the current render target height in pixels, z is 1.0 + 1.0/width and w is 1.0 + 1.0/height.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浪里独行

赏后联系2872235596

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值