mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:57:35 +00:00
LibSoftGPU: Use AK::mix
instead of manual interpolation
This commit is contained in:
parent
8da0925d6d
commit
bca1b9f475
3 changed files with 13 additions and 24 deletions
|
@ -43,11 +43,11 @@ Vertex Clipper::clip_intersection_point(const Vertex& p1, const Vertex& p2, Clip
|
|||
float a = (w1 + x1) / ((w1 + x1) - (w2 + x2));
|
||||
|
||||
Vertex out;
|
||||
out.position = p1.position * (1 - a) + p2.position * a;
|
||||
out.eye_coordinates = p1.eye_coordinates * (1 - a) + p2.eye_coordinates * a;
|
||||
out.clip_coordinates = p1.clip_coordinates * (1 - a) + p2.clip_coordinates * a;
|
||||
out.color = p1.color * (1 - a) + p2.color * a;
|
||||
out.tex_coord = p1.tex_coord * (1 - a) + p2.tex_coord * a;
|
||||
out.position = mix(p1.position, p2.position, a);
|
||||
out.eye_coordinates = mix(p1.eye_coordinates, p2.eye_coordinates, a);
|
||||
out.clip_coordinates = mix(p1.clip_coordinates, p2.clip_coordinates, a);
|
||||
out.color = mix(p1.color, p2.color, a);
|
||||
out.tex_coord = mix(p1.tex_coord, p2.tex_coord, a);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,12 +35,6 @@ constexpr static T interpolate(const T& v0, const T& v1, const T& v2, const Floa
|
|||
return v0 * barycentric_coords.x() + v1 * barycentric_coords.y() + v2 * barycentric_coords.z();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr static T mix(const T& x, const T& y, float interp)
|
||||
{
|
||||
return x * (1 - interp) + y * interp;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE constexpr static Gfx::RGBA32 to_rgba32(const FloatVector4& v)
|
||||
{
|
||||
auto clamped = v.clamped(0, 1);
|
||||
|
@ -821,10 +815,9 @@ void Device::submit_triangle(const Triangle& triangle, Vector<size_t> const& ena
|
|||
break;
|
||||
case TextureEnvMode::Decal: {
|
||||
float src_alpha = fragment.w();
|
||||
float one_minus_src_alpha = 1 - src_alpha;
|
||||
fragment.set_x(texel.x() * src_alpha + fragment.x() * one_minus_src_alpha);
|
||||
fragment.set_y(texel.y() * src_alpha + fragment.y() * one_minus_src_alpha);
|
||||
fragment.set_z(texel.z() * src_alpha + fragment.z() * one_minus_src_alpha);
|
||||
fragment.set_x(mix(fragment.x(), texel.x(), src_alpha));
|
||||
fragment.set_y(mix(fragment.y(), texel.y(), src_alpha));
|
||||
fragment.set_z(mix(fragment.z(), texel.z(), src_alpha));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -108,16 +108,12 @@ FloatVector4 Sampler::sample_2d(FloatVector2 const& uv) const
|
|||
t3 = (i1 < 0 || i1 >= w || j1 < 0 || j1 >= h) ? m_config.border_color : image.texel(layer, level, i1, j1, 0);
|
||||
}
|
||||
|
||||
float alpha = fracf(u - 0.5f);
|
||||
float beta = fracf(v - 0.5f);
|
||||
float const alpha = fracf(u - 0.5f);
|
||||
float const beta = fracf(v - 0.5f);
|
||||
|
||||
float one_minus_alpha = 1 - alpha;
|
||||
float one_minus_beta = 1 - beta;
|
||||
|
||||
auto lerp_0 = t0 * one_minus_alpha + t1 * alpha;
|
||||
auto lerp_1 = t2 * one_minus_alpha + t3 * alpha;
|
||||
|
||||
return lerp_0 * one_minus_beta + lerp_1 * beta;
|
||||
auto const lerp_0 = mix(t0, t1, alpha);
|
||||
auto const lerp_1 = mix(t2, t3, alpha);
|
||||
return mix(lerp_0, lerp_1, beta);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue