LYGIA Shader Library

pointEvaluate (lygia/lighting/light/pointEvaluate)

Calculate point light

Dependencies:

Use:

<void> lightPointEvaluate(<LightPoint> L, <Material> mat, inout <ShadingData> shadingData)

Check it on Github



#ifndef FNC_LIGHT_POINT
#define FNC_LIGHT_POINT

void lightPointEvaluate(LightPoint L, Material mat, inout ShadingData shadingData) {

    float Ldist  = length(L.position);
    vec3 Ldirection = L.position/Ldist;
    shadingData.L = Ldirection;
    shadingData.H = normalize(Ldirection + shadingData.V);
    shadingData.NoL = saturate(dot(shadingData.N, Ldirection));
    shadingData.NoH = saturate(dot(shadingData.N, shadingData.H));

    #ifdef FNC_RAYMARCH_SOFTSHADOW    
    float shadow = raymarchSoftShadow(mat.position, Ldirection);
    #else
    float shadow = 1.0;
    #endif

    float dif  = diffuse(shadingData);
    vec3 spec = specular(shadingData);

    vec3 lightContribution = L.color * L.intensity * shadow * shadingData.NoL;
    if (L.falloff > 0.0)
        lightContribution *= falloff(Ldist, L.falloff);

    shadingData.directDiffuse  += max(vec3(0.0, 0.0, 0.0), shadingData.diffuseColor * lightContribution * dif);
    shadingData.directSpecular += max(vec3(0.0, 0.0, 0.0), lightContribution * spec) * shadingData.energyCompensation;

    // TODO:
    // - make sure that the shadow use a perspective projection
    #ifdef SHADING_MODEL_SUBSURFACE
    float scatterVoH = saturate(dot(shadingData.V, -Ldirection));
    float forwardScatter = exp2(scatterVoH * mat.subsurfacePower - mat.subsurfacePower);
    float backScatter = saturate(shadingData.NoL * mat.subsurfaceThickness + (1.0 - mat.subsurfaceThickness)) * 0.5;
    float subsurface = mix(backScatter, 1.0, forwardScatter) * (1.0 - mat.subsurfaceThickness);
    shadingData.directDiffuse += mat.subsurfaceColor * (subsurface * diffuseLambertConstant());
    #endif
}

#endif

Dependencies:

Use:

<void> lightPointEvaluate(<LightPoint> L, <Material> mat, inout <ShadingData> shadingData)

Check it on Github



#ifndef FNC_LIGHT_POINT
#define FNC_LIGHT_POINT

void lightPointEvaluate(LightPoint L, Material mat, inout ShadingData shadingData) {

    float Ldist  = length(L.position);
    float3 Ldirection = L.position/Ldist;
    shadingData.L = Ldirection;
    shadingData.H = normalize(Ldirection + shadingData.V);
    shadingData.NoL = saturate(dot(shadingData.N, Ldirection));
    shadingData.NoH = saturate(dot(shadingData.N, shadingData.H));

    #ifdef FNC_RAYMARCH_SOFTSHADOW    
    float shadow = raymarchSoftShadow(mat.position, Ldirection);
    #else
    float shadow = 1.0;
    #endif

    float dif  = diffuse(shadingData);
    float3 spec = specular(shadingData);

    float3 lightContribution = L.color * L.intensity * shadow * shadingData.NoL;
    if (L.falloff > 0.0)
        lightContribution *= falloff(Ldist, L.falloff);

    shadingData.directDiffuse  += max(float3(0.0, 0.0, 0.0), shadingData.diffuseColor * lightContribution * dif);
    shadingData.directSpecular += max(float3(0.0, 0.0, 0.0), lightContribution * spec) * shadingData.energyCompensation;

    // TODO:
    // - make sure that the shadow use a perspective projection
    #ifdef SHADING_MODEL_SUBSURFACE
    float scatterVoH = saturate(dot(shadingData.V, -Ldirection));
    float forwardScatter = exp2(scatterVoH * mat.subsurfacePower - mat.subsurfacePower);
    float backScatter = saturate(shadingData.NoL * mat.subsurfaceThickness + (1.0 - mat.subsurfaceThickness)) * 0.5;
    float subsurface = lerp(backScatter, 1.0, forwardScatter) * (1.0 - mat.subsurfaceThickness);
    shadingData.directDiffuse += mat.subsurfaceColor * (subsurface * diffuseLambertConstant());
    #endif
}

#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