Hochwertiger HTML5 und Javascript Code von dem Designbüro Standardabweichung aus München

WebGL GLSL Cook-Torrance Shader Hilight Function

Das HTML5 und Javascript Bild von Standardabweichung aus München

Specular Hilight Cook-Torrance

Funktion zum Berechnen eines Cook-Torrance Specular Hilights in WebGL bzw. OpenGL ES2 Shadern.

float specularCookTorrance( float roughnessValue, float fresnelReflectance, float IOR, vec3 surfacePosition, vec3 surfaceNormal, vec3 lightDirection, float lambertFactor ) { vec3 viewDirection = normalize( -surfacePosition ); vec3 halfDirection = normalize( lightDirection + viewDirection ); float NdotH = max(dot(surfaceNormal, halfDirection), 0.0); float NdotV = max(dot(surfaceNormal, viewDirection), 0.0); float VdotH = max(dot(viewDirection, halfDirection), 0.0); float roughnessSquared = roughnessValue * roughnessValue; float NH2 = 2.0 * NdotH; float g1 = (NH2 * NdotV) / VdotH; float g2 = (NH2 * lambertFactor) / VdotH; float geoAtt = min(1.0, min(g1, g2)); float r1 = 1.0 / ( 4.0 * roughnessSquared * pow(NdotH, 4.0)); float r2 = (NdotH * NdotH - 1.0) / (roughnessSquared * NdotH * NdotH); float roughness = r1 * exp(r2); float fresnel = pow(1.0 - VdotH, 5.0); fresnel *= (1.0 - fresnelReflectance); fresnel += fresnelReflectance; float factor = (fresnel * geoAtt * roughness) / (NdotV * lambertFactor * IOR); return factor; }

HTML5 / Javascript Code Teilen

Javascript Snippet auf Facebook teilen  Facebook
Javascript Snippet auf Facebook teilen  Google+