Fix voxel nodes

This commit is contained in:
Lubos Lenco 2017-03-29 14:32:44 +02:00
parent 44f257f6ba
commit b626197f78
5 changed files with 24 additions and 9 deletions

View file

@ -78,13 +78,13 @@ void main() {
vec3 indirectSpecular = traceSpecularVoxelCone(p / voxelgiDimensions.x, reflectWorld, n, metrough.y * 10.0);
indirectSpecular *= f0 * envBRDF.x + envBRDF.y;
// fragColor.rgb = indirectDiffuse.rgb * 60.0 * albedo + indirectSpecular;
fragColor.rgb = max(vec3(1.0 - (indirectDiffuse.a / 2.0)), 0.05) * albedo;
// fragColor.rgb *= 1.0 - (indirectDiffuse.a / 2.0); // Occ
fragColor.rgb = indirectDiffuse.rgb * 1.3 * albedo + indirectSpecular;
// fragColor.rgb = max(vec3(1.0 - (indirectDiffuse.a / 2.0)), 0.05) * albedo;
fragColor.rgb *= 1.0 - (indirectDiffuse.a / 2.2); // Occ
fragColor.rgb *= texture(ssaotex, texCoord).r * 0.5 + 0.5;
// if (opacity < 1.0) fragColor.rgb = mix(indirectRefractiveLight(-v), fragColor.rgb); // Transparency
return;
// return;
#endif
// Envmap
@ -121,7 +121,7 @@ void main() {
#ifdef _VoxelGI
float m = (fragColor.r + fragColor.g + fragColor.b) / 3.0;
fragColor.rgb += (envl / 5.0) * m;
fragColor.rgb += (envl / 2.0) * m;
#else
fragColor.rgb = envl;
#endif

View file

@ -21,8 +21,8 @@ vec4 traceDiffuseVoxelCone(const vec3 from, vec3 direction) {
vec4 acc = vec4(0.0);
// Controls bleeding from close surfaces
// Low values look rather bad if using shadow cone tracing
float dist = 0.1953125 / 9.0;
const float SQRT2 = 1.414213 / 9.0;
float dist = 0.1953125;
const float SQRT2 = 1.414213;
while (dist < SQRT2 && acc.a < 1.0) {
vec3 c = vec3(from + dist * direction) * 0.5 + vec3(0.5);
float l = (1.0 + CONE_SPREAD * dist / VOXEL_SIZE);
@ -32,7 +32,22 @@ vec4 traceDiffuseVoxelCone(const vec3 from, vec3 direction) {
acc += 0.075 * ll * voxel * pow(1.0 - voxel.a, 2.0);
dist += ll * VOXEL_SIZE * 2.0;
}
vec4 occ = vec4(0.0);
dist = 0.1953125 / 9.0;
const float SQRT2a = 1.414213 / 9.0;
while (dist < SQRT2a && acc.a < 1.0) {
vec3 c = vec3(from + dist * direction) * 0.5 + vec3(0.5);
float l = (1.0 + CONE_SPREAD * dist / VOXEL_SIZE);
float level = log2(l);
float ll = (level + 1.0) * (level + 1.0);
vec4 voxel = textureLod(voxels, c, min(MAX_MIPMAP, level));
occ += 0.075 * ll * voxel * pow(1.0 - voxel.a, 2.0);
dist += ll * VOXEL_SIZE * 2.0;
}
acc.rgb = pow(acc.rgb * 2.0, vec3(1.5));
acc.a = occ.a;
return acc;
}

View file

@ -87,8 +87,8 @@ def make_deferred(cam):
nodes['Screen'].inputs[0].default_value = int(cam.rp_supersampling)
if cam.rp_voxelgi:
links.new(nodes['Begin'].outputs[0], nodes['Clear Image Voxels'].inputs[0])
links.new(nodes['Generate Mipmaps Voxels'].outputs[0], nodes['Set Target Mesh'].inputs[0])
links.new(nodes['Begin'].outputs[0], nodes['Branch Function Voxelize'].inputs[0])
links.new(nodes['Merge Stages Voxelize'].outputs[0], nodes['Set Target Mesh'].inputs[0])
n = nodes['Image 3D Voxels']
n.inputs[1].default_value = cam.rp_voxelgi_resolution[0]
n.inputs[2].default_value = cam.rp_voxelgi_resolution[1]

Binary file not shown.

Binary file not shown.