Giter Club home page Giter Club logo

Comments (8)

smkplus avatar smkplus commented on May 13, 2024

what shader do you want to convert into hlsl?
can you give me shadertoy's link?
my converter just find a pattern in glsl shader and convert it to hlsl
shaders in shadertoy made by different peoples so there isn't standard and same pattern to convert them

from shaderman.

araya avatar araya commented on May 13, 2024

I want to convert https://www.shadertoy.com/view/Wtt3Wl,but it didn't work at all,please teach me how to try it again. My unity version is 2019.3.7f1

from shaderman.

smkplus avatar smkplus commented on May 13, 2024

@araya do you need a font rendering or rotation effect?
that shader is not optimal in game engine
I recommended to use rotation node in shadergraph

from shaderman.

araya avatar araya commented on May 13, 2024

@araya do you need a font rendering or rotation effect?
that shader is not optimal in game engine
I recommended to use rotation node in shadergraph

Thx for reply issue so quickly.
The rotation effect is not must,I just want to show words in shader,for example: show hello world,or show my name.

from shaderman.

smkplus avatar smkplus commented on May 13, 2024

@araya do you need a font rendering or rotation effect?
that shader is not optimal in game engine
I recommended to use rotation node in shadergraph

Thx for reply issue so quickly.
The rotation effect is not must,I just want to show words in shader,for example: show hello world,or show my name.

ok but as I said that's not optimal because there are many calculation!
in my browser run in 6fps!!!

instead you can use this one:

https://github.com/przemyslawzaworski/Unity3D-CG-programming/blob/master/font.shader
https://github.com/przemyslawzaworski/Unity3D-CG-programming/blob/master/font.png

from shaderman.

araya avatar araya commented on May 13, 2024

thx for you recommend,I just want to write my name in shader with pure code, i think it's a cool thing!

from shaderman.

smkplus avatar smkplus commented on May 13, 2024

@araya
I tried to convert your shader

Shader "Hidden/NewImageEffectShader"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
        // No culling or depth
        Cull Off ZWrite Off ZTest Always

        Pass
        {
            CGPROGRAM
            
// Upgrade NOTE: excluded shader from DX11, OpenGL ES 2.0 because it uses unsized arrays
#pragma exclude_renderers d3d11 gles
// Upgrade NOTE: excluded shader from DX11 because it uses wrong array syntax (type[size] name)
#pragma exclude_renderers d3d11
            #pragma vertex vert
            #pragma fragment frag


            #include "UnityCG.cginc"

            struct appdata
            {
                fixed4 vertex : POSITION;
                fixed2 uv : TEXCOORD0;
            };

            struct v2f
            {
                fixed2 uv : TEXCOORD0;
                fixed4 vertex : SV_POSITION;
            };

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                return o;
            }

            sampler2D _MainTex;
            
            #define ZERO min(0,iFrame)

fixed border;

// Modified from http://tog.acm.org/resources/GraphicsGems/gems/Roots3And4.c
// Credits to Doublefresh for hinting there
int solve_quadric(fixed2 coeffs, inout fixed2 roots){

	// normal form: x^2 + px + q = 0
	fixed p = coeffs[1] / 2.;
	fixed q = coeffs[0];

	fixed D = p * p - q;

	if (D < 0.){
		return 0;
	}
	else{
		roots[0] = -sqrt(D) - p;
		roots[1] = sqrt(D) - p;

		return 2;
	}
}

//From Trisomie21
//But instead of his cancellation fix i'm using a newton iteration
int solve_cubic(fixed3 coeffs, inout fixed3 r){

	fixed a = coeffs[2];
	fixed b = coeffs[1];
	fixed c = coeffs[0];

	fixed p = b - a*a / 3.0;
	fixed q = a * (2.0*a*a - 9.0*b) / 27.0 + c;
	fixed p3 = p*p*p;
	fixed d = q*q + 4.0*p3 / 27.0;
	fixed offset = -a / 3.0;
	if(d >= 0.0) { // Single solution
		fixed z = sqrt(d);
		fixed u = (-q + z) / 2.0;
		fixed v = (-q - z) / 2.0;
		u = sign(u)*pow(abs(u),1.0/3.0);
		v = sign(v)*pow(abs(v),1.0/3.0);
		r[0] = offset + u + v;	

		//Single newton iteration to account for cancellation
		fixed f = ((r[0] + a) * r[0] + b) * r[0] + c;
		fixed f1 = (3. * r[0] + 2. * a) * r[0] + b;

		r[0] -= f / f1;

		return 1;
	}
	fixed u = sqrt(-p / 3.0);
	fixed v = acos(-sqrt( -27.0 / p3) * q / 2.0) / 3.0;
	fixed m = cos(v), n = sin(v)*1.732050808;

	//Single newton iteration to account for cancellation
	//(once for every root)
	r[0] = offset + u * (m + m);
    r[1] = offset - u * (n + m);
    r[2] = offset + u * (n - m);

	fixed3 f = ((r + a) * r + b) * r + c;
	fixed3 f1 = (3. * r + 2. * a) * r + b;

	r -= f / f1;

	return 3;
}

fixed cubic_bezier_normal_iteration(fixed t, fixed2 a0, fixed2 a1, fixed2 a2, fixed2 a3){
	//horner's method
	fixed2 a_2=a2+t*a3;
	fixed2 a_1=a1+t*a_2;
	fixed2 b_2=a_2+t*a3;

	fixed2 uv_to_p=a0+t*a_1;
	fixed2 tang=a_1+t*b_2;

	fixed l_tang=dot(tang,tang);
	return t-dot(tang,uv_to_p)/l_tang;
}

fixed cubic_bezier_dis_approx_sq(fixed2 uv, fixed2 p0, fixed2 p1, fixed2 p2, fixed2 p3){
	fixed2 a3 = (-p0 + 3. * p1 - 3. * p2 + p3);
	fixed2 a2 = (3. * p0 - 6. * p1 + 3. * p2);
	fixed2 a1 = (-3. * p0 + 3. * p1);
	fixed2 a0 = p0 - uv;

	fixed d0 = 1e38;

	fixed t;
	fixed3 params=fixed3(0,.5,1);

	for(int i=ZERO;i<3;i++){
		t=params[i];
		for(int j=ZERO;j<3;j++){
			t=cubic_bezier_normal_iteration(t,a0,a1,a2,a3);
		}
		t=clamp(t,0.,1.);
		fixed2 uv_to_p=((a3*t+a2)*t+a1)*t+a0;
		d0=min(d0,dot(uv_to_p,uv_to_p));
	}

	return d0;
}

//segment_dis_sq by iq
fixed length2( fixed2 v ) { return dot(v,v); }

fixed segment_dis_sq( fixed2 p, fixed2 a, fixed2 b ){
	fixed2 pa = p-a, ba = b-a;
	fixed h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
	return length2( pa - ba*h );
}

int segment_int_test(fixed2 uv, fixed2 p0, fixed2 p1){
	p0-=uv;
	p1-=uv;

	int ret;
	
	if(p0.y*p1.y<0.){
		fixed2 nor=p0-p1;
		nor=fixed2(nor.y,-nor.x);
		
		fixed sgn;
		
		if(p0.y>p1.y){
			sgn=1.;
		}
		else{
			sgn=-1.;
		}

		if(dot(nor,p0)*sgn<0.){
			ret=0;
		}
		else{
			ret=1;
		}
	}
	else{
		ret=0;
	}

	return ret;
}

int cubic_bezier_int_test(fixed2 uv, fixed2 p0, fixed2 p1, fixed2 p2, fixed2 p3){

	fixed cu = (-p0.y + 3. * p1.y - 3. * p2.y + p3.y);
	fixed qu = (3. * p0.y - 6. * p1.y + 3. * p2.y);
	fixed li = (-3. * p0.y + 3. * p1.y);
	fixed co = p0.y - uv.y;

	fixed3 roots = fixed3(1e38);
	int n_roots;
    
    int n_ints=0;
    
    if(uv.x<min(min(p0.x,p1.x),min(p2.x,p3.x))){
		if(uv.y>=min(p0.y,p3.y) && uv.y<=max(p0.y,p3.y)){
			n_ints=1;
		}
	}
    else{

        if(abs(cu) < .0001){
            n_roots = solve_quadric(fixed2(co/qu,li/qu),roots.xy);
        }
        else{
            n_roots = solve_cubic(fixed3(co/cu,li/cu,qu/cu),roots);
        }

        for(int i=ZERO;i<n_roots;i++){
            if(roots[i] >= 0. && roots[i] <= 1.){
                fixed x_pos = -p0.x + 3. * p1.x - 3. * p2.x + p3.x;
                x_pos = x_pos * roots[i] + 3. * p0.x - 6. * p1.x + 3. * p2.x;
                x_pos = x_pos * roots[i] + -3. * p0.x + 3. * p1.x;
                x_pos = x_pos * roots[i] + p0.x;

                if(x_pos > uv.x){
                    n_ints++;
                }
            }
        }
    }

	return n_ints;
}

fixed path0_dis_sq(fixed2 uv){
	fixed dis_sq=1e38;

	int num_its=0;

	fixed2[48] p=fixed2[](fixed2(-0.297242,0.075528),
	                  fixed2(-0.297242,0.0973915),
	                  fixed2(-0.3199,0.0993791),
	                  fixed2(-0.329242,0.0993791),
	                  fixed2(-0.354882,0.0993791),
	                  fixed2(-0.375155,0.0844722),
	                  fixed2(-0.375155,0.0638014),
	                  fixed2(-0.375155,0.0345839),
	                  fixed2(-0.33441,0.0224597),
	                  fixed2(-0.33441,-0.011528),
	                  fixed2(-0.33441,-0.0282236),
	                  fixed2(-0.344149,-0.0379628),
	                  fixed2(-0.357466,-0.0379628),
	                  fixed2(-0.370186,-0.0379628),
	                  fixed2(-0.376547,-0.0288199),
	                  fixed2(-0.376547,-0.018882),
	                  fixed2(-0.376547,-0.00516764),
	                  fixed2(-0.364025,-0.000198714),
	                  fixed2(-0.353292,-0.000198714),
	                  fixed2(-0.353888,0.0101367),
	                  fixed2(-0.363826,0.0129192),
	                  fixed2(-0.370783,0.0129192),
	                  fixed2(-0.384696,0.0129192),
	                  fixed2(-0.4,0.00178888),
	                  fixed2(-0.4,-0.019677),
	                  fixed2(-0.4,-0.0439255),
	                  fixed2(-0.380522,-0.0538634),
	                  fixed2(-0.357863,-0.0538634),
	                  fixed2(-0.329043,-0.0538634),
	                  fixed2(-0.302012,-0.0375652),
	                  fixed2(-0.302012,-0.0041739),
	                  fixed2(-0.302012,0.0387578),
	                  fixed2(-0.346733,0.042733),
	                  fixed2(-0.346733,0.0719504),
	                  fixed2(-0.346733,0.083876),
	                  fixed2(-0.339379,0.0900374),
	                  fixed2(-0.328447,0.0900374),
	                  fixed2(-0.317515,0.0900374),
	                  fixed2(-0.313739,0.0836772),
	                  fixed2(-0.313739,0.0767207),
	                  fixed2(-0.313739,0.0701616),
	                  fixed2(-0.317317,0.0628076),
	                  fixed2(-0.322683,0.0596274),
	                  fixed2(-0.320099,0.0566461),
	                  fixed2(-0.317118,0.0554536),
	                  fixed2(-0.31354,0.0554536),
	                  fixed2(-0.303602,0.0554536),
	                  fixed2(-0.297242,0.0640001));

	fixed4[16] c_bez=fixed4[](fixed4(0,1,2,3),
	                        fixed4(3,4,5,6),
	                        fixed4(6,7,8,9),
	                        fixed4(9,10,11,12),
	                        fixed4(12,13,14,15),
	                        fixed4(15,16,17,18),
	                        fixed4(18,19,20,21),
	                        fixed4(21,22,23,24),
	                        fixed4(24,25,26,27),
	                        fixed4(27,28,29,30),
	                        fixed4(30,31,32,33),
	                        fixed4(33,34,35,36),
	                        fixed4(36,37,38,39),
	                        fixed4(39,40,41,42),
	                        fixed4(42,43,44,45),
	                        fixed4(45,46,47,0));

	if(all(lessThan(uv,fixed2(-0.297242,0.0993791)+border)) && all(greaterThan(uv,fixed2(-0.4,-0.0538634)-border))){
		for(int i=ZERO;i<16;i++){
			dis_sq=min(dis_sq,cubic_bezier_dis_approx_sq(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]));
			num_its+=cubic_bezier_int_test(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]);
		}
	}

	fixed sgn=1.;

	if(num_its%2==1){
		sgn=-1.;
	}

	return sgn*dis_sq;
}

fixed path1_dis_sq(fixed2 uv){
	fixed dis_sq=1e38;

	int num_its=0;

	fixed2[36] p=fixed2[](fixed2(-0.234832,0.0222609),
	                  fixed2(-0.234832,0.00954037),
	                  fixed2(-0.243776,-0.0149068),
	                  fixed2(-0.243776,-0.0284223),
	                  fixed2(-0.243776,-0.0397516),
	                  fixed2(-0.237615,-0.0508821),
	                  fixed2(-0.220323,-0.0508821),
	                  fixed2(-0.209789,-0.0508821),
	                  fixed2(-0.194484,-0.0467081),
	                  fixed2(-0.183354,-0.0141118),
	                  fixed2(-0.191702,-0.0141118),
	                  fixed2(-0.196074,-0.0244473),
	                  fixed2(-0.199652,-0.0316026),
	                  fixed2(-0.208397,-0.0316026),
	                  fixed2(-0.21436,-0.0316026),
	                  fixed2(-0.216348,-0.0282236),
	                  fixed2(-0.216348,-0.0232546),
	                  fixed2(-0.216348,-0.0121242),
	                  fixed2(-0.206807,0.0119255),
	                  fixed2(-0.206807,0.0280249),
	                  fixed2(-0.206807,0.0439255),
	                  fixed2(-0.216149,0.0504845),
	                  fixed2(-0.228869,0.0504845),
	                  fixed2(-0.235031,0.0504845),
	                  fixed2(-0.243776,0.0488945),
	                  fixed2(-0.252124,0.0393542),
	                  fixed2(-0.241391,0.0894412),
	                  fixed2(-0.270807,0.085466),
	                  fixed2(-0.299627,-0.0496894),
	                  fixed2(-0.271006,-0.0496894),
	                  fixed2(-0.257292,0.0149068),
	                  fixed2(-0.256099,0.0202733),
	                  fixed2(-0.249938,0.0323976),
	                  fixed2(-0.242186,0.0323976),
	                  fixed2(-0.237217,0.0323976),
	                  fixed2(-0.234832,0.02882));

	fixed2[6] seg=fixed2[](fixed2(9,10),
	                     fixed2(25,26),
	                     fixed2(26,27),
	                     fixed2(27,28),
	                     fixed2(28,29),
	                     fixed2(29,30));

	fixed4[10] c_bez=fixed4[](fixed4(0,1,2,3),
	                        fixed4(3,4,5,6),
	                        fixed4(6,7,8,9),
	                        fixed4(10,11,12,13),
	                        fixed4(13,14,15,16),
	                        fixed4(16,17,18,19),
	                        fixed4(19,20,21,22),
	                        fixed4(22,23,24,25),
	                        fixed4(30,31,32,33),
	                        fixed4(33,34,35,0));

	if(all(lessThan(uv,fixed2(-0.183354,0.0894412)+border)) && all(greaterThan(uv,fixed2(-0.299627,-0.0508821)-border))){
		for(int i=ZERO;i<6;i++){
			dis_sq=min(dis_sq,segment_dis_sq(uv,p[seg[i][0]],p[seg[i][1]]));
			num_its+=segment_int_test(uv,p[seg[i][0]],p[seg[i][1]]);
		}
		for(int i=ZERO;i<10;i++){
			dis_sq=min(dis_sq,cubic_bezier_dis_approx_sq(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]));
			num_its+=cubic_bezier_int_test(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]);
		}
	}

	fixed sgn=1.;

	if(num_its%2==1){
		sgn=-1.;
	}

	return sgn*dis_sq;
}

fixed path2_dis_sq(fixed2 uv){
	fixed dis_sq=1e38;

	int num_its=0;

	fixed2[45] p=fixed2[](fixed2(-0.124919,0.0496896),
	                  fixed2(-0.127105,0.0391554),
	                  fixed2(-0.127105,0.0405467),
	                  fixed2(-0.127105,0.0463107),
	                  fixed2(-0.131876,0.0506833),
	                  fixed2(-0.143205,0.0506833),
	                  fixed2(-0.177789,0.0506833),
	                  fixed2(-0.194286,0.00795032),
	                  fixed2(-0.194286,-0.018882),
	                  fixed2(-0.194286,-0.0425342),
	                  fixed2(-0.181366,-0.0508821),
	                  fixed2(-0.167851,-0.0508821),
	                  fixed2(-0.153739,-0.0508821),
	                  fixed2(-0.144397,-0.0417392),
	                  fixed2(-0.138236,-0.0325963),
	                  fixed2(-0.137043,-0.0445217),
	                  fixed2(-0.129888,-0.0508821),
	                  fixed2(-0.118758,-0.0508821),
	                  fixed2(-0.108025,-0.0508821),
	                  fixed2(-0.0901364,-0.0465093),
	                  fixed2(-0.0788071,-0.0141118),
	                  fixed2(-0.087155,-0.0141118),
	                  fixed2(-0.0901364,-0.0240497),
	                  fixed2(-0.0955028,-0.0327951),
	                  fixed2(-0.103254,-0.0327951),
	                  fixed2(-0.10882,-0.0327951),
	                  fixed2(-0.111403,-0.0298137),
	                  fixed2(-0.111403,-0.0242485),
	                  fixed2(-0.111403,-0.0224597),
	                  fixed2(-0.111205,-0.0204721),
	                  fixed2(-0.110609,-0.0178882),
	                  fixed2(-0.0962985,0.0496896),
	                  fixed2(-0.137043,0.0383603),
	                  fixed2(-0.130683,0.0383603),
	                  fixed2(-0.128894,0.0331926),
	                  fixed2(-0.128894,0.0308075),
	                  fixed2(-0.138435,-0.0141118),
	                  fixed2(-0.14082,-0.0256398),
	                  fixed2(-0.149168,-0.0316026),
	                  fixed2(-0.154931,-0.0316026),
	                  fixed2(-0.158509,-0.0316026),
	                  fixed2(-0.164869,-0.0314042),
	                  fixed2(-0.164869,-0.0160994),
	                  fixed2(-0.164869,0.00258385),
	                  fixed2(-0.153938,0.0383603));

	fixed2[6] seg=fixed2[](fixed2(0,1),
	                     fixed2(1,2),
	                     fixed2(20,21),
	                     fixed2(30,31),
	                     fixed2(31,0),
	                     fixed2(35,36));

	fixed4[13] c_bez=fixed4[](fixed4(2,3,4,5),
	                        fixed4(5,6,7,8),
	                        fixed4(8,9,10,11),
	                        fixed4(11,12,13,14),
	                        fixed4(14,15,16,17),
	                        fixed4(17,18,19,20),
	                        fixed4(21,22,23,24),
	                        fixed4(24,25,26,27),
	                        fixed4(27,28,29,30),
	                        fixed4(32,33,34,35),
	                        fixed4(36,37,38,39),
	                        fixed4(39,40,41,42),
	                        fixed4(42,43,44,32));

	if(all(lessThan(uv,fixed2(-0.0788071,0.0506833)+border)) && all(greaterThan(uv,fixed2(-0.194286,-0.0508821)-border))){
		for(int i=ZERO;i<6;i++){
			dis_sq=min(dis_sq,segment_dis_sq(uv,p[seg[i][0]],p[seg[i][1]]));
			num_its+=segment_int_test(uv,p[seg[i][0]],p[seg[i][1]]);
		}
		for(int i=ZERO;i<13;i++){
			dis_sq=min(dis_sq,cubic_bezier_dis_approx_sq(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]));
			num_its+=cubic_bezier_int_test(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]);
		}
	}

	fixed sgn=1.;

	if(num_its%2==1){
		sgn=-1.;
	}

	return sgn*dis_sq;
}

