diff options
author | Antti Määttä <antti.maatta@qt.io> | 2019-12-12 14:40:21 +0200 |
---|---|---|
committer | Antti Määttä <antti.maatta@qt.io> | 2019-12-27 11:21:24 +0200 |
commit | c4ed0d6acfc2cb444a5260cbd509a427208f7ac5 (patch) | |
tree | 6ceba81778153e8a28f0fa4ef918c2498cb40b51 /res/effectlib/funcdiffuseReflectionBSDF.glsllib | |
parent | 71190e5a059eba4c911abcfdd599c2a98d674ed0 (diff) |
Optimize and cleanup shaders
Change-Id: Ia27680e20f73ffe645d5a336fad7024e67a8389b
Reviewed-by: Janne Kangas <janne.kangas@qt.io>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'res/effectlib/funcdiffuseReflectionBSDF.glsllib')
-rw-r--r-- | res/effectlib/funcdiffuseReflectionBSDF.glsllib | 39 |
1 files changed, 3 insertions, 36 deletions
diff --git a/res/effectlib/funcdiffuseReflectionBSDF.glsllib b/res/effectlib/funcdiffuseReflectionBSDF.glsllib index bda0ea6..05f54a6 100644 --- a/res/effectlib/funcdiffuseReflectionBSDF.glsllib +++ b/res/effectlib/funcdiffuseReflectionBSDF.glsllib @@ -3,41 +3,8 @@ #define PI_SQUARE ( PI * PI ) #endif -vec4 diffuseReflectionBSDF(in vec3 N, in vec3 L, in vec3 viewDir, - in vec3 lightDiffuse, in float roughness) +vec4 diffuseReflectionBSDF(in vec3 N, in vec3 L, in vec3 lightDiffuse) { - float cosThetaI = max( 0.0, dot( N, L ) ); - float factor = cosThetaI; - if ( ( 0.0 < factor ) && ( 0.0 < roughness ) ) - { - // see http://en.wikipedia.org/wiki/Oren%E2%80%93Nayar_reflectance_model - float sigmaSquare = 0.25 * PI_SQUARE * roughness * roughness; - float A = 1.0 - 0.5 * sigmaSquare / ( sigmaSquare + 0.33 ); - float B = 0.45 * sigmaSquare / ( sigmaSquare + 0.09 ); - - // project L and viewDir on surface to get the azimuthal angle between them - // as we don't really need the projections, but the angle between them, - // it's enough to just use the cross instead - vec3 pl = normalize( cross( L, N ) ); - vec3 pv = normalize( cross( viewDir, N ) ); - float cosPhi = max( 0.0, dot( pl, pv ) ); - - float sinAlpha, tanBeta; - float cosThetaO = max( 0.0, dot( N, viewDir ) ); - float sinThetaI = sqrt( max( 0.0, 1.0 - cosThetaI * cosThetaI ) ); - float sinThetaO = sqrt( max( 0.0, 1.0 - cosThetaO * cosThetaO ) ); - if ( cosThetaI < cosThetaO ) - { // -> thetaO < thetaI - sinAlpha = sinThetaI; - tanBeta = sinThetaO / cosThetaO; - } - else - { - sinAlpha = sinThetaO; - tanBeta = sinThetaI / cosThetaI; - } - - factor *= A + B * cosPhi * sinAlpha * tanBeta; - } - return( vec4( factor * lightDiffuse, 1.0 ) ); + float factor = max(0.0, dot(N, L)); + return vec4(factor * lightDiffuse, 1.0); } |