jMonkeyEngine / jMonkeyEngine/jmonkeyengine

ShaderNodes: ColorToGrey has a wrong implementation

Open
#1,284 1 comment 0 reactions 0 assignees View on GitHub

@Mezage is already working on this.

Since Jun 10, 2021.

  • #1572 by @Mezage — open
bug
Dominant language
Java
Stars
4.3k
Forks
1.2k
Avg merge
4d 7h
Merged PRs (30d)
14

Description

So we are talking about this:
https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-core/src/main/resources/Common/MatDefs/ShaderNodes/Basic/colorToGrey.frag

It should extract the luminance of a color (or in other words: convert RGB to Greyscale).

I think the way it has been done only works when r == g == b and then dividing by 3 again (because currently grey can be everything between 0 and 3. So it would only work when only one channel is used).

Also, when r == g == b and we'd do (r + g+ b) / 3, we could also take r, as simple as that.

So: For images already being Greyscale in RGB, we can just take one component.
For Images not being Greyscale, we need a more complicated code like https://github.com/flixel-gdx/flixel-gdx/blob/master/flixel-core/src/org/flixel/data/shaders/blend/luminosity.glsl

Luminance is only Lines 15-21 and we can add a proper RGB->HSL conversion as well.
The license is BSD.

Tagging @neph1 as he contributed the initial ColorToGrey implementation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with jme3-core/src/main/resources/Common/MatDefs/ShaderNodes/Basic/colorToGrey.frag, especially lines 15-21, and review linked pull request #1572 before making changes. Compare the current conversion with the referenced luminosity shader; done means ColorToGrey produces correct luminance for both grayscale and non-grayscale RGB inputs.

Written by the indexing model from the issue text.

Assessment

Domain
computer-graphics
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.