# Pearlescent

A simulation of pearlescence, specifically the trait of materials which contain organic dielectric media squashed together at such proximity as to cause them to refract light, like a pearl does.

For true pearlescence, you would need to know the angle of the light at all times, which is infeasible for most games; this uses a “fake light” parameter, `light_direction`, which can be directed from a major source like the sun, to simulate this. You can update the `light_direction` for the base (non-unique) material at every frame to cut down on processing and memory costs.

##### Shader code

```
shader_type spatial;
uniform float fresnel_power = 3.0;
uniform float interference_frequency = 3.0;
uniform vec3 base : source_color = vec3(1.0, 0.8, 0.6);
uniform vec3 shift : source_color = vec3(0.2, 0.7, 1.0);
uniform float roughness = 0.3;
uniform float metallic = 0.7;
uniform vec3 light_direction = vec3(0.0, -1.0, 0.0);
float fresnel(vec3 view, vec3 normal) {
return pow(1.0 - dot(view, normal), fresnel_power);
}
vec3 irridescence(vec3 view, vec3 normal, vec3 light) {
float dot_view = dot(view, normal);
float dot_light = dot(light, normal);
float angle = abs(dot_view - dot_light);
float interference = sin(angle * interference_frequency) * 0.5 + 0.5;
return mix(base, shift, interference);
}
void fragment() {
ALBEDO = mix(
irridescence(VIEW, NORMAL, light_direction),
vec3(1.0),
fresnel(VIEW, NORMAL));
ROUGHNESS = roughness;
METALLIC = metallic;
}
```

Not entirely sure what you mean by this, you can access light direction handily in a custom light function.