export render texture without lights

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…

thanks in advance

so, after a lot of test, I’ve reached to match the size, but the light influence by my result:
here is a part of my texture material:

and is is a part of the rendered image:

as you can see, the colors are altered:

before take the shot, I change the light with this code:

RenderSettings.defaultReflectionMode = UnityEngine.Rendering.DefaultReflectionMode.Custom;
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Flat;
RenderSettings.ambientEquatorColor = Color.white;
RenderSettings.ambientGroundColor = Color.white;
RenderSettings.ambientLight = Color.white;
RenderSettings.ambientSkyColor = Color.white;
RenderSettings.reflectionIntensity = 0.0f;
RenderSettings.ambientIntensity = 1.0f;

any ideas?

thanks

  1. Why do you not use some Unlit shader which is not affected by any light? What do you try to achieve?
  2. 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.

hi @mholub !
I’ve got the problem that you tried to help me: save texture generated by a shader - Unity Engine - Unity Discussions
I’ve tried to another approach, but the result is not good

If you have small scene which has the object you need to bake, I’ll try to look into it in the evening

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.

  1. You can’t use shaders which depend on lighting. That’s why I modified shader. Look at CarTexture.shader for changes.
  2. 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

instead.

2203245–146343–BakeMaterial.unitypackage (25 KB)

thanks @mholub ! seems to be in the right way, but the output is different from the expected result:


if you see, the color for R is Orange, but in the output is yellow, I think that maybe due by the emission…

Looks like come color conversion issue like linear to srgb. I’ll look into it in the evening

thanks @mholub for your help!!
I’ve tried changing the rgb like this:

c.r = pR / 1.9765625f;
c.g = pG / 1.9765625f;
c.b = pB / 1.9765625f;

is not perfect, but seems more precise

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

2206322–146613–BakeMaterialUnlit.unitypackage (11 KB)

1 Like

thanks @mholub !! :slight_smile:
you’re a great!

@mholub now works fine, but, strange thing, if I test from the editor the texture is exported correctly, if I create the .exe, the texture is lighten… :hushed: