Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Shader "Light2D/Light 9 Points" {
Properties {
_MainTex ("Light texture", 2D) = "white" {}
_ObstacleMul ("Obstacle Mul", Float) = 500
_EmissionColorMul ("Emission color mul", Float) = 1
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 100
Blend OneMinusDstColor One
Cull Off
ZWrite Off
Lighting Off
Pass {
CGPROGRAM
// Upgrade NOTE: excluded shader from DX11 and Xbox360; has structs without semantics (struct v2f members sp)
#pragma exclude_renderers d3d11 xbox360
#pragma vertex vert
#pragma fragment frag
#pragma glsl_no_auto_normalization
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
fixed4 color : COLOR0;
fixed4 normal : TEXCOORD1;
};
struct v2f {
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
fixed4 color : COLOR0;
half4 scrPos : TEXCOORD2;
half4 scrPosCenter : TEXCOORD1;
};
sampler2D _ObstacleTex;
sampler2D _MainTex;
half _ObstacleMul;
half _EmissionColorMul;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = v.texcoord;
o.scrPos = ComputeScreenPos(o.vertex);
o.scrPosCenter = v.normal;
o.color = v.color;
return o;
}
fixed3 maximize(fixed3 vec){
vec = max(vec, fixed3(0.01, 0.01, 0.01));
return vec/max(vec.x, max(vec.y, vec.z));
}
half sum(half3 vec){
return vec.x + vec.y + vec.z;
}
fixed4 frag (v2f i) : COLOR
{
fixed2 thisPos = (i.scrPos.xy/i.scrPos.w);
fixed2 centerPos = i.scrPosCenter;
const fixed sub = 0.111111111111;
fixed m = _ObstacleMul*length((thisPos - centerPos)*fixed2(_ScreenParams.x/_ScreenParams.y, 1)*sub);
fixed4 tex = tex2D(_MainTex, i.texcoord);
clip(tex.a - 0.005);
fixed4 col = i.color*fixed4(tex.rgb, 1)*tex.a;
fixed pos = 1;
pos -= sub; col *= saturate(1 - tex2D(_ObstacleTex, lerp(centerPos, thisPos, pos))*m);
pos -= sub; col *= saturate(1 - tex2D(_ObstacleTex, lerp(centerPos, thisPos, pos))*m);
pos -= sub; col *= saturate(1 - tex2D(_ObstacleTex, lerp(centerPos, thisPos, pos))*m);
pos -= sub; col *= saturate(1 - tex2D(_ObstacleTex, lerp(centerPos, thisPos, pos))*m);
pos -= sub; col *= saturate(1 - tex2D(_ObstacleTex, lerp(centerPos, thisPos, pos))*m);
pos -= sub; col *= saturate(1 - tex2D(_ObstacleTex, lerp(centerPos, thisPos, pos))*m);
pos -= sub; col *= saturate(1 - tex2D(_ObstacleTex, lerp(centerPos, thisPos, pos))*m);
pos -= sub; col *= saturate(1 - tex2D(_ObstacleTex, lerp(centerPos, thisPos, pos))*m);
pos -= sub; col *= saturate(1 - tex2D(_ObstacleTex, lerp(centerPos, thisPos, pos))*m);
col.rgb *= _EmissionColorMul;
return col;
}
ENDCG
}
}
}
2D система освещения для Unity3D, работающая на GPU