Fixing translucency
This commit is contained in:
parent
310cf140b8
commit
c7a548bb5e
|
@ -1,28 +1,35 @@
|
|||
// Weighted blended OIT by McGuire and Bavoil
|
||||
#version 450
|
||||
|
||||
uniform sampler2D gbufferD;
|
||||
// uniform sampler2D gbufferD;
|
||||
uniform sampler2D gbuffer0; // saccum
|
||||
uniform sampler2D gbuffer1; // srevealage
|
||||
|
||||
uniform vec2 texSize;
|
||||
|
||||
in vec2 texCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
vec4 accum = texture(gbuffer0, texCoord);
|
||||
float revealage = accum.a;
|
||||
|
||||
if (revealage == 1.0) {
|
||||
// Save the blending and color texture fetch cost
|
||||
discard;
|
||||
}
|
||||
|
||||
accum.a = texture(gbuffer1, texCoord).r;
|
||||
|
||||
// fragColor = vec4(accum.rgb / clamp(accum.a, 1e-4, 5e4), revealage);
|
||||
|
||||
// const float epsilon = 0.00001;
|
||||
// fragColor = vec4(accum.rgb / max(accum.a, epsilon), 1.0 - revealage);
|
||||
|
||||
fragColor = vec4(accum.rgb / clamp(accum.a, 1e-4, 5e4), 1.0 - revealage);
|
||||
float maxComponent(vec4 v) {
|
||||
return max(max(max(v.x, v.y), v.z), v.w);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 accum = texelFetch(gbuffer0, ivec2(texCoord * texSize), 0);
|
||||
float revealage = 1.0 - accum.a;
|
||||
|
||||
// Save the blending and color texture fetch cost
|
||||
if (revealage >= 1.0) {
|
||||
// discard;
|
||||
fragColor = vec4(accum.rgb, 1.0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isinf(maxComponent(abs(accum)))) {
|
||||
accum.rgb = vec3(revealage);
|
||||
}
|
||||
|
||||
float f = texelFetch(gbuffer1, ivec2(texCoord * texSize), 0).r;
|
||||
|
||||
fragColor = vec4(accum.rgb / clamp(f, 1e-4, 5e4), revealage);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,12 @@
|
|||
"alpha_blend_source": "source_alpha",
|
||||
"alpha_blend_destination": "inverse_source_alpha",
|
||||
"alpha_blend_operation": "add",
|
||||
"links": [],
|
||||
"links": [
|
||||
{
|
||||
"name": "texSize",
|
||||
"link": "_screenSize"
|
||||
}
|
||||
],
|
||||
"vertex_shader": "../include/pass.vert.glsl",
|
||||
"fragment_shader": "translucent_resolve.frag.glsl"
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ class Inc {
|
|||
t.width = 0;
|
||||
t.height = 0;
|
||||
t.displayp = getDisplayp();
|
||||
t.format = "RGBA64";
|
||||
t.format = "R16";
|
||||
var ss = getSuperSampling();
|
||||
if (ss != 1) t.scale = ss;
|
||||
t.depth_buffer = "main";
|
||||
|
|
|
@ -2113,7 +2113,7 @@ class ArmoryExporter:
|
|||
if nmat == None:
|
||||
continue
|
||||
if vs != nmat.vertex_structure:
|
||||
log.warn('Object ' + bobject.name + ' - unable to bind materials to vertex data, please separate object by material (select object - edit mode - P - By Material) or enable Deinterleaved Buffers in Armory Player')
|
||||
log.warn('Object ' + bobject.name + ' - unable to bind materials to vertex data, please separate object by material (select object - edit mode - P - By Material) or enable Deinterleaved Buffers in Armory Project - Flags')
|
||||
break
|
||||
|
||||
self.export_particle_systems()
|
||||
|
|
|
@ -15,23 +15,18 @@ def make(context_id):
|
|||
|
||||
frag.add_out('vec4[2] fragColor')
|
||||
|
||||
if tese != None:
|
||||
tese.add_out('vec4 wvpposition')
|
||||
tese.write('wvpposition = gl_Position;')
|
||||
else:
|
||||
vert.add_out('vec4 wvpposition')
|
||||
vert.write('wvpposition = gl_Position;')
|
||||
sh = tese if tese != None else vert
|
||||
sh.add_out('vec4 wvpposition')
|
||||
sh.write('wvpposition = gl_Position;')
|
||||
|
||||
# Remove fragColor = ...;
|
||||
frag.main = frag.main[:frag.main.rfind('fragColor')]
|
||||
|
||||
frag.write('\n')
|
||||
frag.write('vec4 premultipliedReflect = vec4(vec3(direct * visibility + indirect * occlusion), opacity);')
|
||||
frag.write('vec4 premultipliedReflect = vec4(vec3(direct * lightColor * visibility + indirect * occlusion) * opacity, opacity);')
|
||||
|
||||
frag.write('float fragZ = wvpposition.z / wvpposition.w;')
|
||||
frag.write('float a = min(1.0, premultipliedReflect.a) * 8.0 + 0.01;')
|
||||
frag.write('float b = -fragZ * 0.95 + 1.0;')
|
||||
frag.write('float w = clamp(a * a * a * 1e8 * b * b * b, 1e-2, 3e2);')
|
||||
frag.write('float w = clamp(pow(min(1.0, premultipliedReflect.a * 10.0) + 0.01, 3.0) * 1e8 * pow(1.0 - fragZ * 0.9, 3.0), 1e-2, 3e3);')
|
||||
frag.write('fragColor[0] = vec4(premultipliedReflect.rgb * w, premultipliedReflect.a);')
|
||||
frag.write('fragColor[1] = vec4(premultipliedReflect.a * w, 0.0, 0.0, 1.0);')
|
||||
|
||||
|
|
Loading…
Reference in a new issue