Jump to content

A really awesome edge glow effect on ShaderToy


zyzz1995
 Share

Recommended Posts

I just found really awesome edge glow effect on ShaderToy, here is the link I don't know if the LE have some similar effect or if it possible to port it to LE. I know nothing about shader, so maybe this is a stupid question. I think i should spend some time on learning it though some of my friends told me that it was very difficult.

 

EDIT: the link is repaired now. Sorry for the broken link before. And below is the shader code.

 

// shader input
uniform vec3     iResolution;         // viewport resolution (in pixels)
uniform float     iGlobalTime;         // shader playback time (in seconds)
uniform float     iTimeDelta;         // render time (in seconds)
uniform int     iFrame;             // shader playback frame
uniform float     iChannelTime[4];     // channel playback time (in seconds)
uniform vec3     iChannelResolution[4]; // channel resolution (in pixels)
uniform vec4     iMouse;             // mouse pixel coords. xy: current (if MLB down), zw: click
uniform samplerXX iChannel0..3;         // input channel. XX = 2D/Cube
uniform vec4     iDate;                 // (year, month, day, time in seconds)
uniform float     iSampleRate;         // sound sample rate (i.e., 44100)
float d;
float lookup(vec2 p, float dx, float dy)
{
vec2 uv = (p.xy + vec2(dx * d, dy * d)) / iResolution.xy;
vec4 c = texture(iChannel0, uv.xy);

// return as luma
return 0.2126*c.r + 0.7152*c.g + 0.0722*c.b;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
d = sin(iGlobalTime * 5.0)*0.5 + 1.5; // kernel offset
vec2 p = fragCoord.xy;

// simple sobel edge detection
float gx = 0.0;
gx += -1.0 * lookup(p, -1.0, -1.0);
gx += -2.0 * lookup(p, -1.0, 0.0);
gx += -1.0 * lookup(p, -1.0, 1.0);
gx += 1.0 * lookup(p, 1.0, -1.0);
gx += 2.0 * lookup(p, 1.0, 0.0);
gx += 1.0 * lookup(p, 1.0, 1.0);

float gy = 0.0;
gy += -1.0 * lookup(p, -1.0, -1.0);
gy += -2.0 * lookup(p, 0.0, -1.0);
gy += -1.0 * lookup(p, 1.0, -1.0);
gy += 1.0 * lookup(p, -1.0, 1.0);
gy += 2.0 * lookup(p, 0.0, 1.0);
gy += 1.0 * lookup(p, 1.0, 1.0);

// hack: use g^2 to conceal noise in the video
float g = gx*gx + gy*gy;
float g2 = g * (sin(iGlobalTime) / 2.0 + 0.5);

vec4 col = texture(iChannel0, p / iResolution.xy);
col += vec4(0.0, g, g2, 1.0);

fragColor = col;
}

 

Found a Leadwerks version of the abvoe shader, but can't get it working

 

#version 400
uniform sampler2D texture1;
uniform bool isbackbuffer;
uniform vec2 buffersize;
uniform float currenttime;
out vec4 fragData0;
#define time currenttime * 0.05
float d = sin(time * 5.0)*0.5 + 1.5; // kernel offset
float lookup(vec2 p, float dx, float dy)
{
   vec2 uv = (p.xy + vec2(dx * d, dy * d)) / buffersize.xy;
   vec4 c = texture(texture1, uv.xy);

 // return as luma
   return 0.2126*c.r + 0.7152*c.g + 0.0722*c.b;
}
void main(void)
{
vec2 icoord = vec2(gl_FragCoord.xy/buffersize);
if (isbackbuffer) icoord.y = 1.0 - icoord.y;
   vec2 p = gl_FragCoord.xy/buffersize;
if (isbackbuffer) p.y = 1.0 - p.y;
p*=buffersize;

 // simple sobel edge detection
   float gx = 0.0;
   gx += -1.0 * lookup(p, -1.0, -1.0);
   gx += -2.0 * lookup(p, -1.0,  0.0);
   gx += -1.0 * lookup(p, -1.0,  1.0);
   gx +=  1.0 * lookup(p,  1.0, -1.0);
   gx +=  2.0 * lookup(p,  1.0,  0.0);
   gx +=  1.0 * lookup(p,  1.0,  1.0);

   float gy = 0.0;
   gy += -1.0 * lookup(p, -1.0, -1.0);
   gy += -2.0 * lookup(p,  0.0, -1.0);
   gy += -1.0 * lookup(p,  1.0, -1.0);
   gy +=  1.0 * lookup(p, -1.0,  1.0);
   gy +=  2.0 * lookup(p,  0.0,  1.0);
   gy +=  1.0 * lookup(p,  1.0,  1.0);

   //hack: use g^2 to conceal noise in the video
   float g = gx*gx + gy*gy;
   float g2 = g * (sin(time) / 2.0 + 0.5);

   vec4 col = texture(texture1, p / buffersize.xy);
   col += vec4(0.0, g, g2, 1.0);

   fragData0 = col;
}

Edited by zyzz1995
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...