fixed path3_dis_sq(fixed2 uv){
	fixed dis_sq=1e38;

	int num_its=0;

	fixed2[46] p=fixed2[](fixed2(-0.0128197,0.085466),
	                  fixed2(-0.0225589,0.0397516),
	                  fixed2(-0.0225589,0.0405471),
	                  fixed2(-0.0225589,0.0463111),
	                  fixed2(-0.027329,0.0506837),
	                  fixed2(-0.0386581,0.0506837),
	                  fixed2(-0.0732421,0.0506837),
	                  fixed2(-0.089739,0.00795077),
	                  fixed2(-0.089739,-0.0188816),
	                  fixed2(-0.089739,-0.0425337),
	                  fixed2(-0.0768197,-0.0508816),
	                  fixed2(-0.0633042,-0.0508816),
	                  fixed2(-0.0491924,-0.0508816),
	                  fixed2(-0.0398508,-0.0417387),
	                  fixed2(-0.033888,-0.0325958),
	                  fixed2(-0.0322979,-0.0437263),
	                  fixed2(-0.0251426,-0.049689),
	                  fixed2(-0.0144097,-0.049689),
	                  fixed2(-0.00367677,-0.049689),
	                  fixed2(0.0142115,-0.0465089),
	                  fixed2(0.0255407,-0.0141113),
	                  fixed2(0.0171928,-0.0141113),
	                  fixed2(0.0142115,-0.0240493),
	                  fixed2(0.00884499,-0.0316021),
	                  fixed2(0.00109338,-0.0316021),
	                  fixed2(-0.00447185,-0.0316021),
	                  fixed2(-0.00705565,-0.0298133),
	                  fixed2(-0.00705565,-0.024248),
	                  fixed2(-0.00705565,-0.0224592),
	                  fixed2(-0.00685733,-0.0204716),
	                  fixed2(-0.00626124,-0.0178877),
	                  fixed2(0.016596,0.0894417),
	                  fixed2(-0.0340868,-0.0151056),
	                  fixed2(-0.0366707,-0.0260373),
	                  fixed2(-0.0448197,-0.0316026),
	                  fixed2(-0.0503849,-0.0316026),
	                  fixed2(-0.0539626,-0.0316026),
	                  fixed2(-0.0603228,-0.0314042),
	                  fixed2(-0.0603228,-0.0160994),
	                  fixed2(-0.0603228,0.00258385),
	                  fixed2(-0.0493911,0.0383603),
	                  fixed2(-0.0324967,0.0383603),
	                  fixed2(-0.0265339,0.0383603),
	                  fixed2(-0.0247451,0.0337889),
	                  fixed2(-0.0243477,0.0314038),
	                  fixed2(-0.0340868,-0.0141118));

	fixed2[7] seg=fixed2[](fixed2(0,1),
	                     fixed2(1,2),
	                     fixed2(20,21),
	                     fixed2(30,31),
	                     fixed2(31,0),
	                     fixed2(44,45),
	                     fixed2(45,32));

	fixed4[13] c_bez=fixed4[](fixed4(2,3,4,5),
	                        fixed4(5,6,7,8),
	                        fixed4(8,9,10,11),
	                        fixed4(11,12,13,14),
	                        fixed4(14,15,16,17),
	                        fixed4(17,18,19,20),
	                        fixed4(21,22,23,24),
	                        fixed4(24,25,26,27),
	                        fixed4(27,28,29,30),
	                        fixed4(32,33,34,35),
	                        fixed4(35,36,37,38),
	                        fixed4(38,39,40,41),
	                        fixed4(41,42,43,44));

	if(all(lessThan(uv,fixed2(0.0255407,0.0894417)+border)) && all(greaterThan(uv,fixed2(-0.089739,-0.0508816)-border))){
		for(int i=ZERO;i<7;i++){
			dis_sq=min(dis_sq,segment_dis_sq(uv,p[seg[i][0]],p[seg[i][1]]));
			num_its+=segment_int_test(uv,p[seg[i][0]],p[seg[i][1]]);
		}
		for(int i=ZERO;i<13;i++){
			dis_sq=min(dis_sq,cubic_bezier_dis_approx_sq(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]));
			num_its+=cubic_bezier_int_test(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]);
		}
	}

	fixed sgn=1.;

	if(num_its%2==1){
		sgn=-1.;
	}

	return sgn*dis_sq;
}

fixed path4_dis_sq(fixed2 uv){
	fixed dis_sq=1e38;

	int num_its=0;

	fixed2[34] p=fixed2[](fixed2(0.044025,-0.0174906),
	                  fixed2(0.044025,-0.0151056),
	                  fixed2(0.0442233,-0.0123229),
	                  fixed2(0.0444228,-0.00954037),
	                  fixed2(0.0682738,-0.00814909),
	                  fixed2(0.0901371,0.00954037),
	                  fixed2(0.0901371,0.0323976),
	                  fixed2(0.0901371,0.0423355),
	                  fixed2(0.0859633,0.0514784),
	                  fixed2(0.0682738,0.0514784),
	                  fixed2(0.0275284,0.0514784),
	                  fixed2(0.0146091,0.0035777),
	                  fixed2(0.0146091,-0.0192795),
	                  fixed2(0.0146091,-0.0417392),
	                  fixed2(0.0269321,-0.0508821),
	                  fixed2(0.0456153,-0.0508821),
	                  fixed2(0.0720502,-0.0508821),
	                  fixed2(0.0889446,-0.0323975),
	                  fixed2(0.100274,-0.0141118),
	                  fixed2(0.0935161,-0.0141118),
	                  fixed2(0.0835781,-0.025441),
	                  fixed2(0.0740377,-0.0341864),
	                  fixed2(0.0583358,-0.0341864),
	                  fixed2(0.0487955,-0.0341864),
	                  fixed2(0.0440252,-0.0310062),
	                  fixed2(0.0748326,0.0327951),
	                  fixed2(0.0748326,0.0162982),
	                  fixed2(0.0613171,0.000993797),
	                  fixed2(0.0460126,5.63409e-08),
	                  fixed2(0.0499878,0.0196771),
	                  fixed2(0.0597269,0.0409442),
	                  fixed2(0.0698636,0.0409442),
	                  fixed2(0.07364,0.0409442),
	                  fixed2(0.0748326,0.0377641));

	fixed2[1] seg=fixed2[](fixed2(18,19));

	fixed4[11] c_bez=fixed4[](fixed4(0,1,2,3),
	                        fixed4(3,4,5,6),
	                        fixed4(6,7,8,9),
	                        fixed4(9,10,11,12),
	                        fixed4(12,13,14,15),
	                        fixed4(15,16,17,18),
	                        fixed4(19,20,21,22),
	                        fixed4(22,23,24,0),
	                        fixed4(25,26,27,28),
	                        fixed4(28,29,30,31),
	                        fixed4(31,32,33,25));

	if(all(lessThan(uv,fixed2(0.100274,0.0514784)+border)) && all(greaterThan(uv,fixed2(0.0146091,-0.0508821)-border))){
		for(int i=ZERO;i<1;i++){
			dis_sq=min(dis_sq,segment_dis_sq(uv,p[seg[i][0]],p[seg[i][1]]));
			num_its+=segment_int_test(uv,p[seg[i][0]],p[seg[i][1]]);
		}
		for(int i=ZERO;i<11;i++){
			dis_sq=min(dis_sq,cubic_bezier_dis_approx_sq(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]));
			num_its+=cubic_bezier_int_test(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]);
		}
	}

	fixed sgn=1.;

	if(num_its%2==1){
		sgn=-1.;
	}

	return sgn*dis_sq;
}

fixed path5_dis_sq(fixed2 uv){
	fixed dis_sq=1e38;

	int num_its=0;

	fixed2[20] p=fixed2[](fixed2(0.107031,0.0496896),
	                  fixed2(0.0859628,-0.0496894),
	                  fixed2(0.114584,-0.0496894),
	                  fixed2(0.130485,0.0258385),
	                  fixed2(0.135454,0.03041),
	                  fixed2(0.139031,0.0333914),
	                  fixed2(0.144994,0.0333914),
	                  fixed2(0.150957,0.0333914),
	                  fixed2(0.145392,0.0202733),
	                  fixed2(0.156522,0.0202733),
	                  fixed2(0.166261,0.0202733),
	                  fixed2(0.170833,0.0278261),
	                  fixed2(0.170833,0.0347827),
	                  fixed2(0.170833,0.0423355),
	                  fixed2(0.166062,0.0496896),
	                  fixed2(0.157118,0.0496896),
	                  fixed2(0.147578,0.0496896),
	                  fixed2(0.140025,0.0433292),
	                  fixed2(0.133069,0.0373666),
	                  fixed2(0.135652,0.0496896));

	fixed2[5] seg=fixed2[](fixed2(0,1),
	                     fixed2(1,2),
	                     fixed2(2,3),
	                     fixed2(18,19),
	                     fixed2(19,0));

	fixed4[5] c_bez=fixed4[](fixed4(3,4,5,6),
	                       fixed4(6,7,8,9),
	                       fixed4(9,10,11,12),
	                       fixed4(12,13,14,15),
	                       fixed4(15,16,17,18));

	if(all(lessThan(uv,fixed2(0.170833,0.0496896)+border)) && all(greaterThan(uv,fixed2(0.0859628,-0.0496894)-border))){
		for(int i=ZERO;i<5;i++){
			dis_sq=min(dis_sq,segment_dis_sq(uv,p[seg[i][0]],p[seg[i][1]]));
			num_its+=segment_int_test(uv,p[seg[i][0]],p[seg[i][1]]);
		}
		for(int i=ZERO;i<5;i++){
			dis_sq=min(dis_sq,cubic_bezier_dis_approx_sq(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]));
			num_its+=cubic_bezier_int_test(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]);
		}
	}

	fixed sgn=1.;

	if(num_its%2==1){
		sgn=-1.;
	}

	return sgn*dis_sq;
}

fixed path6_dis_sq(fixed2 uv){
	fixed dis_sq=1e38;

	int num_its=0;

	fixed2[30] p=fixed2[](fixed2(0.187727,0.0771182),
	                  fixed2(0.181764,0.0496896),
	                  fixed2(0.175205,0.0496896),
	                  fixed2(0.173615,0.0417392),
	                  fixed2(0.180174,0.0417392),
	                  fixed2(0.168249,-0.0141118),
	                  fixed2(0.167255,-0.018882),
	                  fixed2(0.166658,-0.0232546),
	                  fixed2(0.166658,-0.0270311),
	                  fixed2(0.166658,-0.0437268),
	                  fixed2(0.176,-0.0508821),
	                  fixed2(0.187926,-0.0508821),
	                  fixed2(0.198659,-0.0508821),
	                  fixed2(0.218336,-0.0465093),
	                  fixed2(0.229665,-0.0141118),
	                  fixed2(0.221317,-0.0141118),
	                  fixed2(0.218336,-0.0240497),
	                  fixed2(0.21118,-0.0316026),
	                  fixed2(0.203429,-0.0316026),
	                  fixed2(0.197863,-0.0316026),
	                  fixed2(0.19528,-0.0298137),
	                  fixed2(0.19528,-0.0242485),
	                  fixed2(0.19528,-0.0224597),
	                  fixed2(0.195478,-0.0204721),
	                  fixed2(0.196074,-0.0178882),
	                  fixed2(0.208795,0.0417392),
	                  fixed2(0.22072,0.0417392),
	                  fixed2(0.22231,0.0496896),
	                  fixed2(0.210385,0.0496896),
	                  fixed2(0.217142,0.0810933));

	fixed2[12] seg=fixed2[](fixed2(0,1),
	                      fixed2(1,2),
	                      fixed2(2,3),
	                      fixed2(3,4),
	                      fixed2(4,5),
	                      fixed2(14,15),
	                      fixed2(24,25),
	                      fixed2(25,26),
	                      fixed2(26,27),
	                      fixed2(27,28),
	                      fixed2(28,29),
	                      fixed2(29,0));

	fixed4[6] c_bez=fixed4[](fixed4(5,6,7,8),
	                       fixed4(8,9,10,11),
	                       fixed4(11,12,13,14),
	                       fixed4(15,16,17,18),
	                       fixed4(18,19,20,21),
	                       fixed4(21,22,23,24));

	if(all(lessThan(uv,fixed2(0.229665,0.0810933)+border)) && all(greaterThan(uv,fixed2(0.166658,-0.0508821)-border))){
		for(int i=ZERO;i<12;i++){
			dis_sq=min(dis_sq,segment_dis_sq(uv,p[seg[i][0]],p[seg[i][1]]));
			num_its+=segment_int_test(uv,p[seg[i][0]],p[seg[i][1]]);
		}
		for(int i=ZERO;i<6;i++){
			dis_sq=min(dis_sq,cubic_bezier_dis_approx_sq(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]));
			num_its+=cubic_bezier_int_test(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]);
		}
	}

	fixed sgn=1.;

	if(num_its%2==1){
		sgn=-1.;
	}

	return sgn*dis_sq;
}

fixed path7_dis_sq(fixed2 uv){
	fixed dis_sq=1e38;

	int num_its=0;

	fixed2[40] p=fixed2[](fixed2(0.272994,0.0514784),
	                  fixed2(0.23205,0.0514784),
	                  fixed2(0.218534,0.00377647),
	                  fixed2(0.218534,-0.0190808),
	                  fixed2(0.218534,-0.0417392),
	                  fixed2(0.231851,-0.0504845),
	                  fixed2(0.250335,-0.0504845),
	                  fixed2(0.274783,-0.0504845),
	                  fixed2(0.294658,-0.0274286),
	                  fixed2(0.297839,0.00934171),
	                  fixed2(0.312348,0.0117267),
	                  fixed2(0.325466,0.0176895),
	                  fixed2(0.333019,0.0258385),
	                  fixed2(0.33123,0.031205),
	                  fixed2(0.322683,0.0252423),
	                  fixed2(0.309764,0.0192796),
	                  fixed2(0.300621,0.0192796),
	                  fixed2(0.300025,0.0192796),
	                  fixed2(0.29923,0.0192796),
	                  fixed2(0.298435,0.0196773),
	                  fixed2(0.298435,0.0405469),
	                  fixed2(0.290087,0.0514786),
	                  fixed2(0.258286,-0.0325963),
	                  fixed2(0.250733,-0.0325963),
	                  fixed2(0.248149,-0.029615),
	                  fixed2(0.248149,-0.0164969),
	                  fixed2(0.248149,0.00298139),
	                  fixed2(0.260472,0.0393542),
	                  fixed2(0.274584,0.0393542),
	                  fixed2(0.279752,0.0393542),
	                  fixed2(0.281739,0.0361739),
	                  fixed2(0.282137,0.0278261),
	                  fixed2(0.278559,0.0262361),
	                  fixed2(0.275975,0.0226584),
	                  fixed2(0.275975,0.0170932),
	                  fixed2(0.275975,0.013118),
	                  fixed2(0.277168,0.00973914),
	                  fixed2(0.281342,0.0087454),
	                  fixed2(0.278161,-0.0147081),
	                  fixed2(0.268025,-0.0325963));

	fixed2[1] seg=fixed2[](fixed2(12,13));

	fixed4[13] c_bez=fixed4[](fixed4(0,1,2,3),
	                        fixed4(3,4,5,6),
	                        fixed4(6,7,8,9),
	                        fixed4(9,10,11,12),
	                        fixed4(13,14,15,16),
	                        fixed4(16,17,18,19),
	                        fixed4(19,20,21,0),
	                        fixed4(22,23,24,25),
	                        fixed4(25,26,27,28),
	                        fixed4(28,29,30,31),
	                        fixed4(31,32,33,34),
	                        fixed4(34,35,36,37),
	                        fixed4(37,38,39,22));

	if(all(lessThan(uv,fixed2(0.333019,0.0514786)+border)) && all(greaterThan(uv,fixed2(0.218534,-0.0504845)-border))){
		for(int i=ZERO;i<1;i++){
			dis_sq=min(dis_sq,segment_dis_sq(uv,p[seg[i][0]],p[seg[i][1]]));
			num_its+=segment_int_test(uv,p[seg[i][0]],p[seg[i][1]]);
		}
		for(int i=ZERO;i<13;i++){
			dis_sq=min(dis_sq,cubic_bezier_dis_approx_sq(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]));
			num_its+=cubic_bezier_int_test(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]);
		}
	}

	fixed sgn=1.;

	if(num_its%2==1){
		sgn=-1.;
	}

	return sgn*dis_sq;
}

fixed path8_dis_sq(fixed2 uv){
	fixed dis_sq=1e38;

	int num_its=0;

	fixed2[44] p=fixed2[](fixed2(0.322087,0.0496896),
	                  fixed2(0.308571,-0.0141118),
	                  fixed2(0.307577,-0.018882),
	                  fixed2(0.306981,-0.0232546),
	                  fixed2(0.306981,-0.0270311),
	                  fixed2(0.306981,-0.0437268),
	                  fixed2(0.316323,-0.0508821),
	                  fixed2(0.328248,-0.0508821),
	                  fixed2(0.335006,-0.0508821),
	                  fixed2(0.34395,-0.0490932),
	                  fixed2(0.352497,-0.039354),
	                  fixed2(0.350509,-0.0480994),
	                  fixed2(0.331627,-0.0536646),
	                  fixed2(0.316124,-0.0594286),
	                  fixed2(0.316124,-0.0779132),
	                  fixed2(0.316124,-0.0908324),
	                  fixed2(0.327453,-0.0993791),
	                  fixed2(0.339578,-0.0993791),
	                  fixed2(0.352696,-0.0993791),
	                  fixed2(0.369789,-0.0940126),
	                  fixed2(0.375751,-0.0655902),
	                  fixed2(0.4,0.0496896),
	                  fixed2(0.37118,0.0496896),
	                  fixed2(0.357664,-0.0141118),
	                  fixed2(0.354683,-0.0240497),
	                  fixed2(0.349515,-0.0316026),
	                  fixed2(0.341764,-0.0316026),
	                  fixed2(0.337192,-0.0316026),
	                  fixed2(0.335801,-0.0274286),
	                  fixed2(0.335801,-0.0228571),
	                  fixed2(0.335801,-0.021267),
	                  fixed2(0.335999,-0.0194782),
	                  fixed2(0.336397,-0.0178882),
	                  fixed2(0.350708,0.0496896),
	                  fixed2(0.327056,-0.0751305),
	                  fixed2(0.327056,-0.0643976),
	                  fixed2(0.336596,-0.0586336),
	                  fixed2(0.349118,-0.0544597),
	                  fixed2(0.346733,-0.0661864),
	                  fixed2(0.344149,-0.0779132),
	                  fixed2(0.338981,-0.0816896),
	                  fixed2(0.335006,-0.0816896),
	                  fixed2(0.330633,-0.0816896),
	                  fixed2(0.327056,-0.0779132));

	fixed2[8] seg=fixed2[](fixed2(0,1),
	                     fixed2(10,11),
	                     fixed2(20,21),
	                     fixed2(21,22),
	                     fixed2(22,23),
	                     fixed2(32,33),
	                     fixed2(33,0),
	                     fixed2(37,38));

	fixed4[12] c_bez=fixed4[](fixed4(1,2,3,4),
	                        fixed4(4,5,6,7),
	                        fixed4(7,8,9,10),
	                        fixed4(11,12,13,14),
	                        fixed4(14,15,16,17),
	                        fixed4(17,18,19,20),
	                        fixed4(23,24,25,26),
	                        fixed4(26,27,28,29),
	                        fixed4(29,30,31,32),
	                        fixed4(34,35,36,37),
	                        fixed4(38,39,40,41),
	                        fixed4(41,42,43,34));

	if(all(lessThan(uv,fixed2(0.4,0.0496896)+border)) && all(greaterThan(uv,fixed2(0.306981,-0.0993791)-border))){
		for(int i=ZERO;i<8;i++){
			dis_sq=min(dis_sq,segment_dis_sq(uv,p[seg[i][0]],p[seg[i][1]]));
			num_its+=segment_int_test(uv,p[seg[i][0]],p[seg[i][1]]);
		}
		for(int i=ZERO;i<12;i++){
			dis_sq=min(dis_sq,cubic_bezier_dis_approx_sq(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]));
			num_its+=cubic_bezier_int_test(uv,p[c_bez[i][0]],p[c_bez[i][1]],p[c_bez[i][2]],p[c_bez[i][3]]);
		}
	}

	fixed sgn=1.;

	if(num_its%2==1){
		sgn=-1.;
	}

	return sgn*dis_sq;
}

            fixed4 frag (v2f i) : SV_Target
            {
            border=2./iResolution.x;
        
            fixed2 uv=fragCoord.xy/iResolution.xy;
            uv-=.5;
            uv.y*=iResolution.y/iResolution.x;
        
            fixed2 mouse=fixed2(0);
        
            if(iMouse.x>0.0){
                mouse = iMouse.xy / iResolution.y;
                mouse.x -= .5 * iResolution.x / iResolution.y;
                mouse.y -= .75;
            }
            
            const fixed pi=3.14159265358979;
        
            fixed t0=smoothstep(0.,5.,iTime);
            fixed t1=t0*6.*pi;
        
            mat2 rot=mat2(cos(t1),sin(t1),-sin(t1),cos(t1));
        
            border*=exp(4.*mouse.y)*exp(1.-1.*t0);
            uv*=exp(4.*mouse.y)*exp(1.-1.*t0);
            uv*=rot;
        
            uv.x+=mouse.x;
        
            fixed dis_sq=1e38;
        
            if(all(lessThan(uv,fixed2(0.4,0.0993791)+border)) && all(greaterThan(uv,fixed2(-0.4,-0.0993791)-border))){
                dis_sq=min(dis_sq,path0_dis_sq(uv));
                dis_sq=min(dis_sq,path1_dis_sq(uv));
                dis_sq=min(dis_sq,path2_dis_sq(uv));
                dis_sq=min(dis_sq,path3_dis_sq(uv));
                dis_sq=min(dis_sq,path4_dis_sq(uv));
                dis_sq=min(dis_sq,path5_dis_sq(uv));
                dis_sq=min(dis_sq,path6_dis_sq(uv));
                dis_sq=min(dis_sq,path7_dis_sq(uv));
                dis_sq=min(dis_sq,path8_dis_sq(uv));
            }
        
            fixed dis=sign(dis_sq)*sqrt(abs(dis_sq));
        
            return fixed4(smoothstep(0., border, dis));
                    }
                    ENDCG
        }
    }
}

from shaderman.

araya avatar araya commented on May 13, 2024

so thx for you convert the shader.It show error: Shader is not supported on this GPU (none of subshaders/fallbacks are suitable) in unity.

from shaderman.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.