Image masking using through camera projection, how to?

Started by Tangled-Universe, December 18, 2007, 03:56:11 PM

Previous topic - Next topic

Tangled-Universe

Yes that exactly one of the reasons why I want to use through camera projection, besides that it is way more convenient when you're able to literally point where you want your effect to be in your current pov. If it works of course :P

Unfortunately my knowledge of functions and how to use them is very limited. I know their capabilities and I can't think of a method to achieve the same result I'm looking for, because I want to mask VERY specific (though large) areas.

In my opinion I think this is a kind of a bug, since the through camera projection doesn't work properly?

bigben

Haven't tested this with the new version but I have a quick test in mind which should provide a more accurate representation of the problem

bigben

OK... my 2c worth on the problem (ie. I could be wrong). Whenever you mention image projections I think back on stitching panoramas, and a possible cause struck me while walking to work. It may be possible that recilinear distortion used in the render calculation is not being matched by remapping the imagemap to match the camera's fov. This would cause alignment errors which would get worse as you move away from the centre of the image (which appears to be the case).

My test that I mentioned in my previous post was performed without this in mind, but it does match the expected behaviour. The attached image shows the difference between a tiled grid image using plan Y and the render of this applied as a TTL image. The errors are radial in nature and get larger as you get closer to the edges. Lines passing through the centre of the image won't be affected much.

The zip file contains the two TGDs and source images.

Have to work now, but if anyone wants to check this further, the problem should be exacerbated by using a wider fov (try 120° - 140°) and should be negligible at narrower fovs (try 5°). Increase the foc on the first TGD, render it and apply the output to the second TGD. (I had to convert the output image to greyscale and resave in Photoshop because TG didn't like the raw output TIFF)

If I'm right, then this is a problem that would make through the lens projection unusable for very accurate masking, but it should also provide a clue for a fix. I'll investigate this later and see if I can confirm this is the case and whether it is possible to do a pre-render remapping of the image map to counter the problem as an interim measure.

[edit] A possible solution to try may be to treat the original image map to be used with through the lens projection as an equirectangular image with the same FOV as the render camera and remap it to a rectilinear image with the same dimensions as the source image. I'll try this later tonight. If it works it should be a relatively simple workaround [/edit]

Matt

T-U,

Can you upload a .tgd that shows how you're trying to connect your shaders? If masking works with Y projection but fails when you try camera projection, there may be a bug that only appears in particular circumstances.

Matt
Just because milk is white doesn't mean that clouds are made of milk.

Tangled-Universe

Quote from: Matt on May 06, 2008, 10:14:35 AM
T-U,

Can you upload a .tgd that shows how you're trying to connect your shaders? If masking works with Y projection but fails when you try camera projection, there may be a bug that only appears in particular circumstances.

Matt


Thank you Matt.
I'm currently at work so I'll upload an example within about 4 hours.
Like I said my suspicion is a bug since using an image mask only for coloring surfaces works fine but when you plug it into a blendshader for populations or strata it freezes.
Unless I'm doing it the wrong way, I'll show you that within a few hours :)

@ BB

Thanks a lot for your time and effort on thinking about a solution for this.
I'll read your suggestions at home because I'm at work now and it seems a bit complicated at first glance.

Martin

Tangled-Universe

Hi Matt,

Here it is: just connect surface layer 01 to the planetshader and you'll see the program crashes.
When you connect surfacelayer 03 ('indirect' method)to the planetshader the program also crashes, but when you connect surfacelayer 02 to the planetshader the color of the mask is projected correctly.

I hope you can figure it out.
Thanks in advance!

Martin

Tangled-Universe

Seconds after posting the zip-file I tried saving the mask as a lzw-compressed tiff-file and that seems to work with both methods....BUT...

...when finishing the preview render after 3 seconds the program still crashes after about 10 seconds. The memory and CPU-usage do not spike. CPU @ 2% and RAM @ ~80 MB.
I've attached the lzw-compressed tiff-file as a zip, since it isn't accepted by the board.

Martin

bigben

Ran a couple more tests and my thoughts on image projection appear to be wrong. My last test worked properly, although some of the settings I used in the image node were different to what I normally use. Investigating the other settings to see if I can make it not work now ....  ???  ;)

Red grid lines in image below are from a plan Y imagemap. Green "lines" are using a rendered version as a through the lens image map applied as a fractal breakup for a shader. Details in the foreground corners line up correctly

[edit] Extra settings didn't make any difference apart from a very slight offset of the image which was expected. Trying a TGD with more severe displacements (including an overhang... an old Volker classic)[/edit]

Oshyan

I was thinking there was a fairly detailed and insightful discussion of this a while back and was looking for it to see if it had any clues, but then I realized it's just earlier in *this* thread. :P Ben, I presume you're using mask images that are exactly the same dimensions (or at least same aspect ratio) as the render, as per earlier discussion in this thread?

Tangled-Universe, if you're experiencing consistent crashing that's a different thing than what Ben is looking at I think. Does your crash happen with only one image type or have you tried multiple options (jpg, png, etc.)?

- Oshyan

bigben

The renders I'm doing at the moment to test this are the using masks that are the same size as the render. I had planned to increase the size of the mask image to see if resizing played any part.

I had experienced similar misalignment issues like the first examples in this thread but I've since been using planY instead as a workaround and didn't have any examples left. The good thing I guess is that so far it's working.  ;) I'll have a look at Martin's original example here next and see if that presents a problem.

Just to keep the discussion mixed... on the image loading problems... the first test I tried involved taking the render and using it "raw" as an image map but TG didn't like it, which I thought was odd. After I resaved in Photoshop it behaved nicely, but I suspect the sequence of events may have been similar to those in http://forums.planetside.co.uk/index.php?topic=3929.msg41671#msg41671. As this was the first time I'd seen this I put it down to a problem with the image file.

bigben

Swapping computers to get this morning's render....  ;)

OK it's still working. This image shows one of Volker's TGDs which was rendered first and a mask drawn over the render. The mask was then used to create a cyan surface layer and rendered. The original mask is overlayed in red in the image. There is a slight offset but this is probably a result of the image smoothing routines. To compensate for this you could move your mask image up and left by 1 pixel when you're finished, but this is not the problem described at the start of this thread.  If you turn off image smoothing it's more accurate, but then it's not smooth  ;)

Tangled-Universe

Great! Could you post the tgd and imagemasks here please? I'd like to take a look.
What's the difference from my method? Or better: did you use your previously described method or mine?

Martin

bigben

No need... I went back to your original files to compare them with my tests. The solution is quite simple, and thinking back... was the cause of my problems as well.

Disconnect the render camera from the image map... problem solved!  ;D

With no camera specified it uses the render camera anyway.

I finished up making a new mask from a render of your TGD to get an idea of how it was going wrong. It appeared to be being stretched vertically. Screengrab below shows your mask stretched to fit the rendered result with the render camera attached to the image map. It's stretched about 135% from the centre.

Oshyan

Ben, are you saying that it crashes when a camera is attached to the Image Map Shader?

- Oshyan

bigben

No crashing, just a misalignment.

When the render camera is attached the image is stretched vertically. I'll have a play tonight with different render proportions, but looking at this example in isolation it may be that the image width is set to the width of the render, and  the height is made the same as the width.

Width:Height here = 1.33 and mask image stretched by 133% to match rendered output

I had a very quick play this morning and I'm not necessarily confident that this is necessarily what is going on, but the behaviour is definitely consistent so there is some form of problem with connecting the camera and Through camera projection.

To explain the screengrab a little more, the bottom layer is the rendered TGD with large fake stones (bright white spots) masked by the mask image (camera attached to image map). I then overlayed the mask image with an opacity of 50% and stretched it to match the fake stones. The handles show the extent of the mask image resizing.