Pshader
in
Programming Questions
•
9 months ago
Does anyone know how i set Pshader as my background as im using the nebula sample as my background image and i want my polygon shapes to appear on top of the nebula, i can get either the nebula effect to appear inside of my polygon shapes or i just get the nebula but no polygon shapes ill show u the code and hopfully some one can help this newbie out.
kind regards
carl reeves
/**
* PolygonPShapeOOP.
*
* Wrapping a PShape inside a custom class
* and demonstrating how we can have a multiple objects each
* using the same PShape.
*/
PShader nebula;
* PolygonPShapeOOP.
*
* Wrapping a PShape inside a custom class
* and demonstrating how we can have a multiple objects each
* using the same PShape.
*/
PShader nebula;
// A list of objects
ArrayList<Polygon> polygons;
ArrayList<Polygon> polygons;
void setup() {
size(640, 640, P2D);
smooth();
nebula = loadShader("nebula.glsl");
nebula.set("resolution", float(width), float(height));
// Make a PShape
PShape star = createShape();
star.fill(0,127);
star.stroke(0);
star.vertex(0, -50);
star.vertex(14, -20);
star.vertex(47, -15);
star.vertex(23, 7);
star.vertex(29, 40);
star.vertex(0, 25);
star.vertex(-29, 40);
star.vertex(-23, 7);
star.vertex(-47, -15);
star.vertex(-14, -20);
star.end(CLOSE);
// Make an ArrayList
polygons = new ArrayList<Polygon>();
// Add a bunch of objects to the ArrayList
// Pass in reference to the PShape
// We coud make polygons with different PShapes
for (int i = 0; i < 25; i++) {
polygons.add(new Polygon(star));
}
}
size(640, 640, P2D);
smooth();
nebula = loadShader("nebula.glsl");
nebula.set("resolution", float(width), float(height));
// Make a PShape
PShape star = createShape();
star.fill(0,127);
star.stroke(0);
star.vertex(0, -50);
star.vertex(14, -20);
star.vertex(47, -15);
star.vertex(23, 7);
star.vertex(29, 40);
star.vertex(0, 25);
star.vertex(-29, 40);
star.vertex(-23, 7);
star.vertex(-47, -15);
star.vertex(-14, -20);
star.end(CLOSE);
// Make an ArrayList
polygons = new ArrayList<Polygon>();
// Add a bunch of objects to the ArrayList
// Pass in reference to the PShape
// We coud make polygons with different PShapes
for (int i = 0; i < 25; i++) {
polygons.add(new Polygon(star));
}
}
void draw() {
background(255);
nebula.set("time", millis() / 500.0);
shader(nebula);
// This kind of raymarching effects are entirely implemented in the
// fragment shader, they only need a quad covering the entire view
// area so every pixel is pushed through the shader.
//rect(0, 0, width, height);
background(255);
nebula.set("time", millis() / 500.0);
shader(nebula);
// This kind of raymarching effects are entirely implemented in the
// fragment shader, they only need a quad covering the entire view
// area so every pixel is pushed through the shader.
//rect(0, 0, width, height);
// Display and move them all
for (Polygon poly : polygons) {
poly.display();
poly.move();
}
}
for (Polygon poly : polygons) {
poly.display();
poly.move();
}
}
1