-
Автор темы
- #1
Здравствуйте, есть рендер круга с градиентом, когда рендерю 3D круг, фейд уходит в сторону, а не в центр или из центра.
В общем, не могу найти определение, чтобы сделать этот фейд из центра.
polyrender:
void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_count, ImU32 col, bool anti_aliased, ImU32 col2)
{
const ImVec2 uv = GImGui->FontTexUvWhitePixel;
const ImVec2 uv2 = GImGui->FontTexUvWhitePixel;
anti_aliased &= GImGui->Style.AntiAliasedFill;
if (anti_aliased)
{
// Anti-aliased Fill
const float AA_SIZE = 0.5f;
const ImU32 col_trans = /*ImU32(ImGui::GetColorU32(ImGuiCol_FirstTabColor)) */col & IM_COL32(255, 255, 255, 0);
const ImU32 col_trans2 =/* ImU32(ImGui::GetColorU32(ImGuiCol_SecondTabColor))*/ col2 & IM_COL32(255, 255, 255, 0);
const int idx_count = (points_count - 2) * 3 + points_count * 6;
const int vtx_count = (points_count * 2);
PrimReserve(idx_count, vtx_count);
// Add indexes for fill
unsigned int vtx_inner_idx = _VtxCurrentIdx;
unsigned int vtx_outer_idx = _VtxCurrentIdx + 1;
for (int i = 2; i < points_count; i++)
{
_IdxWritePtr[0] = (ImDrawIdx)(vtx_inner_idx); _IdxWritePtr[1] = (ImDrawIdx)(vtx_inner_idx + ((i - 1) << 1)); _IdxWritePtr[2] = (ImDrawIdx)(vtx_inner_idx + (i << 1));
_IdxWritePtr += 3;
}
// Compute normals
ImVec2* temp_normals = (ImVec2*)alloca(points_count * sizeof(ImVec2));
for (int i0 = points_count - 1, i1 = 0; i1 < points_count; i0 = i1++)
{
const ImVec2& p0 = points[i0];
const ImVec2& p1 = points[i1];
ImVec2 diff = p1 - p0;
diff *= ImInvLength(diff, 0.5f);
temp_normals[i0].x = diff.y;
temp_normals[i0].y = diff.x;
}
for (int i0 = (points_count ) - 1, i1 = 0; i1 < points_count / 2; i0 = i1++)
{
// Average normals
const ImVec2& n0 = temp_normals[i0];
const ImVec2& n1 = temp_normals[i1];
ImVec2 dm = (n0 + n1);
float dmr2 = dm.x * dm.x + dm.y * dm.y;
if (dmr2 > 180.000001f)
{
float scale = 1.0f / dmr2;
if (scale > 5.0f) scale = 5.0f;
dm *= scale;
}
dm *= AA_SIZE;
// Add indexes for fringes
_IdxWritePtr[0] = (ImDrawIdx)(vtx_inner_idx + (i1 << 1)); _IdxWritePtr[1] = (ImDrawIdx)(vtx_inner_idx + (i0 << 1)); _IdxWritePtr[2] = (ImDrawIdx)(vtx_outer_idx + (i0 << 1));
_IdxWritePtr[3] = (ImDrawIdx)(vtx_outer_idx + (i0 << 1)); _IdxWritePtr[4] = (ImDrawIdx)(vtx_outer_idx + (i1 << 1)); _IdxWritePtr[5] = (ImDrawIdx)(vtx_inner_idx + (i1 << 1));
_IdxWritePtr += 6;
_VtxWritePtr[0].pos = (points[i1] + dm);
_VtxWritePtr[0].uv = uv;
_VtxWritePtr[0].col = col;
_VtxWritePtr[1].pos = (points[i1] + dm);
_VtxWritePtr[1].uv = uv;
_VtxWritePtr[1].col = col_trans;
_VtxWritePtr += 2;
}
for (int i0 = (points_count) - 1, i1 = (points_count / 2); i1 < points_count; i0 = i1++)
{
// Average normals
const ImVec2& n0 = temp_normals[i0];
const ImVec2& n1 = temp_normals[i1];
ImVec2 dm = (n0 + n1);
float dmr2 = dm.x * dm.x + dm.y * dm.y;
if (dmr2 > 0.000001f)
{
float scale = 1.0f / dmr2;
if (scale > 5.0f) scale = 5.0f;
dm *= scale;
}
dm *= AA_SIZE;
// Add indexes for fringes
_IdxWritePtr[0] = (ImDrawIdx)(vtx_inner_idx + (i1 << 1)); _IdxWritePtr[1] = (ImDrawIdx)(vtx_inner_idx + (i0 << 1)); _IdxWritePtr[2] = (ImDrawIdx)(vtx_outer_idx + (i0 << 1));
_IdxWritePtr[3] = (ImDrawIdx)(vtx_outer_idx + (i0 << 1)); _IdxWritePtr[4] = (ImDrawIdx)(vtx_outer_idx + (i1 << 1)); _IdxWritePtr[5] = (ImDrawIdx)(vtx_inner_idx + (i1 << 1));
_IdxWritePtr += 6;
_VtxWritePtr[0].pos = (points[i1] + dm);
_VtxWritePtr[0].uv = uv2;
_VtxWritePtr[0].col = col2;
_VtxWritePtr[1].pos = (points[i1] + dm);
_VtxWritePtr[1].uv = uv2;
_VtxWritePtr[1].col = col_trans2;
_VtxWritePtr += 2;
}
_VtxCurrentIdx += (ImDrawIdx)vtx_count;
}
else
{
// Non Anti-aliased Fill
const int idx_count = (points_count - 2) * 3;
const int vtx_count = points_count;
PrimReserve(idx_count, vtx_count);
for (int i = 0; i < vtx_count; i++)
{
_VtxWritePtr[0].pos = points[i];
_VtxWritePtr[0].uv = uv;
_VtxWritePtr[0].col = col;
_VtxWritePtr++;
}
for (int i = 2; i < points_count; i++)
{
_IdxWritePtr[0] = (ImDrawIdx)(_VtxCurrentIdx); _IdxWritePtr[1] = (ImDrawIdx)(_VtxCurrentIdx + i - 1); _IdxWritePtr[2] = (ImDrawIdx)(_VtxCurrentIdx + i);
_IdxWritePtr += 3;
}
_VtxCurrentIdx += (ImDrawIdx)vtx_count;
}
}