Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

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

Shulou Source: shulou.com Published: 2022-05-31 13:08:42 10月04日 Update

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.

Tags: Pictures albums content effects that is transparency switching changes pixels articles time levels lines knowledge articles smoothing next one side two value. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Tech Info Shulou Technology Redmi vpn