Browse Source

effect layers that do not change will no longer be recalculated every frame, this makes it much faster to work manually

master
Victor Giers 2 years ago
parent
commit
d93cb7a92c
3 changed files with 86 additions and 11 deletions
  1. 1
    1
      data/saves.sav
  2. 34
    4
      secondapplet.pde
  3. 51
    6
      shader.pde

+ 1
- 1
data/saves.sav View File

@@ -1,2 +1,2 @@
//globals
uptime = 116717241
uptime = 116747025

+ 34
- 4
secondapplet.pde View File

@@ -3,6 +3,7 @@
PImage bin;
int maxSurfaceHeight = 500;
int nativeResoX, nativeResoY;
boolean renderSizeChanged = true;

public class SecondApplet extends PApplet {
ControlP5 cp5;
@@ -148,7 +149,6 @@ public class SecondApplet extends PApplet {
}
if (currentBrickHeight + 120 > maxSurfaceHeight) {
surface.setSize(width, maxSurfaceHeight);
println("hi");
heightOverLimit = true;
} else {
heightOverLimit = false;
@@ -179,10 +179,13 @@ public class SecondApplet extends PApplet {
for (int i = 0; i < bricks.size(); i++) {
bricks.get(i).updateSliderPos();
}
for (int i = min(pos1, pos2); i < shaderList.size(); i++) {
println(i);
//shaderList.get(i).change = true;
}
}

void moveShader(int pos1, int pos2) {

if (pos2 > pos1) {
pos2 -=1;
for (int i = pos1; i < pos2; i++) {
@@ -193,6 +196,10 @@ public class SecondApplet extends PApplet {
swapShader(i, i-1);
}
}
for (int i = max(pos1, pos2); i > 0; i--) {
//println(i);
//shaderList.get(i).change = true;
}
}

void removeShader(int pos) {
@@ -206,12 +213,25 @@ public class SecondApplet extends PApplet {
shaderList.get(i).pos = i;
}
}
for (int i = pos; i < shaderList.size(); i++) {
//shaderList.get(i).change = true;
}
}


int previousRenderSize = renderSize;
void applyShader() {
renderSizeChanged = true;
if (previousRenderSize != renderSize)
previousRenderSize = renderSize;
else
renderSizeChanged = false;
for (int i = 0; i < shaderList.size(); i++) {
try {

shaderList.get(i).getValuesFromGUI();
if (bricks.get(i).active) {
shaderList.get(i).getValuesFromGUI();
//shaderList.get(i).getValuesFromGUI();
shaderList.get(i).shade();
}
}
@@ -281,6 +301,13 @@ public class SecondApplet extends PApplet {
resumeAllSliders();
}
}
void toggleActive() {
active = !active;

//for (int i = pos; i < shaderList.size(); i++) {
// shaderList.get(i).change = true;
//}
}

void pauseAllSliders() {
for (int i = 0; i < slider.size(); i++) {
@@ -584,7 +611,10 @@ public class SecondApplet extends PApplet {
if (bricks.get(i).hovering) {
bricks.get(i).press();
}
if (bricks.get(i).hoverActiveButton) bricks.get(i).active = !bricks.get(i).active;
if (bricks.get(i).hoverActiveButton)
{
bricks.get(i).toggleActive();
}
if (bricks.get(i).hoverPauseButton) bricks.get(i).playPause();
}
}

+ 51
- 6
shader.pde View File

@@ -15,9 +15,12 @@ class Param {

class Shader {
int id;
int pos;
int pos, previousPos;
boolean previousActive;
String name;
ArrayList<Param> params = new ArrayList<Param>();
ArrayList<Float> paramValues = new ArrayList<Float>();
boolean paramChanged = true;

PGraphics canvas = createGraphics(renderer.width, renderer.height);
PGraphics result;
@@ -35,7 +38,40 @@ class Shader {
params = gui.bricks.get(pos).params;
}
catch(Exception e) {
println(e);
}

if (paramValues.size() != params.size()) {
for (int i = 0; i < params.size(); i++) {
paramValues.add(0.0);
}
}

paramChanged = false;
for (int i = 0; i < params.size(); i++) {
if (paramValues.get(i) != params.get(i).value) {
paramValues.set(i, params.get(i).value);
paramChanged = true;
}
}
if(pos != previousPos){
paramChanged = true;
}
previousPos = pos;
if(previousActive != gui.bricks.get(pos).active){
paramChanged = true;
}
previousActive = gui.bricks.get(pos).active;
if (!paramChanged) {
for (int i = this.pos; i >= 0; i--) {
if (gui.shaderList.get(i).paramChanged) paramChanged = true;
}
}


if (frameRate < 1) println("Rendering " + this + " on position " + pos + "...");
}

@@ -46,16 +82,26 @@ class Shader {
}

void shade() {
if (renderSizeChanged || paramChanged) {
this.setupCanvas();
this.apply();
this.render();
} else {
// println("nothing changed");
renderer.beginDraw();
renderer.image(result, 0, 0);
renderer.endDraw();
}/*
this.setupCanvas();
this.apply();
this.render();
this.apply();
this.render();
*/
}

void setupCanvas() {
if (directionParamIndex >= 0) direction = (int)this.params.get(directionParamIndex).value;
int cw = (direction == 0 || direction == 2) ? renderer.width : renderer.height;
int ch = (direction == 0 || direction == 2) ? renderer.height : renderer.width;
//if (canvas.width != cw || canvas.height != ch)
canvas = createGraphics(cw, ch);
canvas.beginDraw();
canvas.imageMode(CENTER);
@@ -73,7 +119,6 @@ class Shader {

void render() {
renderer.beginDraw();

renderer.imageMode(CENTER);
renderer.pushMatrix();
renderer.translate(renderer.width/2, renderer.height/2);
@@ -84,7 +129,7 @@ class Shader {
renderer.endDraw();
result = createGraphics(renderer.width, renderer.height);
result.beginDraw();
result.image(renderer,0,0);
result.image(renderer, 0, 0);
result.endDraw();
}
}

Loading…
Cancel
Save