hi all!
I’m trying to export a texture of a square plane to png format: I tried to add a camera ortographic over my plane and use the camera with a rendertexture: everything seems ok, but I have 2 questions:
how can I match the size of the camera to the plane? the plane is squared, I wish a 2048x2048 tex without borders
How can I remove the light to the camera/render texture? suppose that the plane is red 255 0 0, I wish a png everything red, without light effects…
Why do you not use some Unlit shader which is not affected by any light? What do you try to achieve?
For size it is very easy. You take the height of plane in world units, divide it by 2 and this is the value you need to set into ortographic size of the camera. For example: default Unity plane has size 10x10. So ortographic size should be 5.
If for example you have 1 pixel to 1 world unit ratio and plane is 1920x1080 units, then ortographic size should be 540.
thanks @mholub for your time!!
here is the scene:
to test: run the scene, select ExportCamera object and check the Do Export property of Export instance:
thanks!! Cahoots — Ann Arbor Coworking Space
Import the package. Then open “Window/Bake material” from menu.
Select material and press “Bake” button (You can dock the window into right corner for convenience).
It will save output to the texture.
Why it didn’t work for you earlier.
You can’t use shaders which depend on lighting. That’s why I modified shader. Look at CarTexture.shader for changes.
Because your shader is surface shader (which means, it generates lots of small shaders for lots of passes in the pipeline), you can’t use
Graphics.Blit(from, to, material)
You should use
Graphics.Blit(from, to, material, 0) // use only first pass
As I don’t have time to properly investigate why surface shader doesn’t work, here is the solution with plain vertex/fragment shader. If you use linear lighting, you need to set “Bypass SRGB sampling” in output texture import settings