Skip to content

Commit

Permalink
Optional indexed triangles for legacy OpenGL 2.1 to use graphics card…
Browse files Browse the repository at this point in the history
… resources more efficiently.
  • Loading branch information
neurolabusc committed Jul 28, 2020
1 parent 5e10082 commit e144ded
Show file tree
Hide file tree
Showing 102 changed files with 2,019 additions and 2,265 deletions.
199 changes: 95 additions & 104 deletions Resources/shadersOld/Default.txt
Original file line number Diff line number Diff line change
@@ -1,104 +1,95 @@
//pref
Ambient|float|0.0|0|1
Diffuse|float|0.0|1.0|2
Specular|float|0.0|0.25|1
SpecularRough|float|0.01|0.05|1
Edge|float|0|0.05|1.0
Hint: add substantial ambient occlusion (AO). Diffuse shading using spherical harmonics. Copyright 2010 Martins Upitis, BSD2clause.|note
//vert
varying vec3 vN, vV, vL;
varying vec4 vP, vClr;

void main()
{
vN = normalize(gl_NormalMatrix * gl_Normal);
vV = -vec3(gl_ModelViewMatrix*gl_Vertex);
vL = normalize(gl_LightSource[0].position.xyz);
vP = gl_Vertex;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
vClr = gl_Color;
}
//frag
uniform float Ambient, Diffuse, Specular, SpecularRough, Edge;
uniform vec4 ClipPlane;
varying vec3 vN, vV, vL;
varying vec4 vP, vClr;

//Spherical harmonics constants
const float C1 = 0.429043;
const float C2 = 0.511664;
const float C3 = 0.743125;
const float C4 = 0.886227;
const float C5 = 0.247708;

//Spherical harmonics coefficients
// Ramamoorthi, R., and P. Hanrahan. 2001b. "An Efficient Representation for Irradiance Environment Maps." In Proceedings of SIGGRAPH 2001, pp. 497–500.
// https://github.com/eskimoblood/processingSketches/blob/master/data/shader/shinyvert.glsl
// https://github.com/eskimoblood/processingSketches/blob/master/data/shader/shinyvert.glsl
// See table on page 397 of OpenGL programming Guide, 8th Edition Shreiner et al.

// Constants for Old Town Square lighting
const vec3 L00 = vec3( 0.871297, 0.875222, 0.864470);
const vec3 L1m1 = vec3( 0.175058, 0.245335, 0.312891);
const vec3 L10 = vec3( 0.034675, 0.036107, 0.037362);
const vec3 L11 = vec3(-0.004629, -0.029448, -0.048028);
const vec3 L2m2 = vec3(-0.120535, -0.121160, -0.117507);
const vec3 L2m1 = vec3( 0.003242, 0.003624, 0.007511);
const vec3 L20 = vec3(-0.028667, -0.024926, -0.020998);
const vec3 L21 = vec3(-0.077539, -0.086325, -0.091591);
const vec3 L22 = vec3(-0.161784, -0.191783, -0.219152);

// Constants for Eucalyptus Grove lighting
/*const vec3 L00 = vec3( 0.3783264, 0.4260425, 0.4504587);
const vec3 L1m1 = vec3( 0.2887813, 0.3586803, 0.4147053);
const vec3 L10 = vec3( 0.0379030, 0.0295216, 0.0098567);
const vec3 L11 = vec3(-0.1033028, -0.1031690, -0.0884924);
const vec3 L2m2 = vec3(-0.0621750, -0.0554432, -0.0396779);
const vec3 L2m1 = vec3( 0.0077820, -0.0148312, -0.0471301);
const vec3 L20 = vec3(-0.0935561, -0.1254260, -0.1525629);
const vec3 L21 = vec3(-0.0572703, -0.0502192, -0.0363410);
const vec3 L22 = vec3( 0.0203348, -0.0044201, -0.0452180);*/

vec3 SH(vec3 vNormal)
{
vNormal = vec3(vNormal.x,vNormal.z,-vNormal.y);
vec3 diffuseColor = C1 * L22 * (vNormal.x * vNormal.x - vNormal.y * vNormal.y) +
C3 * L20 * vNormal.z * vNormal.z +
C4 * L00 -
C5 * L20 +
2.0 * C1 * L2m2 * vNormal.x * vNormal.y +
2.0 * C1 * L21 * vNormal.x * vNormal.z +
2.0 * C1 * L2m1 * vNormal.y * vNormal.z +
2.0 * C2 * L11 * vNormal.x +
2.0 * C2 * L1m1 * vNormal.y +
2.0 * C2 * L10 * vNormal.z;
return diffuseColor;
}

vec3 desaturate(vec3 color, float amount) {
vec3 gray = vec3(dot(vec3(0.2126,0.7152,0.0722), color));
return vec3(mix(color, gray, amount));
}

void main() {
if ((ClipPlane[0] < 1.5) && (dot( ClipPlane, vP) > 0.0)) discard;
vec3 l = normalize(vL);
vec3 n = normalize(vN);
vec3 v = normalize(vV);
vec3 h = normalize(l+v);
vec3 a = gl_FrontMaterial.ambient.rgb;
a = mix(a, vClr.rgb, vClr.a);
vec3 d = a * Diffuse;
a *= Ambient;
vec3 backcolor = desaturate(0.75 * a + 0.75 * d * abs(dot(n,l)), 0.5);
d *= SH(-reflect(n, l) );
float specular = max(0.0,dot(n,h));
specular = pow(specular, 1.0/(SpecularRough * SpecularRough));
vec3 frontcolor = a + d + specular* Specular;
float edge =((max(dot(n,normalize(vV)), 0.0) - 0.5) * Edge) + 1.0;
edge = min(1.0, edge);
frontcolor *= edge;
float backface = step(0.0, n.z);
gl_FragColor = vec4(mix(backcolor, frontcolor, backface), 1.0);

}
//pref
Ambient|float|0.0|0|1
Diffuse|float|0.0|1|2
Specular|float|0.0|0.25|1
SpecularRough|float|0.01|0.05|1
Edge|float|0|0.05|1.0
Hint: add substantial ambient occlusion (AO). Diffuse shading using spherical harmonics. Copyright 2010 Martins Upitis, BSD2clause.|note
//frag
#version 120
varying vec3 vN, vV, vL;
varying vec4 vP, vClr;
uniform float Ambient = 0.5;
uniform float Diffuse = 0.7;
uniform float Specular = 0.2;
uniform float SpecularRough = 0.05;
uniform float Edge = 0.05;
uniform vec4 ClipPlane = vec4(2.0, 0.0, 0.0, 0.0);

//Spherical harmonics constants
const float C1 = 0.429043;
const float C2 = 0.511664;
const float C3 = 0.743125;
const float C4 = 0.886227;
const float C5 = 0.247708;

//Spherical harmonics coefficients
// Ramamoorthi, R., and P. Hanrahan. 2001b. "An Efficient Representation for Irradiance Environment Maps." In Proceedings of SIGGRAPH 2001, pp. 497–500.
// https://github.com/eskimoblood/processingSketches/blob/master/data/shader/shinyvert.glsl
// https://github.com/eskimoblood/processingSketches/blob/master/data/shader/shinyvert.glsl
// See table on page 397 of OpenGL programming Guide, 8th Edition Shreiner et al.

// Constants for Old Town Square lighting
const vec3 L00 = vec3( 0.871297, 0.875222, 0.864470);
const vec3 L1m1 = vec3( 0.175058, 0.245335, 0.312891);
const vec3 L10 = vec3( 0.034675, 0.036107, 0.037362);
const vec3 L11 = vec3(-0.004629, -0.029448, -0.048028);
const vec3 L2m2 = vec3(-0.120535, -0.121160, -0.117507);
const vec3 L2m1 = vec3( 0.003242, 0.003624, 0.007511);
const vec3 L20 = vec3(-0.028667, -0.024926, -0.020998);
const vec3 L21 = vec3(-0.077539, -0.086325, -0.091591);
const vec3 L22 = vec3(-0.161784, -0.191783, -0.219152);

