89 lines
3.0 KiB
HLSL
89 lines
3.0 KiB
HLSL
#ifndef REPAIR_SURFACE_INCLUDED
|
|
#define REPAIR_SURFACE_INCLUDED
|
|
|
|
void RepairSurface_float(
|
|
float N,
|
|
float3 BaseColor,
|
|
float3 RustColor,
|
|
float RustInitial,
|
|
float RustAmount,
|
|
float PuttyProgress,
|
|
float SandProgress,
|
|
float PaintProgress,
|
|
float PaintSmoothness,
|
|
out float3 Albedo,
|
|
out float Metallic,
|
|
out float Smoothness)
|
|
{
|
|
const float e = 0.04;
|
|
const float3 bareMetal = float3(0.55, 0.56, 0.58);
|
|
const float3 puttyRaw = float3(0.62, 0.58, 0.50);
|
|
const float3 puttySanded = float3(0.74, 0.72, 0.68);
|
|
|
|
// Если деталь целая (RustInitial = 0) — сразу возвращаем чистый родной цвет авто
|
|
if (RustInitial <= 0.001)
|
|
{
|
|
Albedo = BaseColor;
|
|
Metallic = 0.0;
|
|
Smoothness = PaintSmoothness;
|
|
return;
|
|
}
|
|
|
|
float sand = saturate(SandProgress);
|
|
|
|
// 1. Исходная зона повреждения
|
|
float zone = smoothstep(1.0 - RustInitial, 1.0 - RustInitial + e, N);
|
|
|
|
// 2. Шпаклевка (заполняет зачищенный металл от центра к краям)
|
|
float fillEdge = 1.0 - saturate(PuttyProgress) * (RustInitial + e);
|
|
float puttyMask = smoothstep(fillEdge + e, fillEdge, N) * step(0.001, PuttyProgress);
|
|
if (PuttyProgress >= 0.98) puttyMask = 1.0;
|
|
|
|
float3 underColor = lerp(bareMetal, lerp(puttyRaw, puttySanded, sand), puttyMask);
|
|
float underSmooth = lerp(0.45, lerp(0.05, 0.35, sand), puttyMask);
|
|
float underMetal = lerp(0.8, 0.0, puttyMask);
|
|
|
|
// 3. Новая краска (закрывает зашлифованную шпаклевку без белых контуров)
|
|
float paintEdge = (1.0 - RustInitial) + saturate(PaintProgress) * (RustInitial + e);
|
|
float paintMask = (1.0 - smoothstep(paintEdge, paintEdge + e, N)) * step(0.001, PaintProgress);
|
|
if (PaintProgress >= 0.98) paintMask = 1.0;
|
|
|
|
float damageVisible = zone * (1.0 - paintMask);
|
|
|
|
// 4. Текущий остаток ржавчины
|
|
float rust = zone * smoothstep(1.0 - RustAmount, 1.0 - RustAmount + e, N) * step(0.001, RustAmount);
|
|
|
|
float3 col = lerp(BaseColor, underColor, damageVisible);
|
|
float sm = lerp(PaintSmoothness, underSmooth, damageVisible);
|
|
float met = lerp(0.0, underMetal, damageVisible);
|
|
|
|
col = lerp(col, RustColor, rust);
|
|
sm = lerp(sm, 0.08, rust);
|
|
met = lerp(met, 0.0, rust);
|
|
|
|
Albedo = col;
|
|
Metallic = met;
|
|
Smoothness = sm;
|
|
}
|
|
|
|
void RepairSurface_half(
|
|
half N,
|
|
half3 BaseColor,
|
|
half3 RustColor,
|
|
half RustInitial,
|
|
half RustAmount,
|
|
half PuttyProgress,
|
|
half SandProgress,
|
|
half PaintProgress,
|
|
half PaintSmoothness,
|
|
out half3 Albedo,
|
|
out half Metallic,
|
|
out half Smoothness)
|
|
{
|
|
float3 a; float m; float s;
|
|
RepairSurface_float(N, BaseColor, RustColor, RustInitial, RustAmount,
|
|
PuttyProgress, SandProgress, PaintProgress, PaintSmoothness, a, m, s);
|
|
Albedo = a; Metallic = m; Smoothness = s;
|
|
}
|
|
|
|
#endif |