Old 18th May 2008, 15:11   #1
fed0r
Senior Member
 
fed0r's Avatar
 
Join Date: Mar 2008
Location: Russia, Saint-Petersburg
Posts: 121
Send a message via ICQ to fed0r
Code Tricks

Hi all the preset authors. I've got an idea to make a place to share some code pieces. That could be shader,PF,PV and custom vave equations.
Certainly, first read 'For all the newbies' by Ryan.
Have fun surfing this thread, and please don't forget to share your own effects and code!
fed0r is offline   Reply With Quote
Old 18th May 2008, 17:25   #2
fed0r
Senior Member
 
fed0r's Avatar
 
Join Date: Mar 2008
Location: Russia, Saint-Petersburg
Posts: 121
Send a message via ICQ to fed0r
COMP SHADER
Let' start with a simple one:
code:

//PIXELIZE EFFECT
ret=GetPixel(floor(uv*210)/210);
//210 is value of pixelizing.
//Than more it is, than less pixelizing is done.

fed0r is offline   Reply With Quote
Old 18th May 2008, 17:51   #3
Stahlregen
Senior Member
 
Join Date: Feb 2008
Posts: 218
COMP SHADER

An old effect from Milkdrop 1.x days is the hue shader, which basically is a texture effect that seperates the screen into huge fields of different, cycling colors blending into one another. This color information is available as a float 3.

The classic implementation in Milkdrop 1 looks like this:

code:
ret *= hue_shader;


However, this effect isn't very strong, and can be increased, for example like this:

code:
ret *= (hue_shader*6)-4;


However, you can vary it with other values - the higher the number you multiply the hue_shader with, the more intense the colors. The number you substract from this changes the brightness - a value 1-2 smaller than your multiplicator should yield good results.

Of course, you can also use hue_shader in other, more creative manners...
Stahlregen is offline   Reply With Quote
Old 18th May 2008, 18:08   #4
fed0r
Senior Member
 
fed0r's Avatar
 
Join Date: Mar 2008
Location: Russia, Saint-Petersburg
Posts: 121
Send a message via ICQ to fed0r
SHADERS
Type this in warp shader
code:
//SHARP MOTION EFFECT
ret=tex2D(sampler_fc_main,float2(uv.x+q1,uv.y+q2));


And this in PF code
code:

q1=dx;
q2=dy;


This tweak prevents motion smudging when using dx/dy.
fed0r is offline   Reply With Quote
Old 19th May 2008, 15:38   #5
Flexi
wellspring of milk
Major Dude
 
Flexi's Avatar
 
Join Date: Apr 2007
Location: 54.089866,12.11168,18.75
Posts: 2,058
Send a message via ICQ to Flexi
working with layers

