Ejemplo n.º 1
0
        private uint AddMaterialToDictionaryAndGetArrayIndex(RenderMesh renderMesh, ref uint materialArrayIndexCounter)
        {
            // Fill the structure because the dictionary compares the contents for equality:
            ScatteringParameters scatteringParameters = new ScatteringParameters(renderMesh.MaterialPass);

            uint materialArrayIndex;

            if (DeduplicateMaterialParameters)
            {
                // Since we deduplicate materials here, we must check whether or not we should add a material or not before doing so.

                // If "TryGetValue()" succeeds, "materialArrayIndex" will receive the correct value. If it fails, it will be computed below.
                if (!scatteringParametersToArrayIndexDictionary.TryGetValue(scatteringParameters, out materialArrayIndex)) // If the material isn't present in the collection:
                {
                    AddMaterialToArrayAndDictionary(scatteringParameters, materialArrayIndexCounter);
                    materialArrayIndex = materialArrayIndexCounter++; // Use the index before the increment.
                }
            }
            else
            {
                // Since we don't deduplicate materials here, we always add each material and increment the index.
                AddMaterialToArrayAndDictionary(scatteringParameters, materialArrayIndexCounter);
                materialArrayIndex = materialArrayIndexCounter++; // Use the index before the increment.
            }

            return(materialArrayIndex);
        }
Ejemplo n.º 2
0
        private void AddMaterialToArrayAndDictionary(ScatteringParameters scatteringParameters, uint materialArrayIndex)
        {
            // "SetScatteringWidth()" throws an exception if the range is exceeded. // TODO: How to handle this? Don't throw at all?
            SubsurfaceScatteringBlurEffect.SetScatteringWidth(materialArrayIndex, scatteringParameters.ScatteringWidth); // Add the scattering width to the scattering width array.
            if (scatteringParameters.ScatteringKernel != null)
            {
                // TODO: STABILITY: What to do if the scattering width is present but no kernel? The post-process wouldn't be able to handle that correctly.
                //                  Maybe just save a dummy kernel?
                SubsurfaceScatteringBlurEffect.SetScatteringKernel(materialArrayIndex, scatteringParameters.ScatteringKernel);
            }

            scatteringParametersToArrayIndexDictionary[scatteringParameters] = materialArrayIndex; // Add the material to the dictionary and save its associated index in the scattering width array.
        }