private Material m_InitPreFGD ;
private RenderTexture m_PreIntegratedFGD ;
// For area lighting
private Texture2D m_LtcGGXMatrix ; // RGBA
private Texture2D m_LtcDisneyDiffuseMatrix ; // RGBA
private Texture2D m_LtcMultiGGXFresnelDisneyDiffuse ; // RGB, A unused
// For area lighting - We pack all texture inside a texture array to reduce the number of resource required
private Texture2DArray m_LtcData ; // 0: m_LtcGGXMatrix - RGBA, 2: m_LtcDisneyDiffuseMatrix - RGBA, 3: m_LtcMultiGGXFresnelDisneyDiffuse - RGB, A unused
Texture2D CreateLUT ( int width , int height , TextureFormat format , Color [ ] pixels )
{
Texture2D tex = new Texture2D ( width , height , format , false /*mipmap*/ , true /*linear*/ ) ;
tex . hideFlags = HideFlags . HideAndDontSave ;
tex . wrapMode = TextureWrapMode . Clamp ;
tex . filterMode = FilterMode . Bilinear ;
tex . SetPixels ( pixels ) ;
tex . Apply ( ) ;
return tex ;
}
Texture2D LoadLUT ( TextureFormat format , float [ ] LUTScalar )
void LoadLUT ( Texture2DArray tex , int arrayElement , TextureFormat format , float [ ] LUTScalar )
{
const int count = k_LtcLUTResolution * k_LtcLUTResolution ;
Color [ ] pixels = new Color [ count ] ;
pixels [ i ] = new Color ( 0 , 0 , 0 , LUTScalar [ i ] ) ;
}
return CreateLUT ( k_LtcLUTResolution , k_LtcLUTResolution , format , pixels ) ;
tex . SetPixels ( pixels , arrayElement ) ;
Texture2D LoadLUT ( TextureFormat format , double [ , ] LUTTransformInv )
void LoadLUT ( Texture2DArray tex , int arrayElement , TextureFormat format , double [ , ] LUTTransformInv )
{
const int count = k_LtcLUTResolution * k_LtcLUTResolution ;
Color [ ] pixels = new Color [ count ] ;
( float ) LUTTransformInv [ i , 6 ] ) ;
}
return CreateLUT ( k_LtcLUTResolution , k_LtcLUTResolution , format , pixels ) ;
tex . SetPixels ( pixels , arrayElement ) ;
Texture2D LoadLUT ( TextureFormat format , float [ ] LtcGGXMagnitudeData ,
float [ ] LtcGGXFresnelData ,
float [ ] LtcDisneyDiffuseMagnitudeData )
void LoadLUT ( Texture2DArray tex , int arrayElement , TextureFormat format , float [ ] LtcGGXMagnitudeData ,
float [ ] LtcGGXFresnelData ,
float [ ] LtcDisneyDiffuseMagnitudeData )
{
const int count = k_LtcLUTResolution * k_LtcLUTResolution ;
Color [ ] pixels = new Color [ count ] ;
LtcGGXFresnelData [ i ] , LtcDisneyDiffuseMagnitudeData [ i ] , 1 ) ;
}
return CreateLUT ( k_LtcLUTResolution , k_LtcLUTResolution , format , pixels ) ;
tex . SetPixels ( pixels , arrayElement ) ;
}
public void Build ( )
m_PreIntegratedFGD . wrapMode = TextureWrapMode . Clamp ;
m_PreIntegratedFGD . Create ( ) ;
m_LtcGGXMatrix = LoadLUT ( TextureFormat . RGBAHalf , s_LtcGGXMatrixData ) ;
m_LtcDisneyDiffuseMatrix = LoadLUT ( TextureFormat . RGBAHalf , s_LtcDisneyDiffuseMatrixData ) ;
m_LtcData = new Texture2DArray ( k_LtcLUTResolution , k_LtcLUTResolution , 3 , TextureFormat . RGBAHalf , false /*mipmap*/ , true /* linear */ )
{
hideFlags = HideFlags . HideAndDontSave ,
wrapMode = TextureWrapMode . Clamp ,
filterMode = FilterMode . Bilinear
} ;
LoadLUT ( m_LtcData , 0 , TextureFormat . RGBAHalf , s_LtcGGXMatrixData ) ;
LoadLUT ( m_LtcData , 1 , TextureFormat . RGBAHalf , s_LtcDisneyDiffuseMatrixData ) ;
m_LtcMultiGGXFresnelDisneyDiffuse = LoadLUT ( TextureFormat . RGBAHalf , s_LtcGGXMagnitudeData ,
s_LtcGGXFresnelData ,
s_LtcDisneyDiffuseMagnitudeData ) ;
LoadLUT ( m_LtcData , 2 , TextureFormat . RGBAHalf , s_LtcGGXMagnitudeData , s_LtcGGXFresnelData , s_LtcDisneyDiffuseMagnitudeData ) ;
m_LtcData . Apply ( ) ;
isInit = false ;
}
public void Bind ( )
{
Shader . SetGlobalTexture ( "_PreIntegratedFGD" , m_PreIntegratedFGD ) ;
Shader . SetGlobalTexture ( "_LtcGGXMatrix" , m_LtcGGXMatrix ) ;
Shader . SetGlobalTexture ( "_LtcDisneyDiffuseMatrix" , m_LtcDisneyDiffuseMatrix ) ;
Shader . SetGlobalTexture ( "_LtcMultiGGXFresnelDisneyDiffuse" , m_LtcMultiGGXFresnelDisneyDiffuse ) ;
Shader . SetGlobalTexture ( "_PreIntegratedFGD" , m_PreIntegratedFGD ) ;
Shader . SetGlobalTexture ( "_LtcData" , m_LtcData ) ;
}
}
}