Hello, do you know how I can acces a black and white texture in a vertex shader design to draw lines and edit the z position of each vertices based on the color of each pixel ?
If in my sketch I put sh.texture(image);
what is the name of the variable I can use in the vertex shader ?
uniform sampler2D texture;
doesn't seems to work.
import java.util.Date;
import peasy.*;
PeasyCam cam;
ArrayList<PVector> grid;
PShape shapeGrid;
boolean shapeMode;
PShader pshader;
PImage image;
int TWIDTH = 640;
int THEIGHT = 480;
void setup() {
size(640, 480, OPENGL);
cam = new PeasyCam(this, 1000);
cam.setMinimumDistance(50);
cam.setMaximumDistance(1500);
image = loadImage("depth.jpg");
pshader = loadShader("frag.glsl", "vert.glsl");
shapeGrid = createGrid(10);
shapeGrid.setStrokeWeight(1);
}
PShape createGrid(int detail) {
PShape sh = createShape();
sh.beginShape(LINES);
sh.stroke(255, 0, 0);
sh.textureMode(NORMAL);
sh.texture(image);
for (int y=0; y<height-detail; y+=detail) {
for (int x=0; x<width-detail; x+=detail) {
PVector tl, tr;
tl = new PVector(x, y);
tr = new PVector(x+detail, y);
sh.vertex(tl.x, tl.y, tl.z, tl.x/TWIDTH, tl.y/THEIGHT);
sh.vertex(tr.x, tr.y, tr.z, tr.x/TWIDTH, tr.y/THEIGHT);
}
}
sh.endShape(CLOSE);
return sh;
}
void keyPressed() {
if (key=='0') {
Date date = new Date();
String name = "data/images/shapes-"+date.getTime()+".png";
save(name);
}
}
void draw() {
background(127);
shapeMode(CENTER);
shader(pshader, LINES);
shape(shapeGrid);
}