Created
January 7, 2014 17:34
-
-
Save bhouston/8303102 to your computer and use it in GitHub Desktop.
Common.glsl so far
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vec4 inputGamma( const in vec4 input_rgba ) { | |
#ifdef GAMMA_INPUT | |
vec4 output_rgba = input_rgba; | |
output_rgba.xyz * output_rgba.xyz; | |
return output_rgba; | |
#else | |
return input_rgba; | |
#endif | |
} | |
vec3 rgbaToNormal( input_rgba, normal_scale ) { | |
vec3 output_normal = input_rgba.xyz * 2.0 - 1.0; | |
output_normal.xy *= normal_scale; | |
output_normal = normalize( output_normal ); | |
return normalTex; | |
} | |
float halfDot( const in vec3 surfaceNormal, const in vec3 lightNormal ) { | |
return 0.5 * dot( surfaceNormal, lightNormal ) + 0.5; | |
} | |
float lambertDiffuse( const in vec3 surfaceNormal, const in vec3 lightNormal ) { | |
#ifdef HALF_LAMBERT | |
return max( halfDot( surfaceNormal, lightNormal ), 0.0 ); | |
#else | |
return max( dot( surfaceNormal, lightNormal ), 0.0 ); | |
#endif | |
} | |
float lightDistanceFadeOutAlpha( const in vec3 lightSurfaceDelta, const in float lightDistance ) { | |
float alpha = 1.0; | |
if ( lightDistance > 0.0 ) | |
alpha = 1.0 - min( ( length( lightSurfaceDelta ) / lightDistance ), 1.0 ); | |
return alpha; | |
} | |
vec3 schlickCoeff( specularColor, lightNormal, lightHalfNormal ) { | |
return specularColor + vec3( 1.0 - specularColor ) * pow( 1.0 - dot( lightNormal, lightHalfNormal ), 5.0 ); | |
} | |
float specularCoeff( shininessFactor, lightDotNormalHalf, shininess ) { | |
return shininessFactor.r * max( pow( lightDotNormalHalf, shininess ), 0.0 ); | |
} | |
vec3 schlickSpecular( const in vec3 specularColor, const in vec3 surfaceNormal, const in vec3 viewNormal, const in vec3 lightNormal, const in vec3 shininessFactor, const in float shininess ) { | |
vec3 lightHalfNormal = normalize( lightNormal + viewNormal ); | |
float lightDotNormalHalf = max( dot( normal, lightHalfNormal ), 0.0 ); | |
float specularWeight = specularCoeff( shininessFactor, lightDotNormalHalf, shininess ); | |
float specularNormalization = ( shininess + 2.0001 ) / 8.0; | |
vec3 schlick = schlickCoeff( specularColor, lightNormal, lightHalfNormal ); | |
return schlick * specularWeight * specularNormalization; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment