Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shadow maps - Casting shadows on transparent plane #1791

Closed
libe opened this issue Apr 23, 2012 · 28 comments
Closed

Shadow maps - Casting shadows on transparent plane #1791

libe opened this issue Apr 23, 2012 · 28 comments
Labels

Comments

@libe
Copy link

libe commented Apr 23, 2012

Hi,

I need to cast shadows on a transparent plane in order to get only the shadow shown and not the material applied to the plane (I want it fully transparent). Is this possible in three.js? I am using THREE.SpotLight as light source.

As a workaround solution I think I could apply a fully transparent texture map as a material and see if works as expected but was wondering if I could manage to get this effect just tweaking standard material properties.

Thanks

@libe
Copy link
Author

libe commented Apr 23, 2012

OK tried workaround did not work as I cannot get any shadow casted on a transparent texture mapped plane...

@mrdoob
Copy link
Owner

mrdoob commented Apr 26, 2012

I don't think that's possible.

@alteredq
Copy link
Contributor

I'm not sure I understand the question but shadows should get casted on transparent materials.

What shouldn't work is light shining through the transparent materials. That is, everything is either full opaque or fully transparent for shadows, there no in between, independent of material transparency.

See also discussion in #1509

@mrdoob
Copy link
Owner

mrdoob commented Apr 26, 2012

What shouldn't work is light shining through the transparent materials. That is, everything is either full opaque or fully transparent for shadows, there no in between, independent of material transparency.

Yeah, I think that's what he means.

@mrdoob mrdoob closed this as completed Apr 26, 2012
@skrat
Copy link

skrat commented Oct 20, 2012

For reference, if anyone needs it http://pastie.org/5088640

@etx
Copy link

etx commented Oct 26, 2014

@skrat Thanks a million for that shader. Works perfectly for a shadow catcher!

@mrdoob
Copy link
Owner

mrdoob commented Oct 27, 2014

@etx uh, what does that shader do? :U

@etx
Copy link

etx commented Oct 27, 2014

It just gives me the shadow w/ alpha and the rest of the object with that shader is invisible. It's similar to a shadow catcher in CGI software. I'm using threejs to render a product over a photograph, so this is very useful.

@mrdoob
Copy link
Owner

mrdoob commented Oct 27, 2014

Oh right. So it gives you black texture with the visibility stored in the alpha channel. Correct?

@etx
Copy link

etx commented Oct 27, 2014

Yep!

@Jiaying-YU
Copy link

@etx How can you accomplish this using the shader above? what I get is just a black plane......

@JosephClay
Copy link

I have been looking for a way to get his effect, however, using the snippet above I'm getting a THREE.WebGLShader: Shader couldn't compile. error.

@syoels
Copy link

syoels commented Jan 25, 2016

@skrat any chance you can re-upload that shader? the pastie link doesn't work anymore and I have encountered the exact same prob..thanks in advance!

@ghost
Copy link

ghost commented Feb 29, 2016

@etx @skrat could you please please reupload an updated shader? The one you posted doesn't seem to work anymore, like @JosephClay I get the "shader couldn't compile" error...

@WestLangley
Copy link
Collaborator

Try THREE.ShadowMaterial(). See this stackoverflow post.

@mrdoob
Copy link
Owner

mrdoob commented Mar 1, 2016

@WestLangley do you think we should promote ShadowMaterial to core?

@ghost
Copy link

ghost commented Mar 1, 2016

@WestLangley thanks a lot - that solved it. @mrdoob I think it's a super useful feature which many know from GCI so it might be a good promotion for core

@WestLangley
Copy link
Collaborator

@WestLangley do you think we should promote ShadowMaterial to core?

I do not have a strong feeling one way or the other... If I am not mistaken, it suffers the same defficiency as MeshLambertMaterial -- a texel in the shadow of one light gets no light from any other light.

@mrdoob
Copy link
Owner

mrdoob commented Mar 1, 2016

Yeah, it's a mask. Basically how the old shadows used to be.

@martha-anne
Copy link

Hi,

ShadowMaterial sounds like exactly what I need and I am so happy that you've implemented it - but I can't work out what version of three.js I need to download/link to to get it to work. Can you point me in the right direction?

@mrdoob
Copy link
Owner

mrdoob commented Mar 2, 2016

r74 or newer

@martha-anne
Copy link

Thank you! I still get THREE.ShadowMaterial is not a constructor though.

@mrdoob
Copy link
Owner

mrdoob commented Mar 2, 2016

Is not included in the build yet, it's in the examples folder. You need to include it separately:

<script src="js/materials/ShadowMaterial.js"></script>

@riccardolardi
Copy link

would promote it to core as well, it's 4kb

@martha-anne
Copy link

Perfect, thank you! I looked for the shadowMaterial file before and couldn't find it.
Works fantastically for my needs.

@mrdoob
Copy link
Owner

mrdoob commented May 17, 2016

As of r77 ShadowMaterial is now in core.

@riccardolardi
Copy link

@mrdoob great move thanks

@b-z
Copy link

b-z commented Sep 15, 2018

Try THREE.ShadowMaterial(). See this stackoverflow post.

Thanks.
It works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests