Skip to content

Commit

Permalink
TODO: fix the texCoord in make_forward_base.py
Browse files Browse the repository at this point in the history
  • Loading branch information
e2002e committed Jul 30, 2024
1 parent aea321a commit a77bd79
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 91 deletions.
2 changes: 1 addition & 1 deletion Shaders/deferred_light/deferred_light.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 1 addition & 9 deletions Shaders/ssrefr_pass/ssrefr_pass.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion Shaders/std/conetrace.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
16 changes: 14 additions & 2 deletions Sources/armory/renderpath/Inc.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
55 changes: 17 additions & 38 deletions Sources/armory/renderpath/RenderPathDeferred.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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");
Expand Down
48 changes: 15 additions & 33 deletions Sources/armory/renderpath/RenderPathForward.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion blender/arm/material/make_finalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;')
Expand Down
25 changes: 19 additions & 6 deletions blender/arm/material/make_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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);')

Expand Down

0 comments on commit a77bd79

Please sign in to comment.