<?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 shader() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=shader%28%29</link>
      <pubDate>Sun, 08 Aug 2021 17:51:32 +0000</pubDate>
         <description>Tagged with shader() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedshader%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>Render depth buffer onto 2d PGraphics</title>
      <link>https://forum.processing.org/two/discussion/26542/render-depth-buffer-onto-2d-pgraphics</link>
      <pubDate>Mon, 26 Feb 2018 17:32:47 +0000</pubDate>
      <dc:creator>cansik</dc:creator>
      <guid isPermaLink="false">26542@/two/discussions</guid>
      <description><![CDATA[<p>I would like to use the depth buffer of a <code>PGraphics3D</code> in a texture shader on a <code>PGraphics2D</code>. Now I could not really find a way to share the depth buffer of the 3d scene with the 2d texture, so I decided to draw the 3D depth as fragment shader onto a texture and then use this texture as separate input to the 2d texture fragment shader.</p>

<p>In the example sketch, you can enable the depth pass shader for the 3D scene (left picture) with any key. So the depth buffer is correctly drawn onto the screen.</p>

<p>Now the problem that I have is, that I am not able to shade / filter the 3d context with the depth buffer shader, and draw it onto the 2d canvas. Without doing that, I am not able to use it inside the next texture shader I would like to apply to the 2d graphics.</p>

<p>I hope it is not too confusing. What I want is to have the depth information in a 2d texture shader.</p>

<p>Attached is the example sketch, which currently is working on the right side (no depth information is shaded onto the 2d context).</p>

<pre><code>void createDepthImage(PGraphics3D graphics)
{
  if (!graphics.is3D())
    return;

  // add shader to graphics
  graphics.shader(shader);

  depthImage.beginDraw();
  depthImage.image(graphics, 0, 0);
  depthImage.endDraw();

  // reset shader after operation
  if (!shaderApplied)
    graphics.resetShader();
}
</code></pre>

<p>Complete sketch: <a rel="nofollow" href="https://gist.github.com/cansik/d6a61bcfe1ffc4f36eb1592d7143ab8f">gist.github.com/d6a61bcfe1ffc4f36eb1592d7143ab8f</a></p>
]]></description>
   </item>
   <item>
      <title>Simple Shadow Mapping</title>
      <link>https://forum.processing.org/two/discussion/12775/simple-shadow-mapping</link>
      <pubDate>Thu, 01 Oct 2015 14:39:43 +0000</pubDate>
      <dc:creator>Poersch</dc:creator>
      <guid isPermaLink="false">12775@/two/discussions</guid>
      <description><![CDATA[<p>Implemented the <strong>shadow mapping technique</strong> from <a rel="nofollow" href="http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/">this old tutorial</a> (without using any "low level GL") in <strong>Processing 3.0.X</strong>.</p>

<p><img src="http://forum.processing.org/two/uploads/imageupload/754/AP1OS610MBH7.png" alt="shadow_mapping_1" title="shadow_mapping_1" />
<img src="http://forum.processing.org/two/uploads/imageupload/308/YSH4XAOYI5MG.png" alt="shadow_mapping_0" title="shadow_mapping_0" />
<img src="http://forum.processing.org/two/uploads/imageupload/390/1M5LS7Y8DC0B.png" alt="shadow_mapping_2" title="shadow_mapping_2" />
<img src="http://forum.processing.org/two/uploads/imageupload/606/FAL0HGNL81Q4.png" alt="shadow-mapping-dir" title="shadow-mapping-dir" />
<img src="http://forum.processing.org/two/uploads/imageupload/098/IPLAFPE0QR2D.png" alt="shadow-mapping-spot" title="shadow-mapping-spot" /></p>

<p><em>Press <strong>1</strong>, <strong>2</strong> or <strong>3</strong> to switch between the different demo "landscapes", <strong>s</strong> for <strong>spotlight</strong> and <strong>d</strong> for <strong>directional light</strong>.</em></p>

<pre><code>import peasy.*;

PVector lightDir = new PVector();
PShader defaultShader;
PGraphics shadowMap;
int landscape = 1;

void setup() {
    size(800, 800, P3D);
    new PeasyCam(this, 300).rotateX(4.0);
    initShadowPass();
    initDefaultPass();
}

void draw() {

    // Calculate the light direction (actually scaled by negative distance)
    float lightAngle = frameCount * 0.002;
    lightDir.set(sin(lightAngle) * 160, 160, cos(lightAngle) * 160);

    // Render shadow pass
    shadowMap.beginDraw();
    shadowMap.camera(lightDir.x, lightDir.y, lightDir.z, 0, 0, 0, 0, 1, 0);
    shadowMap.background(0xffffffff); // Will set the depth to 1.0 (maximum depth)
    renderLandscape(shadowMap);
    shadowMap.endDraw();
    shadowMap.updatePixels();

    // Update the shadow transformation matrix and send it, the light
    // direction normal and the shadow map to the default shader.
    updateDefaultShader();

    // Render default pass
    background(0xff222222);
    renderLandscape(g);

    // Render light source
    pushMatrix();
    fill(0xffffffff);
    translate(lightDir.x, lightDir.y, lightDir.z);
    box(5);
    popMatrix();

}

public void initShadowPass() {
    shadowMap = createGraphics(2048, 2048, P3D);
    String[] vertSource = {
        "uniform mat4 transform;",

        "attribute vec4 vertex;",

        "void main() {",
            "gl_Position = transform * vertex;",
        "}"
    };
    String[] fragSource = {

        // In the default shader we won't be able to access the shadowMap's depth anymore,
        // just the color, so this function will pack the 16bit depth float into the first
        // two 8bit channels of the rgba vector.
        "vec4 packDepth(float depth) {",
            "float depthFrac = fract(depth * 255.0);",
            "return vec4(depth - depthFrac / 255.0, depthFrac, 1.0, 1.0);",
        "}",

        "void main(void) {",
            "gl_FragColor = packDepth(gl_FragCoord.z);",
        "}"
    };
    shadowMap.noSmooth(); // Antialiasing on the shadowMap leads to weird artifacts
    //shadowMap.loadPixels(); // Will interfere with noSmooth() (probably a bug in Processing)
    shadowMap.beginDraw();
    shadowMap.noStroke();
    shadowMap.shader(new PShader(this, vertSource, fragSource));
    shadowMap.ortho(-200, 200, -200, 200, 10, 400); // Setup orthogonal view matrix for the directional light
    shadowMap.endDraw();
}

public void initDefaultPass() {
    String[] vertSource = {
        "uniform mat4 transform;",
        "uniform mat4 modelview;",
        "uniform mat3 normalMatrix;",
        "uniform mat4 shadowTransform;",
        "uniform vec3 lightDirection;",

        "attribute vec4 vertex;",
        "attribute vec4 color;",
        "attribute vec3 normal;",

        "varying vec4 vertColor;",
        "varying vec4 shadowCoord;",
        "varying float lightIntensity;",

        "void main() {",
            "vertColor = color;",
            "vec4 vertPosition = modelview * vertex;", // Get vertex position in model view space
            "vec3 vertNormal = normalize(normalMatrix * normal);", // Get normal direction in model view space
            "shadowCoord = shadowTransform * (vertPosition + vec4(vertNormal, 0.0));", // Normal bias removes the shadow acne
            "lightIntensity = 0.5 + dot(-lightDirection, vertNormal) * 0.5;",
            "gl_Position = transform * vertex;",
        "}"
    };
    String[] fragSource = {
        "#version 120",

        // Used a bigger poisson disk kernel than in the tutorial to get smoother results
        "const vec2 poissonDisk[9] = vec2[] (",
            "vec2(0.95581, -0.18159), vec2(0.50147, -0.35807), vec2(0.69607, 0.35559),",
            "vec2(-0.0036825, -0.59150), vec2(0.15930, 0.089750), vec2(-0.65031, 0.058189),",
            "vec2(0.11915, 0.78449), vec2(-0.34296, 0.51575), vec2(-0.60380, -0.41527)",
        ");",

        // Unpack the 16bit depth float from the first two 8bit channels of the rgba vector
        "float unpackDepth(vec4 color) {",
            "return color.r + color.g / 255.0;",
        "}",

        "uniform sampler2D shadowMap;",

        "varying vec4 vertColor;",
        "varying vec4 shadowCoord;",
        "varying float lightIntensity;",

        "void main(void) {",

            // Project shadow coords, needed for a perspective light matrix (spotlight)
            "vec3 shadowCoordProj = shadowCoord.xyz / shadowCoord.w;",

            // Only render shadow if fragment is facing the light
            "if(lightIntensity &gt; 0.5) {",
                "float visibility = 9.0;",

                // I used step() instead of branching, should be much faster this way
                "for(int n = 0; n &lt; 9; ++n)",
                    "visibility += step(shadowCoordProj.z, unpackDepth(texture2D(shadowMap, shadowCoordProj.xy + poissonDisk[n] / 512.0)));",

                "gl_FragColor = vec4(vertColor.rgb * min(visibility * 0.05556, lightIntensity), vertColor.a);",
            "} else",
                "gl_FragColor = vec4(vertColor.rgb * lightIntensity, vertColor.a);",

        "}"
    };
    shader(defaultShader = new PShader(this, vertSource, fragSource));
    noStroke();
    perspective(60 * DEG_TO_RAD, (float)width / height, 10, 1000);
}

void updateDefaultShader() {

    // Bias matrix to move homogeneous shadowCoords into the UV texture space
    PMatrix3D shadowTransform = new PMatrix3D(
        0.5, 0.0, 0.0, 0.5, 
        0.0, 0.5, 0.0, 0.5, 
        0.0, 0.0, 0.5, 0.5, 
        0.0, 0.0, 0.0, 1.0
    );

    // Apply project modelview matrix from the shadow pass (light direction)
    shadowTransform.apply(((PGraphicsOpenGL)shadowMap).projmodelview);

    // Apply the inverted modelview matrix from the default pass to get the original vertex
    // positions inside the shader. This is needed because Processing is pre-multiplying
    // the vertices by the modelview matrix (for better performance).
    PMatrix3D modelviewInv = ((PGraphicsOpenGL)g).modelviewInv;
    shadowTransform.apply(modelviewInv);

    // Convert column-minor PMatrix to column-major GLMatrix and send it to the shader.
    // PShader.set(String, PMatrix3D) doesn't convert the matrix for some reason.
    defaultShader.set("shadowTransform", new PMatrix3D(
        shadowTransform.m00, shadowTransform.m10, shadowTransform.m20, shadowTransform.m30, 
        shadowTransform.m01, shadowTransform.m11, shadowTransform.m21, shadowTransform.m31, 
        shadowTransform.m02, shadowTransform.m12, shadowTransform.m22, shadowTransform.m32, 
        shadowTransform.m03, shadowTransform.m13, shadowTransform.m23, shadowTransform.m33
    ));

    // Calculate light direction normal, which is the transpose of the inverse of the
    // modelview matrix and send it to the default shader.
    float lightNormalX = lightDir.x * modelviewInv.m00 + lightDir.y * modelviewInv.m10 + lightDir.z * modelviewInv.m20;
    float lightNormalY = lightDir.x * modelviewInv.m01 + lightDir.y * modelviewInv.m11 + lightDir.z * modelviewInv.m21;
    float lightNormalZ = lightDir.x * modelviewInv.m02 + lightDir.y * modelviewInv.m12 + lightDir.z * modelviewInv.m22;
    float normalLength = sqrt(lightNormalX * lightNormalX + lightNormalY * lightNormalY + lightNormalZ * lightNormalZ);
    defaultShader.set("lightDirection", lightNormalX / -normalLength, lightNormalY / -normalLength, lightNormalZ / -normalLength);

    // Send the shadowmap to the default shader
    defaultShader.set("shadowMap", shadowMap);

}

public void keyPressed() {
    if(key != CODED) {
        if(key &gt;= '1' &amp;&amp; key &lt;= '3')
            landscape = key - '0';
        else if(key == 'd') {
            shadowMap.beginDraw(); shadowMap.ortho(-200, 200, -200, 200, 10, 400); shadowMap.endDraw();
        } else if(key == 's') {
            shadowMap.beginDraw(); shadowMap.perspective(60 * DEG_TO_RAD, 1, 10, 1000); shadowMap.endDraw();
        }
    }
}

public void renderLandscape(PGraphics canvas) {
    switch(landscape) {
        case 1: {
            float offset = -frameCount * 0.01;
            canvas.fill(0xffff5500);
            for(int z = -5; z &lt; 6; ++z)
                for(int x = -5; x &lt; 6; ++x) {
                    canvas.pushMatrix();
                    canvas.translate(x * 12, sin(offset + x) * 20 + cos(offset + z) * 20, z * 12);
                    canvas.box(10, 100, 10);
                    canvas.popMatrix();
                }
        } break;
        case 2: {
            float angle = -frameCount * 0.0015, rotation = TWO_PI / 20;
            canvas.fill(0xffff5500);
            for(int n = 0; n &lt; 20; ++n, angle += rotation) {
                canvas.pushMatrix();
                canvas.translate(sin(angle) * 70, cos(angle * 4) * 10, cos(angle) * 70);
                canvas.box(10, 100, 10);
                canvas.popMatrix();
            }
            canvas.fill(0xff0055ff);
            canvas.sphere(50);
        } break;
        case 3: {
            float angle = -frameCount * 0.0015, rotation = TWO_PI / 20;
            canvas.fill(0xffff5500);
            for(int n = 0; n &lt; 20; ++n, angle += rotation) {
                canvas.pushMatrix();
                canvas.translate(sin(angle) * 70, cos(angle) * 70, 0);
                canvas.box(10, 10, 100);
                canvas.popMatrix();
            }
            canvas.fill(0xff00ff55);
            canvas.sphere(50);
        }
    }
    canvas.fill(0xff222222);
    canvas.box(360, 5, 360);
}
</code></pre>

<p>I mostly commented the Processing part of the sketch, the GLSL stuff is explained in <a rel="nofollow" href="http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/">the linked tutorial</a>. Anyways, I hope you have fun with it. :)</p>
]]></description>
   </item>
   <item>
      <title>GLSL and video Texture</title>
      <link>https://forum.processing.org/two/discussion/26054/glsl-and-video-texture</link>
      <pubDate>Sat, 20 Jan 2018 23:12:54 +0000</pubDate>
      <dc:creator>vjjv</dc:creator>
      <guid isPermaLink="false">26054@/two/discussions</guid>
      <description><![CDATA[<p>hello everyone. Im trying to pass a video as a texture into a fragment shader. but the sketch crash when i run it.</p>

<p>here is the code:</p>

<pre><code>  import processing.video.*;
import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.*;

PeasyCam cam;
PShader sh;
float count;
Movie mov;
PGraphics p;

void setup (){

size(1440, 900, P3D );
mov = new Movie(this, "osc_noc.mov");
mov.play();
p = createGraphics(width,height);
cam = new PeasyCam(this, 500);
sh = loadShader("basicShaderFrag.glsl", "basicShader.glsl");
}

void movieEvent(Movie m) {
  m.read();
}

void draw(){
background(0);
shader(sh);
count +=0.09;
sh.set("u_time", count);

sphere(100);
p.beginDraw();
p.background(0);
p.image(mov, 0, 0, 200, 200);
p.endDraw();
sh.set("tex",p);
// image(p, 5, 260 ,200, 200);
}

#version 150

uniform mat4 transform;
uniform sampler2D tex;

in vec4 position;
in vec2 texCoord;
in vec3 normal;

out vec2 TexCoord;

void main(){

  TexCoord = texCoord;
  gl_Position = transform * position;
}


#ifdef GL_ES
precision mediump float;
#endif

#define PI 3.14

in vec2 TexCoord;
uniform float u_time;
uniform sampler2D tex;

void main(){
  vec2 uv = TexCoord;

  gl_FragColor = vec4(texture(tex, TexCoord));
}
</code></pre>

<p>a white screen appears, and next it close. the console just say: "Finished". 
it may be a bug? i could pass a PImage as a texture. but when i link the fragment and shader program into the sketch folder then crash. ..</p>
]]></description>
   </item>
   <item>
      <title>3D objects and blendMode(ADD) causes artifacts</title>
      <link>https://forum.processing.org/two/discussion/22917/3d-objects-and-blendmode-add-causes-artifacts</link>
      <pubDate>Sun, 04 Jun 2017 13:49:18 +0000</pubDate>
      <dc:creator>trailbalzer47</dc:creator>
      <guid isPermaLink="false">22917@/two/discussions</guid>
      <description><![CDATA[<p><img src="https://forum.processing.org/two/uploads/imageupload/286/FFF55LZUQLI5.png" alt="Screen Shot 2017-06-04 at 7.15.03 PM" title="Screen Shot 2017-06-04 at 7.15.03 PM" /></p>

<p>code is simple I update blendMode(ADD ) in setup and draw sphere() I am going to use shader later but with out shader there is this problem.</p>

<pre><code>void setup() 
{
//....... other setup setup stuff
      blendMode(ADD);
}
int y=0;
void draw()
{
//  hint(ENABLE_DEPTH_TEST);
  noStroke();
  background(0);

  sh.set("mainPower",2.7);
  sh.set("eyePos",0.0, 0.0, 100.0);
  //shader(sh);

  translate(width/2,height/2+y,0);
  fill(250,100,0);
  sphere(90);
  //box(30);
  if(y&gt;height/2)
  y=-height/2;
  else 
  y++;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>In Shaders, how to avoid 'scrubbing' effect</title>
      <link>https://forum.processing.org/two/discussion/21149/in-shaders-how-to-avoid-scrubbing-effect</link>
      <pubDate>Sat, 04 Mar 2017 16:10:45 +0000</pubDate>
      <dc:creator>aarondbaron</dc:creator>
      <guid isPermaLink="false">21149@/two/discussions</guid>
      <description><![CDATA[<p>In the penrose tile example for the shader (InfiniteTiles), one can see that there is a value</p>

<pre><code>tileShader.set("time", millis() / 1000.0);
</code></pre>

<p>If I try to modify this so that the tile will move at a speed according to my mouse,</p>

<pre><code>float t =millis() / 1000.0; 
float pctX = map (mouseX, 0, width, 0, 1);
tileShader.set("time", t*pctX);
</code></pre>

<p>the shader will do this 'scrubbing' effect where the entire image moves very quickly, but then once you stop moving the mouse, it will go at the speed you want.  Is there any way to avoid this scrubbing effect?  What I'm trying to accomplish are smooth increases in speed of the tile movement.</p>
]]></description>
   </item>
   <item>
      <title>Using texture2D for sampling in Processing 3 results in a black screen</title>
      <link>https://forum.processing.org/two/discussion/21485/using-texture2d-for-sampling-in-processing-3-results-in-a-black-screen</link>
      <pubDate>Sun, 19 Mar 2017 23:00:27 +0000</pubDate>
      <dc:creator>gsuberland</dc:creator>
      <guid isPermaLink="false">21485@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to build a chained set of fragment shaders, where the first generates an image (similar to Shadertoy) and the remainder are applied as postprocessing effects.</p>

<p>Back in Processing 2 I was able to do this with a pair of fragment shaders without trouble:</p>

<pre><code>PShader shader1;
PShader shader2;

void setup() {
  size(256, 256, P2D);
  fill(128);
  noStroke();
  shader1 = loadShader("shader1.glsl");
  shader2 = loadShader("shader2.glsl");
}

void draw() {
  shader(shader1);
  shader(shader2);
  rect(0, 0, width, height);
}
</code></pre>

<p>Where shader1 is as follows:</p>

<pre><code>#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif

uniform sampler2D textureSampler;

varying vec4 vertColor;
varying vec4 vertTexCoord;

void main()
{
    vec3 pos = vertTexCoord.xyz;

    gl_FragColor = vec4(pos.x, pos.y, pos.z, 1.0);
}
</code></pre>

<p>And shader2 is as follows:</p>

<pre><code>#ifdef GL_ES
precision mediump float;
#endif

uniform sampler2D texture;

varying vec4 vertColor;
varying vec4 vertTexCoord;

void main () {
    gl_FragColor = texture2D(texture, vertTexCoord.xy);
}
</code></pre>

<p>No matter what I do in Processing 3, this always results in a black image when shader2 is applied, but works fine with just shader1. I have tried all sorts of things, including different OpenGL version directives, passing the resolution to shader2 and dividing the frag coord by it before sampling, and re-arranging the shader calls. I have tried both P2D and P3D mode.</p>

<p>In fact, many of the examples I have tried from the documentation fail to work at all in Processing 3.3.</p>

<p>Any idea what's going on? If it matters, I'm on a GTX 980 Ti with the latest drivers.</p>
]]></description>
   </item>
   <item>
      <title>How to apply a shader to a PGraphics object?</title>
      <link>https://forum.processing.org/two/discussion/20702/how-to-apply-a-shader-to-a-pgraphics-object</link>
      <pubDate>Tue, 07 Feb 2017 17:55:24 +0000</pubDate>
      <dc:creator>Patakk</dc:creator>
      <guid isPermaLink="false">20702@/two/discussions</guid>
      <description><![CDATA[<p>I'm fairly new to shaders and am beginning to like them because of their capabilities in terms of speed an parallelism. What I'd like to do is to apply a certain shader not to the whole sketch, but only to a certain PGraphics image, is that possible?</p>

<p>When using <code>filter()</code>, everything works fine. I just apply it after drawing everything else to the PGraphics.<br />
When trying to use <code>shader()</code>, I call <code>pg.shader(myShader)</code> before drawing any objects to the PGraphics (because that's how shaders work, right?), and in between <code>pg.beginDraw()</code> and <code>pg.endDraw()</code>, but without success. I've tried other combinations, but they don't work either.</p>

<p>What am I missing?</p>
]]></description>
   </item>
   <item>
      <title>Set same source texture for n shapes.</title>
      <link>https://forum.processing.org/two/discussion/17406/set-same-source-texture-for-n-shapes</link>
      <pubDate>Mon, 04 Jul 2016 09:40:10 +0000</pubDate>
      <dc:creator>Digl</dc:creator>
      <guid isPermaLink="false">17406@/two/discussions</guid>
      <description><![CDATA[<p>Hi all.
Very new to shaders, but I've done a fair bit of research.</p>

<p>My sketch is trying to emulate an image "shatter" - a bunch of different PShapes fly around, all with static UV coordinates referencing the same image. Imagine a stained glass window smashing - little bits of image everywhere.</p>

<p>I have things working, albeit slowly, and have been told I can improve my performance with shaders.</p>

<p>I've tried to create a simple working version before implementing into the full sketch. Just trying to draw one PShape with a texture.</p>

<p>Sketch</p>

<pre><code>PShader myShader;
PShape myShape;
PImage myImage;

void setup(){
    size(200, 200, P3D);

    myImage = loadImage("Grug.jpg");
    myShader = loadShader("frag.glsl", "vert.glsl");
    myShape = createShape();

    myShape.beginShape();
    myShape.noFill();
    myShape.noStroke();
    myShape.vertex(20, 20, 20, 20);
    myShape.vertex(80, 20, 80, 20);
    myShape.vertex(80, 80, 80, 80);
    myShape.vertex(20, 80, 20, 80);
    myShape.endShape();
}

void draw(){
    background(150);
    myShader.set("myImage", myImage);
    shader(myShader);
    shape(myShape);
}
</code></pre>

<p>Vert shader</p>

<pre><code>#define PROCESSING_TEXTURE_SHADER

uniform mat4 transform;
uniform mat4 texMatrix;

attribute vec4 vertex;
attribute vec4 color;
attribute vec2 texCoord;

varying vec4 vertColor;
varying vec4 vertTexCoord;

void main() {
  gl_Position = transform * vertex;

  vertColor = color;
  vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0);
}
</code></pre>

<p>Frag shader</p>

<pre><code>#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif

uniform sampler2D texture;
uniform sampler2D myImage;

varying vec4 vertColor;
varying vec4 vertTexCoord;

void main() {
    gl_FragColor = texture2D(myImage, vertTexCoord.st);
}
</code></pre>

<p>However, nothing displays. Note that I want to <em>avoid</em> calling myShape.texture(myImage) when defining the shape. This call does make things work, but on a large scale the framerate dives.</p>

<p>I'm pretty sure it's possible to have a few thousand verts flying about referencing the same texture - please correct me if I'm mistaken. What am I missing? Or is my approach a bit wonky?! Shaders have been a bit to wrap my head around.</p>

<p>Thanks in advance!
(Mac OSX 10.11.5, Processing 3.1.1.)</p>
]]></description>
   </item>
   <item>
      <title>2-pass shader possible with Processing?</title>
      <link>https://forum.processing.org/two/discussion/15929/2-pass-shader-possible-with-processing</link>
      <pubDate>Sat, 09 Apr 2016 10:08:40 +0000</pubDate>
      <dc:creator>MartinVDL</dc:creator>
      <guid isPermaLink="false">15929@/two/discussions</guid>
      <description><![CDATA[<p>Some of the shadertoy shaders use 2or more passes using the built in buffers, for example <a href="https://www.shadertoy.com/view/XsG3z1#" target="_blank" rel="nofollow">https://www.shadertoy.com/view/XsG3z1#</a>. 
Is it possible to use these buffers from within processing or do they have to be created in the GLSL shader code? If so, any examples I could learn from?</p>
]]></description>
   </item>
   <item>
      <title>tiling a texture for a glsl shader</title>
      <link>https://forum.processing.org/two/discussion/15242/tiling-a-texture-for-a-glsl-shader</link>
      <pubDate>Wed, 02 Mar 2016 12:11:30 +0000</pubDate>
      <dc:creator>MartinVDL</dc:creator>
      <guid isPermaLink="false">15242@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to port this shader from shadertoy to processing (<a href="https://www.shadertoy.com/view/ldlXRS" target="_blank" rel="nofollow">https://www.shadertoy.com/view/ldlXRS</a>). It works but in shadertoy it uses a noisemap in ichannel0 that is tiled. I can pass it a noisemap in processing but its not tiled. Anyone know how to solve this?</p>

<p>sketch code:</p>

<pre><code>PShader myShader;
PImage  myImage;

void setup() {
  size(640, 360, P2D);
  noStroke();
  myImage = loadImage("noise512.png");
  myShader = loadShader("noise_anim.glsl");
  myShader.set("resolution", float(width), float(height));

}

void draw() {
  background(0);
  myShader.set("time", millis() / 1000.0);

  shader(myShader);
  image( myImage, 0, 0, width, height ); // when using image or text maps

}
</code></pre>

<p>noise_anim.glsl code:</p>

<pre><code>#ifdef GL_ES
precision highp float;
#endif

#define PROCESSING_TEXTURE_SHADER

uniform float time;
uniform vec2 resolution;
uniform vec2 mouse;
uniform sampler2D texture;


// Layer between Processing and Shadertoy uniforms
vec3 iResolution = vec3(resolution,0.0);
float iGlobalTime = time;
vec4 iMouse = vec4(mouse,0.0,0.0); // zw would normally be the click status

//Noise animation - Electric
//by nimitz (stormoid.com) (twitter: <a href="/two/profile/stormoid">@stormoid</a>)

//The domain is displaced by two fbm calls one for each axis.
//Turbulent fbm (aka ridged) is used for better effect.

#define time iGlobalTime*0.15
#define tau 6.2831853

mat2 makem2(in float theta){
    float c = cos(theta);
    float s = sin(theta);
    return mat2(c,-s,s,c);
    }
float noise( in vec2 x ){
    return texture2D(texture, x*.01).x;
    }

float fbm(in vec2 p)
{   
    float z=2.;
    float rz = 0.;
    vec2 bp = p;
    for (float i= 1.;i &lt; 6.;i++)
    {
        rz+= abs((noise(p)-0.5)*2.)/z;
        z = z*2.;
        p = p*2.;
    }
    return rz;
}

float dualfbm(in vec2 p)
{
    //get two rotated fbm calls and displace the domain
    vec2 p2 = p*.7;
    vec2 basis = vec2(fbm(p2-time*1.6),fbm(p2+time*1.7));
    basis = (basis-.5)*.2;
    p += basis;

    //coloring
    return fbm(p*makem2(time*0.2));
}

float circ(vec2 p) 
{
    float r = length(p);
    //r = log(sqrt(r));
    r = 0.5*log(r);
    return abs(mod(r*4.,tau)-3.14)*3.+.2;

}

void main()
{
    //setup system
    vec2 p = gl_FragCoord.xy / iResolution.xy-0.5;
    p.x *= iResolution.x/iResolution.y;
    p*=4.;

    float rz = dualfbm(p);

    //rings
    p /= exp(mod(time*10.,3.14159));
    rz *= pow(abs((0.1-circ(p))),.9);

    //final color
    vec3 col = vec3(.2,0.1,0.4)/rz;
    col=pow(abs(col),vec3(.99));
    gl_FragColor = vec4(col,1.);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Why is the result upside down</title>
      <link>https://forum.processing.org/two/discussion/13016/why-is-the-result-upside-down</link>
      <pubDate>Wed, 14 Oct 2015 19:04:47 +0000</pubDate>
      <dc:creator>clankill3r</dc:creator>
      <guid isPermaLink="false">13016@/two/discussions</guid>
      <description><![CDATA[<p>It might be due the time since it's getting a bit late...
I know I could remove the 1.0 but it is somewhere else where it goes wrong I guess..</p>

<pre><code>#version 410

uniform mat4 transform;

in vec4 vertex;
in vec2 texCoord;

out vec2 vertTexCoord;

void main() {

    vertTexCoord = vec2(texCoord.x, 1.0 - texCoord.y);
    gl_Position = transform * vertex;
}
</code></pre>

<p>// ----</p>

<pre><code>#version 410


uniform sampler2D texture;

in vec2 vertTexCoord;

out vec4 fragColor;

void main() {
    fragColor = texture(texture, vertTexCoord);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Fast and beautiful blur filter / shader recommendations?</title>
      <link>https://forum.processing.org/two/discussion/6173/fast-and-beautiful-blur-filter-shader-recommendations</link>
      <pubDate>Mon, 07 Jul 2014 03:59:33 +0000</pubDate>
      <dc:creator>tim_pulver</dc:creator>
      <guid isPermaLink="false">6173@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I am just working on a project where I need a good looking fast blur effect. Currently I am using <a rel="nofollow" href="http://incubator.quasimondo.com/processing/fast_blur_deluxe.php">Mario Klingemann’s StackBlur</a> – a mixture between a box blur and a gaussian blur. I really like how it looks, the only problem is – it’s lagging a bit on my computer, when using in realtime, see the video here: <a rel="nofollow" href="https://www.youtube.com/watch?v=ze65pmIH4i8">youtube.com/watch?v=ze65pmIH4i8</a>. Do you know if there is a shader implementation of it or a good alternative?<br />
Thanks,<br />
Cheers Tim</p>
]]></description>
   </item>
   </channel>
</rss>