Created
March 27, 2015 20:41
-
-
Save pyalot/a6f3f3bf1921339ac842 to your computer and use it in GitHub Desktop.
simple physically inspired shading function
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
vec3 shade(vec3 color, float roughness, float metallness){ | |
float fresnelFactor = 0.93; | |
float specularFactor = 0.65; | |
vec3 normal = normalize(vNormal); | |
vec3 eyeDir = getEyeDir(); | |
vec3 N = normal; | |
vec3 V = -eyeDir; | |
vec3 reflected = reflect(eyeDir, normal); | |
vec3 diffuse = textureCube3DLogLuv(envTex, normal, 1.0); | |
vec3 specular = textureCube3DLogLuv(envTex, reflected, roughness); | |
vec3 specularColor = specular*mix(vec3(1), color, metallness); | |
vec3 diffuseColor = diffuse*color; | |
float nonMetallness = 1.0-metallness; | |
float glossiness = 1.0-roughness; | |
float fresnel = pow(1.0-max(0.0, dot(N,V)), 3.5); | |
fresnel = mix(1.0, fresnel, mix(fresnelFactor, fresnelFactor*0.2, metallness)); | |
float specularity = max(metallness, glossiness)*specularFactor*fresnel; | |
vec3 excident = diffuseColor*nonMetallness + specularColor*specularity; | |
return excident; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment