summaryrefslogtreecommitdiffstats
path: root/src/Runtime/res/effectlib/microfacetBSDF.glsllib
diff options
context:
space:
mode:
authorAndy Nichols <andy.nichols@qt.io>2017-12-07 10:56:06 +0100
committerTomi Korpipää <tomi.korpipaa@qt.io>2017-12-14 06:56:38 +0000
commitf28c93051d3bb9a800a4a3a04209aea5f16ab1a9 (patch)
tree9ca98aa63d57dea1adb6313f9a745a39caf1278d /src/Runtime/res/effectlib/microfacetBSDF.glsllib
parent611f47ded9a119edb3a8bed39387958f5fc3a655 (diff)
Convert Tabs -> Spaces and Removed trailing whitespace from effectlib
This was done to make syncing the effectlib shaders in 3D Studio with the effectlib shaders in the 2.0 runtime where they had already been sanitized. This makes the diffing process easier, and will also bring things into line with the Qt coding standard. Change-Id: I0c45dcb7110cc31a24cce24d72b53e1d451b701b Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src/Runtime/res/effectlib/microfacetBSDF.glsllib')
-rw-r--r--src/Runtime/res/effectlib/microfacetBSDF.glsllib240
1 files changed, 120 insertions, 120 deletions
diff --git a/src/Runtime/res/effectlib/microfacetBSDF.glsllib b/src/Runtime/res/effectlib/microfacetBSDF.glsllib
index 1bdd2fee..e164fcad 100644
--- a/src/Runtime/res/effectlib/microfacetBSDF.glsllib
+++ b/src/Runtime/res/effectlib/microfacetBSDF.glsllib
@@ -34,91 +34,91 @@
float GtermSchlick( in mat3 tanFrame, in vec3 l, in vec3 v, in float roughness )
{
- float NdotV = clamp(dot(tanFrame[2], v), 0.0, 1.0);
- float NdotL = clamp(dot(tanFrame[2], l), 0.0, 1.0);
- float k = roughness*roughness*0.79788;
+ float NdotV = clamp(dot(tanFrame[2], v), 0.0, 1.0);
+ float NdotL = clamp(dot(tanFrame[2], l), 0.0, 1.0);
+ float k = roughness*roughness*0.79788;
- float G_V = NdotV / (NdotV * (1.0 + k) + k);
- float G_L = NdotL / (NdotL * (1.0 + k) + k);
+ float G_V = NdotV / (NdotV * (1.0 + k) + k);
+ float G_L = NdotL / (NdotL * (1.0 + k) + k);
- return clamp(( G_V * G_L ), 0.0, 1.0);
+ return clamp(( G_V * G_L ), 0.0, 1.0);
}
float GtermGGX( in mat3 tanFrame, in vec3 l, in vec3 v, in float roughness )
{
- float NdotV = clamp(dot(tanFrame[2], v), 0.0, 1.0);
- float NdotL = clamp(dot(tanFrame[2], l), 0.0, 1.0);
- float k = clamp(roughness*roughness, 0.00, 1.0);
+ float NdotV = clamp(dot(tanFrame[2], v), 0.0, 1.0);
+ float NdotL = clamp(dot(tanFrame[2], l), 0.0, 1.0);
+ float k = clamp(roughness*roughness, 0.00, 1.0);
- float G_V = NdotV + sqrt( (NdotV - NdotV * k) * NdotV + k );
- float G_L = NdotL + sqrt( (NdotL - NdotL * k) * NdotL + k );
+ float G_V = NdotV + sqrt( (NdotV - NdotV * k) * NdotV + k );
+ float G_L = NdotL + sqrt( (NdotL - NdotL * k) * NdotL + k );
- return clamp( 2.0 / ( G_V * G_L ), 0.0, 1.0);
+ return clamp( 2.0 / ( G_V * G_L ), 0.0, 1.0);
}
float DtermGGX( in mat3 tanFrame, in vec3 L, in vec3 V, in float roughness )
{
- float m = clamp(roughness, 0.04, 1.0);
- float m2 = m*m;
+ float m = clamp(roughness, 0.04, 1.0);
+ float m2 = m*m;
- vec3 H = normalize(L + V);
- float NdotH = clamp(dot( tanFrame[2], H ), 0.0001, 1.0);
- float NdotH2 = NdotH * NdotH;
+ vec3 H = normalize(L + V);
+ float NdotH = clamp(dot( tanFrame[2], H ), 0.0001, 1.0);
+ float NdotH2 = NdotH * NdotH;
- float denom = NdotH2 * (m2 - 1.0) + 1.0;
- float D = m2 / (PI * denom * denom);
+ float denom = NdotH2 * (m2 - 1.0) + 1.0;
+ float D = m2 / (PI * denom * denom);
- return max( 0.0, D);
+ return max( 0.0, D);
}
float DtermGGXAniso( in mat3 tanFrame, in vec3 L, in vec3 V, in float roughnessU, float roughnessV )
{
- float roughU = clamp(roughnessU, 0.04, 1.0);
- float roughV = clamp(roughnessV, 0.04, 1.0);
- vec3 H = normalize(L + V);
- float NdotH = clamp( dot(tanFrame[2], H), 0.0001, 1.0 );
- float m = PI * roughU * roughV;
- float HdotX = clamp( abs(dot(H, tanFrame[0])), 0.0001, 1.0 );
+ float roughU = clamp(roughnessU, 0.04, 1.0);
+ float roughV = clamp(roughnessV, 0.04, 1.0);
+ vec3 H = normalize(L + V);
+ float NdotH = clamp( dot(tanFrame[2], H), 0.0001, 1.0 );
+ float m = PI * roughU * roughV;
+ float HdotX = clamp( abs(dot(H, tanFrame[0])), 0.0001, 1.0 );
float HdotY = clamp( abs(dot(H, tanFrame[1])), 0.0001, 1.0 );
- float x2 = roughU*roughU;
- float y2 = roughV*roughV;
+ float x2 = roughU*roughU;
+ float y2 = roughV*roughV;
- float D = (HdotX*HdotX/x2) + (HdotY*HdotY/y2) + (NdotH*NdotH);
- D = 1.0 / ( m * D * D );
+ float D = (HdotX*HdotX/x2) + (HdotY*HdotY/y2) + (NdotH*NdotH);
+ D = 1.0 / ( m * D * D );
- return max( 0.0, D);
+ return max( 0.0, D);
}
vec4 microfacetBSDF( in mat3 tanFrame, in vec3 L, in vec3 V, in vec3 lightSpecular, float ior,
in float roughnessU, in float roughnessV, int mode )
-{
- vec4 rgba = vec4( 0.0f, 0.0f, 0.0f, 1.0f );
- vec3 H = normalize(L + V);
- float HdotL = clamp(dot(H, L), 0.0, 1.0);
- float NdotL = dot(tanFrame[2], L);
-
- if ( NdotL > 0.0 )
- {
- if ( ( mode == scatter_reflect ) || ( mode == scatter_reflect_transmit ) )
- {
- float roughness = calculateRoughness( tanFrame[2], roughnessU, roughnessV, tanFrame[0] );
- // G term
- //float G = GtermSchlick( tanFrame, L, V, roughness );
- float G = GtermGGX( tanFrame, L, V, roughness );
-
- //float D = DtermGGX( tanFrame, L, V, roughness );
- float D = DtermGGXAniso( tanFrame, L, V, roughnessU, roughnessV );
- rgba.rgb = G * D * NdotL * lightSpecular;
- }
-
- if ( ( mode == scatter_transmit ) || ( mode == scatter_reflect_transmit ) )
- {
- rgba.a = pow(1.0 - clamp(HdotL, 0.0, 1.0), 5.0);
- }
- }
-
- return rgba;
+{
+ vec4 rgba = vec4( 0.0f, 0.0f, 0.0f, 1.0f );
+ vec3 H = normalize(L + V);
+ float HdotL = clamp(dot(H, L), 0.0, 1.0);
+ float NdotL = dot(tanFrame[2], L);
+
+ if ( NdotL > 0.0 )
+ {
+ if ( ( mode == scatter_reflect ) || ( mode == scatter_reflect_transmit ) )
+ {
+ float roughness = calculateRoughness( tanFrame[2], roughnessU, roughnessV, tanFrame[0] );
+ // G term
+ //float G = GtermSchlick( tanFrame, L, V, roughness );
+ float G = GtermGGX( tanFrame, L, V, roughness );
+
+ //float D = DtermGGX( tanFrame, L, V, roughness );
+ float D = DtermGGXAniso( tanFrame, L, V, roughnessU, roughnessV );
+ rgba.rgb = G * D * NdotL * lightSpecular;
+ }
+
+ if ( ( mode == scatter_transmit ) || ( mode == scatter_reflect_transmit ) )
+ {
+ rgba.a = pow(1.0 - clamp(HdotL, 0.0, 1.0), 5.0);
+ }
+ }
+
+ return rgba;
}
vec4 microfacetBSDFEnvironment( in mat3 tanFrame, in vec3 viewDir, in float roughnessU, in float roughnessV, int mode )
@@ -130,7 +130,7 @@ vec4 microfacetBSDFEnvironment( in mat3 tanFrame, in vec3 viewDir, in float roug
float roughness = calculateRoughness( tanFrame[2], roughnessU, roughnessV, tanFrame[0] );
vec3 R = reflect( -viewDir, tanFrame[2] );
rgb = 0.01 * evalEnvironmentMap( R, roughness );
- rgb = microfacetBSDF( tanFrame, R, viewDir, rgb, 1.0f, roughnessU, roughnessV, scatter_reflect ).rgb;
+ rgb = microfacetBSDF( tanFrame, R, viewDir, rgb, 1.0f, roughnessU, roughnessV, scatter_reflect ).rgb;
}
#endif
return( vec4( rgb, 1.0f ) );
@@ -139,7 +139,7 @@ vec4 microfacetBSDFEnvironment( in mat3 tanFrame, in vec3 viewDir, in float roug
// see http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
-float radicalInverse_VdC( uint bits)
+float radicalInverse_VdC( uint bits)
{
bits = (bits << 16u) | (bits >> 16u);
bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
@@ -149,74 +149,74 @@ float radicalInverse_VdC( uint bits)
return float(bits) * 2.3283064365386963e-10; // / 0x100000000
}
-vec2 hammersley2d(uint i, uint N)
+vec2 hammersley2d(uint i, uint N)
{
return vec2(float(i)/float(N), radicalInverse_VdC(i));
}
vec2 hammersly[4] = vec2[4] (
- vec2(0.0, 0.0),
- vec2(0.25, 0.5),
- vec2(0.5, 0.25),
- vec2(0.75, 0.75)
- );
+ vec2(0.0, 0.0),
+ vec2(0.25, 0.5),
+ vec2(0.5, 0.25),
+ vec2(0.75, 0.75)
+ );
vec3 ImportanceGGX( in mat3 tanFrame, vec2 Xi, float roughness , vec3 N )
{
- float a = roughness * roughness;
- float Phi = 2.0 * PI * Xi.y;
- float CosTheta = (1.0 - Xi.x);
- float SinTheta = sqrt( 1.0 - CosTheta * CosTheta );
-
- vec3 H;
- H.x = SinTheta * cos( Phi );
- H.y = SinTheta * sin( Phi );
- H.z = CosTheta;
-
- // Tangent to world space
- return tanFrame[0] * H.x + tanFrame[1] * H.y + tanFrame[2] * H.z;
+ float a = roughness * roughness;
+ float Phi = 2.0 * PI * Xi.y;
+ float CosTheta = (1.0 - Xi.x);
+ float SinTheta = sqrt( 1.0 - CosTheta * CosTheta );
+
+ vec3 H;
+ H.x = SinTheta * cos( Phi );
+ H.y = SinTheta * sin( Phi );
+ H.z = CosTheta;
+
+ // Tangent to world space
+ return tanFrame[0] * H.x + tanFrame[1] * H.y + tanFrame[2] * H.z;
}
float DtermGGXAnisoSampled( in mat3 tanFrame, in vec3 H, in float roughnessU, float roughnessV )
{
#if (MATERIAL_IS_NON_DIELECTRIC == 1)
- float roughU = clamp(roughnessU*roughnessU, 0.01, 1.0);
- float roughV = clamp(roughnessV*roughnessV, 0.01, 1.0);
+ float roughU = clamp(roughnessU*roughnessU, 0.01, 1.0);
+ float roughV = clamp(roughnessV*roughnessV, 0.01, 1.0);
#else
- float roughU = clamp(roughnessU, 0.02, 1.0);
- float roughV = clamp(roughnessV, 0.02, 1.0);
+ float roughU = clamp(roughnessU, 0.02, 1.0);
+ float roughV = clamp(roughnessV, 0.02, 1.0);
#endif
-
- float NdotH = clamp( dot(tanFrame[2], H), 0.0001, 1.0 );
- float m = PI * roughU * roughV;
- float HdotX = clamp( abs(dot(H, tanFrame[0])), 0.0001, 1.0 );
+
+ float NdotH = clamp( dot(tanFrame[2], H), 0.0001, 1.0 );
+ float m = PI * roughU * roughV;
+ float HdotX = clamp( abs(dot(H, tanFrame[0])), 0.0001, 1.0 );
float HdotY = clamp( abs(dot(H, tanFrame[1])), 0.0001, 1.0 );
- float x2 = roughU*roughU;
- float y2 = roughV*roughV;
+ float x2 = roughU*roughU;
+ float y2 = roughV*roughV;
- float pdf = (HdotX*HdotX/x2) + (HdotY*HdotY/y2) + (NdotH*NdotH);
- float D = 1.0 / ( m * pdf * pdf );
+ float pdf = (HdotX*HdotX/x2) + (HdotY*HdotY/y2) + (NdotH*NdotH);
+ float D = 1.0 / ( m * pdf * pdf );
- return max( 0.0, D);
+ return max( 0.0, D);
}
vec3 sampleEnv(in vec3 L, float pdf, uint sampleCount, float roughness )
{
- vec2 envMapSize = vec2( textureSize( uEnvironmentTexture, 0 ) );
- float envMapLevels = log2( max( envMapSize.x, envMapSize.y ) );
+ vec2 envMapSize = vec2( textureSize( uEnvironmentTexture, 0 ) );
+ float envMapLevels = log2( max( envMapSize.x, envMapSize.y ) );
- float a = 0.5*log2( float(envMapSize.x*envMapSize.y) / float(sampleCount) );
- float d = 4.0 * (abs(L.z) + 1.0) * (abs(L.z) + 1.0);
- float b = 0.5*log2( pdf * d );
+ float a = 0.5*log2( float(envMapSize.x*envMapSize.y) / float(sampleCount) );
+ float d = 4.0 * (abs(L.z) + 1.0) * (abs(L.z) + 1.0);
+ float b = 0.5*log2( pdf * d );
- // convert coord to 2D
- vec2 tc = vec2( ( atan( L.x, -L.z ) + PI ) / ( 2.0f * PI ), acos( -L.y ) / PI );
- float weight = step( 0.0001, roughness );
+ // convert coord to 2D
+ vec2 tc = vec2( ( atan( L.x, -L.z ) + PI ) / ( 2.0f * PI ), acos( -L.y ) / PI );
+ float weight = step( 0.0001, roughness );
- float lod = max( 0.0, min( (a - b)*weight, envMapLevels ));
+ float lod = max( 0.0, min( (a - b)*weight, envMapLevels ));
- return( textureLod( uEnvironmentTexture, tc, lod ).rgb );
+ return( textureLod( uEnvironmentTexture, tc, lod ).rgb );
}
vec4 microfacetSampledBSDF( in mat3 tanFrame, in vec3 viewDir, in float roughnessU, in float roughnessV, int mode )
@@ -230,25 +230,25 @@ vec4 microfacetSampledBSDF( in mat3 tanFrame, in vec3 viewDir, in float roughnes
const uint NumSamples = 4u;
for( uint i = 0u; i < NumSamples; i++ )
{
- vec2 Xi = hammersly[i]; // pre computed values
- //vec2 Xi = hammersley2d(i, NumSamples);
- vec3 Half = ImportanceGGX( tanFrame, Xi, roughness , tanFrame[2] );
- vec3 H = normalize( Half );
-
- vec3 L = 2.0 * dot( viewDir, Half ) * Half - viewDir;
- float NdotV = clamp( dot( tanFrame[2], viewDir ), 0.0001, 1.0 );
- float NdotR = clamp( dot( tanFrame[2], R ), 0.0, 1.0 );
- float NdotH = clamp( dot( tanFrame[2], H ), 0.0001, 1.0 );
-
- if( NdotV > 0.0001 )
- {
- float G = GtermGGX( tanFrame, L, viewDir, roughness );
- float D = DtermGGXAnisoSampled( tanFrame, H, roughnessU, roughnessV);
-
- vec3 envColor = 0.01 * sampleEnv( L, D, NumSamples, roughness );
-
- rgb += (envColor * G * D * NdotR) / ( 4.0 * NdotV * NdotH);
- }
+ vec2 Xi = hammersly[i]; // pre computed values
+ //vec2 Xi = hammersley2d(i, NumSamples);
+ vec3 Half = ImportanceGGX( tanFrame, Xi, roughness , tanFrame[2] );
+ vec3 H = normalize( Half );
+
+ vec3 L = 2.0 * dot( viewDir, Half ) * Half - viewDir;
+ float NdotV = clamp( dot( tanFrame[2], viewDir ), 0.0001, 1.0 );
+ float NdotR = clamp( dot( tanFrame[2], R ), 0.0, 1.0 );
+ float NdotH = clamp( dot( tanFrame[2], H ), 0.0001, 1.0 );
+
+ if( NdotV > 0.0001 )
+ {
+ float G = GtermGGX( tanFrame, L, viewDir, roughness );
+ float D = DtermGGXAnisoSampled( tanFrame, H, roughnessU, roughnessV);
+
+ vec3 envColor = 0.01 * sampleEnv( L, D, NumSamples, roughness );
+
+ rgb += (envColor * G * D * NdotR) / ( 4.0 * NdotV * NdotH);
+ }
}
rgb /= float(NumSamples);