LYGIA Shader Library

pbrLittle (lygia/lighting/pbrLittle)

simple PBR shading model

Dependencies:

Use:

<vec4> pbrLittle(<Material> material)
<vec4> pbrLittle(<vec4> albedo, <vec3> normal, <float> roughness, <float> metallic [, <vec3> f0] )

Check it on Github






#ifndef CAMERA_POSITION
#define CAMERA_POSITION vec3(0.0, 0.0, -10.0)
#endif

#ifndef LIGHT_POSITION
#define LIGHT_POSITION  vec3(0.0, 10.0, -50.0)
#endif

#ifndef LIGHT_COLOR
#define LIGHT_COLOR     vec3(0.5)
#endif

#ifndef FNC_PBR_LITTLE
#define FNC_PBR_LITTLE

vec4 pbrLittle( vec4 _albedo, vec3 _position, vec3 _normal, float _roughness, float _metallic, vec3 _f0, // Material Basic
                vec3 ior, float thickness,                                                               // Material Iridescence
                float shadow  ) {                                                                        // Light       

    #ifdef LIGHT_DIRECTION
    vec3 L = normalize(LIGHT_DIRECTION);
    #else
    vec3 L = normalize(LIGHT_POSITION - _position);
    #endif
    vec3 N = normalize(_normal);
    vec3 V = normalize(CAMERA_POSITION - _position);

    float notMetal = 1. - _metallic;
    float smooth = .95 - saturate(_roughness);

    // DIFFUSE
    float diff = diffuse(L, N, V, _roughness) * shadow;
    float spec = specular(L, N, V, _roughness) * shadow;

    _albedo.rgb = _albedo.rgb * diff;
#ifdef SCENE_SH_ARRAY
    _albedo.rgb *= tonemapReinhard( sphericalHarmonics(N) );
#endif

    float NoV = dot(N, V); 

    // SPECULAR
    // This is a bit of a stilistic proach
    float specIntensity =   (0.04 * notMetal + 2.0 * _metallic) * 
                            saturate(-1.1 + NoV + _metallic) * // Fresnel
                            (_metallic + smooth * 4.0); // make smaller highlights brighter

    vec3 R = reflect(-V, N);
    vec3 ambientSpecular = tonemapReinhard( envMap(R, _roughness, _metallic) ) * specIntensity;
    ambientSpecular += fresnelReflection(R, _f0, NoV);

    _albedo.rgb = _albedo.rgb * notMetal + ( ambientSpecular 
                    + LIGHT_COLOR * 2.0 * spec
                    ) * (notMetal * smooth + _albedo.rgb * _metallic);

    return _albedo;
}

vec4 pbrLittle(vec4 albedo, vec3 position, vec3 normal, float roughness, float metallic, vec3 f0, float shadow) {
    return pbrLittle(albedo, position, normal, roughness, metallic, f0, vec3(IOR_GLASS), 2000.0, shadow);
}

vec4 pbrLittle(vec4 albedo, vec3 position, vec3 normal, float roughness, float metallic, float shadow) {
    return pbrLittle(albedo, position, normal, roughness, metallic, vec3(0.04), shadow);
}

vec4 pbrLittle(vec4 albedo, vec3 position, vec3 normal, float roughness, float metallic) {
    return pbrLittle(albedo, position, normal, roughness, metallic, vec3(0.04), 1.0);
}

vec4 pbrLittle(vec4 albedo, vec3 normal, float roughness, float metallic) {
    return pbrLittle(albedo, vec3(0.0), normal, roughness, metallic, vec3(0.04), 1.0);
}

vec4 pbrLittle(Material material) {
    float s = 1.0;
    #if defined(LIGHT_SHADOWMAP) && defined(LIGHT_SHADOWMAP_SIZE) && defined(LIGHT_COORD)
    s *= shadow(LIGHT_SHADOWMAP, vec2(LIGHT_SHADOWMAP_SIZE), (LIGHT_COORD).xy, (LIGHT_COORD).z);
    #endif
    return pbrLittle(material.albedo, material.position, material.normal, material.roughness, material.metallic, material.f0, material.ior, material.thickness, material.ambientOcclusion * s) + vec4(material.emissive, 0.0);
}

#endif

Dependencies:

Use:

<float4> pbrLittle(<Material> material)
<float4> pbrLittle(<float4> albedo, <float3> normal, <float> roughness, <float> metallic [, <float3> f0] )

Check it on Github





#ifndef CAMERA_POSITION
#if defined(UNITY_COMPILER_HLSL)
#define CAMERA_POSITION _WorldSpaceCameraPos
#else
#define CAMERA_POSITION float3(0.0, 0.0, -10.0)
#endif
#endif

#ifndef LIGHT_POSITION
#if defined(UNITY_COMPILER_HLSL)
#define LIGHT_POSITION _WorldSpaceLightPos0.xyz
#else
#define LIGHT_POSITION  float3(0.0, 10.0, -50.0)
#endif
#endif

#ifndef LIGHT_COLOR
#if defined(UNITY_COMPILER_HLSL)
#define LIGHT_COLOR     _LightColor0.rgb
#else
#define LIGHT_COLOR     float3(0.5, 0.5, 0.5)
#endif
#endif

#ifndef FNC_PBR_LITTLE
#define FNC_PBR_LITTLE

float4 pbrLittle(float4 albedo, float3 position, float3 normal, float roughness, float metallic, float3 f0, float shadow ) {
    #ifdef LIGHT_DIRECTION
    float3 L = normalize(LIGHT_DIRECTION);
    #else
    float3 L = normalize(LIGHT_POSITION - position);
    #endif
    float3 N = normalize(normal);
    float3 V = normalize(CAMERA_POSITION - position);

    float notMetal = 1. - metallic;
    float smooth = .95 - saturate(roughness);

    // DIFFUSE
    float diff = diffuse(L, N, V, roughness) * shadow;
    float spec = specular(L, N, V, roughness) * shadow;

    albedo.rgb = albedo.rgb * diff;
    #if defined(UNITY_COMPILER_HLSL)
    albedo.rgb *= ShadeSH9(half4(N,1));
    #elif defined(SCENE_SH_ARRAY)
    albedo.rgb *= tonemapReinhard( sphericalHarmonics(N) );
    #endif

    float NoV = dot(N, V); 

    // SPECULAR
    float3 specIntensity =  float3(1.0, 1.0, 1.0) *
                            (0.04 * notMetal + 2.0 * metallic) * 
                            saturate(-1.1 + NoV + metallic) * // Fresnel
                            (metallic + smooth * 4.0); // make smaller highlights brighter

    float3 R = reflect(-V, N);
    float3 ambientSpecular = tonemapReinhard( envMap(R, roughness, metallic) ) * specIntensity;
    ambientSpecular += fresnelReflection(R, f0, NoV) * metallic;

    albedo.rgb =    albedo.rgb * notMetal + ( ambientSpecular 
                    + LIGHT_COLOR * 2.0 * spec
                    ) * (notMetal * smooth + albedo.rgb * metallic);

    return albedo;
}

float4 pbrLittle(float4 albedo, float3 position, float3 normal, float roughness, float metallic, float shadow) {
    return pbrLittle(albedo, position, normal, roughness, metallic, float3(0.04, 0.04, 0.04), shadow);
}

float4 pbrLittle(Material material) {
    return pbrLittle(material.albedo, material.position, material.normal, material.roughness, material.metallic, material.f0, material.ambientOcclusion * material.shadow) + float4(material.emissive, 0.0);
}

#endif

License

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