簡體   English   中英

在 Pi 3 B+ 上使用 Processing Pi 的 GLSL 着色器

[英]GLSL Shaders using Processing Pi on a Pi 3 B+

這是我第一次將 GLSL 着色器從 Processing OSX 移植到在 Raspberry Pi 3 B+ 上運行的 Processing Pi 上。 我有一個非常基本的着色器,可以在兩個視頻播放之間溶解。 它在我的 mac 上運行完全正常,但是當它被移植到 Processing Pi 並更新為使用 Processing 視頻庫 GLvideo 時,它會拋出一個錯誤。

着色器最初是從 ShaderToy 帖子轉換而來的,但我將其重新編寫為直接的 GLSL,以確保沒有任何兼容性問題。 我環顧四周,找不到任何我認為會導致此問題的具體內容。 因此,將不勝感激任何參考、指針或幫助。

我嘗試了其他一些事情,我將視頻調整為更小,將 Pi 的 GPU 內存更新為 256mb 等等。我確保它仍然可以在 OSX 上運行,但是當它在 Raspberry Pi 3B+ 上運行時,草圖是一個空白的白屏。

我想也許 Pi 處理 GLSL 的方式有些不同? 或者如果 Pi GPU 中的 sampler2D 紋理有限制? 在處理方面更是如此,它越過了我的也許不支持將 PGraphics 從 Processing 設置為處理 pi 的着色器中的 sampler2D 紋理? 當您設置texture3D 時,也許GLVideo 圖像有些東西。 另外,也許是我在碎片和顏色着色器的工作方式之間混合了一些東西。 目前我想我正在使用處理顏色着色器。

控制台中唯一的輸出是:

Final caps: video/x-raw(memory:GLMemory), format=(string)RGBA, width=(int)640, height=(int)360, interlace-mode=(string)progressive, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)25/1, texture-target=(string)2D
Final caps: video/x-raw(memory:GLMemory), format=(string)RGBA, width=(int)640, height=(int)360, interlace-mode=(string)progressive, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)25/1, texture-target=(string)2D

shaderDissolveGLSL.pde

//import processing.video.*;
import gohai.glvideo.*;

PShader mixShader;  

PGraphics pg;
PGraphics pg2;

//Movie movie;
//Movie movie2;

GLMovie movie;
GLMovie movie2;

void setup() {
  size(640, 360, P2D);
  noSmooth();
  pg = createGraphics(640, 360, P2D);

  //movie = new Movie(this, "_sm/LabspaceDawnv1blur2.mp4");
  movie = new GLMovie(this, "_sm/LabspaceDawnv1blur2.mp4");
  movie.loop();

  //movie2 = new Movie(this, "_sm/LabspaceFireblur2.mp4");
  movie2 = new GLMovie(this, "_sm/LabspaceFireblur2.mp4");
  movie2.loop();

  pg = createGraphics(width, height, P2D);
  pg2 = createGraphics(width, height, P2D);

  mixShader = loadShader("fadeshader.glsl");
  mixShader.set("iResolution", float(width), float(height));
  mixShader.set("iTime", millis()/1000.);

  mixShader.set("iChannel0", pg);
  mixShader.set("iChannel1", pg2);

}  

//void movieEvent(Movie m) {
void movieEvent(GLMovie m) {
  m.read();
  redraw();
}

void draw() {

  pg.beginDraw();
    pg.image(movie, 0, 0, width, height);
  pg.endDraw();

  pg2.beginDraw();
    pg2.image(movie2, 0, 0, width, height);
  pg2.endDraw();

  shader(mixShader);
  rect(0, 0, width, height);

}

漸變着色器.glsl

// Type of shader expected by Processing
#define PROCESSING_COLOR_SHADER

uniform float iTime;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform vec2 iResolution;

void main() {

    vec2 uv = gl_FragCoord.xy / iResolution.xy;
    vec4 mixColor = vec4(0.0);
    vec4 color0 = vec4(uv.x,uv.y,0.0,1.0);
    vec4 color1 = vec4(uv.x,uv.y,0.0,1.0);

    color0 = texture2D(iChannel0, uv);
    color1 = texture2D(iChannel1, uv);

    float duration = 10.0;
    float t = mod(float(iTime), duration) / duration;

    mixColor = mix(color0, color1, t);
    gl_FragColor = mixColor;
}

如果有人好奇,我已經用較小的視頻更新了示例草圖的新版本: https : //www.dropbox.com/sh/fu2plxmqhf7shtp/AADxqmW9zf73EsdzworCb5ECa? dl =0

任何關於可能發生的事情或從哪里開始調試更多的建議或想法將不勝感激。

謝謝!

我不是 100% 確定,但錯誤可能與視頻編碼以及 GLVideo 庫可以在 Raspberry PI 上解碼的內容有關(依賴 gstreamer)

我已經在舊系統上的 OSX 上遇到了錯誤:草圖在灰色屏幕上凍結了幾秒鍾,然后在沒有任何警告或錯誤的情況下崩潰。

我建議重新編碼視頻,如果不需要,則丟棄音頻通道,並使用與處理傳輸視頻相同或相似的 H.264 編碼器(例如示例 > 庫 > 視頻 > 電影 > 循環)

ffprobe -i /Users/George/Desktop/shaderDisolveGLSL/data/_sm/LabspaceDawn\ v1\ blur\ 2.mp4 
ffprobe version 3.3.3 Copyright (c) 2007-2017 the FFmpeg developers
  built with Apple LLVM version 7.0.0 (clang-700.0.72)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/George/Desktop/shaderDisolveGLSL/data/_sm/LabspaceDawn v1 blur 2.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2020-03-15T14:03:48.000000Z
  Duration: 00:00:49.09, start: 0.000000, bitrate: 218 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/bt709), 640x360 [SAR 1:1 DAR 16:9], 119 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2020-03-15T14:03:48.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 03/15/2020.
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 95 kb/s (default)
    Metadata:
      creation_time   : 2020-03-15T14:03:48.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 03/15/2020.

中轉視頻詳情:

ffprobe -i /Users/George/Desktop/shaderDisolveGLSL/data/transit.mov 
ffprobe version 3.3.3 Copyright (c) 2007-2017 the FFmpeg developers
  built with Apple LLVM version 7.0.0 (clang-700.0.72)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/George/Desktop/shaderDisolveGLSL/data/transit.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    creation_time   : 2012-08-31T20:17:39.000000Z
  Duration: 00:00:12.38, start: 0.000000, bitrate: 731 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 640x360, 727 kb/s, 29.97 fps, 29.97 tbr, 600 tbn, 1200 tbc (default)
    Metadata:
      creation_time   : 2012-08-31T20:17:44.000000Z
      handler_name    : Apple Alias Data Handler
      encoder         : H.264

什么似乎有效:

Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 640x360, 727 kb/s, 29.97 fps, 29.97 tbr, 600 tbn, 1200 tbc (default)

什么似乎崩潰:

Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/bt709), 640x360 [SAR 1:1 DAR 16:9], 119 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)

我在使用movieEvent時遇到了其他一些間歇性 JOGL 錯誤:在draw()偷偷調用.read() draw()似乎解決了這個問題。

這是我設法在 OSX 上運行的代碼的調整版本:

import processing.video.*;
//import gohai.glvideo.*;

PShader mixShader;  

PGraphics pg;
PGraphics pg2;

Movie movie;
Movie movie2;

//GLMovie movie;
//GLMovie movie2;

void setup() {
  size(640, 360, P2D);
  noSmooth();
  noStroke();

  //movie = new Movie(this, "_sm/LabspaceDawnv1blur2.mp4");
  movie = new Movie(this, "transit.mov");
  //movie = new GLMovie(this, "_sm/LabspaceDawnv1blur2.mp4");
  movie.loop();

  //movie2 = new Movie(this, "_sm/LabspaceFireblur2.mp4");
  movie2 = new Movie(this, "transit2.mov");
  //movie2 = new GLMovie(this, "_sm/LabspaceFireblur2.mp4");
  movie2.loop();

  pg = createGraphics(width, height, P2D);
  pg2 = createGraphics(width, height, P2D);

  mixShader = loadShader("fadeshader.glsl");
  mixShader.set("iResolution", float(width), float(height));
  mixShader.set("iChannel0", pg);
  mixShader.set("iChannel1", pg2);

}  

//void movieEvent(Movie m) {
//void movieEvent(GLMovie m) {
  //m.read();
  //redraw();
//}

void draw() {
  if(movie.available()){   movie.read(); }
  if(movie2.available()){   movie2.read(); }
  
  pg.beginDraw();
    // for testing only since both movies are the same
    movie.filter(GRAY);
    pg.image(movie, 0, 0, width, height);
  pg.endDraw();

  pg2.beginDraw();
    pg2.image(movie2, 0, 0, width, height);
  pg2.endDraw();
  
  // don't forget to update time
  mixShader.set("iTime", millis() * 0.01);
  
  shader(mixShader);
  rect(0, 0, width, height);
}

希望這適用於 Raspberry Pi 上的傳輸 mov 以測試編解碼器。 一旦運行順利,請重新編碼您的視頻(Handbreak 可能會對此有所幫助),然后重試。

@jshaw3 我在 RPI3 上進行了測試。 GLVideo 似乎有問題。 如果您不需要音頻,您可能可以使用圖像序列來代替:圖像序列播放器可以使這更容易。 請記住,這應該在不到 5 秒內初始化,以避免在 P3D/GL 端超時(否則延遲加載到第一幀):

import com.hirschandmann.image.*;

PShader mixShader;  

PGraphics pg;
PGraphics pg2;

ISPlayer movie1;
ISPlayer movie2;

boolean loadTriggered = false;

void setup() {
  size(640, 360, P2D);
  noSmooth();
  pg = createGraphics(640, 360, P2D);

  pg = createGraphics(width, height, P2D);
  pg2 = createGraphics(width, height, P2D);

  mixShader = loadShader("fadeshader.glsl");
  mixShader.set("iResolution", float(width), float(height));
  mixShader.set("iTime", millis()/1000.);

  mixShader.set("iChannel0", pg);
  mixShader.set("iChannel1", pg2);

}  

void draw() {
 
  if(!loadTriggered){
    movie1 = new ISPlayer(this,dataPath("_sm/LabspaceDawnv1blur2Frames"));
    movie1.loop();
    
    movie2 = new ISPlayer(this,dataPath("_sm/LabspaceFireblur2Frames"));
    movie2.loop();
    
    loadTriggered = true;
  }
  
  pg.beginDraw();
    if(movie1 != null) pg.image(movie1, 0, 0, width, height);
  pg.endDraw();

  pg2.beginDraw();
    if(movie2 != null) pg2.image(movie2, 0, 0, width, height);
  pg2.endDraw();
  
  shader(mixShader);
  rect(0, 0, width, height);
  
}

請注意,以上假設您已將 .mp4 文件轉換為圖像序列(例如LabspaceDawnv1blur2.mp4 -> LabspaceDawnv1blur2Frames )。 這是一個 ffmepg 示例:

ffmpeg -i LabspaceDawnv1blur2.mp4.mp4 -vf fps=1/60 LabspaceDawnv1blur2.mp4Frames/frame_%04d.png

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM