Old 25th August 2013, 08:52   #1
roofrack
Junior Member
 
Join Date: Jan 2013
Posts: 9
converting psymatics fragment CG shader to milkdrop

Hi everyone, i did a psymatics emulator, it copies waves on a pond, it looks quite cool when you press m and n keys:

https://dl.dropboxusercontent.com/u/114667999/Public.html>https://dl.dropboxusercontent.com/u/...99/Public.html

u need the 2mb unity3d web plugin to run it it will auto download.

I was going to make it in milkdrop, but i didnt know the code involved. here is the code if you want, the relevant info is the variables, and the last function that used the variables to vary the colors.

code:
Shader "Custom/Pattern" {
Properties {
cp ("cp", Float) = 120.0
p2 ("p2", Float) = 111
p3 ("p3", Float) =111
v1 ("v1", Float) = 1
v2 ("v2", Float) = 1.0
v3 ("v3", Float) = 1.0
d1 ("d1", Float) = 1
d2 ("d2", Float) = 1.0
d3 ("d3", Float) = 1.0
cc ("cc", Float) = 0
cv ("cv", Float) = 3
ht ("ht", Float) = 0
thr ("thr", Float) = 0
oct ("oct", Float) = 0
cl1("cl1", Vector) = (0,0,0,0)
cl2("cl2", Vector) = (0,1,0,0)
cl3("cl3", Vector) = (0,0,0,0)
}

SubShader {
Pass {
CGPROGRAM


#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#pragma exclude_renderers gles
#include "UnityCG.cginc"

uniform half cp;
uniform half p2;
uniform half p3;
uniform half v1;
uniform half v2;
uniform half v3;
uniform half d1;
uniform half d2;
uniform half d3;
uniform half cc;
uniform half cv;
uniform half ht;
uniform half thr;
uniform half oct;
uniform half4 cl1;
uniform half4 cl2;
uniform half4 cl3;

//user defined variables
struct input {
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 pos : SV_POSITION;
float3 color : COLOR0;
float2 texcoord : TEXCOORD0;
};

v2f vert (appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.color = v.normal * 0.5 + 0.5;
o.texcoord = v.texcoord;
return o;
}
// fragment function
float4 frag(input i) : COLOR {


half4 clr = half4(0.0,.0,.0,0.0);

half2 xy0 = i.texcoord + half2(-0.5, -0.5);
half c0 = length(xy0); //sqrt of xx+yy, polar coordinate radius math
half r0 = atan2(i.texcoord.x-.5,i.texcoord.y-.5);//angle polar coordinate
if(cc==0){ht= ((acos(sin(c0 * cp))-1.5) *(acos(sin(r0+ 1.57079632679))-1.5)*cv ) ;}
else if(cc==1){ht= ((acos(sin(c0 * cp))-1.5) *(acos(sin(r0*2+1.57079632679))-1.5)*cv ) ;}
else if(cc==2){ht= ((acos(sin(c0 * cp))-1.5) *(acos(sin(r0*4+1.57079632679))-1.5)*cv ) ;}
else if(cc==3){ht= ((acos(sin(c0 * cp))-1.5) *(acos(sin(r0*8+1.57079632679))-1.5)*cv ) ;}
else if(cc==4){ht= ((acos(sin(c0 * cp))-1.5) +(acos(sin(r0+ 1.57079632679))-1.5)*cv ) ;}
else if(cc==5){ht= ((acos(sin(c0 * cp))-1.5) +(acos(sin(r0*2+1.57079632679))-1.5)*cv ) ;}
else if(cc==6){ht= ((acos(sin(c0 * cp))-1.5) +(acos(sin(r0*4+1.57079632679))-1.5)*cv ) ;}
else if(cc==7){ht= ((acos(sin(c0 * cp))-1.5) +(acos(sin(r0*8+1.57079632679))-1.5)*cv ) ;}
//ht= (acos(sin(c0 * cp) *acos(sin(r0*1+1.57079632679)*2 ) ;

//------------------------------
half2 xy1 = i.texcoord + half2(-0.5+d2, -0.5);
half c1 = length(xy1);
ht+= (acos(sin(c1 * p2) *v2 ))-1,5 ;

half2 xy2 = i.texcoord + half2(-0.5-d2, -0.5);
half c2 = length(xy2);
ht+= (acos(sin(c2 * p2) *v2))-1,5 ;

half2 xy3 = i.texcoord + half2(-0.5, -0.5-d2);
half c3 = length(xy3);
ht+= (acos(sin(c3 * p2) *v2 ))-1,5 ;

half2 xy4 = i.texcoord + half2(-0.5, -0.5+d2);
half c4 = length(xy4);
ht+= (acos(sin(c4 * p2) *v2 ))-1,5 ;
//------------------------
half2 xy5 = i.texcoord + half2(-0.5+d3, -0.5+oct);
half c5 = length(xy5);
ht+= (acos(sin(c5 * p3) *v3 ))-1,5 ;

half2 xy6 = i.texcoord + half2(-0.5-d3, -0.5-oct);
half c6 = length(xy6);
ht+= (acos(sin(c6 * p3) *v3))-1,5 ;

half2 xy7 = i.texcoord + half2(-0.5+oct, -0.5-d3);
half c7 = length(xy7);
ht+= (acos(sin(c7 * p3) *v3))-1,5 ;

half2 xy8 = i.texcoord + half2(-0.5-oct, -0.5+d3);
half c8 = length(xy8);
ht+= (acos(sin(c8 * p3) *v3))-1,5 ;
//----------------------------

if (abs(ht) < thr+5){ clr = cl2; } else { clr = cl1; }
if ((ht) < -thr+5){ clr = cl3; }




//clr.g = ht ;

return normalize(clr);
}
ENDCG
}
}

fallback "Diffuse"
}



pressing m button does this every frame:

if (Input.GetKey ("m")){vol1 = vol1+.0011*5;vol2 = vol2-.0017*5; cv= vol1+.0023*5;dis1 = dis1-0.00001409*5;dis2 = dis2-0.000018387*5;per1 = per1-.00002103212*5;per2 = per2-0.0000270711*5;}
roofrack 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