Posts

Showing posts with the label webgl

Mapped color transformation on cors tainted image

Image
Clash Royale CLAN TAG #URR8PPP Mapped color transformation on cors tainted image I need to transform colors in an image obtained from an s3 server which disallows crossOrigin. This is the functionality I need: const img = new Image(); img.src = src; ctx.drawImage(img, 0, 0); const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); const colors = [25,50,100,255]; const data = imageData.data; for (let i = 0; i < data.length; i += 4) { if(data[i] == 1){data[i] = colors[1]} if(data[i] == 2){data[i] = colors[2]} if(data[i] == 3){data[i] = colors[3]} } but got tainted by crossOrigin error: I know I can not use getImageData in this case. I don't want to read the image data. getImageData But maybe complete my task through some other webGL / canvas operation? Rendering on a server or proxying is not possible. Possible duplicate of How to fix getImageData() error The canvas has been tainted by cross-origin data? ...

exact coordinates of gl_PointCoord?

Image
Clash Royale CLAN TAG #URR8PPP exact coordinates of gl_PointCoord? In a vertex i give pointSize a value bigger than 1. Say 15. In the fragment i would like choose a point inside that 15x15 square : vec2 sprite = gl_PointCoord; if (sprite.s == (9. )/15.0 ) discard ; gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); But that does not work when Size is not a power of 2. (if size is 16, so (sprite.s == a/16.) where a is in 1..16 : Perfect !) is a way to achieve my purpose where size is not of power of 2 ? edit : i know the solution with a texture of size : PointSize * PointSize gl_FragColor = texture2D(tex, gl_PointCoord); but that not fit for dynamic change edit 26 july : first I do not understand why it is easier to read in a float texture using webgl2 rather than webgl. For my part I make an ext = gl.getExtension ("OES_texture_float"); and the gl.readpixel uses the same syntax. Then, it is certain that I did not understand everything but I tried the solution s = 0.25 and s = 0.75 ...