Skip to main content
Known Participant
February 10, 2025
Answered

transform world

  • February 10, 2025
  • 1 reply
  • 739 views
Hi folks, not sure if it's possible, but I would like to use transform_world on top of each other. What I mean is to do first transformation, then save it and do other transformation on that result (in a loop). The reason is I want to do initial matrix transformation on one instance (translate,scale,rotation) and then take that result and do other transormation multiple times. Reason for this is to reduce time of matrix multiplication.

Here is approximate code of what I have in mind (but not working as expected of course)

 

// initial transform
ERR(in_data->utils->transform_world(in_data->effect_ref,
  in_data->quality,
  PF_MF_Alpha_STRAIGHT,
  in_data->field,
  input,
  &composite_mode,
  NULL,
  &initial_matrix,
  1L,
  TRUE,
  &output->extent_hint,
  output));

// take output and use that as input
for(A_long i=0; i<100; i++){

  ERR(in_data->utils->transform_world(in_data->effect_ref,
  in_data->quality,
  PF_MF_Alpha_STRAIGHT,
  in_data->field,
  output,
  &composite_mode,
  NULL,
  &second_matrix,
  1L,
  TRUE,
  &output->extent_hint,
  output));

  }

 

 

If I take output as input in looped transform, I get weird results. If I create a new PF_EffectWorld and use that, it also doesn't work properly.
I've pretty much tried anything you can thing of in last week or so, and maybe I'm missing something obvious. Any help would be much appreciated.
Correct answer shachar carmi

ok... i think i partially understand what you're aiming for... i too do some preparative re-transformations of the result, but i do this to achieve exponential replications. 🙂

anyways, here are a the consideration you should take into... consideration...

1. when you transform an image in any way where original pixels don't end up on exact "whole" pixels, the image gets degraded. for example, if an input pixel ends up half way between two output pixels, these two pixels will have that input pixel blended between them. so re-transforming several times with "lossy" transformations, will give you a degraded result (blurry or jagged) compared to a single transformation render with a single matrix containing all the transformation operations.

2. transformation matrix multiplication is VERY cheap. it's a 3x3 matrix. you do like, 20 something operations to multiple the matrix, and then you go and to 6(ish) operations PER PIXEL when rendering, summing up at the TENS OF MILLIONS of operations per 2K image transformed... (without even talking about subsampling...). so you save very little time multiplying the matrices, and spend a TON of time doing redundant rendering.

 

as per "never use 2 renders (transform_world)", i think you misunderstood what i wrote. never use the same buffer as both the input and the output of transform_world, as it reads the input and overwrites it at the same time, most likely resulting in a corrupted output.

if you want to do repeated transformations you should:
1. create a new buffer. let's call it "temp".

2. transform the input to temp.

3. transform temp to output.

4. transform output back to temp.

5. repeat steps 2-4 as much as needed.

6. if the last transformation ended up on temp, copy it to output.

7. NEVER overwrite the input buffer... AE hands you the original, which it caches. writing to the input buffer creates the most bizarre bugs. don't ask.

1 reply

Community Expert
February 10, 2025

1. you can't use the same buffer as both the transform_world input and output. they have to be two different buffers. that might be the cause of the issue you're seeing.
2. FOR THE LOVE OF GOD, MULTIPLY THE MATRICES AND DON'T DO TWO RENDERS!!! AAAAAA!!!!!

Known Participant
February 10, 2025

Sure Shachar :), newbie here and I'm trying to understand this, and I will listen to any advice. But let me explain my issue I'm trying to solve.
So, imagine you want to copy input pixels many times (like a cloner), if I do 1 transformation in a loop, in matrix multiplication I have to multply initial position, scale, rotation in every instance of a loop, which is imho unnecessary cost. I would like to do this initially first, that take that result and to further do matrix operations. That way it's much faster. So, to recap, never use 2 renders (transform_world)? And any advice on how to achive this would be appreciated! Thanks!

shachar carmiCommunity ExpertCorrect answer
Community Expert
February 10, 2025

ok... i think i partially understand what you're aiming for... i too do some preparative re-transformations of the result, but i do this to achieve exponential replications. 🙂

anyways, here are a the consideration you should take into... consideration...

1. when you transform an image in any way where original pixels don't end up on exact "whole" pixels, the image gets degraded. for example, if an input pixel ends up half way between two output pixels, these two pixels will have that input pixel blended between them. so re-transforming several times with "lossy" transformations, will give you a degraded result (blurry or jagged) compared to a single transformation render with a single matrix containing all the transformation operations.

2. transformation matrix multiplication is VERY cheap. it's a 3x3 matrix. you do like, 20 something operations to multiple the matrix, and then you go and to 6(ish) operations PER PIXEL when rendering, summing up at the TENS OF MILLIONS of operations per 2K image transformed... (without even talking about subsampling...). so you save very little time multiplying the matrices, and spend a TON of time doing redundant rendering.

 

as per "never use 2 renders (transform_world)", i think you misunderstood what i wrote. never use the same buffer as both the input and the output of transform_world, as it reads the input and overwrites it at the same time, most likely resulting in a corrupted output.

if you want to do repeated transformations you should:
1. create a new buffer. let's call it "temp".

2. transform the input to temp.

3. transform temp to output.

4. transform output back to temp.

5. repeat steps 2-4 as much as needed.

6. if the last transformation ended up on temp, copy it to output.

7. NEVER overwrite the input buffer... AE hands you the original, which it caches. writing to the input buffer creates the most bizarre bugs. don't ask.