translation - How to move a pixel in glsl? -
OK, suppose I have a ping pong shader setup, the image has a color other than a pixel 0. Define color red and blue colors where the pixels should be moved. (V * r * 2-0.5 = dx ... v is a constant)
How do I now go about transferring this pixel with the encoded amount in color value? I can not paint for any other piece, which is being processed, I can not transfer the "forward" information. Is there a solution?
Be careful, in my reply there is a link that can be very difficult for you GPU This is a successful breakout-style game that is in a shader.
You asked about moving forward "information", and in this example this is done by providing a textmap of the previous animation. The shader needs to know the frame current frame That's where the balls and bricks were in the previous frame.
The moving ball encodes its current direction in one color, such as:
vec3 ball (bull x, bull Y) {// direction direction direction VC3 Draw the ball with (1.0, X? 0.9: 1.0, Y? 0.9: 1.0); }
However, we can not expect that the user can see the single-pixel ball. Thus, the real counterfeit ball has been made in the form of a large white dot in the wake of the actual single-pixel ball.
Texture sampling is used to check the 5x5 field in the previous animation frame around the current pixel, to see that the current pixel is now "awake" in the direction of the actual ball travel or not. Draw fake balls and bonus pixels around the real from the last frame (float x = - 2.0; x and lt; = 2.0; x + = 1.0) {for (float y = -2.0; Y & lt; = 2.0; Y + = 1.0) {If (Ezonus (Texture 2D (backbuffer, position + VC2 (x, y) * pixel) .rgb)) {me.rgb = fakebonus; } If ((stomach (x) <2.0)} (abs (y) <2.0)) (if (itible (texture 2d (backbuffer, position + vc2 (x, y) * pixel). RGB)) .rgb = fake ball;}}}}
In this example, additional code checks to see if the ball comes in contact with a paddle or brick, And the appropriate action takes you.
The basic question you also mention is that you want a color to control the speed of the ball, unfortunately it is very difficult. Control of velocity reveals that you have to sample a large number of pixels around, to see if any of them has the right velocity to land on the pixels. To handle, the host application will need help.
Comments
Post a Comment