GPv3: Texture offset modifier #119050
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Depends on
#119303 GPv3: Fill texture coordinates system
blender/blender
Reference: blender/blender#119050
Loading…
Reference in New Issue
No description provided.
Delete Branch "LukasTonne/blender:gp3-texture-modifier"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Port of the GPv2 texture modifier for transforming UVs of stroke points.
@blender-bot build
A note on converting legacy
uv_fac
and other point attributes:It looks at first like these attributes can be totally arbitrary and user-defined, and replacing them with a simple linear transform might lose data. However, these attributes are consistently overwritten by the
BKE_gpencil_stroke_uv_update
function in GPv2 whenever the geometry is modified and/or the batch cache is rebuilt. Even though these attribute can be modified through the RNA (they are mutable properties!), any such changes are volatile and will never be visible in renders. So ignoring the legacy UV attributes and not converting them is fine.I don't think this currently properly converts texture from the legacy system.
@ -3407,0 +3417,4 @@
float fill_scale;
/** Custom index for passes. */
int layer_pass;
/** Texture fit options. */
Do these comments need double asterisks? (i.e
/* Texture fit options. */
)I cleaned these up, but note that there are other GP2 modifiers that use this format. The style guide isn't explicit about this, i think both variants are fine. It's mostly copy/pasted code here anyway. We may want to do a cleanup pass once the last modifiers are finished.
@ -0,0 +135,4 @@
VArray<float2>::ForSingle(float2(1.0f, 1.0f), curves.curves_num())));
curves_mask.foreach_index(GrainSize(512), [&](int64_t curve_i) {
uv_translations.span[curve_i] += offset;
Have to be very careful here, the
uv_translation
,uv_rotation
anduv_scale
attributes are not the same as the legacy system. The legacy system were applied in the order: translation, rotation then scale. Where as the new system's order is: scale, rotation then translation. Other differences the legacy system had include a bounding box rescaling and the rotation was centered around the point (0.5, 0.5).Because of all of the changes I think it would be better to get the texture matrices transform them, then set the texture matrices, rather than directly working with the attributes.
I've implemented it now so that the effect of the modifier is compatible with the GPv2 way of constructing the transform.
The
texture_matrices
contain the unknown 3D transform, using them directly isn't possible without constructing the 2D UV transform from the attributes. So might as well use the attributes directly.The code converts the new
uv_translation
/uv_rotation
/uv_scale
attributes into the legacy values, then applies the modifier offset, then converts them back. I've considered calculating equivalent offsets for the new attributes directly, which would be slightly more efficient, but converting to the legacy format is clearer IMO and explains why we're doing this weird transformation. I hope the code comment is enough to make this understandable.It looks like the modifier only works properly on counter-clockwise strokes (see image)
@ -0,0 +128,4 @@
const float rotation,
const float scale)
{
/* Texture matrices are a combination of an unknown 3D transform into UV space, with a known 2D
My formater does not like this multi line comment, it should start with
/**
and the comment should be on the second line.This should be fine, the double asterisk is only needed for doxygen comments.
Counterexample:
5ae5614d1e/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc (L257-L266)
@ -0,0 +130,4 @@
{
/* Texture matrices are a combination of an unknown 3D transform into UV space, with a known 2D
* transform on top.
All lines in the comment block should have a
*
The GPv2 modifier actually does exactly the same! The reason is that the normal calculated by the 3-point transform is dependent on the winding order of points 0, 1, and
totpoints*0.75
(BKE_gpencil_stroke_2d_flat
andget_legacy_layer_to_stroke_matrix
respectively).If we want to "fix" this we might flip the normal to make it somewhat consistent across strokes, but that assumes we can determine a "forward" direction to compare against. In any case, i don't think this is something the texture offset modifier should be doing.
EDIT: Correction, i thought you were talking about the fact that the UVs are mirrored for clockwise strokes, but i guess you are referring to the difference in offset? I can't seem to reproduce this though, GPv2 strokes with the modifier look the same after converting. Do you have a test file?
Here's the file I used, the top stroke changes when converted. It appears that only the translation is incorrect, the rotation and scale works fine.
@casey-bianco-davis Object type for both the "Legacy" and "Convert" objects is
GPENCIL
, it looks like the "Convert" object isn't actually converted? It should beGREASEPENCIL
for GPv3.There is something else going on with the GPv2 strokes: When there are multiple GPv2 objects, as in the test file, moving an object (enforing UV updates) creates a completely different pattern. I have a suspicion that this is a GPv2 bug of some kind.
Something funky with the
get_legacy_layer_to_stroke_matrix
i noticed: the normals it computes are pointing in the same direction(0,-1,0)
for both cw and ccw strokes, while laterget_local_to_stroke_matrix
updates use a(0,1,0)
normal for the cw stroke. Picking arbitrary points on a non-convex shape such as the Suzanne example can lead to an "inverted" normal and flip the Y component of the local-to-stroke matrix translation, unlike the more stable Newell cross product. I don't know if this is at all relevant here.EDIT: FWIW i haven't been able to repro the issue when i make the GPv2 strokes convex (using the "to sphere" operator).
I would not spend too much time on this if the GPv2 UVs are buggy and we can't match the old behavior exactly.
What i think is happening:
To make the modifier behave the same way as in GPv2 it will have to compute the same 3-point stroke-to-layer transform, since it cannot rely on uv loc/rot/scale attributes to be interpreted the same way. Once the stroke-to-layer transform is factored out of the input texture matrix, the remaining uv transform should behave as expected, regardless of whether 3-point or Newell's normals are used. It's ugly, but necessary for consistent results if we can't make assumptions about the texture space basis.
Sorry about that, I should have made it clear in my comment, I left the both objects unconverted so that you could convert it.
The function
get_legacy_stroke_to_texture_matrix
atblender/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc:169
should be used to factor out the legacy texture matrix.I've changed it now to compute the legacy layer-to-stroke transform locally in the modifier, so as to not make assumptions about how the uv attributes are applied. This fixes the difference in transforms for concave strokes.
@blender-bot build
@blender-bot build