- Home /
Projector is showing through other objects
Hey guys, so I've been working on my main character and he's got a hood. So I thought, "Hey, wouldn't it be cool if the hood put a shadow over his face?!". I immediately thought of the Projector and made a pretty good looking shadow on his face:
The projector is ignoring the hood so it just shows up on the face.. but, there is a problem: the shadow kinda bleeds/shows through the hood. Here's what I mean:
I've tried so many different things, but nothing's preventing the shadow from 'bleeding' through! Any ideas?
Answer by Glacier Games · Mar 26, 2013 at 07:01 PM
Haha, solved it. Weird solution, but I found a projector shader that doesn't do it.
Shader "Cg projector shader for drop shadows" {
Properties {
_ShadowTex ("Projected Image", 2D) = "white" {}
}
SubShader {
Pass {
Blend Zero OneMinusSrcAlpha // attenuate color in framebuffer
// by 1 minus alpha of _ShadowTex
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// User-specified properties
uniform sampler2D _ShadowTex;
// Projector-specific uniforms
uniform float4x4 _Projector; // transformation matrix
// from object space to projector space
struct vertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float4 posProj : TEXCOORD0;
// position in projector space
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.posProj = mul(_Projector, input.vertex);
output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
return output;
}
float4 frag(vertexOutput input) : COLOR
{
if (input.posProj.w > 0.0) // in front of projector?
{
return tex2D(_ShadowTex ,
float2(input.posProj) / input.posProj.w);
// alternatively: return = tex2Dproj(
// _ShadowTex, float3(input.posProj));
}
else // behind projector
{
return float4(0.0);
}
}
ENDCG
}
}
// The definition of a fallback shader should be commented out
// during development:
// Fallback "Projector/Light"
}
Answer by Quaker_SDR · Dec 22, 2014 at 06:36 AM
Hi,
I have this problem, Can you you help me out ??
I tried using your shader, But it giving a transparent image as output.
Answer by mubashar437 · Dec 22, 2014 at 07:45 AM
to quaker-sdr
http://docs.unity3d.com/Manual/class-Projector.html
maybe second hint will help..........
Answer by HonoraryBob · Feb 26, 2017 at 01:29 AM
@Glacier Games : I also couldn't get this to work - it goes through objects and reverses the pattern. I'm using Unity 5.0.1
Answer by diabuli · Mar 30, 2018 at 09:08 AM
Amazing!!, can you send me the projector prefab with the shader,
Your answer
Follow this Question
Related Questions
how to make a shader that only shows the shadow while the rest becomes completly transparent? 5 Answers
How to make a blob shadow project from a fixed angle as the object rotates? 2 Answers
Blob Shadows - Reversing Shadow Effect? 2 Answers
how to prevent stretched vertical shadow in blob shadow which projected by Projector of Unity 0 Answers
How to use a shadow projector 1 Answer