one very cool way to achieve a nice threedimensional athmosphere on the flat screen is to work with different motion strengths for each color channel (as also shown in geiss' 3layer presets).

warp-shader-code:
code:

float2 uv1 = lerp(uv_orig,uv,1); //equals uv
float2 uv2 = lerp(uv_orig,uv,0.2); // 20% of uv
float2 uv3 = lerp(uv_orig,uv,-0.2); //20% of uv but in the opposite direction

ret.x = GetPixel(uv1).x;
ret.y = GetPixel(uv2).y;
ret.z = GetPixel(uv3).z;



thus, so far won't look great without recoloring the color channels in the composite shader:

code:

float3 base = GetPixel(uv);
ret = float3(0.2,0,0.1)*base.y; //the green color channel mapped on a very dark purple
ret = lerp(ret,float3(0.8,0.5,0),base.x); // layered an orange tone from the red channel thereupon
ret = lerp(ret,1,base.z); // the blue color channel i want to be colored white



okay, this is something. but what about different decay rates for the color channels? the blue one will cover all the others, so here's an addition to the warp shader again:

code:

float2 uv1 = lerp(uv_orig,uv,1); //equals uv
float2 uv2 = lerp(uv_orig,uv,0.2); // 20% of uv
float2 uv3 = lerp(uv_orig,uv,-0.2); //20% of uv but in the opposite direction

ret.x = GetPixel(uv1).x*0.8 - 0.004;
ret.y = GetPixel(uv2).y*0.98 - 0.004;
ret.z = GetPixel(uv3).z*0.6 - 0.004;



combine these shaders with a zoom and/or rotation and you will see.
i wrote these lines from sketch and have not prooved them how they look. either way the power lies in the finetuning of the parameters and your skill in picking colors that harmonize.
But remember thinking in the three dimensions of the color space.

Last edited by Flexi; 19th May 2008 at 16:00.
Flexi is offline   Reply With Quote
Old 19th May 2008, 15:45   #6
Flexi
wellspring of milk
Major Dude
 
Flexi's Avatar
 
Join Date: Apr 2007
Location: 54.089866,12.11168,18.75
Posts: 2,058
Send a message via ICQ to Flexi
@stahlregen:
want to squeeze phat colors off the hue shader?

--> pow(hue_shader,6);
Flexi is offline   Reply With Quote
Old 20th May 2008, 20:11   #7
Stahlregen
Senior Member
 
Join Date: Feb 2008
Posts: 218
Quote:
Originally posted by Flexi
@stahlregen:
want to squeeze phat colors off the hue shader?

--> pow(hue_shader,6);
Actually (hue_shader*X)-(X-1.5) gives me better, clearer results.

Anyway, here's a piece of code that will arrange the instances of a custom shape in a circle (or rather an elipse, depending on your screen's aspect ratio).

CUSTOM SHAPE PER-FRAME

code:
instance_count = 3.14*instance*(2/(num_instance));
x = .5 + 0.1 * sin(instance_count);
y = .5 + 0.1 * cos(instance_count);



Nothing fancy, really.
Stahlregen is offline   Reply With Quote
Old 21st May 2008, 01:20   #8
Saint Goody
Senior Member
 
Join Date: Apr 2008
Location: Somewhere in Southern Indiana
Posts: 184
Damn... I was messing with that trying to fix the aspect problem and realized that aspectx/aspecty is a lil' bit screwy...

Anyone know exactly what the deal with it is?

I am the purple heathen.
Saint Goody is offline   Reply With Quote
Old 21st May 2008, 09:05   #9
Flexi
wellspring of milk
Major Dude
 
Flexi's Avatar
 
Join Date: Apr 2007
Location: 54.089866,12.11168,18.75
Posts: 2,058
Send a message via ICQ to Flexi
aspectx/aspecty is only available in the per-frame section - if you want to use it in the custom wave or shape code you have to pass it by 2 of the q_ variables.

in shaders the syntax looks a little different: aspect.x/aspect.y
Flexi is offline   Reply With Quote
Old 21st May 2008, 21:06   #10
Saint Goody
Senior Member
 
Join Date: Apr 2008
Location: Somewhere in Southern Indiana
Posts: 184
I know, that's what I was doing.

Try playing with aspecty on it.

I am the purple heathen.
Saint Goody is offline   Reply With Quote
Old 22nd May 2008, 05:41   #11
Saint Goody
Senior Member
 
Join Date: Apr 2008
Location: Somewhere in Southern Indiana
Posts: 184
q1=apsectx;
q2=aspecty;

From there I multiply by q1 & q2 whenever I need it.

I am the purple heathen.
Saint Goody is offline   Reply With Quote
Old 22nd May 2008, 10:59   #12
Stahlregen
Senior Member
 
Join Date: Feb 2008
Posts: 218
Well then, an improved version...

code:
PER-FRAME

q1 = .5 // central point x...
q2 = .5 // ...and y coord. Play around with this!
q3 = aspectx;
q4 = aspecty;

CUSTOM SHAPE PER-FRAME

instance_counter = 6.28*instance/num_instance;
x = q1 + .1 * (1/q4) * sin(instance_counter);
y = q2 + .1 * (1/q3) * cos(instance_counter);
ang = instance_counter;



