Shader question

For developers using the Construct 2 Javascript SDK

Post » Fri Nov 27, 2015 8:57 pm

Here is the topic where i started to understand glsl.. (RojoHound glsl help) and never used samplerBack..
documentation-on-built-in-uniforms_t115900
http://gigatron3k.free.fr/Intro/

https://www.shadertoy.com/user/gigatron

https://twitter.com/realistquantum

Ezekiel 1-4 ; ufo landing explanation ..

CONSTRUCT 2 THE ONLY FAST WAY TO HTML5

Image
B
56
S
20
G
29
Posts: 797
Reputation: 21,930

Post » Fri Dec 04, 2015 11:55 pm

if someone try this little tool ..
consider you have .xml file and empty .fx file ;
Go to shadertoy copy a simple fx and past into this tool ; click to convert; and copy code on your .fx
file; As i said complex and compacted fx are not working yet;

http://gigatron3k.free.fr/html5/C2/FX/stc
http://gigatron3k.free.fr/Intro/

https://www.shadertoy.com/user/gigatron

https://twitter.com/realistquantum

Ezekiel 1-4 ; ufo landing explanation ..

CONSTRUCT 2 THE ONLY FAST WAY TO HTML5

Image
B
56
S
20
G
29
Posts: 797
Reputation: 21,930

Post » Sat Dec 05, 2015 8:28 am

@Gigatron
Gigatron wrote:if someone try this little tool ..
consider you have .xml file and empty .fx file ;
Go to shadertoy copy a simple fx and past into this tool ; click to convert; and copy code on your .fx
file; As i said complex and compacted fx are not working yet;

http://gigatron3k.free.fr/html5/C2/FX/stc


Hell's Teeth!

I'd already tried to convert this shader from Shadertoy, and failed but your converter worked first time :)

Only slight issue is it's upside down, but still - hot damn!

Download if interested
If your vision so exceeds your ability, then look to something closer.
Moderator
B
129
S
29
G
77
Posts: 5,188
Reputation: 54,281

Post » Sat Dec 05, 2015 9:04 am

zenox98 wrote:
Only slight issue is it's upside down, but still - hot damn!

Download if interested

Good work ..

To flip fx vertically ... add line 68 :v=-v; //sorry of course talking about y axis ... so v.y=-v.y; same but better sens and not affect x axis
Last edited by Gigatron on Sat Dec 05, 2015 12:26 pm, edited 2 times in total.
http://gigatron3k.free.fr/Intro/

https://www.shadertoy.com/user/gigatron

https://twitter.com/realistquantum

Ezekiel 1-4 ; ufo landing explanation ..

CONSTRUCT 2 THE ONLY FAST WAY TO HTML5

Image
B
56
S
20
G
29
Posts: 797
Reputation: 21,930

Post » Sat Dec 05, 2015 9:38 am

Thanks, Gigatron. Working perfectly now :)

So many toys to explore :>

Just successfully converted a cute tilable water shader - https://www.shadertoy.com/view/MdlXz8


BTW. Have also managed to add a couple of Parameters. Such fun!
If your vision so exceeds your ability, then look to something closer.
Moderator
B
129
S
29
G
77
Posts: 5,188
Reputation: 54,281

Post » Wed Dec 09, 2015 8:35 pm

@Gigatron
Thanks man :) I got an xBR shader semi-working with that tool. Very nice.

Original shader:
Code: Select all
const float coef        = 2.0;
const vec3  rgbw        = vec3(14.352, 28.176, 5.472);

const   vec2 OGLSize    = vec2( 1024.0, 512.0);
const   vec2 OGLInvSize = vec2( 0.0009765625, 0.001953125);
const   vec2 dx         = vec2( 0.0009765625, 0.0);
const   vec2 dy         = vec2( 0.0, 0.001953125 );
const   vec2 x2         = vec2( 0.001953125 , 0.0);
const   vec2 y2         = vec2( 0.0 , 0.00390625 );
const   vec4 xy         = vec4( 0.0009765625, 0.001953125,-0.0009765625,-0.001953125); 
const   vec4 zw         = vec4( 0.001953125 , 0.001953125,-0.001953125 ,-0.00390625 ); 
const   vec4 wz         = vec4( 0.0009765625, 0.00390625 ,-0.0009765625,-0.00390625 ); 


vec4 df(vec4 A, vec4 B)
{
    return abs(A-B);
}

vec4 weighted_distance(vec4 a, vec4 b, vec4 c, vec4 d, vec4 e, vec4 f, vec4 g, vec4 h)
{
    return (df(a,b) + df(a,c) + df(d,e) + df(d,f) + 4.0*df(g,h));
}


uniform sampler2D OGL2Texture;

void main()
{
    vec4  edr, edr_left, edr_up; bvec4 px; // px = pixel, edr = edge detection rule
    vec4  interp_restriction_lv1, interp_restriction_lv2_left, interp_restriction_lv2_up;
    bvec4 nc; // new_color
    vec4  fx, fx_left, fx_up; // inequations of straight lines.
   
    vec2 fp  = fract(gl_TexCoord[0].xy*OGLSize);
    vec2 TexCoord_0 = gl_TexCoord[0].xy-fp*OGLInvSize;

    vec3 A  = texture2D(OGL2Texture, TexCoord_0 + xy.zw ).xyz;
    vec3 B  = texture2D(OGL2Texture, TexCoord_0     -dy ).xyz;
    vec3 C  = texture2D(OGL2Texture, TexCoord_0 + xy.xw ).xyz;
    vec3 D  = texture2D(OGL2Texture, TexCoord_0 - dx    ).xyz;
    vec3 E  = texture2D(OGL2Texture, TexCoord_0         ).xyz;
    vec3 F  = texture2D(OGL2Texture, TexCoord_0 + dx    ).xyz;
    vec3 G  = texture2D(OGL2Texture, TexCoord_0 + xy.zy ).xyz;
    vec3 H  = texture2D(OGL2Texture, TexCoord_0     +dy ).xyz;
    vec3 I  = texture2D(OGL2Texture, TexCoord_0 + xy.xy ).xyz;
    vec3 A1 = texture2D(OGL2Texture, TexCoord_0 + wz.zw ).xyz;
    vec3 C1 = texture2D(OGL2Texture, TexCoord_0 + wz.xw ).xyz;
    vec3 A0 = texture2D(OGL2Texture, TexCoord_0 + zw.zw ).xyz;
    vec3 G0 = texture2D(OGL2Texture, TexCoord_0 + zw.zy ).xyz;
    vec3 C4 = texture2D(OGL2Texture, TexCoord_0 + zw.xw ).xyz;
    vec3 I4 = texture2D(OGL2Texture, TexCoord_0 + zw.xy ).xyz;
    vec3 G5 = texture2D(OGL2Texture, TexCoord_0 + wz.zy ).xyz;
    vec3 I5 = texture2D(OGL2Texture, TexCoord_0 + wz.xy ).xyz;
    vec3 B1 = texture2D(OGL2Texture, TexCoord_0 - y2    ).xyz;
    vec3 D0 = texture2D(OGL2Texture, TexCoord_0 - x2    ).xyz;
    vec3 H5 = texture2D(OGL2Texture, TexCoord_0 + y2    ).xyz;
    vec3 F4 = texture2D(OGL2Texture, TexCoord_0 + x2    ).xyz;

    vec4 b  = vec4(dot(B ,rgbw), dot(D ,rgbw), dot(H ,rgbw), dot(F ,rgbw));
    vec4 c  = vec4(dot(C ,rgbw), dot(A ,rgbw), dot(G ,rgbw), dot(I ,rgbw));
    vec4 d  = b.yzwx;
    vec4 e  = vec4(dot(E,rgbw));
    vec4 f  = b.wxyz;
    vec4 g  = c.zwxy;
    vec4 h  = b.zwxy;
    vec4 i  = c.wxyz;
    vec4 i4 = vec4(dot(I4,rgbw), dot(C1,rgbw), dot(A0,rgbw), dot(G5,rgbw));
    vec4 i5 = vec4(dot(I5,rgbw), dot(C4,rgbw), dot(A1,rgbw), dot(G0,rgbw));
    vec4 h5 = vec4(dot(H5,rgbw), dot(F4,rgbw), dot(B1,rgbw), dot(D0,rgbw));
    vec4 f4 = h5.yzwx;
   
    vec4 Ao = vec4( 1.0, -1.0, -1.0, 1.0 );
    vec4 Bo = vec4( 1.0,  1.0, -1.0,-1.0 );
    vec4 Co = vec4( 1.5,  0.5, -0.5, 0.5 );
    vec4 Ax = vec4( 1.0, -1.0, -1.0, 1.0 );
    vec4 Bx = vec4( 0.5,  2.0, -0.5,-2.0 );
    vec4 Cx = vec4( 1.0,  1.0, -0.5, 0.0 );
    vec4 Ay = vec4( 1.0, -1.0, -1.0, 1.0 );
    vec4 By = vec4( 2.0,  0.5, -2.0,-0.5 );
    vec4 Cy = vec4( 2.0,  0.0, -1.0, 0.5 );
   
    // These inequations define the line below which interpolation occurs.
    fx      = vec4(greaterThan(Ao*fp.y+Bo*fp.x,Co));
    fx_left = vec4(greaterThan(Ax*fp.y+Bx*fp.x,Cx));
    fx_up   = vec4(greaterThan(Ay*fp.y+By*fp.x,Cy));

    interp_restriction_lv1      = vec4(notEqual(e,f))*vec4(notEqual(e,h));
    interp_restriction_lv2_left = vec4(notEqual(e,g))*vec4(notEqual(d,g));
    interp_restriction_lv2_up   = vec4(notEqual(e,c))*vec4(notEqual(b,c));

    edr      = vec4(lessThan(weighted_distance( e, c, g, i, h5, f4, h, f), weighted_distance( h, d, i5, f, i4, b, e, i)))*interp_restriction_lv1;
    edr_left = vec4(lessThanEqual(coef*df(f,g),df(h,c)))*interp_restriction_lv2_left;
    edr_up   = vec4(greaterThanEqual(df(f,g),coef*df(h,c)))*interp_restriction_lv2_up;
   
    nc = bvec4 (edr*(max(max(fx, edr_left*fx_left), edr_up*fx_up)));

    px = lessThanEqual(df(e,f),df(e,h));

    vec3 res = nc.x ? px.x ? F : H : nc.y ? px.y ? B : F : nc.z ? px.z ? D : B : nc.w ? px.w ? H : D : E;   
    gl_FragColor.xyz = res;   
}


