diff --git a/Shaders/deferred_light/deferred_light.frag.glsl b/Shaders/deferred_light/deferred_light.frag.glsl index 4b4b76e49..50bb0d089 100644 --- a/Shaders/deferred_light/deferred_light.frag.glsl +++ b/Shaders/deferred_light/deferred_light.frag.glsl @@ -286,7 +286,7 @@ void main() { #ifdef _VoxelGI fragColor.rgb = textureLod(voxels_diffuse, texCoord, 0.0).rgb * albedo * voxelgiDiff; if(roughness < 1.0 && occspec.y > 0.0) - fragColor.rgb += textureLod(voxels_specular, texCoord, 0.0).rgb * voxelgiRefl * occspec.y; + fragColor.rgb += textureLod(voxels_specular, texCoord, 0.0).rgb * occspec.y * voxelgiRefl; #endif #ifdef _VoxelAOvar diff --git a/Shaders/ssrefr_pass/ssrefr_pass.frag.glsl b/Shaders/ssrefr_pass/ssrefr_pass.frag.glsl index 363115b76..31933e4ea 100644 --- a/Shaders/ssrefr_pass/ssrefr_pass.frag.glsl +++ b/Shaders/ssrefr_pass/ssrefr_pass.frag.glsl @@ -14,9 +14,6 @@ uniform sampler2D gbuffer0; uniform sampler2D gbufferD1; uniform sampler2D gbuffer_refraction; // ior\opacity uniform sampler2D voxels_refraction; -uniform sampler2D voxels_specular; -uniform sampler2D voxels_diffuse; -uniform sampler2D voxels_shadows; uniform mat4 P; uniform mat3 V3; uniform vec2 cameraProj; @@ -114,14 +111,9 @@ void main() { refractionCol = clamp(refractionCol, 0.0, 1.0); refractionCol *= intensity; vec3 color = textureLod(tex, texCoord.xy, 0.0).rgb; - #ifdef _VoxelGI - vec3 diffuse = textureLod(voxels_diffuse, texCoord, 0.0).rgb; - vec3 specular = textureLod(voxels_specular, texCoord, 0.0).rgb; - color = (color + diffuse + specular) * textureLod(voxels_shadows, texCoord, 0.0).r; #ifdef _VoxelRefract - vec3 voxelsRefr = textureLod(voxels_refraction, texCoord, 0.0).rgb; + vec3 voxelsRefr = textureLod(voxels_refraction, texCoord, 0.0).rgb * voxelgiRefr; refractionCol = (refractionCol + voxelsRefr) / 2; #endif - #endif fragColor.rgb = mix(refractionCol, color, opac); } diff --git a/Shaders/std/conetrace.glsl b/Shaders/std/conetrace.glsl index ea93159d7..bd553500e 100644 --- a/Shaders/std/conetrace.glsl +++ b/Shaders/std/conetrace.glsl @@ -169,7 +169,7 @@ vec4 traceDiffuse(const vec3 origin, const vec3 normal, const sampler3D voxels, } vec4 traceSpecular(const vec3 origin, const vec3 normal, const sampler3D voxels, const sampler3D voxelsSDF, const vec3 viewDir, const float roughness, const float clipmaps[voxelgiClipmapCount * 10], const vec2 pixel) { - vec3 specularDir = normalize(reflect(-viewDir, normal)); + vec3 specularDir = reflect(-viewDir, normal); vec3 P = origin + specularDir * (BayerMatrix8[int(pixel.x) % 8][int(pixel.y) % 8] - 0.5) * voxelgiStep; vec4 amount = traceCone(voxels, voxelsSDF, P, normal, specularDir, 0, true, roughness, voxelgiStep, clipmaps); diff --git a/Sources/armory/renderpath/Inc.hx b/Sources/armory/renderpath/Inc.hx index c7c1a765d..99fe0ded4 100644 --- a/Sources/armory/renderpath/Inc.hx +++ b/Sources/armory/renderpath/Inc.hx @@ -537,6 +537,18 @@ class Inc { } #end + #if (rp_voxels != "Off") + #if (rp_voxels == "Voxel AO") + path.bindTarget("voxels_ao", "voxels_ao"); + #else + path.bindTarget("voxels_diffuse", "voxels_diffuse"); + path.bindTarget("voxels_specular", "voxels_specular"); + #end + #end + #if arm_voxelgi_shadows + path.bindTarget("voxels_shadows", "voxels_shadows"); + #end + path.drawMeshes("translucent"); #if rp_render_to_texture @@ -1295,9 +1307,9 @@ class Inc { kha.compute.Compute.setSampledTexture(voxel_ta6, rts.get("voxelsOut").image); kha.compute.Compute.setSampledTexture(voxel_tb6, rts.get("half").image); #if arm_deferred - kha.compute.Compute.setSampledTexture(voxel_tc6, rts.get("gbuffer0_refr").image); + kha.compute.Compute.setSampledTexture(voxel_tc6, rts.get("gbuffer0").image); #else - kha.compute.Compute.setSampledTexture(voxel_tc6, rts.get("lbuffer1_refr").image); + kha.compute.Compute.setSampledTexture(voxel_tc6, rts.get("lbuffer1").image); #end kha.compute.Compute.setSampledTexture(voxel_td6, rts.get("voxelsSDF").image); kha.compute.Compute.setTexture(voxel_te6, rts.get("voxels_refraction").image, kha.compute.Access.Write); diff --git a/Sources/armory/renderpath/RenderPathDeferred.hx b/Sources/armory/renderpath/RenderPathDeferred.hx index 6be210f16..271ee8ff6 100644 --- a/Sources/armory/renderpath/RenderPathDeferred.hx +++ b/Sources/armory/renderpath/RenderPathDeferred.hx @@ -88,9 +88,6 @@ class RenderPathDeferred { #end path.createDepthBuffer("main", "DEPTH24"); - #if (arm_voxelgi_refract || rp_ssrefr) - path.createDepthBuffer("refraction", "DEPTH24"); - #end var t = new RenderTargetRaw(); t.name = "gbuffer0"; @@ -375,28 +372,7 @@ class RenderPathDeferred { t.width = 0; t.height = 0; t.displayp = Inc.getDisplayp(); - t.format = "RGBA64"; - t.scale = Inc.getSuperSampling(); - path.createRenderTarget(t); - - // holds colors before refractive meshes are drawn - var t = new RenderTargetRaw(); - t.name = "gbuffer1_refr"; - t.width = 0; - t.height = 0; - t.displayp = Inc.getDisplayp(); - t.format = "RGBA64"; - t.depth_buffer = "main"; - t.scale = Inc.getSuperSampling(); - path.createRenderTarget(t); - - // holds colors before refractive meshes are drawn - var t = new RenderTargetRaw(); - t.name = "gbuffer0_refr"; - t.width = 0; - t.height = 0; - t.displayp = Inc.getDisplayp(); - t.format = "RGBA64"; + t.format = Inc.getHdrFormat(); t.scale = Inc.getSuperSampling(); path.createRenderTarget(t); @@ -869,7 +845,19 @@ class RenderPathDeferred { path.bindTarget("tex", "tex"); path.drawShader("shader_datas/copy_pass/copy_pass"); - path.setTarget("gbuffer1_refr", ["gbuffer0_refr", "gbuffer_refraction"]); + path.setTarget("tex", ["gbuffer0", "gbuffer_refraction"]); + #if (rp_voxels != "Off") + #if (rp_voxels == "Voxel AO") + path.bindTarget("voxels_ao", "voxels_ao"); + #else + path.bindTarget("voxels_diffuse", "voxels_diffuse"); + path.bindTarget("voxels_specular", "voxels_specular"); + #end + #end + #if arm_voxelgi_shadows + path.bindTarget("voxels_shadows", "voxels_shadows"); + #end + path.drawMeshes("refraction"); #if arm_voxelgi_refract @@ -878,25 +866,16 @@ class RenderPathDeferred { path.drawShader("shader_datas/downsample_depth/downsample_depth"); Inc.resolveRefraction(); #end - path.setTarget("tex"); - #if (rp_voxels == "Voxel AO") - path.bindTarget("voxels_ao", "voxels_ao"); - #else - path.bindTarget("voxels_diffuse", "voxels_diffuse"); - path.bindTarget("voxels_specular", "voxels_specular"); + path.setTarget("tex"); #if arm_voxelgi_refract path.bindTarget("voxels_refraction", "voxels_refraction"); #end - #end - #if arm_voxelgi_shadows - path.bindTarget("voxels_shadows", "voxels_shadows"); - #end path.bindTarget("refr", "tex1"); - path.bindTarget("gbuffer1_refr", "tex"); + path.bindTarget("tex", "tex"); path.bindTarget("_main", "gbufferD"); path.bindTarget("gbufferD1", "gbufferD1"); - path.bindTarget("gbuffer0_refr", "gbuffer0"); + path.bindTarget("gbuffer0", "gbuffer0"); path.bindTarget("gbuffer_refraction", "gbuffer_refraction"); path.drawShader("shader_datas/ssrefr_pass/ssrefr_pass"); diff --git a/Sources/armory/renderpath/RenderPathForward.hx b/Sources/armory/renderpath/RenderPathForward.hx index d2fab034d..8010a76fc 100644 --- a/Sources/armory/renderpath/RenderPathForward.hx +++ b/Sources/armory/renderpath/RenderPathForward.hx @@ -95,10 +95,6 @@ class RenderPathForward { { path.createDepthBuffer("main", "DEPTH24"); - #if (rp_ssrefr || arm_voxelgi_refract) - path.createDepthBuffer("refraction", "DEPTH24"); - #end - var t = new RenderTargetRaw(); t.name = "lbuffer0"; t.width = 0; @@ -132,7 +128,7 @@ class RenderPathForward { t.displayp = Inc.getDisplayp(); t.format = "RGBA64"; t.scale = Inc.getSuperSampling(); - t.depth_buffer = "refraction"; + t.depth_buffer = "main"; path.createRenderTarget(t); } #end @@ -158,25 +154,6 @@ class RenderPathForward { t.format = "R32"; t.scale = Inc.getSuperSampling(); path.createRenderTarget(t); - - var t = new RenderTargetRaw(); - t.name = "lbuffer0_refr"; - t.width = 0; - t.height = 0; - t.format = Inc.getHdrFormat(); - t.displayp = Inc.getDisplayp(); - t.scale = Inc.getSuperSampling(); - t.depth_buffer = "main"; - path.createRenderTarget(t); - - var t = new RenderTargetRaw(); - t.name = "lbuffer1_refr"; - t.width = 0; - t.height = 0; - t.format = Inc.getHdrFormat(); - t.displayp = Inc.getDisplayp(); - t.scale = Inc.getSuperSampling(); - path.createRenderTarget(t); } #end @@ -507,10 +484,6 @@ class RenderPathForward { Inc.resolveSpecular(); path.bindTarget("voxels_diffuse", "voxels_diffuse"); path.bindTarget("voxels_specular", "voxels_specular"); - #if arm_voxelgi_refract - Inc.resolveRefraction(); - path.bindTarget("voxels_refraction", "voxels_refraction"); - #end #end #if arm_voxelgi_shadows Inc.resolveShadows(); @@ -549,15 +522,14 @@ class RenderPathForward { path.bindTarget("lbuffer0", "tex"); path.drawShader("shader_datas/copy_pass/copy_pass"); - path.setTarget("lbuffer0_refr", ["lbuffer1_refr"]); + path.setTarget("lbuffer0", ["lbuffer1", "gbuffer_refraction"]); + #if (rp_voxels != "Off") #if (rp_voxels == "Voxel AO") path.bindTarget("voxels_ao", "voxels_ao"); #else path.bindTarget("voxels_diffuse", "voxels_diffuse"); path.bindTarget("voxels_specular", "voxels_specular"); - #if arm_voxelgi_refract - path.bindTarget("voxels_refraction", "voxels_refraction"); #end #end #if arm_voxelgi_shadows @@ -566,12 +538,22 @@ class RenderPathForward { path.drawMeshes("refraction"); + #if arm_voxelgi_refract + path.setTarget("half"); + path.bindTarget("_main", "texdepth"); + path.drawShader("shader_datas/downsample_depth/downsample_depth"); + Inc.resolveRefraction(); + #end + path.setTarget("lbuffer0"); + #if arm_voxelgi_refract + path.bindTarget("voxels_refraction", "voxels_refraction"); + #end path.bindTarget("refr", "tex1"); - path.bindTarget("lbuffer0_refr", "tex"); + path.bindTarget("lbuffer0", "tex"); path.bindTarget("_main", "gbufferD"); path.bindTarget("gbufferD1", "gbufferD1"); - path.bindTarget("lbuffer1_refr", "gbuffer0"); + path.bindTarget("lbuffer1", "gbuffer0"); path.bindTarget("gbuffer_refraction", "gbuffer_refraction"); path.drawShader("shader_datas/ssrefr_pass/ssrefr_pass"); } diff --git a/blender/arm/material/make_finalize.py b/blender/arm/material/make_finalize.py index 65c77554d..8b38acae7 100644 --- a/blender/arm/material/make_finalize.py +++ b/blender/arm/material/make_finalize.py @@ -75,7 +75,7 @@ def make(con_mesh: ShaderContext): if export_wpos: vert.add_uniform('mat4 W', '_worldMatrix') vert.add_out('vec3 wposition') - vert.write_attrib('wposition = vec4(W * spos).xyz;') + vert.write('wposition = vec4(W * spos).xyz;') elif write_wpos: vert.add_uniform('mat4 W', '_worldMatrix') vert.write_attrib('vec3 wposition = vec4(W * spos).xyz;') diff --git a/blender/arm/material/make_mesh.py b/blender/arm/material/make_mesh.py index 2d9ae3ec5..083cb662f 100644 --- a/blender/arm/material/make_mesh.py +++ b/blender/arm/material/make_mesh.py @@ -668,12 +668,25 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False): frag.write('vec3 indirect = envl;') if '_VoxelAOvar' in wrd.world_defs: - frag.add_include("std/conetrace.glsl") - frag.add_uniform("sampler3D voxels") - if '_VoxelShadow' in wrd.world_defs: - frag.add_uniform("sampler3D voxelsSDF") - frag.add_uniform('float clipmaps[10 * voxelgiClipmapCount]', '_clipmaps'); - frag.write('indirect *= textureLod(voxels_ao, gl_FragCoord.xy, 0.0).r;') + frag.add_uniform("sampler2D voxels_ao"); + vert.add_out('vec2 texCoord') + vert.write('const vec2 madd = vec2(0.5, 0.5);') + vert.write('texCoord = pos.xy * madd + madd;') + if '_InvY' in wrd.world_defs: + frag.write('texCoord.y = 1.0 - texCoord.y;') + frag.write('indirect *= textureLod(voxels_ao, texCoord.xy, 0.0).r;') + + if '_VoxelGI' in wrd.world_defs: + frag.add_uniform("sampler2D voxels_diffuse") + frag.add_uniform("sampler2D voxels_specular") + vert.add_out('vec2 texCoord') + vert.write('const vec2 madd = vec2(0.5, 0.5);') + vert.write('texCoord = pos.xy * madd + madd;') + if '_InvY' in wrd.world_defs: + vert.write('texCoord.y = 1.0 - texCoord.y;') + frag.write("indirect = textureLod(voxels_diffuse, texCoord, 0.0).rgb * albedo * voxelgiDiff;") + frag.write("if (roughness < 1.0 && specular > 0.0)") + frag.write(" indirect += textureLod(voxels_specular, texCoord, 0.0).rgb * specular * voxelgiRefl;") frag.write('vec3 direct = vec3(0.0);')