cansik / processing-postfx

A shader based postFX library for processing.
148 stars 13 forks source link

Render Stuck at origin #35

Closed DankMatterCH closed 2 years ago

DankMatterCH commented 3 years ago

Hello, thank you for providing this awesome library!

I was building an audio visualiser and used postfx to apply a glow to a fractal tree. I cant seem to get the render out of the top left corner though, i have tried matrixReset() and have looked at pretty much every other issue. There was a problem with matrices of PeasyCam, but i am not using this library.

Libraries used: PostFX, Sound

bugmaybe

I dont think this is a common issue, so i wanted to report :)

cansik commented 3 years ago

Thank you for reporting. Would it be possible to share a minimal sketch which recreates this bug so I can test it?

DankMatterCH commented 3 years ago

Hey, thanks for the quick reply! I think I have located the cause in the image feedback loop to get afterimages - When this is enabled, the issue occurs.

import ch.bildspur.postfx.builder.*;
import ch.bildspur.postfx.pass.*;
import ch.bildspur.postfx.*;

PostFX fx;

PImage c;

int firstcycle;

//afterimage settings
float tracerScaling = 0.97;
float trOffsetX = 6;
float trOffsetY = -6;

  void setup() {

      size(1024, 1024, P2D);
      fx = new PostFX(this,1024,1024);

      firstcycle = 1;

  }   //end setup

  void draw() {

      background(0,0,0,0);
      frameRate(30);
      stroke(255);

      //draw a white rectangle
      rect(312,312,400,400);

      //this seeems to be causing trouble V

            //disable image pull on 1st cycle to avoid null pointer
            if(firstcycle == 1){
              firstcycle = 0;
            }
            else{
             //do scaling and translation of image, then display it
             c.resize(round(width*tracerScaling),round(height*tracerScaling));
              imageMode(CENTER);
              image(c,height/2+trOffsetX,width/2+trOffsetY);
            }

            c = get(); // make a screenshot

      // add bloom filter 
      fx.render()
        .sobel()
        .bloom(0.5 , 20 , 30)
        .compose();    

  } // draw end
cansik commented 3 years ago

The problem is the imageMode(CENTER);, which is then also used in compose to draw the buffer to the screen. I would suggest to add the following line:

...
    c.resize(round(width*tracerScaling), round(height*tracerScaling));
    imageMode(CENTER);
    image(c, height/2+trOffsetX, width/2+trOffsetY);
    // set image mode back to corner
    imageMode(CORNER);
  }
...

This should already fix it.