激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專(zhuān)注于服務(wù)器技術(shù)及軟件下載分享
分類(lèi)導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - C# - Unity實(shí)現(xiàn)旋轉(zhuǎn)扭曲圖像特效

Unity實(shí)現(xiàn)旋轉(zhuǎn)扭曲圖像特效

2022-03-11 12:56圖形小菜雞 C#

這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)旋轉(zhuǎn)扭曲圖像特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

旋轉(zhuǎn)扭曲特效是指在一個(gè)圓形區(qū)域內(nèi)扭曲所渲染的圖像,其他像素的旋轉(zhuǎn)程度隨著距離的變化而變化。具體可以通過(guò)修改shader來(lái)實(shí)現(xiàn)。

原始圖片

Unity實(shí)現(xiàn)旋轉(zhuǎn)扭曲圖像特效

扭曲圖片

Unity實(shí)現(xiàn)旋轉(zhuǎn)扭曲圖像特效

?
1
2
3
4
5
6
7
8
9
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
72
73
74
75
76
77
78
79
80
/*====================================================
 
        屏幕扭曲特效shader
 
======================================================*/
shader "hidden/twirleffects"
{
  properties
  {
    _maintex ("texture", 2d) = "white" {}
 
  }
  subshader
  {
    // no culling or depth
    cull off zwrite off ztest always
 
    pass
    {
      cgprogram
      #pragma vertex vert
      #pragma fragment frag
 
      #include "unitycg.cginc"
 
      uniform sampler2d _maintex;
      uniform float4  _maintex_texelsize;
      half4  _maintex_st;
 
      //旋轉(zhuǎn)扭曲的中心
      uniform float4 _centerradius;
      //將旋轉(zhuǎn)矩陣傳入
      uniform float4x4 _rotationmatrix;
 
      struct appdata
      {
        float4 vertex : position;
        float2 uv : texcoord0;
      };
 
      struct v2f
      {
        float2 uv : texcoord0;
        float4 vertex : sv_position;
      };
 
      v2f vert (appdata v)
      {
        v2f o;
        o.vertex = mul(unity_matrix_mvp, v.vertex);
        //將uv坐標(biāo)變換到center坐標(biāo)系中
        o.uv = v.uv - _centerradius.xy;
        return o;
      }
 
      fixed4 frag (v2f i) : sv_target
      {
 
        float2 offest = i.uv;
        //利用旋轉(zhuǎn)矩陣旋轉(zhuǎn)uv
        float2 distortedoffset = multiplyuv(_rotationmatrix,offest.xy);
 
        //計(jì)算uv點(diǎn)在旋轉(zhuǎn)圓中的位置
        float2 tmp = offest / _centerradius.zw;
        float t = min(1,length(tmp));
 
        //根據(jù)uv點(diǎn)在圓中的位置插值uv移動(dòng)的位置
        offest =lerp(distortedoffset,offest,t);
 
        //將uv坐標(biāo)返回原坐標(biāo)系中
        offest += _centerradius.xy;
 
        fixed4 col = tex2d(_maintex, unitystereoscreenspaceuvadjust(offest, _maintex_st));
 
        return col;
      }
      endcg
    }
  }
}

此旋轉(zhuǎn)特效主要就是對(duì)圖像的uv值進(jìn)行偏移,關(guān)鍵代碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
float2 offest = i.uv;
//利用旋轉(zhuǎn)矩陣旋轉(zhuǎn)uv
 float2 distortedoffset = multiplyuv(_rotationmatrix,offest.xy);
 
 //計(jì)算uv點(diǎn)在旋轉(zhuǎn)圓中的位置
float2 tmp = offest / _centerradius.zw;
float t = min(1,length(tmp));
 
//根據(jù)uv點(diǎn)在圓中的位置插值uv移動(dòng)的位置
offest =lerp(distortedoffset,offest,t);
 
//將uv坐標(biāo)返回原坐標(biāo)系中
offest += _centerradius.xy;

根據(jù)uv點(diǎn)的位置,對(duì)圖像進(jìn)行扭曲。

下面是腳本的源碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using system.collections;
using system.collections.generic;
using unityengine;
 
public class twirlscripts : monobehaviour {
 
  [executeineditmode]
 
  public vector2 radius = new vector2(0.3f, 0.3f);
 
  public vector2 center = new vector2(0.5f, 0.5f);
 
  [range(0.0f, 360.0f)]
  public float angle = 0.0f;
 
  public material material;
 
  private void onrenderimage(rendertexture source, rendertexture destination)
  {
 
    matrix4x4 rotationmatrix = matrix4x4.trs(vector3.zero, quaternion.euler(0, 0, angle), vector3.one);
 
    material.setmatrix("_rotationmatrix", rotationmatrix);
    material.setvector("_centerradius", new vector4(center.x, center.y, radius.x, radius.y));
 
    graphics.blit(source, destination, material);
 
  }
 
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://blog.csdn.net/u014222099/article/details/54377229

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲国产中文字幕 | 在线视频成人永久免费 | 国产精品视频久 | 嗯~啊~弄嗯~啊h高潮视频 | 黑色丝袜美美女被躁视频 | 全免费午夜一级毛片真人 | 91成人一区 | 欧美国产91 | 精品国产99久久久久久宅男i | 爽毛片| 依依成人精品视频 | 欧美视频99| 国产亚洲精品久久久久婷婷瑜伽 | 99精品视频久久精品视频 | 午夜神马福利视频 | 99www| 国产精品久久久免费 | 精品国产乱码一区二区三区四区 | 国产视频导航 | 国产精品久久久久久久久久久久久久久久 | 黑人一级片视频 | 一区二区精品视频在线观看 | 欧美成人免费在线视频 | 久草在线观看首页 | 精品一区二区三区电影 | 国产一级做a爱片在线看免 日日草夜夜 | 欧美日韩大片在线观看 | 9999视频| 欧美成人高清视频 | 99成人精品视频 | 99999久久久久久| 日日摸夜夜添夜夜添牛牛 | 电影av在线 | 欧美一级黄色网 | 91婷婷射 | 亚洲一区二区三区四区精品 | 亚洲一区二区国产 | 久久人人爽人人爽人人片av高清 | 亚洲国产精品久久久久久久久 | 国产精品久久久久久影院8一贰佰 | 国产精品一区在线看 |