CG类型
来源:互联网 发布:决胜60秒源码 编辑:程序博客网 时间:2024/06/05 00:17
CG类型
CG支持7种数据类型:
float 32位浮点数half 16位浮点数int 32位整形数fixed 12位定点数bool 布尔数据sampler 纹理对象的句柄 共有:sampler、sampler1D、sampler2D、sampler3D、samplerCUBE、和samplerRECT六种。string 字符串,其实没有必要在CG中用到字符串
此外,CG还支持矩阵数据类型 如:
float2×4 matrix; //表示2×4阶矩阵,包含8个float类型数据
类型使用技巧:
1.精度够用就好 2.颜色和单位向量,使用fixed 3.其他情况,尽量使用half(即范围在[-6万,+6万]、精确的小数点3.3位);否则才使用用float
final color modifier:
编译指令为finalcolor:functionName,函数 接收三个参数 Input IN, SurfaceOutput o, inout fixed4 color final color会影响渲染的最终颜色,它在所有的计算的最后进行影响,比如lightmap、lightprobe等产生的颜色也会受此函数影响。 final color可以用来实现fog,fog只影响渲染的rgb,而不影响alpha,fog的原理是让物体在最终的rgb和fog.color之间根据距离进行过度。
例子:
Shader "MollyWendy/test1" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM #pragma surface surf Lambert finalcolor:mycolor vertex:myvert sampler2D _MainTex; uniform half4 unity_FogColor; uniform half4 unity_FogStart; uniform half4 unity_FogEnd; struct Input { float2 uv_MainTex; half fog; }; // 顶点着色函数 void myvert (inout appdata_full v, out Input data) { UNITY_INITIALIZE_OUTPUT(Input,data); float pos = length(mul (UNITY_MATRIX_MV, v.vertex).xyz); float diff = unity_FogEnd.x - unity_FogStart.x; float invDiff = 1.0f / diff; data.fog = clamp ((unity_FogEnd.x - pos) * invDiff, 0.0, 1.0); } // final color处理函数 void mycolor (Input IN, SurfaceOutput o, inout fixed4 color) { fixed3 fogColor = unity_FogColor.rgb; #ifdef UNITY_PASS_FORWARDADD fogColor = 0; #endif color.rgb = lerp (fogColor, color.rgb, IN.fog); } void surf (Input IN, inout SurfaceOutput o) { half4 c = tex2D (_MainTex, IN.uv_MainTex); o.Albedo = c.rgb; o.Alpha = c.a; } ENDCG } FallBack "Diffuse"}
0 0
- CG类型
- CG
- cg
- cg
- Cg Toolkit
- cg 笔记
- CG 编程
- Cg FAQ
- CG简介
- CG 网址
- cg网站
- cg数据类型
- CG简介
- CG大事记
- cg笔记
- Cg(一)
- Cg(二)
- Cg编程
- PCIE_DMA实例一:xapp1052详细使用说明
- System::String转换为std::string
- 创建登录用户并授权
- 算法细节系列(12):破除想当然
- ZOJ 3958 Cooking Competition【】
- CG类型
- Virtualbox 下配置高版本Linux内核的增强包安装
- MySQL数据安全技术
- MySQL日常总结
- PHP面试笔试细节
- Android 开发中如何用Javah命令生成JNI头文件
- 字体应用
- MySQL数据库安全技术
- Spring Boot 基础篇之 HelloWorld