Tuesday 15 April 2014

opengl - Using shader to move texel to its center -


I am trying to move Square Texture Texlex to the center of the texture at the following time. The following code is working as long as I want the pixel is not ready when it reaches the center of the geometry (a plane) and now it is only going to be once more smaller, while in time Growth and texture seems like a contract.

Enter image details here

  Uniform float Time; VC 2VUV separate; Zero main () {vec2 center = VC2 (0.5, 0.5); Vec2 newPosition = vec2 (vUv.x + t * (center.x - vUv.x), vUv.y + t * (center.y - vUv.y); gl_FragColor = texture2D (texture, vec2 (newposition.x, newposition) ) .y));}  

edit:

It forms a black hole in texture See Enter image details here

As I understand, you want Texx to be on vUv when t = 0 And

The result is zoomed in at the center of the texture.

Actually your code does this by to T = 0 to t = 1 . When t = 1 is the texel state center .

You have similar behaviors while using the function.

  vec2 newPosition = mix (vUv, center, t);  

In addition, when t = 1 all texel a again center and image is a single color image. (The color of the center of the texture)

Your problem is that t continue to grow and when t & gt; 1 Texx continues on their way. They all meet at the center, now they wander away from each other. The effect is that the texture has been reversed and you can see the zoom-out.

There are several solutions based on what you want to end it with:

  • You go to the maximum zoom and want to keep this image: t in the range [0, 1] like this t = clamp (t, 0, 1); .

  • You want to go to the maximum zoom and the image disappears: Pause it to drag when t & gt; 1 (or t> = 1 if you do not want a single color image).

  • You want an infinite zoom-

For this third behavior, you use a new t , t2 :

  • say T2 = 1 - 1 / (t * k + 1); // where K & gt; 0
  • T2 = 1 - POW (K, -T); // where K & gt; 1
  • T2 = F (t); // where F (0) = 0, f is increasing, continuous and in ∞, limit 1

No comments:

Post a Comment