Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Add clipping texture with shader  (Read 1530 times)

0 Members and 1 Guest are viewing this topic.

Gerard Wensink

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Github
    • Email
Add clipping texture with shader
« on: May 26, 2018, 11:38:18 am »
Hello. I draw sprites using a shader, AFTERWARDS i want to clip the resulting texture. (Cutting of top,bottom,left and/or right, by making it transparant or so).

I can do it by drawing the sprite with the shader in a texture, then clip the texture, then draw it on to the renderwindow, but i use a lot of these sprites, and things get slow.

This is my shader witch i use on lots of 64x72 pixel sprites:

uniform float wave_phase;
uniform vec2 wave_amplitude;

void main()
{
    vec4 vertex = gl_Vertex;
    vertex.x += (cos(gl_Vertex.y * 0.02 + wave_phase * 3.8)  + sin(gl_Vertex.y * 0.02 + wave_phase * 6.3) * 0.3) * wave_amplitude.x;
    vertex.y += (sin(gl_Vertex.x * 0.02 + wave_phase * 2.4)  + cos(gl_Vertex.x * 0.02 + wave_phase * 5.2) * 0.3) * wave_amplitude.y;

    gl_Position = gl_ModelViewProjectionMatrix * vertex;
    gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
    gl_FrontColor = gl_Color;
}

Somebody have any idea how to clip the resulting texture? Like with 4 parameters for clipping the top,bottom, left and/or right of the texture?

Thanks in advance.

See example video: Clipping is now done before the shader changes size/position, then clipping is not correct.
I want the sprites to go under the viaduct properly cut off.



« Last Edit: May 26, 2018, 11:42:18 am by Gerard Wensink »

 

anything