Skip to content

Example Sketches

Joon Hyub Lee edited this page Jul 17, 2013 · 35 revisions
**[Home](https://github.com/joonhyublee/joons-renderer/wiki) > Example Sketches**
  • [Basic Example](#Basic Example)
  • [Fill Example](#Fill Example)
  • [Depth of Field Example](#Depth of Field Example)
  • [Animation Example](#Animation Example)
## Basic Example _Before_ ![Basic example before](https://lh3.googleusercontent.com/-9dIoLmyoXaA/Uca_rJxfWGI/AAAAAAAACnE/ACVNU_heHUg/w800-h600-no/captured.png)

After
Basic exmaple after

import joons.JoonsRenderer;

JoonsRenderer jr;

//Camera Setting.
float eyeX = 0;
float eyeY = 0;
float eyeZ = 120;
float centerX = 0;
float centerY = 0;
float centerZ = -1;
float upX = 0;
float upY = 1;
float upZ = 0;
float fov = PI / 4; 
float aspect = 4/3f;  
float zNear = 5;
float zFar = 10000;

void setup() {
  size(800, 600, P3D);
  jr = new JoonsRenderer(this);
}

void draw() {
  jr.beginRecord(); //Make sure to include things you want rendered.

  camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
  perspective(fov, aspect, zNear, zFar);

  jr.background("cornell_box", 100, 100, 100); //Cornell Box: width, height, depth.
  jr.background("gi_instant"); //Global illumination.

  translate(0,10,-10);
  rotateY(-PI/8);
  rotateX(-PI/8);
  jr.fill("diffuse", 255, 255, 255);
  box(20);

  jr.endRecord(); //Make sure to end record.
  jr.displayRendered(true); //Display rendered image if render is completed, and the argument is true.
}

void keyPressed() {
  if (key == 'r' || key == 'R') jr.render(); //Press 'r' key to start rendering.
}

^ top ##Fill Example Before
Fill example before

After
Fill example after

import joons.JoonsRenderer;

JoonsRenderer jr;

//Camera Setting.
float eyeX = 0;
float eyeY = 0;
float eyeZ = 120;
float centerX = 0;
float centerY = 0;
float centerZ = -1;
float upX = 0;
float upY = 1;
float upZ = 0;
float fov = PI / 4; 
float aspect = 4/3f;  
float zNear = 5;
float zFar = 10000;

void setup() {
  size(800, 600, P3D);
  jr = new JoonsRenderer(this);
  jr.setSampler("ipr"); //Rendering mode, either "ipr" or "bucket".
  jr.setSizeMultiplier(2); //Set size of PNG file as a multiple of Processing sketch size.
  jr.setAA(-2, 0); //Set anti aliasing, (aaMin, aaMax, aaSamples). aaMin & aaMax = .. -2, -1, .. , 1, 2 ..; aaMin < aaMax.
  jr.setCaustics(10); //Set caustics. 1, 5, 10 .., affects quality of light reflected & refracted through glass.
}

void draw() {
  jr.beginRecord(); //Make sure to include things you want rendered.
  camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
  perspective(fov, aspect, zNear, zFar);

  jr.background(0, 255, 255); //(gray), or (r, g, b), like Processing.
  jr.background("gi_instant"); //Global illumination.
  //jr.background("gi_ambient_occlusion"); //Global illumination, ambient occlusion mode.

  jr.background("cornell_box", 100, 100, 100); //Cornell box, width, height, depth.

  pushMatrix();
  translate(-40, 20, -20);
  pushMatrix();
  rotateY(-PI/8);

  //jr.fill("light", r, g, b);
  jr.fill("light", 5, 5, 5);
  sphere(13);
  translate(27, 0, 0);

  //jr.fill("mirror", r, g, b);    
  jr.fill("mirror", 255, 255, 255);
  sphere(13);
  translate(27, 0, 0);

  //jr.fill("diffuse", r, g, b);
  jr.fill("diffuse", 150, 255, 255);
  sphere(13);
  translate(27, 0, 0);

  //jr.fill("shiny", r, g, b, shininess);
  jr.fill("shiny", 150, 255, 255, 0.1f);
  sphere(13);

  translate(27, 0, 0);
  popMatrix();
  rotateY(PI/8);
  translate(-10, -27, 30);

  //jr.fill("ambient occlusion", bright r, g, b, dark r, g, b, maximum distance, int samples);
  jr.fill("ambient_occlusion", 150, 255, 255, 0, 0, 255, 50, 16);
  sphere(13);
  translate(27, 0, 0);

  //jr.fill("phong", r, g, b);
  jr.fill("phong", 150, 255, 255);
  sphere(13);
  translate(27, 0, 0);

  //jr.fill("glass", r, g, b);
  jr.fill("glass", 255, 255, 255);
  sphere(13);
  translate(27, 0, 0);

  //jr.fill("constant", r, g, b);
  jr.fill("constant", 150, 255, 255);
  sphere(13);
  popMatrix();

  jr.endRecord(); //Make sure to end record.
  jr.displayRendered(true); //Display rendered image if render is completed, and the argument is true.
}

void keyPressed() {
  if (key == 'r' || key == 'R') jr.render(); //Press 'r' key to start rendering.
}

^ top

Depth of Field Example

Before
DOF before

After
DOF after

import joons.JoonsRenderer;

JoonsRenderer jr;
ArrayList<Float> boxes = new ArrayList<Float> ();

//Camera Setting.
float eyeX = 0;
float eyeY = 120;
float eyeZ = 80;
float centerX = 0;
float centerY = 0;
float centerZ = 10;
float upX = 0;
float upY = 0;
float upZ = -1;
float fov = PI / 4; 
float aspect = 4/3f;  
float zNear = 5;
float zFar = 10000;

void setup() {
  size(800, 600, P3D);
  jr = new JoonsRenderer(this);
  jr.setSampler("bucket");
  jr.setSizeMultiplier(1);
  jr.setAA(0, 2, 4); //setAA(minAA, maxAA, AASamples), increase AASamples to increase blur fidelity.
  jr.setCaustics(20);
  jr.setDOF(130, 3); //setDOF(focusDepth, lensRadius), bigger the lens radius, the blurrier the unfocused objects.

  for (int i = 0; i < 200; i++) {
    boxes.add(random(150)-75);
    boxes.add(random(150)-75);
    boxes.add(random(150)-20);
  }
}

void draw() {
  jr.beginRecord(); //Make sure to include things you want rendered.

  jr.background(0);
  camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
  perspective(fov, aspect, zNear, zFar);

  //Floor.
  jr.fill("diffuse", 100, 100, 100);
  int w = 10000;
  beginShape(QUADS);
  vertex(w, -w, 0);
  vertex(-w, -w, 0);
  vertex(-w, w, 0);
  vertex(w, w, 0);
  endShape();

  //Lighting.
  jr.fill("light", 30, 30, 30, 64);
  int z = 50;
  beginShape(QUADS);
  vertex(-z, -z, 150);
  vertex(-z, z, 150);
  vertex(z, z, 150);
  vertex(z, -z, 150);
  endShape();

  //Random Boxes.
  jr.fill("diffuse", 255, 255, 255);
  for (int i = 0; i < boxes.size()/3; i++) {
    translate(boxes.get(i*3), boxes.get(i*3+1), boxes.get(i*3+2));
    box(2);
    translate(-boxes.get(i*3), -boxes.get(i*3+1), -boxes.get(i*3+2));
  }

  translate(-10, 0, 20);
  jr.fill("glass");
  sphere(15);
  translate(20, 0, 0);
  jr.fill("mirror");
  sphere(15);

  endShape();

  jr.endRecord(); //Make sure to end record.
  jr.displayRendered(true); //Display rendered image if render is completed, and the argument is true.
}

void keyPressed() {
  if (key == 'r' || key == 'R') jr.render(); //Press 'r' key to start rendering.
}

^ top

Animation Example

This example produces 120 PNGs, which you can convert into a 4 second (30 fps) movie using Processing's Movie Maker tool (Processing IDE > Tools > Movie Maker, for Processing 2.0 and over).

Click to go to video Animation example

import joons.JoonsRenderer;

JoonsRenderer jr;

//Camera Setting.
float eyeX = 0;
float eyeY = 0;
float eyeZ = 120;
float centerX = 0;
float centerY = 0;
float centerZ = -1;
float upX = 0;
float upY = 1;
float upZ = 0;
float fov = PI / 4; 
float aspect = 4/3f;  
float zNear = 5;
float zFar = 10000;

int i = 0;
float r = 35;
String fileName;

void setup() {
  size(800, 600, P3D);
  jr = new JoonsRenderer(this);
}

void draw() {
  jr.render(); //The draw() loop that comes right after this method is called is rendered.
  jr.beginRecord(); //Make sure to include things you want rendered.

  camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
  perspective(fov, aspect, zNear, zFar);

  jr.background("cornell_box", 100, 100, 100); //Cornell Box: width, height, depth.
  jr.background("gi_ambient_occlusion"); //Global illumination.

  //Sun.
  translate(0, -15, 0);
  jr.fill("light", 1, 60, 60);
  sphere(5);

  //Planet, revolving at +3 degrees per frame.
  translate(r*cos(i*3*2*PI/360f), 0, r*sin(i*3*2*PI/360f));
  jr.fill("mirror");
  sphere(5);

  jr.endRecord(); //Make sure to end record.
  jr.displayRendered(true); //Display rendered image if render is completed, and the argument is true.

  if (i < 10) fileName = "00"+i;
  if (i >= 10 && i < 100) fileName = "0"+i;
  if (i >= 100 && i < 1000) fileName = ""+i;
  saveFrame(fileName+".PNG");

  i++;
  if (i == 120) exit();
}

^ top

You can’t perform that action at this time.