// Constants for Eucalyptus Grove lighting
/*const vec3 L00 = vec3( 0.3783264, 0.4260425, 0.4504587);
const vec3 L1m1 = vec3( 0.2887813, 0.3586803, 0.4147053);
const vec3 L10 = vec3( 0.0379030, 0.0295216, 0.0098567);
const vec3 L11 = vec3(-0.1033028, -0.1031690, -0.0884924);
const vec3 L2m2 = vec3(-0.0621750, -0.0554432, -0.0396779);
const vec3 L2m1 = vec3( 0.0077820, -0.0148312, -0.0471301);
const vec3 L20 = vec3(-0.0935561, -0.1254260, -0.1525629);
const vec3 L21 = vec3(-0.0572703, -0.0502192, -0.0363410);
const vec3 L22 = vec3( 0.0203348, -0.0044201, -0.0452180);*/

vec3 SH(vec3 vNormal)
{
vNormal = vec3(vNormal.x,vNormal.z,-vNormal.y);
vec3 diffuseColor = C1 * L22 * (vNormal.x * vNormal.x - vNormal.y * vNormal.y) +
C3 * L20 * vNormal.z * vNormal.z +
C4 * L00 -
C5 * L20 +
2.0 * C1 * L2m2 * vNormal.x * vNormal.y +
2.0 * C1 * L21 * vNormal.x * vNormal.z +
2.0 * C1 * L2m1 * vNormal.y * vNormal.z +
2.0 * C2 * L11 * vNormal.x +
2.0 * C2 * L1m1 * vNormal.y +
2.0 * C2 * L10 * vNormal.z;
return diffuseColor;
}

vec3 desaturate(vec3 color, float amount) {
vec3 gray = vec3(dot(vec3(0.2126,0.7152,0.0722), color));
return vec3(mix(color, gray, amount));
}

void main() {
if ((ClipPlane[0] < 1.5) && (dot( ClipPlane, vP) > 0.0)) discard;
vec3 l = normalize(vL);
vec3 n = normalize(vN);
vec3 v = normalize(vV);
vec3 h = normalize(l+v);
vec3 a = vClr.rgb;
vec3 d = a * Diffuse;
a *= Ambient;
vec3 backcolor = desaturate(0.75 * a + 0.75 * d * abs(dot(n,l)), 0.5);
d *= SH(-reflect(n, l) );
float specular = max(0.0,dot(n,h));
specular = pow(specular, 1.0/(SpecularRough * SpecularRough));
vec4 color = vec4(a + d + specular* Specular, 1.0);
float edge =((max(dot(n,normalize(vV)), 0.0) - 0.5) * Edge) + 1.0;
edge = min(1.0, edge);
color.rgb *= edge;
float backface = step(0.0, n.z);
color = vec4(mix(backcolor.rgb, color.rgb, backface), 1.0);
gl_FragColor = color;
}
21 changes: 6 additions & 15 deletions Resources/shadersOld/Fastest.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
//pref
Ambient|float|0|0.0|1
Diffuse|float|0|1|1
AOradius|float|0|0|16
Fastest but poorest: for software emulation like Mesa. Clip plane will be ignored|note
//vert
varying vec3 vL, vN;
varying vec4 vClr;

void main() {
vN = gl_NormalMatrix * gl_Normal;
vL = gl_LightSource[0].position.xyz;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
vClr = gl_Color;
}
//frag
uniform float Diffuse;
//uniform float Ambient;
varying vec3 vL, vN;
#version 120
varying vec3 vN, vL;
varying vec4 vClr;

uniform float Diffuse;
uniform float Ambient;
void main() {
gl_FragColor = vec4( ((dot(normalize(vN),normalize(vL)) * Diffuse)) * mix(gl_FrontMaterial.ambient.rgb, vClr.rgb, vClr.a), 1.0);
gl_FragColor = vec4(vClr.rgb * (Ambient + (dot(normalize(vN),normalize(vL)) * Diffuse)), 1.0);
}
47 changes: 0 additions & 47 deletions Resources/shadersOld/Flat.txt

This file was deleted.

