lygia
/v1.1.6
/lighting
/pbrLittle
)simple PBR shading model
Dependencies:
lygia
/v1.1.6
/math
/powFast
.glsl
lygia
/v1.1.6
/math
/saturate
.glsl
lygia
/v1.1.6
/color
/tonemap
/reinhard
.glsl
lygia
/v1.1.6
/lighting
/shadow
.glsl
lygia
/v1.1.6
/lighting
/material
.glsl
lygia
/v1.1.6
/lighting
/fresnelReflection
.glsl
lygia
/v1.1.6
/lighting
/envMap
.glsl
lygia
/v1.1.6
/lighting
/sphericalHarmonics
.glsl
lygia
/v1.1.6
/lighting
/diffuse
.glsl
lygia
/v1.1.6
/lighting
/specular
.glsl
lygia
/v1.1.6
/math
/saturate
.glsl
Use:
<vec4> pbrLittle(<Material> material)
<vec4> pbrLittle(<vec4> albedo, <vec3> normal, <float> roughness, <float> metallic [, <vec3> f0] )
#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
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) * _metallic;
_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, 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.ambientOcclusion * s) + vec4(material.emissive, 0.0);
}
#endif
Dependencies:
lygia
/v1.1.6
/math
/powFast
.glsl
lygia
/v1.1.6
/color
/tonemap
.glsl
lygia
/v1.1.6
/lighting
/material
.glsl
lygia
/v1.1.6
/lighting
/fresnelReflection
.glsl
lygia
/v1.1.6
/lighting
/envMap
.glsl
lygia
/v1.1.6
/lighting
/sphericalHarmonics
.glsl
lygia
/v1.1.6
/lighting
/diffuse
.glsl
lygia
/v1.1.6
/lighting
/specular
.glsl
lygia
/v1.1.6
/lighting
/UnityLightingCommon
.glsl
Use:
<float4> pbrLittle(<Material> material)
<float4> pbrLittle(<float4> albedo, <float3> normal, <float> roughness, <float> metallic [, <float3> f0] )
#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
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