当前位置:网站首页>Unity shader - cginclude file cginc
Unity shader - cginclude file cginc
2022-07-18 09:27:00 【Tomato ape】
1 summary
CGInclude file , The suffix is .cginc The file of , As the name suggests, it is CG Include files for , It's kind of like C/C++ The header file , We can use some commonly used macros 、 Structure 、 Global variables 、 Help functions are written in CGInclude In file , For efficient reuse .
2 Unity Of CGInclude file
Unity I also have many CGInclude file , Located in the installation directory Editor/Data/CGIncludes Catalog (Windows edition ), As shown below . We are writing by ourselves shader It is often used when Unity Of these CG Include files , such as UnityCG.cginc Various structures defined in ,Lighting.cginc Various lighting models in .
3 Write our own CGInclude file
The standard CGInlcude The file structure is as follows :
MyCG.cginc
#ifndef XXX
#define XXX
// Here we define common macros 、 Structure 、 Global variables 、 Help functions, etc
e.g.
#ifndef MY_CG_INCLUDE
#define MY_CG_INCLUDE
……
#endif
Use #ifndef、#define、#endif To avoid repeated definitions , Because it may be carried out in many places #include "MyCG.cginc" operation , Without this judgment, there will be repeated definitions ,#ifndef XXX It means if the definition does not XXX, Before executing the next code , Otherwise, just skip
inline Inline function
We are Unity The built-in CGInclude Many functions can be found in the file inline keyword , Yes inline The modified function is an inline function , It can solve the problem that some frequently called small functions consume a lot of stack space ( Stack memory ) The problem of , but inline There are limits to the use of ,inline It is only suitable for functions with simple code in the function body and will be used when they are called frequently , Cannot contain complex structure control statements such as while、switch, And the inline function itself cannot be a direct recursive function ( namely , I also call my own functions inside ).
4 Use our own CGInclude file
contain CGInclude file
If used shader and CGInclude The files are in the same directory , Can directly include
.shader
CGPROGRAM
#include "MyCG.cginc"
ENDCG
If not in a directory , You need to add relative paths , such as CGInclude The file in shader In the directory above the file , Then for
#include “…/MyCG.cginc”
there “…/“ Represents the directory above , Two level catalog , Then use ”…/…/”, And so on
If in shader File directory CGInclude In the folder , Then for
#include “CGInclude/MyCG.cginc”
Use caution
contain CGInclude After the document , We can directly use various macros in the file 、 Structure 、 Variable 、 Help function, etc .
But one thing to pay special attention to is , If we were CGInclude Define some variables that need external assignment , We need to remember in shader Assign or declare as Property assignment
Reference resources
《 Use CgInclude Let your Shader modularization ——Unity Built in CgInclude file 》
https://blog.csdn.net/candycat1992/article/details/38780387
《 Use CgInclude Let your Shader modularization —— establish CgInclude File storage lighting model 》
https://blog.csdn.net/candycat1992/article/details/38920347
《 Use CgInclude Let your Shader modularization —— Use #define Instruction creation Shader》
https://blog.csdn.net/candycat1992/article/details/38961411
边栏推荐
- 论文翻译解读:Translating Embeddings for Modeling Multi-relational Data【TransE】
- Codeforces Round #802 D. River Locks
- liquibase初次使用
- Codeforces Round #805 A - G
- 5-Redis架构设计到使用场景-存储原理-数据类型底层结构
- 一键生成VR全景图展示
- datax扩展vertica插件
- Power on, press F11, select one shot, and then select U disk to start
- Codeforces Round #803 (Div. 2) C. 3SUM Closure
- 腾势全新豪华中大型MPV曝光,安全、舒适一个不落
猜你喜欢

华为云Stack南向开放框架,帮助生态伙伴高效入云

Hcip day 8 notes

HCIP第八天笔记
![In a real case, college students were cheated when taking orders. I hope you won't be cheated [painful lesson]](/img/7d/142e69d6da1899cefbcc99d7929fba.png)
In a real case, college students were cheated when taking orders. I hope you won't be cheated [painful lesson]

5-Redis架构设计到使用场景-存储原理-数据类型底层结构

Opengauss cooperates with industry innovation to build a root community of open source databases

Codeforces Round #806 (Div. 4) A - G

Power on, press F11, select one shot, and then select U disk to start

易基因|ENCODE组蛋白ChIP-seq和转录因子ChIP-seq数据标准及处理流程

5个时间序列预测的深度学习模型对比总结:从模拟统计模型到可以预训练的无监督模型
随机推荐
AIRIOT答疑第4期|如何使用數據分析引擎?
量子保密通信浅析
Research on data security governance in China
真实案例,大学生接单被骗,希望大家不要被骗了【惨痛教训】
CVPR 2022 | 提高小数据集利用效率,复旦等提出分层级联ViT网络
SQL也能玩转AI ?没错!MLOps Meetup V3 回顾|OpenMLBD+SQLFlow+Byzer
DMS如何赋权数据库函数权限呢?
卸载CUDA11.1
华为云服务器云数据库创建只读过程
APP自动化测试框架搭建(七)--Airtest基础操作
腾势全新豪华中大型MPV曝光,安全、舒适一个不落
日志服务器的配置
There is no CUDA option in vs2019+cuda11.1 new project
Codeforces Round #803 (Div. 2) A. XOR Mixup
目前网上开户炒股安全吗?
A few minutes before work, I thoroughly understood json stringify()
安装CUDA失败的情况nsight visual studio edition失败
Codeforces Round #804 B Almost Ternary Matrix
idea 新建项目时克隆仓库代码
Codeforces Round #802 C. Helping the Nature