In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how OpenGL Shader to achieve shadow masking effect, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Another use of smoothstep
It is also mentioned that the gradient effect will occur when the range of input parameters an and b in the smoothstep function is too large. As shown in the OpenGL Shader- anti-aliasing implementation:
Realization of masking effect
After seeing this effect, it seems that an and b input parameters in the smoothstep function can be used to achieve different special effects. For example, you can use this feature to achieve a mask effect similar to that in an old movie, with a faint shadow effect around the brightest in the middle of a hazy mask on the edge of the view.
In fact, the realization principle is to use the smoothstep function to input parameters and use a wide range of values, and transform the processing on the basis of drawing circles. The background color is white vec3 (1.), and shadow masking is black vec3 (1.) You can achieve the shadow masking effect.
Void main () {vec2 uv = gl_FragCoord.xy / iResolution.xy; vec4 texture = texture (iChannel2,uv); uv-= 0.5; uv.x * = iResolution.x/iResolution.y; float m = 0.4; m = smoothstep (Mmura 0.2 uv); vec3 pixel = mix (vec3 (1.), vec3 (0.), m); gl_FragColor = vec4 (pixel,1.0) }
In addition to using the smoothstep function, there is another way to achieve the shadow masking effect. Multiplying the color vector vec4 texture and vignette as shown in glsl below is equivalent to changing the brightness of the color value channel to achieve light-dark contrast; at the same time, it can be understood that the closer the value uv.y-0.5 is to the center, the closer it is to 0, then the calculated vignette is about 1.
Void main () {vec2 uv = gl_FragCoord.xy / iResolution.xy; vec4 texture = vec4 (1.); float vigAmt = 4.0; float vignette = (1.0 murvigAmt * (uv.y-0.5) * (uv.y-0.5)) * (1.0 musvigAmt * (uv.x-0.5) * (uv.x-0.5)); texture * = vignette; gl_FragColor = texture;}
Through the comparison, it can also be found that using the circular formula to achieve the mask has a certain arc trend, while the other kind of mask is biased to the rectangle, which is slightly different in the special effect. By analogy, it is certainly possible to achieve star, love and other shape masks in this way.
Smoothstep
Vignette
Effect expansion
Finally, you can add a time time input parameter, through the vigAmt value constantly changing vignette strength to achieve the effect of flickering, there will be a feeling of watching an old movie.
# define time iTimevoid main () {vec2 uv = gl_FragCoord.xy / iResolution.xy; vec4 texture = texture (iChannel2,uv); float vigAmt = 4.0 + 0.3 * sin (time + 5.0 * cos (time*5.0)); float vignette = (1.0murvigAmt * (uv.y-0.5) * (uv.y-0.5)) * (1.0ripvigAmt * (uv.x-0.5) * (uv.x-0.5)) Texture * = vignette; gl_FragColor = texture;}
The above is all the content of the article "how to achieve Shadow masking effect in OpenGL Shader". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.