Skip to content

can someone explain those lantern shaders in flocking app? #3

Description

@shirish47

I tried that shader in shaderfrog here. Some thing looks wired about it. I also tried to use it in processing. here is what it looks like .
screen shot 2017-06-03 at 11 55 58 pm black cube is the light position.
one thing that seems wrong is when cube goes behind the sphere the red blob does not go back. I think its because in code mvpMatrix of cam is passed to shader but I am not getting it how to access mvpMatrix of camera in processing. it must be that problem that is causing the anomaily.
Hey robert please don't mind I am just trying to understand the shader. :) your work always amaze me and I love it just trying to understand how you create those visuals. I know its hard for you to explain the code but I would appreciate if some one might do that. Just learning shaders.

PShader lantern;

void setup() {
  size(700  , 600, P3D);
  noStroke();
  fill(204);
  lantern = loadShader("frag.glsl", "vert.glsl");
  float z =(height/2.0) / tan(PI*30.0 / 180.0);        //default camera pos for processing
  //println(z);
  lantern.set("eyePos",width/2.0, height/2.0, z);  //default camera pos for processing
  lantern.set("roomDim",7000.0,7000.0,7000.0);
  lantern.set("mainPower",05.99);
  
}
float t=0;float r=173;// ticker and radius of sphere
void draw() {
  float dirY = 0;
  float dirX = r*sin(t*2*PI);
  float dirZ = r*cos(t*2*PI);
  lantern.set("lightPos",-dirX,-dirY,dirZ,0);  //setting light pos for the shader 
  shader(lantern);          
  background(0);
  t+=0.01;
  translate(width/2, height/2,0);                 //moiving to center of screen
  //fill(255);
  //directionalLight(20, 204, 204, -dirX, -dirY, dirZ);  // setting directional  ,not need for this shader
  for(int i=0;i<1;i++){         //for if you wanted to create multiple spheres
  fill(120,100,80);
  pushMatrix();
  translate(0, 0, 0);           // translate multiple spheres to different positions : set the random values or some calculated locations(x= rad*sin(theta), y= rad*cos(theta))
  sphere(170);                   //main sphere with shader
  //box(900,900,0);
  popMatrix();
  }

  resetShader();
  pushMatrix();
  translate(-dirX, -dirY, dirZ);
  fill(255,0,0);
  box(10,10,10);           //virtual light box , just to see where the light is.
  popMatrix();
}````

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions