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

Percent Closer Soft Shadows by spidersharma03 #8933

Closed
wants to merge 7 commits into from

Conversation

bhouston
Copy link
Contributor

I'm submitting this PR but it was written fully by @spidersharma03.

This implements Percent Closer Soft Shadows (PCSS) as discussed here in issue #7653

The results look like this:

image

@bhouston
Copy link
Contributor Author

This is a rough implementation, it likely needs to be polished to be fully general case. What is great is that all the hard stuff is implemented in this PR.

@bhouston
Copy link
Contributor Author

/ping @MasterJames

@bhouston
Copy link
Contributor Author

One aspect of polishing will be to get the light source radius implemented as previously described here: #7672

@bhouston
Copy link
Contributor Author

numBlockers = numBlockers + 1.0;
}
}
avgBlockerDepth = blockerSum / numBlockers;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potential divide by zero? /ping @Spidersharma

@MasterJames
Copy link
Contributor

MasterJames commented May 20, 2016

Demo link cloth rendered black on my mobile but this is really great seems pretty quick too. Excellent amendments.
Maybe there's a need for an adjustible blur factor too.
Spot Light's penumbra?

@bhouston
Copy link
Contributor Author

Did some more polishing and got it looking like this - smooth but grainy:

image

@bhouston
Copy link
Contributor Author

@MasterJames wrote:

Maybe there's a need for an adjustible blur factor too. Spot Light's penumbra?

The physical solution is to have a radius of the light source. Larger bulbs make blurrying shadows, point-like light sources have crisper shadows. I'd prefer to go that route.

@MasterJames
Copy link
Contributor

Sorry I thought the penumbra represented the same concept?

@erichlof
Copy link
Contributor

@bhouston and @spidersharma03 ,
Thanks so much for this upgrade to the shadow system! One quick typo check, there is a double return statement on these lines (which I don't think is possible in glsl):
https://github.com/bhouston/three.js/blob/d1c22a07b826cb407032cfc05c69f944c8dfbc19/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl#L201-L202

Thanks again for the great contribution!

@spidersharma03
Copy link
Contributor

@erichlof Arh, yeah thats a mistake, and the second return should be removed. I forgot to remove that, though it should work.

@mrdoob
Copy link
Owner

mrdoob commented May 20, 2016

Have you tried this on iPad? The fixed poisson disk usually makes things 2x faster on iPad (like 60fps instead of 30fps).

@mrdoob
Copy link
Owner

mrdoob commented May 20, 2016

By the way, this looks really nice!

@thmasn
Copy link
Contributor

thmasn commented Jun 30, 2016

will this eventually be pulled?
would work great with #9234

@abelnation
Copy link
Contributor

FYI. The RectAreaLight work currently does not consider any shadow information. That's work to be done as a follow-up.

@mrdoob
Copy link
Owner

mrdoob commented Jun 30, 2016

will this eventually be pulled?

Oh! I thought @bhouston said on twitter-land that a new PR was coming? Is this good to go @bhouston?

@spidersharma03
Copy link
Contributor

Yes, we did many changes in this PR, specially correct handling of directional light, and other bug fixes. I think @bhouston will be able to say better on the current state.

@bhouston
Copy link
Contributor Author

bhouston commented Jul 4, 2016

I'd like to get this pushed, it is a pretty slow technique though. We ended up not using in in Clara.io for the time being because while it works and also looks great on high end machines, especially on GeForce 960+, it just kills low end devices.

@mrdoob
Copy link
Owner

mrdoob commented Jul 12, 2016

I keep dreaming of how current FPS could be a value stored in the renderer and incorporated with policies that have pretty reliable defaults.

I've heard you. But I don't think the renderer should be that "smart". One could easily build a SmartWebGLRenderer on top that does what you propose.

@MasterJames
Copy link
Contributor

Okay I wondered if you felt adding a super simple current FPS and average FPS (over a second or two) would be a useful idea in the main renderer or where. The one in stats seems excessive when needed? Thanks for your feedback and time as always.

@mrdoob
Copy link
Owner

mrdoob commented Jul 12, 2016

I don't think the renderer should have any logic for that. The renderer/s should be as "dumb" and predictable as possible.

@bhouston
Copy link
Contributor Author

I agree with @mrdoob, any sort of adaptive rendering quality should be
outside of WebGLRenderer, but I think it would be okay to put pieces of it
in examples/js. :)

Best regards,
Ben Houston (Cell: 613-762-4113, Skype: ben.exocortex, Twitter:
@exocortexcom)
https://Clara.io - Online 3D Modeling and Rendering

On Tue, Jul 12, 2016 at 7:16 PM, Mr.doob notifications@github.com wrote:

I don't think the renderer should have any logic for that. The renderer/s
should be as "dumb" and predictable as possible.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#8933 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AAj6_c7YdZ_2kHN70d6UJJ7PDQedc5t4ks5qVCBHgaJpZM4IiekW
.

@deepak-ghimire
Copy link

Hi Guys,
It's a great news that there has been some adaptation of PCSS algorithm. I had implemented a version , around a year ago, of PCSS for my mockup tool to generate final render (and preview) with PCSS shadows, but not too perfect :(

I am not a pro with GLSL but if some of my code portion is helpful please feel free to use.

It's a great news to hear that PCSS is progressing.
Many thanks to @spidersharma03, @bhouston , @mrdoob for the initiative.

mockup
mockup 1
you can find the code at Mockup Studio in
<script id="shadowmap_pars_fragment" type="x-shader/x-fragment">

P.S. apologies for a substandard comment, I am still new to GitHub.

@spidersharma03
Copy link
Contributor

I am preparing a PR for the PCSS, on which me and @bhouston worked some time back. Will submit it soon.

@edankwan
Copy link

@DEIP You version works very nicely. Can I hack it into a custom threejs build to use?

@deepak-ghimire
Copy link

@edankwan yes sure, Please note that I am using custom values rather than dynamic values, You'll have to consider that too.

@edankwan
Copy link

@DEIP I placed a directional light from the top, and it doesn't seem to work.
floor

@deepak-ghimire
Copy link

@edankwan I had done it only for SpotLight,

@ghost
Copy link

ghost commented Sep 29, 2016

We had handled directional light in a different and correct way by
introducing a spread angle parameter

On 29-Sep-2016 4:42 PM, "Deepak Ghimire" notifications@github.com wrote:

@edankwan https://github.com/edankwan I had done it only for SpotLight,


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#8933 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABmpZozc3S27DuCRZuANiTmIr0cHq8ixks5qu50GgaJpZM4IiekW
.

@edankwan
Copy link

Sweet. Looking forward to the merge

@Jozain Jozain deleted the pcss_remake branch November 28, 2016 15:21
@sam-g-steel
Copy link
Contributor

sam-g-steel commented Jan 21, 2017

@mrdoob, @bhouston,
I'm looking at updating this code and resubmitting this as a pull request that has no conflicts.

Would that be helpful?

@mrdoob
Copy link
Owner

mrdoob commented May 25, 2017

@sam-g-steel yes please!

@sam-g-steel
Copy link
Contributor

sam-g-steel commented May 27, 2017 via email

@mrdoob
Copy link
Owner

mrdoob commented Aug 16, 2017

@mrdoob
Copy link
Owner

mrdoob commented Aug 16, 2017

Many thanks!

@mrdoob mrdoob closed this Aug 16, 2017
@trusktr
Copy link
Contributor

trusktr commented Dec 13, 2017

Just for clarity, is PCFSoft different than PCSS?

@ghost
Copy link

ghost commented Dec 13, 2017 via email

@MasterJames
Copy link
Contributor

@trusktr
Copy link
Contributor

trusktr commented Dec 14, 2017

Oh, so PCFSoft lets us specify a constant shadow radius (blur) no matter of object distance, while PCSS is basically that but with increasing 'radius' as shadow goes further from the object?

@ghost
Copy link

ghost commented Dec 14, 2017 via email

@trusktr
Copy link
Contributor

trusktr commented Dec 14, 2017

Really why I'm asking, is because the Three.js WebGLRenderer Constants Shadow Types documentation says

PCFSoftShadowMap filters shadow maps using the Percentage-Closer Soft Shadows (PCSS) algorithm.

which seems to mean that using PCFSoftShadowMap will give us results like what is in this pull request, but that doesn't seem to be the case, so I was confused.

Is it just not officially implemented yet (other than in the examples), and PCFSoftShadowMap is a place holder for it?

@mrdoob
Copy link
Owner

mrdoob commented Dec 14, 2017

@trusktr this is not part of the build at the moment, but it's used in a example:

https://threejs.org/examples/#webgl_shadowmap_pcss

ofrohn pushed a commit to ofrohn/three.js that referenced this pull request Jun 17, 2018
@mrdoob mrdoob mentioned this pull request Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.