google / filament

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
https://google.github.io/filament/
Apache License 2.0
17.63k stars 1.86k forks source link

LINEAR tone mapping disables sRGB encoding. #1658

Closed geroge-d closed 4 years ago

geroge-d commented 5 years ago

Hi guys I want to change the default tone_mapping algorithm,because ACES is too bright . I tried to change the function tonemap in the file filament\shaders\src\tone_mapping.fs , and rebuild matc, but it seams nothing changed. Could you please tell how to change the tone_mapping algorithm? thanks in advance

romainguy commented 5 years ago

You cannot change the tone mapping operator. If you do change the source file you need to rebuild matc and all materials. But if your problem is that things are too bright it's probably an exposure issue, not a tone mapping issue.

geroge-d commented 5 years ago

I use the code below to draw image. I create a rendertarget with RGBA16F texture as color backend . If i use View.ToneMapping.ACES , the result is brighter than original image, but if i use View.ToneMapping.LINEAR, the result is darker than original image. So I don't know how to draw image by unlit mode to render target, so that it is the same bright with the original one. Any advice is much appreciated

material { name : "Image 2dmode_normal", parameters : [ { type : sampler2d, name : texture }, { type:float, name:alpha } ], requires : [ uv0 ], blending : fade, shadingModel : unlit } void material(inout MaterialInputs material) { prepareMaterial(material); float4 texel = texture(materialParams_texture, getUV0()); float4 outputColor = float4(texel.rgb materialParams.alpha, texel.a materialParams.alpha); material.baseColor = outputColor; }

romainguy commented 5 years ago

That's because there's an issue where we don't properly apply gamma encoding when tone mapping is off. Another thing you can do is simply leave the default tone mapping on and apply the inverse tone mapping to your color (see the Materials.md.html documentation).

geroge-d commented 5 years ago

I just found a workaround Because I blit the rendertarget to different target, by using the following code. the accumulated effect causes image too brighter. So if Filament provide blit rendertarget directly to Java, maybe we don't need to do blit use the following code Blit code: material { name : blit, shadingModel : unlit,

parameters : [
    {
        type : sampler2d,
        name : color
    }
],
requires: [
    uv0
],
culling : none,
blending : fade,
flipUV : false

}

fragment {

void material(inout MaterialInputs material) {
    prepareMaterial(material);
    float4 outputColor = texture(materialParams_color, getUV0());
    material.baseColor = outputColor;
}

}

geroge-d commented 5 years ago

Now, i just close tonemaping for 2d image drawing, instead use that code for 2d image draw. it work great now

material { name : "Image 2dmode_normal", parameters : [ { type : sampler2d, name : texture }, { type:float, name:alpha } ], requires : [ uv0 ], blending : fade, shadingModel : unlit } void material(inout MaterialInputs material) { prepareMaterial(material); float4 texel = texture(materialParams_texture, getUV0()); float4 outputColor = float4(texel.rgb materialParams.alpha, texel.a materialParams.alpha); if ( outputColor.a > 0.0 ) material.baseColor = float4(Tonemap_Unreal(outputColor.rgb),outputColor.a); else{ material.baseColor = outputColor; }

}
romainguy commented 4 years ago

We are rewriting the tonemapper which will give us the flexibility you need. See: https://github.com/google/filament/pull/2561

Closing this for now since you have a workaround. In the future the new tone mapping/color grading APIs will let you choose/provide your tone mapper.