- Home /
Question by
OmegaNemesis28 · Apr 26, 2014 at 07:17 AM ·
shaderalpha
Clamp cone shape from shader alpha
In the following transparent shader, I'm subtracting out shapes so you can "see through the holes" of the material.
However, I want to be able to 'slice out' a cone shape from the material. Currently, I only have circular holes.
void surfaceRemoval (Input IN, inout SurfaceOutput o) {
fixed4 baseColor = tex2D(_MainTex, IN.uv_MainTex) * _Color;
float alpha = (1.0 - (baseColor.a + circle(center, IN.location, radius, maxradius)
+ circle(center, IN.location, radius, maxradius)
+ cone(start, IN.location, radius, maxradius, height))
);
o.Albedo = baseColor.rgb;
o.Alpha = alpha;
}
//return 0 if (pos - nearVertex) > _FogRadius
float circle(float4 pos, float2 nearVertex, float radius, float radiusMax) {
float removal = clamp(radius - length(pos.xz - nearVertex.xy), 0.0, radius);
return (1.0/radiusMax)*atten/removal;
}
float cone(float4 pos, float2 nearVertex, float radius, float radiusMax, float height)
{
float lateralArea = 3.141592654 * radius * sqrt(radius*2 + height*2);
float removal= clamp(lateralArea - length(pos.xz - nearVertex.xy), 0.0, lateralArea);
return removal;
}
The circles work great! But the cone still remains a circle. It definitely has to do with my clamp formula, lateralArea might be right but its still remaining a circle. If I change it even slightly, it just subtracts the whole material and makes it completely invisible.
I'm a total noob with shaders so if anyone can help that would really mean alot!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613143617im_/https://answers.unity.com/themes/thub/images/avi.jpg)