Make use of some glsl built-ins

This commit is contained in:
Grant Sanderson 2023-01-28 15:01:32 -08:00
parent 474a6c27e3
commit 368f48f8dd
2 changed files with 2 additions and 2 deletions

View file

@ -31,7 +31,7 @@ vec4 add_light(vec4 color, vec3 point, vec3 unit_normal){
// When unit normal points towards light, brighten
float bright_factor = max(light_to_normal, 0) * reflectiveness;
// For glossy surface, add extra shine if light beam go towards camera
vec3 light_reflection = -to_light + 2 * unit_normal * dot(to_light, unit_normal);
vec3 light_reflection = reflect(-to_light, unit_normal);
float light_to_cam = dot(light_reflection, to_camera);
float shine = gloss * exp(-3 * pow(1 - light_to_cam, 2));
bright_factor += shine;

View file

@ -26,7 +26,7 @@ float dist_to_curve(){
// Evaluate F(x, y) = y - x^2
// divide by its gradient's magnitude
float Fxy = y0 - x0 * x0;
float approx_dist = abs(Fxy) / sqrt(1.0 + 4 * x0 * x0);
float approx_dist = abs(Fxy) * inversesqrt(1.0 + 4 * x0 * x0);
if(approx_dist < QUICK_DIST_WIDTH) return approx_dist;
// Otherwise, solve for the minimal distance.