Transparent plane with RenderTexture - no show shadows?
Hey Hey, i know there are some more threads about this all over main portals but none really matched my needs...
I am trying to stream a cameras view, which sees objects and shadows but not the surface the shadow receives, to a RenderTexture. To get a shadow on a transparent surface, i found several working shaders like this (https://www.youtube.com/watch?v=M6zFKfF4gOE)
The RenderTexture is supposed to be on a transparent surface as well so it only shows the objects and their shadows. The Problem is, that the receiving plane doesn't show the shadow and i can't see why...
Does anybody have any suggestions?
Answer by neosca · Jul 11, 2017 at 11:47 AM
I use this shader to create a material which only shows shadows and apply transparency to rest of the area. Create a new shader and copy the below code and compile. Than change the material from Standard to FX>MatteShadow
Shader "FX/Matte Shadow" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader {
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 200
Blend Zero SrcColor
CGPROGRAM
#pragma surface surf ShadowOnly alphatest:_Cutoff
fixed4 _Color;
struct Input {
float2 uv_MainTex;
};
inline fixed4 LightingShadowOnly (SurfaceOutput s, fixed3 lightDir, fixed atten)
{
fixed4 c;
c.rgb = s.Albedo*atten;
c.a = s.Alpha;
return c;
}
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = _Color;
o.Albedo = c.rgb;
o.Alpha = 1;
}
ENDCG
}
Fallback "Transparent/Cutout/VertexLit"
}
Answer by ivank · Aug 24, 2017 at 04:32 PM
@maechtigerhoros @neosca Hello, do I understand correctly that the subject of the question (and answer) is something in 3D graphics commonly called as matte shadow?
I can reccomend the free shader from Unity guy Keigiro Takahashi, which allows to adjust also the color and transparency of the shadows: https://github.com/keijiro/ShadowDrawer
It has however the same drawback as the one provided by Neosca - it does not work against skyboxes - only against the solid color or another object (plane - floor, wall). Unfortunately it seems to be caused by Unity design itself :-(
Hope it helps a little
Answer by dkollmann · Mar 08, 2018 at 03:29 PM
Does this still work with the current Unity version? I have trouble to get it to work as expected. The shadows are visible but so is the plane.
Some feedback would be gret since I am unsure if the problem is with my set up or in general with the shader.
Thanks, Daniel
Your answer
![](https://koobas.hobune.stream/wayback/20220612125942im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Something wrong with the cut out feature of the standard shader? 0 Answers
RenderTexture Scope Effect 0 Answers
FBX Model looks wrong after scaling 0 Answers
How to make dynamic ripple with shader? 0 Answers
How to make 2D Sprite Shadow? 0 Answers