From e30a8c7f4679a415029282080af9e80d46e63941 Mon Sep 17 00:00:00 2001 From: Lubos Lenco Date: Mon, 11 May 2020 09:03:13 +0200 Subject: [PATCH] Metal fixes --- .../clear_color_depth_pass.frag.glsl} | 0 .../clear_color_depth_pass.json} | 4 +-- .../clear_color_pass.frag.glsl | 8 +++++ .../clear_color_pass/clear_color_pass.json | 15 ++++++++++ .../clear_depth_pass.frag.glsl | 8 +++++ .../clear_depth_pass/clear_depth_pass.json | 19 ++++++++++++ Shaders/include/pass_viewray.vert.glsl | 2 +- Shaders/include/pass_viewray2.vert.glsl | 4 +-- .../motion_blur_pass.frag.glsl | 8 ++--- .../motion_blur_veloc_pass.frag.glsl | 6 ++-- Shaders/probe_cubemap/probe_cubemap.frag.glsl | 4 +-- Shaders/probe_planar/probe_planar.frag.glsl | 4 +-- .../smaa_blend_weight.frag.glsl | 29 ++++++++++--------- .../smaa_edge_detect.vert.glsl | 4 +-- .../smaa_neighborhood_blend.frag.glsl | 8 ++--- .../smaa_neighborhood_blend.vert.glsl | 4 +-- Shaders/ssgi_pass/ssgi_pass.frag.glsl | 2 +- Shaders/ssr_pass/ssr_pass.frag.glsl | 12 ++++---- Shaders/std/gbuffer.glsl | 10 +++---- Shaders/std/shadows.glsl | 4 +-- Shaders/std/ssrs.glsl | 2 +- Shaders/taa_pass/taa_pass.frag.glsl | 4 +-- .../armory/renderpath/RenderPathDeferred.hx | 9 ++++++ .../armory/renderpath/RenderPathForward.hx | 6 ++-- blender/arm/make_renderpath.py | 4 ++- blender/arm/material/make_decal.py | 6 ++-- blender/arm/material/make_mesh.py | 2 +- 27 files changed, 126 insertions(+), 62 deletions(-) rename Shaders/{clear_pass/clear_pass.frag.glsl => clear_color_depth_pass/clear_color_depth_pass.frag.glsl} (100%) rename Shaders/{clear_pass/clear_pass.json => clear_color_depth_pass/clear_color_depth_pass.json} (70%) create mode 100644 Shaders/clear_color_pass/clear_color_pass.frag.glsl create mode 100644 Shaders/clear_color_pass/clear_color_pass.json create mode 100644 Shaders/clear_depth_pass/clear_depth_pass.frag.glsl create mode 100644 Shaders/clear_depth_pass/clear_depth_pass.json diff --git a/Shaders/clear_pass/clear_pass.frag.glsl b/Shaders/clear_color_depth_pass/clear_color_depth_pass.frag.glsl similarity index 100% rename from Shaders/clear_pass/clear_pass.frag.glsl rename to Shaders/clear_color_depth_pass/clear_color_depth_pass.frag.glsl diff --git a/Shaders/clear_pass/clear_pass.json b/Shaders/clear_color_depth_pass/clear_color_depth_pass.json similarity index 70% rename from Shaders/clear_pass/clear_pass.json rename to Shaders/clear_color_depth_pass/clear_color_depth_pass.json index c2165846..5a7b5b93 100644 --- a/Shaders/clear_pass/clear_pass.json +++ b/Shaders/clear_color_depth_pass/clear_color_depth_pass.json @@ -1,14 +1,14 @@ { "contexts": [ { - "name": "clear_pass", + "name": "clear_color_depth_pass", "depth_write": true, "compare_mode": "always", "cull_mode": "none", "links": [], "texture_params": [], "vertex_shader": "../include/pass.vert.glsl", - "fragment_shader": "clear_pass.frag.glsl", + "fragment_shader": "clear_color_depth_pass.frag.glsl", "color_attachments": ["_HDR"] } ] diff --git a/Shaders/clear_color_pass/clear_color_pass.frag.glsl b/Shaders/clear_color_pass/clear_color_pass.frag.glsl new file mode 100644 index 00000000..c8cf9ad8 --- /dev/null +++ b/Shaders/clear_color_pass/clear_color_pass.frag.glsl @@ -0,0 +1,8 @@ +#version 450 + +in vec2 texCoord; +out vec4 fragColor; + +void main() { + fragColor = vec4(0.0, 0.0, 0.0, 1.0); +} diff --git a/Shaders/clear_color_pass/clear_color_pass.json b/Shaders/clear_color_pass/clear_color_pass.json new file mode 100644 index 00000000..3c2c5582 --- /dev/null +++ b/Shaders/clear_color_pass/clear_color_pass.json @@ -0,0 +1,15 @@ +{ + "contexts": [ + { + "name": "clear_color_pass", + "depth_write": false, + "compare_mode": "always", + "cull_mode": "none", + "links": [], + "texture_params": [], + "vertex_shader": "../include/pass.vert.glsl", + "fragment_shader": "clear_color_pass.frag.glsl", + "color_attachments": ["_HDR"] + } + ] +} diff --git a/Shaders/clear_depth_pass/clear_depth_pass.frag.glsl b/Shaders/clear_depth_pass/clear_depth_pass.frag.glsl new file mode 100644 index 00000000..78cb125e --- /dev/null +++ b/Shaders/clear_depth_pass/clear_depth_pass.frag.glsl @@ -0,0 +1,8 @@ +#version 450 + +in vec2 texCoord; +out vec4 fragColor; + +void main() { + gl_FragDepth = 1.0; +} diff --git a/Shaders/clear_depth_pass/clear_depth_pass.json b/Shaders/clear_depth_pass/clear_depth_pass.json new file mode 100644 index 00000000..ca318696 --- /dev/null +++ b/Shaders/clear_depth_pass/clear_depth_pass.json @@ -0,0 +1,19 @@ +{ + "contexts": [ + { + "name": "clear_depth_pass", + "depth_write": true, + "color_write_red": false, + "color_write_green": false, + "color_write_blue": false, + "color_write_alpha": false, + "compare_mode": "always", + "cull_mode": "none", + "links": [], + "texture_params": [], + "vertex_shader": "../include/pass.vert.glsl", + "fragment_shader": "clear_depth_pass.frag.glsl", + "color_attachments": ["_HDR"] + } + ] +} diff --git a/Shaders/include/pass_viewray.vert.glsl b/Shaders/include/pass_viewray.vert.glsl index 5c916a4a..0b77b14d 100644 --- a/Shaders/include/pass_viewray.vert.glsl +++ b/Shaders/include/pass_viewray.vert.glsl @@ -14,7 +14,7 @@ void main() { // Scale vertex attribute to [0-1] range const vec2 madd = vec2(0.5, 0.5); texCoord = pos.xy * madd + madd; - #ifdef HLSL + #ifdef _InvY texCoord.y = 1.0 - texCoord.y; #endif diff --git a/Shaders/include/pass_viewray2.vert.glsl b/Shaders/include/pass_viewray2.vert.glsl index 727a42a6..8370ab38 100644 --- a/Shaders/include/pass_viewray2.vert.glsl +++ b/Shaders/include/pass_viewray2.vert.glsl @@ -13,14 +13,14 @@ void main() { // Scale vertex attribute to [0-1] range const vec2 madd = vec2(0.5, 0.5); texCoord = pos.xy * madd + madd; - #ifdef HLSL + #ifdef _InvY texCoord.y = 1.0 - texCoord.y; #endif gl_Position = vec4(pos.xy, 0.0, 1.0); // NDC (at the back of cube) - vec4 v = vec4(pos.x, pos.y, 1.0, 1.0); + vec4 v = vec4(pos.x, pos.y, 1.0, 1.0); v = vec4(invP * v); viewRay = vec3(v.xy / v.z, 1.0); } diff --git a/Shaders/motion_blur_pass/motion_blur_pass.frag.glsl b/Shaders/motion_blur_pass/motion_blur_pass.frag.glsl index 5161e0bd..f58a2e80 100644 --- a/Shaders/motion_blur_pass/motion_blur_pass.frag.glsl +++ b/Shaders/motion_blur_pass/motion_blur_pass.frag.glsl @@ -18,7 +18,7 @@ in vec3 viewRay; out vec4 fragColor; vec2 getVelocity(vec2 coord, float depth) { - #ifdef HLSL + #ifdef _InvY coord.y = 1.0 - coord.y; #endif vec4 currentPos = vec4(coord.xy * 2.0 - 1.0, depth, 1.0); @@ -26,7 +26,7 @@ vec2 getVelocity(vec2 coord, float depth) { vec4 previousPos = prevVP * worldPos; previousPos /= previousPos.w; vec2 velocity = (currentPos - previousPos).xy / 40.0; - #ifdef HLSL + #ifdef _InvY velocity.y = -velocity.y; #endif return velocity; @@ -34,7 +34,7 @@ vec2 getVelocity(vec2 coord, float depth) { void main() { fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb; - + float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0; if (depth == 1.0) { return; @@ -42,7 +42,7 @@ void main() { float blurScale = motionBlurIntensity * frameScale; vec2 velocity = getVelocity(texCoord, depth) * blurScale; - + vec2 offset = texCoord; int processed = 1; for(int i = 0; i < 8; ++i) { diff --git a/Shaders/motion_blur_veloc_pass/motion_blur_veloc_pass.frag.glsl b/Shaders/motion_blur_veloc_pass/motion_blur_veloc_pass.frag.glsl index a361e3a9..e521f7b1 100755 --- a/Shaders/motion_blur_veloc_pass/motion_blur_veloc_pass.frag.glsl +++ b/Shaders/motion_blur_veloc_pass/motion_blur_veloc_pass.frag.glsl @@ -14,11 +14,11 @@ out vec4 fragColor; void main() { vec2 velocity = textureLod(sveloc, texCoord, 0.0).rg * motionBlurIntensity * frameScale; - - #ifdef HLSL + + #ifdef _InvY velocity.y = -velocity.y; #endif - + fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb; // float speed = length(velocity / texStep); diff --git a/Shaders/probe_cubemap/probe_cubemap.frag.glsl b/Shaders/probe_cubemap/probe_cubemap.frag.glsl index ee33182c..648bec1e 100644 --- a/Shaders/probe_cubemap/probe_cubemap.frag.glsl +++ b/Shaders/probe_cubemap/probe_cubemap.frag.glsl @@ -17,7 +17,7 @@ out vec4 fragColor; void main() { vec2 texCoord = wvpposition.xy / wvpposition.w; texCoord = texCoord * 0.5 + 0.5; - #ifdef HLSL + #ifdef _InvY texCoord.y = 1.0 - texCoord.y; #endif @@ -46,7 +46,7 @@ void main() { vec3 v = wp - eye; vec3 r = reflect(v, n); - #ifdef HLSL + #ifdef _InvY r.y = -r.y; #endif float intensity = clamp((1.0 - roughness) * dot(wp - probep, n), 0.0, 1.0); diff --git a/Shaders/probe_planar/probe_planar.frag.glsl b/Shaders/probe_planar/probe_planar.frag.glsl index c2de3f0b..81b1782a 100644 --- a/Shaders/probe_planar/probe_planar.frag.glsl +++ b/Shaders/probe_planar/probe_planar.frag.glsl @@ -17,7 +17,7 @@ out vec4 fragColor; void main() { vec2 texCoord = wvpposition.xy / wvpposition.w; texCoord = texCoord * 0.5 + 0.5; - #ifdef HLSL + #ifdef _InvY texCoord.y = 1.0 - texCoord.y; #endif @@ -39,7 +39,7 @@ void main() { vec3 wp = getPos2(invVP, depth, texCoord); vec4 pp = probeVP * vec4(wp.xyz, 1.0); vec2 tc = (pp.xy / pp.w) * 0.5 + 0.5; - #ifdef HLSL + #ifdef _InvY tc.y = 1.0 - tc.y; #endif diff --git a/Shaders/smaa_blend_weight/smaa_blend_weight.frag.glsl b/Shaders/smaa_blend_weight/smaa_blend_weight.frag.glsl index db2f6593..b1239d53 100644 --- a/Shaders/smaa_blend_weight/smaa_blend_weight.frag.glsl +++ b/Shaders/smaa_blend_weight/smaa_blend_weight.frag.glsl @@ -1,5 +1,6 @@ #version 450 +#include "compiled.inc" #define SMAA_MAX_SEARCH_STEPS_DIAG 8 #define SMAA_AREATEX_MAX_DISTANCE 16 #define SMAA_AREATEX_MAX_DISTANCE_DIAG 20 @@ -33,7 +34,7 @@ out vec4 fragColor; vec2 cdw_end; vec4 textureLodA(sampler2D tex, vec2 coord, float lod) { - #ifdef HLSL + #ifdef _InvY coord.y = 1.0 - coord.y; #endif return textureLod(tex, coord, lod); @@ -104,7 +105,7 @@ vec2 SMAASearchDiag2(vec2 texcoord, vec2 dir) { return coord.zw; } -/** +/** * Similar to SMAAArea, this calculates the area corresponding to a certain * diagonal distance and crossing edges 'e'. */ @@ -147,7 +148,7 @@ vec2 SMAACalculateDiagWeights(vec2 texcoord, vec2 e, vec4 subsampleIndices) { // Fetch the crossing edges: vec4 coords = mad(vec4(-d.x + 0.25, d.x, d.y, -d.y - 0.25), screenSizeInv.xyxy, texcoord.xyxy); vec4 c; - + c.xy = SMAASampleLevelZeroOffset(edgesTex, coords.xy, ivec2(-1, 0)).rg; c.zw = SMAASampleLevelZeroOffset(edgesTex, coords.zw, ivec2( 1, 0)).rg; c.yxwz = SMAADecodeDiagBilinearAccess(c.xyzw); @@ -172,7 +173,7 @@ vec2 SMAACalculateDiagWeights(vec2 texcoord, vec2 e, vec4 subsampleIndices) { d.yw = SMAASearchDiag2(texcoord, vec2(1.0, 1.0)/*, cdw_end*/); float dadd = cdw_end.y > 0.9 ? 1.0 : 0.0; d.y += dadd; - } + } else { d.yw = vec2(0.0, 0.0); } @@ -207,7 +208,7 @@ vec2 SMAACalculateDiagWeights(vec2 texcoord, vec2 e, vec4 subsampleIndices) { /** * This allows to determine how much length should we add in the last step - * of the searches. It takes the bilinearly interpolated edge (see + * of the searches. It takes the bilinearly interpolated edge (see * @PSEUDO_GATHER4), and adds 0, 1 or 2, depending on which edges and * crossing edges are active. */ @@ -244,7 +245,7 @@ float SMAASearchXLeft(vec2 texcoord, float end) { * which edges are active from the four fetched ones. */ vec2 e = vec2(0.0, 1.0); - while (texcoord.x > end && + while (texcoord.x > end && e.g > 0.8281 && // Is there some edge not activated? e.r == 0.0) { // Or is there a crossing edge that breaks the line? e = textureLodA(edgesTex, texcoord, 0.0).rg; @@ -257,20 +258,20 @@ float SMAASearchXLeft(vec2 texcoord, float end) { float SMAASearchXRight(vec2 texcoord, float end) { vec2 e = vec2(0.0, 1.0); - while (texcoord.x < end && + while (texcoord.x < end && e.g > 0.8281 && // Is there some edge not activated? e.r == 0.0) { // Or is there a crossing edge that breaks the line? e = textureLodA(edgesTex, texcoord, 0.0).rg; texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord); } - + float offset = mad(-(255.0 / 127.0), SMAASearchLength(e, 0.5), 3.25); return mad(-screenSizeInv.x, offset, texcoord.x); } float SMAASearchYUp(vec2 texcoord, float end) { vec2 e = vec2(1.0, 0.0); - while (texcoord.y > end && + while (texcoord.y > end && e.r > 0.8281 && // Is there some edge not activated? e.g == 0.0) { // Or is there a crossing edge that breaks the line? e = textureLodA(edgesTex, texcoord, 0.0).rg; @@ -282,7 +283,7 @@ float SMAASearchYUp(vec2 texcoord, float end) { float SMAASearchYDown(vec2 texcoord, float end) { vec2 e = vec2(1.0, 0.0); - while (texcoord.y < end && + while (texcoord.y < end && e.r > 0.8281 && // Is there some edge not activated? e.g == 0.0) { // Or is there a crossing edge that breaks the line? e = textureLodA(edgesTex, texcoord, 0.0).rg; @@ -292,14 +293,14 @@ float SMAASearchYDown(vec2 texcoord, float end) { return mad(-screenSizeInv.y, offset, texcoord.y); } -/** +/** * Ok, we have the distance and both crossing edges. So, what are the areas * at each side of current edge? */ vec2 SMAAArea(vec2 dist, float e1, float e2, float offset) { // Rounding prevents precision errors of bilinear filtering: vec2 texcoord = mad(vec2(SMAA_AREATEX_MAX_DISTANCE, SMAA_AREATEX_MAX_DISTANCE), round(4.0 * vec2(e1, e2)), dist); - + // We do a scale and bias for mapping to texel space: texcoord = mad(SMAA_AREATEX_PIXEL_SIZE, texcoord, 0.5 * SMAA_AREATEX_PIXEL_SIZE); @@ -363,7 +364,7 @@ vec4 SMAABlendingWeightCalculationPS(vec2 texcoord, vec2 pixcoord, // one of the boundaries is enough. weights.rg = SMAACalculateDiagWeights(texcoord, e, subsampleIndices); - // We give priority to diagonals, so if we find a diagonal we skip + // We give priority to diagonals, so if we find a diagonal we skip // horizontal/vertical processing. //SMAA_BRANCH if (weights.r == -weights.g) { // weights.r + weights.g == 0.0 @@ -433,7 +434,7 @@ vec4 SMAABlendingWeightCalculationPS(vec2 texcoord, vec2 pixcoord, // We want the distances to be in pixel units: d = abs(round(mad(screenSize.yy, d, -pixcoord.yy))); - // SMAAArea below needs a sqrt, as the areas texture is compressed + // SMAAArea below needs a sqrt, as the areas texture is compressed // quadratically: vec2 sqrt_d = sqrt(d); diff --git a/Shaders/smaa_edge_detect/smaa_edge_detect.vert.glsl b/Shaders/smaa_edge_detect/smaa_edge_detect.vert.glsl index 61b3961c..7ce815b3 100644 --- a/Shaders/smaa_edge_detect/smaa_edge_detect.vert.glsl +++ b/Shaders/smaa_edge_detect/smaa_edge_detect.vert.glsl @@ -11,7 +11,7 @@ out vec4 offset0; out vec4 offset1; out vec4 offset2; -#ifdef HLSL +#ifdef _InvY #define V_DIR(v) -(v) #else #define V_DIR(v) v @@ -21,7 +21,7 @@ void main() { // Scale vertex attribute to [0-1] range const vec2 madd = vec2(0.5, 0.5); texCoord = pos.xy * madd + madd; - #ifdef HLSL + #ifdef _InvY texCoord.y = 1.0 - texCoord.y; #endif diff --git a/Shaders/smaa_neighborhood_blend/smaa_neighborhood_blend.frag.glsl b/Shaders/smaa_neighborhood_blend/smaa_neighborhood_blend.frag.glsl index d307e79d..99dca290 100755 --- a/Shaders/smaa_neighborhood_blend/smaa_neighborhood_blend.frag.glsl +++ b/Shaders/smaa_neighborhood_blend/smaa_neighborhood_blend.frag.glsl @@ -18,7 +18,7 @@ out vec4 fragColor; // Neighborhood Blending Pixel Shader (Third Pass) vec4 textureLodA(sampler2D tex, vec2 coords, float lod) { - #ifdef HLSL + #ifdef _InvY coords.y = 1.0 - coords.y; #endif return textureLod(tex, coords, lod); @@ -49,7 +49,7 @@ vec4 SMAANeighborhoodBlendingPS(vec2 texcoord, vec4 offset) { // Calculate the blending offsets: vec4 blendingOffset = vec4(0.0, a.y, 0.0, a.w); vec2 blendingWeight = a.yw; - + if (h) { blendingOffset.x = a.x; blendingOffset.y = 0.0; @@ -58,11 +58,11 @@ vec4 SMAANeighborhoodBlendingPS(vec2 texcoord, vec4 offset) { blendingWeight.x = a.x; blendingWeight.y = a.z; } - + blendingWeight /= dot(blendingWeight, vec2(1.0, 1.0)); // Calculate the texture coordinates: - #ifdef HLSL + #ifdef _InvY vec2 tc = vec2(texcoord.x, 1.0 - texcoord.y); #else vec2 tc = texcoord; diff --git a/Shaders/smaa_neighborhood_blend/smaa_neighborhood_blend.vert.glsl b/Shaders/smaa_neighborhood_blend/smaa_neighborhood_blend.vert.glsl index 8d433797..6568ab64 100644 --- a/Shaders/smaa_neighborhood_blend/smaa_neighborhood_blend.vert.glsl +++ b/Shaders/smaa_neighborhood_blend/smaa_neighborhood_blend.vert.glsl @@ -9,7 +9,7 @@ uniform vec2 screenSizeInv; out vec2 texCoord; out vec4 offset; -#ifdef HLSL +#ifdef _InvY #define V_DIR(v) -(v) #else #define V_DIR(v) v @@ -19,7 +19,7 @@ void main() { // Scale vertex attribute to [0-1] range const vec2 madd = vec2(0.5, 0.5); texCoord = pos.xy * madd + madd; - #ifdef HLSL + #ifdef _InvY texCoord.y = 1.0 - texCoord.y; #endif diff --git a/Shaders/ssgi_pass/ssgi_pass.frag.glsl b/Shaders/ssgi_pass/ssgi_pass.frag.glsl index acc6d341..694e0f21 100755 --- a/Shaders/ssgi_pass/ssgi_pass.frag.glsl +++ b/Shaders/ssgi_pass/ssgi_pass.frag.glsl @@ -37,7 +37,7 @@ vec2 getProjectedCoord(vec3 hitCoord) { vec4 projectedCoord = P * vec4(hitCoord, 1.0); projectedCoord.xy /= projectedCoord.w; projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5; - #ifdef HLSL + #ifdef _InvY projectedCoord.y = 1.0 - projectedCoord.y; #endif return projectedCoord.xy; diff --git a/Shaders/ssr_pass/ssr_pass.frag.glsl b/Shaders/ssr_pass/ssr_pass.frag.glsl index 0fc1ea0a..8ec84256 100755 --- a/Shaders/ssr_pass/ssr_pass.frag.glsl +++ b/Shaders/ssr_pass/ssr_pass.frag.glsl @@ -29,13 +29,13 @@ vec2 getProjectedCoord(const vec3 hit) { vec4 projectedCoord = P * vec4(hit, 1.0); projectedCoord.xy /= projectedCoord.w; projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5; - #ifdef HLSL + #ifdef _InvY projectedCoord.y = 1.0 - projectedCoord.y; #endif return projectedCoord.xy; } -float getDeltaDepth(const vec3 hit) { +float getDeltaDepth(const vec3 hit) { depth = textureLod(gbufferD, getProjectedCoord(hit), 0.0).r * 2.0 - 1.0; vec3 viewPos = getPosView(viewRay, depth, cameraProj); return viewPos.z - hit.z; @@ -79,7 +79,7 @@ void main() { float spec = fract(textureLod(gbuffer1, texCoord, 0.0).a); if (spec == 0.0) { fragColor.rgb = vec3(0.0); return; } - + float d = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0; if (d == 1.0) { fragColor.rgb = vec3(0.0); return; } @@ -88,18 +88,18 @@ void main() { 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 reflected = normalize(reflect(viewPos, viewNormal)); hitCoord = viewPos; - + #ifdef _CPostprocess vec3 dir = reflected * (1.0 - rand(texCoord) * PPComp10.y * roughness) * 2.0; #else vec3 dir = reflected * (1.0 - rand(texCoord) * ssrJitter * roughness) * 2.0; #endif - + // * max(ssrMinRayStep, -viewPos.z) vec4 coords = rayCast(dir); diff --git a/Shaders/std/gbuffer.glsl b/Shaders/std/gbuffer.glsl index d72a8783..233213c0 100755 --- a/Shaders/std/gbuffer.glsl +++ b/Shaders/std/gbuffer.glsl @@ -19,7 +19,7 @@ vec3 getPosView(const vec3 viewRay, const float depth, const vec2 cameraProj) { return viewRay * linearDepth; } -vec3 getPos(const vec3 eye, const vec3 eyeLook, const vec3 viewRay, const float depth, const vec2 cameraProj) { +vec3 getPos(const vec3 eye, const vec3 eyeLook, const vec3 viewRay, const float depth, const vec2 cameraProj) { // eyeLook, viewRay should be normalized float linearDepth = cameraProj.y / ((depth * 0.5 + 0.5) - cameraProj.x); float viewZDist = dot(eyeLook, viewRay); @@ -27,7 +27,7 @@ vec3 getPos(const vec3 eye, const vec3 eyeLook, const vec3 viewRay, const float return wposition; } -vec3 getPosNoEye(const vec3 eyeLook, const vec3 viewRay, const float depth, const vec2 cameraProj) { +vec3 getPosNoEye(const vec3 eyeLook, const vec3 viewRay, const float depth, const vec2 cameraProj) { // eyeLook, viewRay should be normalized float linearDepth = cameraProj.y / ((depth * 0.5 + 0.5) - cameraProj.x); float viewZDist = dot(eyeLook, viewRay); @@ -35,7 +35,7 @@ vec3 getPosNoEye(const vec3 eyeLook, const vec3 viewRay, const float depth, cons return wposition; } -#ifdef HLSL +#if defined(HLSL) || defined(METAL) vec3 getPos2(const mat4 invVP, const float depth, vec2 coord) { coord.y = 1.0 - coord.y; #else @@ -47,7 +47,7 @@ vec3 getPos2(const mat4 invVP, const float depth, const vec2 coord) { return pos.xyz; } -#ifdef HLSL +#if defined(HLSL) || defined(METAL) vec3 getPosView2(const mat4 invP, const float depth, vec2 coord) { coord.y = 1.0 - coord.y; #else @@ -59,7 +59,7 @@ vec3 getPosView2(const mat4 invP, const float depth, const vec2 coord) { return pos.xyz; } -#ifdef HLSL +#if defined(HLSL) || defined(METAL) vec3 getPos2NoEye(const vec3 eye, const mat4 invVP, const float depth, vec2 coord) { coord.y = 1.0 - coord.y; #else diff --git a/Shaders/std/shadows.glsl b/Shaders/std/shadows.glsl index 5a7769fb..d610676a 100755 --- a/Shaders/std/shadows.glsl +++ b/Shaders/std/shadows.glsl @@ -35,7 +35,7 @@ float PCFCube(samplerCubeShadow shadowMapCube, const vec3 lp, vec3 ml, const flo const float s = shadowmapCubePcfSize; // TODO: incorrect... float compare = lpToDepth(lp, lightProj) - bias * 1.5; ml = ml + n * bias * 20; - #ifdef HLSL + #ifdef _InvY ml.y = -ml.y; #endif float result = texture(shadowMapCube, vec4(ml, compare)); @@ -105,7 +105,7 @@ float shadowTestCascade(sampler2DShadow shadowMap, const vec3 eye, const vec3 p, int casi; int casIndex; mat4 LWVP = getCascadeMat(d, casi, casIndex); - + vec4 lPos = LWVP * vec4(p, 1.0); lPos.xyz /= lPos.w; diff --git a/Shaders/std/ssrs.glsl b/Shaders/std/ssrs.glsl index a04374f8..c9586610 100644 --- a/Shaders/std/ssrs.glsl +++ b/Shaders/std/ssrs.glsl @@ -9,7 +9,7 @@ vec2 getProjectedCoord(vec3 hitCoord) { vec4 projectedCoord = VP * vec4(hitCoord, 1.0); projectedCoord.xy /= projectedCoord.w; projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5; - #ifdef HLSL + #if defined(HLSL) || defined(METAL) projectedCoord.y = 1.0 - projectedCoord.y; #endif return projectedCoord.xy; diff --git a/Shaders/taa_pass/taa_pass.frag.glsl b/Shaders/taa_pass/taa_pass.frag.glsl index 57ec11af..cdaf2bbb 100755 --- a/Shaders/taa_pass/taa_pass.frag.glsl +++ b/Shaders/taa_pass/taa_pass.frag.glsl @@ -15,12 +15,12 @@ const float SMAA_REPROJECTION_WEIGHT_SCALE = 30.0; void main() { vec4 current = textureLod(tex, texCoord, 0.0); - + #ifdef _Veloc // Velocity is assumed to be calculated for motion blur, so we need to inverse it for reprojection vec2 velocity = -textureLod(sveloc, texCoord, 0.0).rg; - #ifdef HLSL + #ifdef _InvY velocity.y = -velocity.y; #endif diff --git a/Sources/armory/renderpath/RenderPathDeferred.hx b/Sources/armory/renderpath/RenderPathDeferred.hx index 87665920..90e243f6 100644 --- a/Sources/armory/renderpath/RenderPathDeferred.hx +++ b/Sources/armory/renderpath/RenderPathDeferred.hx @@ -37,6 +37,15 @@ class RenderPathDeferred { path = _path; + #if kha_metal + { + path.loadShader("shader_datas/clear_color_depth_pass/clear_color_depth_pass"); + path.loadShader("shader_datas/clear_color_pass/clear_color_pass"); + path.loadShader("shader_datas/clear_depth_pass/clear_depth_pass"); + path.clearShader = "shader_datas/clear_color_depth_pass/clear_color_depth_pass"; + } + #end + #if (rp_background == "World") { path.loadShader("shader_datas/world_pass/world_pass"); diff --git a/Sources/armory/renderpath/RenderPathForward.hx b/Sources/armory/renderpath/RenderPathForward.hx index e989636f..fc74be45 100644 --- a/Sources/armory/renderpath/RenderPathForward.hx +++ b/Sources/armory/renderpath/RenderPathForward.hx @@ -64,8 +64,10 @@ class RenderPathForward { #if kha_metal { - path.loadShader("shader_datas/clear_pass/clear_pass"); - path.clearShader = "shader_datas/clear_pass/clear_pass"; + path.loadShader("shader_datas/clear_color_depth_pass/clear_color_depth_pass"); + path.loadShader("shader_datas/clear_color_pass/clear_color_pass"); + path.loadShader("shader_datas/clear_depth_pass/clear_depth_pass"); + path.clearShader = "shader_datas/clear_color_depth_pass/clear_color_depth_pass"; } #end diff --git a/blender/arm/make_renderpath.py b/blender/arm/make_renderpath.py index 8da7d32c..f0e76103 100755 --- a/blender/arm/make_renderpath.py +++ b/blender/arm/make_renderpath.py @@ -128,7 +128,9 @@ def build(): assets.add_khafile_def('rp_shadowmap_cube={0}'.format(rpdat.rp_shadowmap_cube)) if arm.utils.get_gapi() == 'metal': - assets.add_shader_pass('clear_pass') + assets.add_shader_pass('clear_color_depth_pass') + assets.add_shader_pass('clear_color_pass') + assets.add_shader_pass('clear_depth_pass') assets.add_khafile_def('rp_background={0}'.format(rpdat.rp_background)) if rpdat.rp_background == 'World': diff --git a/blender/arm/material/make_decal.py b/blender/arm/material/make_decal.py index 90a026a1..32e896e9 100644 --- a/blender/arm/material/make_decal.py +++ b/blender/arm/material/make_decal.py @@ -30,7 +30,7 @@ def make(context_id): vert.write('wnormal = N * vec3(0.0, 0.0, 1.0);') vert.write('wvpposition = WVP * vec4(pos.xyz, 1.0);') vert.write('gl_Position = wvpposition;') - + frag.add_include('compiled.inc') frag.add_include('std/gbuffer.glsl') frag.ins = vert.outs @@ -43,11 +43,11 @@ def make(context_id): frag.write_attrib(' vec2 screenPosition = wvpposition.xy / wvpposition.w;') frag.write_attrib(' vec2 depthCoord = screenPosition * 0.5 + 0.5;') - frag.write_attrib('#ifdef HLSL') + frag.write_attrib('#ifdef _InvY') frag.write_attrib(' depthCoord.y = 1.0 - depthCoord.y;') frag.write_attrib('#endif') frag.write_attrib(' float depth = texture(gbufferD, depthCoord).r * 2.0 - 1.0;') - + frag.write_attrib(' vec3 wpos = getPos2(invVP, depth, depthCoord);') frag.write_attrib(' vec4 mpos = invW * vec4(wpos, 1.0);') frag.write_attrib(' if (abs(mpos.x) > 1.0) discard;') diff --git a/blender/arm/material/make_mesh.py b/blender/arm/material/make_mesh.py index 517a1a59..5965e850 100644 --- a/blender/arm/material/make_mesh.py +++ b/blender/arm/material/make_mesh.py @@ -413,7 +413,7 @@ def make_forward_mobile(con_mesh): frag.add_uniform('samplerCubeShadow shadowMapPoint[1]') frag.write('const float s = shadowmapCubePcfSize;') # TODO: incorrect... frag.write('float compare = lpToDepth(ld, lightProj) - pointBias * 1.5;') - frag.write('#ifdef HLSL') + frag.write('#ifdef _InvY') frag.write('l.y = -l.y;') frag.write('#endif') if '_Legacy' in wrd.world_defs: