Commit d46e939d authored by Eric Anholt's avatar Eric Anholt

Add some Humus demos I had around.

parent 701c7392
The Humus demos don't have an explicit copyright license on the
shaders, but the C++ code that loads them has this for its license
text:
/* * * * * * * * * * * * * Author's note * * * * * * * * * * * *\
* _ _ _ _ _ _ _ _ _ _ _ _ *
* |_| |_| |_| |_| |_|_ _|_| |_| |_| _|_|_|_|_| *
* |_|_ _ _|_| |_| |_| |_|_|_|_|_| |_| |_| |_|_ _ _ *
* |_|_|_|_|_| |_| |_| |_| |_| |_| |_| |_| |_|_|_|_ *
* |_| |_| |_|_ _ _|_| |_| |_| |_|_ _ _|_| _ _ _ _|_| *
* |_| |_| |_|_|_| |_| |_| |_|_|_| |_|_|_|_| *
* *
* http://www.humus.name *
* *
* This file is a part of the work done by Humus. You are free to *
* use the code in any way you like, modified, unmodified or copied *
* into your own work. However, I expect you to respect these points: *
* - If you use this file and its contents unmodified, or use a major *
* part of this file, please credit the author and leave this note. *
* - For use in anything commercial, please request my approval. *
* - Share your work and ideas too as much as you can. *
* *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*********** .---. .-"-. *******************\
* -------- * / ._. / <B4> ` \ * ---------------- *
* Author's * \_ (__\ \_<B0>v<B0>_/ * humus@rogers.com *
* note * // \\ // \\ * ICQ #47010716 *
* -------- * (( )) (( )) * ---------------- *
* ****--""---""-------""---""--**** ********\
* This file is a part of the work done by Humus. You are free to use *
* the code in any way you like, modified, unmodified or copy'n'pasted *
* into your own work. However, I expect you to respect these points: *
* @ If you use this file and its contents unmodified, or use a major *
* part of this file, please credit the author and leave this note. *
* @ For use in anything commercial, please request my approval. *
* @ Share your work and ideas too as much as you can. *
\*********************************************************************/
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#line 14
uniform sampler1D CelShade;
varying vec3 lVec;
varying vec3 norm;
void main(){
vec3 lightVec = normalize(lVec);
float diffuse = dot(lightVec, norm);
gl_FragColor = texture1D(CelShade, diffuse);
}
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#line 0
uniform vec3 lightPos;
varying vec3 lVec;
varying vec3 norm;
void main(){
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
lVec = lightPos - gl_Vertex.xyz;
norm = gl_Normal;
}
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#line 19
varying vec3 norm;
void main(){
gl_FragColor = vec4(0.0);
}
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#line 0
uniform vec3 camPos;
uniform float outlineThreshold;
uniform float edgeThreshold;
varying vec3 norm;
void main(){
vec4 pos = gl_Vertex;
vec3 dir = camPos - gl_Vertex.xyz;
pos.w = float(
dot(dir, gl_MultiTexCoord0.xyz) * dot(dir, gl_MultiTexCoord1.xyz) < outlineThreshold ||
dot(gl_MultiTexCoord0.xyz, gl_MultiTexCoord1.xyz) < edgeThreshold);
gl_Position = gl_ModelViewProjectionMatrix * pos;
}
uniform vec4 color;
void main()
{
gl_FragColor = color;
}
attribute vec4 position;
void main()
{
gl_Position = position;
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#line 18
uniform sampler2D Base;
uniform sampler2D Bump;
uniform float fade;
varying vec2 texCoord;
varying vec3 lVec;
void main(){
vec3 lightVec = normalize(lVec);
vec3 viewVec = lightVec;
float atten = saturate(1.0 / (1.0 + dot(lVec, lVec)) - 0.1);
vec4 base = texture2D(Base, texCoord);
vec3 bump = texture2D(Bump, texCoord).xyz;
vec3 normal = normalize(bump * 2.0 - 1.0);
float diffuse = saturate(dot(lightVec, normal));
float specular = pow(diffuse, 16.0);
gl_FragColor = fade * atten * ((diffuse * 0.7 + 0.3) * base + 0.5 * specular);
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#line 2
uniform vec3 camPos;
varying vec2 texCoord;
varying vec3 lVec;
void main(){
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
texCoord = gl_Vertex.xz * 0.0625;
lVec = 0.005 * (camPos - gl_Vertex.xyz).xzy;
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#define BATCH_INSTANCES 64
#line 45
uniform sampler3D Noise;
uniform float fade;
varying vec3 texCoord;
varying vec3 normal;
varying vec3 lVec;
void main(){
vec3 lightVec = normalize(lVec);
vec3 viewVec = lightVec;
float atten = saturate(1.0 / (1.0 + dot(lVec, lVec)) - 0.1);
vec4 darkWood = vec4(0.09, 0.04, 0.01, 1.0);
vec4 liteWood = vec4(0.92, 0.51, 0.13, 1.0);
float rings = fract(texture3D(Noise, texCoord * 0.15, 1.0).x * 4.0);
rings *= 4.0 * (1.0 - rings);
rings *= rings;
float n = texture3D(Noise, texCoord).x;
vec4 base = lerp(darkWood, liteWood, rings + n);
float diffuse = saturate(dot(lightVec, normal));
float specular = pow(diffuse, 64.0);
gl_FragColor = fade * atten * ((diffuse * 0.8 + 0.2) * base + 0.4 * specular);
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#define BATCH_INSTANCES 64
#line 2
uniform vec3 camPos;
void rotate(const vec2 sc, inout vec2 pos){
pos.xy = vec2(dot(pos, sc), dot(pos, vec2(-sc.y, sc.x)));
}
varying vec3 texCoord;
varying vec3 normal;
varying vec3 lVec;
uniform vec4 attribs[BATCH_INSTANCES];
uniform float time;
uniform float fallAngle;
void main(){
vec4 attrib = attribs[int(gl_MultiTexCoord0.x)];
float a = saturate(time - attrib.w);
a = fallAngle * pow(a, 0.8);
vec2 scA = vec2(cos(a), sin(a));
vec2 scB = vec2(cos(-attrib.z), sin(-attrib.z));
vec4 position = gl_Vertex;
normal = gl_Normal;
rotate(scA, position.xy);
rotate(scA, normal.xy);
rotate(scB, position.xz);
rotate(scB, normal.xz);
position.xz += attrib.xy;
gl_Position = gl_ModelViewProjectionMatrix * position;
texCoord = gl_Vertex.xyz * 0.283 + attrib.w * vec3(7.243, 2.6783, 9.4921);
lVec = 0.005 * (camPos - position.xyz);
}
uniform vec4 color;
void main()
{
gl_FragColor = color;
}
attribute vec4 position;
void main()
{
gl_Position = position;
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#line 28
uniform sampler2D Base;
uniform sampler2D Bump;
uniform vec2 plxCoeffs;
uniform bool hasParallax;
varying vec2 texCoord;
varying vec3 vVec;
void main(){
#ifdef MULTIPASS
vec3 viewVec = normalize(vVec);
vec2 plxTexCoord = texCoord;
if (hasParallax){
float height = texture2D(Bump, texCoord).w;
float offset = height * plxCoeffs.x + plxCoeffs.y;
plxTexCoord += offset * viewVec.xy;
}
vec4 base = texture2D(Base, plxTexCoord);
gl_FragColor = 0.1 * base;
#endif
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#line 2
attribute vec2 textureCoord;
attribute vec3 tangent;
attribute vec3 binormal;
attribute vec3 normal;
uniform vec3 camPos;
varying vec2 texCoord;
varying vec3 vVec;
void main(){
gl_Position = ftransform();
#ifdef MULTIPASS
texCoord = textureCoord;
vec3 viewVec = camPos - gl_Vertex.xyz;
vVec.x = dot(viewVec, tangent);
vVec.y = dot(viewVec, binormal);
vVec.z = dot(viewVec, normal);
#endif
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#define SHADOWS
#line 36
uniform sampler2D Base;
uniform sampler2D Bump;
uniform samplerCube ShadowMap;
uniform vec3 lightColor;
uniform vec2 plxCoeffs;
uniform vec4 select;
uniform bool hasParallax;
varying vec2 texCoord;
varying vec3 lVec;
varying vec3 vVec;
varying vec3 shadowVec;
void main(){
vec3 lighting = vec3(0.0);
float atten = saturate(1.0 - dot(lVec, lVec));
#ifndef BRANCHING
atten *= float(lVec.z > 0.0);
#else
if (atten > 0.0)
if (lVec.z > 0.0)
#endif
{
#ifdef SHADOWS
# ifndef BRANCHING
atten *= float(length(shadowVec) < dot(textureCube(ShadowMap, shadowVec), select));
# else
if (length(shadowVec) < dot(textureCube(ShadowMap, shadowVec), select))
# endif
#endif
{
vec3 lightVec = normalize(lVec);
vec3 viewVec = normalize(vVec);
vec2 plxTexCoord = texCoord;
if (hasParallax){
float height = texture2D(Bump, texCoord).w;
float offset = height * plxCoeffs.x + plxCoeffs.y;
plxTexCoord += offset * viewVec.xy;
}
vec3 base = texture2D(Base, plxTexCoord).rgb;
vec3 bump = texture2D(Bump, plxTexCoord).xyz * 2.0 - 1.0;
bump = normalize(bump);
float diffuse = saturate(dot(lightVec, bump));
float specular = pow(saturate(dot(reflect(-viewVec, bump), lightVec)), 16.0);
lighting = atten * lightColor * (diffuse * base + 0.6 * specular);
}
}
gl_FragColor.rgb = lighting;
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#define SHADOWS
#line 2
uniform vec3 lightPos;
uniform vec3 camPos;
uniform float invRadius;
attribute vec2 textureCoord;
attribute vec3 tangent;
attribute vec3 binormal;
attribute vec3 normal;
varying vec2 texCoord;
varying vec3 lVec;
varying vec3 vVec;
varying vec3 shadowVec;
void main(){
gl_Position = ftransform();
texCoord = textureCoord;
vec3 lightVec = invRadius * (lightPos - gl_Vertex.xyz);
shadowVec = -lightVec;
lVec.x = dot(lightVec, tangent);
lVec.y = dot(lightVec, binormal);
lVec.z = dot(lightVec, normal);
vec3 viewVec = camPos - gl_Vertex.xyz;
vVec.x = dot(viewVec, tangent);
vVec.y = dot(viewVec, binormal);
vVec.z = dot(viewVec, normal);
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#define SHADOWS
#define BRANCHING
#line 36
uniform sampler2D Base;
uniform sampler2D Bump;
uniform samplerCube ShadowMap;
uniform vec3 lightColor;
uniform vec2 plxCoeffs;
uniform vec4 select;
uniform bool hasParallax;
varying vec2 texCoord;
varying vec3 lVec;
varying vec3 vVec;
varying vec3 shadowVec;
void main(){
vec3 lighting = vec3(0.0);
float atten = saturate(1.0 - dot(lVec, lVec));
#ifndef BRANCHING
atten *= float(lVec.z > 0.0);
#else
if (atten > 0.0)
if (lVec.z > 0.0)
#endif
{
#ifdef SHADOWS
# ifndef BRANCHING
atten *= float(length(shadowVec) < dot(textureCube(ShadowMap, shadowVec), select));
# else
if (length(shadowVec) < dot(textureCube(ShadowMap, shadowVec), select))
# endif
#endif
{
vec3 lightVec = normalize(lVec);
vec3 viewVec = normalize(vVec);
vec2 plxTexCoord = texCoord;
if (hasParallax){
float height = texture2D(Bump, texCoord).w;
float offset = height * plxCoeffs.x + plxCoeffs.y;
plxTexCoord += offset * viewVec.xy;
}
vec3 base = texture2D(Base, plxTexCoord).rgb;
vec3 bump = texture2D(Bump, plxTexCoord).xyz * 2.0 - 1.0;
bump = normalize(bump);
float diffuse = saturate(dot(lightVec, bump));
float specular = pow(saturate(dot(reflect(-viewVec, bump), lightVec)), 16.0);
lighting = atten * lightColor * (diffuse * base + 0.6 * specular);
}
}
gl_FragColor.rgb = lighting;
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#define SHADOWS
#define BRANCHING
#line 2
uniform vec3 lightPos;
uniform vec3 camPos;
uniform float invRadius;
attribute vec2 textureCoord;
attribute vec3 tangent;
attribute vec3 binormal;
attribute vec3 normal;
varying vec2 texCoord;
varying vec3 lVec;
varying vec3 vVec;
varying vec3 shadowVec;
void main(){
gl_Position = ftransform();
texCoord = textureCoord;
vec3 lightVec = invRadius * (lightPos - gl_Vertex.xyz);
shadowVec = -lightVec;
lVec.x = dot(lightVec, tangent);
lVec.y = dot(lightVec, binormal);
lVec.z = dot(lightVec, normal);
vec3 viewVec = camPos - gl_Vertex.xyz;
vVec.x = dot(viewVec, tangent);
vVec.y = dot(viewVec, binormal);
vVec.z = dot(viewVec, normal);
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#line 18
varying vec3 lightVec;
void main(){
gl_FragColor = vec4(length(lightVec) + 0.005);
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#line 2
uniform mat4 mvp;
uniform vec3 lightPos;
uniform float invRadius;
varying vec3 lightVec;
void main(){
gl_Position = mvp * gl_Vertex;
lightVec = invRadius * (lightPos - gl_Vertex.xyz);
}
uniform vec4 color;
void main()
{
gl_FragColor = color;
}
attribute vec4 position;
void main()
{
gl_Position = position;
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#define MULTIPASS
#line 28
uniform sampler2D Base;
uniform sampler2D Bump;
uniform vec2 plxCoeffs;
uniform bool hasParallax;
varying vec2 texCoord;
varying vec3 vVec;
void main(){
#ifdef MULTIPASS
vec3 viewVec = normalize(vVec);
vec2 plxTexCoord = texCoord;
if (hasParallax){
float height = texture2D(Bump, texCoord).w;
float offset = height * plxCoeffs.x + plxCoeffs.y;
plxTexCoord += offset * viewVec.xy;
}
vec4 base = texture2D(Base, plxTexCoord);
gl_FragColor = 0.1 * base;
#endif
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#define MULTIPASS
#line 2
attribute vec2 textureCoord;
attribute vec3 tangent;
attribute vec3 binormal;
attribute vec3 normal;
uniform vec3 camPos;
varying vec2 texCoord;
varying vec3 vVec;
void main(){
gl_Position = ftransform();
#ifdef MULTIPASS
texCoord = textureCoord;
vec3 viewVec = camPos - gl_Vertex.xyz;
vVec.x = dot(viewVec, tangent);
vVec.y = dot(viewVec, binormal);
vVec.z = dot(viewVec, normal);
#endif
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#line 13
uniform sampler2D Base;
varying vec2 texCoord;
void main(){
gl_FragColor = texture2D(Base, texCoord) * gl_Color;
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#line 2
varying vec2 texCoord;
void main(){
gl_Position = ftransform();
texCoord = gl_MultiTexCoord0.xy;
gl_FrontColor = gl_Color;
}
#version 120
#define saturate(x) clamp(x,0.0,1.0)
#define lerp mix
#define LIGHT_COUNT 3
#line 43
uniform sampler2D Base;
uniform sampler2D Bump;
uniform samplerCube ShadowMap;
uniform vec3 lightColor[LIGHT_COUNT];
uniform vec2 plxCoeffs;
uniform bool hasParallax;
varying vec3 lVec[LIGHT_COUNT];
varying vec2 texCoord;