From d46e939d8f28ed1c4162a33e99378d5797e4e3a1 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 8 Sep 2011 23:02:27 -0700 Subject: Add some Humus demos I had around. --- shaders/humus-celshading/1.frag | 17 +++++++ shaders/humus-celshading/1.vert | 18 +++++++ shaders/humus-celshading/2.frag | 11 +++++ shaders/humus-celshading/2.vert | 23 +++++++++ shaders/humus-celshading/3.frag | 6 +++ shaders/humus-celshading/3.vert | 6 +++ shaders/humus-domino/1.frag | 28 +++++++++++ shaders/humus-domino/1.vert | 19 ++++++++ shaders/humus-domino/2.frag | 36 ++++++++++++++ shaders/humus-domino/2.vert | 47 ++++++++++++++++++ shaders/humus-domino/3.frag | 6 +++ shaders/humus-domino/3.vert | 6 +++ shaders/humus-dynamicbranching/1.frag | 32 ++++++++++++ shaders/humus-dynamicbranching/1.vert | 29 +++++++++++ shaders/humus-dynamicbranching/10.frag | 63 ++++++++++++++++++++++++ shaders/humus-dynamicbranching/10.vert | 38 +++++++++++++++ shaders/humus-dynamicbranching/11.frag | 64 ++++++++++++++++++++++++ shaders/humus-dynamicbranching/11.vert | 39 +++++++++++++++ shaders/humus-dynamicbranching/12.frag | 10 ++++ shaders/humus-dynamicbranching/12.vert | 19 ++++++++ shaders/humus-dynamicbranching/13.frag | 6 +++ shaders/humus-dynamicbranching/13.vert | 6 +++ shaders/humus-dynamicbranching/2.frag | 33 +++++++++++++ shaders/humus-dynamicbranching/2.vert | 30 ++++++++++++ shaders/humus-dynamicbranching/3.frag | 12 +++++ shaders/humus-dynamicbranching/3.vert | 14 ++++++ shaders/humus-dynamicbranching/4.frag | 82 +++++++++++++++++++++++++++++++ shaders/humus-dynamicbranching/4.vert | 45 +++++++++++++++++ shaders/humus-dynamicbranching/5.frag | 83 +++++++++++++++++++++++++++++++ shaders/humus-dynamicbranching/5.vert | 46 ++++++++++++++++++ shaders/humus-dynamicbranching/6.frag | 83 +++++++++++++++++++++++++++++++ shaders/humus-dynamicbranching/6.vert | 46 ++++++++++++++++++ shaders/humus-dynamicbranching/7.frag | 84 ++++++++++++++++++++++++++++++++ shaders/humus-dynamicbranching/7.vert | 47 ++++++++++++++++++ shaders/humus-dynamicbranching/8.frag | 62 ++++++++++++++++++++++++ shaders/humus-dynamicbranching/8.vert | 37 ++++++++++++++ shaders/humus-dynamicbranching/9.frag | 63 ++++++++++++++++++++++++ shaders/humus-dynamicbranching/9.vert | 38 +++++++++++++++ shaders/humus-hdr/1.frag | 39 +++++++++++++++ shaders/humus-hdr/1.vert | 37 ++++++++++++++ shaders/humus-hdr/2.frag | 23 +++++++++ shaders/humus-hdr/2.vert | 15 ++++++ shaders/humus-hdr/3.frag | 26 ++++++++++ shaders/humus-hdr/3.vert | 26 ++++++++++ shaders/humus-hdr/4.frag | 22 +++++++++ shaders/humus-hdr/4.vert | 25 ++++++++++ shaders/humus-hdr/5.frag | 28 +++++++++++ shaders/humus-hdr/5.vert | 16 ++++++ shaders/humus-hdr/6.frag | 6 +++ shaders/humus-hdr/6.vert | 6 +++ shaders/humus-portals/1.frag | 32 ++++++++++++ shaders/humus-portals/1.vert | 30 ++++++++++++ shaders/humus-portals/2.frag | 6 +++ shaders/humus-portals/2.vert | 6 +++ shaders/humus-raytracedshadows/1.frag | 25 ++++++++++ shaders/humus-raytracedshadows/1.vert | 32 ++++++++++++ shaders/humus-raytracedshadows/2.frag | 20 ++++++++ shaders/humus-raytracedshadows/2.vert | 30 ++++++++++++ shaders/humus-raytracedshadows/3.frag | 15 ++++++ shaders/humus-raytracedshadows/3.vert | 16 ++++++ shaders/humus-raytracedshadows/4.frag | 22 +++++++++ shaders/humus-raytracedshadows/4.vert | 29 +++++++++++ shaders/humus-raytracedshadows/5.frag | 16 ++++++ shaders/humus-raytracedshadows/5.vert | 26 ++++++++++ shaders/humus-raytracedshadows/6.frag | 6 +++ shaders/humus-raytracedshadows/6.vert | 6 +++ shaders/humus-volumetricfogging2/1.frag | 86 +++++++++++++++++++++++++++++++++ shaders/humus-volumetricfogging2/1.vert | 55 +++++++++++++++++++++ shaders/humus-volumetricfogging2/2.frag | 8 +++ shaders/humus-volumetricfogging2/2.vert | 12 +++++ shaders/humus-volumetricfogging2/3.frag | 6 +++ shaders/humus-volumetricfogging2/3.vert | 6 +++ 72 files changed, 2093 insertions(+) create mode 100644 shaders/humus-celshading/1.frag create mode 100644 shaders/humus-celshading/1.vert create mode 100644 shaders/humus-celshading/2.frag create mode 100644 shaders/humus-celshading/2.vert create mode 100644 shaders/humus-celshading/3.frag create mode 100644 shaders/humus-celshading/3.vert create mode 100644 shaders/humus-domino/1.frag create mode 100644 shaders/humus-domino/1.vert create mode 100644 shaders/humus-domino/2.frag create mode 100644 shaders/humus-domino/2.vert create mode 100644 shaders/humus-domino/3.frag create mode 100644 shaders/humus-domino/3.vert create mode 100644 shaders/humus-dynamicbranching/1.frag create mode 100644 shaders/humus-dynamicbranching/1.vert create mode 100644 shaders/humus-dynamicbranching/10.frag create mode 100644 shaders/humus-dynamicbranching/10.vert create mode 100644 shaders/humus-dynamicbranching/11.frag create mode 100644 shaders/humus-dynamicbranching/11.vert create mode 100644 shaders/humus-dynamicbranching/12.frag create mode 100644 shaders/humus-dynamicbranching/12.vert create mode 100644 shaders/humus-dynamicbranching/13.frag create mode 100644 shaders/humus-dynamicbranching/13.vert create mode 100644 shaders/humus-dynamicbranching/2.frag create mode 100644 shaders/humus-dynamicbranching/2.vert create mode 100644 shaders/humus-dynamicbranching/3.frag create mode 100644 shaders/humus-dynamicbranching/3.vert create mode 100644 shaders/humus-dynamicbranching/4.frag create mode 100644 shaders/humus-dynamicbranching/4.vert create mode 100644 shaders/humus-dynamicbranching/5.frag create mode 100644 shaders/humus-dynamicbranching/5.vert create mode 100644 shaders/humus-dynamicbranching/6.frag create mode 100644 shaders/humus-dynamicbranching/6.vert create mode 100644 shaders/humus-dynamicbranching/7.frag create mode 100644 shaders/humus-dynamicbranching/7.vert create mode 100644 shaders/humus-dynamicbranching/8.frag create mode 100644 shaders/humus-dynamicbranching/8.vert create mode 100644 shaders/humus-dynamicbranching/9.frag create mode 100644 shaders/humus-dynamicbranching/9.vert create mode 100644 shaders/humus-hdr/1.frag create mode 100644 shaders/humus-hdr/1.vert create mode 100644 shaders/humus-hdr/2.frag create mode 100644 shaders/humus-hdr/2.vert create mode 100644 shaders/humus-hdr/3.frag create mode 100644 shaders/humus-hdr/3.vert create mode 100644 shaders/humus-hdr/4.frag create mode 100644 shaders/humus-hdr/4.vert create mode 100644 shaders/humus-hdr/5.frag create mode 100644 shaders/humus-hdr/5.vert create mode 100644 shaders/humus-hdr/6.frag create mode 100644 shaders/humus-hdr/6.vert create mode 100644 shaders/humus-portals/1.frag create mode 100644 shaders/humus-portals/1.vert create mode 100644 shaders/humus-portals/2.frag create mode 100644 shaders/humus-portals/2.vert create mode 100644 shaders/humus-raytracedshadows/1.frag create mode 100644 shaders/humus-raytracedshadows/1.vert create mode 100644 shaders/humus-raytracedshadows/2.frag create mode 100644 shaders/humus-raytracedshadows/2.vert create mode 100644 shaders/humus-raytracedshadows/3.frag create mode 100644 shaders/humus-raytracedshadows/3.vert create mode 100644 shaders/humus-raytracedshadows/4.frag create mode 100644 shaders/humus-raytracedshadows/4.vert create mode 100644 shaders/humus-raytracedshadows/5.frag create mode 100644 shaders/humus-raytracedshadows/5.vert create mode 100644 shaders/humus-raytracedshadows/6.frag create mode 100644 shaders/humus-raytracedshadows/6.vert create mode 100644 shaders/humus-volumetricfogging2/1.frag create mode 100644 shaders/humus-volumetricfogging2/1.vert create mode 100644 shaders/humus-volumetricfogging2/2.frag create mode 100644 shaders/humus-volumetricfogging2/2.vert create mode 100644 shaders/humus-volumetricfogging2/3.frag create mode 100644 shaders/humus-volumetricfogging2/3.vert (limited to 'shaders') diff --git a/shaders/humus-celshading/1.frag b/shaders/humus-celshading/1.frag new file mode 100644 index 0000000..1b58efc --- /dev/null +++ b/shaders/humus-celshading/1.frag @@ -0,0 +1,17 @@ +#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); +} + diff --git a/shaders/humus-celshading/1.vert b/shaders/humus-celshading/1.vert new file mode 100644 index 0000000..fb28d3b --- /dev/null +++ b/shaders/humus-celshading/1.vert @@ -0,0 +1,18 @@ +#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; +} + + diff --git a/shaders/humus-celshading/2.frag b/shaders/humus-celshading/2.frag new file mode 100644 index 0000000..97bf6df --- /dev/null +++ b/shaders/humus-celshading/2.frag @@ -0,0 +1,11 @@ +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#line 19 + + +varying vec3 norm; + +void main(){ + gl_FragColor = vec4(0.0); +} + diff --git a/shaders/humus-celshading/2.vert b/shaders/humus-celshading/2.vert new file mode 100644 index 0000000..63c2205 --- /dev/null +++ b/shaders/humus-celshading/2.vert @@ -0,0 +1,23 @@ +#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; +} + + diff --git a/shaders/humus-celshading/3.frag b/shaders/humus-celshading/3.frag new file mode 100644 index 0000000..4c72c26 --- /dev/null +++ b/shaders/humus-celshading/3.frag @@ -0,0 +1,6 @@ +uniform vec4 color; +void main() +{ + gl_FragColor = color; +} + diff --git a/shaders/humus-celshading/3.vert b/shaders/humus-celshading/3.vert new file mode 100644 index 0000000..b081d0f --- /dev/null +++ b/shaders/humus-celshading/3.vert @@ -0,0 +1,6 @@ +attribute vec4 position; +void main() +{ + gl_Position = position; +} + diff --git a/shaders/humus-domino/1.frag b/shaders/humus-domino/1.frag new file mode 100644 index 0000000..af0fff3 --- /dev/null +++ b/shaders/humus-domino/1.frag @@ -0,0 +1,28 @@ +#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); +} + diff --git a/shaders/humus-domino/1.vert b/shaders/humus-domino/1.vert new file mode 100644 index 0000000..4114202 --- /dev/null +++ b/shaders/humus-domino/1.vert @@ -0,0 +1,19 @@ +#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; +} + + + diff --git a/shaders/humus-domino/2.frag b/shaders/humus-domino/2.frag new file mode 100644 index 0000000..61ffb92 --- /dev/null +++ b/shaders/humus-domino/2.frag @@ -0,0 +1,36 @@ +#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); +} + diff --git a/shaders/humus-domino/2.vert b/shaders/humus-domino/2.vert new file mode 100644 index 0000000..df4b21d --- /dev/null +++ b/shaders/humus-domino/2.vert @@ -0,0 +1,47 @@ +#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); +} + + + diff --git a/shaders/humus-domino/3.frag b/shaders/humus-domino/3.frag new file mode 100644 index 0000000..4c72c26 --- /dev/null +++ b/shaders/humus-domino/3.frag @@ -0,0 +1,6 @@ +uniform vec4 color; +void main() +{ + gl_FragColor = color; +} + diff --git a/shaders/humus-domino/3.vert b/shaders/humus-domino/3.vert new file mode 100644 index 0000000..b081d0f --- /dev/null +++ b/shaders/humus-domino/3.vert @@ -0,0 +1,6 @@ +attribute vec4 position; +void main() +{ + gl_Position = position; +} + diff --git a/shaders/humus-dynamicbranching/1.frag b/shaders/humus-dynamicbranching/1.frag new file mode 100644 index 0000000..e911164 --- /dev/null +++ b/shaders/humus-dynamicbranching/1.frag @@ -0,0 +1,32 @@ +#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 + +} + diff --git a/shaders/humus-dynamicbranching/1.vert b/shaders/humus-dynamicbranching/1.vert new file mode 100644 index 0000000..df41037 --- /dev/null +++ b/shaders/humus-dynamicbranching/1.vert @@ -0,0 +1,29 @@ +#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 +} + + + diff --git a/shaders/humus-dynamicbranching/10.frag b/shaders/humus-dynamicbranching/10.frag new file mode 100644 index 0000000..889bbe7 --- /dev/null +++ b/shaders/humus-dynamicbranching/10.frag @@ -0,0 +1,63 @@ +#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; +} + diff --git a/shaders/humus-dynamicbranching/10.vert b/shaders/humus-dynamicbranching/10.vert new file mode 100644 index 0000000..8e1914b --- /dev/null +++ b/shaders/humus-dynamicbranching/10.vert @@ -0,0 +1,38 @@ +#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); +} + + + diff --git a/shaders/humus-dynamicbranching/11.frag b/shaders/humus-dynamicbranching/11.frag new file mode 100644 index 0000000..c9ea43d --- /dev/null +++ b/shaders/humus-dynamicbranching/11.frag @@ -0,0 +1,64 @@ +#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; +} + diff --git a/shaders/humus-dynamicbranching/11.vert b/shaders/humus-dynamicbranching/11.vert new file mode 100644 index 0000000..2e20300 --- /dev/null +++ b/shaders/humus-dynamicbranching/11.vert @@ -0,0 +1,39 @@ +#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); +} + + + diff --git a/shaders/humus-dynamicbranching/12.frag b/shaders/humus-dynamicbranching/12.frag new file mode 100644 index 0000000..c230815 --- /dev/null +++ b/shaders/humus-dynamicbranching/12.frag @@ -0,0 +1,10 @@ +#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); +} + diff --git a/shaders/humus-dynamicbranching/12.vert b/shaders/humus-dynamicbranching/12.vert new file mode 100644 index 0000000..0cffa84 --- /dev/null +++ b/shaders/humus-dynamicbranching/12.vert @@ -0,0 +1,19 @@ +#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); +} + + + diff --git a/shaders/humus-dynamicbranching/13.frag b/shaders/humus-dynamicbranching/13.frag new file mode 100644 index 0000000..4c72c26 --- /dev/null +++ b/shaders/humus-dynamicbranching/13.frag @@ -0,0 +1,6 @@ +uniform vec4 color; +void main() +{ + gl_FragColor = color; +} + diff --git a/shaders/humus-dynamicbranching/13.vert b/shaders/humus-dynamicbranching/13.vert new file mode 100644 index 0000000..b081d0f --- /dev/null +++ b/shaders/humus-dynamicbranching/13.vert @@ -0,0 +1,6 @@ +attribute vec4 position; +void main() +{ + gl_Position = position; +} + diff --git a/shaders/humus-dynamicbranching/2.frag b/shaders/humus-dynamicbranching/2.frag new file mode 100644 index 0000000..9032629 --- /dev/null +++ b/shaders/humus-dynamicbranching/2.frag @@ -0,0 +1,33 @@ +#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 + +} + diff --git a/shaders/humus-dynamicbranching/2.vert b/shaders/humus-dynamicbranching/2.vert new file mode 100644 index 0000000..2202e78 --- /dev/null +++ b/shaders/humus-dynamicbranching/2.vert @@ -0,0 +1,30 @@ +#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 +} + + + diff --git a/shaders/humus-dynamicbranching/3.frag b/shaders/humus-dynamicbranching/3.frag new file mode 100644 index 0000000..ad2e73c --- /dev/null +++ b/shaders/humus-dynamicbranching/3.frag @@ -0,0 +1,12 @@ +#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; +} + diff --git a/shaders/humus-dynamicbranching/3.vert b/shaders/humus-dynamicbranching/3.vert new file mode 100644 index 0000000..7b0a5d5 --- /dev/null +++ b/shaders/humus-dynamicbranching/3.vert @@ -0,0 +1,14 @@ +#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; +} + + + diff --git a/shaders/humus-dynamicbranching/4.frag b/shaders/humus-dynamicbranching/4.frag new file mode 100644 index 0000000..3244b1f --- /dev/null +++ b/shaders/humus-dynamicbranching/4.frag @@ -0,0 +1,82 @@ +#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; +varying vec3 vVec; +#ifdef SHADOWS +varying vec3 shadowVec[LIGHT_COUNT]; +#endif + +void main(){ +// float atten[LIGHT_COUNT]; + vec3 atten; + for (int i = 0; i < LIGHT_COUNT; i++){ + atten[i] = 1.0 - dot(lVec[i], lVec[i]); + } + atten = max(atten, 0.0); + + + 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 lighting = 0.1 * base; + +#ifdef BRANCHING + if (dot(atten, atten) > 0.0) +#endif + { + + vec3 bump = texture2D(Bump, plxTexCoord).xyz * 2.0 - 1.0; + bump = normalize(bump); + vec3 reflVec = reflect(-viewVec, bump); + + for (int i = 0; i < LIGHT_COUNT; i++){ +#ifndef BRANCHING + atten[i] *= float(lVec[i].z > 0.0); +#else + if (atten[i] > 0.0) + if (lVec[i].z > 0.0) +#endif + { + +#ifdef SHADOWS +# ifndef BRANCHING + atten[i] *= float(length(shadowVec[i]) < textureCube(ShadowMap, shadowVec[i])[i]); +# else + if (length(shadowVec[i]) < textureCube(ShadowMap, shadowVec[i])[i]) +# endif +#endif + { + vec3 lightVec = normalize(lVec[i]); + + float diffuse = saturate(dot(lightVec, bump)); + float specular = pow(saturate(dot(reflVec, lightVec)), 16.0); + + lighting += atten[i] * lightColor[i] * (diffuse * base + 0.6 * specular); + } + } + } + } + + gl_FragColor.rgb = lighting; +} + diff --git a/shaders/humus-dynamicbranching/4.vert b/shaders/humus-dynamicbranching/4.vert new file mode 100644 index 0000000..9dd0d12 --- /dev/null +++ b/shaders/humus-dynamicbranching/4.vert @@ -0,0 +1,45 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#define LIGHT_COUNT 3 +#line 2 +uniform vec3 camPos; +uniform vec3 lightPos[LIGHT_COUNT]; +uniform float invRadius[LIGHT_COUNT]; + +attribute vec2 textureCoord; +attribute vec3 tangent; +attribute vec3 binormal; +attribute vec3 normal; + +varying vec3 lVec[LIGHT_COUNT]; +varying vec2 texCoord; +varying vec3 vVec; +#ifdef SHADOWS +varying vec3 shadowVec[LIGHT_COUNT]; +#endif + +void main(){ + gl_Position = ftransform(); + + texCoord = textureCoord; + + for (int i = 0; i < LIGHT_COUNT; i++){ + vec3 lightVec = invRadius[i] * (lightPos[i] - gl_Vertex.xyz); + +#ifdef SHADOWS + shadowVec[i] = -lightVec; +#endif + lVec[i].x = dot(lightVec, tangent); + lVec[i].y = dot(lightVec, binormal); + lVec[i].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); +} + + + diff --git a/shaders/humus-dynamicbranching/5.frag b/shaders/humus-dynamicbranching/5.frag new file mode 100644 index 0000000..c3027fc --- /dev/null +++ b/shaders/humus-dynamicbranching/5.frag @@ -0,0 +1,83 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#define BRANCHING +#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; +varying vec3 vVec; +#ifdef SHADOWS +varying vec3 shadowVec[LIGHT_COUNT]; +#endif + +void main(){ +// float atten[LIGHT_COUNT]; + vec3 atten; + for (int i = 0; i < LIGHT_COUNT; i++){ + atten[i] = 1.0 - dot(lVec[i], lVec[i]); + } + atten = max(atten, 0.0); + + + 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 lighting = 0.1 * base; + +#ifdef BRANCHING + if (dot(atten, atten) > 0.0) +#endif + { + + vec3 bump = texture2D(Bump, plxTexCoord).xyz * 2.0 - 1.0; + bump = normalize(bump); + vec3 reflVec = reflect(-viewVec, bump); + + for (int i = 0; i < LIGHT_COUNT; i++){ +#ifndef BRANCHING + atten[i] *= float(lVec[i].z > 0.0); +#else + if (atten[i] > 0.0) + if (lVec[i].z > 0.0) +#endif + { + +#ifdef SHADOWS +# ifndef BRANCHING + atten[i] *= float(length(shadowVec[i]) < textureCube(ShadowMap, shadowVec[i])[i]); +# else + if (length(shadowVec[i]) < textureCube(ShadowMap, shadowVec[i])[i]) +# endif +#endif + { + vec3 lightVec = normalize(lVec[i]); + + float diffuse = saturate(dot(lightVec, bump)); + float specular = pow(saturate(dot(reflVec, lightVec)), 16.0); + + lighting += atten[i] * lightColor[i] * (diffuse * base + 0.6 * specular); + } + } + } + } + + gl_FragColor.rgb = lighting; +} + diff --git a/shaders/humus-dynamicbranching/5.vert b/shaders/humus-dynamicbranching/5.vert new file mode 100644 index 0000000..35161d5 --- /dev/null +++ b/shaders/humus-dynamicbranching/5.vert @@ -0,0 +1,46 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#define BRANCHING +#define LIGHT_COUNT 3 +#line 2 +uniform vec3 camPos; +uniform vec3 lightPos[LIGHT_COUNT]; +uniform float invRadius[LIGHT_COUNT]; + +attribute vec2 textureCoord; +attribute vec3 tangent; +attribute vec3 binormal; +attribute vec3 normal; + +varying vec3 lVec[LIGHT_COUNT]; +varying vec2 texCoord; +varying vec3 vVec; +#ifdef SHADOWS +varying vec3 shadowVec[LIGHT_COUNT]; +#endif + +void main(){ + gl_Position = ftransform(); + + texCoord = textureCoord; + + for (int i = 0; i < LIGHT_COUNT; i++){ + vec3 lightVec = invRadius[i] * (lightPos[i] - gl_Vertex.xyz); + +#ifdef SHADOWS + shadowVec[i] = -lightVec; +#endif + lVec[i].x = dot(lightVec, tangent); + lVec[i].y = dot(lightVec, binormal); + lVec[i].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); +} + + + diff --git a/shaders/humus-dynamicbranching/6.frag b/shaders/humus-dynamicbranching/6.frag new file mode 100644 index 0000000..7059fc0 --- /dev/null +++ b/shaders/humus-dynamicbranching/6.frag @@ -0,0 +1,83 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#define SHADOWS +#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; +varying vec3 vVec; +#ifdef SHADOWS +varying vec3 shadowVec[LIGHT_COUNT]; +#endif + +void main(){ +// float atten[LIGHT_COUNT]; + vec3 atten; + for (int i = 0; i < LIGHT_COUNT; i++){ + atten[i] = 1.0 - dot(lVec[i], lVec[i]); + } + atten = max(atten, 0.0); + + + 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 lighting = 0.1 * base; + +#ifdef BRANCHING + if (dot(atten, atten) > 0.0) +#endif + { + + vec3 bump = texture2D(Bump, plxTexCoord).xyz * 2.0 - 1.0; + bump = normalize(bump); + vec3 reflVec = reflect(-viewVec, bump); + + for (int i = 0; i < LIGHT_COUNT; i++){ +#ifndef BRANCHING + atten[i] *= float(lVec[i].z > 0.0); +#else + if (atten[i] > 0.0) + if (lVec[i].z > 0.0) +#endif + { + +#ifdef SHADOWS +# ifndef BRANCHING + atten[i] *= float(length(shadowVec[i]) < textureCube(ShadowMap, shadowVec[i])[i]); +# else + if (length(shadowVec[i]) < textureCube(ShadowMap, shadowVec[i])[i]) +# endif +#endif + { + vec3 lightVec = normalize(lVec[i]); + + float diffuse = saturate(dot(lightVec, bump)); + float specular = pow(saturate(dot(reflVec, lightVec)), 16.0); + + lighting += atten[i] * lightColor[i] * (diffuse * base + 0.6 * specular); + } + } + } + } + + gl_FragColor.rgb = lighting; +} + diff --git a/shaders/humus-dynamicbranching/6.vert b/shaders/humus-dynamicbranching/6.vert new file mode 100644 index 0000000..e0867e3 --- /dev/null +++ b/shaders/humus-dynamicbranching/6.vert @@ -0,0 +1,46 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#define SHADOWS +#define LIGHT_COUNT 3 +#line 2 +uniform vec3 camPos; +uniform vec3 lightPos[LIGHT_COUNT]; +uniform float invRadius[LIGHT_COUNT]; + +attribute vec2 textureCoord; +attribute vec3 tangent; +attribute vec3 binormal; +attribute vec3 normal; + +varying vec3 lVec[LIGHT_COUNT]; +varying vec2 texCoord; +varying vec3 vVec; +#ifdef SHADOWS +varying vec3 shadowVec[LIGHT_COUNT]; +#endif + +void main(){ + gl_Position = ftransform(); + + texCoord = textureCoord; + + for (int i = 0; i < LIGHT_COUNT; i++){ + vec3 lightVec = invRadius[i] * (lightPos[i] - gl_Vertex.xyz); + +#ifdef SHADOWS + shadowVec[i] = -lightVec; +#endif + lVec[i].x = dot(lightVec, tangent); + lVec[i].y = dot(lightVec, binormal); + lVec[i].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); +} + + + diff --git a/shaders/humus-dynamicbranching/7.frag b/shaders/humus-dynamicbranching/7.frag new file mode 100644 index 0000000..f855983 --- /dev/null +++ b/shaders/humus-dynamicbranching/7.frag @@ -0,0 +1,84 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#define SHADOWS +#define BRANCHING +#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; +varying vec3 vVec; +#ifdef SHADOWS +varying vec3 shadowVec[LIGHT_COUNT]; +#endif + +void main(){ +// float atten[LIGHT_COUNT]; + vec3 atten; + for (int i = 0; i < LIGHT_COUNT; i++){ + atten[i] = 1.0 - dot(lVec[i], lVec[i]); + } + atten = max(atten, 0.0); + + + 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 lighting = 0.1 * base; + +#ifdef BRANCHING + if (dot(atten, atten) > 0.0) +#endif + { + + vec3 bump = texture2D(Bump, plxTexCoord).xyz * 2.0 - 1.0; + bump = normalize(bump); + vec3 reflVec = reflect(-viewVec, bump); + + for (int i = 0; i < LIGHT_COUNT; i++){ +#ifndef BRANCHING + atten[i] *= float(lVec[i].z > 0.0); +#else + if (atten[i] > 0.0) + if (lVec[i].z > 0.0) +#endif + { + +#ifdef SHADOWS +# ifndef BRANCHING + atten[i] *= float(length(shadowVec[i]) < textureCube(ShadowMap, shadowVec[i])[i]); +# else + if (length(shadowVec[i]) < textureCube(ShadowMap, shadowVec[i])[i]) +# endif +#endif + { + vec3 lightVec = normalize(lVec[i]); + + float diffuse = saturate(dot(lightVec, bump)); + float specular = pow(saturate(dot(reflVec, lightVec)), 16.0); + + lighting += atten[i] * lightColor[i] * (diffuse * base + 0.6 * specular); + } + } + } + } + + gl_FragColor.rgb = lighting; +} + diff --git a/shaders/humus-dynamicbranching/7.vert b/shaders/humus-dynamicbranching/7.vert new file mode 100644 index 0000000..13116ad --- /dev/null +++ b/shaders/humus-dynamicbranching/7.vert @@ -0,0 +1,47 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#define SHADOWS +#define BRANCHING +#define LIGHT_COUNT 3 +#line 2 +uniform vec3 camPos; +uniform vec3 lightPos[LIGHT_COUNT]; +uniform float invRadius[LIGHT_COUNT]; + +attribute vec2 textureCoord; +attribute vec3 tangent; +attribute vec3 binormal; +attribute vec3 normal; + +varying vec3 lVec[LIGHT_COUNT]; +varying vec2 texCoord; +varying vec3 vVec; +#ifdef SHADOWS +varying vec3 shadowVec[LIGHT_COUNT]; +#endif + +void main(){ + gl_Position = ftransform(); + + texCoord = textureCoord; + + for (int i = 0; i < LIGHT_COUNT; i++){ + vec3 lightVec = invRadius[i] * (lightPos[i] - gl_Vertex.xyz); + +#ifdef SHADOWS + shadowVec[i] = -lightVec; +#endif + lVec[i].x = dot(lightVec, tangent); + lVec[i].y = dot(lightVec, binormal); + lVec[i].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); +} + + + diff --git a/shaders/humus-dynamicbranching/8.frag b/shaders/humus-dynamicbranching/8.frag new file mode 100644 index 0000000..d993cbb --- /dev/null +++ b/shaders/humus-dynamicbranching/8.frag @@ -0,0 +1,62 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#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; +} + diff --git a/shaders/humus-dynamicbranching/8.vert b/shaders/humus-dynamicbranching/8.vert new file mode 100644 index 0000000..c85acdd --- /dev/null +++ b/shaders/humus-dynamicbranching/8.vert @@ -0,0 +1,37 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#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); +} + + + diff --git a/shaders/humus-dynamicbranching/9.frag b/shaders/humus-dynamicbranching/9.frag new file mode 100644 index 0000000..6ebce5a --- /dev/null +++ b/shaders/humus-dynamicbranching/9.frag @@ -0,0 +1,63 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#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; +} + diff --git a/shaders/humus-dynamicbranching/9.vert b/shaders/humus-dynamicbranching/9.vert new file mode 100644 index 0000000..e9b8a9b --- /dev/null +++ b/shaders/humus-dynamicbranching/9.vert @@ -0,0 +1,38 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#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); +} + + + diff --git a/shaders/humus-hdr/1.frag b/shaders/humus-hdr/1.frag new file mode 100644 index 0000000..d46a8cb --- /dev/null +++ b/shaders/humus-hdr/1.frag @@ -0,0 +1,39 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix + +varying vec2 texCoord, lmCoord; +varying vec3 lightVec; +varying vec3 vVec; + + +#line 36 +uniform sampler2D Base; +uniform sampler2D Bump; +uniform sampler2D LightMap; + +uniform vec2 plx; +uniform float gloss; + +const vec3 lightColor = vec3(0.12, 0.14, 0.2); + +void main(){ + vec3 viewVec = normalize(vVec); + + float height = texture2D(Bump, texCoord).a; + vec2 plxCoord = texCoord + (height * plx.x + plx.y) * viewVec.xy; + + + vec3 base = texture2D(Base, plxCoord).rgb; + vec3 bump = texture2D(Bump, plxCoord).xyz; + vec3 normal = normalize(bump * 2.0 - 1.0); + + float diffuse = saturate(dot(lightVec, normal)); + float specular = pow(saturate(dot(reflect(-viewVec, normal), lightVec)), 16.0); + + + vec4 shadow = texture2D(LightMap, lmCoord); + + gl_FragColor.rgb = lightColor * (shadow.x * (diffuse * base + gloss * specular) + 0.7 * shadow.w * base); +} + diff --git a/shaders/humus-hdr/1.vert b/shaders/humus-hdr/1.vert new file mode 100644 index 0000000..7916aba --- /dev/null +++ b/shaders/humus-hdr/1.vert @@ -0,0 +1,37 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix + +varying vec2 texCoord, lmCoord; +varying vec3 lightVec; +varying vec3 vVec; + + +#line 8 +attribute vec2 textureCoord; +attribute vec3 tangent; +attribute vec3 binormal; +attribute vec3 normal; +attribute vec2 lightMapCoord; + +uniform vec3 lightDir; +uniform vec3 camPos; + +void main(){ + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + + texCoord = textureCoord; + lmCoord = lightMapCoord; + + lightVec.x = dot(lightDir, tangent); + lightVec.y = dot(lightDir, binormal); + lightVec.z = dot(lightDir, normal); + + vec3 viewVec = camPos - gl_Vertex.xyz; + vVec.x = dot(viewVec, tangent); + vVec.y = dot(viewVec, binormal); + vVec.z = dot(viewVec, normal); +} + + + diff --git a/shaders/humus-hdr/2.frag b/shaders/humus-hdr/2.frag new file mode 100644 index 0000000..646d789 --- /dev/null +++ b/shaders/humus-hdr/2.frag @@ -0,0 +1,23 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix + +varying vec3 cubeCoord; + + +#line 14 +uniform samplerCube RGB; +uniform samplerCube Exp; + +uniform vec2 scaleBias; + +void main(){ + vec3 sky = textureCube(RGB, cubeCoord).rgb; + float ex = textureCube(Exp, cubeCoord).x; + + // Expand RGBE + sky *= exp2(ex * scaleBias.x + scaleBias.y); + + gl_FragColor.rgb = sky.rgb; +} + diff --git a/shaders/humus-hdr/2.vert b/shaders/humus-hdr/2.vert new file mode 100644 index 0000000..b888dcc --- /dev/null +++ b/shaders/humus-hdr/2.vert @@ -0,0 +1,15 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix + +varying vec3 cubeCoord; + + +#line 6 +void main(){ + gl_Position = gl_Vertex; + cubeCoord = gl_MultiTexCoord0.xyz; +} + + + diff --git a/shaders/humus-hdr/3.frag b/shaders/humus-hdr/3.frag new file mode 100644 index 0000000..ccd7b36 --- /dev/null +++ b/shaders/humus-hdr/3.frag @@ -0,0 +1,26 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix + +varying vec2 texCoord0; +varying vec2 texCoord1; +varying vec2 texCoord2; +varying vec2 texCoord3; + + +#line 25 +uniform sampler2D Image; + +uniform float invRange; + +void main(){ + // Downscale and convert to fixed point + vec3 base = texture2D(Image, texCoord0).rgb; + base += texture2D(Image, texCoord1).rgb; + base += texture2D(Image, texCoord2).rgb; + base += texture2D(Image, texCoord3).rgb; + + // Clamp for nvidia ... + gl_FragColor.rgb = min(base.rgb * invRange, 1.0); +} + diff --git a/shaders/humus-hdr/3.vert b/shaders/humus-hdr/3.vert new file mode 100644 index 0000000..5addf41 --- /dev/null +++ b/shaders/humus-hdr/3.vert @@ -0,0 +1,26 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix + +varying vec2 texCoord0; +varying vec2 texCoord1; +varying vec2 texCoord2; +varying vec2 texCoord3; + + +#line 9 +uniform vec2 halfPixel; + +void main(){ + gl_Position = gl_Vertex; + + vec2 texCoord = gl_Vertex.xy * 0.5 + 0.5; + + texCoord0 = texCoord + halfPixel * vec2( 1, 1); + texCoord1 = texCoord + halfPixel * vec2(-1, 1); + texCoord2 = texCoord + halfPixel * vec2(-1, -1); + texCoord3 = texCoord + halfPixel * vec2( 1, -1); +} + + + diff --git a/shaders/humus-hdr/4.frag b/shaders/humus-hdr/4.frag new file mode 100644 index 0000000..c9f9c34 --- /dev/null +++ b/shaders/humus-hdr/4.frag @@ -0,0 +1,22 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix + +varying vec2 texCoord0; +varying vec2 texCoord1; +varying vec2 texCoord2; +varying vec2 texCoord3; + + +#line 24 +uniform sampler2D Image; + +void main(){ + vec3 base = texture2D(Image, texCoord0).rgb; + base += texture2D(Image, texCoord1).rgb; + base += texture2D(Image, texCoord2).rgb; + base += texture2D(Image, texCoord3).rgb; + + gl_FragColor.rgb = 0.25 * base.rgb; +} + diff --git a/shaders/humus-hdr/4.vert b/shaders/humus-hdr/4.vert new file mode 100644 index 0000000..6dd49b7 --- /dev/null +++ b/shaders/humus-hdr/4.vert @@ -0,0 +1,25 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix + +varying vec2 texCoord0; +varying vec2 texCoord1; +varying vec2 texCoord2; +varying vec2 texCoord3; + + +#line 9 +uniform vec2 sample0, sample1, sample2, sample3; + +void main(){ + gl_Position = gl_Vertex; + + vec2 texCoord = gl_Vertex.xy * 0.5 + 0.5; + texCoord0 = texCoord + sample0; + texCoord1 = texCoord + sample1; + texCoord2 = texCoord + sample2; + texCoord3 = texCoord + sample3; +} + + + diff --git a/shaders/humus-hdr/5.frag b/shaders/humus-hdr/5.frag new file mode 100644 index 0000000..9418882 --- /dev/null +++ b/shaders/humus-hdr/5.frag @@ -0,0 +1,28 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix + +varying vec2 texCoord; + + +#line 15 +uniform sampler2D Base; +uniform sampler2D Blur; + +uniform float exposure; +uniform float range; +uniform float blurStrength; + +void main(){ + vec4 base = texture2D(Base, texCoord); + vec4 blur = texture2D(Blur, texCoord); + + blur.rgb = pow(blur.rgb, vec3(blurStrength)); + + blur *= range; + + vec4 color = base + blur; + + gl_FragColor.rgb = 1.0 - exp(-exposure * color.rgb); +} + diff --git a/shaders/humus-hdr/5.vert b/shaders/humus-hdr/5.vert new file mode 100644 index 0000000..dd00aed --- /dev/null +++ b/shaders/humus-hdr/5.vert @@ -0,0 +1,16 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix + +varying vec2 texCoord; + + +#line 6 +void main(){ + gl_Position = gl_Vertex; + + texCoord = gl_Vertex.xy * 0.5 + 0.5; +} + + + diff --git a/shaders/humus-hdr/6.frag b/shaders/humus-hdr/6.frag new file mode 100644 index 0000000..4c72c26 --- /dev/null +++ b/shaders/humus-hdr/6.frag @@ -0,0 +1,6 @@ +uniform vec4 color; +void main() +{ + gl_FragColor = color; +} + diff --git a/shaders/humus-hdr/6.vert b/shaders/humus-hdr/6.vert new file mode 100644 index 0000000..b081d0f --- /dev/null +++ b/shaders/humus-hdr/6.vert @@ -0,0 +1,6 @@ +attribute vec4 position; +void main() +{ + gl_Position = position; +} + diff --git a/shaders/humus-portals/1.frag b/shaders/humus-portals/1.frag new file mode 100644 index 0000000..9503ded --- /dev/null +++ b/shaders/humus-portals/1.frag @@ -0,0 +1,32 @@ +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#line 26 + + +uniform sampler2D Base; +uniform sampler2D Bump; + +uniform float invRadius; +uniform float ambient; + +varying vec2 texCoord; +varying vec3 lightVec; +varying vec3 viewVec; + +void main(){ + vec4 base = texture2D(Base, texCoord); + vec3 bump = texture2D(Bump, texCoord).xyz * 2.0 - 1.0; + + bump = normalize(bump); + + float distSqr = dot(lightVec, lightVec); + vec3 lVec = lightVec * inversesqrt(distSqr); + + float atten = clamp(1.0 - invRadius * sqrt(distSqr), 0.0, 1.0); + float diffuse = clamp(dot(lVec, bump), 0.0, 1.0); + + float specular = pow(clamp(dot(reflect(normalize(-viewVec), bump), lVec), 0.0, 1.0), 16.0); + + gl_FragColor = ambient * base + (diffuse * base + 0.6 * specular) * atten; +} + diff --git a/shaders/humus-portals/1.vert b/shaders/humus-portals/1.vert new file mode 100644 index 0000000..7a83406 --- /dev/null +++ b/shaders/humus-portals/1.vert @@ -0,0 +1,30 @@ +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#line 0 + + +varying vec2 texCoord; +varying vec3 lightVec; +varying vec3 viewVec; + +uniform vec3 lightPos; +uniform vec3 camPos; + +void main(){ + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + + texCoord = gl_MultiTexCoord0.xy; + + vec3 lVec = lightPos - gl_Vertex.xyz; + lightVec.x = dot(gl_MultiTexCoord1.xyz, lVec); + lightVec.y = dot(gl_MultiTexCoord2.xyz, lVec); + lightVec.z = dot(gl_MultiTexCoord3.xyz, lVec); + + vec3 vVec = camPos - gl_Vertex.xyz; + viewVec.x = dot(gl_MultiTexCoord1.xyz, vVec); + viewVec.y = dot(gl_MultiTexCoord2.xyz, vVec); + viewVec.z = dot(gl_MultiTexCoord3.xyz, vVec); +} + + + diff --git a/shaders/humus-portals/2.frag b/shaders/humus-portals/2.frag new file mode 100644 index 0000000..4c72c26 --- /dev/null +++ b/shaders/humus-portals/2.frag @@ -0,0 +1,6 @@ +uniform vec4 color; +void main() +{ + gl_FragColor = color; +} + diff --git a/shaders/humus-portals/2.vert b/shaders/humus-portals/2.vert new file mode 100644 index 0000000..b081d0f --- /dev/null +++ b/shaders/humus-portals/2.vert @@ -0,0 +1,6 @@ +attribute vec4 position; +void main() +{ + gl_Position = position; +} + diff --git a/shaders/humus-raytracedshadows/1.frag b/shaders/humus-raytracedshadows/1.frag new file mode 100644 index 0000000..00a7027 --- /dev/null +++ b/shaders/humus-raytracedshadows/1.frag @@ -0,0 +1,25 @@ +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#define SHADOW_SOFTNESS 0.0005 +#define SPHERE_COUNT 7 +#line 26 + + +varying vec3 lightVec; +varying vec4 sphereVec[SPHERE_COUNT]; + +void main(){ + vec4 shadow = vec4(1.0); + + vec3 lVec = lightVec / dot(lightVec, lightVec); + for (int i = 0; i < SPHERE_COUNT; i++){ + float t = saturate(dot(sphereVec[i].xyz, lVec)); + vec3 p = t * lightVec - sphereVec[i].xyz; + float len = dot(p, p); + + shadow.w *= saturate(SHADOW_SOFTNESS * len - sphereVec[i].w); + } + + gl_FragColor = shadow; +} + diff --git a/shaders/humus-raytracedshadows/1.vert b/shaders/humus-raytracedshadows/1.vert new file mode 100644 index 0000000..b480549 --- /dev/null +++ b/shaders/humus-raytracedshadows/1.vert @@ -0,0 +1,32 @@ +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#define SHADOW_SOFTNESS 0.0005 +#define SPHERE_COUNT 7 +#line 0 + + +uniform float scale; +uniform vec3 offset; + +uniform vec3 lightPos; +uniform vec4 spherePos[SPHERE_COUNT]; + +varying vec3 lightVec; +varying vec4 sphereVec[SPHERE_COUNT]; + +void main(){ + vec4 pos = gl_Vertex; + pos.xyz *= scale; + pos.xyz += offset; + + gl_Position = gl_ModelViewProjectionMatrix * pos; + + lightVec = lightPos - pos.xyz; + for (int i = 0; i < SPHERE_COUNT; i++){ + sphereVec[i].xyz = spherePos[i].xyz - pos.xyz; + sphereVec[i].w = spherePos[i].w * SHADOW_SOFTNESS - 0.5; + } +} + + + diff --git a/shaders/humus-raytracedshadows/2.frag b/shaders/humus-raytracedshadows/2.frag new file mode 100644 index 0000000..6307be1 --- /dev/null +++ b/shaders/humus-raytracedshadows/2.frag @@ -0,0 +1,20 @@ +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#line 26 + + +uniform sampler2D Base; +uniform sampler2D Bump; + +varying vec2 texCoord; +varying vec3 lVec; + +void main(){ + vec4 base = texture2D(Base, texCoord); + vec3 bump = normalize(texture2D(Bump, texCoord).xyz * 2.0 - 1.0); + + float diffuse = dot(normalize(lVec), bump); + + gl_FragColor = diffuse * base; +} + diff --git a/shaders/humus-raytracedshadows/2.vert b/shaders/humus-raytracedshadows/2.vert new file mode 100644 index 0000000..195cb8e --- /dev/null +++ b/shaders/humus-raytracedshadows/2.vert @@ -0,0 +1,30 @@ +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#line 0 + + +uniform vec3 lightPos; +uniform vec3 camPos; + +attribute vec2 textureCoord; +attribute vec3 tangent; +attribute vec3 binormal; +attribute vec3 normal; + +varying vec2 texCoord; +varying vec3 lVec; + +void main(){ + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + texCoord = textureCoord; + + vec3 lightVec = lightPos - gl_Vertex.xyz; + vec3 viewVec = lightPos - gl_Vertex.xyz; + + lVec.x = dot(lightVec, tangent); + lVec.y = dot(lightVec, binormal); + lVec.z = dot(lightVec, normal); +} + + + diff --git a/shaders/humus-raytracedshadows/3.frag b/shaders/humus-raytracedshadows/3.frag new file mode 100644 index 0000000..649ceaf --- /dev/null +++ b/shaders/humus-raytracedshadows/3.frag @@ -0,0 +1,15 @@ +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#line 12 + + +uniform sampler2D Base; + +varying vec2 texCoord; + +void main(){ + vec4 base = texture2D(Base, texCoord); + + gl_FragColor = 0.17 * base; +} + diff --git a/shaders/humus-raytracedshadows/3.vert b/shaders/humus-raytracedshadows/3.vert new file mode 100644 index 0000000..899dc72 --- /dev/null +++ b/shaders/humus-raytracedshadows/3.vert @@ -0,0 +1,16 @@ +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#line 0 + + +attribute vec2 textureCoord; + +varying vec2 texCoord; + +void main(){ + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + texCoord = textureCoord; +} + + + diff --git a/shaders/humus-raytracedshadows/4.frag b/shaders/humus-raytracedshadows/4.frag new file mode 100644 index 0000000..62bb66b --- /dev/null +++ b/shaders/humus-raytracedshadows/4.frag @@ -0,0 +1,22 @@ +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#line 25 + + +uniform vec4 color; + +varying vec3 lVec; +varying vec3 vVec; +varying vec3 norm; + +void main(){ + vec3 lightVec = (lVec); + vec3 viewVec = (vVec); + vec3 normal = normalize(norm); + + float diffuse = saturate(dot(lightVec, normal)); + float specular = pow(saturate(dot(reflect(-viewVec, normal), lightVec)), 20.0); + + gl_FragColor = diffuse * color + specular; +} + diff --git a/shaders/humus-raytracedshadows/4.vert b/shaders/humus-raytracedshadows/4.vert new file mode 100644 index 0000000..9994755 --- /dev/null +++ b/shaders/humus-raytracedshadows/4.vert @@ -0,0 +1,29 @@ +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#line 0 + + +uniform float scale; +uniform vec3 offset; + +uniform vec3 lightPos; +uniform vec3 camPos; + +varying vec3 lVec; +varying vec3 vVec; +varying vec3 norm; + +void main(){ + vec4 pos = gl_Vertex; + pos.xyz *= scale; + pos.xyz += offset; + + gl_Position = gl_ModelViewProjectionMatrix * pos; + + lVec = normalize(lightPos - pos.xyz); + vVec = normalize(camPos - pos.xyz); + norm = gl_Vertex.xyz; +} + + + diff --git a/shaders/humus-raytracedshadows/5.frag b/shaders/humus-raytracedshadows/5.frag new file mode 100644 index 0000000..43cbb45 --- /dev/null +++ b/shaders/humus-raytracedshadows/5.frag @@ -0,0 +1,16 @@ +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#line 22 + + +uniform vec4 color; + +varying vec3 lightVec; +varying vec3 normal; + +void main(){ + float diffuse = 0.17 * (0.4 * dot(lightVec, normal) + 0.6); + + gl_FragColor = diffuse * color; +} + diff --git a/shaders/humus-raytracedshadows/5.vert b/shaders/humus-raytracedshadows/5.vert new file mode 100644 index 0000000..3c3c10a --- /dev/null +++ b/shaders/humus-raytracedshadows/5.vert @@ -0,0 +1,26 @@ +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#line 0 + + +uniform vec3 lightPos; + +uniform float scale; +uniform vec3 offset; + +varying vec3 lightVec; +varying vec3 normal; + +void main(){ + vec4 pos = gl_Vertex; + pos.xyz *= scale; + pos.xyz += offset; + + gl_Position = gl_ModelViewProjectionMatrix * pos; + + lightVec = normalize(lightPos - pos.xyz); + normal = gl_Vertex.xyz; +} + + + diff --git a/shaders/humus-raytracedshadows/6.frag b/shaders/humus-raytracedshadows/6.frag new file mode 100644 index 0000000..4c72c26 --- /dev/null +++ b/shaders/humus-raytracedshadows/6.frag @@ -0,0 +1,6 @@ +uniform vec4 color; +void main() +{ + gl_FragColor = color; +} + diff --git a/shaders/humus-raytracedshadows/6.vert b/shaders/humus-raytracedshadows/6.vert new file mode 100644 index 0000000..b081d0f --- /dev/null +++ b/shaders/humus-raytracedshadows/6.vert @@ -0,0 +1,6 @@ +attribute vec4 position; +void main() +{ + gl_Position = position; +} + diff --git a/shaders/humus-volumetricfogging2/1.frag b/shaders/humus-volumetricfogging2/1.frag new file mode 100644 index 0000000..d2aacd6 --- /dev/null +++ b/shaders/humus-volumetricfogging2/1.frag @@ -0,0 +1,86 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#define COUNT 40 +#define FIRST_PASS +#line 52 +uniform sampler2D Base; +uniform sampler2D Bump; +uniform sampler3D Fog; +uniform sampler3D LightMap; + +varying vec2 texCoord; +varying vec3 lVec; +varying vec3 vVec; + +varying vec3 dir; + +varying vec3 fogCrd; +varying vec3 shadowCrd; + +uniform float fogStart; +uniform vec3 shadowStart; + +uniform vec4 fogScaleBias; +uniform vec3 shadowScale, shadowBias; + +void main(){ + const vec3 fogColor = vec3(0.9, 1.0, 0.8); + const float fogDensity = 0.005; + + float n = fogDensity * length(dir); + + vec3 fogCoord = fogCrd; + vec3 shadowCoord = shadowCrd; + +#ifdef FIRST_PASS + + // Regular per pixel lighting + float atten = 1.0 / (1.0 + 0.000001 * dot(lVec, lVec)); + vec3 lightVec = normalize(lVec); + vec3 viewVec = normalize(vVec); + + vec3 base = texture2D(Base, texCoord).rgb; + vec3 normal = normalize(texture2D(Bump, texCoord).xyz * 2.0 - 1.0); + + float diffuse = saturate(dot(lightVec, normal)); + float specular = pow(saturate(dot(reflect(-viewVec, normal), lightVec)), 16.0); + + float shadow = texture3D(LightMap, shadowCrd).x; + + vec3 lighting = atten * shadow * (diffuse * base + 0.5 * specular) + 0.14 * base; +#else + + // For later passes, continue the fog computation where we stopped last pass + fogCoord += fogStart * dir; + shadowCoord += shadowStart * dir; + +#endif + + float a = 1.0; + float b = 0.0; + + // Volumetric fog computation + for (int i = 0; i < COUNT; i++){ + fogCoord += fogScaleBias.w * dir; + shadowCoord += shadowScale * dir; + + float fog = texture3D(Fog, fogCoord).x; + float shadow = texture3D(LightMap, shadowCoord).x; + + // Compute weighting factors. This implements the commented out lerp more efficiently. + float x = 1.0 - fog * n; + a *= x; + b = lerp(shadow, b, x); + } + +#ifdef FIRST_PASS + gl_FragColor.rgb = lighting * a + fogColor * b; +#else + // "lighting" is in the framebuffer, so we use alpha blending to multiply it with "a". + gl_FragColor.rgb = b * fogColor; + gl_FragColor.a = a; +#endif + +} + diff --git a/shaders/humus-volumetricfogging2/1.vert b/shaders/humus-volumetricfogging2/1.vert new file mode 100644 index 0000000..6b1d7af --- /dev/null +++ b/shaders/humus-volumetricfogging2/1.vert @@ -0,0 +1,55 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#define COUNT 40 +#define FIRST_PASS +#line 2 +uniform mat4 mvp; + +uniform vec3 lightPos; +uniform vec3 camPos; + +attribute vec2 textureCoord; +attribute vec3 tangent; +attribute vec3 binormal; +attribute vec3 normal; + +varying vec2 texCoord; +varying vec3 lVec; +varying vec3 vVec; + +varying vec3 dir; + +varying vec3 fogCrd; +varying vec3 shadowCrd; + + +uniform vec4 fogScaleBias; +uniform vec3 shadowScale, shadowBias; + +void main(){ + gl_Position = mvp * gl_Vertex; + + vec3 viewVec = camPos - gl_Vertex.xyz; + +#ifdef FIRST_PASS + texCoord = textureCoord; + + vec3 lightVec = lightPos - gl_Vertex.xyz; + lVec.x = dot(lightVec, tangent); + lVec.y = dot(lightVec, binormal); + lVec.z = dot(lightVec, normal); + + vVec.x = dot(viewVec, tangent); + vVec.y = dot(viewVec, binormal); + vVec.z = dot(viewVec, normal); +#endif + + dir = viewVec / 40.0; + + fogCrd = gl_Vertex.xyz * fogScaleBias.w + fogScaleBias.xyz; + shadowCrd = gl_Vertex.xyz * shadowScale + shadowBias; +} + + + diff --git a/shaders/humus-volumetricfogging2/2.frag b/shaders/humus-volumetricfogging2/2.frag new file mode 100644 index 0000000..469786f --- /dev/null +++ b/shaders/humus-volumetricfogging2/2.frag @@ -0,0 +1,8 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#line 11 +void main(){ + gl_FragColor = vec4(0.0); +} + diff --git a/shaders/humus-volumetricfogging2/2.vert b/shaders/humus-volumetricfogging2/2.vert new file mode 100644 index 0000000..e42df26 --- /dev/null +++ b/shaders/humus-volumetricfogging2/2.vert @@ -0,0 +1,12 @@ +#version 120 +#define saturate(x) clamp(x,0.0,1.0) +#define lerp mix +#line 2 +uniform mat4 mvp; + +void main(){ + gl_Position = mvp * gl_Vertex; +} + + + diff --git a/shaders/humus-volumetricfogging2/3.frag b/shaders/humus-volumetricfogging2/3.frag new file mode 100644 index 0000000..4c72c26 --- /dev/null +++ b/shaders/humus-volumetricfogging2/3.frag @@ -0,0 +1,6 @@ +uniform vec4 color; +void main() +{ + gl_FragColor = color; +} + diff --git a/shaders/humus-volumetricfogging2/3.vert b/shaders/humus-volumetricfogging2/3.vert new file mode 100644 index 0000000..b081d0f --- /dev/null +++ b/shaders/humus-volumetricfogging2/3.vert @@ -0,0 +1,6 @@ +attribute vec4 position; +void main() +{ + gl_Position = position; +} + -- cgit v1.2.3