Skip to content

Mask does not appear in syphon feed. #32

@Tenkir

Description

@Tenkir

I have an alpha mask that I'm using on the canvas. It works fine in the processing image, but when viewing the syphon feed, I only see the base layer. The mask and anything after are not rendered.

import processing.video.*;
import codeanticode.syphon.*;

PGraphics canvas;
SyphonServer server;
PImage mask;
PImage lines;
PImage backdrop;
Movie background;

void setup() {
  size(1920,1080, P3D);
  canvas = createGraphics(1920, 1080, P3D);
  mask = loadImage("alpha_mask.png");
  backdrop = loadImage("white_backdrop.png");
  background = new Movie(this, "finalimage_1.mov");
  background.loop();
  
  // Create syhpon server to send frames out.
  server = new SyphonServer(this, "Processing Syphon");
}

void draw() {
  canvas.beginDraw();
  canvas.background(100);
  canvas.image(background, 420, 0);
  canvas.mask(mask);
  canvas.image(backdrop, 0, 0);
  canvas.endDraw();
  image(canvas, 0, 0);
  server.sendImage(canvas);
}

void movieEvent(Movie m) {
  m.read();
}

Processing Window:
screen shot 2017-09-22 at 12 07 44 am

MadMapper:
screen shot 2017-09-22 at 12 07 55 am

Activity

vade

vade commented on Sep 22, 2017

@vade
Member

Ensure both apps agree on premultiplied vs unpremultiplied alpha. No idea what Processing's mask option does but my guess is your alpha is not premultiplied in Processing.

vade

vade commented on Sep 22, 2017

@vade
Member
bangnoise

bangnoise commented on Oct 25, 2017

@bangnoise
Member

I thought this sounded like it might be a real issue, but I can't get canvas.mask() to have any effect within Processing. If you can attach a minimal sketch folder with images to demonstrate the problem, I'll take a look.

added this to the Version 4 milestone on Mar 12, 2022
codeanticode

codeanticode commented on Mar 12, 2022

@codeanticode
Contributor

Revising very old issues, just for fun :-)

In this case, what's happening is that the texture that's backing the rendering surface (either onscreen or offscreen) is not updated with the output from the filter (mask() in P2D/P3D internally calls filter()), for some reason (it should, so opened a bug about this in the main processing4 repo: processing/processing4#449).

But, it gets full updated in the next frame, so one temporary workaround is to move the server.sendImage(canvas) call to the top of the draw() function.

A shorter example demonstrating the workaround. Original code (filter output does not show up in the receiveFrames sketch)

import codeanticode.syphon.*;

PGraphics canvas;
SyphonServer server;

PShader edges;

void setup() { 
  size(400,400, P3D);
  canvas = createGraphics(400, 400, P3D);
  edges = loadShader("edges.glsl");
  
  // Create syhpon server to send frames out.
  server = new SyphonServer(this, "Processing Syphon");
}

void draw() {  
  canvas.beginDraw();
  canvas.background(127);
  canvas.lights();
  canvas.translate(width/2, height/2);
  canvas.rotateX(frameCount * 0.01);
  canvas.rotateY(frameCount * 0.01);  
  canvas.box(150);
  canvas.filter(THRESHOLD);
  canvas.endDraw();
  image(canvas, 0, 0);
 server.sendImage(canvas);
}

Modified code (it works as expected):

void draw() {
  server.sendImage(canvas);
  canvas.beginDraw();
  canvas.background(127);
  ...

Also worth noting that the issue affects both the filter() function that takes only predetermined filters and the one with the PShader argument.

self-assigned this
on Mar 12, 2022
removed this from the Version 4 milestone on Mar 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @codeanticode@vade@bangnoise@Tenkir

      Issue actions

        Mask does not appear in syphon feed. · Issue #32 · Syphon/Processing