Alpha color offset

Color Offset gains an alpha channel (Frame Properties, Change All, property
copy, interpolation and root folding), drawn by adding it to the texel's
alpha. Saved as AlphaOffset in the editor's copy only and counted by the
Isaac warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-08 17:22:15 -04:00
1 parent 0adb0f89bc
commit 4375844c84
17 files changed
+39 -51

No files matched your search

+5 -5
View File
@@ -157,13 +157,13 @@ namespace anm2ed
return result;
}
void texture_uniforms_set(Shader& shader, mat4 transform, vec4 tint, vec3 colorOffset, vec2 textureSize,
void texture_uniforms_set(Shader& shader, mat4 transform, vec4 tint, vec4 colorOffset, vec2 textureSize,
float playbackTime)
{
if (shader.uniforms.empty())
{
glUniform1i(glGetUniformLocation(shader.id, shader::UNIFORM_TEXTURE), 0);
glUniform3fv(glGetUniformLocation(shader.id, shader::UNIFORM_COLOR_OFFSET), 1, value_ptr(colorOffset));
glUniform4fv(glGetUniformLocation(shader.id, shader::UNIFORM_COLOR_OFFSET), 1, value_ptr(colorOffset));
glUniform4fv(glGetUniformLocation(shader.id, shader::UNIFORM_TINT), 1, value_ptr(tint));
glUniformMatrix4fv(glGetUniformLocation(shader.id, shader::UNIFORM_TRANSFORM), 1, GL_FALSE, value_ptr(transform));
return;
@@ -186,7 +186,7 @@ namespace anm2ed
texture_uniform_set(uniform, tint);
break;
case shader::UNIFORM_BINDING_COLOR_OFFSET:
texture_uniform_set(uniform, vec4(colorOffset, 0.0f));
texture_uniform_set(uniform, colorOffset);
break;
case shader::UNIFORM_BINDING_TEXTURE_SIZE:
texture_uniform_set(uniform, vec4(textureSize, 0.0f, 0.0f));
@@ -206,7 +206,7 @@ namespace anm2ed
}
}
void Canvas::texture_render(Shader& shader, GLuint texture, mat4 transform, vec4 tint, vec3 colorOffset,
void Canvas::texture_render(Shader& shader, GLuint texture, mat4 transform, vec4 tint, vec4 colorOffset,
float* vertices, vec2 textureSize, float playbackTime, TextureBlur blur) const
{
canvas_blend_premultiplied_set();
@@ -279,7 +279,7 @@ namespace anm2ed
// A layer draw's crop of its spritesheet. A blurred one (Flash's BlurFilter: a box `blur` canvas pixels wide) grows by
// the box's reach, in texels at the draw's scale, and averages its crop over it.
void Canvas::layer_render(Shader& shader, GLuint texture, vec2 textureSize, const mat4& transform,
const model::Draw& draw, vec4 tint, vec3 colorOffset) const
const model::Draw& draw, vec4 tint, vec4 colorOffset) const
{
auto blurred = draw;
auto& frame = blurred.frame;
+2 -2
View File
@@ -72,10 +72,10 @@ namespace anm2ed
void axes_render(resource::Shader&, float, glm::vec2, glm::vec4 = glm::vec4(1.0f)) const;
void grid_render(resource::Shader&, float, glm::vec2, glm::ivec2 = glm::ivec2(32, 32), glm::ivec2 = {},
glm::vec4 = glm::vec4(1.0f)) const;
void texture_render(resource::Shader&, GLuint, glm::mat4 = {1.0f}, glm::vec4 = glm::vec4(1.0f), glm::vec3 = {},
void texture_render(resource::Shader&, GLuint, glm::mat4 = {1.0f}, glm::vec4 = glm::vec4(1.0f), glm::vec4 = {},
float* = (float*)TEXTURE_VERTICES, glm::vec2 = {}, float = 0.0f, TextureBlur = {}) const;
void layer_render(resource::Shader&, GLuint, glm::vec2, const glm::mat4&, const model::Draw&, glm::vec4,
glm::vec3) const;
glm::vec4) const;
void rect_fill_render(resource::Shader&, const glm::mat4&, const glm::mat4&, glm::vec4 = glm::vec4(1.0f)) const;
void layers_render(resource::Shader&, const model::Model&, const model::Animation&, const model::DrawOptions&,
const glm::mat4&, const std::function<const resource::Image*(const model::Draw&)>&,
+2 -2
View File
@@ -179,9 +179,9 @@ options:
auto issues = model::isaac_issues_get(model);
std::println("isaac issues: {} eased frames, {} group transforms, {} skewed frames, {} shader frames, {} depth "
"frames, {} blurred frames, {} trigger sounds, {} animation layers",
"frames, {} alpha offset frames, {} blurred frames, {} trigger sounds, {} animation layers",
issues.easedFrames, issues.groupTransforms, issues.skewFrames, issues.shaderFrames, issues.depthFrames,
issues.blurFrames, issues.triggerSounds, issues.animationLayers);
issues.alphaOffsetFrames, issues.blurFrames, issues.triggerSounds, issues.animationLayers);
return 0;
}
+1
View File
@@ -387,6 +387,7 @@ namespace anm2ed::imgui
{issues.skewFrames, FORMAT_ISAAC_SKEW_FRAMES},
{issues.shaderFrames, FORMAT_ISAAC_SHADER_FRAMES},
{issues.depthFrames, FORMAT_ISAAC_DEPTH_FRAMES},
{issues.alphaOffsetFrames, FORMAT_ISAAC_ALPHA_OFFSET_FRAMES},
{issues.blurFrames, FORMAT_ISAAC_BLUR_FRAMES},
{issues.triggerSounds, FORMAT_ISAAC_TRIGGER_SOUNDS},
{issues.animationLayers, FORMAT_ISAAC_ANIMATION_LAYERS}})
+1 -1
View File
@@ -725,7 +725,7 @@ namespace anm2ed::imgui
tint.a = std::max(0.0f, tint.a - (alphaOffset + sampleAlpha));
auto customShader = sampleDocument.shader_get(frame.shaderId);
layer_render(customShader ? *customShader : shaderTexture, resource::texture::id_get(*layerTexture),
textureSize, baseTransform, draw, tint, frame.colorOffset + sampleColor);
textureSize, baseTransform, draw, tint, frame.colorOffset + vec4(sampleColor, 0.0f));
auto color = isOnion ? onionColor
: isActiveDocument && is_layer_selected(draw.id) ? SELECTED_LAYER_BORDER_COLOR
+2 -3
View File
@@ -270,8 +270,8 @@ namespace anm2ed::imgui
{ frame.tint = tint; });
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_TINT));
auto colorOffsetEdit = color_edit3_persistent(localize.get(BASIC_COLOR_OFFSET),
frame ? &useFrame.colorOffset : &dummy_value<vec3>());
auto colorOffsetEdit = color_edit4_persistent(localize.get(BASIC_COLOR_OFFSET),
frame ? &useFrame.colorOffset : &dummy_value<vec4>());
frame_edit(colorOffsetEdit, EDIT_FRAME_COLOR_OFFSET,
[colorOffset = useFrame.colorOffset](Document&, model::Frame& frame, model::Track*,
const Reference&) { frame.colorOffset = colorOffset; });
@@ -412,7 +412,6 @@ namespace anm2ed::imgui
dummy_value<int>() = 0;
dummy_value<bool>() = 0;
dummy_value<vec2>() = vec2();
dummy_value<vec3>() = vec3();
dummy_value<vec4>() = vec4();
}
}
@@ -178,7 +178,8 @@ namespace anm2ed::imgui::wizard
value_ptr(settings.changeTint),
false},
{BASIC_COLOR_OFFSET,
{&settings.changeIsColorOffsetR, &settings.changeIsColorOffsetG, &settings.changeIsColorOffsetB},
{&settings.changeIsColorOffsetR, &settings.changeIsColorOffsetG, &settings.changeIsColorOffsetB,
&settings.changeIsColorOffsetA},
value_ptr(settings.changeColorOffset),
false}};
+1
View File
@@ -191,6 +191,7 @@ namespace anm2ed
X(colorOffsetR, colorOffset.r, false, true, changeIsColorOffsetR, changeColorOffset.r) \
X(colorOffsetG, colorOffset.g, false, true, changeIsColorOffsetG, changeColorOffset.g) \
X(colorOffsetB, colorOffset.b, false, true, changeIsColorOffsetB, changeColorOffset.b) \
X(colorOffsetA, colorOffset.a, false, true, changeIsColorOffsetA, changeColorOffset.a) \
X(blur, blur, true, false, changeIsBlur, changeBlur)
struct FrameChange
+1 -1
View File
@@ -48,7 +48,7 @@ namespace anm2ed::model
glm::vec2 skew{};
float rotation{};
glm::vec4 tint{types::color::WHITE};
glm::vec3 colorOffset{};
glm::vec4 colorOffset{};
int duration{1};
bool isVisible{true};
Interpolation interpolation{Interpolation::NONE};
+5 -1
View File
@@ -39,7 +39,7 @@ namespace anm2ed::model
"LayerId", "NullId", "SpritesheetId", "Fps", "Version", "FrameNum", "Delay", "AtFrame", "EventId", "RegionId",
"ShaderId", "Depth", "SoundId", "GroupId", "Index", "Loop", "StartMarker", "EndMarker", "Visible", "ShowRect", "IsExpanded", "Enabled", "Rotation",
"XPivot", "YPivot", "XCrop", "YCrop", "XPosition", "YPosition", "Width", "Height", "XScale", "YScale", "SkewX",
"SkewY", "ShearX", "ShearY", "RedTint", "GreenTint", "BlueTint", "AlphaTint", "RedOffset", "GreenOffset", "BlueOffset",
"SkewY", "ShearX", "ShearY", "RedTint", "GreenTint", "BlueTint", "AlphaTint", "RedOffset", "GreenOffset", "BlueOffset", "AlphaOffset",
"Interpolated", "Origin", "BakeInterpolation", "BakeDelay", "BakeCount", "OriginalDelay", "Library", "Animation",
"ChildAnimation", "ChildMode", "ChildStart", "Restart", "Blur"};
// clang-format on
@@ -217,6 +217,7 @@ namespace anm2ed::model
frame.tint[i] = color_get(element, TINT_ATTRIBUTES[i], frame.tint[i]);
for (int i = 0; i < (int)std::size(OFFSET_ATTRIBUTES); ++i)
frame.colorOffset[i] = color_get(element, OFFSET_ATTRIBUTES[i], frame.colorOffset[i]);
frame.colorOffset.a = color_get(element, "AlphaOffset", frame.colorOffset.a);
frame.duration = int_get(element, "Delay", frame.duration);
frame.isVisible = bool_get(element, "Visible", frame.isVisible);
frame.interpolation = interpolation_read(element, "Interpolated");
@@ -1164,6 +1165,8 @@ namespace anm2ed::model
sink.attribute(TINT_ATTRIBUTES[i], math::float_to_uint8(frame.tint[i]));
for (int i = 0; i < (int)std::size(OFFSET_ATTRIBUTES); ++i)
sink.attribute(OFFSET_ATTRIBUTES[i], math::float_to_uint8(frame.colorOffset[i]));
if (writer.is(SERIALIZE_EXTENSIONS) && math::float_to_uint8(frame.colorOffset.a) != 0)
sink.attribute("AlphaOffset", math::float_to_uint8(frame.colorOffset.a));
sink.attribute("Rotation", frame.rotation);
interpolation_add(sink, "Interpolated", frame.interpolation);
if (writer.is(SERIALIZE_EXTENSIONS) && frame.shaderId != -1) sink.attribute("ShaderId", frame.shaderId);
@@ -1372,6 +1375,7 @@ namespace anm2ed::model
issues.skewFrames += frame.skew != glm::vec2();
issues.shaderFrames += frame.shaderId != -1;
issues.depthFrames += track.type == ItemType::LAYER && frame.depth != 0;
issues.alphaOffsetFrames += math::float_to_uint8(frame.colorOffset.a) != 0;
issues.blurFrames += track.type == ItemType::LAYER && frame.blur != 0.0f;
issues.triggerSounds +=
track.type == ItemType::TRIGGER &&
+1
View File
@@ -16,6 +16,7 @@ namespace anm2ed::model
int skewFrames{};
int shaderFrames{};
int depthFrames{};
int alphaOffsetFrames{};
int blurFrames{};
int triggerSounds{};
int animationLayers{};
+3 -2
View File
@@ -85,7 +85,7 @@ namespace anm2ed::resource::shader
in vec2 i_uv_out;
uniform sampler2D u_texture;
uniform vec4 u_tint;
uniform vec3 u_color_offset;
uniform vec4 u_color_offset;
uniform float u_blur;
uniform vec4 u_region;
uniform vec2 u_texel;
@@ -116,7 +116,8 @@ namespace anm2ed::resource::shader
texColor = sum.a > 0.0 ? vec4(sum.rgb / sum.a, sum.a) : vec4(0.0);
}
texColor *= u_tint;
texColor.rgb += u_color_offset;
texColor.rgb += u_color_offset.rgb;
texColor.a = clamp(texColor.a + u_color_offset.a, 0.0, 1.0);
texColor.rgb *= texColor.a;
o_fragColor = texColor;
}
+2 -1
View File
@@ -230,6 +230,7 @@ namespace anm2ed
X(FORMAT_DURATION, "Duration: {0}", "Duracion: {0}", "Продолжительность: {0}", "时长: {0}", "유지 시간: {0}") \
X(FORMAT_EVENT_LABEL, "Event: {0}", "Evento: {0}", "Событие: {0}", "事件: {0}", "이벤트: {0}") \
X(FORMAT_ID, "ID: {0}", "ID: {0}", "ID: {0}", "ID: {0}", "ID: {0}") \
X(FORMAT_ISAAC_ALPHA_OFFSET_FRAMES, "{} frame(s) use an alpha offset, which the game doesn't support; it will be dropped.", "{} Frame(s) usan un desplazamiento de alfa, que el juego no soporta; se descartará.", "{} кадр(ов) используют смещение альфы, которое игра не поддерживает; оно будет отброшено.", "{} 帧使用了透明度偏移,游戏不支持;将被丢弃。", "{}개의 프레임이 알파 오프셋을 사용합니다. 게임에서 지원하지 않으므로 제거됩니다.") \
X(FORMAT_ISAAC_ANIMATION_LAYERS, "{} layer(s) play animations, which the game doesn't support; they will draw nothing.", "{} capa(s) reproducen animaciones, que el juego no soporta; no dibujarán nada.", "{} слой(ёв) проигрывают анимации, которые игра не поддерживает; они ничего не отобразят.", "{} 个图层播放动画,游戏不支持;它们将不显示任何内容。", "{}개의 레이어가 애니메이션을 재생합니다. 게임에서 지원하지 않으므로 아무것도 그리지 않습니다.") \
X(FORMAT_ISAAC_BLUR_FRAMES, "{} frame(s) blur their layer, which the game doesn't support; they will draw sharp.", "{} Frame(s) desenfocan su capa, que el juego no soporta; se dibujarán nítidos.", "{} кадр(ов) размывают слой, что игра не поддерживает; они будут нарисованы чётко.", "{} 个帧模糊了图层,游戏不支持,将清晰绘制。", "프레임 {}개가 게임이 지원하지 않는 레이어 흐림을 사용합니다. 선명하게 그려집니다.") \
X(FORMAT_ISAAC_DEPTH_FRAMES, "{} frame(s) change their layer's depth, which the game doesn't support; they will draw in timeline order.", "{} Frame(s) cambian la profundidad de su capa, que el juego no soporta; se dibujarán en el orden de la línea de tiempo.", "{} кадр(ов) меняют глубину слоя, что игра не поддерживает; они будут рисоваться в порядке таймлайна.", "{} 个帧改变了图层深度,游戏不支持,将按时间轴顺序绘制。", "프레임 {}개가 게임이 지원하지 않는 레이어 깊이를 바꿉니다. 타임라인 순서로 그려집니다.") \
@@ -684,7 +685,7 @@ namespace anm2ed
X(TOOLTIP_CHANGE_ALL_NULLS, "The frame property changes will apply to null frames.", "Los cambios de propiedades de frame se aplicaran a los frames null.", "Изменения свойств кадра будут применены к нулевым кадрам.", "帧属性更改将应用于 Null 帧。", "프레임 속성 변경 사항을 Null 프레임에 적용합니다.") \
X(TOOLTIP_CENTER_VIEW, "Centers the view.", "Centra la vista.", "Центрирует вид.", "居中视角.", "미리보기 화면을 가운데에 맞춥니다.") \
X(TOOLTIP_CLOSE_SETTINGS, "Close without updating settings.", "Cerrar sin actualizar las configuraciones.", "Закрыть без обновления настройки.", "关闭但不保存设置.", "설정을 갱신하지 않고 닫습니다.") \
X(TOOLTIP_COLOR_OFFSET, "Change the color added onto the frame.", "Cambia el color añadido al Frame.", "Изменить цвет, который добавлен на кадр.", "更改覆盖在帧上的颜色.", "프레임에 더해지는 색을 변경합니다.") \
X(TOOLTIP_COLOR_OFFSET, "Change the color added onto the frame.\n(Alpha is editor only; the game ignores it.)", "Cambia el color añadido al Frame.\n(El alfa es solo del editor; el juego lo ignora.)", "Изменить цвет, который добавлен на кадр.\n(Альфа только для редактора; игра её игнорирует.)", "更改添加到帧上的颜色。\n(透明度仅限编辑器;游戏会忽略它。)", "프레임에 더해지는 색상을 변경합니다.\n(알파는 에디터 전용이며 게임에서는 무시됩니다.)") \
X(TOOLTIP_ONLY_SELECTED_ITEM, "Only the selected item (root, layer or null) is onionskinned and shows its pivot path.", "Solo el elemento seleccionado (raíz, capa o null) usa papel cebolla y muestra la trayectoria de su pivote.", "Оньонскин и путь опорной точки показываются только для выбранного элемента (корень, слой или null).", "仅对选中的项目(根、图层或空节点)显示洋葱皮和枢轴路径。", "선택한 항목(루트, 레이어 또는 널)에만 전후 비교와 피벗 경로를 표시합니다.") \
X(TOOLTIP_PIVOT_PATH, "Show the path each item's pivot travels through the animation, with a dot on every frame.", "Muestra la trayectoria que recorre el pivote de cada elemento durante la animación, con un punto en cada Frame.", "Показать путь опорной точки каждого элемента в анимации, с точкой на каждом кадре.", "显示每个项目的枢轴在动画中移动的路径,每帧一个点。", "애니메이션 동안 각 항목의 피벗이 지나는 경로를 프레임마다 점으로 표시합니다.") \
X(TOOLTIP_REGION, "Set the spritesheet region the frame will use.", "Establece la región del spritesheet que usará el frame.", "Установить регион спрайт-листа, который будет использовать кадр.", "设置帧将使用的图集区域.", "프레임이 사용할 스프라이트 시트 영역을 설정합니다.") \
+1 -1
View File
@@ -128,7 +128,7 @@ namespace anm2ed
X(CHANGE_IS_CHILD_START_RANDOM, changeIsChildStartRandom, STRING_UNDEFINED, BOOL, false) \
X(CHANGE_IS_CHILD_RESTART, changeIsChildRestart, STRING_UNDEFINED, BOOL, false) \
X(CHANGE_TINT, changeTint, STRING_UNDEFINED, VEC4, {}) \
X(CHANGE_COLOR_OFFSET, changeColorOffset, STRING_UNDEFINED, VEC3, {}) \
X(CHANGE_COLOR_OFFSET, changeColorOffset, STRING_UNDEFINED, VEC4, {}) \
X(CHANGE_REGION_ID, changeRegionId, STRING_UNDEFINED, INT, -1) \
X(CHANGE_IS_VISIBLE, changeIsVisible, STRING_UNDEFINED, BOOL, false) \
X(CHANGE_INTERPOLATION, changeInterpolation, STRING_UNDEFINED, INT, 0) \
-30
View File
@@ -144,36 +144,6 @@ namespace anm2ed::imgui
return edit_state::NONE;
}
edit_state::Type color_edit3_persistent(const char* label, vec3* value, ImGuiColorEditFlags flags)
{
static bool isEditing{};
static vec3 start{NAN};
auto persistent = value ? *value : vec4();
ImGui::ColorEdit3(label, value_ptr(persistent), flags);
if (!value) return edit_state::NONE;
if (ImGui::IsItemActivated() && persistent != start)
{
isEditing = true;
start = *value;
return edit_state::START;
}
else if (ImGui::IsItemDeactivatedAfterEdit())
{
isEditing = false;
*value = persistent;
start = vec4{NAN};
return edit_state::END;
}
else if (isEditing)
{
*value = persistent;
return edit_state::DURING;
}
return edit_state::NONE;
}
edit_state::Type color_edit4_persistent(const char* label, vec4* value, ImGuiColorEditFlags flags)
{
static bool isEditing{};
-1
View File
@@ -27,7 +27,6 @@ namespace anm2ed::imgui
const char* = "%.3f", ImGuiSliderFlags = 0);
types::edit_state::Type drag_float2_persistent(const char*, glm::vec2*, float = DRAG_SPEED, float = {}, float = {},
const char* = "%.3f", ImGuiSliderFlags = 0);
types::edit_state::Type color_edit3_persistent(const char*, glm::vec3*, ImGuiColorEditFlags = 0);
types::edit_state::Type color_edit4_persistent(const char*, glm::vec4*, ImGuiColorEditFlags = 0);
bool radio_button_icon(const char*, int*, int, ImTextureID, ImVec2, ImVec4 = ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
bool combo_id_mapped(const std::string&, int*, const std::vector<int>&, const std::vector<std::string>&);
+10
View File
@@ -115,3 +115,13 @@ TEST_CASE("an animation layer draws its child animation, from this file or a lib
CHECK(model::isaac_issues_get(anm2).animationLayers == 3);
CHECK(game_document_get(model::model_to_string(anm2)).find(" Animation=\"") == std::string::npos);
}
TEST_CASE("an alpha offset is kept by the editor's copy only")
{
auto anm2 = model_load(file_load(TEST_DIR / "render" / "spin.anm2"));
anm2.frame_edit({0, LAYER, 0, 0})->colorOffset.a = -0.5f;
auto text = model::model_to_string(anm2);
CHECK(game_document_get(text).find("AlphaOffset") == std::string::npos);
CHECK(model_load(text).frame_get({0, LAYER, 0, 0})->colorOffset.a == doctest::Approx(-127.0f / 255.0f));
CHECK(model::isaac_issues_get(anm2).alphaOffsetFrames == 1);
}