Conversion (tinkered around to try and make it work properly):
fx:
Code: Select all
#ifdef GL_ES
precision mediump float;
#endif

uniform highp float WindowsWidth;
uniform highp float WindowsHeight;


uniform mediump sampler2D samplerFront;
varying mediump vec2 vTex;
uniform mediump float seconds;
uniform mediump float date;
uniform mediump float pixelWidth;
uniform mediump float pixelHeight;
vec2 iResolution = vec2( 1./pixelWidth, 1./pixelHeight);


const float coef        = 2.0;
const vec3  rgbw        = vec3(14.352, 28.176, 5.472);

//const vec2 dx         = vec2( 0.0009765625, 0.0);
//const vec2 dy         = vec2( 0.0, 0.001953125 );
//const vec2 x2         = vec2( 0.001953125 , 0.0);
//const vec2 y2         = vec2( 0.0 , 0.00390625 );
//const vec4 xy         = vec4( 0.0009765625, 0.001953125,-0.0009765625,-0.001953125); 
//const vec4 zw         = vec4( 0.001953125 , 0.001953125,-0.001953125 ,-0.00390625 ); 
//const vec4 wz         = vec4( 0.0009765625, 0.00390625 ,-0.0009765625,-0.00390625 ); 



vec4 df(vec4 A, vec4 B)
{
    return abs(A-B);
}

vec4 weighted_distance(vec4 a, vec4 b, vec4 c, vec4 d, vec4 e, vec4 f, vec4 g, vec4 h)
{
    return (df(a,b) + df(a,c) + df(d,e) + df(d,f) + 4.0*df(g,h));
}



void main()
{
//   float x = 0.5 * (1.0 / WindowsWidth);
//   float y = 0.5 * (1.0 / WindowsHeight);

   vec2 dx         = vec2( 0.0009765625, 0.0);//vec2(x, 0.0);//
   vec2 dy         = vec2( 0.0, 0.001953125 );//vec2(0.0, y);//
   vec2 x2         = vec2( 0.001953125 , 0.0);//vec2(y, 0);//
   vec2 y2         = vec2(0.0, 0.00390625);//vec2( 0.0 , y*2.0 );//
   vec4 xy         = vec4( 0.0009765625, 0.001953125,-0.0009765625,-0.001953125);//vec4( x, y,-x,-y);// 
   vec4 zw         = vec4( 0.001953125 , 0.001953125,-0.001953125 ,-0.00390625 );//vec4( y , y,-y ,-(y*2.0) );// 
   vec4 wz         = vec4( 0.0009765625, 0.00390625 ,-0.0009765625,-0.00390625 );  //vec4( x, y*2.0 ,-x,-(y*2.0) );//

    vec4  edr, edr_left, edr_up; bvec4 px; // px = pixel, edr = edge detection rule
    vec4  interp_restriction_lv1, interp_restriction_lv2_left, interp_restriction_lv2_up;
    bvec4 nc; // new_color
    vec4  fx, fx_left, fx_up; // inequations of straight lines.
   
   lowp float alpha = texture2D(samplerFront, vTex).a;

    vec2 fp  = fract(vTex.xy*vec2(WindowsWidth,WindowsHeight));
    vec2 TexCoord_0 = vTex.xy-fp*vec2(0.0009765625, 0.001953125);//vec2(x, y);

    vec3 A  = texture2D(samplerFront, TexCoord_0 + xy.zw ).xyz;
    vec3 B  = texture2D(samplerFront, TexCoord_0     -dy ).xyz;
    vec3 C  = texture2D(samplerFront, TexCoord_0 + xy.xw ).xyz;
    vec3 D  = texture2D(samplerFront, TexCoord_0 - dx    ).xyz;
    vec3 E  = texture2D(samplerFront, TexCoord_0         ).xyz;
    vec3 F  = texture2D(samplerFront, TexCoord_0 + dx    ).xyz;
    vec3 G  = texture2D(samplerFront, TexCoord_0 + xy.zy ).xyz;
    vec3 H  = texture2D(samplerFront, TexCoord_0     +dy ).xyz;
    vec3 I  = texture2D(samplerFront, TexCoord_0 + xy.xy ).xyz;
    vec3 A1 = texture2D(samplerFront, TexCoord_0 + wz.zw ).xyz;
    vec3 C1 = texture2D(samplerFront, TexCoord_0 + wz.xw ).xyz;
    vec3 A0 = texture2D(samplerFront, TexCoord_0 + zw.zw ).xyz;
    vec3 G0 = texture2D(samplerFront, TexCoord_0 + zw.zy ).xyz;
    vec3 C4 = texture2D(samplerFront, TexCoord_0 + zw.xw ).xyz;
    vec3 I4 = texture2D(samplerFront, TexCoord_0 + zw.xy ).xyz;
    vec3 G5 = texture2D(samplerFront, TexCoord_0 + wz.zy ).xyz;
    vec3 I5 = texture2D(samplerFront, TexCoord_0 + wz.xy ).xyz;
    vec3 B1 = texture2D(samplerFront, TexCoord_0 - y2    ).xyz;
    vec3 D0 = texture2D(samplerFront, TexCoord_0 - x2    ).xyz;
    vec3 H5 = texture2D(samplerFront, TexCoord_0 + y2    ).xyz;
    vec3 F4 = texture2D(samplerFront, TexCoord_0 + x2    ).xyz;

    vec4 b  = vec4(dot(B ,rgbw), dot(D ,rgbw), dot(H ,rgbw), dot(F ,rgbw));
    vec4 c  = vec4(dot(C ,rgbw), dot(A ,rgbw), dot(G ,rgbw), dot(I ,rgbw));
    vec4 d  = b.yzwx;
    vec4 e  = vec4(dot(E,rgbw));
    vec4 f  = b.wxyz;
    vec4 g  = c.zwxy;
    vec4 h  = b.zwxy;
    vec4 i  = c.wxyz;
    vec4 i4 = vec4(dot(I4,rgbw), dot(C1,rgbw), dot(A0,rgbw), dot(G5,rgbw));
    vec4 i5 = vec4(dot(I5,rgbw), dot(C4,rgbw), dot(A1,rgbw), dot(G0,rgbw));
    vec4 h5 = vec4(dot(H5,rgbw), dot(F4,rgbw), dot(B1,rgbw), dot(D0,rgbw));
    vec4 f4 = h5.yzwx;
   
    vec4 Ao = vec4( 1.0, -1.0, -1.0, 1.0 );
    vec4 Bo = vec4( 1.0,  1.0, -1.0,-1.0 );
    vec4 Co = vec4( 1.5,  0.5, -0.5, 0.5 );
    vec4 Ax = vec4( 1.0, -1.0, -1.0, 1.0 );
    vec4 Bx = vec4( 0.5,  2.0, -0.5,-2.0 );
    vec4 Cx = vec4( 1.0,  1.0, -0.5, 0.0 );
    vec4 Ay = vec4( 1.0, -1.0, -1.0, 1.0 );
    vec4 By = vec4( 2.0,  0.5, -2.0,-0.5 );
    vec4 Cy = vec4( 2.0,  0.0, -1.0, 0.5 );
    vec4 Ci = vec4(0.25, 0.25, 0.25, 0.25);
   
    // These inequations define the line below which interpolation occurs.
    fx      = vec4(greaterThan(Ao*fp.y+Bo*fp.x,Co));
    fx_left = vec4(greaterThan(Ax*fp.y+Bx*fp.x,Cx));
    fx_up   = vec4(greaterThan(Ay*fp.y+By*fp.x,Cy));

    interp_restriction_lv1      = vec4(notEqual(e,f))*vec4(notEqual(e,h));
    interp_restriction_lv2_left = vec4(notEqual(e,g))*vec4(notEqual(d,g));
    interp_restriction_lv2_up   = vec4(notEqual(e,c))*vec4(notEqual(b,c));

    edr      = vec4(lessThan(weighted_distance( e, c, g, i, h5, f4, h, f), weighted_distance( h, d, i5, f, i4, b, e, i)))*interp_restriction_lv1;
    edr_left = vec4(lessThanEqual(coef*df(f,g),df(h,c)))*interp_restriction_lv2_left;
    edr_up   = vec4(greaterThanEqual(df(f,g),coef*df(h,c)))*interp_restriction_lv2_up;
   
    nc = bvec4 (edr*(max(max(fx, edr_left*fx_left), edr_up*fx_up)));

    px = lessThanEqual(df(e,f),df(e,h));

    vec3 res = nc.x ? px.x ? F : H : nc.y ? px.y ? B : F : nc.z ? px.z ? D : B : nc.w ? px.w ? H : D : E;   
    gl_FragColor.xyz = res;   
   gl_FragColor.a = alpha;
}

