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

Better lights and shadow maps [ working example attached ] #6420

Closed
ghost opened this issue Apr 16, 2015 · 14 comments
Closed

Better lights and shadow maps [ working example attached ] #6420

ghost opened this issue Apr 16, 2015 · 14 comments

Comments

@ghost
Copy link

ghost commented Apr 16, 2015

Hi
I've experimented with three.js few days, and it seems to bee very cool.
But one thing bothers me, there is something not right with shadows.
In reality shadow doesn't exist, it is just place where light does not reach, but in three.js lights are first calculated and after that shadows are casted.

So I've tried different approach, first created new material, called it MeshPhong2Material
It uses exactly same code as MeshPhongMaterial, except shadows and spot lights.

I disabled spot lighting code in fragment shader, and then put spot light calculations directly to the loop where shadows are casted, changed it a bit, and added several uniforms for light information.
So no need to cast any shadows, to not put light on shadowed areas is enough, and thats it.

The result you can see on screens below. On the scene are 4 spot light, colors of those are more-less: red,green,blue and white, shadow maps are 2048 x 2048px
As a side effect most acne problems dissapeared , for free.
shadowDarknes parameter is not needed anymore.
Another good thing, it seems to be about 30% faster on my laptop's Nvidia NVS 3100M than current shadows, with this scene at least, 22fps vs 16fps,
this is because light is not calculated anymore in shadowed areas.

This method fits closer to real lights, as you can see there are colored shadows, exactly like in nature with this kind of lights.

What i've done is now just a proof of concept, code is a 'dirty hack', for experiments only.
It works now only with spot lights. Spot lights without shadows do not work.
I am not sure how to to put it in three.js in the proper way, maybe add new material, new light type, or just flag in existing ones.

There is problem with current three.js structure, shadows are a plugin which like separate thing, to make it work with lighting requires to add additional uniforms with lighting information, because current shadowmap does not know to which light it bellongs.

It would be nice to see this method as an alternative to current shadows.
What do you think?

Here is working example: http://cypd.vot.pl/shadowexperiment/
Just play a bit with settings, most difference is when 2 light are enabled, you can control the camera using mouse.

4 lights,
original shader:
2

modified shader:
1

2 lights
original shader:
4

modified shader:
3

regards
CypD

@satori99
Copy link
Contributor

Wow. The improvement over existing shadows is impressive.

Expecially in regards to shadow acne. It is practically gone completely in your demo. And it's crazy fast!

Nice work.

@titansoftime
Copy link
Contributor

Holy crap!

@RemusMar
Copy link
Contributor

The method gives better results for objects who cast and receive shadows at the same time.
And those colored shadows look very nice.
Good job!

@jonnenauha
Copy link
Contributor

Nice 👍

@mrdoob
Copy link
Owner

mrdoob commented Apr 21, 2015

This looks great! 😮
I've one concern though. How about the case of VR, were one would like to compute the shadows once and not twice?

@rohan-deshpande
Copy link
Contributor

Very interesting. Will try this out for sure!

@nanni83
Copy link

nanni83 commented Jun 12, 2015

I have tried it out, but acne issue (shadow artifacts) doesn't get fixed. Is there any extra property needed to be set for this. I am using spotlight as per your code. Please help.

Thanks

@ghost
Copy link
Author

ghost commented Jun 13, 2015

@mrdoob

I've one concern though. How about the case of VR, were one would like to compute the shadows once and not twice?

I think in case of VR there will be no problem, because depth textures you need render only once, and then render two normal images , one for each eye. So i think it is not much different from what is now.

@nanni83
I will publish full source code if you wish. This way it will be the most convenient.
Notice that shadow acne still exist in my example, only difference is that acne is not visible so much on this scene. So it may be dependent on the scale of objects and far and near parameters for shadow cameras. And I changed parameter shadowBias=0.00002, but i don't think it makes much difference here.

@mrdoob
Copy link
Owner

mrdoob commented Jun 20, 2015

I think in case of VR there will be no problem, because depth textures you need render only once, and then render two normal images , one for each eye. So i think it is not much different from what is now.

Ah! Sounds great then!

Regarding implementation, I would replace the current code altogether 😀

@prafullit
Copy link
Contributor

It's awesome.

@mrdoob
Copy link
Owner

mrdoob commented Sep 17, 2015

@Cypd Any chance you could re-implement this on top of the dev branch? THREE.ShadowMap is now much simpler!

@tschw
Copy link
Contributor

tschw commented Sep 22, 2015

Related #7153

@ghost
Copy link
Author

ghost commented Sep 23, 2015

For some reasons no, or not yet at least . So if someone wants to do it first, feel free and do it, don't wait for me ;)

@mrdoob
Copy link
Owner

mrdoob commented Nov 6, 2015

Done!

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

No branches or pull requests

9 participants