Modifying blinky.cg?

I just found out about this shader and I am seriously loving it! I don’t know who I should thank for making it but kudos to that person if you’re reading this.

I would love to make some changes to the shader for personal use. The problem is – looking at the code – it doesn’t say much to me. Could someone point out some of the key values that I should be looking at? I would like to try reduce the darkness/contrast for example, it can be a bit taxing for the eyes like this. Here’s the code:


struct input
{
   float2 video_size;
   float2 texture_size;
   float2 output_size;
   float  frame_count;
   float  frame_direction;
   float frame_rotation;
};

struct vert_out
{
   float2 tex_direct;
   float2 tex_0;
   float2 tex_60;
   float2 tex_120;
   float2 tex_180;
   float2 tex_240;
   float2 tex_300;
};

void main_vertex
(
   float4 position : POSITION,
   out float4 oPosition : POSITION,
   uniform float4x4 modelViewProj,
   float2 tex : TEXCOORD0,
   uniform input IN,
   out vert_out verts: TEXCOORD1
)
{
   oPosition = mul(modelViewProj, position);
   float2 one = 1.0 / IN.texture_size;
   float angle = IN.frame_count = IN.frame_count / 20.0;
   float scale = 1.0 + 0.2 * sin(0.5 * angle);
   float2x2 rotate = scale * float2x2(
         cos(angle),    sin(angle),
         -sin(angle),   cos(angle)
   );

   verts.tex_direct = tex;
   verts.tex_0 = tex + one * mul(rotate, float2(1.0, 0.0));
   verts.tex_60 = tex + one * mul(rotate, float2(0.5, 0.7));
   verts.tex_120 = tex + one * mul(rotate, float2(-0.5, 0.7));
   verts.tex_180 = tex + one * mul(rotate, float2(-1.0, 0.0));
   verts.tex_240 = tex + one * mul(rotate, float2(-0.5, -0.7));
   verts.tex_300 = tex + one * mul(rotate, float2(0.5, -0.7));
}

float4 main_fragment (in vert_out verts : TEXCOORD1, uniform sampler2D s0 : TEXUNIT0) : COLOR
{
   float4 tex_mid = tex2D(s0, verts.tex_direct);
   float4 tex0 = tex2D(s0, verts.tex_0);
   float4 tex60 = tex2D(s0, verts.tex_60);
   float4 tex120 = tex2D(s0, verts.tex_120);
   float4 tex180 = tex2D(s0, verts.tex_180);
   float4 tex240 = tex2D(s0, verts.tex_240);
   float4 tex300 = tex2D(s0, verts.tex_300);

   float4 minimum = min(min(min(tex0, tex60), min(tex120, tex180)), min(tex240, tex300));
   float4 maximum = max(max(max(tex0, tex60), max(tex120, tex180)), max(tex240, tex300));
   float4 diff = 1.0 - exp(-(maximum - minimum));
   return lerp(tex_mid, diff, 0.9);
}

I think mudlord is the original author, maybe…? Anyway, you can try this version, which has a ‘contrast’ parameter that you can adjust:

#pragma parameter contrast "Blinky - Contrast" 1.0 0.0 1.0 0.05
#ifdef PARAMETER_UNIFORM
uniform float contrast;
#else
#define contrast 1.0
#endif

/* COMPATIBILITY 
   - HLSL compilers
   - Cg   compilers
*/

struct input
{
   float2 video_size;
   float2 texture_size;
   float2 output_size;
   float  frame_count;
   float  frame_direction;
   float frame_rotation;
};

struct vert_out
{
   float2 tex_direct;
   float2 tex_0;
   float2 tex_60;
   float2 tex_120;
   float2 tex_180;
   float2 tex_240;
   float2 tex_300;
};

void main_vertex
(
   float4 position : POSITION,
   out float4 oPosition : POSITION,
   uniform float4x4 modelViewProj,
   float2 tex : TEXCOORD0,
   uniform input IN,
   out vert_out verts: TEXCOORD1
)
{
   oPosition = mul(modelViewProj, position);
   float2 one = 1.0 / IN.texture_size;
   float angle = IN.frame_count = IN.frame_count / 20.0;
   float scale = 1.0 + 0.2 * sin(0.5 * angle);
   float2x2 rotate = scale * float2x2(
         cos(angle),    sin(angle),
         -sin(angle),   cos(angle)
   );

   verts.tex_direct = tex;
   verts.tex_0 = tex + one * mul(rotate, float2(1.0, 0.0));
   verts.tex_60 = tex + one * mul(rotate, float2(0.5, 0.7));
   verts.tex_120 = tex + one * mul(rotate, float2(-0.5, 0.7));
   verts.tex_180 = tex + one * mul(rotate, float2(-1.0, 0.0));
   verts.tex_240 = tex + one * mul(rotate, float2(-0.5, -0.7));
   verts.tex_300 = tex + one * mul(rotate, float2(0.5, -0.7));
}

float4 main_fragment (in vert_out verts : TEXCOORD1, uniform sampler2D s0 : TEXUNIT0) : COLOR
{
   float4 tex_mid = tex2D(s0, verts.tex_direct);
   float4 tex0 = tex2D(s0, verts.tex_0);
   float4 tex60 = tex2D(s0, verts.tex_60);
   float4 tex120 = tex2D(s0, verts.tex_120);
   float4 tex180 = tex2D(s0, verts.tex_180);
   float4 tex240 = tex2D(s0, verts.tex_240);
   float4 tex300 = tex2D(s0, verts.tex_300);

   float4 minimum = min(min(min(tex0, tex60), min(tex120, tex180)), min(tex240, tex300));
   float4 maximum = max(max(max(tex0, tex60), max(tex120, tex180)), max(tex240, tex300));
   float4 diff = 1.0 - exp(-(maximum - minimum * contrast));
   return lerp(tex_mid, diff, 0.9);
}

Nice, thanks! Testing now.

I like to set the contrast to 0.75 for normal use and 1.0 for a psychedelic experience. 75% is way less straining yet still makes everything look like it was made for high resolution. Any less contrast and the effect starts to diminish. Is there any other value you think I might wanna fiddle with?

Color adjustment comes to mind to compensate for the contrast.


Pretty much anywhere you see a number, you can multiply it by something to change the effect. I usually start with 0.5 or 2.0 to halve/double the effect.

Is it possible to isolate just the portion that divides the edges like that?

Also, where does mudlord hang out?

in the ‘scale’ line in the vertex, you can add a multiplier there to make the different lines more offset.

He hasn’t been on the forum in a long time, I don’t think, but he’s on IRC pretty frequently.

Can you also add brightness adjustment? Or anything to help the remaining darkness, I don’t understand which value could be causing this.

Dunno about that, but you could just put the image-adjustment shader after it and use it to adjust brightness, etc

Actually I was using a version of SNES9x with 6xBRZ filter support from here http://www.snes9x.com/phpbb3/viewtopic.php?f=8&t=15191&start=40 so I can only set one shader at a time. But I had to try retroarch immediately because multishader support sounds awesome. But for the life of me I can not understand where to set up the shaders for use. I downloaded them using retroarch but there doesn’t seem to be a config screen for them.

Here is an image illustrating why I am looking for a solution to the darkness:


On the left is blinky.cg with my modified values (can I post the code btw?) and on the right is what I think it should look like ideally (corrected with photo editor). I am hoping for people to see the value in this.

Sure, you can post code, just put it in bbcode

 brackets.

Here it is. I’m still looking for ways to make it brighter.

/* COMPATIBILITY 
   - HLSL compilers
   - Cg compilers
*/

struct input
{
   float2 video_size;
   float2 texture_size;
   float2 output_size;
   float frame_count;
   float frame_direction;
   float frame_rotation;
};

struct vert_out
{
   float2 tex_direct;
   float2 tex_0;
   float2 tex_60;
   float2 tex_120;
   float2 tex_180;
   float2 tex_240;
   float2 tex_300;
};

void main_vertex
(
   float4 position : POSITION,
   out float4 oPosition : POSITION,
   uniform float4x4 modelViewProj,
   float2 tex : TEXCOORD0,
   uniform input IN,
   out vert_out verts: TEXCOORD1
)
{
   oPosition = mul(modelViewProj, position);
   float2 one = 1.1 / IN.texture_size;
   float angle = IN.frame_count = IN.frame_count / 60;
   float scale = 0.9 + 0.3 * sin(1.0 * angle);
   float2x2 rotate = scale * float2x2(
         cos(angle),   sin(angle),
         sin(angle),   cos(angle)
   );

   verts.tex_direct = tex;
   verts.tex_0 = tex + one * mul(rotate, float2(1.0, 0.0));
   verts.tex_60 = tex + one * mul(rotate, float2(0.5, 0.7));
   verts.tex_120 = tex + one * mul(rotate, float2(-0.5, 0.7));
   verts.tex_180 = tex + one * mul(rotate, float2(-1.0, 0.0));
   verts.tex_240 = tex + one * mul(rotate, float2(-0.5, -0.7));
   verts.tex_300 = tex + one * mul(rotate, float2(0.5, -0.7));
}

float4 main_fragment (in vert_out verts : TEXCOORD1, uniform sampler2D s0 : TEXUNIT0) : COLOR
{
   float4 tex_mid = tex2D(s0, verts.tex_direct);
   float4 tex0 = tex2D(s0, verts.tex_0);
   float4 tex60 = tex2D(s0, verts.tex_60);
   float4 tex120 = tex2D(s0, verts.tex_120);
   float4 tex180 = tex2D(s0, verts.tex_180);
   float4 tex240 = tex2D(s0, verts.tex_240);
   float4 tex300 = tex2D(s0, verts.tex_300);

   float4 minimum = min(min(min(tex0, tex60), min(tex120, tex180)), min(tex240, tex300));
   float4 maximum = max(max(max(tex0, tex60), max(tex120, tex180)), max(tex240, tex300));
   float4 diff = 1.0 - exp(-(maximum - minimum));
   return lerp(tex_mid, diff, 0.6);
}

Playing around I also stumbled on to this “reverse” mode…


/* COMPATIBILITY 
   - HLSL compilers
   - Cg compilers
*/

struct input
{
   float2 video_size;
   float2 texture_size;
   float2 output_size;
   float frame_count;
   float frame_direction;
   float frame_rotation;
};

struct vert_out
{
   float2 tex_direct;
   float2 tex_0;
   float2 tex_60;
   float2 tex_120;
   float2 tex_180;
   float2 tex_240;
   float2 tex_300;
};

void main_vertex
(
   float4 position : POSITION,
   out float4 oPosition : POSITION,
   uniform float4x4 modelViewProj,
   float2 tex : TEXCOORD0,
   uniform input IN,
   out vert_out verts: TEXCOORD1
)
{
   oPosition = mul(modelViewProj, position);
   float2 one = 1.0 / IN.texture_size;
   float angle = IN.frame_count = IN.frame_count / 60.0;
   float scale = 1.0 + 0.0 * sin(1.0 * angle);
   float2x2 rotate = scale * float2x2(
         cos(angle),   sin(angle),
         sin(angle),   cos(angle)
   );

   verts.tex_direct = tex;
   verts.tex_0 = tex + one * mul(rotate, float2(1.0, 0.0));
   verts.tex_60 = tex + one * mul(rotate, float2(0.5, 0.7));
   verts.tex_120 = tex + one * mul(rotate, float2(-0.5, 0.7));
   verts.tex_180 = tex + one * mul(rotate, float2(-1.0, 0.0));
   verts.tex_240 = tex + one * mul(rotate, float2(-0.5, -0.7));
   verts.tex_300 = tex + one * mul(rotate, float2(0.5, -0.7));
}

float4 main_fragment (in vert_out verts : TEXCOORD1, uniform sampler2D s0 : TEXUNIT0) : COLOR
{
   float4 tex_mid = tex2D(s0, verts.tex_direct);
   float4 tex0 = tex2D(s0, verts.tex_0);
   float4 tex60 = tex2D(s0, verts.tex_60);
   float4 tex120 = tex2D(s0, verts.tex_120);
   float4 tex180 = tex2D(s0, verts.tex_180);
   float4 tex240 = tex2D(s0, verts.tex_240);
   float4 tex300 = tex2D(s0, verts.tex_300);

   float4 minimum = min(min(min(tex0, tex60), min(tex120, tex180)), min(tex240, tex300));
   float4 maximum = max(max(max(tex0, tex60), max(tex120, tex180)), max(tex240, tex300));
   float4 diff = 1.0 - exp(-(minimum - maximum));
   return lerp(tex_mid, diff, 0.6);
}