forked from prisonerjohn/ofxWarp
-
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.
added openGL 2 shaders (#version 120)
- Loading branch information
Showing
7 changed files
with
158 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
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,19 @@ | ||
#version 120 | ||
|
||
varying vec3 v; | ||
varying vec3 N; | ||
|
||
varying vec2 vTexCoord; | ||
varying vec4 vColor; | ||
|
||
void main(void) { | ||
|
||
vec2 coord = gl_TexCoord[0].st; | ||
vec2 uv = coord * 2.0 - 1.0; | ||
float d = dot(uv, uv); | ||
float rim = smoothstep(0.7, 0.8, d); | ||
rim += smoothstep(0.3, 0.4, d) - smoothstep(0.5, 0.6, d); | ||
rim += smoothstep(0.1, 0.0, d); | ||
gl_FragColor = mix(vec4( 0.0, 0.0, 0.0, 0.25), vColor, rim); | ||
|
||
} |
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,23 @@ | ||
#version 120 | ||
|
||
varying vec3 v; | ||
varying vec3 N; | ||
|
||
attribute vec4 iPositionScale; | ||
attribute vec4 iColor; | ||
|
||
attribute vec4 position; | ||
attribute vec2 texcoord; | ||
attribute vec4 color; | ||
|
||
varying vec2 vTexCoord; | ||
varying vec4 vColor; | ||
|
||
void main(void) { | ||
|
||
vTexCoord = texcoord; | ||
vColor = gl_Color * iColor; | ||
gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xy * iPositionScale.z + iPositionScale.xy, position.zw); | ||
|
||
|
||
} |
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,55 @@ | ||
#version 120 | ||
|
||
varying vec3 v; | ||
varying vec3 N; | ||
|
||
uniform sampler2DRect uTexture; | ||
uniform vec4 uExtends; | ||
uniform vec3 uLuminance; | ||
uniform vec3 uGamma; | ||
uniform vec4 uEdges; | ||
uniform vec4 uCorners; | ||
uniform float uExponent; | ||
uniform bool uEditing; | ||
|
||
float map(float value,float inMin,float inMax,float outMin,float outMax){ | ||
return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin); | ||
} | ||
|
||
float grid(vec2 uv,vec2 size){ | ||
vec2 coord = uv / size; | ||
vec2 grid = abs(fract(coord - 0.5) - 0.5) / (2.0 * fwidth(coord)); | ||
float line = min(grid.x, grid.y); | ||
return 1.0 - min(line, 1.0); | ||
} | ||
|
||
void main(void) | ||
{ | ||
|
||
vec2 coord = gl_TexCoord[0].st; | ||
vec4 texColor = texture2DRect(uTexture, coord); | ||
|
||
vec2 mapCoord = vec2(map(coord.x, uCorners.x, uCorners.z, 0.0, 1.0), map(coord.y, uCorners.y, uCorners.w, 0.0, 1.0)); | ||
|
||
float a = 1.0; | ||
if (uEdges.x > 0.0) a *= clamp(mapCoord.x / uEdges.x, 0.0, 1.0); | ||
if (uEdges.y > 0.0) a *= clamp(mapCoord.y / uEdges.y, 0.0, 1.0); | ||
if (uEdges.z > 0.0) a *= clamp((1.0 - mapCoord.x) / uEdges.z, 0.0, 1.0); | ||
if (uEdges.w > 0.0) a *= clamp((1.0 - mapCoord.y) / uEdges.w, 0.0, 1.0); | ||
|
||
const vec3 one = vec3(1.0); | ||
vec3 blend = (a < 0.5) ? (uLuminance * pow(2.0 * a, uExponent)) : one - (one - uLuminance) * pow(2.0 * (1.0 - a), uExponent); | ||
|
||
texColor.rgb *= pow(blend, one / uGamma); | ||
|
||
if (uEditing) | ||
{ | ||
float f = grid(mapCoord.xy * uExtends.xy, uExtends.zw); | ||
vec4 gridColor = vec4(1.0f); | ||
gl_FragColor = mix(texColor, gridColor, f); | ||
} | ||
else | ||
{ | ||
gl_FragColor = texColor; | ||
} | ||
} |
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,12 @@ | ||
#version 120 | ||
|
||
varying vec3 v; | ||
varying vec3 N; | ||
|
||
void main(){ | ||
v = vec3(gl_ModelViewMatrix * gl_Vertex); | ||
N = normalize(gl_NormalMatrix * gl_Normal); | ||
|
||
gl_TexCoord[0] = gl_MultiTexCoord0; | ||
gl_Position = ftransform(); | ||
} |
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,36 @@ | ||
#version 120 | ||
|
||
varying vec3 v; | ||
varying vec3 N; | ||
|
||
uniform sampler2DRect uTexture; | ||
uniform vec3 uLuminance; | ||
uniform vec3 uGamma; | ||
uniform vec4 uEdges; | ||
uniform vec4 uCorners; | ||
uniform float uExponent; | ||
|
||
float map(float value, float inMin, float inMax, float outMin, float outMax){ | ||
return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin); | ||
} | ||
|
||
void main(void){ | ||
|
||
vec2 coord = gl_TexCoord[0].st; | ||
vec4 texColor = texture2DRect(uTexture, coord); | ||
|
||
vec2 mapCoord = vec2(map(coord.x, uCorners.x, uCorners.z, 0.0, 1.0), map(coord.y, uCorners.y, uCorners.w, 0.0, 1.0)); | ||
|
||
float a = 1.0; | ||
if (uEdges.x > 0.0) a *= clamp(mapCoord.x / uEdges.x, 0.0, 1.0); | ||
if (uEdges.y > 0.0) a *= clamp(mapCoord.y / uEdges.y, 0.0, 1.0); | ||
if (uEdges.z > 0.0) a *= clamp((1.0 - mapCoord.x) / uEdges.z, 0.0, 1.0); | ||
if (uEdges.w > 0.0) a *= clamp((1.0 - mapCoord.y) / uEdges.w, 0.0, 1.0); | ||
|
||
const vec3 one = vec3(1.0); | ||
vec3 blend = (a < 0.5) ? (uLuminance * pow(2.0 * a, uExponent)) : one - (one - uLuminance) * pow(2.0 * (1.0 - a), uExponent); | ||
|
||
texColor.rgb *= pow(blend, one / uGamma); | ||
|
||
gl_FragColor = texColor; | ||
} |
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,12 @@ | ||
#version 120 | ||
|
||
varying vec3 v; | ||
varying vec3 N; | ||
|
||
void main(){ | ||
v = vec3(gl_ModelViewMatrix * gl_Vertex); | ||
N = normalize(gl_NormalMatrix * gl_Normal); | ||
|
||
gl_TexCoord[0] = gl_MultiTexCoord0; | ||
gl_Position = ftransform(); | ||
} |