bkaradzic / bgfx

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
https://bkaradzic.github.io/bgfx/overview.html
BSD 2-Clause "Simplified" License
15.14k stars 1.95k forks source link

shaderc and bgfx results different for shader 1.2 and 1.3 and above #734

Open ahmedwf opened 8 years ago

ahmedwf commented 8 years ago

This plagued me for quite some time. I found two issues:

  1. in developing a more complete deferred shading implementation with HDR, For some reason when using multiple texture samplers, sometimes BGFX does not bind the correct texture. to solve, from time to time I have to change the binding stage index to get the proper texture mapping to the shader sampler.
  2. sampling my lum texture in the tone mapping shader/pass results in very wrong results during tonemapping, simply changing the shader model to 1.2 gives correct results. with 1.3 and above. I have tried with BGRA8 and f32/f16 lum textures. also sampling lum with .5, .5 delivers unreliable results vs using v_texcoord0 (lum texture is 1x1 pixels)

$input v_texcoord0, v_texcoord1, v_texcoord2, v_texcoord3, v_texcoord4

/*

SAMPLER2D(s_texColor, 0); SAMPLER2D(s_texLum, 1); SAMPLER2D(s_texBlur, 2);

void main() { vec3 rgb = decodeRGBE8(texture2D(s_texColor, v_texcoord0) ); //float lum = clamp(decodeRE8(texelFetch(s_texLum, ivec2(gl_FragCoord.xy), 0) ), 0.1, 0.7); float lum = clamp(decodeRE8(texture2D(s_texLum, v_texcoord0)), 0.1, 0.7);

vec3 Yxy = convertRGB2Yxy(rgb);

float middleGray = g_ToneMapScalars.x;
float whiteSqr   = g_ToneMapScalars.y;
float treshold   = g_ToneMapScalars.z;
float offset     = g_ToneMapScalars.w;

float lp = Yxy.x * middleGray / (lum + 0.0001);
Yxy.x = reinhard2(lp, whiteSqr);

rgb = convertYxy2RGB(Yxy);

vec4 blur = blur9(s_texBlur
                , v_texcoord0
                , v_texcoord1
                , v_texcoord2
                , v_texcoord3
                , v_texcoord4
                );

rgb += 0.6 * blur.xyz;
gl_FragColor = toGamma(vec4(rgb, 1.0) );

}

bkaradzic commented 8 years ago

Can you modify existing sample with minimal number of changes that reproduces the error?