LYGIA Shader Library

phong (lygia/v1.1.6/lighting/specular/phong)

Dependencies:

Check it on Github


#ifndef SPECULAR_POW
#if defined(TARGET_MOBILE) || defined(PLATFORM_RPI) || defined(PLATFORM_WEBGL)
#define SPECULAR_POW(A,B) powFast(A,B)
#else
#define SPECULAR_POW(A,B) pow(A,B)
#endif
#endif

#ifndef FNC_SPECULAR_PHONG
#define FNC_SPECULAR_PHONG 

// https://github.com/glslify/glsl-specular-phong
float specularPhong(const in vec3 L, const in vec3 N, const in vec3 V, const in float shininess) {
    vec3 R = reflect(L, N); // 2.0 * dot(N, L) * N - L;
    return SPECULAR_POW(max(0.0, dot(R, -V)), shininess);
}

float specularPhongRoughness(const in vec3 L, const in vec3 N, const in vec3 V, const in float roughness) {
    return specularPhong(L, N, V, toShininess(roughness, 0.0) );
}

float specularPhongRoughness(const in vec3 L, const in vec3 N, const in vec3 V, const in float roughness, const in float fresnel) {
    return specularPhongRoughness(L, N, V, roughness );
}

float specularPhongRoughness(const in vec3 L, const in vec3 N, const in vec3 V, const in float NoV, const in float NoL, const in float roughness, const in float fresnel) {
    return specularPhongRoughness(L, N, V, roughness);
}

#endif

Dependencies:

Check it on Github


#ifndef SPECULAR_POW
#if defined(TARGET_MOBILE) || defined(PLATFORM_RPI) || defined(PLATFORM_WEBGL)
#define SPECULAR_POW(A,B) powFast(A,B)
#else
#define SPECULAR_POW(A,B) pow(A,B)
#endif
#endif

#ifndef FNC_SPECULAR_PHONG
#define FNC_SPECULAR_PHONG 

// https://github.com/glslify/glsl-specular-phong
float specularPhong(float3 L, float3 N, float3 V, float shininess) {
    float3 R = reflect(L, N); // 2.0 * dot(N, L) * N - L;
    return SPECULAR_POW(max(0.0, dot(R, -V)), shininess);
}

float specularPhongRoughness(float3 L, float3 N, float3 V, float roughness) {
    return specularPhong(L, N, V, toShininess(roughness, 0.0) );
}

float specularPhongRoughness(float3 L, float3 N, float3 V, float roughness, float fresnel) {
    return specularPhongRoughness(L, N, V, roughness );
}

float specularPhongRoughness(float3 L, float3 N, float3 V, float NoV, float NoL, float roughness, float fresnel) {
    return specularPhongRoughness(L, N, V, roughness);
}

#endif

LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).

It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository