Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use shader to realize the photo album of gradual transition in android

2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

The knowledge of this article "how to use shader to achieve gradual transition in android" is not understood by most people, so the editor summarizes the following contents, detailed contents, clear steps, and certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use shader to achieve gradual transition in android" article.

Effect:

Realization idea

Split the function points, there are mainly two: one is to achieve the gradual change of the picture, and the other is to achieve the switching of the picture.

The gradual change of the picture can be understood as the change of the transparency of the local pixels in a certain direction over time. The effect achieved in demo is a horizontal roller switch. The mathematical realization of horizontal translation is actually a simple vertical line x = time about the change of time. We only need to compare the x coordinate of each pixel with this vertical line, setting the transparency to 0 on the left and 1 on the right, and then smooth sampling to have the effect of gradual transition:

Void main () {

Vec4 color = vec4 (1,1,1,1)

Color * = texture (texture, v_uv0)

Color * = v_color

# if USE_TRAMSFORM

Color.a = smoothstep (0.0, u_fade_radius, u_fade_radius + v_uv0.x-u_time)

# endif

Gl_FragColor = color

}

The gradual change of the picture is realized, and then there is the switching of the picture. All the pictures are actually in a queue. After the gradual change is completed, we only need to put the top picture at the bottom, so that this photo album can be played in a loop all the time. In this process, we add some picture state processing to achieve the effect of the gradient album in demo.

IsTransforming: boolean = false

BgTramsform () {

If (this.isTransforming) return

This.isTransforming = true

Let time = 0.0

Let node = this.switchNodeList [0]

Let material = node.getComponent (cc.Sprite) .getMaterial (0)

Material.setProperty ('ubiquitous radiating, this.fadeRadius)

Material.setProperty ('upright timekeeping, time)

Material.define ('USE_TRAMSFORM', true, 0, true)

Let timer = setInterval () = > {

Time + = 0.03

Material.setProperty ('upright timekeeping, time)

If (time > 1.0 + this.fadeRadius) {

This.switchNodeList.shift ()

This.switchNodeList.push (node)

This.switchNodeList.forEach ((node, idx) = > node.zIndex = this.switchNodeList.length-idx)

Material.define ('USE_TRAMSFORM', false, 0, true)

This.isTransforming = false

Timer & & clearInterval (timer)

}

}, 30)

} the above is the content of this article on "how to use shader to achieve gradual transition in android". I believe you all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report