fix: raw false color
This commit is contained in:
1 parent
e1efd648d3
commit
2cca2bd3a7
3 files changed
+61
-50
No files matched your search
@@ -76,6 +76,7 @@ object QuadBayerShaders {
|
||||
uniform int uCfaPattern;
|
||||
uniform vec4 uBlackLevel;
|
||||
uniform float uWhiteLevel;
|
||||
// Calculation-only relative WB gains; WRITE_OUTPUT removes them again.
|
||||
uniform vec4 uWhiteBalanceGains;
|
||||
uniform float uHighlightClipThreshold;
|
||||
uniform float uHighlightCeiling;
|
||||
@@ -123,22 +124,15 @@ object QuadBayerShaders {
|
||||
return max(float(rawVal) - bl, 0.0) / max(wl - bl, 1.0);
|
||||
}
|
||||
|
||||
float cameraSampleAt(ivec2 coord, int channelIndex) {
|
||||
float calculationSampleAt(ivec2 coord, int channelIndex) {
|
||||
ivec2 sampleCoord = clampCoord(coord, uImageSize);
|
||||
float sensor = readSensorNormalized(sampleCoord, channelIndex);
|
||||
float linear = sensor * getLensShadingGain(sampleCoord);
|
||||
float linear = sensor * getLensShadingGain(sampleCoord) *
|
||||
max(uWhiteBalanceGains[channelIndex], 1e-6);
|
||||
return min(max(linear, 0.0), uHighlightCeiling);
|
||||
}
|
||||
|
||||
float reconstructionWbGain(int channelIndex) {
|
||||
return max(uWhiteBalanceGains[channelIndex], 1e-6);
|
||||
}
|
||||
|
||||
float balancedSampleAt(ivec2 coord, int channelIndex) {
|
||||
return cameraSampleAt(coord, channelIndex) * reconstructionWbGain(channelIndex);
|
||||
}
|
||||
|
||||
float estimateOpposedCameraLinear(ivec2 coord, int color, int targetChannelIndex, float fallback) {
|
||||
float estimateOpposedLinear(ivec2 coord, int color, float fallback) {
|
||||
float sumRed = 0.0;
|
||||
float sumGreen = 0.0;
|
||||
float sumBlue = 0.0;
|
||||
@@ -154,7 +148,7 @@ object QuadBayerShaders {
|
||||
ivec2 sampleCoord = clampCoord(coord + ivec2(dx, dy), uImageSize);
|
||||
int sampleChannel = getQuadChannelIndex(uCfaPattern, sampleCoord.x, sampleCoord.y);
|
||||
int sampleColor = colorFromChannelIndex(sampleChannel);
|
||||
float balanced = balancedSampleAt(sampleCoord, sampleChannel);
|
||||
float balanced = calculationSampleAt(sampleCoord, sampleChannel);
|
||||
|
||||
if (sampleColor == RED) {
|
||||
sumRed += balanced;
|
||||
@@ -183,8 +177,7 @@ object QuadBayerShaders {
|
||||
opposedRoot = 0.5 * (rootRed + rootGreen);
|
||||
}
|
||||
|
||||
float reconstructed = pow(max(opposedRoot, 0.0), power) /
|
||||
reconstructionWbGain(targetChannelIndex);
|
||||
float reconstructed = pow(max(opposedRoot, 0.0), power);
|
||||
return max(reconstructed, fallback);
|
||||
}
|
||||
|
||||
@@ -198,7 +191,7 @@ object QuadBayerShaders {
|
||||
return min(max(linear, 0.0), uHighlightCeiling);
|
||||
}
|
||||
|
||||
float reconstructed = estimateOpposedCameraLinear(coord, color, channelIndex, linear);
|
||||
float reconstructed = estimateOpposedLinear(coord, color, linear);
|
||||
return min(mix(linear, reconstructed, clipMask), uHighlightCeiling);
|
||||
}
|
||||
|
||||
@@ -210,7 +203,7 @@ object QuadBayerShaders {
|
||||
int channelIndex = getQuadChannelIndex(uCfaPattern, coord.x, coord.y);
|
||||
int color = colorFromChannelIndex(channelIndex);
|
||||
float sensor = readSensorNormalized(coord, channelIndex);
|
||||
float linear = cameraSampleAt(coord, channelIndex);
|
||||
float linear = calculationSampleAt(coord, channelIndex);
|
||||
float val = reconstructHighlightSample(coord, channelIndex, color, sensor, linear);
|
||||
|
||||
cfa[idx] = val;
|
||||
@@ -448,18 +441,19 @@ object QuadBayerShaders {
|
||||
layout (rgba16f, binding = 0) writeonly uniform highp image2D uOutputImage;
|
||||
|
||||
uniform ivec2 uImageSize;
|
||||
uniform vec3 uCalculationGains;
|
||||
|
||||
void main() {
|
||||
ivec2 coord = ivec2(gl_GlobalInvocationID.xy);
|
||||
if (coord.x >= uImageSize.x || coord.y >= uImageSize.y) return;
|
||||
|
||||
int idx = coord.y * uImageSize.x + coord.x;
|
||||
vec4 color = vec4(
|
||||
vec3 cameraRgb = vec3(
|
||||
max(0.0, tmpR[idx]),
|
||||
max(0.0, rgb1[idx]),
|
||||
max(0.0, tmpB[idx]),
|
||||
1.0
|
||||
);
|
||||
max(0.0, tmpB[idx])
|
||||
) / max(uCalculationGains, vec3(1e-6));
|
||||
vec4 color = vec4(cameraRgb, 1.0);
|
||||
imageStore(uOutputImage, coord, color);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
@@ -542,7 +542,7 @@ class RawDemosaicProcessor {
|
||||
)
|
||||
}
|
||||
|
||||
private fun highlightReconstructionWbGains(metadata: RawMetadata): FloatArray {
|
||||
private fun demosaicCalculationWbGains(metadata: RawMetadata): FloatArray {
|
||||
val gains = metadata.whiteBalanceGains
|
||||
fun safeGain(index: Int, fallback: Float): Float {
|
||||
val value = gains.getOrElse(index) { fallback }
|
||||
@@ -569,8 +569,8 @@ class RawDemosaicProcessor {
|
||||
|
||||
return floatArrayOf(
|
||||
normalized(safeGain(0, greenBase)),
|
||||
normalized(greenEven),
|
||||
normalized(greenOdd),
|
||||
1f,
|
||||
1f,
|
||||
normalized(safeGain(3, greenBase))
|
||||
)
|
||||
}
|
||||
@@ -1832,13 +1832,13 @@ class RawDemosaicProcessor {
|
||||
if (rawDomainHighlightReconstructionEnabled) 1 else 0
|
||||
)
|
||||
val metadataWbGains = actualMetadata.whiteBalanceGains
|
||||
val highlightWbGains = highlightReconstructionWbGains(actualMetadata)
|
||||
val calculationWbGains = demosaicCalculationWbGains(actualMetadata)
|
||||
val lscSize = lensShadingLogString(actualMetadata)
|
||||
PLog.d(
|
||||
TAG,
|
||||
"RCD populate: cfa=${actualMetadata.cfaPattern} black=${blackLevel4.contentToString()} " +
|
||||
"white=${actualMetadata.whiteLevel} metadataWb=${metadataWbGains.contentToString()} " +
|
||||
"highlightWb=${highlightWbGains.contentToString()} " +
|
||||
"calculationWb=${calculationWbGains.contentToString()} " +
|
||||
"lsc=$lscSize " +
|
||||
"highlightReconstruction=$rawDomainHighlightReconstructionEnabled " +
|
||||
"highlightThreshold=$RCD_HIGHLIGHT_RECONSTRUCTION_THRESHOLD " +
|
||||
@@ -1850,7 +1850,7 @@ class RawDemosaicProcessor {
|
||||
GLES31.glGetUniformLocation(
|
||||
rcdPopulateProgram,
|
||||
"uWhiteBalanceGains"
|
||||
), 1, highlightWbGains, 0
|
||||
), 1, calculationWbGains, 0
|
||||
)
|
||||
GLES31.glDispatchCompute((actualWidth + 15) / 16, (actualHeight + 15) / 16, 1)
|
||||
GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT)
|
||||
@@ -1979,6 +1979,12 @@ class RawDemosaicProcessor {
|
||||
GLES31.glGetUniformLocation(rcdWriteOutputProgram, "uBorder"),
|
||||
RCD_OUTPUT_MARGIN
|
||||
)
|
||||
GLES31.glUniform3f(
|
||||
GLES31.glGetUniformLocation(rcdWriteOutputProgram, "uCalculationGains"),
|
||||
calculationWbGains[0],
|
||||
1f,
|
||||
calculationWbGains[3]
|
||||
)
|
||||
GLES31.glBindImageTexture(
|
||||
RCD_OUTPUT_IMAGE_UNIT,
|
||||
demosaicTextureId,
|
||||
@@ -4831,7 +4837,7 @@ class RawDemosaicProcessor {
|
||||
}.coerceAtLeast(0f)
|
||||
}
|
||||
val metadataWbGains = metadata.whiteBalanceGains
|
||||
val highlightWbGains = highlightReconstructionWbGains(metadata)
|
||||
val calculationWbGains = demosaicCalculationWbGains(metadata)
|
||||
val lscSize = lensShadingLogString(metadata)
|
||||
|
||||
try {
|
||||
@@ -4862,14 +4868,14 @@ class RawDemosaicProcessor {
|
||||
GLES31.glUniform4fv(
|
||||
GLES31.glGetUniformLocation(rcdPopulateProgram, "uWhiteBalanceGains"),
|
||||
1,
|
||||
highlightWbGains,
|
||||
calculationWbGains,
|
||||
0
|
||||
)
|
||||
PLog.d(
|
||||
TAG,
|
||||
"Linear RCD populate: cfa=${metadata.cfaPattern} black=${blackLevel4.contentToString()} " +
|
||||
"white=${metadata.whiteLevel} metadataWb=${metadataWbGains.contentToString()} " +
|
||||
"highlightWb=${highlightWbGains.contentToString()} lsc=$lscSize"
|
||||
"calculationWb=${calculationWbGains.contentToString()} lsc=$lscSize"
|
||||
)
|
||||
GLES31.glDispatchCompute((width + 15) / 16, (height + 15) / 16, 1)
|
||||
GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT)
|
||||
@@ -4929,6 +4935,12 @@ class RawDemosaicProcessor {
|
||||
GLES31.glUniform2i(GLES31.glGetUniformLocation(rcdWriteOutputProgram, "uImageSize"), width, height)
|
||||
GLES31.glUniform1i(GLES31.glGetUniformLocation(rcdWriteOutputProgram, "uCfaPattern"), metadata.cfaPattern)
|
||||
GLES31.glUniform1i(GLES31.glGetUniformLocation(rcdWriteOutputProgram, "uBorder"), RCD_OUTPUT_MARGIN)
|
||||
GLES31.glUniform3f(
|
||||
GLES31.glGetUniformLocation(rcdWriteOutputProgram, "uCalculationGains"),
|
||||
calculationWbGains[0],
|
||||
1f,
|
||||
calculationWbGains[3]
|
||||
)
|
||||
GLES31.glBindImageTexture(
|
||||
RCD_OUTPUT_IMAGE_UNIT,
|
||||
demosaicTextureId,
|
||||
@@ -4987,7 +4999,7 @@ class RawDemosaicProcessor {
|
||||
}.coerceAtLeast(0f)
|
||||
}
|
||||
val metadataWbGains = metadata.whiteBalanceGains
|
||||
val highlightWbGains = highlightReconstructionWbGains(metadata)
|
||||
val calculationWbGains = demosaicCalculationWbGains(metadata)
|
||||
val lscSize = lensShadingLogString(metadata)
|
||||
val expandedBlockSize = RawCfaCorrection.expandedBayerBlockSize(metadata.cfaPattern)
|
||||
|
||||
@@ -5033,7 +5045,7 @@ class RawDemosaicProcessor {
|
||||
GLES31.glUniform4fv(
|
||||
GLES31.glGetUniformLocation(quadPopulateProgram, "uWhiteBalanceGains"),
|
||||
1,
|
||||
highlightWbGains,
|
||||
calculationWbGains,
|
||||
0
|
||||
)
|
||||
PLog.d(
|
||||
@@ -5041,7 +5053,7 @@ class RawDemosaicProcessor {
|
||||
"Expanded Bayer populate: cfa=${metadata.cfaPattern} block=${expandedBlockSize}x$expandedBlockSize " +
|
||||
"black=${blackLevel4.contentToString()} " +
|
||||
"white=${metadata.whiteLevel} metadataWb=${metadataWbGains.contentToString()} " +
|
||||
"highlightWb=${highlightWbGains.contentToString()} lsc=$lscSize " +
|
||||
"calculationWb=${calculationWbGains.contentToString()} lsc=$lscSize " +
|
||||
"highlightReconstruction=$highlightReconstructionEnabled " +
|
||||
"highlightThreshold=$RCD_HIGHLIGHT_RECONSTRUCTION_THRESHOLD " +
|
||||
"highlightCeiling=$RCD_HIGHLIGHT_RECONSTRUCTION_CEILING"
|
||||
@@ -5086,6 +5098,12 @@ class RawDemosaicProcessor {
|
||||
width,
|
||||
height
|
||||
)
|
||||
GLES31.glUniform3f(
|
||||
GLES31.glGetUniformLocation(quadWriteOutputProgram, "uCalculationGains"),
|
||||
calculationWbGains[0],
|
||||
1f,
|
||||
calculationWbGains[3]
|
||||
)
|
||||
GLES31.glBindImageTexture(
|
||||
RCD_OUTPUT_IMAGE_UNIT,
|
||||
demosaicTextureId,
|
||||
|
||||
@@ -30,7 +30,9 @@ object RcdShaders {
|
||||
uniform int uCfaPattern;
|
||||
uniform vec4 uBlackLevel; // R, Gr, Gb, B 或 [0,1,2,3] 四通道黑电平
|
||||
uniform float uWhiteLevel;
|
||||
uniform vec4 uWhiteBalanceGains; // R, Gr, Gb, B 高光重建用相对白平衡增益,输出仍保持 camera RGB
|
||||
// R, G, G, B relative gains used only to condition RCD calculations.
|
||||
// WRITE_OUTPUT removes them again, so the externally visible result remains camera RGB.
|
||||
uniform vec4 uWhiteBalanceGains;
|
||||
uniform float uHighlightClipThreshold;
|
||||
uniform float uHighlightCeiling;
|
||||
uniform bool uHighlightReconstructionEnabled;
|
||||
@@ -118,23 +120,17 @@ object RcdShaders {
|
||||
return max(float(rawVal) - bl, 0.0) / max(wl - bl, 1.0);
|
||||
}
|
||||
|
||||
float cameraSampleAt(ivec2 coord, int channelIndex) {
|
||||
float calculationSampleAt(ivec2 coord, int channelIndex) {
|
||||
ivec2 sampleCoord = clampCoord(coord);
|
||||
float sensor = readSensorNormalized(sampleCoord, channelIndex);
|
||||
float linear = sensor * getLensShadingGain(channelIndex, sampleCoord);
|
||||
float linear = sensor * getLensShadingGain(channelIndex, sampleCoord) *
|
||||
max(uWhiteBalanceGains[channelIndex], 1e-6);
|
||||
return min(max(linear, 0.0), uHighlightCeiling);
|
||||
}
|
||||
|
||||
float reconstructionWbGain(int channelIndex) {
|
||||
return max(uWhiteBalanceGains[channelIndex], 1e-6);
|
||||
}
|
||||
|
||||
float balancedSampleAt(ivec2 coord, int channelIndex) {
|
||||
return cameraSampleAt(coord, channelIndex) * reconstructionWbGain(channelIndex);
|
||||
}
|
||||
|
||||
// Estimate clipped photosites in a white-balanced domain, then convert back to camera RGB.
|
||||
float estimateOpposedCameraLinear(ivec2 coord, int color, int targetChannelIndex, float fallback) {
|
||||
// Both ordinary interpolation and clipped-site estimation stay in the same
|
||||
// white-balanced calculation domain. Output conversion is deliberately deferred.
|
||||
float estimateOpposedLinear(ivec2 coord, int color, float fallback) {
|
||||
float sumRed = 0.0;
|
||||
float sumGreen = 0.0;
|
||||
float sumBlue = 0.0;
|
||||
@@ -147,7 +143,7 @@ object RcdShaders {
|
||||
ivec2 sampleCoord = clampCoord(coord + ivec2(dx, dy));
|
||||
int sampleColor = getBayerColor(uCfaPattern, sampleCoord.x, sampleCoord.y);
|
||||
int channelIndex = getBlackLevelIndex(uCfaPattern, sampleCoord.x, sampleCoord.y);
|
||||
float balanced = balancedSampleAt(sampleCoord, channelIndex);
|
||||
float balanced = calculationSampleAt(sampleCoord, channelIndex);
|
||||
|
||||
if (sampleColor == RED) {
|
||||
sumRed += balanced;
|
||||
@@ -176,8 +172,7 @@ object RcdShaders {
|
||||
opposedRoot = 0.5 * (rootRed + rootGreen);
|
||||
}
|
||||
|
||||
float reconstructed = pow(max(opposedRoot, 0.0), power) /
|
||||
reconstructionWbGain(targetChannelIndex);
|
||||
float reconstructed = pow(max(opposedRoot, 0.0), power);
|
||||
return max(reconstructed, fallback);
|
||||
}
|
||||
|
||||
@@ -191,7 +186,7 @@ object RcdShaders {
|
||||
return min(max(linear, 0.0), uHighlightCeiling);
|
||||
}
|
||||
|
||||
float reconstructed = estimateOpposedCameraLinear(coord, color, channelIndex, linear);
|
||||
float reconstructed = estimateOpposedLinear(coord, color, linear);
|
||||
return min(mix(linear, reconstructed, clipMask), uHighlightCeiling);
|
||||
}
|
||||
|
||||
@@ -204,7 +199,7 @@ object RcdShaders {
|
||||
int blIdx = getBlackLevelIndex(uCfaPattern, coord.x, coord.y);
|
||||
int color = getBayerColor(uCfaPattern, coord.x, coord.y);
|
||||
float sensor = readSensorNormalized(coord, blIdx);
|
||||
float linear = cameraSampleAt(coord, blIdx);
|
||||
float linear = calculationSampleAt(coord, blIdx);
|
||||
float val = reconstructHighlightSample(coord, blIdx, color, sensor, linear);
|
||||
|
||||
cfa[idx] = val;
|
||||
@@ -732,6 +727,7 @@ object RcdShaders {
|
||||
uniform ivec2 uImageSize;
|
||||
uniform int uCfaPattern;
|
||||
uniform int uBorder;
|
||||
uniform vec3 uCalculationGains;
|
||||
|
||||
#define RED 0
|
||||
#define GREEN 1
|
||||
@@ -953,6 +949,9 @@ object RcdShaders {
|
||||
color = ppgColorAt(coord);
|
||||
}
|
||||
|
||||
// Undo the calculation-only white balance. Downstream color conversion
|
||||
// therefore receives the same camera RGB domain as before this RCD pass.
|
||||
color /= max(uCalculationGains, vec3(1e-6));
|
||||
imageStore(uOutputImage, coord, vec4(color, 1.0));
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
Reference in new issue
Block a user