当前位置:网站首页>[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);
边栏推荐
- 亚马逊、速卖通、Lazada、Shopee、eBay、wish、沃尔玛、阿里国际、美客多等跨境电商平台,测评自养号该如何利用产品上新期抓住流量?
- Zhonggan micro sprint technology innovation board: annual revenue of 240million, net loss of 17.82 million, proposed to raise 600million
- NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
- Puzzle (016.3) is inextricably linked
- Zzuli:1058 solving inequalities
- NOI OPENJUDGE 1.6(09)
- Common shortcut keys in PCB
- FPGA blocking assignment and non blocking assignment
- Joomla! CMS 3.0~3.4.6 RCE
- NPM install is stuck with various strange errors of node NPY
猜你喜欢
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
On MEM series functions of C language
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
论文分享:Generating Playful Palettes from Images
My QT learning path -- how qdatetimeedit is empty
Qt development - scrolling digital selector commonly used in embedded system
C language fcntl function
Implement Gobang with C language
Sub GHz wireless solution Z-Wave 800 Series zg23 SOC and zgm230s modules
[ue4] geometry drawing pipeline
随机推荐
提高效率 Or 增加成本,开发人员应如何理解结对编程?
Common shortcut keys in PCB
J-luggage lock of ICPC Shenyang station in 2021 regional games (simple code)
How to color ordinary landscape photos, PS tutorial
X86 assembly language - Notes from real mode to protected mode
Talking about part of data storage in C language
洛谷P5536 【XR-3】核心城市 题解
Plane vector addition
Dllexport et dllimport
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
7-9 one way in, two ways out (25 points)
Rasterization: a practical implementation (2)
C language fcntl function
Some concepts about agile
7-1 positive integer a+b (15 points)
Ultra simple mobile map development
Tonybot humanoid robot starts for the first time 0630
Code writing and playing method of tonybot humanoid robot at fixed distance
Zzuli:1046 product of odd numbers
C language to realize mine sweeping