69 changes: 29 additions & 40 deletions Resources/shadersOld/Gooch.txt
Original file line number Diff line number Diff line change
@@ -1,55 +1,44 @@
//pref
Specular|float|0.0|80|120
OutlineWidth|float|0.0|0.05|0.5
Specular|float|0.0|0.66|1
OutlineWidth|float|0.0|0.1|0.25
Warm|float|0.0|0.9|1
Cool|float|0.0|0.9|1
Amount|float|0.0|0.6|1
Gooch Non-Photorealistic Rendering. Adapted from Fluxus Library, Copyright 2007 Dave Griffiths, GPLv2|note
//vert
varying vec3 N,V,L;
varying vec4 P, vClr;
void main()
{
P = gl_Vertex;
N = gl_NormalMatrix * gl_Normal;
V = -vec3(gl_ModelViewMatrix*gl_Vertex);
//V = vec3(0.0, 0.0, 1.0);
L = gl_LightSource[0].position.xyz;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
vClr = gl_Color;
}
//frag
uniform float OutlineWidth, Specular, Warm, Cool, Amount;
uniform vec4 ClipPlane;
varying vec4 P, vClr;
varying vec3 N, V, L;
#version 120
varying vec3 vN, vV, vL;
varying vec4 vP, vClr;
uniform float Specular = 0.6;
uniform float OutlineWidth = 0.1;
uniform float Warm = 0.9;
uniform float Cool = 0.5;
uniform float Amount = 0.5;
uniform vec4 ClipPlane = vec4(2.0, 0.0, 0.0, 0.0);
vec3 desaturate(vec3 color, float amount) {
vec3 gray = vec3(dot(vec3(0.2126,0.7152,0.0722), color));
return vec3(mix(color, gray, amount));
}
void main()
{
if ((ClipPlane[0] < 1.5) && (dot( ClipPlane, P) > 0.0)) discard;
void main() {
if ((ClipPlane[0] < 1.5) && (dot( ClipPlane, vP) > 0.0)) discard;
vec3 warm = vec3(1.0, 1.0, 0.0) * Warm;
vec3 cool = vec3(0.0, 0.0, 1.0) * Cool;
vec3 d = gl_FrontMaterial.diffuse.rgb;
d = mix(d.rgb, vClr.rgb, vClr.a);
cool = mix(d, cool, Amount);
warm = mix(d, warm, Amount);
vec3 l = normalize(L);
vec3 n = normalize(N);
float diffuse = dot(l,n);
if (n.z < 0.0) { //i.e. if (!gl_FrontFacing)
vec3 backsurface = desaturate(min(mix(0.75*cool,0.75*warm,abs(diffuse)),1.0),0.5);
gl_FragColor = vec4(backsurface, 1.0);
return;
}
vec3 v = normalize(V);
vec3 h = normalize(l+v);
float specular = pow(dot(n,h),Specular);
vec3 colour = min(mix(cool,warm,diffuse)+specular,1.0);
if (dot(n,v) < OutlineWidth) colour=vec3(0,0,0);
gl_FragColor = vec4(colour, 1.0);
vec3 l = normalize(vL);
vec3 n = normalize(vN);
float diffuse = dot(l,n);
cool = mix(vClr.rgb, cool, Amount);
warm = mix(vClr.rgb, warm, Amount);
if (n.z < 0.0) { //i.e. if (!gl_FrontFacing)
vec3 backsurface = desaturate(min(mix(0.75*cool,0.75*warm,abs(diffuse)),1.0),0.5);
gl_FragColor = vec4(backsurface, 1.0);
return;
}
vec3 v = normalize(vV);
vec3 h = normalize(l+v);
float specular = pow(dot(n,h),Specular * 80.0);
vec4 color = vec4(min(mix(cool,warm,diffuse)+specular,1.0), 1.0);
if (dot(n,v) < OutlineWidth) color.rgb *= 0.0;
gl_FragColor = color;
}
// Copyright (C) 2007 Dave Griffiths
// Licence: GPLv2 (see COPYING)
Expand Down
Loading

0 comments on commit e144ded

Please sign in to comment.