PBR fixing, episode 572
This commit is contained in:
parent
f141a948ac
commit
dbac828891
3 changed files with 51 additions and 24 deletions
shaders/lib
|
@ -24,9 +24,8 @@ struct T_PBRPrecomputed
|
|||
float PBR_SchlickFresnel(
|
||||
in float u )
|
||||
{
|
||||
const float m = clamp( 1 - u , 0 , 1 ) ,
|
||||
m2 = m * m;
|
||||
return m2 * m2 * m;
|
||||
const float m = 1 - u , m2 = M_Sqr( m );
|
||||
return M_Sqr( m2 ) * m;
|
||||
}
|
||||
|
||||
float PBR_GTR2Aniso(
|
||||
|
@ -38,7 +37,7 @@ float PBR_GTR2Aniso(
|
|||
{
|
||||
float x = hDotX / ax , y = hDotY / ay ,
|
||||
p = x * x + y * y + nDotH * nDotH;
|
||||
return 1 / ( PI * ax * ay * p * p );
|
||||
return 1 / ( ax * ay * p * p );
|
||||
}
|
||||
|
||||
float PBR_SmithGGXAniso(
|
||||
|
@ -59,7 +58,7 @@ T_PBRPrecomputed PBR_Precompute(
|
|||
{
|
||||
T_PBRPrecomputed rv;
|
||||
|
||||
rv.nDotV = dot( normal , camDir );
|
||||
rv.nDotV = abs( dot( normal , camDir ) ) + 1e-5;
|
||||
rv.fv = PBR_SchlickFresnel( rv.nDotV );
|
||||
|
||||
float tDir = step( .99 , abs( normal.z ) ) ,
|
||||
|
@ -93,19 +92,21 @@ vec3 PBR_Shade(
|
|||
in vec3 lightDir )
|
||||
{
|
||||
float nDotL = dot( normal , lightDir );
|
||||
if ( nDotL < 0 || pre.nDotV < 0 ) {
|
||||
if ( nDotL < 0 ) {
|
||||
return vec3( 0 );
|
||||
}
|
||||
|
||||
vec3 halfVec = normalize( lightDir + camDir ) ;
|
||||
float nDotH = dot( normal , halfVec ) ,
|
||||
lDotH = dot( lightDir , halfVec ) ,
|
||||
float nDotH = M_Saturate( dot( normal , halfVec ) ) ,
|
||||
lDotH = M_Saturate( dot( lightDir , halfVec ) ) ,
|
||||
|
||||
// Diffuse fresnel - go from 1 at normal incidence to .5 at grazing
|
||||
// and mix in diffuse retro-reflection based on roughness
|
||||
FL = PBR_SchlickFresnel( nDotL ) ,
|
||||
Fd90 = 0.5 + 2 * lDotH * lDotH * material.roughness ,
|
||||
Fd = mix( 1 , Fd90 , FL ) * mix( 1 , Fd90 , pre.fv ) ,
|
||||
Fd90 = ( 0.5 + 2 * lDotH * lDotH ) * material.roughness ,
|
||||
Fd = ( 1 + ( Fd90 - 1 ) * FL )
|
||||
* ( 1 + ( Fd90 - 1 ) * pre.fv )
|
||||
* ( 1 - 0.51 * material.roughness / 1.51 ) ,
|
||||
|
||||
// Based on Hanrahan-Krueger brdf approximation of isotropic bssrdf
|
||||
// 1.25 scale is used to (roughly) preserve albedo
|
||||
|
@ -124,11 +125,10 @@ vec3 PBR_Shade(
|
|||
pre.ax , pre.ay ) * pre.vgs;
|
||||
|
||||
vec3 Fs = mix( pre.cSpecular , vec3(1) , FH );
|
||||
return nDotL * ( ( ( 1 / PI )
|
||||
* mix( Fd , ss , material.subsurface )
|
||||
* material.cAlbedo /* + Fsheen */)
|
||||
* pow( 1 - material.metallic , 3 )
|
||||
+ Gs * Fs * Ds );
|
||||
return nDotL * ( mix( Fd , ss , material.subsurface )
|
||||
* material.cAlbedo
|
||||
* ( 1 - material.metallic )
|
||||
+ Gs * Fs * Ds ) / PI;
|
||||
}
|
||||
|
||||
vec3 PBR_Shade(
|
||||
|
|
|
@ -36,7 +36,7 @@ vec3 M_NormalizeColor(
|
|||
float M_Saturate(
|
||||
in float x )
|
||||
{
|
||||
return clamp( x , 0 , 1 );
|
||||
return clamp( x , 0. , 1. );
|
||||
}
|
||||
|
||||
float M_LengthSqr(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue