当前位置:网站首页>[opengl] advanced chapter of texture - principle of flowmap
[opengl] advanced chapter of texture - principle of flowmap
2022-07-03 14:46:00 【ZJU_ fish1996】
flowmap Simply put, it is a special uv Texture animation , We record the motion vector in the texture , And let the texture uv Move in a particular direction .
Its principle is very simple , But if you multiply the motion vector by time , Superimposed on the original texture coordinates , Then you won't get the right result :
vec2 motionvector = texture(flowmap, uv).xy * 2 - 1; // decode motion vector
uv = uv + time * motionvector;
vec3 color = texture(tex, uv).rgb;
When we accumulate a texture disturbance , The image is bound to be distorted , This distortion occurs when the texture is stretched or compressed , And texture generation tiling. But the value is small , Less distortion .
We must ensure that the motion vector accumulated on the texture coordinates is a relatively small value , Therefore, we should apply motion vectors circularly in a small numerical space .
Based on this idea , We optimize our code as follows :
vec2 motionvector = texture(flowmap, uv).xy * 2 - 1; // decode motion vector
uv = uv + fract(time) * motionvector * flowstrength;
vec3 color = texture(tex, uv).rgb;
We intercept the fractional part of time , Make sure its value is in a small range , among ,flowstrength Can be used to control the range of values , The greater the numerical , The greater the range of motion , The deformation of the image will also be more serious . In general , This parameter should not exceed 1.
however , This kind of circular application will bring discontinuity , therefore flowmap The real difficulty is , How to realize the never-ending “ flow ”.
In order to reduce the effect of discontinuity , We apply two phases that differ by half a period uv motion , And mix between the two images , Get a result that looks more correct .
Specifically applied to texture , As the first image uv The movement is at the end of the current cycle , Fade out , Of the second image uv The motion starts at the beginning of the cycle , Fade into .
vec2 motionvector = texture(flowmap, uv).xy * 2 - 1; // decode motion vector
vec2 uv1 = uv + fract(time) * motionvector * flowstrength;
vec2 uv2 = uv + fract(time + 0.5) * motionvector * flowstrength;
vec3 color1 = texture(tex, uv1).rgb;
vec3 color2 = texture(tex, uv2).rgb;
According to time , Calculate a mixing coefficient :
float alpha = abs((fract(time) - 0.5) * 2); // Simulated triangular wave , You can also use sin Function simulation
vec3 color = mix(color1, color2, alpha);
边栏推荐
- Tonybot humanoid robot infrared remote control play 0630
- [opengl] geometry shader
- Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块
- Address book sorting
- The picture quality has been improved! LR enhancement details_ Lightroom turns on AI photo detail enhancement: picture clarity increases by 30%
- 【7.3】146. LRU caching mechanism
- [opengl] face pinching system
- 数学常数表 by q779
- Talking about part of data storage in C language
- Understand the application scenario and implementation mechanism of differential segment
猜你喜欢
puzzle(016.3)千丝万缕
提高效率 Or 增加成本,开发人员应如何理解结对编程?
Puzzle (016.3) is inextricably linked
Adobe Premiere Pro 15.4 has been released. It natively supports Apple M1 and adds the function of speech to text
Timecho of Tianmou technology completed an angel round financing of nearly 100 million yuan to create a native timing database of the industrial Internet of things
Tonybot Humanoïde Robot Infrared Remote play 0630
The picture quality has been improved! LR enhancement details_ Lightroom turns on AI photo detail enhancement: picture clarity increases by 30%
【北大青鸟昌平校区】互联网行业中,哪些岗位越老越吃香?
tonybot 人形机器人 红外遥控玩法 0630
C language DUP function
随机推荐
C language to implement a password manager (under update)
PS tips - draw green earth with a brush
tonybot 人形机器人 首次开机 0630
7-3 count the number of words in a line of text
Qt—绘制其他东西
Accelerating strategy learning using parallel differentiable simulation
Table of mathematical constants by q779
Tiantu investment sprint Hong Kong stocks: asset management scale of 24.9 billion, invested in xiaohongshu and Naixue
Find books ()
NOI OPENJUDGE 1.6(09)
Dllexport et dllimport
Talking about part of data storage in C language
Luogu p5536 [xr-3] core city solution
Use of form text box (I) select text
J-luggage lock of ICPC Shenyang station in 2021 regional games (simple code)
Optical cat super account password and broadband account password acquisition
Zzuli: cumulative sum of 1050 factorials
Luogu p5194 [usaco05dec]scales s solution
C language dup2 function
Implement Gobang with C language