Automatically arranges a custom shape's instances in more accurate circles (and turns each instance, too). Vary the factors (+.1*...) in the x/y coords for larger/smaller circles, for example with bass/treb/mid.

Also, a way to show custom shapes only in a fraction of all frames:

code:
PER-FRAME
shape_count = if(below(shape_count,5),shape_count+1,1);
q1 = shape_count;

CUSTOM SHAPE PER-FRAME

transparency = if(equal(q1,5),1,0);
a = transparency;
a2 = transparency;
border_a = transparency;



This example turns the inner opacity, outer opacity and border opacity of the shape to 1 (opaque) in every 5th frame and to 0 (transparent) in the remaining ones.
Stahlregen is offline   Reply With Quote
Old 13th June 2008, 19:21   #13
Stahlregen
Senior Member
 
Join Date: Feb 2008
Posts: 218
Some spiral custom wave code I just whipped up as a mental excercise. I do think I saw something similiar in a preset before, though.

code:
CUSTOM WAVE PER-POINT

centerx = .5;
centery = .5;
amplitude = .15;
turns = 6;
size = .3;
speed = 1; // negative values will make it spin the other way round...

x = centerx+(size-size*sample)*sin(speed*3.14*time+sample*6.28*turns)
*(1+amplitude*(value1+value2));

y = centery+(size-size*sample)*cos(speed*3.14*time+sample*6.28*turns)
*(1+amplitude*(value1+value2));



If you want it leaner, just directly insert the values.
Stahlregen is offline   Reply With Quote
Old 15th June 2008, 19:25   #14
fed0r
Senior Member
 
fed0r's Avatar
 
Join Date: Mar 2008
Location: Russia, Saint-Petersburg
Posts: 121
Send a message via ICQ to fed0r
Double-ret

hmmm.. I've just written some code to pass 6 vals from warp shader to composite, but it doesn't work!
I knew the precision was not too high, but I didn't even think that was THAT kind of LOW.
I attached the preset file; please tell me smth about it.
Attached Files
File Type: milk fed - double-ret experimental.milk (6.6 KB, 348 views)
fed0r is offline   Reply With Quote
Old 15th June 2008, 19:49   #15
Flexi
wellspring of milk
Major Dude
 
Flexi's Avatar
 
Join Date: Apr 2007
Location: 54.089866,12.11168,18.75
Posts: 2,058
Send a message via ICQ to Flexi
hey, can you please try to explain what you actually tried to demonstrate with your code.
where do you see a lack of quality?

one thing always to mention: avoid fractions! - pass the inverse of q1 and do a multiplication!

passing 6 or more values is possible, i guess your failure is located at a different place.
Flexi is offline   Reply With Quote
Old 15th June 2008, 20:07   #16
Stahlregen
Senior Member
 
Join Date: Feb 2008
Posts: 218
edit: never mind, I was wrong here...
Stahlregen is offline   Reply With Quote
Old 27th June 2008, 14:00   #17
Flexi
wellspring of milk
Major Dude
 
Flexi's Avatar
 
Join Date: Apr 2007
Location: 54.089866,12.11168,18.75
Posts: 2,058
Send a message via ICQ to Flexi
quadratic julia fractals and lighting

hi punks,

because it is a pretty simple code, here's the how-to to julia fractals
PHP Code:
//warp shader code
shader_body
{
float2 zoom 1.9// very sensitive - needs fine adjustement
float2 c float2(0.4,0.32); // edit the shape by these two vars
float2 my_uv = (uv-0.5)*zoom//hint: try uv_orig or a scaled version of uv here
my_uv float2(my_uv.x*my_uv.my_uv.y*my_uv.y2*my_uv.x*my_uv.y) + c//complex squaring plus c

ret tex2Dsampler_fc_mainmy_uv ).xyz*0.9 0.01// defining the gradient of the fractal descent in color

