﻿// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

namespace Stride.Rendering.Materials
{
    class MaterialSubsurfaceScatteringScatteringProfileCustomUniform : IMaterialSubsurfaceScatteringScatteringProfile
    {
        cbuffer PerMaterial
        {
            stage float4 ScatteringProfile[6];
        }
        
        // TODO: This does not result in the exact same kind of profiles as the skin profile. But it's close.
        // Improve it using the "Extending Separable Subsurface Scattering to Arbitrary Materials" paper.
        float3 Compute(float dd)
        {
            float3 sum = 0.0;

            for(int i=0; i<6; ++i)
            {
                sum += exp(dd * ScatteringProfile[i].xyz) * ScatteringProfile[i].w;
            }
            
            return sum;
        }
    };
}
