Unity Shader剖切管道隧道

这篇博客介绍了如何在section_clipping_CS.cginc中增加_TubeLens变量来表示管道长度,并详细讲述了如何使用向量投影技术进行管道中心点裁剪的代码更新。通过_AxisDirs和_TubeLens的统一,提升三维场景中复杂几何体的渲染效率。
摘要由CSDN通过智能技术生成

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;
		}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值