Skip to content

Blend modes are not set on WebGL Graphics primitives drawn to a RenderTexture #5565

@danarcher

Description

@danarcher

Version

  • Phaser Version: v3.52.0
  • Operating system: Windows 10 Version 1909 (OS Build 18363.1379)
  • Browser: Firefox 85.0.2 (64-bit)

Description

Under WebGL, calling setBlendMode() on a Graphics object has no effect when drawing that Graphics object to a RenderTexture.

The workaround is to add the Graphics object to a Container, and draw that Container to the RenderTexture.

This came up whilst drawing primitives to a Graphics object using additive blending, then drawing that RenderTexture to the scene using multiplicative blending, in order to implement a light/shadow effect.

Example Test Code

See https://codepen.io/danarcher/pen/OJbWYeW. The code is drawing concentric circles using additive blending.

Set workaround to true to see the workaround in effect, whereby concentric circles of increasing (additive) brightness are visible.

The workaround isn't necessary when using the canvas rather than WebGL renderer (change Phaser.WEBGL to Phaser.CANVAS in the example to demonstrate).

Additional Information

There is no call to the renderer to set the blend mode from GraphicsWebGLRenderer or RenderTextureWebGLRenderer.

There is a call to the renderer to set the blend mode from ContainerWebGLRenderer.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions