<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anneka Goss on Medium]]></title>
        <description><![CDATA[Stories by Anneka Goss on Medium]]></description>
        <link>https://medium.com/@annekagoss?source=rss-b503798ba927------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Wru0E6rV-kLsQrlDCMBIpw.jpeg</url>
            <title>Stories by Anneka Goss on Medium</title>
            <link>https://medium.com/@annekagoss?source=rss-b503798ba927------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 22:14:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@annekagoss/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Accessible WebGL]]></title>
            <link>https://annekagoss.medium.com/accessible-webgl-43d15f9caa21?source=rss-b503798ba927------2</link>
            <guid isPermaLink="false">https://medium.com/p/43d15f9caa21</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[graphics]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[creative]]></category>
            <category><![CDATA[accessibility]]></category>
            <dc:creator><![CDATA[Anneka Goss]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 16:50:39 GMT</pubDate>
            <atom:updated>2021-01-11T16:50:39.619Z</atom:updated>
            <content:encoded><![CDATA[<p>Accessibility and custom graphic effects are often framed as mutually exclusive concerns. When frontend teams rightfully choose to prioritize accessibility over flashy decoration, the possibilities for experimentation and novel experiences collapse and minimalism and uniformity dominate web experiences. Procedural graphics are quarantined to one-off experiments and separate codebases. The preference for simplicity and static assets is understandable considering how little is available in terms of documentation, best practices, and modern industry-standard tooling. However there are avenues for cooperation between accessibility and live-generated effects, and custom shaders can even be used to enforce some accessibility standards.</p><p>This article seeks to address the discrepancy between what is possible in terms of accessible WebGL and what is documented. In general, all guidelines for accessible animations also apply to live graphics. These include honoring reduced motion browser and device settings, providing pause and hide controls, and limiting confusing and overwhelming movement. The following sections will focus on accessibility strategies that are unique to WebGL and do not intend to minimize the importance of general animation guidelines. First will be a case study in the automatic enforcement of WGAC color contrast guidelines within media using fragment shaders, which provides a strategy for the accessible use of full screen background images and video. The second section is a guide for maintaining keyboard navigation and screen reader support when rasterizing DOM elements for effects that encompass both background and foreground content.</p><h3><strong>Accessible Contrast</strong></h3><p>Full-screen background images, video and animations are widely used for flashy splash screens and ad takeovers. As visually powerful as this may be, frontend teams always seems to run into the same problem: keeping the foreground text readable. Even with static images in the background, resizing the window will change which pixels lie underneath text content. Throw in additional accessible contrast guidelines and suddenly you need to rework the entire design strategy.</p><p>Instead of going back to the drawing board, WebGL can be used to programmatically enforce contrast ratios between background and foreground content, including non-generative image and video content. Given a WGAC contrast compliance level, a foreground text color, and background pixel data, a fragment shader can recolor a background to conform to the desired contrast ratio on the fly.</p><p>The Web Content Accessibility Guidelines (WCAG 2.1) define specifications for color contrast ratios that will be perceivable to users with visual impairments. A contrast ratio is a measure of relative perceived luminance between two colors ranging from 1:1 for no contrast and 21:1 for total contrast. The guidelines provide two contrast compliance levels: <a href="https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html">AA with a minimum ratio of 4.5:1 and AAA with a minimum of 7:1</a>, where AA ensures visibility for users with 20/40 visual acuity and AAA ensures visibility for users with 20/80 visual acuity. As of now AA is the recommended standard for most use cases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2OrnAf1ieKj51iIuRFBzaw.png" /><figcaption>Minimum contrast ratios for AA and AAA compliance levels.</figcaption></figure><p><a href="https://css-tricks.com/understanding-web-accessibility-color-contrast-guidelines-and-ratios/">This article by Stacie Arellano on CSS Tricks</a> is an excellent step-by-step guide for calculating the contrast ratio between two RGB colors. In a nutshell, the luminance for normalized, gamma-corrected colors can be found using this <a href="https://www.w3.org/TR/WCAG20-TECHS/G18.html#G18-tests">W3 relative luminance formula</a>. This is what <a href="https://webaim.org/resources/contrastchecker/">contrast checker tools</a> are doing with the hex colors that you enter. This checking can easily be ported to a fragment shader in a WebGL context, where it can be run concurrently per-pixel on a bitmap asset rather than on one single color. Beyond that, it can lighten or darken each pixel in proportion to its unique deviation from the desired ratio.</p><p>The following section explains a technical implementation of approximate per-pixel contrast correction based on a client project from last year. The design system centered around an abstract, full-screen background of three colors, the placement and RGB values of which were determined by a combination of user preferences and post-workout recovery habits. The foreground text and UI could either be black or white depending on the device theme preferences. This complexity of color combinations made it a good use case for a WebGL contrast-correction proof of concept.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*bZRJZ6Llv4pgrF-F-iItgA.gif" /><figcaption>Screen capture of the proof of concept for automatic color contrast correction. <a href="https://github.com/annekagoss/accessible-webgl-demos">https://github.com/annekagoss/accessible-webgl-demos</a></figcaption></figure><p>There are several options available for WebGL wrapper libraries that can simplify the setup process. <a href="https://threejs.org/">Three.js</a>, <a href="https://github.com/react-spring/react-three-fiber">React Three Fiber</a>, and <a href="https://aframe.io/">Aframe</a> are the most actively maintained at the moment. Regardless of your setup, the fundamental workflow for this contrast correction is the same.</p><p>After the external background source is loaded, pass it to a fragment shader as a sampler uniform along with the main foreground UI color and the target compliance ratio. During this step it’s important to normalize the RGB channels from 0–255 to 0–1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lmls5WXWgepQiIs6aLhn1g.png" /><figcaption>The WebGL pipeline for passing foreground color and target contrast compliance level to the fragment shader.</figcaption></figure><p>Within the fragment shader, the first step is to determine if the given pixel is above or below the target ratio. To do this, it’s possible to port the <a href="https://www.w3.org/TR/WCAG20-TECHS/G18.html#G18-tests">W3 relative luminance formula</a> from JavaScript. The three scalars that are multiplied to each channel at the end come from the <a href="https://www.itu.int/rec/R-REC-BT.709">HDTV broadcasting standards</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M1mYR7nC060DJj7-C06PjA.png" /></figure><p>The function for calculating the ratio between the background and foreground luminance values can also be ported from JavaScript examples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*DQIv7FoKeMA-ZdAjatx-bQ.png" /></figure><p>Once it’s established that the pixel color does need to be adjusted, the next step is to find a luminance that would result in the target ratio. A little bit of algebra transforms the contrast ratio function into one that outputs a new luminance, based on whether the color should be lightened or darkened.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LpaNWM7I-Aj3sFxWksBpGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NN61yNDH2i1Jg_sPHE8M4g.png" /><figcaption>Contrast correction within the fragment shader.</figcaption></figure><p>Now for the tricky part: applying this new luminance to the pixel color. Because this should target the luminance specifically without touching hue or saturation, the original RGB color will need to be transformed into another color space, and then transformed back after making the adjustment. The two common color spaces for this, HSL and HSV(HSB), handle lightness differently: HSL uses the maximum value of the R, G, and B color channels, while HSV uses the average between the highest and lowest color channel.</p><p>Determining which color space to use requires some experimentation. HSL seems to desaturate colors as it lightens them, while HSV maintains separation but makes colors appear too dark. In addition, HSL creates odd banding and glitching when darkening near-white colors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mdocsih7ncBPKTSmyNmjow.png" /><figcaption>Luminance adjustment in HSL and HSV color spaces.</figcaption></figure><p><a href="http://alienryderflex.com/hsp.html">HSP</a> is a lesser-known color space that uses perceptual luminance. It calculates the P channel slightly differently than the W3 relative luminance function, slightly prioritizing the green channel over red and blue to mimic human color perception.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*5e6Z72hAZBtFtMWMTCfaKg.png" /><figcaption>HSP perceptual lightness, in comparison to HSV and HSL. From HSP Color Model — Alternative to HSV (HSB) and HSL ©2006 Darel Rex Finley <a href="http://alienryderflex.com/hsp.html">http://alienryderflex.com/hsp.html</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*VZe5aBV4a-tWL3j5W0NUGg.png" /></figure><p>Although the HSP luminosity formula may be perceptually more accurate, it’s more useful to use the W3 version when trying to match their standards for contrast. Adjusting the HSP / RGB conversion functions to use the W3 standard results in slightly lighter colors, and the same saturation and accuracy benefits over HSL and HSV.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G3F221adLcYbA-NIvwySzw.png" /><figcaption>Luminance adjusted HSL, HSV, HSP, and HSP with W3 luminance color spaces.</figcaption></figure><p>To verify that the adjustments bring the colors to the target contrast ratio, the same luminance checking functions can be run over the new RGB value. Additionally, colors can be verified with a web-based contrast checker. The results show that this technique still results in lightened colors that are slightly too light, and darkened colors that are significantly too dark for all color spaces. However this is easily fixed by adding offsets to the luminance targets. Regardless of whether offsets were used, the adjusted HSP color space produced more accurate colors with better retained saturation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3GxLOYOPhH0kuId3cPkeZg.png" /><figcaption>Initial results with new contrast ratios. The numbers below the screenshots are the resulting color contrast ratios of the colors that are closest to the text color.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4vvbNfETXgpidUBA88nRDg.png" /><figcaption>Corrected results with new contrast ratios. The numbers below the screenshots are the resulting color contrast ratios of the colors that are closest to the text color.</figcaption></figure><p>The results may not be perfect, but they demonstrate that is is possible to programmatically adjust bitmap content to be more compliant with accessibility standards. This technique can be used with any image file type that can be used as the source for an image HTML tag. Video frames can also be processed on this fly, whether they come from a <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Tutorial/Animating_textures_in_WebGL">file</a>, stream or <a href="https://dev.to/terabaud/realtime-video-processing-with-webgl-5653">webcam</a>. Overall this strategy has potential to be refined and adapted as a browser extension or built-in CSS or SVG filter for easily increasing the contrast of media-heavy websites.</p><h3>Accessible DOM Rasterization</h3><p>DOM rasterization is the process of converting a DOM element or tree of elements into pixel data. It allows page elements like headings, text, and buttons to be rendered differently from how the browser would normally interpret their style rules. Rasterization occurs during<a href="https://css-tricks.com/browser-painting-and-considerations-for-web-performance/"> paint</a>, the last step that the browser takes to translate HTML, CSS and Javascript into the visual representation that appears on the screen. This is how<a href="https://css-tricks.com/almanac/properties/f/filter/"> CSS and SVG filters</a> work. They wait until the browser has painted the render tree to color data, and only then apply per-pixel effects. By sending rasterized DOM pixels to a WebGL fragment shader instead of a pre-defined filter, it’s possible to transform DOM elements with completely custom effects and interactions.<a href="http://taotajima.jp/"> Filmmaker Tao Tajima’s website</a> is a great example of this. It makes a rasterized copy of the text for each project description and distorts it along with the page transitions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3xcqA7QWx0oWMX2GZ6U7wA.png" /><figcaption>Rasterized text, mid transition.<a href="http://taotajima.jp/"> http://taotajima.jp/</a></figcaption></figure><p>The downside to custom rasterization is that it negates all of the interactivity and accessibility features that are native to DOM elements, when it flattens them into pixels on a canvas. Intuitive navigation, interaction and error states are invaluable for an accessible user experience. That includes visual feedback like focus states, accurate screen reader descriptions, and searchable text. Maintaining native DOM behavior is possible by using a copy of the rasterized DOM elements as an overlay, where text and UI element colors are all transparent.</p><p>Native interactions, visual feedback and responsiveness can all be maintained by overlaying the canvas with two copies of the original DOM elements. The first copy receives user input. Although its text and UI elements use transparent RGBA colors, they are themselves fully opaque to enable hover, focus, active states and other visual feedback. This copy then translates these local states to a second copy, which is hidden but uses fully opaque colors. The interactions then trigger a side effect which re-rasterizes the second colorful copy and sends updated uniforms to the shader. Interactions that are specific to the canvas should be read from the parent component in order to avoid triggering unwanted rasterizations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TkPfL2IunWzyA8WbYbHOVA.png" /><figcaption>Maintaining native DOM interactivity by overlaying multiple copies of the UI.</figcaption></figure><p>With this technique, keyboard navigation and screen reader messages can be designed normally. As long as the second, non-interactive copy is set to not receive pointer events, keyboard navigation will automatically bypass it. Form and input behavior will also be handled normally by the screen reader.</p><p>The following section will go into more detail on technical implementation with React, React hooks, and native WebGL, although any frontend framework or WebGL wrapper library would work as well. Instead of a full step-by-step guide, it will focus on a few points key to this particular challenge: UI setup, handling user interactions, DOM rasterization, and working with WebGL textures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*5fSDCK4l9RAldIM-SlPAHw.gif" /><figcaption>Screen capture of the proof of concept for rasterized DOM elements with accessible navigation and screen reader behavior.<a href="https://github.com/annekagoss/accessible-webgl-demos"> https://github.com/annekagoss/accessible-webgl-demos</a></figcaption></figure><p><strong>UI Setup<br></strong>For this strategy, the foreground UI copies need to be able to communicate directly with the WebGL context to trigger and provide content for the rasterization. React Refs and Ref forwarding allows this foreground content to be kept in separate components and files from the rest of the WebGL configuration. Ref objects are also useful for storing per-frame data that will update shader uniforms, but shouldn’t trigger React renders.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OUbHZEF-x1iYPDZJvd9G8w.png" /></figure><p><strong>User Interactions<br></strong>User interactions are triggered in the interactive copy of the foreground UI, and trigger both state updates in the second copy and the texture rebinding process. While foreground state updates can be contained within the components themselves, WebGL updates should be contained in a separate hook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lSMD9rxueSBHbApxlCJLEw.png" /></figure><p>Because the first copy is intercepting user events, it needs to communicate UI changes to the copy that will be rasterized. This can be achieved with a shared state in the parent component or with React Context.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s6UFWpQeMfjVuML5MP9HOA.png" /></figure><p>For triggering updates to the WebGL context, a separate hook can manage subscriptions to provided events. In this example, an event target ref, an image source ref and a list of events to subscribe to are passed to a useRasterizeToGL hook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-7f6QdwgI9WNYyWXPqPokQ.png" /></figure><p>Throttling refreshes and limiting event subscriptions to only those passed in helps to limit costly image loads and texture reassignments. Load and resize events are the exceptions, being necessary for an accurate rasterization regardless of the source content. To update the texture, skip the texture creation step and bind the new image to the current texture and uniform location.</p><p><strong>Rasterization<br></strong>The process of rasterization itself requires several steps: serializing an HTML element, rending it within an SVG, and finally converting that SVG to a base64-encoded PNG. PNG is the preferred format for sending to fragment shaders because its built-in alpha channel automatically complies with the expected 4-component color type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d2B8MhBlgTapQLQp1WAP2Q.png" /><figcaption>The steps for rasterizing a DOM element to be rendered with a custom fragment shader.</figcaption></figure><p>Once an element is stored in a React Ref, it can be serialized with<a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLSerializer"> XMLSerializer</a>, then embedded in an SVG Data URI as a foreign object. It’s important to make sure that all CSS styles and fonts that will be applied to the element are either inline or also embedded in the SVG style tag. The width and height from the element bounding client rect will be essential later for WebGL texture creation and rendering from the sampler data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*040FVYQ4HJwe5osQQGMA3A.png" /></figure><p>In order to convert the SVG image into a PNG, it first needs to be loaded and rendered to an offscreen 2D canvas. The base64 encoded PNG can then be written to a variable with the canvas toDataURL method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CePAhv9UcxH3hgo9PAVGLA.png" /><figcaption>The PNG data is now ready to be written to a WebGL texture.</figcaption></figure><p>This process is admittedly fairly involved, however once it has been set up, foreground contents and shader effects can be swapped out with little effort. For example, the color contrast correction shader from the previous section could be easily applied to specific DOM elements. Still, this approach has enough moving parts that it should be used for projects where a significant amount of DOM rasterization is necessary. For one-off effects, pre-rendered assets would most likely be more appropriate solutions. Regardless, this case study proves that there is no excuse for foregoing accessibility in favor of programmatic graphics. There is always a solution to accessibility concerns, and they should never be given lower priority than a background effect. Conversely, commitment to maintaining an accessible web does not always mean rejecting creativity and experimentation.</p><p>The overall gaming industry is slowly learning to address the needs of accessible players.<a href="https://www.polygon.com/2013/7/2/4488030/the-controller-project-disabled-gamers-custom-hardware"> What started with custom controllers</a> had grown into a push for software based accommodations and<a href="https://www.engadget.com/facebook-oculus-quest-180053872.html"> standardized guidelines</a>. Games and VR applications are including more sophisticated visual, auditory and haptic cues to ensure that all users receive the same information. More robust customization is also becoming the norm, allowing players to remap buttons, define a dominant hand, set text display style and speed, and calibrate rendering for all types of color perception.<a href="https://dagersystem.com/accessibility-news-roundup-ps5-ux-assassins-creed-valhalla-and-fifa-21/"> Some games are even introducing audio hints so blind players can easily move through the world.</a> Finally, general awareness and advocacy for accessibility in games is gaining visibility in<a href="https://caniplaythat.com/"> game review sites</a> and<a href="https://vicaption.com/handbook/twitch-opening-opportunities-disabled-streamers"> platforms like Twitch</a>.</p><p>Web developers have a responsibility to match, if not set the standard for the game industry’s efforts for greater accessibility. Browsers support custom graphics and games, but they also provide vital daily services for billions of people. The technology that allows people to access medical records and check their bank accounts should not be falling behind the entertainment industry when it comes to providing for diverse users. So perhaps games and graphics in the browser are not a hindrance to accessibility, but an invitation to utilize solutions that are being tried in video games. It’s time to get creative and give every user consideration and respect.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43d15f9caa21" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>