xml:
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<c2effect>
   <!-- About -->
   <id>XBR</id>         <!-- Never change the ID.  Change the name instead -->
   <name>xBR</name>
   <category>Advanced Effect Layout</category>
   <description>Use this effect on individual sprites or the whole layout. Based on code by Hyllian and Anata</description>
   <author>Hyllian</author>
   
   <!-- Settings -->
   
   <!-- Extend the bounding box for effect processing by a number of pixels to show the edges
       of effects which go beyond the object edges, e.g. blur and warp. -->
   <extend-box-horizontal>10</extend-box-horizontal>
   <extend-box-vertical>10</extend-box-vertical>
   
   <!-- Set to true if the background is sampled (samplerBack is referenced at all in the shader) -->
   <blends-background>false</blends-background>
   
   <!-- Set to true if the background is not sampled at 1:1 with the foreground (e.g. the
       background texture co-ordinates are modified in some way by the shader, as done
       by Glass and Lens) -->
   <cross-sampling>false</cross-sampling>
   
   <!-- Set to true if the effect changes over time, e.g. Noise or Warp effects. -->
   <animated>false</animated>
   
   <!-- Parameters -->
   <parameters>
      <param>
         <name>Width</name>
         <description>Destination X</description>
         <type>float</type>
         <initial>0</initial>
         <uniform>WindowsWidth</uniform>
      </param>
      <param>
         <name>Height</name>
         <description>Destination Y</description>
         <type>float</type>
         <initial>0</initial>
         <uniform>WindowsHeight</uniform>
      </param>
   </parameters>
</c2effect>


Use it on a layout and input the game target resolution in the Width and Height fields. So far it'll smooth along one angle but not the other. And no luck yet getting it to work properly on an object basis.

EDIT:
Posted the wrong shader, fixed now :oops:
B
34
S
15
G
6
Posts: 509
Reputation: 7,326

