diff --git a/leenkx/blender/lnx/material/make_mesh.py b/leenkx/blender/lnx/material/make_mesh.py index 08a933f..dc92084 100644 --- a/leenkx/blender/lnx/material/make_mesh.py +++ b/leenkx/blender/lnx/material/make_mesh.py @@ -611,7 +611,7 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False): sh = tese if tese is not None else vert sh.add_out('vec3 eyeDir') sh.add_uniform('vec3 eye', '_cameraPosition') - sh.write('eyeDir = eye - wposition;') + sh.write('eyeDir = eye - spos.xyz;') frag.add_include('std/light.glsl') is_shadows = '_ShadowMap' in wrd.world_defs @@ -680,15 +680,19 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False): frag.add_uniform("sampler2D voxels_ao"); frag.write('envl *= textureLod(voxels_ao, texCoord, 0.0).rrr;') - frag.write('vec3 indirect = envl;') - + if '_VoxelGI' in wrd.world_defs: + frag.write('vec3 indirect = vec3(0.0);') + else: + frag.write('vec3 indirect = envl;') + if '_VoxelGI' in wrd.world_defs: if parse_opacity: - frag.write('indirect = traceDiffuse(wposition, n, voxels, clipmaps).rgb * albedo * voxelgiDiff;') + frag.write('vec4 trace = traceDiffuse(wposition, wnormal, voxels, clipmaps);') + frag.write('indirect = ((trace.rgb * albedo + envl * (1.0 - trace.a)) * voxelgiDiff);') frag.write('if (roughness < 1.0 && specular > 0.0){') frag.add_uniform('sampler2D sveloc') frag.write(' vec2 velocity = -textureLod(sveloc, gl_FragCoord.xy, 0.0).rg;') - frag.write(' indirect += traceSpecular(wposition, n, voxels, voxelsSDF, normalize(eye - wposition), roughness, clipmaps, gl_FragCoord.xy, velocity).rgb * specular * voxelgiRefl;}') + frag.write(' indirect += traceSpecular(wposition, n, voxels, voxelsSDF, vVec, roughness, clipmaps, gl_FragCoord.xy, velocity).rgb * specular * voxelgiRefl;}') else: frag.add_uniform("sampler2D voxels_diffuse") frag.add_uniform("sampler2D voxels_specular") @@ -732,8 +736,9 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False): vert.add_uniform('mat4 LVP', '_biasLightViewProjectionMatrix') vert.write('lightPosition = LVP * vec4(wposition, 1.0);') else: - frag.add_uniform('mat4 LWVP', '_biasLightWorldViewProjectionMatrixSun') - frag.write('vec4 lightPosition = LWVP * vec4(wposition + n * shadowsBias * 100, 1.0);') + vert.add_out('vec4 lightPosition') + vert.add_uniform('mat4 LWVP', '_biasLightWorldViewProjectionMatrixSun') + vert.write('lightPosition = LWVP * lightPosition;') frag.write('vec3 lPos = lightPosition.xyz / lightPosition.w;') frag.write('const vec2 smSize = shadowmapSize;') if parse_opacity: @@ -796,7 +801,7 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False): if '_VoxelRefract' in wrd.world_defs and parse_opacity: frag.write('if (opacity < 1.0) {') frag.write(' vec2 velocity = -textureLod(sveloc, gl_FragCoord.xy, 0.0).rg;') - frag.write(' vec3 refraction = traceRefraction(wposition, n, voxels, voxelsSDF, normalize(eye - wposition), ior, roughness, clipmaps, gl_FragCoord.xy,velocity).rgb;') + frag.write(' vec3 refraction = traceRefraction(wposition, n, voxels, voxelsSDF, vVec, ior, roughness, clipmaps, gl_FragCoord.xy,velocity).rgb;') frag.write(' indirect = mix(refraction, indirect, opacity) * voxelgiRefr;') frag.write(' direct = mix(refraction, direct, opacity) * voxelgiRefr;') frag.write('}')