GammaCorrectionFilter

So it’s expecting JME to already be in gamma mode or the application to have converted all of the srgb textures to linear or?

I admit that I may not be following along properly at this point.

3 Likes

The title of this topic is “GammaCorrectionFilter”.
The name of filter that Pavl_G is developing is “ContrastAdjustment”.

2 Likes

Yes, but in order for the buffer that the filter uses to have linear space color for input to the not-gamma-correction filter it should have JME in gamma mode (so that it will load srgb textures into linear space) or the user should be expected to do same.

When JME is not in gamma mode, what goes in the post-proc buffer is only “kind of linear”. It’s really some hybrid srgb+linear space color.

Maybe that’s ok for this filter.

2 Likes

Alright, i have made the filter, but when i run the test, it went into a black screen :

When i removed the filter i can see the scene :

Conclusion : something goes wrong with the final pass glFragColor so the objects are rendered but not drawn.

the code :

the test :

Any ideas ?

2 Likes

Maybe that’s ok for this filter.

It’s okay for this filter.

Not sure what’s causing the black screen, but I did spot a couple bugs in the fragment shader:

    color.g = (color.r - minBrightness) / (maxBrightness - minBrightness);
    color.b = (color.r - minBrightness) / (maxBrightness - minBrightness); 

The green and blue channels shouldn’t depend on color.r.

1 Like

Yeah I have spotted that too, and fixed the code on another commit, but stills not seeing anything.

1 Like

I don’t know of any debugger for GLSL. If I were debugging this, I would roll back to some known-good version and then test each change, one at a time.

1 Like

I have tested unifying the effect on all channels as the Heart does, but stills nothing, are you sure the filter was working fine on Heart with jme3.4.0 ?

My laptop uses GLSL130 so I use the glsl100 shader files version.

Yes, I just tested it using “TestContrast.java”.

1 Like

I will have to test on android or windows then.

In the ContrastAdjustmentFilter class you have:

material.setFloat("exp_r", exp_r);
material.setFloat("exp_g", exp_g);
material.setFloat("exp_b", exp_b);

But in the .frag file you have:

uniform float exp_r;
uniform float exp_g;
uniform float exp_b;

Shouldn’t those uniform float variables be preceded by an “m_” (thus m_exp_r and so on) in the fragment file as shown in the wiki?

To use this uniform in the shader, you need to declare it in the .frag or .vert files (depending on where you need it). You can make use of the defines here and later in the code: Note that the “m_” prefix specifies that the uniform is a material parameter.

3 Likes

When I searched the web for black screens due to shaders, one of the things that catches my eyes was the misnaming between the frag and vert files, but now I somehow sure of that was the problem.

Thanks @fba I will test that and report.

1 Like

Fantastic, now it works fine :slight_smile: :

blue exp = 1/2.2f, red = green = 3f

The same with low brightness (0.2 → 0.4)

exp = 3 equally in all channels

r = 1.8, g = 1.8, b = 2.1 and brightness at max :

same image with low brightness (0.1 → 0.9) :

brightness above 1 :

Again, thanks @fba , i think unless your comment, i would have been spinning around myself now :sweat_smile:

NB : the brightness min and max values must lie between 0 and 1, because color.rgb is a normalized value.

5 Likes

Good to know it works now. I’m glad I could help.

4 Likes

Runtime testing on desktop :

On Android :



PR :

4 Likes

Hello there,

In order for me to change Vector3f to ColorRGBA, I will have to apply the power law on the alpha channel too.

I am doubtful it would be unappropriate to apply the power law on the alpha channel since the book I used didn’t mention the alpha channel when applying the tone map operator function after color reproduction, so from my understanding that the alpha channel may be just scaling the other colors !?

Are there any issues from applying the power law on the alpha channel ?

1 Like

I can’t think of a use for power-law on the alpha channel. Another reason to make the default exponent=0. Or you could just ignore the alpha component of the exponent.

1 Like

Ignoring a value seems not to be a clean code, developers would almost think that there is something wrong, and issues would start to arise.

I think we could make the alpha channel value as just a pre-scale value from 0 to 1 so on the constructor :

this.redChannel = redChannel * (alphaChannel % 1.1f);
....

And alpha default is 1.
What do you think ?

Oops! I should have said default exponent=1, not 0.

If the alpha exponent is ignored, that must be documented.

I don’t want the alpha channel to affect the other channels. That would be confusing.

2 Likes