[GLSL / Maths / GLGraphics / GSVideo] Scaled translation in GLSL [solved ✓]
in
Contributed Library Questions
•
11 months ago
Hi all,
ClipFilter.xml:
Makio135
http://makio135.com/
I have a little math problem with glsl scaled translation:
I have a GSMovie playing in a GLTexture tex, i apply a GLTextureFilter ClipFilter that translate my movie following mouse coords, and apply Opacity and Scale.
The problem is: i want to apply Scale
from the center of the translation
.
So, here is my program:
GLSLClip.pde:
- import processing.opengl.*;
- import codeanticode.glgraphics.*;
- import codeanticode.gsvideo.*;
- GSMovie movie;
- GLTexture tex, texFiltered;
- GLTextureFilter ClipFilter;
- float Opacity=.5, Scale=1.0;
- void setup() {
- size(640, 480, GLConstants.GLGRAPHICS);
- tex = new GLTexture(this);
- texFiltered = new GLTexture(this);
- movie = new GSMovie(this, "station.mov");
- movie.setPixelDest(tex);
- movie.loop();
- ClipFilter = new GLTextureFilter(this, "ClipFilter.xml");
- }
- void movieEvent(GSMovie movie) {
- movie.read();
- }
- void draw() {
- if (movie.ready() && movie.width>1) {
- if (tex.putPixelsIntoTexture()) {
- background(255, 0, 0);
- float x = map(mouseX, 0, width, -.5, .5);
- float y = map(mouseY, 0, height, -.5, .5);
- ClipFilter.setParameterValue("posXY", new float[]{x, y});
- ClipFilter.setParameterValue("Scale", Scale);
- ClipFilter.setParameterValue("Opacity", Opacity);
- tex.filter(ClipFilter, texFiltered);
- image(texFiltered, 0, 0, width, height);
- }
- }
- }
- void keyPressed() {
- if(key == CODED){
- if (keyCode == UP && Opacity<1){
- Opacity += .1;
- println("Opacity: "+Opacity);
- }
- else if (keyCode == DOWN && Opacity>0){
- Opacity -= .1;
- println("Opacity: "+Opacity);
- }
- else if (keyCode == LEFT && Scale>.1){
- Scale -= .1;
- println("Scale: "+Scale);
- }
- else if (keyCode == RIGHT && Scale<3){
- Scale += .1;
- println("Scale: "+Scale);
- }
- }
- }
- <filter name="Clip Filter">
- <description>Clip Filter with posXY,Scale,Opacity</description>
- <fragment>ClipFilter.glsl</fragment>
- <textures input="1" output="1"></textures>
- <parameter type="vec2" name="posXY" label="Clip position">0 0</parameter>
- <parameter type="float" name="Scale" label="Scale">1</parameter>
- <parameter type="float" name="Opacity" label="Opacity">1</parameter>
- </filter>
ClipFilter.glsl:
- uniform sampler2D src_tex_unit0;
- uniform vec2 src_tex_offset0;
- uniform vec2 posXY;
- uniform float Scale;
- uniform float Opacity;
- void main(void)
- {
- vec2 tex_coord = (gl_TexCoord[0].st - posXY)/Scale; // Here is the problem
- vec4 color0 = texture2D(src_tex_unit0, tex_coord);
- if(tex_coord[0] <= 0) gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
- else if(tex_coord[0] >= 1) gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
- else if(tex_coord[1] <= 0) gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
- else if(tex_coord[1] >= 1) gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
- else gl_FragColor = vec4(color0.rgb, Opacity);
- }
Must be something not so hard but can't resolve it at the moment (not really used to GLSL coords transformation).
Thanks.
@admins: i'wasn't sure of the section, so feel free to move it if you think it is more a "Processing with Other Languages" (or else) thread.
http://makio135.com/
1