First commit
This commit is contained in:
118
shaders/edgeDetection.shader
Executable file
118
shaders/edgeDetection.shader
Executable file
@@ -0,0 +1,118 @@
|
||||
#version 300 es
|
||||
|
||||
in vec3 position;
|
||||
in vec2 uv;
|
||||
|
||||
uniform mat4 viewProjection;
|
||||
uniform vec2 res;
|
||||
|
||||
out vec2 textureCoord;
|
||||
out vec4 vOffset[ 3 ];
|
||||
|
||||
void SMAAEdgeDetectionVS( vec2 texcoord ) {
|
||||
vOffset[ 0 ] = texcoord.xyxy + res.xyxy * vec4( -1.0, 0.0, 0.0, 1.0 ); // WebGL port note: Changed sign in W component
|
||||
vOffset[ 1 ] = texcoord.xyxy + res.xyxy * vec4( 1.0, 0.0, 0.0, -1.0 ); // WebGL port note: Changed sign in W component
|
||||
vOffset[ 2 ] = texcoord.xyxy + res.xyxy * vec4( -2.0, 0.0, 0.0, 2.0 ); // WebGL port note: Changed sign in W component
|
||||
}
|
||||
|
||||
|
||||
|
||||
void main(void) {
|
||||
textureCoord = uv;
|
||||
SMAAEdgeDetectionVS( textureCoord );
|
||||
|
||||
gl_Position = viewProjection * vec4(position, 1.0);
|
||||
}
|
||||
|
||||
// #keplerEngine - Split
|
||||
|
||||
#version 300 es
|
||||
|
||||
precision highp float;
|
||||
|
||||
#define SMAA_THRESHOLD 0.2
|
||||
|
||||
|
||||
uniform vec2 res;
|
||||
|
||||
|
||||
uniform sampler2D material_sampler;
|
||||
uniform sampler2D sceneSampler;
|
||||
|
||||
in vec2 textureCoord;
|
||||
in vec4 vOffset[ 3 ];
|
||||
|
||||
|
||||
out vec4 fragmentColor;
|
||||
|
||||
|
||||
vec4 SMAAColorEdgeDetectionPS( vec2 texcoord, vec4 offset[3], sampler2D colorTex ) {
|
||||
vec2 threshold = vec2( SMAA_THRESHOLD, SMAA_THRESHOLD );
|
||||
|
||||
// Calculate color deltas:
|
||||
vec4 delta;
|
||||
vec3 C = texture( colorTex, texcoord ).rgb;
|
||||
|
||||
vec3 Cleft = texture( colorTex, offset[0].xy ).rgb;
|
||||
vec3 t = abs( C - Cleft );
|
||||
delta.x = max( max( t.r, t.g ), t.b );
|
||||
|
||||
vec3 Ctop = texture( colorTex, offset[0].zw ).rgb;
|
||||
t = abs( C - Ctop );
|
||||
delta.y = max( max( t.r, t.g ), t.b );
|
||||
|
||||
// We do the usual threshold:
|
||||
vec2 edges = step( threshold, delta.xy );
|
||||
|
||||
// Then discard if there is no edge:
|
||||
if ( dot( edges, vec2( 1.0, 1.0 ) ) == 0.0 )
|
||||
discard;
|
||||
|
||||
// Calculate right and bottom deltas:
|
||||
vec3 Cright = texture( colorTex, offset[1].xy ).rgb;
|
||||
t = abs( C - Cright );
|
||||
delta.z = max( max( t.r, t.g ), t.b );
|
||||
|
||||
vec3 Cbottom = texture( colorTex, offset[1].zw ).rgb;
|
||||
t = abs( C - Cbottom );
|
||||
delta.w = max( max( t.r, t.g ), t.b );
|
||||
|
||||
// Calculate the maximum delta in the direct neighborhood:
|
||||
float maxDelta = max( max( max( delta.x, delta.y ), delta.z ), delta.w );
|
||||
|
||||
// Calculate left-left and top-top deltas:
|
||||
vec3 Cleftleft = texture( colorTex, offset[2].xy ).rgb;
|
||||
t = abs( C - Cleftleft );
|
||||
delta.z = max( max( t.r, t.g ), t.b );
|
||||
|
||||
vec3 Ctoptop = texture( colorTex, offset[2].zw ).rgb;
|
||||
t = abs( C - Ctoptop );
|
||||
delta.w = max( max( t.r, t.g ), t.b );
|
||||
|
||||
// Calculate the final maximum delta:
|
||||
maxDelta = max( max( maxDelta, delta.z ), delta.w );
|
||||
|
||||
// Local contrast adaptation in action:
|
||||
edges.xy *= step( 0.5 * maxDelta, delta.xy );
|
||||
|
||||
return vec4( edges, 0.0, 0.0 );
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
//vec4 sceneColor = vec4( texture( sceneSampler, textureCoord).xyz, 1.0 );
|
||||
|
||||
vec4 abc = SMAAColorEdgeDetectionPS( textureCoord, vOffset, material_sampler );
|
||||
|
||||
|
||||
|
||||
if(length(abc) > .6) {
|
||||
fragmentColor = vec4(221.0/256.0, 161.0/256.0, 87.0/256.0, 1.0);
|
||||
} else {
|
||||
fragmentColor = vec4( 0.0 );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user