Metal: GLSL shader compatibility 4th pass
MSL follows C++ standard convention, and such variable declarations within switch statements must have their scope localised within each case. Adding braces in all cases ensures correct behaviour and avoids 'case ... bypass initialization of local variable' compilation error. struct initialisation to follow C++ rules for Metal. Implicit constructors replaced with either explicit constructors or list-initialization where appropriate. Ref T96261 Authored by Apple: Michael Parkin-White Reviewed By: fclem Maniphest Tasks: T96261 Differential Revision: https://developer.blender.org/D14451
This commit is contained in:
@@ -40,6 +40,15 @@ struct OcclusionData {
|
||||
vec4 horizons;
|
||||
/* Custom large scale occlusion. */
|
||||
float custom_occlusion;
|
||||
|
||||
#ifdef GPU_METAL
|
||||
/* Constructors required for OcclusionData(..) syntax. */
|
||||
inline OcclusionData() = default;
|
||||
inline OcclusionData(vec4 in_horizons, float in_custom_occlusion)
|
||||
: horizons(in_horizons), custom_occlusion(in_custom_occlusion)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
vec4 pack_occlusion_data(OcclusionData data)
|
||||
|
||||
@@ -7,7 +7,15 @@ struct ClosureInputDiffuse {
|
||||
vec3 albedo; /** Used for multibounce GTAO approximation. Not applied to final radiance. */
|
||||
};
|
||||
|
||||
#define CLOSURE_INPUT_Diffuse_DEFAULT ClosureInputDiffuse(vec3(0.0), vec3(0.0))
|
||||
#ifdef GPU_METAL
|
||||
/* C++ struct initialization. */
|
||||
# define CLOSURE_INPUT_Diffuse_DEFAULT \
|
||||
{ \
|
||||
vec3(0.0), vec3(0.0) \
|
||||
}
|
||||
#else
|
||||
# define CLOSURE_INPUT_Diffuse_DEFAULT ClosureInputDiffuse(vec3(0.0), vec3(0.0))
|
||||
#endif
|
||||
|
||||
struct ClosureEvalDiffuse {
|
||||
vec3 probe_sampling_dir; /** Direction to sample probes from. */
|
||||
|
||||
@@ -10,7 +10,14 @@ struct ClosureInputGlossy {
|
||||
float roughness; /** Input roughness, not squared. */
|
||||
};
|
||||
|
||||
#define CLOSURE_INPUT_Glossy_DEFAULT ClosureInputGlossy(vec3(0.0), 0.0)
|
||||
#ifdef GPU_METAL
|
||||
# define CLOSURE_INPUT_Glossy_DEFAULT \
|
||||
{ \
|
||||
vec3(0.0), 0.0 \
|
||||
}
|
||||
#else
|
||||
# define CLOSURE_INPUT_Glossy_DEFAULT ClosureInputGlossy(vec3(0.0), 0.0)
|
||||
#endif
|
||||
|
||||
struct ClosureEvalGlossy {
|
||||
vec4 ltc_mat; /** LTC matrix values. */
|
||||
|
||||
@@ -157,7 +157,15 @@
|
||||
#define ClosureInputDummy ClosureOutput
|
||||
#define ClosureOutputDummy ClosureOutput
|
||||
#define ClosureEvalDummy ClosureOutput
|
||||
#define CLOSURE_EVAL_DUMMY ClosureOutput(vec3(0))
|
||||
#ifdef GPU_METAL
|
||||
/* C++ struct initialization. */
|
||||
# define CLOSURE_EVAL_DUMMY \
|
||||
{ \
|
||||
vec3(0) \
|
||||
}
|
||||
#else
|
||||
# define CLOSURE_EVAL_DUMMY ClosureOutput(vec3(0))
|
||||
#endif
|
||||
#define CLOSURE_INPUT_Dummy_DEFAULT CLOSURE_EVAL_DUMMY
|
||||
#define closure_Dummy_eval_init(cl_in, cl_common, cl_out) CLOSURE_EVAL_DUMMY
|
||||
#define closure_Dummy_planar_eval(cl_in, cl_eval, cl_common, data, cl_out)
|
||||
@@ -180,8 +188,15 @@ struct ClosureInputCommon {
|
||||
/** Custom occlusion value set by the user. */
|
||||
float occlusion;
|
||||
};
|
||||
|
||||
#define CLOSURE_INPUT_COMMON_DEFAULT ClosureInputCommon(1.0)
|
||||
#ifdef GPU_METAL
|
||||
/* C++ struct initialization. */
|
||||
# define CLOSURE_INPUT_COMMON_DEFAULT \
|
||||
{ \
|
||||
1.0 \
|
||||
}
|
||||
#else
|
||||
# define CLOSURE_INPUT_COMMON_DEFAULT ClosureInputCommon(1.0)
|
||||
#endif
|
||||
|
||||
struct ClosureEvalCommon {
|
||||
/** Result of SSAO. */
|
||||
|
||||
@@ -10,8 +10,15 @@ struct ClosureInputRefraction {
|
||||
float roughness; /** Input roughness, not squared. */
|
||||
float ior; /** Index of refraction ratio. */
|
||||
};
|
||||
|
||||
#define CLOSURE_INPUT_Refraction_DEFAULT ClosureInputRefraction(vec3(0.0), 0.0, 0.0)
|
||||
#ifdef GPU_METAL
|
||||
/* C++ struct initialization. */
|
||||
# define CLOSURE_INPUT_Refraction_DEFAULT \
|
||||
{ \
|
||||
vec3(0.0), 0.0, 0.0 \
|
||||
}
|
||||
#else
|
||||
# define CLOSURE_INPUT_Refraction_DEFAULT ClosureInputRefraction(vec3(0.0), 0.0, 0.0)
|
||||
#endif
|
||||
|
||||
struct ClosureEvalRefraction {
|
||||
vec3 P; /** LTC matrix values. */
|
||||
|
||||
@@ -7,9 +7,15 @@
|
||||
struct ClosureInputTranslucent {
|
||||
vec3 N; /** Shading normal. */
|
||||
};
|
||||
|
||||
#define CLOSURE_INPUT_Translucent_DEFAULT ClosureInputTranslucent(vec3(0.0))
|
||||
|
||||
#ifdef GPU_METAL
|
||||
/* C++ struct initialization. */
|
||||
# define CLOSURE_INPUT_Translucent_DEFAULT \
|
||||
{ \
|
||||
vec3(0.0) \
|
||||
}
|
||||
#else
|
||||
# define CLOSURE_INPUT_Translucent_DEFAULT ClosureInputTranslucent(vec3(0.0))
|
||||
#endif
|
||||
/* Stubs. */
|
||||
#define ClosureEvalTranslucent ClosureEvalDummy
|
||||
#define ClosureOutputTranslucent ClosureOutput
|
||||
|
||||
@@ -30,6 +30,50 @@ struct Closure {
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Metal Default Constructor - Requred for C++ constructor syntax. */
|
||||
#ifdef GPU_METAL
|
||||
inline Closure() = default;
|
||||
# ifdef VOLUMETRICS
|
||||
/* Explicit Closure constructors -- To support GLSL syntax */
|
||||
inline Closure(vec3 in_absorption, vec3 in_scatter, vec3 in_emission, float in_anisotropy)
|
||||
: absorption(in_absorption),
|
||||
scatter(in_scatter),
|
||||
emission(in_emission),
|
||||
anisotropy(in_anisotropy)
|
||||
{
|
||||
}
|
||||
# else
|
||||
/* Explicit Closure constructors -- To support GLSL syntax */
|
||||
inline Closure(vec3 in_radiance,
|
||||
vec3 in_transmittance,
|
||||
float in_holdout,
|
||||
vec4 in_ssr_data,
|
||||
vec2 in_ssr_normal,
|
||||
int in_flag
|
||||
# ifdef USE_SSS
|
||||
,
|
||||
vec3 in_sss_irradiance,
|
||||
vec3 in_sss_albedo,
|
||||
float in_sss_radius
|
||||
# endif /* USE_SSS */
|
||||
)
|
||||
: radiance(in_radiance),
|
||||
transmittance(in_transmittance),
|
||||
holdout(in_holdout),
|
||||
ssr_data(in_ssr_data),
|
||||
ssr_normal(in_ssr_normal),
|
||||
flag(in_flag)
|
||||
# ifdef USE_SSS
|
||||
,
|
||||
sss_irradiance(in_sss_irradiance),
|
||||
sss_albedo(in_sss_albedo),
|
||||
sss_radius(in_sss_radius)
|
||||
# endif /* USE_SSS */
|
||||
{
|
||||
}
|
||||
# endif /* VOLUMETRICS */
|
||||
#endif /* GPU_METAL */
|
||||
};
|
||||
|
||||
#ifndef GPU_METAL
|
||||
|
||||
@@ -334,7 +334,15 @@ struct DofGatherData {
|
||||
float layer_opacity;
|
||||
};
|
||||
|
||||
#define GATHER_DATA_INIT DofGatherData(vec4(0.0), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
|
||||
#ifdef GPU_METAL
|
||||
/* C++ struct initialization. */
|
||||
# define GATHER_DATA_INIT \
|
||||
{ \
|
||||
vec4(0.0), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 \
|
||||
}
|
||||
#else
|
||||
# define GATHER_DATA_INIT DofGatherData(vec4(0.0), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
|
||||
#endif
|
||||
|
||||
void dof_gather_ammend_weight(inout DofGatherData sample_data, float weight)
|
||||
{
|
||||
|
||||
@@ -116,7 +116,7 @@ void blend_mode_output(
|
||||
color.a *= opacity;
|
||||
frag_revealage = frag_color = clamp(1.0 / max(vec4(1e-6), 1.0 - color * color.a), 0.0, 1e18);
|
||||
break;
|
||||
case MODE_HARDLIGHT:
|
||||
case MODE_HARDLIGHT: {
|
||||
/* Reminder: Blending func is multiply blend (dst.rgba * src.rgba). */
|
||||
/**
|
||||
* We need to separate the overlay equation into 2 term (one mul and one add).
|
||||
@@ -134,6 +134,7 @@ void blend_mode_output(
|
||||
frag_revealage = frag_color = 2.0 * s + 2.0 * color * (1.0 - s * 2.0);
|
||||
frag_revealage = max(vec4(0.0), frag_revealage);
|
||||
break;
|
||||
}
|
||||
case MODE_HARDLIGHT_SECOND_PASS:
|
||||
/* Reminder: Blending func is additive blend (dst.rgba + src.rgba). */
|
||||
color = mix(vec4(0.5), color, color.a * opacity);
|
||||
|
||||
@@ -57,13 +57,13 @@ void main()
|
||||
/* XXX do interpolation in a non-linear space to have a better visual result. */
|
||||
col_high = pow(colorBackground.rgb, vec3(1.0 / 2.2));
|
||||
col_low = pow(colorBackgroundGradient.rgb, vec3(1.0 / 2.2));
|
||||
bg_col = mix(col_low, col_high, uvcoordsvar.t);
|
||||
bg_col = mix(col_low, col_high, uvcoordsvar.y);
|
||||
/* Convert back to linear. */
|
||||
bg_col = pow(bg_col, vec3(2.2));
|
||||
/* Dither to hide low precision buffer. (Could be improved) */
|
||||
bg_col += dither();
|
||||
break;
|
||||
case BG_RADIAL:
|
||||
case BG_RADIAL: {
|
||||
/* Do interpolation in a non-linear space to have a better visual result. */
|
||||
col_high = pow(colorBackground.rgb, vec3(1.0 / 2.2));
|
||||
col_low = pow(colorBackgroundGradient.rgb, vec3(1.0 / 2.2));
|
||||
@@ -76,12 +76,14 @@ void main()
|
||||
/* Dither to hide low precision buffer. (Could be improved) */
|
||||
bg_col += dither();
|
||||
break;
|
||||
case BG_CHECKER:
|
||||
}
|
||||
case BG_CHECKER: {
|
||||
float size = sizeChecker * sizePixel;
|
||||
ivec2 p = ivec2(floor(gl_FragCoord.xy / size));
|
||||
bool check = mod(p.x, 2) == mod(p.y, 2);
|
||||
bg_col = (check) ? colorCheckerPrimary.rgb : colorCheckerSecondary.rgb;
|
||||
break;
|
||||
}
|
||||
case BG_MASK:
|
||||
fragColor = vec4(vec3(1.0 - alpha), 0.0);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user