SRP ScriptableRenderContext.DrawShadows masks RGBA writes?

I have a custom working differed SRP with working shadows.
HOWEVER I’m trying to test some more advanced effects and I need to write out color information while shadows render to the shadow depth buffer.

Question is: Does “ScriptableRenderContext.DrawShadows” disable RGBA pixel writes when it renders shadow caster objects?

My realtime soft shadow experiments so far below.

Found a work around using DrawRenderers method for now but DrawShadows method needs an option to prevent it from disabling color writes.

if (!camera.TryGetCullingParameters(false, out var cullingParameters)) Debug.LogError("Failed: TryGetCullingParameters");
cullingParameters.shadowDistance = asset.hq_shadowDistance;
cullingParameters.cullingOptions = CullingOptions.ShadowCasters;
for (int pi = 0; pi != cullingParameters.cullingPlaneCount; ++pi)
{
    var plane = cullingParameters.GetCullingPlane(pi);
    plane.distance += asset.hq_shadowDistance;
    cullingParameters.SetCullingPlane(pi, plane);
}
var shadowCullResults = context.Cull(ref cullingParameters);

var filterSettings = FilteringSettings.defaultValue;
var drawSettings = new DrawingSettings(new ShaderTagId("ShadowCaster"), new SortingSettings());
var sortSettings = drawSettings.sortingSettings;
sortSettings.criteria = SortingCriteria.None;
drawSettings.perObjectData = PerObjectData.None;
drawSettings.enableDynamicBatching = true;
drawSettings.enableInstancing = true;
context.DrawRenderers(shadowCullResults, ref drawSettings, ref filterSettings);

DrawShadows dosn’t attach to framebuffer any other buffers rather than depth. There is no RGBA at all.

Do you know what the correct culling options are to make “DrawRenderers” match “DrawShadows”?

I think my work around is close by probably not exact.
I’m adding a transparent shadows pass is why I’m doing this.

As ad-hoc solution i used a virtual camera. Get cullingParameters from it and then draw what needed as usual. Not ideal but fine. Maybe there is a more proper way to do it, need to investigate.

I have the same problem. Is there any solutions?

This is what I’m currently doing. Not fully tested as I’m still working on other parts of the SRP but is doing what I need atm.

        protected void CameraPrep_CustomShadows(ref ScriptableRenderContext context, Camera camera, out CullingResults shadowCullResults, float shadowDistance)
        {
            // cull shadow casters
            if (!camera.TryGetCullingParameters(false, out var cullingParameters)) Debug.LogError("Failed: TryGetCullingParameters");
            cullingParameters.cullingOptions = CullingOptions.ShadowCasters;
            for (int pi = 0; pi != cullingParameters.cullingPlaneCount; ++pi)
            {
                var plane = cullingParameters.GetCullingPlane(pi);
                plane.distance += shadowDistance * .5f;
                cullingParameters.SetCullingPlane(pi, plane);
            }
            shadowCullResults = context.Cull(ref cullingParameters);
        }

Its being used for transparent shadows. Here you can see it working for these shadows based off OIT objects.

Bumping this thread: I had run into this problem as well, DrawShadows really need a way for users to override ColorMask settings (it overwrites shader settings), otherwise people would have to use DrawRenderers to workaround it.

In 2019.4.11 release notes was point about shadow. Need to try.

1 Like

Tested, it does work.

MRT works too. Nice.

O nice will have to test this