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, 0.5, 0.5)
#endif

#ifndef FNC_PBR_LITTLE
#define FNC_PBR_LITTLE

vec4 pbrLittle(Material mat, ShadingData shadingData) {
    shadingDataNew(mat, shadingData);
    #ifdef LIGHT_DIRECTION
    shadingData.L = normalize(LIGHT_DIRECTION);
    #else
    shadingData.L = normalize(LIGHT_POSITION - mat.position);
    #endif
    shadingData.H = normalize(shadingData.L + shadingData.V);
    shadingData.NoL = saturate(dot(shadingData.N, shadingData.L));
    shadingData.NoH = saturate(dot(shadingData.N, shadingData.H));

    float notMetal = 1.0 - mat.metallic;
    float smoothness = 0.95 - saturate(mat.roughness);

    #if defined(LIGHT_SHADOWMAP) && defined(LIGHT_SHADOWMAP_SIZE) && defined(LIGHT_COORD)
    float shadow = shadow(LIGHT_SHADOWMAP, vec2(LIGHT_SHADOWMAP_SIZE), (LIGHT_COORD).xy, (LIGHT_COORD).z);
    #elif defined(FNC_RAYMARCH_SOFTSHADOW)
    float shadow = raymarchSoftShadow(mat.position, shadingData.L);
    #else
    float shadow = 1.0;
    #endif

    // DIFFUSE
    float diff = diffuse(shadingData) * shadow;
    vec3 spec = specular(shadingData) * shadow;

    vec3 albedo = mat.albedo.rgb * diff;
// #ifdef SCENE_SH_ARRAY
//     albedo.rgb += tonemap( sphericalHarmonics(shadingData.N) ) * 0.25;
// #endif

    // SPECULAR
    // This is a bit of a stylistic approach
    float specIntensity =   (0.04 * notMetal + 2.0 * mat.metallic) * 
                            saturate(-1.1 + shadingData.NoV + mat.metallic) * // Fresnel
                            (mat.metallic + smoothness * 4.0); // make smaller highlights brighter

    vec3 ambientSpecular = tonemap( envMap(mat, shadingData) ) * specIntensity;
    ambientSpecular += fresnelReflection(mat, shadingData) * (1.0-mat.roughness);

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

    return vec4(albedo, mat.albedo.a);
}

vec4 pbrLittle(const in Material mat) {
    ShadingData shadingData = shadingDataNew();
    shadingData.V = normalize(CAMERA_POSITION - mat.position);
    return pbrLittle(mat, shadingData);
}

#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
#define CAMERA_POSITION float3(0.0, 0.0, -10.0)
#endif

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

#ifndef LIGHT_COLOR
#define LIGHT_COLOR     float3(0.5, 0.5, 0.5)
#endif

#ifndef FNC_PBR_LITTLE
#define FNC_PBR_LITTLE

float4 pbrLittle(Material mat, ShadingData shadingData) {
    shadingDataNew(mat, shadingData);
    #ifdef LIGHT_DIRECTION
    shadingData.L = normalize(LIGHT_DIRECTION);
    #else
    shadingData.L = normalize(LIGHT_POSITION - mat.position);
    #endif
    shadingData.H = normalize(shadingData.L + shadingData.V);
    shadingData.NoL = saturate(dot(shadingData.N, shadingData.L));
    shadingData.NoH = saturate(dot(shadingData.N, shadingData.H));

    float notMetal = 1.0 - mat.metallic;
    float smoothness = 0.95 - saturate(mat.roughness);

    #if defined(LIGHT_SHADOWMAP) && defined(LIGHT_SHADOWMAP_SIZE) && defined(LIGHT_COORD)
    float shadow = shadow(LIGHT_SHADOWMAP, float2(LIGHT_SHADOWMAP_SIZE), (LIGHT_COORD).xy, (LIGHT_COORD).z);
    #elif defined(FNC_RAYMARCH_SOFTSHADOW)
    float shadow = raymarchSoftShadow(mat.position, shadingData.L);
    #else
    float shadow = 1.0;
    #endif

    // DIFFUSE
    float diff = diffuse(shadingData) * shadow;
    float3 spec = specular(shadingData) * shadow;

    float3 albedo = mat.albedo.rgb * diff;
// #ifdef SCENE_SH_ARRAY
    // _albedo.rgb = _albedo.rgb + tonemapReinhard( sphericalHarmonics(N) ) * 0.25;
// #endif

    // SPECULAR
    // This is a bit of a stylistic approach
    float specIntensity =   (0.04 * notMetal + 2.0 * mat.metallic) * 
                            saturate(-1.1 + shadingData.NoV + mat.metallic) * // Fresnel
                            (mat.metallic + smoothness * 4.0); // make smaller highlights brighter

    float3 ambientSpecular = tonemapReinhard( envMap(mat, shadingData) ) * specIntensity;
    ambientSpecular += fresnelReflection(mat, shadingData) * (1.0-mat.roughness);

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

    return float4(albedo, mat.albedo.a);
}

float4 pbrLittle(const in Material mat) {
    ShadingData shadingData = shadingDataNew();
    shadingData.V = normalize(CAMERA_POSITION - mat.position);
    return pbrLittle(mat, shadingData);
}

#endif

Licenses

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