Support specular highlight in vecr lighting colorizer

This commit is contained in:
Nikita Lisitsa 2024-06-22 01:16:15 +03:00
parent b290bfb063
commit 17e23e41d4
2 changed files with 18 additions and 2 deletions

View file

@ -24,6 +24,9 @@ namespace psemek::vecr
any shape = {};
gfx::color_rgba color0 = {0, 0, 0, 0};
gfx::color_rgba color1 = {0, 0, 0, 0};
gfx::color_rgba specular_color = {0, 0, 0, 0};
float specular_power = 0.f;
float specular_intensity = 0.f;
float slope = 1.f;
geom::vector<float, 3> direction = {0.f, 0.f, 1.f};
};

View file

@ -24,10 +24,23 @@ namespace psemek::vecr
auto normal = geom::swizzle<0, 1, -1>(real_sample.gradient * lighting.slope);
normal[2] = 1.f;
normal = geom::normalized(normal);
auto factor = 0.5f + 0.5f * geom::dot(geom::normalized(normal), lighting.direction);
geom::vector view{0.f, 0.f, 1.f};
return gfx::lerp(gfx::to_colorf(lighting.color0), gfx::to_colorf(lighting.color1), factor);
auto reflected = 2.f * geom::dot(normal, lighting.direction) * normal - lighting.direction;
auto NdotL = geom::dot(normal, lighting.direction);
auto RdotV = geom::dot(reflected, view);
auto lightness = 0.5f + 0.5f * NdotL;
auto specular = lighting.specular_intensity * std::pow(std::max(0.f, RdotV), lighting.specular_power);
auto result = gfx::lerp(gfx::to_colorf(lighting.color0), gfx::to_colorf(lighting.color1), lightness);
result = gfx::lerp(result, gfx::to_colorf(lighting.specular_color), specular);
return result;
}
}