<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with getstate() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=getstate%28%29</link>
      <pubDate>Sun, 08 Aug 2021 17:51:33 +0000</pubDate>
         <description>Tagged with getstate() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedgetstate%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Send individual msj to a shader</title>
      <link>https://forum.processing.org/two/discussion/28034/send-individual-msj-to-a-shader</link>
      <pubDate>Thu, 31 May 2018 05:47:56 +0000</pubDate>
      <dc:creator>vjjv</dc:creator>
      <guid isPermaLink="false">28034@/two/discussions</guid>
      <description><![CDATA[<p>hey everybody. this time i've a problem sending invididual mensajes to a fragment shader. I've an array of spheres, and i want that every sphere have a different size of blur, witch is a uniform of the fragment. The  main code is from an example, a post-processing effects.</p>

<p>How can i do?</p>

<pre><code>import controlP5.*;

ControlP5 cp5;
import peasy.*;

ArrayList&lt;Sphere&gt;s;

PGraphics canvas;

PGraphics brightPass;
PGraphics horizontalBlurPass;
PGraphics verticalBlurPass;

PShader bloomFilter;
PShader blurFilter;
PeasyCam cam;
float angle = 0;

final int surfaceWidth = 250;
final int surfaceHeight = 250;

float luminanceFilter = 0.02;
float blurSize = 100;
float sigma = 200;

void setup()
{
  cam = new PeasyCam(this, 1400);
  size(1000, 1000, P3D);

  s = new ArrayList&lt;Sphere&gt;();

  canvas = createGraphics(width, height, P3D);

  brightPass = createGraphics(width, height, P2D);
  brightPass.noSmooth();

  horizontalBlurPass = createGraphics(width, height, P2D);
  horizontalBlurPass.noSmooth(); 

  verticalBlurPass = createGraphics(width, height, P2D);
  verticalBlurPass.noSmooth(); 

  bloomFilter = loadShader("bloomFrag.glsl");
  blurFilter = loadShader("blurFrag.glsl");
}

void draw()
{
  background(0);
  bloomFilter.set("brightPassThreshold", luminanceFilter);
  angle += 0.05;

  for(Sphere s: s){
  blurFilter.set("blurSize", s.p);
  }

  blurFilter.set("sigma", sigma); 

  canvas.beginDraw();
  render(canvas);
  canvas.endDraw();

  // bright pass
  brightPass.beginDraw();
  brightPass.shader(bloomFilter);
  brightPass.image(canvas, 0, 0);
  brightPass.endDraw();

  // blur horizontal pass
  horizontalBlurPass.beginDraw();
  blurFilter.set("horizontalPass", 1);
  horizontalBlurPass.shader(blurFilter);
  horizontalBlurPass.image(brightPass, 0, 0);
  horizontalBlurPass.endDraw();

  // blur vertical pass
  verticalBlurPass.beginDraw();
  blurFilter.set("horizontalPass", 0);
  verticalBlurPass.shader(blurFilter);
  verticalBlurPass.image(horizontalBlurPass, 0, 0);
  verticalBlurPass.endDraw();


  cam.beginHUD();
  blendMode(BLEND);
  blendMode(SCREEN);
  image(brightPass, 0, 0);
  image(verticalBlurPass, 0, 0);

  cam.endHUD();

println(frameRate);
}

void render(PGraphics pg)
{
  cam.getState().apply(pg);

  pg.background(0, 50);

  canvas.pushMatrix();
  canvas.translate(width/2, height/2);
  for(Sphere s: s){
  s.display();

  }
  canvas.popMatrix();


}

void mousePressed() {
  s.add(new Sphere(random(-width/2, width/2), random(-height/2, height/2), random(1000)));
}


class Sphere {

  float p;
  float w;
  float h;

  Sphere(float _w, float _h, float _p) {
  p = _p;
  w = _w;
  h = _h;
  }

  void display() {
    canvas.pushMatrix();
    canvas.translate(w, h);
    noFill();
    canvas.sphere(100);

    canvas.popMatrix();
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Depth of Field effect with a shader</title>
      <link>https://forum.processing.org/two/discussion/28019/depth-of-field-effect-with-a-shader</link>
      <pubDate>Sat, 26 May 2018 14:51:51 +0000</pubDate>
      <dc:creator>solub</dc:creator>
      <guid isPermaLink="false">28019@/two/discussions</guid>
      <description><![CDATA[<p>Posting the question back here since it seems I won't get any help on the new forum (?).</p>

<p>As some of you may already know I'm trying to make a Depth of Field effect in Python mode. 
I've recently stumbled onto <a rel="nofollow" href="https://forum.processing.org/two/discussion/6515/working-dof-example-shared">this thread</a> where I could get hold of a Proscene <a rel="nofollow" href="https://github.com/remixlab/proscene.droid/tree/master/examples/Demos/DOF">DOF demo sketch</a> based on the following shaders:</p>

<p><strong>depth.glsl</strong></p>

<pre><code>uniform float maxDepth;

void main() {
  float depth = gl_FragCoord.z / gl_FragCoord.w;
  gl_FragColor = vec4(vec3(1.0 - depth/maxDepth), 1.0);
}
</code></pre>

<p><strong>dof.glsl</strong></p>

<pre><code>uniform sampler2D texture;

varying vec4 vertexture;
varying vec4 vertTexCoord;

uniform sampler2D tDepth;

uniform float maxBlur; // max blur amount
uniform float aperture; // aperture - bigger values for shallower depth of field

uniform float focus;
uniform float aspect;

void main() {
    vec2 vUv = vertTexCoord.st;

    vec2 aspectcorrect = vec2( 1.0, aspect );

    vec4 depth1 = texture2D( tDepth, vUv );

    float factor = depth1.x - focus;

    vec2 dofblur = vec2 ( clamp( factor * aperture, -maxBlur, maxBlur ) );

    vec2 dofblur9 = dofblur * 0.9;
    vec2 dofblur7 = dofblur * 0.7;
    vec2 dofblur4 = dofblur * 0.4;

    vec4 col = vec4( 0.0 );

    col += texture2D( texture, vUv.xy );
    col += texture2D( texture, vUv.xy + ( vec2( 0.0, 0.4 ) * aspectcorrect ) * dofblur );
    col += texture2D( texture, vUv.xy + ( vec2( 0.15, 0.37 ) * aspectcorrect ) * dofblur );
    col += texture2D( texture, vUv.xy + ( vec2( 0.29, 0.29 ) * aspectcorrect ) * dofblur );
    col += texture2D( texture, vUv.xy + ( vec2( -0.37, 0.15 ) * aspectcorrect ) * dofblur );
    col += texture2D( texture, vUv.xy + ( vec2( 0.40, 0.0 ) * aspectcorrect ) * dofblur );
    col += texture2D( texture, vUv.xy + ( vec2( 0.37, -0.15 ) * aspectcorrect ) * dofblur );
    col += texture2D( texture, vUv.xy + ( vec2( 0.29, -0.29 ) * aspectcorrect ) * dofblur );
    col += texture2D( texture, vUv.xy + ( vec2( -0.15, -0.37 ) * aspectcorrect ) * dofblur );
    col += texture2D( texture, vUv.xy + ( vec2( 0.0, -0.4 ) * aspectcorrect ) * dofblur );
    col += texture2D( texture, vUv.xy + ( vec2( -0.15, 0.37 ) * aspectcorrect ) * dofblur );
    col += texture2D( texture, vUv.xy + ( vec2( -0.29, 0.29 ) * aspectcorrect ) * dofblur );
    col += texture2D( texture, vUv.xy + ( vec2( 0.37, 0.15 ) * aspectcorrect ) * dofblur );
    col += texture2D( texture, vUv.xy + ( vec2( -0.4, 0.0 ) * aspectcorrect ) * dofblur );
    col += texture2D( texture, vUv.xy + ( vec2( -0.37, -0.15 ) * aspectcorrect ) * dofblur );
    col += texture2D( texture, vUv.xy + ( vec2( -0.29, -0.29 ) * aspectcorrect ) * dofblur );
    col += texture2D( texture, vUv.xy + ( vec2( 0.15, -0.37 ) * aspectcorrect ) * dofblur );

    col += texture2D( texture, vUv.xy + ( vec2( 0.15, 0.37 ) * aspectcorrect ) * dofblur9 );
    col += texture2D( texture, vUv.xy + ( vec2( -0.37, 0.15 ) * aspectcorrect ) * dofblur9 );
    col += texture2D( texture, vUv.xy + ( vec2( 0.37, -0.15 ) * aspectcorrect ) * dofblur9 );
    col += texture2D( texture, vUv.xy + ( vec2( -0.15, -0.37 ) * aspectcorrect ) * dofblur9 );
    col += texture2D( texture, vUv.xy + ( vec2( -0.15, 0.37 ) * aspectcorrect ) * dofblur9 );
    col += texture2D( texture, vUv.xy + ( vec2( 0.37, 0.15 ) * aspectcorrect ) * dofblur9 );
    col += texture2D( texture, vUv.xy + ( vec2( -0.37, -0.15 ) * aspectcorrect ) * dofblur9 );
    col += texture2D( texture, vUv.xy + ( vec2( 0.15, -0.37 ) * aspectcorrect ) * dofblur9 );

    col += texture2D( texture, vUv.xy + ( vec2( 0.29, 0.29 ) * aspectcorrect ) * dofblur7 );
    col += texture2D( texture, vUv.xy + ( vec2( 0.40, 0.0 ) * aspectcorrect ) * dofblur7 );
    col += texture2D( texture, vUv.xy + ( vec2( 0.29, -0.29 ) * aspectcorrect ) * dofblur7 );
    col += texture2D( texture, vUv.xy + ( vec2( 0.0, -0.4 ) * aspectcorrect ) * dofblur7 );
    col += texture2D( texture, vUv.xy + ( vec2( -0.29, 0.29 ) * aspectcorrect ) * dofblur7 );
    col += texture2D( texture, vUv.xy + ( vec2( -0.4, 0.0 ) * aspectcorrect ) * dofblur7 );
    col += texture2D( texture, vUv.xy + ( vec2( -0.29, -0.29 ) * aspectcorrect ) * dofblur7 );
    col += texture2D( texture, vUv.xy + ( vec2( 0.0, 0.4 ) * aspectcorrect ) * dofblur7 );

    col += texture2D( texture, vUv.xy + ( vec2( 0.29, 0.29 ) * aspectcorrect ) * dofblur4 );
    col += texture2D( texture, vUv.xy + ( vec2( 0.4, 0.0 ) * aspectcorrect ) * dofblur4 );
    col += texture2D( texture, vUv.xy + ( vec2( 0.29, -0.29 ) * aspectcorrect ) * dofblur4 );
    col += texture2D( texture, vUv.xy + ( vec2( 0.0, -0.4 ) * aspectcorrect ) * dofblur4 );
    col += texture2D( texture, vUv.xy + ( vec2( -0.29, 0.29 ) * aspectcorrect ) * dofblur4 );
    col += texture2D( texture, vUv.xy + ( vec2( -0.4, 0.0 ) * aspectcorrect ) * dofblur4 );
    col += texture2D( texture, vUv.xy + ( vec2( -0.29, -0.29 ) * aspectcorrect ) * dofblur4 );
    col += texture2D( texture, vUv.xy + ( vec2( 0.0, 0.4 ) * aspectcorrect ) * dofblur4 );

    gl_FragColor = col / 41.0;
    gl_FragColor.a = 1.0;
}
</code></pre>

<p>What I'd like is to be able to use those shaders using the PeasyCam library instead of the Proscene dependency.</p>

<p>In the sketch below I'm testing the shaders on a point cloud. I’m drawing the points on the <code>scene</code> PGraphics and then passing it through 2 other PGraphics (<code>canvas</code> and <code>buf</code>). In theory it should work but I’m still stuck with the PeasyCam part at the very end of the script.</p>

<p>If I write:</p>

<ul>
<li><code>cam.getState().apply(canvas)</code>: I get a DoF effect BUT on a 2D canvas</li>
<li><code>cam.getState().apply(scene)</code> : I get a 3D canvas BUT without a DoF effect</li>
</ul>

<p>Any help would be really appreciated.</p>

<pre><code>add_library('peasycam')
liste = []

def setup():
    global depthShader, dofShader, cam, canvas, buf, scene
    size(900, 900, P3D)

    cam = PeasyCam(this, 900)
    cam.setMaximumDistance(width)

    for e in range(100):
        liste.append(PVector(random(width), random(height), random(width)))

    depthShader = loadShader("depth.glsl")
    dofShader = loadShader("dof.glsl")

    depthShader.set("maxDepth", cam.getDistance())
    dofShader.set("aspect", width / float(height))
    dofShader.set("maxBlur", 0.015)
    dofShader.set("aperture", 0.02)

    canvas = createGraphics(width, height, P3D)
    canvas.shader(depthShader)
    buf = createGraphics(width, height, P3D)
    buf.shader(dofShader)

    scene = createGraphics(width, height, P3D)

    frameRate(1000)

def draw():

    scene.beginDraw()
    scene.background(255)
    scene.stroke(0)
    scene.strokeWeight(10)
    for e in liste:
        scene.point(e.x-width/2, e.y-height/2, e.z-height/2)
    scene.endDraw()

    canvas.beginDraw()
    canvas.image(scene, 0, 0)
    canvas.endDraw()

    buf.beginDraw()
    dofShader.set("focus", map(mouseX, 0, width, -0.5, 1.5))
    dofShader.set("tDepth", canvas)
    buf.image(scene, 0, 0)
    buf.endDraw()

    cam.beginHUD()
    image(buf, 0, 0)
    cam.endHUD()

    cam.getState().apply(scene)
</code></pre>
]]></description>
   </item>
   <item>
      <title>Apply PeasyCam on PGraphics3D</title>
      <link>https://forum.processing.org/two/discussion/19554/apply-peasycam-on-pgraphics3d</link>
      <pubDate>Tue, 06 Dec 2016 12:39:13 +0000</pubDate>
      <dc:creator>cansik</dc:creator>
      <guid isPermaLink="false">19554@/two/discussions</guid>
      <description><![CDATA[<p>At the moment I am working on a <a rel="nofollow" href="https://forum.processing.org/two/discussion/comment/81637/">multi-pass rendering in processing</a>. There I have to use a new <code>PGraphics3D</code> <strong>canvas</strong> and I can not use the default <code>g</code> object. After the rendering and shading, I'm just going to "print" it on to the <code>g</code> object again as texture:</p>

<pre><code>cam.beginHUD();
image(canvas, 0, 0);
cam.endHUD();
</code></pre>

<p>Now I have the problem that things like <a rel="nofollow" href="https://github.com/jdf/peasycam">peasycam</a> do not work anymore because they are attached to the original <code>g</code> and do not transform the camera matrix of my <strong>canvas</strong>.</p>

<p>So I tried to use the camera matrix of the original graphics and copy it to my canvas:</p>

<pre><code>PGraphics3D p = (PGraphics3D)this.g;
canvas.camera = p.camera;
</code></pre>

<p>This did not work, maybe because peasycam is doing something special and it does not change the original camera matrix. So my next idea was to use the static <code>apply</code> method from peasy cam. I had to copy the function out of the original code and make it public:</p>

<pre><code>import peasy.org.apache.commons.math.geometry.Rotation;
import peasy.org.apache.commons.math.geometry.Vector3D;

Vector3D positionVec = new Vector3D(cam.getPosition()[0], cam.getPosition()[1], cam.getPosition()[2]);
Vector3D rotationVec = new Vector3D(cam.getRotations()[0], cam.getRotations()[1], cam.getRotations()[2]);
apply(canvas, positionVec, new Rotation(rotationVec, 0), cam.getDistance());
</code></pre>

<p>Here the <code>apply</code> method:</p>

<pre><code>void apply(final PGraphics g, final Vector3D center, final Rotation rotation, 
  final double distance) {
  final Vector3D pos = rotation.applyTo(Vector3D.plusK).scalarMultiply(distance).add(center);
  final Vector3D rup = rotation.applyTo(Vector3D.plusJ);
  g.camera((float)pos.getX(), (float)pos.getY(), (float)pos.getZ(), //
    (float)center.getX(), (float)center.getY(), (float)center.getZ(), //
    (float)rup.getX(), (float)rup.getY(), (float)rup.getZ());
}
</code></pre>

<p>There I always have a <strong>zero norm for rotation</strong> (Arithmetic Exception).
So my final idea was to just copy all the rotations and translation to my camera matrix:</p>

<pre><code>canvas.beginCamera();
canvas.camera();

canvas.rotateX(cam.getRotations()[0]);
canvas.rotateY(cam.getRotations()[1]);
canvas.rotateZ(cam.getRotations()[2]);

canvas.translate(
  cam.getPosition()[0], 
  cam.getPosition()[1], 
  cam.getPosition()[2]);

canvas.endCamera();
</code></pre>

<p>So now I could rotate my cube, but it was not accurate and I think there is something wrong with some axis.</p>

<p>I would like to ask if someone has done this before and if there is a simple method to do this?</p>
]]></description>
   </item>
   <item>
      <title>(PeasyCam lib)  how to make easeout for CameraState transition?</title>
      <link>https://forum.processing.org/two/discussion/23858/peasycam-lib-how-to-make-easeout-for-camerastate-transition</link>
      <pubDate>Sat, 19 Aug 2017 06:51:32 +0000</pubDate>
      <dc:creator>venitable</dc:creator>
      <guid isPermaLink="false">23858@/two/discussions</guid>
      <description><![CDATA[<p>I try to use keyboard to control  camera rotation / position , 
   Here I use get/setState( ),But  this  generate  linear transition ,
   Is there any way to make  easeout  transition?</p>

<pre><code>   import peasy.*;
    PeasyCam  cam;
    CameraState state;
    void setup(){ 
      size(400,400,P3D);
      cam=new PeasyCam(this,300);
      state=cam.getState();
    }
    void draw(){  
      box(80);
    }
    void keyPressed(){
       if(key=='s')
          state = cam.getState();
       if(key=='r')
          cam.setState(state);
    }
</code></pre>
]]></description>
   </item>
   </channel>
</rss>