recursive means, the fractal is defined by a previous calculation of itself. In the first instance this means the white surrounding: the space out of your screen - the colors of the border. In this case the border is white and with every step the grey value will be decreased.(other gradients are doable - out: black, linear gradient by adding 0.004 - use your imagination). remember my posting about using layers - a julia fractal can be a very effectful one.

But the really cool thing i want to show you, is how to 3d'ish illuminate your flat color patches! therefore you need at least a little 3D model, but that's no big deal - simply imagine the color patch as its own heightmap. what we are interested in, are the gradients of this heightmap in order to refract some light rays. i experimented a lot and came up with this code:
PHP Code:
//comp shader code
shader_body
{
    
float2 d texsize.zw*8;
    
float3 dx = ( GetBlur1(uv float2(1,0)*d) - GetBlur1(uv-float2(1,0)*d) );
    
float3 dy = ( GetBlur1(uv float2(0,1)*d) - GetBlur1(uv-float2(0,1)*d) );
    
float2 light_pos float2(q1,q2);
    
float3 col float3(4,4,4);
    
float c 4;
    
float dd 16;
    
float3 plastic;
    
plastic.col.x/(1+dd*pow(lengthuv float2(dx.x,dy.x)*light_pos),0.5));
    
plastic.col.y/(1+dd*pow(lengthuv float2(dx.y,dy.y)*light_pos),0.5));
    
plastic.col.z/(1+dd*pow(lengthuv float2(dx.z,dy.z)*light_pos),0.5));

    
ret plastic*GetPixel(uv);


i simply take a horizontal(dx) and a vertical(dy) difference as my gradients - that's it. (okay it's not that simple - first i defined the distance where to grab the difference from (16pixels) and i also 'blurred' the heightmap - technically spoken a lowpass filter)

okay now let's have a lightsource. If you like a HDR-overbrightening effect, give it a color greater than one. (maybe you need to scale the final output then)
don't understand me wrong - this is absolutely NOT physically motivated, i just wanted to achieve some nice effects, so i imagined: either the surface is reflecting the light in a direct way, or with a distortion. the intesity corresponds to the inverse of the squareroot of the distance. This is the empirical part, try your own ideas but this gives a cool plastic look. Finally multiplicate the light value with the color value (lower regions/the darker parts of the color channel won't reflect any light)

explanation of some variables i used:
d - pixeldistance the gradient is grabbed from
col - overbrightened color of the lightsource
c - actually the 'height of the heightmap' (nasty hack, i know, should be replaced by a trigonometric calculation)
dd - something like a 'highlight' factor (try 16,32,64)

enjoy!
Attached Files
File Type: milk flexi - julia set illuminating example.milk (5.8 KB, 419 views)
Flexi is offline   Reply With Quote
Old 27th June 2008, 14:31   #18
Flexi
wellspring of milk
Major Dude
 
Flexi's Avatar
 
Join Date: Apr 2007
Location: 54.089866,12.11168,18.75
Posts: 2,058
Send a message via ICQ to Flexi
Flexi is offline   Reply With Quote
Old 28th June 2008, 09:13   #19
fed0r
Senior Member
 
fed0r's Avatar
 
Join Date: Mar 2008
Location: Russia, Saint-Petersburg
Posts: 121
Send a message via ICQ to fed0r
WooOoooOOooOoiooWW!w!!
Thank you Flexi!!!
Cool stuff! Yeah!
fed0r is offline   Reply With Quote
Old 1st July 2008, 11:12   #20
Flexi
wellspring of milk
Major Dude
 
Flexi's Avatar
 
Join Date: Apr 2007
Location: 54.089866,12.11168,18.75
Posts: 2,058
Send a message via ICQ to Flexi
today some 3D custom wave/shape code - see comments in the example code

I ♥ chaos!
Attached Files
File Type: milk flexi - lorenz attractor.milk (10.5 KB, 461 views)

Last edited by Flexi; 1st July 2008 at 11:35.
Flexi is offline   Reply With Quote
Old 2nd July 2008, 07:48   #21
fed0r
Senior Member
 
fed0r's Avatar
 
Join Date: Mar 2008
Location: Russia, Saint-Petersburg
Posts: 121
Send a message via ICQ to fed0r
OMFG!
fed0r is offline   Reply With Quote
Old 2nd July 2008, 09:50   #22
Flexi
wellspring of milk
Major Dude
 
Flexi's Avatar
 
Join Date: Apr 2007
Location: 54.089866,12.11168,18.75
Posts: 2,058
Send a message via ICQ to Flexi
calm down, it's just another kind of building block that still requires some work to get a decent preset off it - have fun!
Flexi is offline   Reply With Quote
Old 8th July 2008, 17:11   #23
Flexi
wellspring of milk
Major Dude
 
Flexi's Avatar
 
Join Date: Apr 2007
Location: 54.089866,12.11168,18.75
Posts: 2,058
Send a message via ICQ to Flexi
i just realized that i really had broccoli for lunch yesterday

edge glow and motion blur.
Attached Files
File Type: milk flexi - romanesco fantasies [motion blurred].milk (12.8 KB, 447 views)
Flexi is offline   Reply With Quote
Old 3rd December 2008, 21:01   #24
Flexi
wellspring of milk
Major Dude
 
Flexi's Avatar
 
Join Date: Apr 2007
Location: 54.089866,12.11168,18.75
Posts: 2,058
Send a message via ICQ to Flexi
This time i crawled through Martin's very cool ripples on water code and i also added a true reflection

here's the code:
PHP Code:
// composite shader code

shader_body {
float h 0.3;                     // height of the horizon
float cut_off 0.01;              // cut off lower border
float2 t float2(0.5,0.25)*time;  // velocity
float strength 0.025;


float2 c uv_orig-float2(0.5,1-h);
float z 1/c.y;
float2 uv_water float2(c.x*z*h,z*h)+t;
int mask = (c.y>0);
uv_water = (tex2D(sampler_noise_hq,uv_water/2)-0.5)*mask;
float2 uv_mirror 1.0-abs(frac((c+float2(0.5,1))*0.5)*2-1)+float2(0,-cut_off);
uv_mirror =saturate(uv_mirror-uv_water.xy*strength);


ret GetPixel(uv_mirror); // no further after effects

as you can see i cleaned it up and parameterized the code.
have fun, and let me see cool mixes

Attached Files
File Type: milk flexi + martin - enhanced reflection prototype.milk (9.9 KB, 333 views)
Flexi is offline   Reply With Quote
Old 10th January 2009, 22:14   #25
Stahlregen
Senior Member
 
Join Date: Feb 2008
Posts: 218
I experimented with some easy to use video echo code because I wanted to try out loops.

Put this in your Comp. Shader:

code:
float n = 0; float2 uvo = uv; float3 ret2 = 0;
float3 alpha = .5;
float2 uv_echo = (uv-.5)*1*float2(-1,-1)+.5;
while (n<=1) {
// start

ret = tex2D(sampler_main,uv);

// end
ret2 = lerp(ret,ret2,n*alpha);
uv = uv_echo; n++;
} uv = uvo; ret = ret2;



Replace ret = tex2D(sampler_main,uv); with your code. The effects you use here will be repeated once with the normal uv coordinates and once with uv_echo, then blended together to produce the old video echo effect.

The alpha variable controls how visible the video echo will be. (As this is a float3, you can blend color channels independently by using float3(R,G,B) instead of just a factor).

By modifying the factor in uv_echo you control the zoom of the echo (bigger factors reduce zoom) and the float2(-1,-1) controls the orientation of the echo (x,y; 1 = normal, -1 = flipped).

Be advised that while this may save time, it probably cost you a lot of instruction slots.
Stahlregen is offline   Reply With Quote
Old 12th January 2009, 16:50   #26
Flexi
wellspring of milk
Major Dude
 
Flexi's Avatar
 
Join Date: Apr 2007
Location: 54.089866,12.11168,18.75
Posts: 2,058
Send a message via ICQ to Flexi
working with gradients

sorry for a little confusion with this pack, but it went so cool that i ended up describing two different kinds of gradients.

i wrote the tutorial in december when i was working on the milkcore and i simply forgot it lying there unnoticed in it's cold folder...

okay.
first i thought it would be nice for newbies to see what's possible for recoloring the output from the warp shader.
even if it might look so - here's no distortion applied on the uv vector of the input from the warp shader. i only once rotated a palette.

00 - the basis of the tutorial. all further changes are done in the composite shader, where they're also commented.
00 - the basics of using gradients in recoloring single color channels (background: vertical. foreground: horizontal)
01 - calculating the gradient vector from the input image and using it for a displacement mapping on a diagonal black-to-white-gradient
02 - mixing two horizontal gradients via another vertical one to a genuine palette
03 - tiling the palette
04 - tiling with further mirroring
05 - rotating the palette
06 - (combination interlude: nice sky gradient in the background, and rotated displaced palette for the foreground)
07 - additional rotation of the (input gradient) displacement vector
08 - left empty for your amusement
09 - same palette for fore- & background plus rotated displacement
10 & 11 - http://www.youtube.com/watch?v=VWx0BVAdAhU
12 - using a texture as palette
Attached Files
File Type: zip flexi - guide to work with gradients.zip (48.5 KB, 412 views)

Last edited by Flexi; 12th January 2009 at 17:13.
Flexi is offline   Reply With Quote
Old 15th January 2009, 23:34   #27
Cope
Senior Member
 
Cope's Avatar
 
Join Date: Jul 2008
Location: Germany
Posts: 149
Nice guide

a lot of my presets use effects based off colors, I find you can use them to make things more random. especially if you use some sort of color based transformation, injecting a changing gradient on beats or something will make the whole thing more responsive and add a touch of random too

thought I'd share a couple other tricks I use quite often. they're both for the per-frame code.

the first one is a counter based on beats. useful if you have an effect that you want to be driven by a beat (or a set volume level or what have you) but don't want it to be too chaotic.

code:
bass_thresh = above(bass_att,bass_thresh)*2 +
(1-above(bass_att,bass_thresh))*((bass_thresh-1.3)*0.96+1.3);
count = equal(bass_thresh, 2)*1 + (1-equal(bass_thresh, 2))*count;
count = count - above(count, 0.02)*0.02;



so it's just a normal bass_thresh variable, whenever it hits 2 (beat detected) count is set to 1 then decreases back down to 0. we can make it decrease faster or more slowly by changing the bolded part. count can be piped into a q variable to be used for something like a lerp in the shaders. bass_thresh can be replaced with anything else, like above(vol, 1.5) or another beat detection variable.

code:
xx = equal(bass_thresh,2)*5*sin(time*4) + (1-equal(bass_thresh,2))*xx;



this one picks a number between -5..5 whenever a beat is detected, and keeps the variable constant whenever there's no beat. pretty simple really. only downside is bass_thresh isn't very accurate, and if there's a big change in volume of the music it'll keep bass_thresh at 2 for long periods of time, causing xx to go insane.

Murphey's fighting Occam, and I'm in the stands.
Cope is offline   Reply With Quote
Old 17th January 2009, 15:21   #28
Stahlregen
Senior Member
 
Join Date: Feb 2008
Posts: 218
Fun things - Complex Multiplication/Division Functions:

code:

//Complex Multiplication
float2 ComMul(float2 mul1, float2 mul2) {
float2 mul = float2(mul1.x*mul2.x - mul1.y*mul2.y, mul1.y*mul2.x + mul1.x*mul2.y);
return mul;
}

//Complex Division
float2 ComDiv(float2 div1, float2 div2) {
float2 div = float2( (div1.x*div2.x + div1.y*div2.y)/(div2.x*div2.x + div2.y*div2.y),
(div1.y*div2.x + div1.x*div2.y)/(div2.x*div2.x + div2.y*div2.y) );
return div;
}



1. Paste code before shader.
2. Call with ComMul(float2,float2) or ComDiv(float2,float2) to do complex multiplication or division of the float2s.
3. ????
4. PROFIT!

For more info: Pixel Shader guide by Cope.
Stahlregen is offline   Reply With Quote
Old 17th January 2009, 16:52   #29
Cope
Senior Member
 
Cope's Avatar
 
Join Date: Jul 2008
Location: Germany
Posts: 149
The same thing occurred to me yesterday while I was playing with different fractal equations. I was going to make a post about it today, but you beat me to it

Nice job

Murphey's fighting Occam, and I'm in the stands.
Cope is offline   Reply With Quote
Old 17th January 2009, 17:11   #30
Nitorami
Major Dude
 
Join Date: Mar 2008
Location: Erlangen
Posts: 859
Quote:
Originally posted by Cope


(1-above(bass_att,bass_thresh))*((bass_thresh-1.3)*0.96+1.3);
count = equal(bass_thresh, 2)*1 + (1-equal(bass_thresh, 2))*count;
count = count - above(count, 0.02)*0.02;

Just a note on this: If you multiply a variable by a factor < 1, to make it decay slowly, the speed of decay will depend on the frame rate, because, well, at 60fps the multiplication is just performed more often per second than at 20fps, and the behaviour of the preset may be quite different, e.g the beat response may be triggered far more frequently. The solution is of course to adjust all decay factors to the frame rate. For instance

decay = pow (0.96, 30/fps);
x = x*decay;

will perform an fps independant decay of x.
Nitorami is offline   Reply With Quote
Old 12th February 2009, 18:39   #31
Flexi
wellspring of milk
Major Dude
 
Flexi's Avatar
 
Join Date: Apr 2007
Location: 54.089866,12.11168,18.75
Posts: 2,058
Send a message via ICQ to Flexi
the bipolar mapping

it turned out that the bipolar mapping makes a great nonlinear kaleidoscope so here's the code

PHP Code:
// per-frame-code

bb bb*0.99 bass*0.02//dampened sound vars
mm mm*0.99 mid*0.02;
tt tt*0.99 treb*0.02;
mx max(max(bb,mm),tt);
mn min(min(bb,mm),tt);
t1 = (bb-mn)/(mx-mn); // normalize
t2 = (mm-mn)/(mx-mn);
t3 = (tt-mn)/(mx-mn);

0.1/fps// change velocity here
bm bm + (t1-t2)*v;
mt mt + (t2-t3)*v;

q21 1// position of pole 1 (x,y)
q22 0;
q23 = -1// position of pole 2 (x,y)
q24 0;
q26 = -bm// longitude
q27 mt// latitude 
q21/q22 and q23/24 are the positions for the two poles
q27 defines a shift on the line between the poles
q26 impacts the angular motion orthogonal to the line between the poles.

In this case the normalized ratio between bass/mid/treb is taken to keep the strength of the motion in a certain limit. you can use time expressions as well


PHP Code:
// composite shader code
float2 uv_orig,c,bipolar;

shader_body
{
uv_orig uv;

uv 0.5 + (uv-0.5)*4// try apply some overall zoom in or out, works good in play with number of iterations
float cutoff 0.96// cut off borders
int n 1// number of radial mirrors
float s 0.333// logarithmic zoom factor
int depth 4//number of fractal iterations

for(int i=0;i<depth;i++){
 
= (uv-0.5)*2*aspect.wz;
   
numerator = (float2(q21,q22))*64;
   
denominator float2(q23,q24);
   
fraction float2numerator.x*denominator.numerator.y*denominator.y,
                      
numerator.y*denominator.numerator.x*denominator.y)/
                      (
denominator.x*denominator.denominator.y*denominator.y);
   
fraction-0.5// kind of a Moebius transformation
   
bipolar float2(n*atan2(c.x,c.y)*M_INV_PI_2*2+q26,s*aspect.w*log(length(c))+q27);
   
uv 0.5 + (0.5 absfracbipolar 0.5 ) * 2.0 1.0 ))*cutoff// mirror
}
 
// lighting and coloring
 //...
ret GetPixel(uv);

with this code the geometry is broken down to the kaleidoscope effect. nevertheless this one is only one special case. imagine setting the location of the poles and the polar translation individually for each iteration step.

Anyway i posted this to demonstrate the effectiveness of simple gradients when they are distorted in a nonlinear way. The following example file consist of several techniques described in this thread.
there's a lighting model to find as well as there are two gradients and a line of code for a nice edge enhancement with a halo.
the output of the warp shader is a single separation mask in the green channel. so everything you see is based on the 8 bit separation mask and there are still 2 unused color channels for further effects
Flexi is offline   Reply With Quote
Old 13th February 2009, 04:09   #32
Amandio C
Senior Member
 
Join Date: Dec 2008
Posts: 400
Will surely try this back home. Thanks for sharing.
Amandio C is offline   Reply With Quote
Old 19th February 2009, 15:16   #33
Flexi
wellspring of milk
Major Dude
 
Flexi's Avatar
 
Join Date: Apr 2007
Location: 54.089866,12.11168,18.75
Posts: 2,058
Send a message via ICQ to Flexi
some parameter play and two simple circular gradients.
..ooops..
Flexi is offline   Reply With Quote
Old 19th February 2009, 15:17   #34
Flexi
wellspring of milk
Major Dude
 
