- Home /
Question by
slingchilders · Aug 30, 2017 at 07:52 PM ·
shaderstexture2dmaterials
Texture2D created at runtime has different color values for the shader than the same one imported to the editor
I have a very simple shader that switches pixel colors of a texture:
float myR = floor(c.r == 1.0 ? 255 : c.r * 256.0);
float myG = floor(c.g == 1.0 ? 255 : c.g * 256.0);
float myB = floor(c.b == 1.0 ? 255 : c.b * 256.0);
if (myR == 255.0 && myG == 255.0 && myB == 102.0) {
c = _Detail1;
}
When I import a texture to the editor and set it to be uncompressed, point filter, with no mipmaps this change works perfect.
Now, I tried to create a texture at runtime from the same file. Using the same settings, and now the shader doesn't switch the colors. It's exactly the same file, created as such:
Texture2D tex = new Texture2D(1, 1, TextureFormat.ARGB32, false);
tex .LoadImage(File.ReadAllBytes(filePath));
tex .filterMode = FilterMode.Point;
Then I pass this texture to the exactly same material, and the shader is not working. What gives?
I tried setting every Texture format possible, and it doesn't change anything.
Either texture2d.LoadImage behaves differently to what Editor does and gives slightly different pixel values, or there's some hidden compression somewhere :/
Any tips?
Comment
Your answer
