Hello,
In my script I am generating a texture3D and I just figured out, that I probably have forgotten to script a normalization process that puts my values in between 0 and 1. I didn’t check if any of my thousand values are higher or lower then this boarders but I expect that they easily are outside. So since I didn’t implement a normalization and also since I receive a texture that represents what I expected It should, I wonder if there is a default value normalization implement by unity itself?
for example somewhere in here:
texture.SetPixels(colors);
texture.Apply();
What do I mean with Normalization:
Normalization puts the values into a specific range, most often in between 0 and 1. Like that an array will be changed from its original look [1, 0, 1, 2, 5, 1, 3, 1] into [0.2, 0, 0.2, 0.4, 1, 0.2, 0.6, 0.2].
If there wouldn’t be a normalization the first array would be represented as a texture that looks something like [1,0,1,1,1,1,1,1] fully colored or non colored since there are no values between 0 and 1. the normalized array on the other hand would be represented with a gradually changing color.
Does anybody know if there is a normalization method used in the unity texture creation process or was it just lucky circumstance that it seems to lead to my expected outcome?
I’d be surprised if that was the case but take a RenderDoc capture and check.
Maybe you are using a floating point texture format?
for using the UVW coordinates, isn’t it ment to be float since you need values between 0 to 1? even if the format is RGBA32?
When you look at GraphicsFormat, you can find formats ending with _UNORM, _SNORM, _UINT, _SINT, _SFLOAT and _SRGB. _UNORM means, you’ll get a value between 0 and 1 when sampling. _SNORM gives you a value between -1 and 1. _UINT is an unsigned integer, _SINT is a signed integer, _SFLOAT is a floating point value and _SRGB is a linearized value between 0 and 1.
This is also true for the TextureFormat and RenderTextureFormat formats, they are just not named that clearly and SRGB is a separate flag.
When you use a _UNORM format like TextureFormat.RGBA32, the texture can’t hold any value outside the 0-1 range. Values outside of that range will be clamped. Also you only have 8 bits per channel so 256 possible values between 0 and 1. You could say, it’s a fixed point format.
A floating point format like _SFLOAT allows you to store a floating point value that is not restricted to 0 to 1. It also has a higher precision due to being floating point instead of fixed point and 16 or 32 bits per channel.
So if you used a _SFLOAT format, the values wouldn’t be clamped and the shader would see the values that you put in [1, 0, 1, 2, 5, 1, 3, 1]. That could explain why you are not seeing any artifacts. If you did not use a _SFLOAT format, I don’t know why you are not seeing any artifacts but you could check the values of the texture in RenderDoc.
I hope that answers your question because I’m not 100% sure if I understood you correctly.
1 Like
Awesome explanation. Thanks a lot. It helped me to understand the topic. Unfortunately I am using a _UNORM texture. I’ll try to figure out how that RenderDoc is working to confirm that it is really a _UNORM texture.
Maybe I messed up something in my code, but that is at least a hint for me where to search the cause of my problem. Thanks for that one.
But even more fascinating is what you mentioned about the _SNORM. I’ll try to figure out if that could be of use for me, since I am using now 2 channels (1 with values 0to1 representing positive values, and 1 with values 0to1 representing negative values). With your hint I might be able to reduce the channel amount I’ am using, that would be awesome.