[GenerateHLSL]
public struct VolumeProperties
{
public Vector3 extinction ;
public float asymmetry ;
public Vector3 scattering ;
public float align16 ;
public Vector3 scattering ; // [0, 1], prefer sRGB
public float extinction ; // [0, 1], prefer sRGB
public float asymmetry ; // Global (scene) property
public float align16_0 ;
public float align16_1 ;
public float align16_2 ;
properties . extinction = Vector3 . zero ;
properties . scattering = Vector3 . zero ;
properties . extinction = 0 ;
properties . scattering = Vector3 . zero ;
return properties ;
}
public class VolumeParameters
{
public Bounds bounds ; // Position and dimensions in meters
public Color albedo ; // Single scattering albedo [0, 1]
public Vector3 meanFreePath ; // In meters [0.0 1, inf]
public float asymmetry ; // [-1, 1]; 0 = isotropic
public Bounds bounds ; // Position and dimensions in meters
public Color albedo ; // Single scattering albedo [0, 1]
public float meanFreePath ; // In meters [1, inf]. Should be chromatic - this is an optimization!
public float anisotropy ; // [-1, 1]; 0 = isotropic
meanFreePath = new Vector3 ( 1 0 0 .0f, 1 0 0.0f , 1 0 0.0f ) ;
asymmetry = 0.0f ;
meanFreePath = 1 0.0f ;
anisotropy = 0.0f ;
}
public bool IsVolumeUnbounded ( )
public Vector3 GetAbsorptionCoefficient ( )
{
return Vector3 . Max ( GetExtinctionCoefficient ( ) - GetScatteringCoefficient ( ) , Vector3 . zero ) ;
float extinction = GetExtinctionCoefficient ( ) ;
Vector3 scattering = GetScatteringCoefficient ( ) ;
return Vector3 . Max ( new Vector3 ( extinction , extinction , extinction ) - scattering , Vector3 . zero ) ;
return new Vector3 ( albedo . r / meanFreePath . x , albedo . g / meanFreePath . y , albedo . b / meanFreePath . z ) ;
}
float extinction = GetExtinctionCoefficient ( ) ;
public Vector3 GetExtinctionCoefficient ( )
{
return new Vector3 ( 1.0f / meanFreePath . x , 1.0f / meanFreePath . y , 1.0f / meanFreePath . z ) ;
return new Vector3 ( albedo . r * extinction , albedo . g * extinction , albedo . b * extinction ) ;
public void SetAbsorptionAndScatteringCoefficients ( Vector3 absorption , Vector3 scattering )
public float GetExtinctionCoefficient ( )
Debug . Assert ( Mathf . Min ( absorption . x , absorption . y , absorption . z ) > = 0 , "The absorption coefficient must be non-negative." ) ;
Debug . Assert ( Mathf . Min ( scattering . x , scattering . y , scattering . z ) > = 0 , "The scattering coefficient must be non-negative." ) ;
Vector3 extinction = absorption + scattering ;
meanFreePath = new Vector3 ( 1.0f / extinction . x , 1.0f / extinction . y , 1.0f / extinction . z ) ;
albedo = new Color ( scattering . x * meanFreePath . x , scattering . y * meanFreePath . y , scattering . z * meanFreePath . z ) ;
Constrain ( ) ;
return 1.0f / meanFreePath ;
}
public void Constrain ( )
albedo . g = Mathf . Clamp01 ( albedo . g ) ;
albedo . b = Mathf . Clamp01 ( albedo . b ) ;
meanFreePath . x = Mathf . Max ( meanFreePath . x , 0.01f ) ;
meanFreePath . y = Mathf . Max ( meanFreePath . y , 0.01f ) ;
meanFreePath . z = Mathf . Max ( meanFreePath . z , 0.01f ) ;
meanFreePath = Mathf . Max ( meanFreePath , 1.0f ) ;
asymmetry = Mathf . Clamp ( asymmetry , - 1.0f , 1.0f ) ;
anisotropy = Mathf . Clamp ( anisotropy , - 1.0f , 1.0f ) ;
}
public VolumeProperties GetProperties ( )
properties . scattering = GetScatteringCoefficient ( ) ;
properties . asymmetry = asymmetry ;
properties . asymmetry = anisotropy ;
return properties ;
}