namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[GenerateHLSL]
public class SSSConstants
{
public const int SSS_PROFILES_MAX = 8 ;
}
[Serializable]
public class SubsurfaceScatteringProfile : ScriptableObject
{
[ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]
public Color scatterDistance1 ;
public Color scatterDistance1 ;
public Color scatterDistance2 ;
public float lerpWeight ;
public TexturingMode texturingMode ;
public bool enableTransmission ;
public Color tintColor ;
public Vector2 thicknessRemap ;
public Color scatterDistance2 ;
public float lerpWeight ;
public TexturingMode texturingMode ;
public bool enableTransmission ;
public bool enableThinMaterial ;
public Color tintColor ;
public Vector2 thicknessRemap ;
public int settingsIndex ;
public int settingsIndex ;
Vector4 [ ] m_FilterKernel ;
Vector4 [ ] m_FilterKernel ;
Vector3 [ ] m_HalfRcpVariances ;
Vector3 [ ] m_HalfRcpVariances ;
Vector4 m_HalfRcpWeightedVariances ;
Vector4 m_HalfRcpWeightedVariances ;
scatterDistance1 = new Color ( 0.3f , 0.3f , 0.3f , 0.0f ) ;
scatterDistance2 = new Color ( 0.6f , 0.6f , 0.6f , 0.0f ) ;
lerpWeight = 0.5f ;
texturingMode = TexturingMode . PreAndPostScatter ;
enableTransmission = false ;
tintColor = Color . white ;
thicknessRemap = new Vector2 ( 0 , 1 ) ;
settingsIndex = SubsurfaceScatteringSettings . neutralProfileID ; // Updated by SubsurfaceScatteringSettings.OnValidate() once assigned
scatterDistance1 = new Color ( 0.3f , 0.3f , 0.3f , 0.0f ) ;
scatterDistance2 = new Color ( 0.6f , 0.6f , 0.6f , 0.0f ) ;
lerpWeight = 0.5f ;
texturingMode = TexturingMode . PreAndPostScatter ;
enableTransmission = false ;
enableThinMaterial = false ;
tintColor = Color . white ;
thicknessRemap = new Vector2 ( 0 , 1 ) ;
settingsIndex = SubsurfaceScatteringSettings . neutralProfileID ; // Updated by SubsurfaceScatteringSettings.OnValidate() once assigned
UpdateKernelAndVarianceData ( ) ;
}
[Serializable]
public class SubsurfaceScatteringSettings : ISerializationCallbackReceiver
{
public const int maxNumProfiles = 8 ;
public const int neutralProfileID = maxNumProfiles - 1 ;
public const int neutralProfileID = SSSConstants . SSS_PROFILES_MAX - 1 ;
public int numProfiles ;
public SubsurfaceScatteringProfile [ ] profiles ;
[NonSerialized] public int thinMaterialFlags ; // 1 bit/profile; 1 = is thin material (allow specific optimization)
[NonSerialized] public Vector4 [ ] tintColors ; // For transmission; alpha is unused
[NonSerialized] public float [ ] thicknessRemaps ; // Remap: 0 = start, 1 = end - start
[NonSerialized] public Vector4 [ ] halfRcpVariancesAndLerpWeights ;
profiles [ 0 ] = null ;
texturingModeFlags = 0 ;
transmissionFlags = 0 ;
thinMaterialFlags = 0 ;
tintColors = null ;
thicknessRemaps = null ;
halfRcpVariancesAndLerpWeights = null ;
public void OnValidate ( )
{
// Reserve one slot for the neutral profile.
numProfiles = Math . Min ( profiles . Length , maxNumProfiles - 1 ) ;
numProfiles = Math . Min ( profiles . Length , SSSConstants . SSS_PROFILES_MAX - 1 ) ;
if ( profiles . Length ! = numProfiles )
{
public void UpdateCache ( )
{
texturingModeFlags = 0 ;
transmissionFlags = 0 ;
texturingModeFlags = 0 ;
transmissionFlags = 0 ;
thinMaterialFlags = 0 ;
if ( tintColors = = null | | tintColors . Length ! = maxNumProfiles )
if ( tintColors = = null | | tintColors . Length ! = SSSConstants . SSS_PROFILES_MAX )
tintColors = new Vector4 [ maxNumProfiles ] ;
tintColors = new Vector4 [ SSSConstants . SSS_PROFILES_MAX ] ;
if ( thicknessRemaps = = null | | thicknessRemaps . Length ! = ( maxNumProfiles * 2 ) )
if ( thicknessRemaps = = null | | thicknessRemaps . Length ! = ( SSSConstants . SSS_PROFILES_MAX * 2 ) )
thicknessRemaps = new float [ maxNumProfiles * 2 ] ;
thicknessRemaps = new float [ SSSConstants . SSS_PROFILES_MAX * 2 ] ;
if ( halfRcpVariancesAndLerpWeights = = null | | halfRcpVariancesAndLerpWeights . Length ! = ( maxNumProfiles * 2 ) )
if ( halfRcpVariancesAndLerpWeights = = null | | halfRcpVariancesAndLerpWeights . Length ! = ( SSSConstants . SSS_PROFILES_MAX * 2 ) )
halfRcpVariancesAndLerpWeights = new Vector4 [ maxNumProfiles * 2 ] ;
halfRcpVariancesAndLerpWeights = new Vector4 [ SSSConstants . SSS_PROFILES_MAX * 2 ] ;
if ( halfRcpWeightedVariances = = null | | halfRcpWeightedVariances . Length ! = maxNumProfiles )
if ( halfRcpWeightedVariances = = null | | halfRcpWeightedVariances . Length ! = SSSConstants . SSS_PROFILES_MAX )
halfRcpWeightedVariances = new Vector4 [ maxNumProfiles ] ;
halfRcpWeightedVariances = new Vector4 [ SSSConstants . SSS_PROFILES_MAX ] ;
if ( filterKernels = = null | | filterKernels . Length ! = ( maxNumProfiles * SubsurfaceScatteringProfile . numSamples ) )
if ( filterKernels = = null | | filterKernels . Length ! = ( SSSConstants . SSS_PROFILES_MAX * SubsurfaceScatteringProfile . numSamples ) )
filterKernels = new Vector4 [ maxNumProfiles * SubsurfaceScatteringProfile . numSamples ] ;
filterKernels = new Vector4 [ SSSConstants . SSS_PROFILES_MAX * SubsurfaceScatteringProfile . numSamples ] ;
}
for ( int i = 0 ; i < numProfiles ; i + + )
texturingModeFlags | = ( ( int ) profiles [ i ] . texturingMode ) < < i ;
transmissionFlags | = ( profiles [ i ] . enableTransmission ? 1 : 0 ) < < i ;
thinMaterialFlags | = ( profiles [ i ] . enableThinMaterial ? 1 : 0 ) < < i ;
tintColors [ i ] = profiles [ i ] . tintColor ;
thicknessRemaps [ 2 * i ] = profiles [ i ] . thicknessRemap . x ;
} ;
public readonly GUIContent sssProfileTransmission = new GUIContent ( "Enable Transmission" , "Toggles simulation of light passing through thin objects. Depends on the thickness of the material." ) ;
public readonly GUIContent sssProfileTintColor = new GUIContent ( "Transmission Tint Color" , "Tints transmitted light." ) ;
public readonly GUIContent sssProfileThinMaterial = new GUIContent ( "Enable Thin Material" , "Define is the material is thin (paper, leaf) or not. Allow to get cheap transmission and shadow." ) ;
public readonly GUIContent sssProfileMinMaxThickness = new GUIContent ( "Min-Max Thickness" , "Shows the values of the thickness remap below (in centimeters)." ) ;
public readonly GUIContent sssProfileThicknessRemap = new GUIContent ( "Thickness Remap" , "Remaps the thickness parameter from [0, 1] to the desired range (in centimeters)." ) ;
private RenderTexture m_ProfileImage , m_TransmittanceImage ;
private Material m_ProfileMaterial , m_TransmittanceMaterial ;
private SerializedProperty m_ScatterDistance1 , m_ScatterDistance2 , m_LerpWeight , m_TintColor ,
private SerializedProperty m_ScatterDistance1 , m_ScatterDistance2 , m_LerpWeight , m_TintColor , m_ThinMaterial ,
m_TexturingMode , m_Transmission , m_ThicknessRemap ;
void OnEnable ( )
m_LerpWeight = serializedObject . FindProperty ( "lerpWeight" ) ;
m_TexturingMode = serializedObject . FindProperty ( "texturingMode" ) ;
m_Transmission = serializedObject . FindProperty ( "enableTransmission" ) ;
m_ThinMaterial = serializedObject . FindProperty ( "enableThinMaterial" ) ;
m_TintColor = serializedObject . FindProperty ( "tintColor" ) ;
m_ThicknessRemap = serializedObject . FindProperty ( "thicknessRemap" ) ;
m_TexturingMode . intValue = EditorGUILayout . Popup ( styles . sssTexturingMode , m_TexturingMode . intValue , styles . sssTexturingModeOptions ) ;
EditorGUILayout . PropertyField ( m_Transmission , styles . sssProfileTransmission ) ;
EditorGUILayout . PropertyField ( m_TintColor , styles . sssProfileTintColor ) ;
EditorGUILayout . PropertyField ( m_ThinMaterial , styles . sssProfileThinMaterial ) ;
EditorGUILayout . PropertyField ( m_ThicknessRemap , styles . sssProfileMinMaxThickness ) ;
Vector2 thicknessRemap = m_ThicknessRemap . vector2Value ;
EditorGUILayout . Space ( ) ;
// Draw the transmittance graph.
m_TransmittanceMaterial . SetColor ( "_StdDev1" , stdDev1 ) ;
m_TransmittanceMaterial . SetColor ( "_StdDev2" , stdDev2 ) ;
m_TransmittanceMaterial . SetFloat ( "_LerpWeight" , m_LerpWeight . floatValue ) ;
m_TransmittanceMaterial . SetColor ( "_StdDev1" , stdDev1 ) ;
m_TransmittanceMaterial . SetColor ( "_StdDev2" , stdDev2 ) ;
m_TransmittanceMaterial . SetFloat ( "_LerpWeight" , m_LerpWeight . floatValue ) ;
m_TransmittanceMaterial . SetVector ( "_TintColor" , m_TintColor . colorValue ) ;
m_TransmittanceMaterial . SetVector ( "_TintColor" , m_TintColor . colorValue ) ;
EditorGUI . DrawPreviewTexture ( GUILayoutUtility . GetRect ( 1 6 , 1 6 ) , m_TransmittanceImage , m_TransmittanceMaterial , ScaleMode . ScaleToFit , 1 6.0f ) ;
serializedObject . ApplyModifiedProperties ( ) ;