Processing, 類PShader用法介紹。
構造函數
PShader()PShader(parent)PShader(parent, vertFilename, fragFilename)PShader(parent, vertURL, fragURL)PShader(parent, vertSource, fragSource)
參數
parent父程序vertFilename頂點著色器的名稱fragFilename片段著色器的名稱vertURL頂點著色器的網絡位置fragURL片段著色器的網絡位置
說明
該類封裝了一個 GLSL 著色器程序,包括一個頂點著色器和一個片段著色器。它與 P2D 和 P3D 渲染器兼容,但與默認渲染器不兼容。使用loadShader() 函數加載您的著色器代碼。 [注意:強烈建議使用loadShader() 創建PShader 對象,而不是手動調用PShader 構造函數。]
例子
PShader blur;
void setup() {
size(640, 360, P2D);
// Shaders files must be in the "data" folder to load correctly
blur = loadShader("blur.glsl");
stroke(0, 102, 153);
rectMode(CENTER);
}
void draw() {
filter(blur);
rect(mouseX-75, mouseY, 150, 150);
ellipse(mouseX+75, mouseY, 150, 150);
}
PImage tex;
PShader deform;
void setup() {
size(640, 360, P2D);
tex = loadImage("tex1.jpg");
deform = loadShader("deform.glsl");
deform.set("resolution", float(width), float(height));
}
void draw() {
deform.set("time", millis() / 1000.0);
deform.set("mouse", float(mouseX), float(mouseY));
shader(deform);
image(tex, 0, 0, width, height);
}
方法
set()在著色器中設置一個變量
相關用法
- Processing PShape.enableStyle()用法及代碼示例
- Processing PShape用法及代碼示例
- Processing PShape.setStroke()用法及代碼示例
- Processing PShape.addChild()用法及代碼示例
- Processing PShape.isVisible()用法及代碼示例
- Processing PShape.getChildCount()用法及代碼示例
- Processing PShape.getVertex()用法及代碼示例
- Processing PShape.resetMatrix()用法及代碼示例
- Processing PShape.rotateX()用法及代碼示例
- Processing PShape.getChild()用法及代碼示例
- Processing PShape.rotateY()用法及代碼示例
- Processing PShape.setVisible()用法及代碼示例
- Processing PShape.beginContour()用法及代碼示例
- Processing PShape.beginShape()用法及代碼示例
- Processing PShape.endShape()用法及代碼示例
- Processing PShape.getVertexCount()用法及代碼示例
- Processing PShape.setFill()用法及代碼示例
- Processing PShape.rotate()用法及代碼示例
- Processing PShape.endContour()用法及代碼示例
- Processing PShape.scale()用法及代碼示例
- Processing PShape.disableStyle()用法及代碼示例
- Processing PShape.translate()用法及代碼示例
- Processing PShape.setVertex()用法及代碼示例
- Processing Pulse用法及代碼示例
- Processing PVector.set()用法及代碼示例
注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 PShader。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
