Unity Shader剖切管道隧道

CrossSection无法满足要求。

1.在section_clipping_CS.cginc新增_TubeLens,表示管道长度

#if CLIP_TUBES
	uniform float4 _AxisDirs[64];
	uniform float _TubeLens[64];//新增
#endif

2.修改裁剪代码

向量B=管道中心到该点的向量

向量A=_AxisDirs[i] * dot(_AxisDirs[i], posWorld - _centerPoints[i]) 
向量A为向量B管道轴线上的投影

向量C=posWorld - _centerPoints[i] -向量A
向量C为向量B在垂直于轴线平面上投影

		#if CLIP_TUBES
		bool _clipTubes = false;
		int _centerCountTruncated = min(_centerCount, 64);
		for (int i = 0; i < _centerCountTruncated; i++)
		{
			bool clip1 = ((dot(posWorld - _centerPoints[i] - _AxisDirs[i] * dot(_AxisDirs[i], posWorld - _centerPoints[i]),
				posWorld - _centerPoints[i] - _AxisDirs[i] * dot(_AxisDirs[i], posWorld - _centerPoints[i])) - _Radiuses[i] * _Radiuses[i]) < 0);
			bool clip2 = ((dot(_AxisDirs[i] * dot(_AxisDirs[i], posWorld - _centerPoints[i]), _AxisDirs[i] * dot(_AxisDirs[i], posWorld - _centerPoints[i])) - _TubeLens[i] * _TubeLens[i]) < 0);
			
			bool clip3 = clip1 && clip2;
			_clipTubes = _clipTubes || clip3;
		}

猜你喜欢

转载自blog.csdn.net/zouxin_88/article/details/121681874
今日推荐