diff options
Diffstat (limited to 'shaders/humus-dynamicbranching/31.shader_test')
-rw-r--r-- | shaders/humus-dynamicbranching/31.shader_test | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/shaders/humus-dynamicbranching/31.shader_test b/shaders/humus-dynamicbranching/31.shader_test new file mode 100644 index 0000000..3c0849a --- /dev/null +++ b/shaders/humus-dynamicbranching/31.shader_test @@ -0,0 +1,122 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#version 130 +#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; +} + + + + + + + + + + + + + + + +[vertex shader] +#version 130 +#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); +} + + + |