Post » Thu Dec 10, 2015 6:35 am

Would you like to try this one ;

Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<c2effect>
   <!-- About -->
   <id>XBR</id>         <!-- Never change the ID.  Change the name instead -->
   <name>xBR</name>
   <category>Advanced Effect Layout</category>
   <description>Use this effect on individual sprites or the whole layout. Based on code by Hyllian and Anata</description>
   <author>Hyllian</author>
   
   <!-- Settings -->
   
   <!-- Extend the bounding box for effect processing by a number of pixels to show the edges
       of effects which go beyond the object edges, e.g. blur and warp. -->
   <extend-box-horizontal>10</extend-box-horizontal>
   <extend-box-vertical>10</extend-box-vertical>
   
   <!-- Set to true if the background is sampled (samplerBack is referenced at all in the shader) -->
   <blends-background>false</blends-background>
   
   <!-- Set to true if the background is not sampled at 1:1 with the foreground (e.g. the
       background texture co-ordinates are modified in some way by the shader, as done
       by Glass and Lens) -->
   <cross-sampling>false</cross-sampling>
   
   <!-- Set to true if the effect changes over time, e.g. Noise or Warp effects. -->
   <animated>false</animated>
   
   <!-- Parameters -->
   <parameters>
      <param>
         <name>Width</name>
         <description>Destination X</description>
         <type>float</type>
         <initial>0</initial>
         <uniform>WindowsWidth</uniform>
      </param>
      <param>
         <name>Height</name>
         <description>Destination Y</description>
         <type>float</type>
         <initial>0</initial>
         <uniform>WindowsHeight</uniform>
      </param>
     <param>
         <name>X Coef</name>
         <description>X Coef Multiplier</description>
         <type>percent</type>
         <initial>0.2</initial>
         <uniform>x_coef</uniform>
      </param>
       <param>
         <name>Y Coef</name>
         <description>Y Coef Multiplier</description>
         <type>percent</type>
         <initial>0.2</initial>
         <uniform>y_coef</uniform>
      </param>
    
    
   </parameters>
</c2effect>


Code: Select all
#ifdef GL_ES
precision mediump float;
#endif




uniform mediump sampler2D samplerFront;
varying mediump vec2 vTex;
uniform mediump float seconds;
uniform mediump float date;
uniform mediump float pixelWidth;
uniform mediump float pixelHeight;
vec2 iResolution = vec2( 1./pixelWidth, 1./pixelHeight);

uniform  float WindowsWidth;
uniform  float WindowsHeight;
uniform  float x_coef;
uniform  float y_coef;

const float  coef=2.0;
const vec3  rgbw        = vec3(14.352, 28.176, 5.472);

// const vec2 dx         = vec2( 0.0009765625, 0.0);
// const vec2 dy         = vec2( 0.0, 0.001953125 );
// const vec2 x2         = vec2( 0.001953125 , 0.0);
// const vec2 y2         = vec2( 0.0 , 0.00390625 );
// const vec4 xy         = vec4( 0.0009765625, 0.001953125,-0.0009765625,-0.001953125);
// const vec4 zw         = vec4( 0.001953125 , 0.001953125,-0.001953125 ,-0.00390625 );
// const vec4 wz         = vec4( 0.0009765625, 0.00390625 ,-0.0009765625,-0.00390625 );



vec4 df(vec4 A, vec4 B)
{
    return abs(A-B);
}

vec4 weighted_distance(vec4 a, vec4 b, vec4 c, vec4 d, vec4 e, vec4 f, vec4 g, vec4 h)
{
    return (df(a,b) + df(a,c) + df(d,e) + df(d,f) + 4.0*df(g,h));
}



