80 lines
2.6 KiB
Plaintext
80 lines
2.6 KiB
Plaintext
material {
|
|
name: "SanctificationCardHolographic",
|
|
shading_model: physical,
|
|
blending: opaque,
|
|
culling: back,
|
|
parameters: [
|
|
{ type: sampler2d, name: artwork_texture, hint: default_white },
|
|
{ type: sampler2d, name: finish_mask_texture, hint: default_black },
|
|
{ type: vec3, name: light_position, default: [2.2, 2.5, 4.4] },
|
|
{ type: float, name: finish_strength, default: 0.6 },
|
|
{ type: float, name: roughness, default: 0.23 },
|
|
{ type: float, name: surface_detail, default: 0.14 },
|
|
],
|
|
}
|
|
|
|
fragment {
|
|
vec3 Spectrum(float phase) {
|
|
return 0.52 + 0.48 * cos(
|
|
6.2831853 * (phase + vec3(0.0, 0.33, 0.67))
|
|
);
|
|
}
|
|
|
|
float Hash(vec2 p) {
|
|
return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
|
|
}
|
|
|
|
void Surface(inout MaterialInputs material) {
|
|
vec2 uv = GetUV(0);
|
|
vec3 artwork = SRGBToLinear(texture(artwork_texture, uv).rgb);
|
|
float mask = texture(finish_mask_texture, uv).r;
|
|
vec3 normal = GetWorldNormal();
|
|
vec3 view_direction = GetViewDirection();
|
|
vec3 light_direction = normalize(
|
|
material_params.light_position - GetWorldPosition()
|
|
);
|
|
|
|
float paper = Hash(floor(uv * vec2(230.0, 322.0)));
|
|
artwork *= 0.985 + (paper - 0.5) *
|
|
material_params.surface_detail * 0.08;
|
|
|
|
float view_phase = dot(view_direction, vec3(0.43, 0.24, 0.87));
|
|
float light_phase = dot(light_direction, vec3(-0.31, 0.66, 0.68));
|
|
float phase = uv.x * 1.7 + uv.y * 0.9 +
|
|
view_phase * 0.78 + light_phase * 0.34;
|
|
vec3 spectrum = Spectrum(phase);
|
|
float grazing = pow(
|
|
1.0 - clamp(dot(normal, view_direction), 0.0, 1.0),
|
|
0.72
|
|
);
|
|
float coating = clamp(
|
|
mask * material_params.finish_strength *
|
|
(0.34 + grazing * 1.28),
|
|
0.0,
|
|
0.92
|
|
);
|
|
vec3 spectral_ink = artwork * mix(vec3(0.88), spectrum, 0.72);
|
|
vec3 coated = mix(artwork, mix(artwork, spectral_ink, 0.48), coating);
|
|
coated += spectrum * coating * grazing * 0.12;
|
|
|
|
material.base_color = vec4(coated, 1.0);
|
|
material.metallic = coating * 0.18;
|
|
material.roughness = clamp(
|
|
mix(max(material_params.roughness, 0.56), 0.22, coating),
|
|
kMinRoughness,
|
|
1.0
|
|
);
|
|
material.normal = normal;
|
|
material.specular_weight = 1.0;
|
|
material.specular_color = vec3(1.0);
|
|
material.ior = 1.5;
|
|
material.clearcoat = coating * 0.58;
|
|
material.clearcoat_roughness = 0.24;
|
|
material.clearcoat_normal = normal;
|
|
material.iridescence = coating * 0.42;
|
|
material.iridescence_ior = 1.3;
|
|
material.iridescence_thickness = mix(180.0, 430.0, spectrum.r);
|
|
PrepareMaterial(material);
|
|
}
|
|
}
|