Improve float pack

This commit is contained in:
luboslenco 2018-05-26 16:39:10 +02:00
parent 9aa2610c13
commit 0da20589c6
6 changed files with 20 additions and 13 deletions

View file

@ -80,7 +80,7 @@ void main() {
vec2 metrough = unpackFloat(g0.b);
vec4 g1 = texture(gbuffer1, texCoord); // Basecolor.rgb, spec/occ
float spec = floor(g1.a) / 100.0;
vec2 occspec = unpackFloat2(g1.a);
vec3 albedo = surfaceAlbedo(g1.rgb, metrough.x); // g1.rgb - basecolor
#ifdef _IndPos
@ -113,10 +113,10 @@ void main() {
fragColor.rgb = indirectDiffuse.rgb * voxelgiDiff * g1.rgb;
if (spec > 0.0) {
if (occspec.y > 0.0) {
vec3 indirectSpecular = traceSpecular(voxels, voxpos, n, v, metrough.y);
indirectSpecular *= f0 * envBRDF.x + envBRDF.y;
fragColor.rgb += indirectSpecular * voxelgiSpec * spec;
fragColor.rgb += indirectSpecular * voxelgiSpec * occspec.y;
}
// if (!isInsideCube(voxpos)) fragColor = vec4(1.0); // Show bounds
@ -151,7 +151,7 @@ void main() {
envl.rgb *= albedo;
#ifdef _Rad // Indirect specular
envl.rgb += prefilteredColor * (f0 * envBRDF.x + envBRDF.y) * 1.5 * spec;
envl.rgb += prefilteredColor * (f0 * envBRDF.x + envBRDF.y) * 1.5 * occspec.y;
#else
#ifdef _EnvCol
envl.rgb += backgroundCol * surfaceF0(g1.rgb, metrough.x); // f0
@ -159,10 +159,10 @@ void main() {
#endif
#ifdef _SSS
envl.rgb *= envmapStrength * fract(g1.a);
envl.rgb *= envmapStrength * occspec.x;
#else
#ifndef _VoxelGIRefract
envl.rgb *= envmapStrength * fract(g1.a); // Occlusion
envl.rgb *= envmapStrength * occspec.x; // Occlusion
#endif
#endif

View file

@ -99,7 +99,7 @@ void main() {
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, metallic/roughness, depth
vec4 g1 = texture(gbuffer1, texCoord); // Basecolor.rgb, spec/occ
float spec = floor(g1.a) / 100.0;
float spec = unpackFloat2(g1.a).g;
// #ifdef _InvY // D3D
// float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0; // 0 - 1 => -1 - 1
// #else

View file

@ -75,7 +75,7 @@ out vec4 fragColor;
void main() {
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, metallic/roughness, depth
vec4 g1 = texture(gbuffer1, texCoord); // Basecolor.rgb, spec/occ
float spec = floor(g1.a) / 100.0;
float spec = unpackFloat2(g1.a).g;
// float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0; // 0 - 1 => -1 - 1
// TODO: store_depth
// TODO: Firefox throws feedback loop detected error, read depth from gbuffer0

View file

@ -131,7 +131,7 @@ void main() {
return;
}
float spec = floor(texture(gbuffer1, texCoord).a) / 100.0;
float spec = fract(texture(gbuffer1, texCoord).a);
if (spec == 0.0) {
fragColor.rgb = vec3(0.0);
return;

View file

@ -71,15 +71,22 @@ vec3 getPos2NoEye(const vec3 eye, const mat4 invVP, const float depth, const vec
}
float packFloat(const float f1, const float f2) {
float index = floor(f1 * 100.0); // Temporary
float alpha = clamp(f2, 0.0, 1.0 - 0.001);
return index + alpha;
return floor(f1 * 100.0) + min(f2, 1.0 - 1.0 / 100.0);
}
vec2 unpackFloat(const float f) {
return vec2(floor(f) / 100.0, fract(f));
}
float packFloat2(const float f1, const float f2) {
// Higher f1 = less precise f2
return floor(f1 * 255.0) + min(f2, 1.0 - 1.0 / 100.0);
}
vec2 unpackFloat2(const float f) {
return vec2(floor(f) / 255.0, fract(f));
}
vec4 encodeRGBM(const vec3 rgb) {
const float maxRange = 6.0;
float maxRGB = max(rgb.x, max(rgb.g, rgb.b));

View file

@ -354,7 +354,7 @@ def make_deferred(con_mesh):
frag.write('fragColor[0] = vec4(n.xy, packFloat(metallic, roughness), 1.0 - ((wvpposition.z / wvpposition.w) * 0.5 + 0.5));')
else:
frag.write('fragColor[0] = vec4(n.xy, packFloat(metallic, roughness), 1.0 - gl_FragCoord.z);')
frag.write('fragColor[1] = vec4(basecol.rgb, packFloat(specular, occlusion));')
frag.write('fragColor[1] = vec4(basecol.rgb, packFloat2(occlusion, specular));')
if '_gbuffer2' in wrd.world_defs:
if '_Veloc' in wrd.world_defs: