I play with Metal for iOS, creating a small game. In one of my kernel shaders (in my .metal files). I am defining a structure for storing some metadata for part of the game.
The structure is as follows:
struct ColorSetup {
float4 color;
float4 degradationColor;
float degradationRate;
};
This works fine, but when I try to add more fields to my structure, for example:
struct ColorSetup {
float4 color;
float4 degradationColor;
float4 threshholdColor;
float degradationRate;
};
, , . . , . , , ( 48 64 ), - . , , .
, , , . - . , , .
struct ColorSetup {
packed_float4 color;
packed_float4 degradationColor;
float degradationRate;
};
, , , , .
, ?
Edit:
MTLBuffer, inline .metal :
constant ColorSetup redColor = {
.color = red,
.degradationColor = white,
.degradationRate = 0.0035
};
2:
, .
, , , , .
float4 degrade(float4 color, ColorSetup colorSetup, ColorLimit colorLimit) {
float4 targetColor = colorSetup.degradationColor;
float rate = colorSetup.degradationRate;
if (colorLimit.degradationThreshold.r < color.r && colorLimit.degradationThreshold.g < color.g && colorLimit.degradationThreshold.b < color.b) {
targetColor = colorSetup.degradationColor;
} else {
targetColor = colorSetup.color;
}
int r = (color.r - targetColor.r) < 0 ? 1 : -1;
int g = (color.g - targetColor.g) < 0 ? 1 : -1;
int b = (color.b - targetColor.b) < 0 ? 1 : -1;
float4 newColor = float4(color.r + float(r)*rate, color.g + float(g)*rate, color.b + float(b)*rate, 1);
return normalizeColor(newColor);
}
, , :
struct ColorSetup {
float4 color;
float4 degradationColor;
float degradationRate;
};
( , - . , ).
struct ColorSetup {
float4 color;
float4 degradationColor;
float degradationRate;
float padding;
};
, float .
constant ColorSetup redColor = {
.color = red,
.degradationColor = white,
.degradationRate = 0.0035,
};
:
constant ColorSetup redColor = {
.color = red,
.degradationColor = white,
.degradationRate = 0.0035,
.padding = 0
};
, .
: int, :
struct ColorSetup {
float4 color;
float4 degradationColor;
float degradationRate;
int padding;
};