A fellow developer in a Greek Unity 3d facebook group showed this video and asked how to recreate it in unity After some time, Renaldas Zioma showed up and explained the principle. I made a small project to demonstrate the technique, available here https://www.dropbox.com/s/77udpj0l5wk65ap/location based opacity.7z?dl=0 And a screenshot : I wish to thanks Renaldas Zioma for supporting our local community. -Ippokratis
Really cool effect, I'm trying to think of a place for it to be useful but got nothing, how have people been using this? thx for sharing
A shield for example, or a teleportation device, or a fireball which constantly expands and burns everything in it....
Nice! I was just looking for this exact thing. I'm making a conical holographic projection in which things are moving in and out of the projected cone (and of course we only want to see what is within the cone).
Sorry for the slight necro-bump, but does anyone know how I could reverse the effect? So everything BUT the sphere area is visible? And... How hard would it be to change the area form a sphere to something else? Cylindwer, cube, mabye even mesh? I know barely anythign about writing shaders, and I can't find anything like this; that isn't outdated :/
This is so awesome! I would also be interested to see if it could work with different shapes but its exciting to know the effect can be created in unity regardless. The dropbox folder with the example files is empty though so I cant see how the effect was achieved. Would it be possible to make these example files available again? I would love to dive in and use this feature in a gameplay prototype.
Hi, thanks for letting me know that the link was down. I updated the link, it works now. Kind regards
This is a modification of standard Surface Shader to achieve that. Code (CSharp): Shader "Test/ClipSphereShader" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _Glossiness ("Smoothness", Range(0,1)) = 0.5 _Metallic ("Metallic", Range(0,1)) = 0.0 _ClippingCentre ("Clipping Centre", Vector) = (0,0,0,0) _radius ("radius", float) = 1.5 } SubShader { Tags { "RenderType"="Opaque" "Queue" = "Transparent"} LOD 200 Cull off CGPROGRAM // Physically based Standard lighting model, and enable shadows on all light types #pragma surface surf Standard fullforwardshadows // Use shader model 3.0 target, to get nicer looking lighting #pragma target 3.0 sampler2D _MainTex; struct Input { float2 uv_MainTex; float3 worldPos; }; half _Glossiness; half _Metallic; fixed4 _Color; float _radius; uniform float3 _ClippingCentre; // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader. // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing. // #pragma instancing_options assumeuniformscaling UNITY_INSTANCING_CBUFFER_START(Props) // put more per-instance properties here UNITY_INSTANCING_CBUFFER_END void surf (Input IN, inout SurfaceOutputStandard o) { if(sign(_radius)*(dot((IN.worldPos - _ClippingCentre),(IN.worldPos - _ClippingCentre)) - _radius*_radius)>0) discard; //sign(_radius) : negative to clip the outside of the sphere // Albedo comes from a texture tinted by color fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; o.Albedo = c.rgb; // Metallic and smoothness come from slider variables o.Metallic = _Metallic; o.Smoothness = _Glossiness; o.Alpha = c.a; } ENDCG } FallBack "Diffuse" } Then manipulate with Clipping Centre and radius values on the materials. This way you can define various geometries for the discard directive. Spheres, tubes, boxes and other primitive solids, single and multiple can be achieved.