Metal fixes
This commit is contained in:
parent
a05ab6d855
commit
e30a8c7f46
|
@ -1,14 +1,14 @@
|
||||||
{
|
{
|
||||||
"contexts": [
|
"contexts": [
|
||||||
{
|
{
|
||||||
"name": "clear_pass",
|
"name": "clear_color_depth_pass",
|
||||||
"depth_write": true,
|
"depth_write": true,
|
||||||
"compare_mode": "always",
|
"compare_mode": "always",
|
||||||
"cull_mode": "none",
|
"cull_mode": "none",
|
||||||
"links": [],
|
"links": [],
|
||||||
"texture_params": [],
|
"texture_params": [],
|
||||||
"vertex_shader": "../include/pass.vert.glsl",
|
"vertex_shader": "../include/pass.vert.glsl",
|
||||||
"fragment_shader": "clear_pass.frag.glsl",
|
"fragment_shader": "clear_color_depth_pass.frag.glsl",
|
||||||
"color_attachments": ["_HDR"]
|
"color_attachments": ["_HDR"]
|
||||||
}
|
}
|
||||||
]
|
]
|
8
Shaders/clear_color_pass/clear_color_pass.frag.glsl
Normal file
8
Shaders/clear_color_pass/clear_color_pass.frag.glsl
Normal 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);
|
||||||
|
}
|
15
Shaders/clear_color_pass/clear_color_pass.json
Normal file
15
Shaders/clear_color_pass/clear_color_pass.json
Normal 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"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
8
Shaders/clear_depth_pass/clear_depth_pass.frag.glsl
Normal file
8
Shaders/clear_depth_pass/clear_depth_pass.frag.glsl
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
in vec2 texCoord;
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_FragDepth = 1.0;
|
||||||
|
}
|
19
Shaders/clear_depth_pass/clear_depth_pass.json
Normal file
19
Shaders/clear_depth_pass/clear_depth_pass.json
Normal 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"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -14,7 +14,7 @@ void main() {
|
||||||
// Scale vertex attribute to [0-1] range
|
// Scale vertex attribute to [0-1] range
|
||||||
const vec2 madd = vec2(0.5, 0.5);
|
const vec2 madd = vec2(0.5, 0.5);
|
||||||
texCoord = pos.xy * madd + madd;
|
texCoord = pos.xy * madd + madd;
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
texCoord.y = 1.0 - texCoord.y;
|
texCoord.y = 1.0 - texCoord.y;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,14 @@ void main() {
|
||||||
// Scale vertex attribute to [0-1] range
|
// Scale vertex attribute to [0-1] range
|
||||||
const vec2 madd = vec2(0.5, 0.5);
|
const vec2 madd = vec2(0.5, 0.5);
|
||||||
texCoord = pos.xy * madd + madd;
|
texCoord = pos.xy * madd + madd;
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
texCoord.y = 1.0 - texCoord.y;
|
texCoord.y = 1.0 - texCoord.y;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gl_Position = vec4(pos.xy, 0.0, 1.0);
|
gl_Position = vec4(pos.xy, 0.0, 1.0);
|
||||||
|
|
||||||
// NDC (at the back of cube)
|
// 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);
|
v = vec4(invP * v);
|
||||||
viewRay = vec3(v.xy / v.z, 1.0);
|
viewRay = vec3(v.xy / v.z, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ in vec3 viewRay;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
vec2 getVelocity(vec2 coord, float depth) {
|
vec2 getVelocity(vec2 coord, float depth) {
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
coord.y = 1.0 - coord.y;
|
coord.y = 1.0 - coord.y;
|
||||||
#endif
|
#endif
|
||||||
vec4 currentPos = vec4(coord.xy * 2.0 - 1.0, depth, 1.0);
|
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;
|
vec4 previousPos = prevVP * worldPos;
|
||||||
previousPos /= previousPos.w;
|
previousPos /= previousPos.w;
|
||||||
vec2 velocity = (currentPos - previousPos).xy / 40.0;
|
vec2 velocity = (currentPos - previousPos).xy / 40.0;
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
velocity.y = -velocity.y;
|
velocity.y = -velocity.y;
|
||||||
#endif
|
#endif
|
||||||
return velocity;
|
return velocity;
|
||||||
|
@ -34,7 +34,7 @@ vec2 getVelocity(vec2 coord, float depth) {
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb;
|
fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb;
|
||||||
|
|
||||||
float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
|
float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
|
||||||
if (depth == 1.0) {
|
if (depth == 1.0) {
|
||||||
return;
|
return;
|
||||||
|
@ -42,7 +42,7 @@ void main() {
|
||||||
|
|
||||||
float blurScale = motionBlurIntensity * frameScale;
|
float blurScale = motionBlurIntensity * frameScale;
|
||||||
vec2 velocity = getVelocity(texCoord, depth) * blurScale;
|
vec2 velocity = getVelocity(texCoord, depth) * blurScale;
|
||||||
|
|
||||||
vec2 offset = texCoord;
|
vec2 offset = texCoord;
|
||||||
int processed = 1;
|
int processed = 1;
|
||||||
for(int i = 0; i < 8; ++i) {
|
for(int i = 0; i < 8; ++i) {
|
||||||
|
|
|
@ -14,11 +14,11 @@ out vec4 fragColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec2 velocity = textureLod(sveloc, texCoord, 0.0).rg * motionBlurIntensity * frameScale;
|
vec2 velocity = textureLod(sveloc, texCoord, 0.0).rg * motionBlurIntensity * frameScale;
|
||||||
|
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
velocity.y = -velocity.y;
|
velocity.y = -velocity.y;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb;
|
fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb;
|
||||||
|
|
||||||
// float speed = length(velocity / texStep);
|
// float speed = length(velocity / texStep);
|
||||||
|
|
|
@ -17,7 +17,7 @@ out vec4 fragColor;
|
||||||
void main() {
|
void main() {
|
||||||
vec2 texCoord = wvpposition.xy / wvpposition.w;
|
vec2 texCoord = wvpposition.xy / wvpposition.w;
|
||||||
texCoord = texCoord * 0.5 + 0.5;
|
texCoord = texCoord * 0.5 + 0.5;
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
texCoord.y = 1.0 - texCoord.y;
|
texCoord.y = 1.0 - texCoord.y;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ void main() {
|
||||||
|
|
||||||
vec3 v = wp - eye;
|
vec3 v = wp - eye;
|
||||||
vec3 r = reflect(v, n);
|
vec3 r = reflect(v, n);
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
r.y = -r.y;
|
r.y = -r.y;
|
||||||
#endif
|
#endif
|
||||||
float intensity = clamp((1.0 - roughness) * dot(wp - probep, n), 0.0, 1.0);
|
float intensity = clamp((1.0 - roughness) * dot(wp - probep, n), 0.0, 1.0);
|
||||||
|
|
|
@ -17,7 +17,7 @@ out vec4 fragColor;
|
||||||
void main() {
|
void main() {
|
||||||
vec2 texCoord = wvpposition.xy / wvpposition.w;
|
vec2 texCoord = wvpposition.xy / wvpposition.w;
|
||||||
texCoord = texCoord * 0.5 + 0.5;
|
texCoord = texCoord * 0.5 + 0.5;
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
texCoord.y = 1.0 - texCoord.y;
|
texCoord.y = 1.0 - texCoord.y;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ void main() {
|
||||||
vec3 wp = getPos2(invVP, depth, texCoord);
|
vec3 wp = getPos2(invVP, depth, texCoord);
|
||||||
vec4 pp = probeVP * vec4(wp.xyz, 1.0);
|
vec4 pp = probeVP * vec4(wp.xyz, 1.0);
|
||||||
vec2 tc = (pp.xy / pp.w) * 0.5 + 0.5;
|
vec2 tc = (pp.xy / pp.w) * 0.5 + 0.5;
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
tc.y = 1.0 - tc.y;
|
tc.y = 1.0 - tc.y;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
|
#include "compiled.inc"
|
||||||
#define SMAA_MAX_SEARCH_STEPS_DIAG 8
|
#define SMAA_MAX_SEARCH_STEPS_DIAG 8
|
||||||
#define SMAA_AREATEX_MAX_DISTANCE 16
|
#define SMAA_AREATEX_MAX_DISTANCE 16
|
||||||
#define SMAA_AREATEX_MAX_DISTANCE_DIAG 20
|
#define SMAA_AREATEX_MAX_DISTANCE_DIAG 20
|
||||||
|
@ -33,7 +34,7 @@ out vec4 fragColor;
|
||||||
vec2 cdw_end;
|
vec2 cdw_end;
|
||||||
|
|
||||||
vec4 textureLodA(sampler2D tex, vec2 coord, float lod) {
|
vec4 textureLodA(sampler2D tex, vec2 coord, float lod) {
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
coord.y = 1.0 - coord.y;
|
coord.y = 1.0 - coord.y;
|
||||||
#endif
|
#endif
|
||||||
return textureLod(tex, coord, lod);
|
return textureLod(tex, coord, lod);
|
||||||
|
@ -104,7 +105,7 @@ vec2 SMAASearchDiag2(vec2 texcoord, vec2 dir) {
|
||||||
return coord.zw;
|
return coord.zw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Similar to SMAAArea, this calculates the area corresponding to a certain
|
* Similar to SMAAArea, this calculates the area corresponding to a certain
|
||||||
* diagonal distance and crossing edges 'e'.
|
* diagonal distance and crossing edges 'e'.
|
||||||
*/
|
*/
|
||||||
|
@ -147,7 +148,7 @@ vec2 SMAACalculateDiagWeights(vec2 texcoord, vec2 e, vec4 subsampleIndices) {
|
||||||
// Fetch the crossing edges:
|
// 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 coords = mad(vec4(-d.x + 0.25, d.x, d.y, -d.y - 0.25), screenSizeInv.xyxy, texcoord.xyxy);
|
||||||
vec4 c;
|
vec4 c;
|
||||||
|
|
||||||
c.xy = SMAASampleLevelZeroOffset(edgesTex, coords.xy, ivec2(-1, 0)).rg;
|
c.xy = SMAASampleLevelZeroOffset(edgesTex, coords.xy, ivec2(-1, 0)).rg;
|
||||||
c.zw = SMAASampleLevelZeroOffset(edgesTex, coords.zw, ivec2( 1, 0)).rg;
|
c.zw = SMAASampleLevelZeroOffset(edgesTex, coords.zw, ivec2( 1, 0)).rg;
|
||||||
c.yxwz = SMAADecodeDiagBilinearAccess(c.xyzw);
|
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*/);
|
d.yw = SMAASearchDiag2(texcoord, vec2(1.0, 1.0)/*, cdw_end*/);
|
||||||
float dadd = cdw_end.y > 0.9 ? 1.0 : 0.0;
|
float dadd = cdw_end.y > 0.9 ? 1.0 : 0.0;
|
||||||
d.y += dadd;
|
d.y += dadd;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
d.yw = vec2(0.0, 0.0);
|
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
|
* 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
|
* @PSEUDO_GATHER4), and adds 0, 1 or 2, depending on which edges and
|
||||||
* crossing edges are active.
|
* crossing edges are active.
|
||||||
*/
|
*/
|
||||||
|
@ -244,7 +245,7 @@ float SMAASearchXLeft(vec2 texcoord, float end) {
|
||||||
* which edges are active from the four fetched ones.
|
* which edges are active from the four fetched ones.
|
||||||
*/
|
*/
|
||||||
vec2 e = vec2(0.0, 1.0);
|
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.g > 0.8281 && // Is there some edge not activated?
|
||||||
e.r == 0.0) { // Or is there a crossing edge that breaks the line?
|
e.r == 0.0) { // Or is there a crossing edge that breaks the line?
|
||||||
e = textureLodA(edgesTex, texcoord, 0.0).rg;
|
e = textureLodA(edgesTex, texcoord, 0.0).rg;
|
||||||
|
@ -257,20 +258,20 @@ float SMAASearchXLeft(vec2 texcoord, float end) {
|
||||||
|
|
||||||
float SMAASearchXRight(vec2 texcoord, float end) {
|
float SMAASearchXRight(vec2 texcoord, float end) {
|
||||||
vec2 e = vec2(0.0, 1.0);
|
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.g > 0.8281 && // Is there some edge not activated?
|
||||||
e.r == 0.0) { // Or is there a crossing edge that breaks the line?
|
e.r == 0.0) { // Or is there a crossing edge that breaks the line?
|
||||||
e = textureLodA(edgesTex, texcoord, 0.0).rg;
|
e = textureLodA(edgesTex, texcoord, 0.0).rg;
|
||||||
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
|
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
float offset = mad(-(255.0 / 127.0), SMAASearchLength(e, 0.5), 3.25);
|
float offset = mad(-(255.0 / 127.0), SMAASearchLength(e, 0.5), 3.25);
|
||||||
return mad(-screenSizeInv.x, offset, texcoord.x);
|
return mad(-screenSizeInv.x, offset, texcoord.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
float SMAASearchYUp(vec2 texcoord, float end) {
|
float SMAASearchYUp(vec2 texcoord, float end) {
|
||||||
vec2 e = vec2(1.0, 0.0);
|
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.r > 0.8281 && // Is there some edge not activated?
|
||||||
e.g == 0.0) { // Or is there a crossing edge that breaks the line?
|
e.g == 0.0) { // Or is there a crossing edge that breaks the line?
|
||||||
e = textureLodA(edgesTex, texcoord, 0.0).rg;
|
e = textureLodA(edgesTex, texcoord, 0.0).rg;
|
||||||
|
@ -282,7 +283,7 @@ float SMAASearchYUp(vec2 texcoord, float end) {
|
||||||
|
|
||||||
float SMAASearchYDown(vec2 texcoord, float end) {
|
float SMAASearchYDown(vec2 texcoord, float end) {
|
||||||
vec2 e = vec2(1.0, 0.0);
|
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.r > 0.8281 && // Is there some edge not activated?
|
||||||
e.g == 0.0) { // Or is there a crossing edge that breaks the line?
|
e.g == 0.0) { // Or is there a crossing edge that breaks the line?
|
||||||
e = textureLodA(edgesTex, texcoord, 0.0).rg;
|
e = textureLodA(edgesTex, texcoord, 0.0).rg;
|
||||||
|
@ -292,14 +293,14 @@ float SMAASearchYDown(vec2 texcoord, float end) {
|
||||||
return mad(-screenSizeInv.y, offset, texcoord.y);
|
return mad(-screenSizeInv.y, offset, texcoord.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ok, we have the distance and both crossing edges. So, what are the areas
|
* Ok, we have the distance and both crossing edges. So, what are the areas
|
||||||
* at each side of current edge?
|
* at each side of current edge?
|
||||||
*/
|
*/
|
||||||
vec2 SMAAArea(vec2 dist, float e1, float e2, float offset) {
|
vec2 SMAAArea(vec2 dist, float e1, float e2, float offset) {
|
||||||
// Rounding prevents precision errors of bilinear filtering:
|
// 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);
|
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:
|
// We do a scale and bias for mapping to texel space:
|
||||||
texcoord = mad(SMAA_AREATEX_PIXEL_SIZE, texcoord, 0.5 * SMAA_AREATEX_PIXEL_SIZE);
|
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.
|
// one of the boundaries is enough.
|
||||||
weights.rg = SMAACalculateDiagWeights(texcoord, e, subsampleIndices);
|
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.
|
// horizontal/vertical processing.
|
||||||
//SMAA_BRANCH
|
//SMAA_BRANCH
|
||||||
if (weights.r == -weights.g) { // weights.r + weights.g == 0.0
|
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:
|
// We want the distances to be in pixel units:
|
||||||
d = abs(round(mad(screenSize.yy, d, -pixcoord.yy)));
|
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:
|
// quadratically:
|
||||||
vec2 sqrt_d = sqrt(d);
|
vec2 sqrt_d = sqrt(d);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ out vec4 offset0;
|
||||||
out vec4 offset1;
|
out vec4 offset1;
|
||||||
out vec4 offset2;
|
out vec4 offset2;
|
||||||
|
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
#define V_DIR(v) -(v)
|
#define V_DIR(v) -(v)
|
||||||
#else
|
#else
|
||||||
#define V_DIR(v) v
|
#define V_DIR(v) v
|
||||||
|
@ -21,7 +21,7 @@ void main() {
|
||||||
// Scale vertex attribute to [0-1] range
|
// Scale vertex attribute to [0-1] range
|
||||||
const vec2 madd = vec2(0.5, 0.5);
|
const vec2 madd = vec2(0.5, 0.5);
|
||||||
texCoord = pos.xy * madd + madd;
|
texCoord = pos.xy * madd + madd;
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
texCoord.y = 1.0 - texCoord.y;
|
texCoord.y = 1.0 - texCoord.y;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ out vec4 fragColor;
|
||||||
// Neighborhood Blending Pixel Shader (Third Pass)
|
// Neighborhood Blending Pixel Shader (Third Pass)
|
||||||
|
|
||||||
vec4 textureLodA(sampler2D tex, vec2 coords, float lod) {
|
vec4 textureLodA(sampler2D tex, vec2 coords, float lod) {
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
coords.y = 1.0 - coords.y;
|
coords.y = 1.0 - coords.y;
|
||||||
#endif
|
#endif
|
||||||
return textureLod(tex, coords, lod);
|
return textureLod(tex, coords, lod);
|
||||||
|
@ -49,7 +49,7 @@ vec4 SMAANeighborhoodBlendingPS(vec2 texcoord, vec4 offset) {
|
||||||
// Calculate the blending offsets:
|
// Calculate the blending offsets:
|
||||||
vec4 blendingOffset = vec4(0.0, a.y, 0.0, a.w);
|
vec4 blendingOffset = vec4(0.0, a.y, 0.0, a.w);
|
||||||
vec2 blendingWeight = a.yw;
|
vec2 blendingWeight = a.yw;
|
||||||
|
|
||||||
if (h) {
|
if (h) {
|
||||||
blendingOffset.x = a.x;
|
blendingOffset.x = a.x;
|
||||||
blendingOffset.y = 0.0;
|
blendingOffset.y = 0.0;
|
||||||
|
@ -58,11 +58,11 @@ vec4 SMAANeighborhoodBlendingPS(vec2 texcoord, vec4 offset) {
|
||||||
blendingWeight.x = a.x;
|
blendingWeight.x = a.x;
|
||||||
blendingWeight.y = a.z;
|
blendingWeight.y = a.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
blendingWeight /= dot(blendingWeight, vec2(1.0, 1.0));
|
blendingWeight /= dot(blendingWeight, vec2(1.0, 1.0));
|
||||||
|
|
||||||
// Calculate the texture coordinates:
|
// Calculate the texture coordinates:
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
vec2 tc = vec2(texcoord.x, 1.0 - texcoord.y);
|
vec2 tc = vec2(texcoord.x, 1.0 - texcoord.y);
|
||||||
#else
|
#else
|
||||||
vec2 tc = texcoord;
|
vec2 tc = texcoord;
|
||||||
|
|
|
@ -9,7 +9,7 @@ uniform vec2 screenSizeInv;
|
||||||
out vec2 texCoord;
|
out vec2 texCoord;
|
||||||
out vec4 offset;
|
out vec4 offset;
|
||||||
|
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
#define V_DIR(v) -(v)
|
#define V_DIR(v) -(v)
|
||||||
#else
|
#else
|
||||||
#define V_DIR(v) v
|
#define V_DIR(v) v
|
||||||
|
@ -19,7 +19,7 @@ void main() {
|
||||||
// Scale vertex attribute to [0-1] range
|
// Scale vertex attribute to [0-1] range
|
||||||
const vec2 madd = vec2(0.5, 0.5);
|
const vec2 madd = vec2(0.5, 0.5);
|
||||||
texCoord = pos.xy * madd + madd;
|
texCoord = pos.xy * madd + madd;
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
texCoord.y = 1.0 - texCoord.y;
|
texCoord.y = 1.0 - texCoord.y;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ vec2 getProjectedCoord(vec3 hitCoord) {
|
||||||
vec4 projectedCoord = P * vec4(hitCoord, 1.0);
|
vec4 projectedCoord = P * vec4(hitCoord, 1.0);
|
||||||
projectedCoord.xy /= projectedCoord.w;
|
projectedCoord.xy /= projectedCoord.w;
|
||||||
projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;
|
projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
projectedCoord.y = 1.0 - projectedCoord.y;
|
projectedCoord.y = 1.0 - projectedCoord.y;
|
||||||
#endif
|
#endif
|
||||||
return projectedCoord.xy;
|
return projectedCoord.xy;
|
||||||
|
|
|
@ -29,13 +29,13 @@ vec2 getProjectedCoord(const vec3 hit) {
|
||||||
vec4 projectedCoord = P * vec4(hit, 1.0);
|
vec4 projectedCoord = P * vec4(hit, 1.0);
|
||||||
projectedCoord.xy /= projectedCoord.w;
|
projectedCoord.xy /= projectedCoord.w;
|
||||||
projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;
|
projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
projectedCoord.y = 1.0 - projectedCoord.y;
|
projectedCoord.y = 1.0 - projectedCoord.y;
|
||||||
#endif
|
#endif
|
||||||
return projectedCoord.xy;
|
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;
|
depth = textureLod(gbufferD, getProjectedCoord(hit), 0.0).r * 2.0 - 1.0;
|
||||||
vec3 viewPos = getPosView(viewRay, depth, cameraProj);
|
vec3 viewPos = getPosView(viewRay, depth, cameraProj);
|
||||||
return viewPos.z - hit.z;
|
return viewPos.z - hit.z;
|
||||||
|
@ -79,7 +79,7 @@ void main() {
|
||||||
|
|
||||||
float spec = fract(textureLod(gbuffer1, texCoord, 0.0).a);
|
float spec = fract(textureLod(gbuffer1, texCoord, 0.0).a);
|
||||||
if (spec == 0.0) { fragColor.rgb = vec3(0.0); return; }
|
if (spec == 0.0) { fragColor.rgb = vec3(0.0); return; }
|
||||||
|
|
||||||
float d = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
|
float d = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
|
||||||
if (d == 1.0) { fragColor.rgb = vec3(0.0); return; }
|
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.z = 1.0 - abs(enc.x) - abs(enc.y);
|
||||||
n.xy = n.z >= 0.0 ? enc.xy : octahedronWrap(enc.xy);
|
n.xy = n.z >= 0.0 ? enc.xy : octahedronWrap(enc.xy);
|
||||||
n = normalize(n);
|
n = normalize(n);
|
||||||
|
|
||||||
vec3 viewNormal = V3 * n;
|
vec3 viewNormal = V3 * n;
|
||||||
vec3 viewPos = getPosView(viewRay, d, cameraProj);
|
vec3 viewPos = getPosView(viewRay, d, cameraProj);
|
||||||
vec3 reflected = normalize(reflect(viewPos, viewNormal));
|
vec3 reflected = normalize(reflect(viewPos, viewNormal));
|
||||||
hitCoord = viewPos;
|
hitCoord = viewPos;
|
||||||
|
|
||||||
#ifdef _CPostprocess
|
#ifdef _CPostprocess
|
||||||
vec3 dir = reflected * (1.0 - rand(texCoord) * PPComp10.y * roughness) * 2.0;
|
vec3 dir = reflected * (1.0 - rand(texCoord) * PPComp10.y * roughness) * 2.0;
|
||||||
#else
|
#else
|
||||||
vec3 dir = reflected * (1.0 - rand(texCoord) * ssrJitter * roughness) * 2.0;
|
vec3 dir = reflected * (1.0 - rand(texCoord) * ssrJitter * roughness) * 2.0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// * max(ssrMinRayStep, -viewPos.z)
|
// * max(ssrMinRayStep, -viewPos.z)
|
||||||
vec4 coords = rayCast(dir);
|
vec4 coords = rayCast(dir);
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ vec3 getPosView(const vec3 viewRay, const float depth, const vec2 cameraProj) {
|
||||||
return viewRay * linearDepth;
|
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
|
// eyeLook, viewRay should be normalized
|
||||||
float linearDepth = cameraProj.y / ((depth * 0.5 + 0.5) - cameraProj.x);
|
float linearDepth = cameraProj.y / ((depth * 0.5 + 0.5) - cameraProj.x);
|
||||||
float viewZDist = dot(eyeLook, viewRay);
|
float viewZDist = dot(eyeLook, viewRay);
|
||||||
|
@ -27,7 +27,7 @@ vec3 getPos(const vec3 eye, const vec3 eyeLook, const vec3 viewRay, const float
|
||||||
return wposition;
|
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
|
// eyeLook, viewRay should be normalized
|
||||||
float linearDepth = cameraProj.y / ((depth * 0.5 + 0.5) - cameraProj.x);
|
float linearDepth = cameraProj.y / ((depth * 0.5 + 0.5) - cameraProj.x);
|
||||||
float viewZDist = dot(eyeLook, viewRay);
|
float viewZDist = dot(eyeLook, viewRay);
|
||||||
|
@ -35,7 +35,7 @@ vec3 getPosNoEye(const vec3 eyeLook, const vec3 viewRay, const float depth, cons
|
||||||
return wposition;
|
return wposition;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HLSL
|
#if defined(HLSL) || defined(METAL)
|
||||||
vec3 getPos2(const mat4 invVP, const float depth, vec2 coord) {
|
vec3 getPos2(const mat4 invVP, const float depth, vec2 coord) {
|
||||||
coord.y = 1.0 - coord.y;
|
coord.y = 1.0 - coord.y;
|
||||||
#else
|
#else
|
||||||
|
@ -47,7 +47,7 @@ vec3 getPos2(const mat4 invVP, const float depth, const vec2 coord) {
|
||||||
return pos.xyz;
|
return pos.xyz;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HLSL
|
#if defined(HLSL) || defined(METAL)
|
||||||
vec3 getPosView2(const mat4 invP, const float depth, vec2 coord) {
|
vec3 getPosView2(const mat4 invP, const float depth, vec2 coord) {
|
||||||
coord.y = 1.0 - coord.y;
|
coord.y = 1.0 - coord.y;
|
||||||
#else
|
#else
|
||||||
|
@ -59,7 +59,7 @@ vec3 getPosView2(const mat4 invP, const float depth, const vec2 coord) {
|
||||||
return pos.xyz;
|
return pos.xyz;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HLSL
|
#if defined(HLSL) || defined(METAL)
|
||||||
vec3 getPos2NoEye(const vec3 eye, const mat4 invVP, const float depth, vec2 coord) {
|
vec3 getPos2NoEye(const vec3 eye, const mat4 invVP, const float depth, vec2 coord) {
|
||||||
coord.y = 1.0 - coord.y;
|
coord.y = 1.0 - coord.y;
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -35,7 +35,7 @@ float PCFCube(samplerCubeShadow shadowMapCube, const vec3 lp, vec3 ml, const flo
|
||||||
const float s = shadowmapCubePcfSize; // TODO: incorrect...
|
const float s = shadowmapCubePcfSize; // TODO: incorrect...
|
||||||
float compare = lpToDepth(lp, lightProj) - bias * 1.5;
|
float compare = lpToDepth(lp, lightProj) - bias * 1.5;
|
||||||
ml = ml + n * bias * 20;
|
ml = ml + n * bias * 20;
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
ml.y = -ml.y;
|
ml.y = -ml.y;
|
||||||
#endif
|
#endif
|
||||||
float result = texture(shadowMapCube, vec4(ml, compare));
|
float result = texture(shadowMapCube, vec4(ml, compare));
|
||||||
|
@ -105,7 +105,7 @@ float shadowTestCascade(sampler2DShadow shadowMap, const vec3 eye, const vec3 p,
|
||||||
int casi;
|
int casi;
|
||||||
int casIndex;
|
int casIndex;
|
||||||
mat4 LWVP = getCascadeMat(d, casi, casIndex);
|
mat4 LWVP = getCascadeMat(d, casi, casIndex);
|
||||||
|
|
||||||
vec4 lPos = LWVP * vec4(p, 1.0);
|
vec4 lPos = LWVP * vec4(p, 1.0);
|
||||||
lPos.xyz /= lPos.w;
|
lPos.xyz /= lPos.w;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ vec2 getProjectedCoord(vec3 hitCoord) {
|
||||||
vec4 projectedCoord = VP * vec4(hitCoord, 1.0);
|
vec4 projectedCoord = VP * vec4(hitCoord, 1.0);
|
||||||
projectedCoord.xy /= projectedCoord.w;
|
projectedCoord.xy /= projectedCoord.w;
|
||||||
projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;
|
projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;
|
||||||
#ifdef HLSL
|
#if defined(HLSL) || defined(METAL)
|
||||||
projectedCoord.y = 1.0 - projectedCoord.y;
|
projectedCoord.y = 1.0 - projectedCoord.y;
|
||||||
#endif
|
#endif
|
||||||
return projectedCoord.xy;
|
return projectedCoord.xy;
|
||||||
|
|
|
@ -15,12 +15,12 @@ const float SMAA_REPROJECTION_WEIGHT_SCALE = 30.0;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 current = textureLod(tex, texCoord, 0.0);
|
vec4 current = textureLod(tex, texCoord, 0.0);
|
||||||
|
|
||||||
#ifdef _Veloc
|
#ifdef _Veloc
|
||||||
// Velocity is assumed to be calculated for motion blur, so we need to inverse it for reprojection
|
// 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;
|
vec2 velocity = -textureLod(sveloc, texCoord, 0.0).rg;
|
||||||
|
|
||||||
#ifdef HLSL
|
#ifdef _InvY
|
||||||
velocity.y = -velocity.y;
|
velocity.y = -velocity.y;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,15 @@ class RenderPathDeferred {
|
||||||
|
|
||||||
path = _path;
|
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")
|
#if (rp_background == "World")
|
||||||
{
|
{
|
||||||
path.loadShader("shader_datas/world_pass/world_pass");
|
path.loadShader("shader_datas/world_pass/world_pass");
|
||||||
|
|
|
@ -64,8 +64,10 @@ class RenderPathForward {
|
||||||
|
|
||||||
#if kha_metal
|
#if kha_metal
|
||||||
{
|
{
|
||||||
path.loadShader("shader_datas/clear_pass/clear_pass");
|
path.loadShader("shader_datas/clear_color_depth_pass/clear_color_depth_pass");
|
||||||
path.clearShader = "shader_datas/clear_pass/clear_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
|
#end
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,9 @@ def build():
|
||||||
assets.add_khafile_def('rp_shadowmap_cube={0}'.format(rpdat.rp_shadowmap_cube))
|
assets.add_khafile_def('rp_shadowmap_cube={0}'.format(rpdat.rp_shadowmap_cube))
|
||||||
|
|
||||||
if arm.utils.get_gapi() == 'metal':
|
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))
|
assets.add_khafile_def('rp_background={0}'.format(rpdat.rp_background))
|
||||||
if rpdat.rp_background == 'World':
|
if rpdat.rp_background == 'World':
|
||||||
|
|
|
@ -30,7 +30,7 @@ def make(context_id):
|
||||||
vert.write('wnormal = N * vec3(0.0, 0.0, 1.0);')
|
vert.write('wnormal = N * vec3(0.0, 0.0, 1.0);')
|
||||||
vert.write('wvpposition = WVP * vec4(pos.xyz, 1.0);')
|
vert.write('wvpposition = WVP * vec4(pos.xyz, 1.0);')
|
||||||
vert.write('gl_Position = wvpposition;')
|
vert.write('gl_Position = wvpposition;')
|
||||||
|
|
||||||
frag.add_include('compiled.inc')
|
frag.add_include('compiled.inc')
|
||||||
frag.add_include('std/gbuffer.glsl')
|
frag.add_include('std/gbuffer.glsl')
|
||||||
frag.ins = vert.outs
|
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 screenPosition = wvpposition.xy / wvpposition.w;')
|
||||||
frag.write_attrib(' vec2 depthCoord = screenPosition * 0.5 + 0.5;')
|
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(' depthCoord.y = 1.0 - depthCoord.y;')
|
||||||
frag.write_attrib('#endif')
|
frag.write_attrib('#endif')
|
||||||
frag.write_attrib(' float depth = texture(gbufferD, depthCoord).r * 2.0 - 1.0;')
|
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(' vec3 wpos = getPos2(invVP, depth, depthCoord);')
|
||||||
frag.write_attrib(' vec4 mpos = invW * vec4(wpos, 1.0);')
|
frag.write_attrib(' vec4 mpos = invW * vec4(wpos, 1.0);')
|
||||||
frag.write_attrib(' if (abs(mpos.x) > 1.0) discard;')
|
frag.write_attrib(' if (abs(mpos.x) > 1.0) discard;')
|
||||||
|
|
|
@ -413,7 +413,7 @@ def make_forward_mobile(con_mesh):
|
||||||
frag.add_uniform('samplerCubeShadow shadowMapPoint[1]')
|
frag.add_uniform('samplerCubeShadow shadowMapPoint[1]')
|
||||||
frag.write('const float s = shadowmapCubePcfSize;') # TODO: incorrect...
|
frag.write('const float s = shadowmapCubePcfSize;') # TODO: incorrect...
|
||||||
frag.write('float compare = lpToDepth(ld, lightProj) - pointBias * 1.5;')
|
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('l.y = -l.y;')
|
||||||
frag.write('#endif')
|
frag.write('#endif')
|
||||||
if '_Legacy' in wrd.world_defs:
|
if '_Legacy' in wrd.world_defs:
|
||||||
|
|
Loading…
Reference in a new issue