Metal fixes

This commit is contained in:
Lubos Lenco 2020-05-11 09:03:13 +02:00
parent a05ab6d855
commit e30a8c7f46
27 changed files with 126 additions and 62 deletions

View file

@ -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"]
}
]

View file

@ -0,0 +1,8 @@
#version 450
in vec2 texCoord;
out vec4 fragColor;
void main() {
fragColor = vec4(0.0, 0.0, 0.0, 1.0);
}

View file

@ -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"]
}
]
}

View file

@ -0,0 +1,8 @@
#version 450
in vec2 texCoord;
out vec4 fragColor;
void main() {
gl_FragDepth = 1.0;
}

View file

@ -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"]
}
]
}

View file

@ -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

View file

@ -13,7 +13,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

View file

@ -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;

View file

@ -15,7 +15,7 @@ out vec4 fragColor;
void main() {
vec2 velocity = textureLod(sveloc, texCoord, 0.0).rg * motionBlurIntensity * frameScale;
#ifdef HLSL
#ifdef _InvY
velocity.y = -velocity.y;
#endif

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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

View file

@ -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);
@ -62,7 +62,7 @@ vec4 SMAANeighborhoodBlendingPS(vec2 texcoord, vec4 offset) {
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;

View file

@ -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

View file

@ -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;

View file

@ -29,7 +29,7 @@ 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;

View file

@ -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

View file

@ -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));

View file

@ -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;

View file

@ -20,7 +20,7 @@ void main() {
// 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

View file

@ -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");

View file

@ -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

View file

@ -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':

View file

@ -43,7 +43,7 @@ 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;')

View file

@ -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: