diff --git a/data/fogZLight_frag.glsl b/data/fogZLight_frag.glsl new file mode 100644 index 0000000..6ad1ef3 --- /dev/null +++ b/data/fogZLight_frag.glsl @@ -0,0 +1,40 @@ +#ifdef GL_ES +precision mediump float; +precision mediump int; +#endif + +//This shader creates a depth based fog as well as highlighting a specific zDepth plane. + +varying vec4 vertColor; +varying vec3 ecNormal; +varying vec3 lightDir; + +uniform float zPlane; +uniform float fogNear; +uniform float fogFar; +uniform vec4 fogColor; +uniform bool zPlaneIndicatorOn; + +const vec4 highlightCol = vec4(1.0, 0.0, 0.0, 1.0); + +void main() { + vec3 direction = normalize(lightDir); + vec3 normal = normalize( ecNormal ); + float intensity = max( 0.0, dot( direction, normal) ); + + + float depth = 1.0 / gl_FragCoord.w; + float hlFactor = 0.6 / (pow( zPlane - depth, 2.0) + 1.0); + float fogFactor = smoothstep( fogNear, fogFar, depth ); + + + vec4 lit = vec4(intensity, intensity, intensity, 1) * vertColor; + gl_FragColor = mix( lit, vertColor, 0.75 ); + gl_FragColor = mix(gl_FragColor, fogColor, fogFactor); + + + if( zPlaneIndicatorOn ) { + gl_FragColor = mix(gl_FragColor, highlightCol, hlFactor); + } +} + diff --git a/data/fogZLight_vert.glsl b/data/fogZLight_vert.glsl new file mode 100644 index 0000000..b178e54 --- /dev/null +++ b/data/fogZLight_vert.glsl @@ -0,0 +1,25 @@ +#define PROCESSING_LIGHT_SHADER + +uniform mat4 modelview; +uniform mat4 transform; +uniform mat3 normalMatrix; + +uniform vec4 lightPosition; +uniform vec3 lightNormal; + +attribute vec4 vertex; //vertex -----> gl_Vertex +attribute vec4 color; //color ------> gl_Color +attribute vec3 normal; + +varying vec4 vertColor; +varying vec3 ecNormal; +varying vec3 lightDir; + +void main() { + gl_Position = transform * vertex; // gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + vec3 ecVertex = vec3(modelview * vertex); + + ecNormal = normalize( normalMatrix * normal ); + lightDir = normalize( lightPosition.xyz - ecVertex ); + vertColor = color; +}