void main()
{
//   float x = 0.5 * (1.0 / WindowsWidth);
//   float y = 0.5 * (1.0 / WindowsHeight);

   vec2 dx         = vec2( 0.0009765625, 0.0);//vec2(x, 0.0);//
   vec2 dy         = vec2( 0.0, 0.001953125 );//vec2(0.0, y);//
   vec2 x2         = vec2( 0.001953125 , 0.0);//vec2(y, 0);//
   vec2 y2         = vec2(0.0, 0.00390625);//vec2( 0.0 , y*2.0 );//
   vec4 xy         = vec4( 0.0009765625, 0.001953125,-0.0009765625,-0.001953125);//vec4( x, y,-x,-y);//
   vec4 zw         = vec4( 0.001953125 , 0.001953125,-0.001953125 ,-0.00390625 );//vec4( y , y,-y ,-(y*2.0) );//
   vec4 wz         = vec4( 0.0009765625, 0.00390625 ,-0.0009765625,-0.00390625 );  //vec4( x, y*2.0 ,-x,-(y*2.0) );//

    vec4  edr, edr_left, edr_up; bvec4 px; // px = pixel, edr = edge detection rule
    vec4  interp_restriction_lv1, interp_restriction_lv2_left, interp_restriction_lv2_up;
    bvec4 nc; // new_color
    vec4  fx, fx_left, fx_up; // inequations of straight lines.
   
    float alpha = texture2D(samplerFront, vTex).a;

    vec2 fp  = fract(vTex.xy*vec2(WindowsWidth,WindowsHeight));
    vec2 TexCoord_0 = vTex.xy-fp*vec2(0.0009765625*x_coef, 0.001953125*y_coef);//vec2(x, y);

    vec3 A  = texture2D(samplerFront, TexCoord_0 + xy.zw ).xyz;
    vec3 B  = texture2D(samplerFront, TexCoord_0     -dy ).xyz;
    vec3 C  = texture2D(samplerFront, TexCoord_0 + xy.xw ).xyz;
    vec3 D  = texture2D(samplerFront, TexCoord_0 - dx    ).xyz;
    vec3 E  = texture2D(samplerFront, TexCoord_0         ).xyz;
    vec3 F  = texture2D(samplerFront, TexCoord_0 + dx    ).xyz;
    vec3 G  = texture2D(samplerFront, TexCoord_0 + xy.zy ).xyz;
    vec3 H  = texture2D(samplerFront, TexCoord_0     +dy ).xyz;
    vec3 I  = texture2D(samplerFront, TexCoord_0 + xy.xy ).xyz;
    vec3 A1 = texture2D(samplerFront, TexCoord_0 + wz.zw ).xyz;
    vec3 C1 = texture2D(samplerFront, TexCoord_0 + wz.xw ).xyz;
    vec3 A0 = texture2D(samplerFront, TexCoord_0 + zw.zw ).xyz;
    vec3 G0 = texture2D(samplerFront, TexCoord_0 + zw.zy ).xyz;
    vec3 C4 = texture2D(samplerFront, TexCoord_0 + zw.xw ).xyz;
    vec3 I4 = texture2D(samplerFront, TexCoord_0 + zw.xy ).xyz;
    vec3 G5 = texture2D(samplerFront, TexCoord_0 + wz.zy ).xyz;
    vec3 I5 = texture2D(samplerFront, TexCoord_0 + wz.xy ).xyz;
    vec3 B1 = texture2D(samplerFront, TexCoord_0 - y2    ).xyz;
    vec3 D0 = texture2D(samplerFront, TexCoord_0 - x2    ).xyz;
    vec3 H5 = texture2D(samplerFront, TexCoord_0 + y2    ).xyz;
    vec3 F4 = texture2D(samplerFront, TexCoord_0 + x2    ).xyz;

    vec4 b  = vec4(dot(B ,rgbw), dot(D ,rgbw), dot(H ,rgbw), dot(F ,rgbw));
    vec4 c  = vec4(dot(C ,rgbw), dot(A ,rgbw), dot(G ,rgbw), dot(I ,rgbw));
    vec4 d  = b.yzwx;
    vec4 e  = vec4(dot(E,rgbw));
    vec4 f  = b.wxyz;
    vec4 g  = c.zwxy;
    vec4 h  = b.zwxy;
    vec4 i  = c.wxyz;
    vec4 i4 = vec4(dot(I4,rgbw), dot(C1,rgbw), dot(A0,rgbw), dot(G5,rgbw));
    vec4 i5 = vec4(dot(I5,rgbw), dot(C4,rgbw), dot(A1,rgbw), dot(G0,rgbw));
    vec4 h5 = vec4(dot(H5,rgbw), dot(F4,rgbw), dot(B1,rgbw), dot(D0,rgbw));
    vec4 f4 = h5.yzwx;
   
    vec4 Ao = vec4( 1.0, -1.0, -1.0, 1.0 );
    vec4 Bo = vec4( 1.0,  1.0, -1.0,-1.0 );
    vec4 Co = vec4( 1.5,  0.5, -0.5, 0.5 );
    vec4 Ax = vec4( 1.0, -1.0, -1.0, 1.0 );
    vec4 Bx = vec4( 0.5,  2.0, -0.5,-2.0 );
    vec4 Cx = vec4( 1.0,  1.0, -0.5, 0.0 );
    vec4 Ay = vec4( 1.0, -1.0, -1.0, 1.0 );
    vec4 By = vec4( 2.0,  0.5, -2.0,-0.5 );
    vec4 Cy = vec4( 2.0,  0.0, -1.0, 0.5 );
    vec4 Ci = vec4(0.25, 0.25, 0.25, 0.25);
   
    // These inequations define the line below which interpolation occurs.
    fx      = vec4(greaterThan(Ao*fp.y+Bo*fp.x,Co));
    fx_left = vec4(greaterThan(Ax*fp.y+Bx*fp.x,Cx));
    fx_up   = vec4(greaterThan(Ay*fp.y+By*fp.x,Cy));

    interp_restriction_lv1      = vec4(notEqual(e,f))*vec4(notEqual(e,h));
    interp_restriction_lv2_left = vec4(notEqual(e,g))*vec4(notEqual(d,g));
    interp_restriction_lv2_up   = vec4(notEqual(e,c))*vec4(notEqual(b,c));

    edr      = vec4(lessThan(weighted_distance( e, c, g, i, h5, f4, h, f), weighted_distance( h, d, i5, f, i4, b, e, i)))*interp_restriction_lv1;
    edr_left = vec4(lessThanEqual(coef*df(f,g),df(h,c)))*interp_restriction_lv2_left;
    edr_up   = vec4(greaterThanEqual(df(f,g),coef*df(h,c)))*interp_restriction_lv2_up;
   
    nc = bvec4 (edr*(max(max(fx, edr_left*fx_left), edr_up*fx_up)));

    px = lessThanEqual(df(e,f),df(e,h));

    vec3 res = nc.x ? px.x ? F : H : nc.y ? px.y ? B : F : nc.z ? px.z ? D : B : nc.w ? px.w ? H : D : E;   
    gl_FragColor.xyz = res;   
   gl_FragColor.a = alpha;
}


