Как делать градиенты?

Как делать градиенты? Например для roundedbox?

Возможно, с помощью таких текстур: Gradients - Garry's Mod Wiki

Вот готовый код

local mat_white = Material("vgui/white")

function SimpleLinearGradient(x, y, w, h, startColor, endColor, horizontal)
	LinearGradient(x, y, w, h, { {offset = 0, color = startColor}, {offset = 1, color = endColor} }, horizontal)
end

function LinearGradient(x, y, w, h, stops, horizontal)
	if #stops == 0 then
		return
	elseif #stops == 1 then
		surface.SetDrawColor(stops[1].color)
		surface.DrawRect(x, y, w, h)
		return
	end

	table.SortByMember(stops, "offset", true)

	render.SetMaterial(mat_white)
	mesh.Begin(MATERIAL_QUADS, #stops - 1)
	for i = 1, #stops - 1 do
		local offset1 = math.Clamp(stops[i].offset, 0, 1)
		local offset2 = math.Clamp(stops[i + 1].offset, 0, 1)
		if offset1 == offset2 then continue end

		local deltaX1, deltaY1, deltaX2, deltaY2

		local color1 = stops[i].color
		local color2 = stops[i + 1].color

		local r1, g1, b1, a1 = color1.r, color1.g, color1.b, color1.a
		local r2, g2, b2, a2
		local r3, g3, b3, a3 = color2.r, color2.g, color2.b, color2.a
		local r4, g4, b4, a4

		if horizontal then
			r2, g2, b2, a2 = r3, g3, b3, a3
			r4, g4, b4, a4 = r1, g1, b1, a1
			deltaX1 = offset1 * w
			deltaY1 = 0
			deltaX2 = offset2 * w
			deltaY2 = h
		else
			r2, g2, b2, a2 = r1, g1, b1, a1
			r4, g4, b4, a4 = r3, g3, b3, a3
			deltaX1 = 0
			deltaY1 = offset1 * h
			deltaX2 = w
			deltaY2 = offset2 * h
		end

		mesh.Color(r1, g1, b1, a1)
		mesh.Position(Vector(x + deltaX1, y + deltaY1))
		mesh.AdvanceVertex()

		mesh.Color(r2, g2, b2, a2)
		mesh.Position(Vector(x + deltaX2, y + deltaY1))
		mesh.AdvanceVertex()

		mesh.Color(r3, g3, b3, a3)
		mesh.Position(Vector(x + deltaX2, y + deltaY2))
		mesh.AdvanceVertex()

		mesh.Color(r4, g4, b4, a4)
		mesh.Position(Vector(x + deltaX1, y + deltaY2))
		mesh.AdvanceVertex()
	end
	mesh.End()
end

и пример

        hook.Add("HUDPaint", "LinearGradient", function()
            LinearGradient(100, 100, 200, 5, {
                {offset = 0, color = Color(255, 255, 255)},
                {offset = 1, color = Color(255, 0, 0)}
            }, true)
        end)

А можно как то этот градиент закруглить?если да то как?

local mat_white = Material("vgui/white")

function SimpleLinearGradientRounded(x, y, w, h, startColor, endColor, horizontal, radius)
	LinearGradientRounded(x, y, w, h, { {offset = 0, color = startColor}, {offset = 1, color = endColor} }, horizontal, radius)
end

function LinearGradientRounded(x, y, w, h, stops, horizontal, radius)
	if #stops == 0 then
		return
	elseif #stops == 1 then
		surface.SetDrawColor(stops[1].color)
		draw.RoundedBox(radius, x, y, w, h, stops[1].color)
		return
	end

	table.SortByMember(stops, "offset", true)

	render.SetMaterial(mat_white)

	local step = horizontal and w or h
	local stepSize = step / #stops

	for i = 1, #stops - 1 do
		local offset1 = math.Clamp(stops[i].offset, 0, 1)
		local offset2 = math.Clamp(stops[i + 1].offset, 0, 1)
		if offset1 == offset2 then continue end

		local color1 = stops[i].color
		local color2 = stops[i + 1].color

		local r1, g1, b1, a1 = color1.r, color1.g, color1.b, color1.a
		local r2, g2, b2, a2 = color2.r, color2.g, color2.b, color2.a

		for j = 0, stepSize do
			local t = j / stepSize
			local r = Lerp(t, r1, r2)
			local g = Lerp(t, g1, g2)
			local b = Lerp(t, b1, b2)
			local a = Lerp(t, a1, a2)

			surface.SetDrawColor(r, g, b, a)

			if horizontal then
				draw.RoundedBox(radius, x + (offset1 * w) + (j * (w / stepSize)), y, w / stepSize, h, Color(r, g, b, a))
			else
				draw.RoundedBox(radius, x, y + (offset1 * h) + (j * (h / stepSize)), w, h / stepSize, Color(r, g, b, a))
			end
		end
	end
end

Пример

hook.Add("HUDPaint", "LinearGradientRoundedExample", function()
	SimpleLinearGradientRounded(100, 100, 200, 50, Color(255, 255, 255), Color(255, 0, 0), true, 8)
end)