-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |