We positioned the object in front of our camera, and changed the object to the render camera layer.We cloned the object we want to take a picture of.We’ve set up a camera on its own layer.This will render everything the camera sees into our render texture. This means that when we tell the camera to render, the results will go to our render texture instead of the screen.Īnd the render comes next. We assign the temporary render texture to our camera’s target texture. So it’s a good idea to check for a null return value and deal with it accordingly. It’s worth mentioning that if you ask for a format that isn’t supported the texture will come back as null without raising any errors (at least it did for me). ![]() You can check out the documentation for additional parameters and other information about how it works. Here, we’re asking for a small texture with a 16-bit depth buffer. RenderTexture.GetTemporary allows us to acquire a temporary render texture from a pool maintained by Unity. camera.targetTexture = RenderTexture.GetTemporary(128, 128, 16) I believe it was designed to simplify post processing effects, but it works equally well for our needs. We could create a render texture in the editor and assign it to the camera, but Unity provides a nice way to acquire a temporary render texture with code. void SetLayerRecursively(GameObject o, int layer)įoreach (Transform t in o.GetComponentsInChildren (true)) So we set the layer by calling this function, passing in the cloned object. Now we need to make sure the cloned object, and any children, are in the layer that the camera renders. You can really do whatever you want here, even add multiple objects and lights and set up a whole scene. These values need to be set so the object is positioned in front of the rendering camera. We instantiate the object at the desired position and rotation, then set the scale. GameObject.Instantiate(prefab, position, rotation) as GameObject This lets us change the object’s properties at will without messing with the original. ![]() To render the object, we first want to clone it. Also, you’ll need to remove the Audio Listener or you get complaints from Unity about having multiples. The camera and the light all get their own layer to work on, and the main game camera has its culling mask set to ignore that layer. I usually make it orthographic and fill with a solid background color, but you can really do anything you want. I’ll mostly just describe the actual rendering part, and you can look at the code for the rest.įirst, we set up a camera that will be used to render the object. I’m not going to do a step by step tutorial. I’ll spend the rest of this post describing how I do this sort of thing. Render Textures are a straightforward method for creating an image like this at runtime. These images could be created statically by your artist, but sometimes the image needs to change based on something happening in the game, or there is some other compelling reason where runtime creation is required. For example, to display in a toolbar, or chat message or something similar. My idea is to somehow set black as transparent, and if i want to use black as paint, i can just pick the shade right next to it.On occasion when making a video game there is a need to display a texture that contains an image of a 3D game object. Problem is the render texture is black, and i want it transparent with only the painted areas showing on the board. ![]() So far i been using blit and a shader to draw on a render texture that i placed on the whiteboard. Is there any established method in unity to make render texture render its default black color as transparent? Is there a better way, should i not use render texture? The reason i use render texture is cause i want to use blit To be clear i am not using a camera for the render texture, i don't want to project anything on it, just draw, but i want the whiteboards base material to show through where render texture is its default black color,I am making a whiteboard, and i am looking for an efficient way to draw on it. ![]() My idea is to somehow set black as transparent, and if i want to use black as paint, i can just pick the shade right next to it. I am making a whiteboard, and i am looking for an efficient way to draw on it. I will try to post this again, tried to post before but on login in the post was duplicated, and then i was sent to moderators.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |