namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[Serializable]
public struct DensityVolumeParameters
public struct DensityVolumeArtistParameters
public Color albedo ; // Single scattering albedo [0, 1]. Alpha is ignored
public float meanFreePath ; // In meters [1, inf]. Should be chromatic - this is an optimization!
public float asymmetry ; // Only used if (isLocal == false)
public Color albedo ; // Single scattering albedo [0, 1]. Alpha is ignored
public float meanFreePath ; // In meters [1, inf]. Should be chromatic - this is an optimization!
public float asymmetry ; // Only used if (isLocal == false)
public int textureIndex ;
public Vector3 textureScrollingSpeed ;
public Vector3 textureTiling ;
public Vector3 textureScrollingSpeed ;
public Vector3 textureTiling ;
private Vector3 volumeScrollingAmount ;
public Vector3 positiveFade ;
public Vector3 negativeFade ;
public DensityVolumeParameters ( Color color , float _meanFreePath , float _asymmetry )
public int textureIndex ; // This shouldn't be public... Internal, maybe?
private Vector3 volumeScrollingAmount ;
public DensityVolumeArtistParameters ( Color color , float _meanFreePath , float _asymmetry )
albedo = color ;
meanFreePath = _meanFreePath ;
asymmetry = _asymmetry ;
albedo = color ;
meanFreePath = _meanFreePath ;
asymmetry = _asymmetry ;
volumeMask = null ;
textureIndex = - 1 ;
volumeMask = null ;
textureIndex = - 1 ;
textureTiling = Vector3 . one ;
textureTiling = Vector3 . one ;
positiveFade = Vector3 . zero ;
negativeFade = Vector3 . zero ;
}
public void Update ( bool animate , float time )
volumeScrollingAmount = Vector3 . zero ;
}
public DensityVolumeData GetData ( )
public DensityVolumeEngineData GetData ( )
DensityVolumeData data = new DensityVolumeData ( ) ;
DensityVolumeEngineData data = new DensityVolumeEngineData ( ) ;
data . extinction = VolumeRenderingUtils . ExtinctionFromMeanFreePath ( meanFreePath ) ;
data . scattering = VolumeRenderingUtils . ScatteringFromExtinctionAndAlbedo ( data . extinction , ( Vector3 ) ( Vector4 ) albedo ) ;
data . extinction = VolumeRenderingUtils . ExtinctionFromMeanFreePath ( meanFreePath ) ;
data . scattering = VolumeRenderingUtils . ScatteringFromExtinctionAndAlbedo ( data . extinction , ( Vector3 ) ( Vector4 ) albedo ) ;
data . textureIndex = textureIndex ;
data . textureScroll = volumeScrollingAmount ;
data . textureTiling = textureTiling ;
data . textureIndex = textureIndex ;
data . textureScroll = volumeScrollingAmount ;
data . textureTiling = textureTiling ;
// Avoid numerical problems by clamping extreme values.
data . rcpPosFade . x = Mathf . Clamp ( 1.0f / positiveFade . x , 0.00001526f , 6 5 5 3 6.0f ) ;
data . rcpNegFade . x = Mathf . Clamp ( 1.0f / negativeFade . x , 0.00001526f , 6 5 5 3 6.0f ) ;
data . rcpPosFade . y = Mathf . Clamp ( 1.0f / positiveFade . y , 0.00001526f , 6 5 5 3 6.0f ) ;
data . rcpNegFade . y = Mathf . Clamp ( 1.0f / negativeFade . y , 0.00001526f , 6 5 5 3 6.0f ) ;
data . rcpPosFade . z = Mathf . Clamp ( 1.0f / positiveFade . z , 0.00001526f , 6 5 5 3 6.0f ) ;
data . rcpNegFade . z = Mathf . Clamp ( 1.0f / negativeFade . z , 0.00001526f , 6 5 5 3 6.0f ) ;
return data ;
}
[AddComponentMenu("Rendering/Density Volume", 1100)]
public class DensityVolume : MonoBehaviour
{
public DensityVolumeParameters parameters = new DensityVolumeParameters ( Color . white , 1 0.0f , 0.0f ) ;
public DensityVolumeArtist Parameters parameters = new DensityVolumeArtist Parameters ( Color . white , 1 0.0f , 0.0f ) ;
private Texture3D previousVolumeMask = null ;
void OnDrawGizmos ( )
{
Gizmos . color = parameters . albedo ;
// Positive fade box.
Gizmos . color = Color . red ;
Gizmos . DrawWireCube ( - 0.5f * parameters . positiveFade , Vector3 . one - parameters . positiveFade ) ;
// Negative fade box.
Gizmos . color = Color . blue ;
Gizmos . DrawWireCube ( 0.5f * parameters . negativeFade , Vector3 . one - parameters . negativeFade ) ;
// Bounding box.
Gizmos . color = parameters . albedo ;
Gizmos . DrawWireCube ( Vector3 . zero , Vector3 . one ) ;
}
}