Initial Commit

This commit is contained in:
plane000
2018-04-20 10:15:15 +01:00
parent 49150ccfe4
commit 62101e8e61
2870 changed files with 520122 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
/**
* Glossy Fish Eye
*
* A fish-eye shader is used on the main surface and
* a glossy specular reflection shader is used on the
* offscreen canvas.
*/
PShader fisheye;
PShader glossy;
PGraphics canvas;
PImage img;
PShape ball;
boolean useFishEye = true;
void setup() {
size(640, 640, P3D);
canvas = createGraphics(width, height, P3D);
fisheye = loadShader("FishEye.glsl");
fisheye.set("aperture", 180.0);
glossy = loadShader("GlossyFrag.glsl", "GlossyVert.glsl");
glossy.set("AmbientColour", 0.0, 0.0, 0.0);
glossy.set("DiffuseColour", 0.9, 0.2, 0.2);
glossy.set("SpecularColour", 1.0, 1.0, 1.0);
glossy.set("AmbientIntensity", 1.0);
glossy.set("DiffuseIntensity", 1.0);
glossy.set("SpecularIntensity", 0.7);
glossy.set("Roughness", 0.7);
glossy.set("Sharpness", 0.0);
ball = createShape(SPHERE, 50);
ball.setStroke(false);
}
void draw() {
canvas.beginDraw();
canvas.shader(glossy);
canvas.noStroke();
canvas.background(0);
canvas.pushMatrix();
canvas.rotateY(frameCount * 0.01);
canvas.pointLight(204, 204, 204, 1000, 1000, 1000);
canvas.popMatrix();
for (float x = 0; x < canvas.width + 100; x += 100) {
for (float y = 0; y < canvas.height + 100; y += 100) {
for (float z = 0; z < 400; z += 100) {
canvas.pushMatrix();
canvas.translate(x, y, -z);
canvas.shape(ball);
canvas.popMatrix();
}
}
}
canvas.endDraw();
if (useFishEye == true) {
shader(fisheye);
}
image(canvas, 0, 0, width, height);
}
void mousePressed() {
if (useFishEye) {
useFishEye = false;
resetShader();
} else {
useFishEye = true;
}
}

View File

@@ -0,0 +1,59 @@
// Inspired by the "Angular Fisheye à la Bourke" sketch from
// Jonathan Cremieux, as shown in the OpenProcessing website:
// http://openprocessing.org/visuals/?visualID=12140
// Using the inverse transform of the angular fisheye as
// explained in Paul Bourke's website:
// http://paulbourke.net/miscellaneous/domefisheye/fisheye/
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define PROCESSING_TEXTURE_SHADER
uniform sampler2D texture;
uniform mat4 texMatrix;
varying vec4 vertColor;
varying vec4 vertTexCoord;
uniform float aperture;
const float PI = 3.1415926535;
void main(void) {
float apertureHalf = 0.5 * aperture * (PI / 180.0);
// This factor ajusts the coordinates in the case that
// the aperture angle is less than 180 degrees, in which
// case the area displayed is not the entire half-sphere.
float maxFactor = sin(apertureHalf);
// The st factor takes into account the situation when non-pot
// textures are not supported, so that the maximum texture
// coordinate to cover the entire image might not be 1.
vec2 stFactor = vec2(1.0 / abs(texMatrix[0][0]), 1.0 / abs(texMatrix[1][1]));
vec2 pos = (2.0 * vertTexCoord.st * stFactor - 1.0);
float l = length(pos);
if (l > 1.0) {
gl_FragColor = vec4(0, 0, 0, 1);
} else {
float x = maxFactor * pos.x;
float y = maxFactor * pos.y;
float n = length(vec2(x, y));
float z = sqrt(1.0 - n * n);
float r = atan(n, z) / PI;
float phi = atan(y, x);
float u = r * cos(phi) + 0.5;
float v = r * sin(phi) + 0.5;
gl_FragColor = texture2D(texture, vec2(u, v) / stFactor) * vertColor;
}
}

View File

@@ -0,0 +1,44 @@
// Copyright (C) 2007 Dave Griffiths
// Copyright (C) 2007 Dave Griffiths
// Licence: GPLv2 (see COPYING)
// Fluxus Shader Library
// ---------------------
// Glossy Specular Reflection Shader
// A more controllable version of blinn shading,
// Useful for ceramic or fluids - from Advanced
// Renderman, thanks to Larry Gritz
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
uniform vec3 AmbientColour;
uniform vec3 DiffuseColour;
uniform vec3 SpecularColour;
uniform float AmbientIntensity;
uniform float DiffuseIntensity;
uniform float SpecularIntensity;
uniform float Roughness;
uniform float Sharpness;
varying vec3 N;
varying vec3 P;
varying vec3 V;
varying vec3 L;
void main() {
float w = 0.18*(1.0-Sharpness);
vec3 l = normalize(L);
vec3 n = normalize(N);
vec3 v = normalize(V);
vec3 h = normalize(l+v);
float diffuse = dot(l,n);
float specular = smoothstep(0.72-w,0.72+w,pow(max(0.0,dot(n,h)),1.0/Roughness));
gl_FragColor = vec4(AmbientColour*AmbientIntensity +
DiffuseColour*diffuse*DiffuseIntensity +
SpecularColour*specular*SpecularIntensity,1);
}

View File

@@ -0,0 +1,33 @@
// Copyright (C) 2007 Dave Griffiths
// Licence: GPLv2 (see COPYING)
// Fluxus Shader Library
// ---------------------
// Glossy Specular Reflection Shader
// A more controllable version of blinn shading,
// Useful for ceramic or fluids - from Advanced
// Renderman, thanks to Larry Gritz
#define PROCESSING_LIGHT_SHADER
uniform mat4 modelview;
uniform mat4 transform;
uniform mat3 normalMatrix;
uniform vec4 lightPosition[8];
attribute vec4 vertex;
attribute vec3 normal;
varying vec3 N;
varying vec3 P;
varying vec3 V;
varying vec3 L;
void main() {
N = normalize(normalMatrix * normal);
P = vertex.xyz;
V = -vec3(modelview * vertex);
L = vec3(modelview * (lightPosition[0] - vertex));
gl_Position = transform * vertex;
}