I added a simple cube to the scene. Now, I want, that the bottom of the cube is transparent. How can I make this with a shader?
I tried that with mesh colors. It’s working, but it’s not like a shader.
Mesh.colors
I added a simple cube to the scene. Now, I want, that the bottom of the cube is transparent. How can I make this with a shader?
I tried that with mesh colors. It’s working, but it’s not like a shader.
Mesh.colors
You could add a simple clip to the standard shader to get rid of one side, if you want to see the ‘inside’ sides of the cube that remains, you will also need to turn off culling:
Shader "Custom/TransparentSide" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB) Trans (A)", 2D) = "white" {}
_Side ("Side Normal", Vector) = (0,-1,0,0)
_Tolerance ("Tolerance", Range(0.0001, 0.1)) = 0.025
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
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 worldNormal;
};
half _Glossiness;
float _Tolerance;
fixed3 _Side;
half _Metallic;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o) {
float mask = dot(IN.worldNormal, normalize(_Side.xyz));
clip(1 - _Tolerance - mask);
// 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"
}
Here, ‘Side Normal’ is the normal direction of the side you want to cut, i.e. the bottom side of a cube would be x=0, y=-1, z=0. note that the w component is completely disregarded, but no 3 component vector exists as a property type (as far as I know). ‘Tolreance’ adjusts how strict the cutting is, “should sides almost facing this direction also be cut”, the range of values it allows is somewhat arbitrary, though setting it to 0 may not work due to floating point errors.