[Rendering] feat: a per-view flag tells a material it is drawn for a shadow map - #3387
Nicogo1705 wants to merge 1 commit into
Conversation
Ethereal77
left a comment
There was a problem hiding this comment.
Maybe better as two separate PRs, but anyway:
-
The optimization I wrote about the clamping I think should be better in theory. Better to test its correctness and performance, of course.
min+maxshould be branchless while also not falling into the previousinfinite/NaNproblem. -
Nice idea the shadow caster pass identification!
I would have preferred however if this were called something likeDepthOnlyPassor something alike. It's weird (even if logically correct) that the depth-prepass invokes a shadow-caster pass. But maybe renaming those are a bigger change not worth the effort.
|
@Ethereal77 |
f3108f8 to
2b4d960
Compare
|
Thanks for the review!
|
2b4d960 to
f27bcef
Compare
|
Hey, no need to apologize. I'm not opposed to grouping if the changes are small. I understand it's more convenient sometimes to dump several changes into a single PR than open several. I just like that PRs sometimes serve as a kind of auto-documentation on how the software evolved and why some changes were needed, and combining several changes into one makes each change less discoverable and sometimes less understandable (context switching overhead 😄). Just my opinion, of course |
Oh, now I see what you mean. I have misread the PR and thought you have also rewritten the depth-prepass to use this and this just served to compute the depth-only output (hence my comment). But I see now that the depth-prepass was already using the shadow caster effect. Sorry for the confusion |
ShadowMapCasterPassInfo carries ShadowMapViewFlag in a PerView constant buffer: 1 in a shadow map view, 0 in every other one. A material whose surface is computed in the pixel shader (a ray-marched volume, a parallax search) reads it to settle for a depth good enough for a shadow and skip the rest. The value is the view's, not a constant: the caster effect also runs the camera's depth-only prepass, where such a material must not write its shadow depth. ShadowCasterRenderFeature writes the flag for every view that has the group, skipping a layout the view draws nothing through, which has no resources prepared for it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
f27bcef to
b82de9f
Compare
|
Both fixes were reworked after review, so this is the moment to split as suggested: this PR keeps the shadow map flag, the bright pass clamp moved to #3429. Rebased on master, one commit each. Verified on the voxel GI demo on Direct3D 11: shadows, camera prepass and voxelization views. |
| } | ||
| // A layout the view draws nothing through has no resources prepared for it. | ||
| var resourceGroup = viewLayout.Entries[view.Index].Resources; | ||
| if (resourceGroup == null || resourceGroup.ConstantBuffer.Data == System.IntPtr.Zero) |
There was a problem hiding this comment.
"A layout the view draws nothing through has no resources prepared for it."
Not sure I get that.
resourceGroup should not be null (always created in RootEffectRenderFeatures).
I think ConstantBuffer.Data should always exists.
Data == Zero only happens for a layout without a PerView cbuffer. Such a layout has neither logical group, so without the guard both Hash == ObjectId.Empty checks would skip it before anything reads ConstantBuffer.Data.
Did you hit a crash without it? If yes, can you share the repro? That would be a different bug. If not, let's drop the guard.
| cbuffer PerView.ShadowMapView | ||
| { | ||
| /// 1 in a shadow map view, 0 in every other view, the camera's depth-only prepass included. | ||
| stage float ShadowMapViewFlag; |
There was a problem hiding this comment.
I was wondering, if no ShadowCasterRenderFeature, this viewflag is basically undefined memory?
Should we accept that and add to doc, or do something for this case (i.e. always default to 0 in MaterialRenderFeature)?
PR Details
A material whose surface is not its mesh (a ray-marched volume, a parallax search) needs to know when it is drawn for a shadow map, to settle for a depth good enough for a shadow and skip the rest. Nothing told it.
ShadowMapCasterPassInfocarriesShadowMapViewFlagin aPerViewconstant buffer: 1 in a shadow map view, 0 in every other one. A material mixes it in and reads the flag in the pixel stage.ShadowCasterRenderFeaturewrites the flag for every view that has the group, and skips a layout the view draws nothing through, which has no resources prepared for it.Reworked after review: no stream, no marker shader, no effect mixins, one loop over the view layouts. The bright pass clamp that was here moved to #3429.
Verified on Direct3D 11 with the voxel GI demo: the grid's shadow material casts in the shadow views, draws nothing in the camera prepass and the voxelization views.
Types of changes
Checklist