mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
moving the OpenGL examples to the core
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
// Fish-eye shader on the main surface, glossy specular reflection shader
|
||||
// on the offscreen canvas.
|
||||
|
||||
PGraphics canvas;
|
||||
PShader fisheye;
|
||||
PShader glossy;
|
||||
PImage img;
|
||||
PShape ball;
|
||||
|
||||
boolean usingFishEye;
|
||||
|
||||
void setup() {
|
||||
size(800, 800, P3D);
|
||||
canvas = createGraphics(800, 800, P3D);
|
||||
|
||||
fisheye = (PShader)loadShader("FishEye.glsl", PShader.TEXTURED);
|
||||
fisheye.set("aperture", 180.0);
|
||||
shader(fisheye, PShader.TEXTURED);
|
||||
usingFishEye = true;
|
||||
|
||||
glossy = (PShader)loadShader("GlossyVert.glsl", "GlossyFrag.glsl", PShader.LIT);
|
||||
glossy.set("AmbientColour", 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);
|
||||
canvas.shader(glossy, PShader.LIT);
|
||||
|
||||
ball = createShape(SPHERE, 50);
|
||||
//ball.fill(200, 50, 50);
|
||||
ball.noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
canvas.beginDraw();
|
||||
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();
|
||||
|
||||
image(canvas, 0, 0, width, height);
|
||||
|
||||
println(frameRate);
|
||||
}
|
||||
|
||||
public void mousePressed() {
|
||||
if (usingFishEye) {
|
||||
resetShader(PShader.TEXTURED);
|
||||
usingFishEye = false;
|
||||
} else {
|
||||
shader(fisheye, PShader.TEXTURED);
|
||||
usingFishEye = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// 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/
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
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);
|
||||
|
||||
vec2 pos = 2.0 * vertTexcoord.st - 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(textureSampler, vec2(u, v)) * vertColor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// 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
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// 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
|
||||
|
||||
uniform mat4 modelviewMatrix;
|
||||
uniform mat4 projmodelviewMatrix;
|
||||
uniform mat3 normalMatrix;
|
||||
|
||||
uniform vec4 lightPosition[8];
|
||||
|
||||
attribute vec4 inVertex;
|
||||
attribute vec3 inNormal;
|
||||
|
||||
varying vec3 N;
|
||||
varying vec3 P;
|
||||
varying vec3 V;
|
||||
varying vec3 L;
|
||||
|
||||
void main() {
|
||||
N = normalize(normalMatrix * inNormal);
|
||||
P = inVertex.xyz;
|
||||
V = -vec3(modelviewMatrix * inVertex);
|
||||
L = vec3(modelviewMatrix * (lightPosition[0] - inVertex));
|
||||
gl_Position = projmodelviewMatrix * inVertex;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user