lygia
/lighting
/pbr
)Simple PBR shading model
Dependencies:
lygia
/math
/saturate
.glsl
lygia
/lighting
/shadingData
/new
.glsl
lygia
/lighting
/material
.glsl
lygia
/lighting
/light
/new
.glsl
lygia
/lighting
/light
/resolve
.glsl
lygia
/lighting
/light
/iblEvaluate
.glsl
Use:
<vec4> pbr( <Material> material )
#ifndef DIFFUSE_FNC
#define DIFFUSE_FNC diffuseLambertConstant
#endif
#ifndef SPECULAR_FNC
#define SPECULAR_FNC specularCookTorrance
#endif
#ifndef CAMERA_POSITION
#define CAMERA_POSITION vec3(0.0, 0.0, -10.0)
#endif
#ifndef FNC_PBR
#define FNC_PBR
vec4 pbr(const Material mat, ShadingData shadingData) {
shadingDataNew(mat, shadingData);
// Indirect Lights ( Image Based Lighting )
// ----------------------------------------
lightIBLEvaluate(mat, shadingData);
// Direct Lights
// -------------
{
#if defined(LIGHT_DIRECTION)
LightDirectional L = LightDirectionalNew();
lightResolve(L, mat, shadingData);
#elif defined(LIGHT_POSITION)
LightPoint L = LightPointNew();
lightResolve(L, mat, shadingData);
#endif
#if defined(LIGHT_POINTS) && defined(LIGHT_POINTS_TOTAL)
for (int i = 0; i < LIGHT_POINTS_TOTAL; i++) {
LightPoint L = LIGHT_POINTS[i];
lightResolve(L, mat, shadingData);
}
#endif
}
// Final Sum
// ---------
vec4 color = vec4(0.0, 0.0, 0.0, 1.0);
// Diffuse
color.rgb += shadingData.indirectDiffuse;
color.rgb += shadingData.directDiffuse;
// Specular
color.rgb += shadingData.indirectSpecular;
color.rgb += shadingData.directSpecular;
color.rgb += mat.emissive;
color.a = mat.albedo.a;
return color;
}
vec4 pbr(const in Material mat) {
ShadingData shadingData = shadingDataNew();
shadingData.V = normalize(CAMERA_POSITION - mat.position);
return pbr(mat, shadingData);
}
#endif
Dependencies:
lygia
/lighting
/shadingData
/new
.glsl
lygia
/lighting
/material
.glsl
lygia
/lighting
/light
/new
.glsl
lygia
/lighting
/light
/resolve
.glsl
lygia
/lighting
/light
/iblEvaluate
.glsl
Use:
<float4> pbr( <Material> material )
#ifndef DIFFUSE_FNC
#define DIFFUSE_FNC diffuseLambertConstant
#endif
#ifndef SPECULAR_FNC
#define SPECULAR_FNC specularCookTorrance
#endif
#ifndef CAMERA_POSITION
#define CAMERA_POSITION float3(0.0, 0.0, -10.0)
#endif
#ifndef FNC_PBR
#define FNC_PBR
float4 pbr(const Material mat, ShadingData shadingData) {
shadingDataNew(mat, shadingData);
// Indirect Lights ( Image Based Lighting )
// ----------------------------------------
lightIBLEvaluate(mat, shadingData);
// Direct Lights
// -------------
{
#if defined(LIGHT_DIRECTION)
LightDirectional L = LightDirectionalNew();
lightResolve(L, mat, shadingData);
#elif defined(LIGHT_POSITION)
LightPoint L = LightPointNew();
lightResolve(L, mat, shadingData);
#endif
#if defined(LIGHT_POINTS) && defined(LIGHT_POINTS_TOTAL)
for (int i = 0; i < LIGHT_POINTS_TOTAL; i++) {
LightPoint L = LIGHT_POINTS[i];
lightResolve(L, mat, shadingData);
}
#endif
}
// Final Sum
// ---------
float4 color = float4(0.0, 0.0, 0.0, 1.0);
// Diffuse
color.rgb += shadingData.indirectDiffuse;
color.rgb += shadingData.directDiffuse;
// Specular
color.rgb += shadingData.indirectSpecular;
color.rgb += shadingData.directSpecular;
color.rgb += mat.emissive;
color.a = mat.albedo.a;
return color;
}
float4 pbr(const in Material mat) {
ShadingData shadingData = shadingDataNew();
shadingData.V = normalize(CAMERA_POSITION - mat.position);
return pbr(mat, shadingData);
}
#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.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository