在untiy中如何编写自定义的cginc

这里是创建的部分 

unity 自定义shader cginc 函数工具库并引用_我们做点事情吧-CSDN博客

注意事项:

.cginc文件的语法和shaderlab的语法是一致的,也就是说在unity中.shader文件中用的方法核函数在.cginc中一样

举个例子:

// params 
uniform float4		_TransitionCellSize;
uniform float4		_ScreenAndImageSize;
uniform float		_TransitionRange;

#define S(v) smoothstep(0.,1.5*fwidth(v), v )
// Mirror every side
vec2 mirror(vec2 v) {
	// The progress is added to vector making it 0 to 2
	// Se we mod by 2
	vec2 m = mod(v, 2.0);
	// Not sure about this one
	return mix(m, 2.0 - m, step(1.0, m));
}
float cubicInOut(float t) {
	return t < 0.5
		? 4.0 * t * t * t
		: 0.5 * pow(2.0 * t - 2.0, 3.0) + 1.0;
} 

上面是一段.cginc文件中的内容,其中的mix  pow也是shader文件中常用的,只不过写作的格式就是直接引用加函数,没有像shader中的Properties SubShader Pass的代码块,可以理解为.cginc就是咱们写shader的时候的工具类集合,可以把自己写的工具方法放到一个自己定义的.cginc文件中进行调用

你可能感兴趣的:(C#,图形学/shader,unity,游戏引擎)