diff --git a/Shaders/ssr_pass/ssr_pass.frag.glsl b/Shaders/ssr_pass/ssr_pass.frag.glsl index 84aa2fab3b..138056afdd 100644 --- a/Shaders/ssr_pass/ssr_pass.frag.glsl +++ b/Shaders/ssr_pass/ssr_pass.frag.glsl @@ -92,7 +92,7 @@ void main() { vec3 viewNormal = V3 * n; vec3 viewPos = getPosView(viewRay, d, cameraProj); - vec3 reflected = reflect(viewPos, viewNormal); + vec3 reflected = reflect(normalize(viewPos), viewNormal); hitCoord = viewPos; #ifdef _CPostprocess diff --git a/Shaders/ssrefr_pass/ssrefr_pass.frag.glsl b/Shaders/ssrefr_pass/ssrefr_pass.frag.glsl index 08366beb83..91ccb21155 100644 --- a/Shaders/ssrefr_pass/ssrefr_pass.frag.glsl +++ b/Shaders/ssrefr_pass/ssrefr_pass.frag.glsl @@ -81,11 +81,10 @@ void main() { vec3 n; n.z = 1.0 - abs(enc.x) - abs(enc.y); n.xy = n.z >= 0.0 ? enc.xy : octahedronWrap(enc.xy); - n = normalize(n); vec3 viewNormal = V3 * n; vec3 viewPos = getPosView(viewRay, d, cameraProj); - vec3 refracted = refract(-viewPos, viewNormal, ior); + vec3 refracted = refract(normalize(viewPos), viewNormal, 1.0 / ior); hitCoord = viewPos; vec3 dir = refracted * (1.0 - rand(texCoord) * ss_refractionJitter * roughness) * 2.0; diff --git a/Sources/armory/renderpath/RenderPathDeferred.hx b/Sources/armory/renderpath/RenderPathDeferred.hx index 5f2d35722b..e7f14aec20 100644 --- a/Sources/armory/renderpath/RenderPathDeferred.hx +++ b/Sources/armory/renderpath/RenderPathDeferred.hx @@ -364,17 +364,6 @@ class RenderPathDeferred { t.format = "R32"; t.scale = Inc.getSuperSampling(); path.createRenderTarget(t); - - // holds normals - var t = new RenderTargetRaw(); - t.name = "lbuffer1"; - t.width = 0; - t.height = 0; - t.format = Inc.getHdrFormat(); - t.displayp = Inc.getDisplayp(); - t.scale = Inc.getSuperSampling(); - path.createRenderTarget(t); - } #end @@ -784,7 +773,7 @@ class RenderPathDeferred { path.bindTarget("tex", "tex"); path.drawShader("shader_datas/copy_pass/copy_pass"); - path.setTarget("tex", ["lbuffer1", "gbuffer_refraction"]); + path.setTarget("tex", ["gbuffer0", "gbuffer_refraction"]); path.drawMeshes("refraction"); path.setTarget("tex"); @@ -792,7 +781,7 @@ class RenderPathDeferred { path.bindTarget("tex", "tex"); path.bindTarget("_main", "gbufferD"); path.bindTarget("gbufferD1", "gbufferD1"); - path.bindTarget("lbuffer1", "gbuffer0"); + path.bindTarget("gbuffer0", "gbuffer0"); path.bindTarget("gbuffer_refraction", "gbuffer_refraction"); path.drawShader("shader_datas/ssrefr_pass/ssrefr_pass"); } diff --git a/blender/arm/material/make_refract.py b/blender/arm/material/make_refract.py new file mode 100644 index 0000000000..6d13230128 --- /dev/null +++ b/blender/arm/material/make_refract.py @@ -0,0 +1,48 @@ +import bpy + +import arm +import arm.material.cycles as cycles +import arm.material.mat_state as mat_state +import arm.material.make_mesh as make_mesh +import arm.material.make_finalize as make_finalize +import arm.assets as assets + +if arm.is_reload(__name__): + cycles = arm.reload_module(cycles) + mat_state = arm.reload_module(mat_state) + make_mesh = arm.reload_module(make_mesh) + make_finalize = arm.reload_module(make_finalize) + assets = arm.reload_module(assets) +else: + arm.enable_reload(__name__) + + +def make(context_id): + con_refract = mat_state.data.add_context({ 'name': context_id, 'depth_write': True, 'compare_mode': 'less', 'cull_mode': 'clockwise' }) + + make_mesh.make_forward_base(con_refract, parse_opacity=True, transluc_pass=True) + + vert = con_refract.vert + frag = con_refract.frag + tese = con_refract.tese + + frag.add_include('std/gbuffer.glsl') + frag.add_out('vec4 fragColor[3]') + + # Remove fragColor = ...; + frag.main = frag.main[:frag.main.rfind('fragColor')] + frag.write('\n') + + wrd = bpy.data.worlds['Arm'] + + frag.write('n /= (abs(n.x) + abs(n.y) + abs(n.z));') + frag.write('n.xy = n.z >= 0.0 ? n.xy : octahedronWrap(n.xy);') + frag.write('fragColor[0] = vec4(direct + indirect, packFloat2(occlusion, specular));') + frag.write('fragColor[1] = vec4(n.xy, roughness, metallic);') + frag.write('fragColor[2] = vec4(ior, opacity, 0.0, 0.0);') + make_finalize.make(con_refract) + + # assets.vs_equal(con_refract, assets.shader_cons['transluc_vert']) # shader_cons has no transluc yet + # assets.fs_equal(con_refract, assets.shader_cons['transluc_frag']) + + return con_refract