- Home /
Render Texture to Full Quality Texture for GUI Use
So I am rendering items into 48x48 images for icons for items in my RPG's Inventory. Everything renders correctly, and the alpha works correctly just as I want, but the problem is the Quality settings (Specifically the Half Res Texture Quality etc) are lowering the quality of the texture (as it should). The way I would fix this with a texture being painted on the GUI would be by changing the import settings to GUI Texture Type. This would allow the texture to not be affected by the quality settings.
The issue is, I'm rendering this texture at Runtime using Render Texture, and ending up with a Texture2D. How can I change the texture type to GUI so it won't be affected by the quality settings?
How it looks on Quarter Resolution:
How it looks on Full Resolution:
@FrankStars$$anonymous$$o well, I would but I can't because i create the textures at runtime by using the Render Texture class and a camera. That's the dilemma haha!
The screen size isn't important, as the texture size will always need to be 48x48. I'm also not using the camera's viewport rectangle, as the camera is disabled and is rendering the image to the texture, which is then being drawn on the screen using GUITexture.Draw(..)
private void RenderItemTexture(int id) {
CameraObj.transform.position = items[id].getCameraPosition();
cameraObj.transform.rotation = items[id].getCameraRotation();
GameObject itemObject = (GameObject) Instantiate(items[id].getItemObject());
itemObject.transform.position = Vector3.zero;
RenderTexture currentRT = new RenderTexture(48,48,16,RenderTextureFormat.ARGB32);
currentRT.anisoLevel = 0;
cameraObj.GetComponent<Camera>().targetTexture = currentRT;
RenderTexture.active = cameraObj.GetComponent<Camera>().targetTexture;
cameraObj.GetComponent<Camera>().Render();
Texture2D image = new Texture2D(currentRT.width, currentRT.height);
image.ReadPixels(new Rect(0, 0, currentRT.width, currentRT.height), 0, 0);
image.Apply(false);
RenderTexture.active = null;
items[id].setItemTexture(image);
Destroy (itemObject);
}
@FrankStars$$anonymous$$o That did nothing. The only way I can see this being fixed is if I can change the texture type to GUI. I can't seem to figure out how to do that though at runtime.
Well that's not the issue. I'm okay with the texture on the actual model the camera is viewing being reduced. It also isn't causing the issue.
The Actual texture being created in the code i posted previously, the Texture2D image = new Texture2D(...) is the texture having its resolution reduced due to the quality settings.
The only Solution I found was to make the texture 4x the size. On the lowest graphic settings on my rpg, I use Quarter texture resolution, so to keep the image looking the same on all settings I made it 192x192, 4 times bigger than 48x48. This allows it to look the same, but this really is not a good solution... It works fine for my needs at the moment, but it's an absolute waste of memory.
Answer by Richard 3 · May 20, 2014 at 07:58 AM
Hi. Have a look at mipMapBias, this will sharpen your image if you give it a negative value. Larger the negative value sharper your image will be. But be careful go to far negative as this will slow performance. Try -0.5 should look good.
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour {
void Example() {
renderer.material.mainTexture.mipMapBias = -0.5F;
}
}
Cheers!
Your answer
Follow this Question
Related Questions
RenderTexture not working when in WebPlayer, unless in fullscreen 1 Answer
unity 3 Render Texture limitations on IOS (cant set bigger then 512 - bug?) 2 Answers
is using OnPostRender to draw textures Pro only? 3 Answers
Odd-size RenderTexture for rectangular minimap 0 Answers
How to update texture during runtime to display damage? 0 Answers