用Shader實現的一些效果
/////////////////////////////////////////////////////////橡皮效果////////////////////////////////////////////////////////////////////
堡壘之夜,裡面敲擊建築時有橡皮那種彈彈彈的效果
最終效果
思路
- 根據對應的座標和範圍內的頂點,根據法線進行偏移。
- 根據時間計算偏移持續時間和反彈次數。
原始碼
[AppleScript] 純文字檢視 複製程式碼
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
指令碼
[AppleScript] 純文字檢視 複製程式碼
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
/////////////////////////////////////////////////////////Shader能量護盾////////////////////////////////////////////////////////////////////
利用場景的深度資訊——能量護盾
利用場景的深度資訊可以做一些很有趣的效果,比如能量護盾~ 這個效果雖然不算複雜但是很多遊戲裡面有有應用,看起來也夠炫酷。而利用深度資訊還可以做很多其他的效果。以後有空慢慢更新吧………… 下面正題 這個效果分為三個部分: 半透效果 最簡單的一部分,但需要一些關於shader的常識性知識。
shader設定 逐句分析: Cull Off 關閉背面剪裁。因為是要半透的自然可以看到背面,因此需要關閉背面剪裁 ZWrite Off 關閉Z快取寫入。因為護盾本身是不會“遮擋”到其他物體的,因此關閉。這裡的遮擋需要理解渲染管線的Z快取原理。 ZTest On 開啟Z快取測試。護盾需要被其他物體所“遮擋”。同上需要理解Z快取。 Blend SrcAlpha OneMinusSrcAlpha 混合方式 Alpha混合。意思是用Alpha的值來控制計算顏色和顏色快取中的值進行混合。(混合的方法有很多具體可查閱相關文件) 然後在ps裡瞎雞兒做個護盾樣子的圖取樣就行了~(其實可以弄個GrabPass然後加個噪音擾動弄出能量扭曲空間的效果)。這裡偷個懶就不搞了~
護盾貼圖 邊緣高亮 法線方向和視角的方向差異越大就說明越靠近邊緣,再加個引數用來調整。
ps:可以在頂點著色器裡獲得法線和視角方向以減少計算量,在片段著色器裡使用的時候記得歸一化。
獲取法線和視角方向
相交高亮 這就是關鍵了。 現在頂點著色器裡獲得對應的場景座標
隨後在片段著色器裡用場景座標對深度圖進行取樣
需要注意的是:這裡的_CameraDepthTexture需要在前面提前宣告。 我們用自身的座標和場景深度相減。得到的值小於一定範圍就認為是和場景相交的部分了。 最後使用高亮的係數對根據貼圖取樣的顏色和高亮的顏色進行插值得到了最終的顏色值。 下面是程式碼: [AppleScript] 純文字檢視複製程式碼
|
http://www.manew.com/thread-115809-1-1.html