当前位置:网站首页>Ripple effect of mouse click (unity & shader)
Ripple effect of mouse click (unity & shader)
2022-06-30 04:53:00 【LintonL】
Original address :http://www.manew.com/thread-106798-1-1.html
------------------------------------------------------------------------------------------------------
One 、 Preface
It's another one that hasn't been updated for a long time , Or is it too busy , Life goes on and on , Of course, there are good things to share with you .It uses .5.0 edition , practice , First on the renderings , As shown in the figure : The effect is to respond to each mouse click , A random color is generated at the click position of the mouse

What's hidden in this post
// How to convert colors
fixed3 shift_col(fixed3 RGB, half3 shift)
{
fixed3 RESULT = fixed3(RGB);
float VSU = shift.z*shift.y*cos(shift.x*3.14159265 / 180);
float VSW = shift.z*shift.y*sin(shift.x*3.14159265 / 180);
RESULT.x = (.299*shift.z + .701*VSU + .168*VSW)*RGB.x
+ (.587*shift.z - .587*VSU + .330*VSW)*RGB.y
+ (.114*shift.z - .114*VSU - .497*VSW)*RGB.z;
RESULT.y = (.299*shift.z - .299*VSU - .328*VSW)*RGB.x
+ (.587*shift.z + .413*VSU + .035*VSW)*RGB.y
+ (.114*shift.z - .114*VSU + .292*VSW)*RGB.z;
RESULT.z = (.299*shift.z - .3*VSU + 1.25*VSW)*RGB.x
+ (.587*shift.z - .588*VSU - 1.05*VSW)*RGB.y
+ (.114*shift.z + .886*VSU - .203*VSW)*RGB.z;
return RESULT;
}The attribute part is :
[PerRendererData] The command means that the texture on other materials of the object will be loaded directly
[Toggle] Command means a checkable option that can be displayed on the panel
Properties
{
[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
[HideInInspector]_StartTime("StartTime", Float) = 0
_Time("AnimationTime", Range(0.1, 10.0)) = 1.5
_Width("Width", Range(0.1, 3.0)) = 0.3
_StartWidth("StartWidth", Range(0, 1.0)) = 0.3
[Toggle] _isAlpha("isAlpha",Float) = 1
[Toggle] _isColorShift("isColorShift",Float) = 1
[MaterialToggle] PixelSnap("Pixel snap", Float) = 1
}Vertex and clip shader code :
v2f vert(appdata_base IN)
{
v2f OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.texcoord = IN.texcoord;
return OUT;
}
fixed4 frag(v2f IN) : SV_Target
{
fixed4 color = tex2D(_MainTex, IN.texcoord);
float2 pos = (IN.texcoord - float2(0.5,0.5)) * 2; // Width
float dis = (_Time.y - _StartTime) / _AnimationTime + _StartWidth - length(pos);
// Greater than the maximum width and less than 0 All pixels in this part are removed
if (dis < 0 || dis > _Width)
return fixed4(0,0,0,0);
// If the transparency gradient is turned on, let the transparency interpolate
float alpha = 1;
if (_isAlpha == 1)
{
alpha = clamp((_Width - dis) * 3, 0.1, 1.5);
}
fixed3 shiftColor = color;
if (_isColorShift == 1)
{
half3 shift = half3(_Time.w * 10, 1, 1);
shiftColor = shift_col(color, shift);
}
return fixed4(shiftColor, color.a * alpha);
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(SpriteRenderer))]
[RequireComponent(typeof(Collider2D))]
public class Ripple : MonoBehaviour
{
SpriteRenderer mSpriteRenderer;
Collider2D mCircleCollider;
void Awake()
{
mSpriteRenderer = transform.GetComponent<SpriteRenderer>();
mCircleCollider = transform.GetComponent<Collider2D>();
}
void Start()
{
Invoke("unenabledTrigger", 0.05f);
mSpriteRenderer.material.SetFloat("_StartTime", Time.time);
float animationTime = mSpriteRenderer.material.GetFloat("_AnimationTime");
float destroyTime = animationTime;
destroyTime -= mSpriteRenderer.material.GetFloat("_StartWidth") * animationTime;
destroyTime += mSpriteRenderer.material.GetFloat("_Width") * animationTime;
Destroy(transform.gameObject, destroyTime);
}
public void unenabledTrigger()
{
mCircleCollider.enabled = false;
}
public void OnTriggerEnter2D(Collider2D collider)
{
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
[RequireComponent(typeof(Image))]
public class Control : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler
{
public GameObject prefabRippleEffect;
public void OnDrag(PointerEventData eventData)
{
}
public void OnPointerDown(PointerEventData eventData)
{
CreateNewRipple(eventData.position);
}
public void OnPointerUp(PointerEventData eventData)
{
}
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
CheckTap();
}
private void CheckTap()
{
foreach (Touch item in Input.touches)
{
if (item.phase == TouchPhase.Began)
{
CreateNewRipple(item.position);
}
}
}
/// <summary>
/// Create a new ripple
/// </summary>
/// <param name="pos"></param>
private void CreateNewRipple(Vector2 pos)
{
Vector2 worldPos = Camera.main.ScreenToWorldPoint(pos);
GameObject tempNewRipple = Instantiate(prefabRippleEffect, worldPos, Quaternion.identity, transform);
}
}边栏推荐
- HTC vive cosmos development - handle button event
- Unity3d Google Earth
- Connect to the database and run node JS running database shows that the database is missing
- pycharm 数据库工具
- z-index属性在什么情况下会失效?
- IIS request SSL certificate
- Paging query, using jdbc-- paging query
- 力扣209. 长度最小的子数组
- Is the Flink connector JDBC open source? Where can I download it
- Draw on screen border in Commodore 64
猜你喜欢

Output directory of log files after unity3d packaging

力扣349. 两个数组的交集

Solution to Autowired annotation warning

Redis implements SMS login function (II) redis implements login function

Preorder traversal of Li Kou 589:n fork tree

Force buckle 59 Spiral matrix II

Window10 jar double click to run without response

Easyrecovery data recovery software recovers my photo and video data two years ago

PBR material: basic principle and simple fabrication

pycharm 数据库工具
随机推荐
Autowired注解警告的解决办法
UE4 method of embedding web pages
A must see cruise experience in Bangkok: visit the Mekong River and enjoy the scenery on both sides of the river
Differences between cookies and sessions
力扣209. 长度最小的子数组
What is multimodal interaction?
【Paper】2015_ Coordinated cruise control for high-speed train movements based on a multi-agent model
【Paper】2006_ Time-Optimal Control of a Hovering Quad-Rotor Helicopter
力扣59. 螺旋矩阵 II
Pourquoi l'ordinateur n'a - t - il pas de réseau après l'ouverture du Hotspot win10?
Encapsulating JDBC tool classes
Output directory of log files after unity3d packaging
图的一些表示方式、邻居和度的介绍
Force buckle 59 Spiral matrix II
力扣349. 两个数组的交集
力扣2049:统计最高分的节点数目
Steamvr causes abnormal scene camera
Force buckle 349 Intersection of two arrays
Detailed explanation of cookies and sessions
PBR material: basic principle and simple fabrication