Scirra / Construct-bugs

Public bug report submissions for Construct 3 and Construct Animate. Please read the guidelines then click the 'Issues' tab to get started.
https://www.construct.net
108 stars 83 forks source link

Drawing canvas premultiply alpha bug #8024

Closed WilsonPercival closed 4 months ago

WilsonPercival commented 4 months ago

Problem description

I have a Drawing canvas. When I change the background color of the layer to white, the Drawing canvas becomes invisible.

Attach a .c3p

drawing_canvas_premultiply_alpha_bug_r263b.zip

Steps to reproduce

  1. Open and run the project.
  2. Press any key.

Observed result

https://github.com/WilsonPercival/WilsonPercival/assets/91274932/e9090e21-7615-4e54-8468-4a51abefaf09

Expected result

I should see Drawing canvas no matter what color the layer is.

More details

Affected browsers/platforms: Chrome

First affected release: Broke in r263b because this is the first version in which the drawingCanvas.surfaceDeviceWidth method started working.

System details

View details Platform information Product: Construct 3 r392 (beta) Browser: Chrome 124.0.6367.208 Browser engine: Chromium Context: browser Operating system: Windows 11 Device type: desktop Device pixel ratio: 1.5 Logical CPU cores: 16 Approx. device memory: 8 GB User agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Language setting: en-US Local storage Storage quota (approx): 283 gb Storage usage (approx): 34 mb (0%) Persistant storage: Yes Browser support notes This list contains missing features that are not required, but could improve performance or user experience if supported. Nothing is missing. Everything is OK! WebGL information Version string: WebGL 2.0 (OpenGL ES 3.0 Chromium) Numeric version: 2 Supports NPOT textures: yes Supports GPU profiling: no Supports highp precision: yes Vendor: Google Inc. (AMD) Renderer: ANGLE (AMD, AMD Radeon(TM) Graphics (0x00001638) Direct3D11 vs_5_0 ps_5_0, D3D11) Major performance caveat: no Maximum texture size: 16384 Point size range: 1 to 1024 Extensions: EXT_clip_control EXT_color_buffer_float EXT_color_buffer_half_float EXT_conservative_depth EXT_depth_clamp EXT_disjoint_timer_query_webgl2 EXT_float_blend EXT_polygon_offset_clamp EXT_texture_compression_bptc EXT_texture_compression_rgtc EXT_texture_filter_anisotropic EXT_texture_mirror_clamp_to_edge EXT_texture_norm16 KHR_parallel_shader_compile NV_shader_noperspective_interpolation OES_draw_buffers_indexed OES_texture_float_linear OVR_multiview2 WEBGL_blend_func_extended WEBGL_clip_cull_distance WEBGL_compressed_texture_s3tc WEBGL_compressed_texture_s3tc_srgb WEBGL_debug_renderer_info WEBGL_debug_shaders WEBGL_lose_context WEBGL_multi_draw WEBGL_polygon_mode WEBGL_provoking_vertex WEBGL_stencil_texturing Audio information System sample rate: 48000 Hz Output channels: 2 Output interpretation: speakers Supported decode formats: WebM Opus (audio/webm;codecs=opus) WebM Vorbis (audio/webm;codecs=vorbis) MPEG-4 Opus (audio/mp4;codecs=opus) MPEG-4 AAC (audio/mp4;codecs=mp4a.40.2) MP3 (audio/mpeg) FLAC (audio/flac) PCM WAV (audio/wav;codecs=1) Supported encode formats: WebM Opus (audio/webm;codecs=opus) Video information Supported decode formats: WebM AV1 (video/webm;codecs=av01.0.00M.08) WebM VP9 (video/webm;codecs=vp9) WebM VP8 (video/webm;codecs=vp8) MPEG-4 AV1 (video/mp4;codecs=av01.0.00M.08) MPEG-4 H.265 (video/mp4;codecs=hev1.1.2.L93.B0) MPEG-4 H.264 (video/mp4;codecs=avc1.420034) Supported encode formats: WebM AV1 (video/webm;codecs=av01.0.00M.08) WebM VP9 (video/webm;codecs=vp9) WebM VP8 (video/webm;codecs=vp8) WebM H.264 (video/webm;codecs=avc1.420034)
AshleyScirra commented 4 months ago

This is a bug in your code. You load image data with red components of 255 but alpha components of 0, which is not premultiplied. loadImagePixelData() defaults the premultiplyAlpha parameter to false, so it does not attempt to premultiply this. Therefore you load unpremultiplied data as premultiplied, which is invalid, and renders incorrectly.

If you pass valid premultiplied data, or pass premultiplyAlpha as true, it should appear correct.