- Home /
Rendertexture + Normalized View Rect.
I'm using render textures to make it appear as though my user is drawing on the pages of a book. Essentially, the page texture of the book comes from a render texture, so my user can draw on it in real time (though the pen marks are really just being "videotaped" on another camera and sent to the page's texture, and then when the page turns (using the megafier deformers from the asset store), the drawing deforms with the page (yay!). But that's not the important, troubling thing -- that's just context.
The PROBLEM at the moment is that I can't seem to resize the camera's normalized view rect and have it display properly. That is, currently, the objects that the render texture is viewing are stretched out to fit the viewing area of the camera. This causes everything else that isn't stretched I put in front of that camera to look squished. Here are some screenshots of what's happening/going wrong. Let me know if you need higher res.
What do you think? How can I stop my camera from pulling these weird tricks?
Cheers,
Simon
Answer by Catlard · Feb 17, 2013 at 03:47 PM
Figured it out. I needed to mess with the tiling and offset on the materials of the rendertextures. Silly me.
This is a good solution if you are using the render texture for display only. I've run into the same problem and can't figure out a workaround because I need the exact pixels of the cropped normalized rect, to use it with GetPixels, ReadPixels etc.
I find it weird that a render texture from a camera seems to keep the screen ratio even if you have adjusted the normalized viewport rect. Strange.
Answer by Orahpajo · Feb 06, 2013 at 04:15 PM
Hi,
you are not alone with your problem. I use the RTs to make a minimap for my game. Anoing thing about that is, that my map has a longer and a smaller side so that I would like to rescale my camera. But when I do that, my RT crops the long side down to the side of the short side.
Regards
Very glad to know I'm not alone! I've about given up hope of having this answered here. I'll try editing the question, and see if anything new pops up. Thanks, dude. It sounds like we're having a similar problem.
Hi again,
I came up with a solution for my problem, maybe it is helping you to. I use Scale$$anonymous$$ode.ScaleAndCrop
like in the follwoing line:
GUI.DrawTexture(new Rect(Screen.width-210, 10, 200, 100), mapTexture,Scale$$anonymous$$ode.ScaleAndCrop, true, 0f);
This way the texture is cropped 50px on the top and 50px on the bottom, because the crop happens centered.
Regards
Ah! Sorry, Unfortunately, I don't think that's going to work -- because I can't use GUI.drawtexture for what I'm doing -- it has to be done through rendertextures. Thanks, though!
Your answer
Follow this Question
Related Questions
Unity Grabpass Feature 1 Answer
Applying post-processing effects to RenderTextures 1 Answer
Mouseclick GameObject through the view of a RenderTexture 0 Answers
Screen Points to construct a Rect (Not axis aligned) 0 Answers
What is the procedure of capturing a particular region using Render Texture 0 Answers