lygia
/v1.1.4
/lighting
/pbrGlass
)simple glass shading model
Dependencies:
lygia
/v1.1.4
/lighting
/material
.glsl
lygia
/v1.1.4
/lighting
/ior
.glsl
lygia
/v1.1.4
/lighting
/specular
.glsl
lygia
/v1.1.4
/lighting
/fresnelReflection
.glsl
lygia
/v1.1.4
/lighting
/ior
/2eta
.glsl
lygia
/v1.1.4
/lighting
/ior
/2f0
.glsl
lygia
/v1.1.4
/lighting
/reflection
.glsl
lygia
/v1.1.4
/lighting
/common
/specularAO
.glsl
lygia
/v1.1.4
/lighting
/common
/envBRDFApprox
.glsl
Use:
<vec4> glass(<Material> material)
#ifndef LIGHT_COLOR
#define LIGHT_COLOR vec3(1.0)
#endif
#ifndef IBL_LUMINANCE
#define IBL_LUMINANCE 1.0
#endif
#ifndef FNC_PBRGLASS
#define FNC_PBRGLASS
vec4 pbrGlass(const Material _mat) {
vec3 V = normalize(CAMERA_POSITION - _mat.position); // View
vec3 N = _mat.normal; // Normal front
vec3 No = _mat.normal; // Normal out
#if defined(SCENE_BACK_SURFACE)
No = normalize( N - _mat.normal_back );
#endif
float roughness = _mat.roughness;
vec3 f0 = ior2f0(_mat.ior);
vec3 eta = ior2eta(_mat.ior);
vec3 Re = reflection(V, N, roughness);
vec3 RaG = refract(-V, No, eta.g);
#if !defined(TARGET_MOBILE) && !defined(PLATFORM_RPI)
vec3 RaR = refract(-V, No, eta.r);
vec3 RaB = refract(-V, No, eta.b);
#endif
float NoV = dot(N, V); // Normal . View
// Global Ilumination ( mage Based Lighting )
// ------------------------
vec3 E = envBRDFApprox(_mat.albedo.rgb, NoV, roughness);
vec3 Fr = vec3(0.0, 0.0, 0.0);
Fr = envMap(Re, roughness) * E;
#if !defined(PLATFORM_RPI)
Fr += tonemap( fresnelReflection(Re, _mat.f0, NoV) ) * (1.0-roughness) * 0.2;
#endif
vec4 color = vec4(0.0, 0.0, 0.0, 1.0);
color.rgb = envMap(RaG, roughness);
#if !defined(TARGET_MOBILE) && !defined(PLATFORM_RPI)
color.r = envMap(RaR, roughness).r;
color.b = envMap(RaB, roughness).b;
#endif
// color.rgb *= exp( -_mat.thickness * 200.0);
color.rgb += Fr * IBL_LUMINANCE;
#if defined(LIGHT_DIRECTION)
color.rgb += LIGHT_COLOR * specular(normalize(LIGHT_DIRECTION), N, V, roughness) * _mat.shadow;
#elif defined(LIGHT_POSITION)
color.rgb += LIGHT_COLOR * specular(normalize(LIGHT_POSITION - position), N, V, roughness) * _mat.shadow;
#endif
return color;
}
#endif
Dependencies:
lygia
/v1.1.4
/lighting
/material
.glsl
lygia
/v1.1.4
/lighting
/ior
.glsl
lygia
/v1.1.4
/lighting
/specular
.glsl
lygia
/v1.1.4
/lighting
/fresnelReflection
.glsl
lygia
/v1.1.4
/lighting
/ior
/2eta
.glsl
lygia
/v1.1.4
/lighting
/ior
/2f0
.glsl
lygia
/v1.1.4
/lighting
/reflection
.glsl
lygia
/v1.1.4
/lighting
/common
/specularAO
.glsl
lygia
/v1.1.4
/lighting
/common
/envBRDFApprox
.glsl
lygia
/v1.1.4
/lighting
/UnityLightingCommon
.glsl
Use:
<vec4> glass(<Material> material)
#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 IBL_LUMINANCE
#define IBL_LUMINANCE 1.0
#endif
#ifndef FNC_PBRGLASS
#define FNC_PBRGLASS
float4 pbrGlass(const Material _mat) {
float3 V = normalize(CAMERA_POSITION - _mat.position); // View
float3 N = _mat.normal; // Normal front
float3 No = _mat.normal; // Normal out
#if defined(SCENE_BACK_SURFACE)
No = normalize( N - _mat.normal_back );
#endif
float roughness = _mat.roughness;
float3 f0 = ior2f0(_mat.ior);
float3 eta = ior2eta(_mat.ior);
float3 Re = reflection(V, N, roughness);
float3 RaR = refract(-V, No, eta.r);
float3 RaG = refract(-V, No, eta.g);
float3 RaB = refract(-V, No, eta.b);
float NoV = dot(N, V); // Normal . View
// Global Ilumination ( mage Based Lighting )
// ------------------------
float3 E = envBRDFApprox(_mat.albedo.rgb, NoV, roughness);
float3 Fr = float3(0.0, 0.0, 0.0);
Fr = tonemap( envMap(Re, roughness) ) * E;
Fr += tonemap( fresnelReflection(Re, _mat.f0, NoV) ) * (1.0-roughness);
float4 color = float4(0.0, 0.0, 0.0, 1.0);
color.rgb = envMap(RaG, roughness);
#if !defined(TARGET_MOBILE) && !defined(PLATFORM_RPI)
color.r = envMap(RaR, roughness).r;
color.b = envMap(RaB, roughness).b;
#endif
color.rgb = tonemap(color.rgb);
// color.rgb *= exp( -_mat.thickness * 200.0);
color.rgb += Fr * IBL_LUMINANCE;
#if defined(LIGHT_DIRECTION)
color.rgb += LIGHT_COLOR * specular(normalize(LIGHT_DIRECTION), N, V, roughness) * _mat.shadow;
#elif defined(LIGHT_POSITION)
color.rgb += LIGHT_COLOR * specular(normalize(LIGHT_POSITION - position), N, V, roughness) * _mat.shadow;
#endif
return color;
}
#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