当前位置:网站首页>Unity interactive water ripple post-treatment
Unity interactive water ripple post-treatment
2022-07-03 08:26:00 【T.D.C】
Unity Interactive water ripple post-treatment
- be based on unity post-processing , Provide interactive screen water ripple effect
- git Address :https://github.com/ak47007tiger/OilWater
- design sketch
characteristic
- Provide 2 Algorithms : One from shader toy; A classic algorithm for online search
- I'm pragmatism , If there are ready-made algorithms , I'm not going to start with 0 To calculate , After understanding it, I only care about its use value
- Auto fit large screen , The larger the screen, the more stuck
- Key parameters are provided with configuration , Don't write code
How to see the effect after downloading the project
- open Assets/OilWave/Loading.unity, function
- Shortcut key "control + i" Switch scenes , Click the screen in the scene with pictures
principle
- This principle is said from the perspective of a rear-view mirror , That is, Zhugeliang , This is mainly to help readers understand , I can't reproduce the creator's ideas
- Water ripple is a kind of transmission of vibration , We need to create vibrations 、 Diffuse vibration
- There are ups and downs after the waves on the water surface , Specular reflection 、 refraction , To be realistic , We need to achieve these effects , This article doesn't care
- In natural phenomena, other places under the water can be seen on the water circle , Hereinafter referred to as distortion , This phenomenon is what this paper aims to achieve
Realize the idea
- Suppose a texture is calm water
- Produce initial vibration , Set a certain area of a texture r The channel is a value
- Spread vibration , Update this texture every frame , Let this area r The value of the channel can spread out like a ring , You need to know the value of the previous frame , You cannot discard the value of the previous frame after the current frame is updated , So we need to g The channel saves the vibration value of the previous frame
- The more volatility , The more severe the distortion , That is, the larger the pixel value representing the vibration amplitude in the vibration texture , The larger the offset when sampling the image to be displayed
combination Unity How to realize
- Vibration texture : Create a texture , Each frame call shader Read and render this texture
- Find out CustomRenderTexture Encapsulates this function , Direct use , Appoint shaderPass For spreading vibration pass, See the engineering code for details
- Generate amplitude
- CustomRenderTexutre On reset UpdateZones Will execute all pass, Add a function to convert clicks to texture coordinates , And send the coordinates to the material , Execute click pass The initial vibration will be set to a certain pixel of the vibration texture
- Let the whole scene produce interactive water ripples , Sample and distort the texture generated by the game scene , Post processing can meet this demand
- Twist formula
- Input
- x,y
- Amplitude texture waterTex
- Scene texture mainTex
- In the middle
- The amplitude of the target pixel up, down, left and right , l, r, t, b
- offset = normalize(float3(r - l, t - b, 1))
- With offset You can do that. mainTex Conduct distorted sampling
- Input
Needed unity knowledge
- Material property settings
- shader grammar
- CustomRenderTexutre characteristic
- Customize the post-processing process
Description of main classes in the project
- The code is all there Assets/OilWave Next , Under other folders are irrelevant codes , Have no meaning , Never mind
- ConfigManager, It is written for modifying the material parameters without changing the code after the program is packaged
- DemoForResolutionAdapt, Responsible for creating CustomRenderTexture, If the screen is too large, shrink the created vibration texture to improve performance
- EffectInput, adapter pc And mobile , Handle mouse click or finger touch events
- OilWavePostProcessing, Update vibration texture , Post execution processing
- ProcessingConfig, Parameter class , Used to create data objects
- WaterManager, Management resources , Adapt to screen size switching
- WaterWave01, One of the earliest demo edition , There is not so much business logic
- WaterWave01.shader, Update the vibration texture shader
- WaterWaveShow.shader, Post processing shows shader, The logic of distorted sampling is here
边栏推荐
- animation
- A tunnel to all ports of the server
- MXone Pro自适应2.0影视模板西瓜视频主题苹果cmsV10模板
- Osgearth north arrow display
- Creation and content of mapnode -- osgearth rendering engine series (2)
- Compilation error: "not in executable format: file format not recognized"“
- [audio and video] ijkplayer error code
- 数据的存储
- P1596 [USACO10OCT]Lake Counting S
- OpenGL learning notes
猜你喜欢
Advanced OSG collision detection
Display terrain database on osgearth ball
Unity change default editor
A tunnel to all ports of the server
C language - Introduction - essence Edition - take you into programming (I)
Introduction to hexadecimal coding
基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程
Student educational administration management system of C # curriculum design
Some understandings of 3dfiles
C语言-入门-精华版-带你走进编程(一)
随机推荐
About Wireshark's unsuccessful installation of npcap
Editor Extensions
Puhua PLM empowers the whole scene product lifecycle management and helps the enterprise digital transformation of the main line of products
Use of ue5 QRcode plug-in
Classes and objects
[public key cryptography] ECC elliptic cryptosystem (implementing ElGamal encryption method)
Flex flexible box layout
Some understandings of 3dfiles
UE4 plug in development
Osgearth starry background
Compilation error: "not in executable format: file format not recognized"“
Redis data structure
[set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)
Unity2019_ Natural ambient light_ Sky box
How to establish rectangular coordinate system in space
Maxcompute string splitting function -split_ PART
KunlunBase MeetUP 等您来!
Sequence of map implementation classes
Clion toolchains are not configured configure disable profile problem solving
MySQL containerization (1) docker installation MySQL