Skip to content

Commit

Permalink
Added new shader with lights.
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyegan committed Feb 28, 2014
1 parent 3889cdb commit 7f66574
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
40 changes: 40 additions & 0 deletions data/fogZLight_frag.glsl
Original file line number Diff line number Diff line change
@@ -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);
}
}

25 changes: 25 additions & 0 deletions data/fogZLight_vert.glsl
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 7f66574

Please sign in to comment.