Hello,
I want to achieve the same shadowing as seen in the picture without using lights at all.
Is it even possible?
at the moment I have a shader that applies color only on faces that are a dot of center vector and normal vector at the distance from the radius, lerping to full transparent as seen in the second picture, but I can’t figure out how to make the shader ignore all verts that are"hidden" behind other verts of other objects.
edit.: I am using ortographic projector pointing downwards to apply material with the shader.
I’m thankful for any ideas on how_to.
the shader looks like this:
Shader "Custom/CircularScanning" {
Properties {
_ScannerPosition ("Scanner Position", vector) = (0, 0, 0)
_Color ("Color Tint", Color) = (1, 1, 1, 1)
_Radius ("Real Time Radius Value", float) = 0
_ScanDistance ("Scan Distance", float) = 15
}
SubShader {
Pass {
Tags {
"RenderType"="Opaque"
}
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _ScannerPosition;
float4 _Color;
float _Radius;
float _ScanDistance;
struct v2f {
float4 pos : SV_POSITION;
float3 worldPos : TEXCOORD1;
float3 normal : NORMAL;
};
v2f vert(appdata_base v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
o.normal = v.normal;
return o;
}
fixed4 frag(v2f i) : COLOR {
float distFromCenter = distance(_ScannerPosition, i.worldPos);
float3 toCenter = _ScannerPosition - i.worldPos;
half dir = dot (normalize (toCenter), i.normal);
dir = dir > 0 ? 1 : dir;
float4 tintColor = _Color * dir;
if (_Radius > 0 && _Radius <= _ScanDistance){ // scanner check - we're scanning; _Radius is more than 0
if (distFromCenter >= _Radius - 10 && distFromCenter < _Radius){ // Inside the scanner circle: outer edge (fading into tintColor)
tintColor = lerp(float4(0, 0, 0, 0), tintColor, (distance (i.worldPos, _ScannerPosition)-(_Radius-10)) / 10);
}
else if (distFromCenter < _Radius - 10){ // Inside the scanner circle: inner circle
tintColor = float4(0, 0, 0, 0);
}
else if (distFromCenter > _Radius){ // Outside the scanner circle
tintColor = float4(0, 0, 0, 0);
}
}
else if (_Radius > _ScanDistance || _Radius <= 0){ // scanner check - If we're not scanning, make everything fully transparent
return float4(0, 0, 0, 0);
}
return tintColor;
}
ENDCG
}
}
FallBack "Diffuse"
}
I am not very good with shaders, if you see some performance hammers in the code please feel free to point them out.