Skip to content

Commit

Permalink
use correct normalize values, add refraction pass on top of mesh pass…
Browse files Browse the repository at this point in the history
… and use an extra python file to create the shader like transluc.
  • Loading branch information
e2002e committed Apr 1, 2024
1 parent 036e6db commit a469aee
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Shaders/ssr_pass/ssr_pass.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Shaders/ssrefr_pass/ssrefr_pass.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 2 additions & 13 deletions Sources/armory/renderpath/RenderPathDeferred.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -784,15 +773,15 @@ 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");
path.bindTarget("refr", "tex1");
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");
}
Expand Down
48 changes: 48 additions & 0 deletions blender/arm/material/make_refract.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a469aee

Please sign in to comment.