Flexi's Avatar
 
Join Date: Apr 2007
Location: 54.089866,12.11168,18.75
Posts: 2,058
Send a message via ICQ to Flexi
i guess this one will give a good start on another complex number repetition pack soon
Attached Files
File Type: milk flexi - tissue issue.milk (10.0 KB, 304 views)
Flexi is offline   Reply With Quote
Old 15th April 2010, 15:43   #35
Flexi
wellspring of milk
Major Dude
 
Flexi's Avatar
 
Join Date: Apr 2007
Location: 54.089866,12.11168,18.75
Posts: 2,058
Send a message via ICQ to Flexi
Attached Files
File Type: milk Flexi - milk field.milk (12.2 KB, 244 views)
Flexi is offline   Reply With Quote
Old 18th April 2010, 03:27   #36
Amandio C
Senior Member
 
Join Date: Dec 2008
Posts: 400
zebras crossing
Attached Files
File Type: zip amandio c + flexi - zebras crossing.zip (5.5 KB, 219 views)
Amandio C is offline   Reply With Quote
Old 10th June 2011, 11:05   #37
ginkner
Junior Member
 
Join Date: Sep 2005
Posts: 6
Quote:
//El Ginks' Custom Wave Spirograph Generator Code
//Inside Custom Wave Per-Point code.
//Emulates a Spirograph.
//Basic Setup
//sample range setup. You might need to change this if
//the figure doesnt meet form a closed loop.
s=sample*3.14159*12;
t=time; //available for change.

//Spirograph Settings
cx=0.5; //center of the figure: x-coordinant
cy=0.5; //center of the figure: y-coordinant
rad=0.1; //size of the figure
tension=0.5+0.45*sin(time); //Its a bit complicated to explain.
outer=0.3; //Radius of outer circle
inner=0.25; //Radius of inner circle
ang=-t;


//Start Spirograph
l=tension/inner;
k=inner/outer;

//Spirograph Generator
xt=rad*((1-k)*cos(s)+l*k*cos(ang+s*((1-k)/k)));
yt=rad*((1-k)*sin(s)-l*k*sin(ang+s*((1-k)/k)));

//Set
x=0.5+xt;
y=0.5+yt;
Sorry its not all pretty. Milkdrop decided that the filename string was tool long after I was done commenting all of this. :\
ginkner is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Visualizations > MilkDrop > MilkDrop Presets

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump