Unity shader實現百葉窗特效

2022-09-29 17:00:19 字數 3463 閱讀 7157

1.將劃分為水平n欄,**如下:

shader "unlit/bycshader"

_color ("tint", color) = (1,1,1,1)

_stencilcomp ("stencil comparison", float) = 8

_stencil ("stencil id", float) = 0

_stencilop ("stencil operation", float) = 0

_stencilwritemask ("stencil write mask", float) = 255

_stencilreadmask ("stencil read mask", float) = 255

_colormask ("color mask", float) = 15

_lan("lan",float) = 10

[toggle(unity_ui_alphaclip)] _useuialphaclip ("use alpha clip", float) = 0 }

subshader

stencil

cull off

lighting off

zwrite off

ztest [unity_guiztestmode]

blend srcalpha oneminussrcalpha

colormask [_colormask]

pass

; struct v2f

;v2f vert(appdata_t v)

sampler2d _maintex;

float _lan;

float4 frag(v2f in) : sv_target

endcg

} }}

如上圖,劃分為n欄後,對每一欄進行單獨處理,即可做到每一欄都同時進行顏色消減。

2.對每一欄同時進行顏色消減(控制閾值可以通過c#**實現)

**如下:

shader "unlit/bycshader"

_color ("tint", color) = (1,1,1,1)

_stencilcomp ("stencil comparison", float) = 8

_stencil ("stencil id", float) = 0

_stencilop ("stencil operation", float) = 0

_stencilwritemask ("stencil write mask", float) = 255

_stencilreadmask ("stencil read mask", float) = 255

_colormask ("color mask", float) = 15

_lan("lan",float) = 10

_stepx("stepx",range(0.0,1.0))=1.0

[toggle(unity_ui_alphaclip)] _useuialphaclip ("use alpha clip", float) = 0 }

subshader

stencil

cull off

lighting off

zwrite off

ztest [unity_guiztestmode]

blend srcalpha oneminussrcalpha

colormask [_colormask]

pass

; struct v2f

;v2f vert(appdata_t v)

sampler2d _maintex;

float _lan;

float _stepx;

float4 frag(v2f in) : sv_target

return float4(uv.xy,1.0,1.0);

}endcg

} }}

效果如下:

3.加上切變,百葉窗在關閉開啟時,是有透視變化的。用切變可以近似模擬透視,因為透視的實現代價很大,所以用切變。

新增一張,並進行切變

**如下:

shader "unlit/bycshader"

_color ("tint", color) = (1,1,1,1)

_stencilcomp ("stencil comparison", float) = 8

_stencil ("stencil id", float) = 0

_stencilop ("stencil operation", float) = 0

_stencilwritemask ("stencil write mask", float) = 255

_stencilreadmask ("stencil read mask", float) = 255

_colormask ("color mask", float) = 15

_lan("lan",float) = 10

_stepx("stepx",range(0.0,1.0))=1程式設計客棧.0

[toggle(unity_ui_alphaclip)] _useuialphaclip ("use alpha clip", float) = 0 }

subshader

stencil

cull off

lighting off

zwrite off

ztest [unity_guiztestmode]

blend srcalpha oneminussrcalpha

colormask [_colormask]

pass

; struct v2f

;v2f vert(appdata_t v)

sampler2d _maintex;

float _lan;

float _stepx;

float4 frag(v2f in) : sv_target

//這裡進行切變

float x1 = uv.x;

uv = in.texcoord;

uv+=float2(-0.5,-0.5);

uv.x-=x1;//切變時,先將重心調整到中心,然後繞每一欄的起點進行切變(這裡類似於繞某一點旋轉,所以後面要進行反向操作,加了就減,減了就加)

float2x2 qiebian = float2x2(1,0,(1.0-_stepx),1);

uv = mul(qiebian,uv);

uv-=float2(-0.5,-0.5);

uv.x+=x1;

float4 color= tex2d(_maintex, uv);

return color;

}endcg

} }}

效果如下:

本文標題: unity shader實現百葉窗特效

本文位址: /ruanjian/csharp/289905.html

WPF Clip實現百葉窗

原文 wpf clip實現百葉窗 效果圖 後台 public mainwindow pathgeometry pg null dispatchertimer timer null 設定矩形的大小 double size 100 矩形的初始寬度 double size1 0 private void ...

html實現百葉窗效果

html實現百葉窗效果 原理很簡單就是相當於把分成n份開始輪播,下面開始上 並解析其步驟 style中的 當然這裡要用到絕對定位 byc 想分成幾份 子容器的寬度就是父容器的寬度 份數 也要用定位超出的部分讓其隱藏 byc div byc div p 新增 本次例項用了五張 byc div p nt...

百葉窗效果

doctype html html lang en head meta charset utf 8 title 百葉窗效果 title style body box box li box li div box li div p style head body ul class box id box1...