WebGL: Displaying new Texture2D as a RawTexture
Hi - it seems like creating Texture2Ds on runtime and modifiying them with SetPixel should not be a problem in a WebGL build - but somehow I cannot manage to get it working. On the long run I want to modify vertex positions with a new Texture2D.
When I noticed my approach did not work when building to WebGL I tried to display the texture as a RawTexture UI element - which is not an issue in the editor but it is not working in WebGL either.
This is the code I use to create the new texture:
meshRenderer.material = Instantiate(meshRenderer.material);
texture = new Texture2D(textureSize, textureSize, TextureFormat.Alpha8, true);
meshRenderer.material.SetTexture("_TexDYN", texture);
rawImage.texture = texture;
In this example textureSize is 64 as WebGL only supports power of two textures. I use TextureFormat.Alpha8 because i only need one channel for my texture - but using the default TextureFormat does not work either.
This is the code for updating the texture:
texture.SetPixel(pixelUV.x, pixelUV.y, new Color(value, value, value, value));
texture.Apply();
Pretty basic stuff I thought - are there any restrictions for WebGL I'm not aware of?
Everything works perfectly in the Editor and Windows Build.
I'm using Unity 2020.3.19f1
Your answer
Follow this Question
Related Questions
pixel perfect sprited converted from texture2d 0 Answers
[WebGL 2.0] Texture2DArray support? 1 Answer
Texture manipulation 0 Answers