Hide part of an object behind invisible oject.
I dont know how to explain it, so need something like this:
Answer by bugmagnet · Sep 24, 2016 at 06:03 PM
Here is one solution:
The invisible object should need a custom shader (it would be very simple) that needs to be 'additive' while being black and at the same time write to the zbuffer. Something like this (untested):
Properties
{
_Color ("Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
Lighting Off
Blend SrcAlpha One
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
fixed4 _Color;
v2f vert (appdata v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
return _Color;
}
ENDCG
}
Then just make sure you set the color to black, and it should do what you want. Note that this new shader will block ALL things, and will likely only draw the skybox where it is seen.
Your shader does the thing to cut everything to the skybox. But i need to cut only the '$$anonymous$$y object'. $$anonymous$$y goal is to make circle cuts in Windshield rain texture, to make wipers effect, so i cant deal with skybox(
I found a shader, thad does something, but it's artifacting all the time ;(
Shader "Custom/Subtractive" {
SubShader {
Tags { "Queue" = "Background" }
Pass
{
Blend Zero One
Lighting On
ZWrite On
$$anonymous$$aterial
{
Diffuse (0,0,0,0)
}
}
}
}
I'm not good at shader writing, but i think this effect could be done by using second camera to ignore the '$$anonymous$$y object'. But my knoweledge in this topic are low :(
Shader "Subtractive"
{
SubShader
{
Pass
{
Blend Zero One
Lighting On
ZWrite On
$$anonymous$$aterial
{
Diffuse (0,0,0,0)
}
}
}
}
This is almost what i want, but it flikkering and makes artefacts of the skybox( Pls help
Your answer
Follow this Question
Related Questions
struggling with Playing card game in unity 2 Answers
how to make terrain in 2D game? 0 Answers
Texture Strange Behaviour 0 Answers
Apparent Memory Leak during texture change 0 Answers
how to get a model with one material and one textuer 0 Answers