Skip to content

Implements color matrices, allows /atom.color to be set with one - #1062

Merged
wixoaGit merged 15 commits into
OpenDreamProject:masterfrom
Altoids1:color-matrix-DMside
Mar 27, 2023
Merged

wixoaGit merged 15 commits into
OpenDreamProject:masterfrom
Altoids1:color-matrix-DMside

Conversation

@Altoids1

@Altoids1 Altoids1 commented Feb 14, 2023 •

Copy link
Copy Markdown
Contributor

image

Summary

This was supposed to be me doing something very simple to dip my toes into the graphics side of this project, but lucky for me, this has been a total trap. After a few days of losing my mind, here's something that only works with novel RT code.

Changelog

  • Setting /atom.color to a color matrix now works.
  • The color filter (instantiated by filter(type="color",..) now works.

@amylizzle

Copy link
Copy Markdown
Collaborator

minor bug found: setting color to a matrix and then setting filters seems to delete the color matrix filter.

/obj/thing
    color = list(null, null, null, "#0000", "#333f")

    New()
        src.filters = filter(type="alpha", render_source="button")```

@Altoids1

Copy link
Copy Markdown
Contributor Author

minor bug found: setting color to a matrix and then setting filters seems to delete the color matrix filter.

/obj/thing
    color = list(null, null, null, "#0000", "#333f")

    New()
        src.filters = filter(type="alpha", render_source="button")```

I've pretty much come to the conclusion that "color" will have to be treated very specially by filter() to handle the fact that it's implicitly also interfaced with by /atom.color

@Altoids1
Altoids1 force-pushed the color-matrix-DMside branch 2 times, most recently from 33e1360 to ed8a80a Compare February 17, 2023 22:16
@amylizzle amylizzle mentioned this pull request Feb 27, 2023
6 of 14 tasks

@amylizzle amylizzle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Minor things.

Have you tested this with an invert color matrix? I'm just wondering if the shader's color vector does clamping or anything before output.

Comment thread OpenDreamClient/Rendering/DreamIcon.cs Resolved
Comment thread OpenDreamShared/Dream/IconAppearance.cs Resolved
Comment thread Resources/Shaders/colormatrix.swsl Resolved
@github-actions

github-actions Bot commented Mar 2, 2023

Copy link
Copy Markdown

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Altoids1 added 12 commits March 21, 2023 18:10
This is going to end up used a lot for our implementation of DM color matrices.
While implementing more of /atom.color, I ended up creating a cyclical dependency where, creating an appearance required accessing the color var, and doing a get on the color var required the appearance. This caused a stack overflow as it attempted to create an appearance a zillion times.

None of that is featured here though, just some changes to avoid the implicit instantiation of an appearance when just asking if it exists or not.
Previously, defaultAlpha would not kick in if the color was long enough. Fixed that! :^)

(hopefully that doesn't break anything :c)
Still need to allow invokation of it via setting the filters var but, hey, look at that! :^)
Also corrects the default argument for the shader, so the client doesn't crash :^)
This is basically what it means to implement the new color filter for filter() and the filters metaobject list thingie.

Also adds a rudimentary test for this in IntegrationTests.

I think this works? :^)
This PR also includes a parity note: I am not sure how BYOND handles setting a color filter when an atom already has a color var set to a color string (a ColorMatrix crashes in BYOND, however). We can investigate later if it's important :^)

EDIT: Removed hack once I figured out what the heck I was missing in my serialization class thing for ColorMatrix
This is the... simplest thing I could think of for handling the fact that an atom can get a color matrix in two ways: one from a filter, and one from assigning to /atom.color.

Also includes some patches done in response to reviews on the PR by people who aren't Wixoa. Thanks everybody.

EDIT: Removes random debug print I left in there :^)
@Altoids1
Altoids1 force-pushed the color-matrix-DMside branch from 242268f to 5b97d2c Compare March 22, 2023 18:50
@amylizzle

Copy link
Copy Markdown
Collaborator

Setting a color on /turf's definition like

/turf
	color = matrix(1,0,0,0,1,0,0,0,1)

causes a lot of this error to spam:

=DM StackTrace=
   /atom/<init>
   new /turf
2

=C# StackTrace=
System.Collections.Generic.KeyNotFoundException: The given key '4294967295' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at OpenDreamRuntime.Rendering.ServerAppearanceSystem.MustGetAppearance(UInt32 appearanceId) in /home/amy/OpenDream/OpenDreamRuntime/Rendering/ServerAppearanceSystem.cs:line 50
   at OpenDreamRuntime.DreamMapManager.MustGetTurfAppearance(DreamObject turf) in /home/amy/OpenDream/OpenDreamRuntime/DreamMapManager.cs:line 196
   at OpenDreamRuntime.AtomManager.UpdateAppearance(DreamObject atom, Action`1 update) in /home/amy/OpenDream/OpenDreamRuntime/AtomManager.cs:line 88
   at OpenDreamRuntime.Objects.MetaObjects.DreamMetaObjectAtom.OnVariableSet(DreamObject dreamObject, String varName, DreamValue value, DreamValue oldValue) in /home/amy/OpenDream/OpenDreamRuntime/Objects/MetaObjects/DreamMetaObjectAtom.cs:line 129
   at OpenDreamRuntime.Objects.MetaObjects.DreamMetaObjectTurf.OnVariableSet(DreamObject dreamObject, String varName, DreamValue value, DreamValue oldValue) in /home/amy/OpenDream/OpenDreamRuntime/Objects/MetaObjects/DreamMetaObjectTurf.cs:line 26
   at OpenDreamRuntime.Objects.DreamObject.SetVariable(String name, DreamValue value) in /home/amy/OpenDream/OpenDreamRuntime/Objects/DreamObject.cs:line 111
   at OpenDreamRuntime.Procs.DMProcState.AssignReference(DMReference reference, DreamValue value) in /home/amy/OpenDream/OpenDreamRuntime/Procs/DMProc.cs:line 538
   at OpenDreamRuntime.Procs.DMOpcodeHandlers.Assign(DMProcState state) in /home/amy/OpenDream/OpenDreamRuntime/Procs/DMOpcodeHandlers.cs:line 27
   at OpenDreamRuntime.Procs.DMProcState.Resume() in /home/amy/OpenDream/OpenDreamRuntime/Procs/DMProc.cs:line 297
   at OpenDreamRuntime.DreamThread.Resume() in /home/amy/OpenDream/OpenDreamRuntime/DreamThread.cs:line 231```

@out-of-phaze

Copy link
Copy Markdown
Contributor

Is it actually valid to set color with a 3x3 matrix (as in, via matrix()) in BYOND? The BYOND ref seems to imply it's not supported.

@amylizzle

Copy link
Copy Markdown
Collaborator

Is it actually valid to set color with a 3x3 matrix (as in, via matrix()) in BYOND? The BYOND ref seems to imply it's not supported.

You are correct, it should be a list(), but also the error is still the same. Also also we should probably compile error on invalid color setting like that.

Eventually we're going to want a better solution to this, but this should be fine for now.

Also edited the values for the color matrix demo so that it will actually display any discrepancies caused by colour-space-related hooplah.
Comment thread OpenDreamShared/Dream/IconAppearance.cs Resolved
Comment thread OpenDreamShared/Dream/IconAppearance.cs Resolved
Comment thread OpenDreamShared/Dream/ColorMatrix.cs Resolved
Comment thread OpenDreamRuntime/AtomManager.cs Resolved
Comment thread OpenDreamRuntime/DreamMapManager.cs Resolved
Comment thread OpenDreamRuntime/DreamMapManager.cs Resolved
@wixoaGit
wixoaGit merged commit f919184 into OpenDreamProject:master Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants