- Home /
Weird problem with render texture.
Hello there guys.
I just bought unity3d pro because i was in great need of the render texture effect.
My project at the moment needs to have 4 render textures that will be handled to create the content of the application.
I have 4 cameras that will pass the available data to be shown to those RTs.
Though i was in need to create the cameras fit in some specified aspect ratios.
So i applied this code to all of the cameras when the game is starting to initialize them.
/// <summary>
/// Determine the size of the camera depending on the aspect ratio that we need.
/// </summary>
public static Rect CameraViewPortRect(Camera c, Vector2 pageSize)
{
Rect rect = c.rect;
// set the desired aspect ratio.
float targetaspect = pageSize.x / pageSize.y;
// determine the game window's current aspect ratio.
float windowaspect = (float)Screen.width / (float)Screen.height;
// current viewport height should be scaled by this amount
float scaleheight = windowaspect / targetaspect;
// if scaled height is less than current height, add letterbox
if (scaleheight < 1.0f)
{
rect = c.rect;
rect.width = 1.0f;
rect.height = scaleheight;
rect.x = 0;
rect.y = (1.0f - scaleheight) / 2.0f;
c.rect = rect;
}
else // add pillarbox
{
float scalewidth = 1.0f / scaleheight;
rect = c.rect;
rect.width = scalewidth;
rect.height = 1.0f;
rect.x = (1.0f - scalewidth) / 2.0f;
rect.y = 0;
c.rect = rect;
}
return rect;
}
When i do so it means that i have the cameras that will pass the parameters to the render texture properly initialized. My cameras are orthographic with a size of 1.495 !
Those are the settings of all four RTs that will exist on my scene.
The modifications on the camera lead to the following result:
What i really cannot understand is the following result on the target geometry quad / plane that render texture is applied:
http://imageshack.com/a/img537/7224/4Qz9Hd.jpg
Sry for the comment like continuation of the post.
Well what i wanted though was to be able to have my render texture fit on the surface that is applied. And i cannot find a way that this can be done.
And secondly it behaves as if it ren renders a part of the camera that is applied onto. That means that this area in red that is in the center of the quad is a PART of the rescaled camera.
I cannot figure why it is behaving that way.
Your answer
Follow this Question
Related Questions
Project collaboration between free and pro users? 0 Answers
how do you apply a render texture to an object? 1 Answer
Portal effect using render textures: how should I move the camera? 2 Answers
Converting textures to video or frames 0 Answers
Save RenderTarget (Color Format: Depth) into a png as a heightmap 0 Answers