Shader "ShaderMan/MyShader"
{
Properties{
//Properties
}
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
Pass
{
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct VertexInput {
fixed4 vertex : POSITION;
fixed2 uv:TEXCOORD0;
fixed4 tangent : TANGENT;
fixed3 normal : NORMAL;
//VertexInput
};
struct VertexOutput {
fixed4 pos : SV_POSITION;
fixed2 uv:TEXCOORD0;
//VertexOutput
};
//Variables
//Sci-fi radar based on the work of gmunk for Oblivion
//http://work.gmunk.com/OBLIVION-GFX
#define SMOOTH(r,R) (1.0-smoothstep(R-1.0,R+1.0, r))
#define RANGE(a,b,x) ( step(a,x)*(1.0-step(b,x)) )
#define RS(a,b,x) ( smoothstep(a-1.0,a+1.0,x)*(1.0-smoothstep(b-1.0,b+1.0,x)) )
#define M_PI 3.1415926535897932384626433832795
#define blue1 fixed3(0.74,0.95,1.00)
#define blue2 fixed3(0.87,0.98,1.00)
#define blue3 fixed3(0.35,0.76,0.83)
#define blue4 fixed3(0.953,0.969,0.89)
#define red fixed3(1.00,0.38,0.227)
#define MOV(a,b,c,d,t) (fixed2(a*cos(t)+b*cos(0.1*(t)), c*sin(t)+d*cos(0.1*(t))))
fixed movingLine(fixed2 uv, fixed2 center, fixed radius)
{
//angle of the line
fixed theta0 = 90.0 * _Time.y;
fixed2 d = uv - center;
fixed r = sqrt( dot( d, d ) );
if(r<radius)
{
//compute the distance to the line theta=theta0
fixed2 p = radius*fixed2(cos(theta0*M_PI/180.0),
-sin(theta0*M_PI/180.0));
fixed l = length( d - p*clamp( dot(d,p)/dot(p,p), 0.0, 1.0) );
d = normalize(d);
//compute gradient based on angle difference to theta0
fixed theta = fmod(180.0*atan2(d.x,d.y)/M_PI+theta0,360.0);
fixed gradient = clamp(1.0-theta/90.0,0.0,1.0);
return SMOOTH(l,1.0)+0.5*gradient;
}
else return 0.0;
}
fixed circle(fixed2 uv, fixed2 center, fixed radius, fixed width)
{
fixed r = length(uv - center);
return SMOOTH(r-width/2.0,radius)-SMOOTH(r+width/2.0,radius);
}
fixed circle2(fixed2 uv, fixed2 center, fixed radius, fixed width, fixed opening)
{
fixed2 d = uv - center;
fixed r = sqrt( dot( d, d ) );
d = normalize(d);
if( abs(d.y) > opening )
return SMOOTH(r-width/2.0,radius)-SMOOTH(r+width/2.0,radius);
else
return 0.0;
}
fixed circle3(fixed2 uv, fixed2 center, fixed radius, fixed width)
{
fixed2 d = uv - center;
fixed r = sqrt( dot( d, d ) );
d = normalize(d);
fixed theta = 180.0*(atan2(d.x,d.y)/M_PI);
return smoothstep(2.0, 2.1, abs(fmod(theta+2.0,45.0)-2.0)) *
lerp( 0.5, 1.0, step(45.0, abs(fmod(theta, 180.0)-90.0)) ) *
(SMOOTH(r-width/2.0,radius)-SMOOTH(r+width/2.0,radius));
}
fixed triangles(fixed2 uv, fixed2 center, fixed radius)
{
fixed2 d = uv - center;
return RS(-8.0, 0.0, d.x-radius) * (1.0-smoothstep( 7.0+d.x-radius,9.0+d.x-radius, abs(d.y)))
+ RS( 0.0, 8.0, d.x+radius) * (1.0-smoothstep( 7.0-d.x-radius,9.0-d.x-radius, abs(d.y)))
+ RS(-8.0, 0.0, d.y-radius) * (1.0-smoothstep( 7.0+d.y-radius,9.0+d.y-radius, abs(d.x)))
+ RS( 0.0, 8.0, d.y+radius) * (1.0-smoothstep( 7.0-d.y-radius,9.0-d.y-radius, abs(d.x)));
}
fixed _cross(fixed2 uv, fixed2 center, fixed radius)
{
fixed2 d = uv - center;
int x = int(d.x);
int y = int(d.y);
fixed r = sqrt( dot( d, d ) );
if( (r<radius) && ( (x==y) || (x==-y) ) )
return 1.0;
else return 0.0;
}
fixed dots(fixed2 uv, fixed2 center, fixed radius)
{
fixed2 d = uv - center;
fixed r = sqrt( dot( d, d ) );
if( r <= 2.5 )
return 1.0;
if( ( r<= radius) && ( (abs(d.y+0.5)<=1.0) && ( fmod(d.x+1.0, 50.0) < 2.0 ) ) )
return 1.0;
else if ( (abs(d.y+0.5)<=1.0) && ( r >= 50.0 ) && ( r < 115.0 ) )
return 0.5;
else
return 0.0;
}
fixed bip1(fixed2 uv, fixed2 center)
{
return SMOOTH(length(uv - center),3.0);
}
fixed bip2(fixed2 uv, fixed2 center)
{
fixed r = length(uv - center);
fixed R = 8.0+fmod(87.0*_Time.y, 80.0);
return (0.5-0.5*cos(30.0*_Time.y)) * SMOOTH(r,5.0)
+ SMOOTH(6.0,r)-SMOOTH(8.0,r)
+ smoothstep(max(8.0,R-20.0),R,r)-SMOOTH(R,r);
}
VertexOutput vert (VertexInput v)
{
VertexOutput o;
o.pos = UnityObjectToClipPos (v.vertex);
o.uv = v.uv;
//VertexFactory
return o;
}
fixed4 frag(VertexOutput i) : SV_Target
{
fixed3 finalColor;
fixed2 uv = i.uv;
fixed2 c =1/2.0;
finalColor = fixed3( 0.3*_cross(uv, c, 240.0) );
finalColor += ( circle(uv, c, 100.0, 1.0)
+ circle(uv, c, 165.0, 1.0) ) * blue1;
finalColor += (circle(uv, c, 240.0, 2.0) );//+ dots(uv,c,240.0)) * blue4;
finalColor += circle3(uv, c, 313.0, 4.0) * blue1;
finalColor += triangles(uv, c, 315.0 + 30.0*sin(_Time.y)) * blue2;
finalColor += movingLine(uv, c, 240.0) * blue3;
finalColor += circle(uv, c, 10.0, 1.0) * blue3;
finalColor += 0.7 * circle2(uv, c, 262.0, 1.0, 0.5+0.2*cos(_Time.y)) * blue3;
if( length(uv-c) < 240.0 )
{
//animate some bips with random movements
fixed2 p = 130.0*MOV(1.3,1.0,1.0,1.4,3.0+0.1*_Time.y);
finalColor += bip1(uv, c+p) * fixed3(1,1,1);
p = 130.0*MOV(0.9,-1.1,1.7,0.8,-2.0+sin(0.1*_Time.y)+0.15*_Time.y);
finalColor += bip1(uv, c+p) * fixed3(1,1,1);
p = 50.0*MOV(1.54,1.7,1.37,1.8,sin(0.1*_Time.y+7.0)+0.2*_Time.y);
finalColor += bip2(uv,c+p) * red;
}
ENDCG
}
}
}
有无懂shader的?帮看一下这个报错怎么解决/抱拳
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 什么都不会的私小教 2022-10-13 17:58关注
数据格式错了,fixed2 是要二维的,你这个fixed2 c = 1/ 2.0; 改成 fixed c = 1/ 2.0
解决 无用评论 打赏 举报
悬赏问题
- ¥15 程序不包含适用于入口点的静态Main方法
- ¥15 素材场景中光线烘焙后灯光失效
- ¥15 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记