Dont forget to follow variables in source try to understand what they do ....
http://gigatron3k.free.fr/Intro/

https://www.shadertoy.com/user/gigatron

https://twitter.com/realistquantum

Ezekiel 1-4 ; ufo landing explanation ..

CONSTRUCT 2 THE ONLY FAST WAY TO HTML5

Image
B
56
S
20
G
29
Posts: 797
Reputation: 21,930

Post » Thu Dec 10, 2015 12:41 pm

@Gigatron

Can't seem to see anything with your last example.

Tried applying to both a sprite and a Layout, with numerous combinations of values for coef and width/height, but still nothing.

Now I feel dumb again :(
If your vision so exceeds your ability, then look to something closer.
Moderator
B
129
S
29
G
77
Posts: 5,188
Reputation: 54,281

Post » Thu Dec 10, 2015 1:38 pm

Wow thanks! It works very nice here :)

So I guess the new x_coef and y_coef are necessary for the shader to know what pixel rate to scale by?

Now I just need to figure out how to get it to blend with the alpha channel as well, so far I just grabbed the original alpha and applied that :P I should see if I can update it to the newest xBR version too, this one's a bit old I think.

@zenox98:
You have 'high quality' and 'point sampling' turned on? It should work if you apply the effect to either a layout, layer or object and input the original game res width and height. I just went with the default x_coef/y_coef. Also had to add a 'precision mediump float;' at the top to get it to compile but since you didn't get an error I guess you already took care of that.
B
34
S
15
G
6
Posts: 509
Reputation: 7,326

Post » Thu Dec 10, 2015 1:54 pm

@ErekT

Settings OK. No errors - just nothing.

It could be my GTX 970.
Gigatron had to amend some of his shaders before they would work on it previously, so it may be the same situation here.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
129
S
29
G
77
Posts: 5,188
Reputation: 54,281

PreviousNext

Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 1 guest