stride3d/stride · error · Exception

Too many scattering materials present in order to be able…

Error message

Too many scattering materials present in order to be able to fit them all into a single array! Maximum count is 8.

What it means

SetScatteringWidth stores per-material scattering widths into a fixed-size array limited by MaxMaterialCount (8). Passing materialIndex > 8 would overflow the backing array, so the method throws a plain Exception with the 'Maximum count is 8' message. Note the check uses > rather than >= so index exactly 8 is also out of bounds at runtime.

Solutions

  1. Keep the number of scattering materials at or below 8 (indices 0-7)
  2. Merge or drop excess SSS materials before registering them with SubsurfaceScatteringBlur
  3. Use materialIndex values strictly less than MaxMaterialCount

Example fix

// before
blur.SetScatteringWidth(9, width); // throws
// after
if (materialIndex < SubsurfaceScatteringBlur.MaxMaterialCount)
    blur.SetScatteringWidth(materialIndex, width);
Defensive patterns

Strategy: validation

Validate before calling

if (materialIndex >= SubsurfaceScatteringBlur.MaxMaterialCount)
    throw new ArgumentException("materialIndex must be < MaxMaterialCount (8)");

Try / catch

try { blur.SetScatteringWidth(i, width); }
catch (Exception) { logger.Warning("Too many SSS materials; dropping index " + i); }

Prevention

When it happens

Trigger: Calling SetScatteringWidth with materialIndex 9+ (or 8, which passes the check but overflows materialScatteringWidths), e.g. when a scene has more than 8 subsurface-scattering materials.

Common situations: Scenes with many SSS materials exceeding the shader's fixed constant buffer size; per-material loops that iterate past the MaxMaterialCount constant.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/8b463344ac5a09d6. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Rendering/Rendering/Images/SubsurfaceScattering/SubsurfaceScatteringBlur.cs:264

            blurVShader.SetInput(ColorInputIndex, inputFrameBufferColorAttachmentCopy); // Color attachment -> Texture0
            blurVShader.SetOutput(outputFrameBuffer);

            for (int i = 0; i < NumberOfPasses; ++i)
            {
                //blurHShader.Parameters.Set(SubsurfaceScatteringBlurShaderKeys.AngularOffset, (float)i / (float)NumberOfPasses * System.Math.PI);
                SetValueParameterForBothShaders(SubsurfaceScatteringBlurShaderKeys.IterationNumber, (float)i);

                // Perform the actual rendering:
                blurHShader.Draw(context, "SubsurfaceScattering_blur_H");
                blurVShader.Draw(context, "SubsurfaceScattering_blur_V");
            }
        }

        public void SetScatteringWidth(uint materialIndex, float width)
        {
            if (materialIndex > MaxMaterialCount)
            {
                throw new Exception("Too many scattering materials present in order to be able to fit them all into a single array! Maximum count is " + MaxMaterialCount + ".");
            }

            materialScatteringWidths[materialIndex] = width;
        }

        public void SetScatteringKernel(uint materialIndex, Vector4[] scatteringKernel)
        {
            if (materialIndex > MaxMaterialCount)
            {
                throw new Exception("Too many scattering materials present in order to be able to fit them all into a single array! Maximum count is " + MaxMaterialCount + ".");
            }

            scatteringKernel.CopyTo(materialScatteringKernels, (int)materialIndex * SubsurfaceScatteringSettings.SamplesPerScatteringKernel2);   // Insert into the global scattering kernel array.
        }

        /// <summary>
        /// If active, the the light won't scatter across large depth differences.
        /// The depth falloff can be configured using "Depth falloff strength".

View on GitHub (pinned to 96fad776d2)