Oct
25
2012

Radar Shader

Converted this shader to Unity. (again didnt came out the same as the original..but almost)

Webplayer:
http://unitycoder.com/upload/demos/radar_shader_unity/

Shader Source:


// original shader: http://glsl.heroku.com/e#4190.1
// converted to unity - mgear - http://unitycoder.com/blog
Shader "mShaders/Radar1"
{
Properties {
tex ("Texture (RGB)", 2D) = "white" {}
resolution("resolution", Vector) = (1,1,0,0)
//mouse("mouse", Vector) = (1,1,0,0)
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma target 3.0
#pragma surface surf Lambert
#define GRID_SIZE 32
#define PI 3.1416
uniform float2 resolution;
//uniform float2 mouse;
//uniform float time;
//uniform sampler2D tex;
struct Input {
float2 uvtex;
};
float3 color(float d) {
return d * float3(0, 1, 0);
}
int mod(int a, int b) {
return a - ((a / b) * b);
}
void surf (Input IN, inout SurfaceOutput o)
{
float time = _Time.x*10;
float2 p = (-1.0 + 2.0 * ((IN.uvtex.xy) / resolution.xy));
//p -= (2.0 * mouse.xy) - vec2(1.0);
p.x *= (resolution.x / resolution.y);
float2 uv;
float a = (atan2(p.y,p.x) + time);
float r = sqrt(dot(p,p));
uv.x = 0.1/r;
uv.y = a/(PI);
float len = dot(p,p);
float3 col = color(pow(frac(uv.y / -2.0), 15.0));
if (len > 0.7) col = float3(0.8,0.8,0.8);
if (len > 0.73) col = float3(0,0,0);

bool grid_x = mod(int(IN.uvtex.x) - int(resolution.x / 2.0), GRID_SIZE) == 0;
bool grid_y = mod(int(IN.uvtex.y) - int(resolution.y / 2.0), GRID_SIZE) == 0;

if (len < 0.7)
{
if (grid_x || grid_y)
col += color(0.1);

if (grid_x && grid_y)
col += color(1.0);
}
half4 c = float4(col, 1.0);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}


Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.