Unity3D Shader图像扭曲过场效果
Posted MrBlue
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity3D Shader图像扭曲过场效果相关的知识,希望对你有一定的参考价值。
把脚本挂在摄像机上
using UnityEngine; using System.Collections; [RequireComponent(typeof(Camera))] public class PostEffectTwist : MonoBehaviour { public Material ma; void OnRenderImage(RenderTexture src, RenderTexture dest) { Graphics.Blit (src, dest, ma); } }
创建一个材质,再创建一个Shader
Shader "Hidden/NewImageEffectShader" { Properties { _MainTex ("Texture", 2D) = "white" {} _Angle ("Rotation", Float) = 0 } SubShader { // No culling or depth Cull Off ZWrite Off ZTest Always Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" 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); o.uv = v.uv; return o; } sampler2D _MainTex; float _Angle; fixed4 frag (v2f i) : SV_Target { float2 uv = float2(i.uv.x-0.5,i.uv.y-0.5); float f = distance(uv,float2(0,0)); float s = sin(lerp(0,_Angle,f)); float c = cos(lerp(0,_Angle,f)); // -c s // s c uv = float2(-uv.x*c+uv.y*s,uv.x*s+uv.y*c); uv = float2(uv.x+0.5,uv.y+0.5); fixed4 col = tex2D(_MainTex, uv); return col; } ENDCG } } }
以上是关于Unity3D Shader图像扭曲过场效果的主要内容,如果未能解决你的问题,请参考以下文章
shader编程-三维场景下SDF建模,对模型进行扭曲弯曲裁剪掏空操作(WebGL-Shader开发基础12)
shader编程-三维场景下SDF建模,对模型进行扭曲弯曲裁剪掏空操作(WebGL-Shader开发基础12)