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
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