Support specular highlight in vecr lighting colorizer
This commit is contained in:
parent
b290bfb063
commit
17e23e41d4
2 changed files with 18 additions and 2 deletions
|
|
@ -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};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue