fix: try fix rawmax highlights
This commit is contained in:
1 parent
a0e071537f
commit
52d86fe1c7
5 files changed
+559
-555
No files matched your search
+255
-72
@@ -1,66 +1,21 @@
|
||||
package com.hinnka.mycamera.processor
|
||||
|
||||
internal data class RawRadianceHighlightAdmissionEvidence(
|
||||
val eligibleTileCount: Int,
|
||||
val supportedTileCount: Int,
|
||||
)
|
||||
|
||||
internal data class RawRadianceHighlightAdmissionRequirements(
|
||||
val minimumEligibleTiles: Int,
|
||||
val minimumEligibleCoverage: Float,
|
||||
)
|
||||
|
||||
internal data class RawRadianceHighlightAdmission(
|
||||
val accepted: Boolean,
|
||||
val eligibleCoverage: Float,
|
||||
)
|
||||
|
||||
/** Selects the temporally ranked anchor that survived normal-frame registration. */
|
||||
internal fun selectRadianceHighlightAnchor(
|
||||
candidateIndices: IntArray,
|
||||
frameCount: Int,
|
||||
acceptedFrameIndices: Set<Int>,
|
||||
): Int? {
|
||||
if (frameCount <= 0 || acceptedFrameIndices.isEmpty()) return null
|
||||
return candidateIndices.firstOrNull { candidate ->
|
||||
candidate in 0 until frameCount && candidate in acceptedFrameIndices
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Admits the ultrashort observation against the area that actually needs highlight recovery.
|
||||
* Whole-frame quadrant coverage is deliberately irrelevant: a valid highlight may occupy one
|
||||
* small corner, while good flow elsewhere says nothing about that highlight.
|
||||
* GPU passes dedicated to the ultrashort highlight observation.
|
||||
*
|
||||
* Direct normal-to-short flow remains the only geometric measurement. Saturated tiles never
|
||||
* become alignment seeds: their flow is inferred once from a mutually observable collar, then a
|
||||
* separate rejection field decides whether the resulting hole may be filled. Rejection may spread
|
||||
* through the saturated core, inferred flow may not.
|
||||
*/
|
||||
internal fun planRadianceHighlightAdmission(
|
||||
evidence: RawRadianceHighlightAdmissionEvidence,
|
||||
requirements: RawRadianceHighlightAdmissionRequirements,
|
||||
): RawRadianceHighlightAdmission {
|
||||
val eligibleTiles = evidence.eligibleTileCount.coerceAtLeast(0)
|
||||
val supportedTiles = evidence.supportedTileCount.coerceIn(0, eligibleTiles)
|
||||
val coverage = if (eligibleTiles > 0) {
|
||||
supportedTiles.toFloat() / eligibleTiles
|
||||
} else {
|
||||
0f
|
||||
}
|
||||
val accepted = eligibleTiles >= requirements.minimumEligibleTiles.coerceAtLeast(1) &&
|
||||
supportedTiles > 0 &&
|
||||
coverage >= requirements.minimumEligibleCoverage.coerceIn(0f, 1f)
|
||||
return RawRadianceHighlightAdmission(
|
||||
accepted = accepted,
|
||||
eligibleCoverage = coverage,
|
||||
)
|
||||
}
|
||||
|
||||
/** GPU passes dedicated to the ultrashort highlight observation. */
|
||||
internal object GlesRadianceHighlightShaders {
|
||||
/**
|
||||
* Builds evidence on the flow grid after reference -> short flow composition.
|
||||
* Builds dense evidence for direct or collar-inferred flow.
|
||||
*
|
||||
* R: fraction of normal samples lacking highlight headroom.
|
||||
* G: fraction of short samples retaining headroom.
|
||||
* G: minimum short-frame headroom validity in the sampled tile.
|
||||
* B: exposure-normalized photometric agreement where both observations are valid.
|
||||
* A: final geometric path confidence.
|
||||
* A: geometric confidence carried by the supplied flow.
|
||||
*/
|
||||
val buildSupport: String = """
|
||||
#version 300 es
|
||||
@@ -93,18 +48,13 @@ internal object GlesRadianceHighlightShaders {
|
||||
|
||||
void main() {
|
||||
ivec2 tile = ivec2(gl_FragCoord.xy);
|
||||
vec2 center = min(
|
||||
vec2(tile * uTileSize + ivec2(uTileSize / 2)),
|
||||
vec2(uPlaneSize - ivec2(1))
|
||||
);
|
||||
vec4 flow = texelFetch(
|
||||
uComposedFlow,
|
||||
clamp(tile, ivec2(0), uGridSize - ivec2(1)),
|
||||
0
|
||||
);
|
||||
int sampleSpacing = max(uTileSize / 4, 1);
|
||||
float normalNeedSum = 0.0;
|
||||
float shortValiditySum = 0.0;
|
||||
float shortValidityMin = 1.0;
|
||||
float photometricSum = 0.0;
|
||||
float photometricWeightSum = 0.0;
|
||||
float sampleCount = 0.0;
|
||||
@@ -113,19 +63,25 @@ internal object GlesRadianceHighlightShaders {
|
||||
uPhotometricSigmaFull * uPhotometricSigmaFull,
|
||||
sigmaStart2 + 1e-4
|
||||
);
|
||||
for (int y = -2; y <= 2; ++y) {
|
||||
for (int x = -2; x <= 2; ++x) {
|
||||
vec2 referencePosition = center +
|
||||
vec2(x * sampleSpacing, y * sampleSpacing);
|
||||
const int MAX_TILE_SIZE = 32;
|
||||
for (int y = 0; y < MAX_TILE_SIZE; ++y) {
|
||||
for (int x = 0; x < MAX_TILE_SIZE; ++x) {
|
||||
if (x >= uTileSize || y >= uTileSize) continue;
|
||||
vec2 referencePosition = vec2(
|
||||
tile * uTileSize + ivec2(x, y)
|
||||
);
|
||||
if (!insidePlane(referencePosition)) continue;
|
||||
vec2 shortPosition = referencePosition + flow.rg;
|
||||
bool inside = insidePlane(referencePosition) &&
|
||||
insidePlane(shortPosition);
|
||||
bool shortInside = insidePlane(shortPosition);
|
||||
vec4 referenceSample = proxyAt(uReferenceProxy, referencePosition);
|
||||
vec4 shortSample = proxyAt(uShortProxy, shortPosition);
|
||||
float insideWeight = inside ? 1.0 : 0.0;
|
||||
normalNeedSum += (1.0 - referenceSample.g) * insideWeight;
|
||||
shortValiditySum += shortSample.g * insideWeight;
|
||||
float overlap = referenceSample.g * shortSample.g * insideWeight;
|
||||
normalNeedSum += 1.0 - referenceSample.g;
|
||||
shortValidityMin = min(
|
||||
shortValidityMin,
|
||||
shortInside ? shortSample.g : 0.0
|
||||
);
|
||||
float overlap = referenceSample.g * shortSample.g *
|
||||
(shortInside ? 1.0 : 0.0);
|
||||
float difference = referenceSample.r - shortSample.r;
|
||||
float differenceVariance = max(
|
||||
referenceSample.a + shortSample.a,
|
||||
@@ -139,17 +95,244 @@ internal object GlesRadianceHighlightShaders {
|
||||
);
|
||||
photometricSum += agreement * overlap;
|
||||
photometricWeightSum += overlap;
|
||||
sampleCount += insideWeight;
|
||||
sampleCount += 1.0;
|
||||
}
|
||||
}
|
||||
float denominator = max(sampleCount, 1.0);
|
||||
fragColor = vec4(
|
||||
normalNeedSum / denominator,
|
||||
shortValiditySum / denominator,
|
||||
shortValidityMin,
|
||||
photometricWeightSum > 1e-5 ?
|
||||
photometricSum / photometricWeightSum : 0.0,
|
||||
clamp(flow.a, 0.0, 1.0)
|
||||
);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
/**
|
||||
* Produces a continuous collar-consensus flow without recursive propagation.
|
||||
*
|
||||
* Only direct forward/backward-validated samples outside the saturated core can contribute.
|
||||
* Angular coverage and flow variance make a one-sided or multi-motion collar lose confidence.
|
||||
*/
|
||||
val inferFlowFromCollar: String = """
|
||||
#version 300 es
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
uniform sampler2D uDirectFlow;
|
||||
uniform sampler2D uDirectSupport;
|
||||
uniform ivec2 uGridSize;
|
||||
uniform int uRadiusTiles;
|
||||
uniform float uNeedStart;
|
||||
uniform float uNeedFull;
|
||||
uniform float uDirectConfidenceStart;
|
||||
uniform float uDirectConfidenceFull;
|
||||
uniform float uShortValidityThreshold;
|
||||
uniform float uPhotometricThreshold;
|
||||
uniform float uMinimumSampleWeight;
|
||||
uniform float uFullSampleWeight;
|
||||
uniform float uMinimumSectorWeight;
|
||||
uniform int uMinimumSectors;
|
||||
uniform float uFlowSigmaStart;
|
||||
uniform float uFlowSigmaFull;
|
||||
out vec4 fragColor;
|
||||
|
||||
const int MAX_RADIUS_TILES = 4;
|
||||
|
||||
void main() {
|
||||
ivec2 tile = ivec2(gl_FragCoord.xy);
|
||||
float radius2 = float(max(uRadiusTiles * uRadiusTiles, 1));
|
||||
float sampleWeightSum = 0.0;
|
||||
vec2 weightedFlowSum = vec2(0.0);
|
||||
float weightedFlowNormSum = 0.0;
|
||||
vec4 sectorWeights = vec4(0.0);
|
||||
|
||||
for (int y = -MAX_RADIUS_TILES; y <= MAX_RADIUS_TILES; ++y) {
|
||||
for (int x = -MAX_RADIUS_TILES; x <= MAX_RADIUS_TILES; ++x) {
|
||||
if (x == 0 && y == 0) continue;
|
||||
if (abs(x) > uRadiusTiles || abs(y) > uRadiusTiles) continue;
|
||||
ivec2 sampleTile = tile + ivec2(x, y);
|
||||
if (any(lessThan(sampleTile, ivec2(0))) ||
|
||||
any(greaterThanEqual(sampleTile, uGridSize))) {
|
||||
continue;
|
||||
}
|
||||
vec4 directFlow = texelFetch(uDirectFlow, sampleTile, 0);
|
||||
vec4 support = texelFetch(uDirectSupport, sampleTile, 0);
|
||||
float normalObservable = 1.0 - smoothstep(
|
||||
min(uNeedStart, uNeedFull),
|
||||
max(uNeedStart, uNeedFull),
|
||||
support.r
|
||||
);
|
||||
float flowConfidence = smoothstep(
|
||||
min(uDirectConfidenceStart, uDirectConfidenceFull),
|
||||
max(uDirectConfidenceStart, uDirectConfidenceFull),
|
||||
directFlow.a
|
||||
);
|
||||
float shortValidity = smoothstep(
|
||||
min(uShortValidityThreshold, 0.999),
|
||||
1.0,
|
||||
support.g
|
||||
);
|
||||
float photometricAgreement = smoothstep(
|
||||
min(uPhotometricThreshold, 0.999),
|
||||
1.0,
|
||||
support.b
|
||||
);
|
||||
float spatialWeight = exp(
|
||||
-0.5 * float(x * x + y * y) / radius2
|
||||
);
|
||||
float weight = normalObservable * flowConfidence *
|
||||
shortValidity * photometricAgreement * spatialWeight;
|
||||
sampleWeightSum += weight;
|
||||
weightedFlowSum += directFlow.rg * weight;
|
||||
weightedFlowNormSum += dot(directFlow.rg, directFlow.rg) * weight;
|
||||
|
||||
if (abs(x) >= abs(y)) {
|
||||
if (x < 0) sectorWeights.x += weight;
|
||||
else sectorWeights.y += weight;
|
||||
} else {
|
||||
if (y < 0) sectorWeights.z += weight;
|
||||
else sectorWeights.w += weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vec2 consensusFlow = weightedFlowSum / max(sampleWeightSum, 1e-6);
|
||||
float flowVariance = max(
|
||||
weightedFlowNormSum / max(sampleWeightSum, 1e-6) -
|
||||
dot(consensusFlow, consensusFlow),
|
||||
0.0
|
||||
);
|
||||
float flowSigma = sqrt(flowVariance);
|
||||
float sectorCount =
|
||||
step(uMinimumSectorWeight, sectorWeights.x) +
|
||||
step(uMinimumSectorWeight, sectorWeights.y) +
|
||||
step(uMinimumSectorWeight, sectorWeights.z) +
|
||||
step(uMinimumSectorWeight, sectorWeights.w);
|
||||
float sampleConfidence = smoothstep(
|
||||
min(uMinimumSampleWeight, uFullSampleWeight),
|
||||
max(uMinimumSampleWeight, uFullSampleWeight),
|
||||
sampleWeightSum
|
||||
);
|
||||
float sectorConfidence = step(
|
||||
float(max(uMinimumSectors, 1)) - 0.5,
|
||||
sectorCount
|
||||
);
|
||||
float consistencyConfidence = 1.0 - smoothstep(
|
||||
min(uFlowSigmaStart, uFlowSigmaFull),
|
||||
max(uFlowSigmaStart, uFlowSigmaFull),
|
||||
flowSigma
|
||||
);
|
||||
bool canBeEnclosed =
|
||||
tile.x >= uRadiusTiles && tile.y >= uRadiusTiles &&
|
||||
tile.x < uGridSize.x - uRadiusTiles &&
|
||||
tile.y < uGridSize.y - uRadiusTiles;
|
||||
float confidence = sampleConfidence * sectorConfidence *
|
||||
consistencyConfidence * (canBeEnclosed ? 1.0 : 0.0);
|
||||
fragColor = vec4(
|
||||
consensusFlow,
|
||||
flowSigma,
|
||||
clamp(confidence, 0.0, 1.0)
|
||||
);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
/**
|
||||
* Seeds rejection inside a saturated core whenever its collar model or mapped short-frame
|
||||
* headroom is not trustworthy. G stores the core mask so later passes cannot cross it.
|
||||
*/
|
||||
val buildHoleRejectionSeed: String = """
|
||||
#version 300 es
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
uniform sampler2D uInferredFlow;
|
||||
uniform sampler2D uCandidateSupport;
|
||||
uniform float uNeedThreshold;
|
||||
uniform float uAcceptanceConfidence;
|
||||
uniform float uShortValidityThreshold;
|
||||
out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
ivec2 tile = ivec2(gl_FragCoord.xy);
|
||||
vec4 inferredFlow = texelFetch(uInferredFlow, tile, 0);
|
||||
vec4 support = texelFetch(uCandidateSupport, tile, 0);
|
||||
float core = step(uNeedThreshold, support.r);
|
||||
float localAccepted =
|
||||
step(uAcceptanceConfidence, inferredFlow.a) *
|
||||
step(uShortValidityThreshold, support.g);
|
||||
float rejection = core * (1.0 - localAccepted);
|
||||
fragColor = vec4(rejection, core, 0.0, 1.0);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
/**
|
||||
* Spreads only rejection through the connected saturated core. This prevents a locally valid
|
||||
* outer ring from surrounding a deeper unsupported center without ever promoting inferred
|
||||
* flow into a new geometric seed.
|
||||
*/
|
||||
val propagateHoleRejection: String = """
|
||||
#version 300 es
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
uniform sampler2D uInputRejection;
|
||||
uniform ivec2 uGridSize;
|
||||
out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
ivec2 tile = ivec2(gl_FragCoord.xy);
|
||||
vec4 center = texelFetch(uInputRejection, tile, 0);
|
||||
if (center.g < 0.5) {
|
||||
fragColor = center;
|
||||
return;
|
||||
}
|
||||
float rejection = center.r;
|
||||
for (int y = -1; y <= 1; ++y) {
|
||||
for (int x = -1; x <= 1; ++x) {
|
||||
ivec2 neighborTile = tile + ivec2(x, y);
|
||||
if (any(lessThan(neighborTile, ivec2(0))) ||
|
||||
any(greaterThanEqual(neighborTile, uGridSize))) {
|
||||
continue;
|
||||
}
|
||||
vec4 neighbor = texelFetch(uInputRejection, neighborTile, 0);
|
||||
rejection = max(
|
||||
rejection,
|
||||
neighbor.r * step(0.5, neighbor.g)
|
||||
);
|
||||
}
|
||||
}
|
||||
fragColor = vec4(rejection, center.g, 0.0, 1.0);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
/**
|
||||
* Converts the continuous collar model and propagated region decision into a binary geometric
|
||||
* gate. Accepted cores are one all the way to their center; rejected cores are zero.
|
||||
*/
|
||||
val applyHoleDecision: String = """
|
||||
#version 300 es
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
uniform sampler2D uInferredFlow;
|
||||
uniform sampler2D uCandidateSupport;
|
||||
uniform sampler2D uRejection;
|
||||
uniform float uNeedThreshold;
|
||||
uniform float uAcceptanceConfidence;
|
||||
uniform float uShortValidityThreshold;
|
||||
out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
ivec2 tile = ivec2(gl_FragCoord.xy);
|
||||
vec4 inferredFlow = texelFetch(uInferredFlow, tile, 0);
|
||||
vec4 support = texelFetch(uCandidateSupport, tile, 0);
|
||||
vec4 rejection = texelFetch(uRejection, tile, 0);
|
||||
float core = step(uNeedThreshold, support.r);
|
||||
float accepted = core *
|
||||
step(uAcceptanceConfidence, inferredFlow.a) *
|
||||
step(uShortValidityThreshold, support.g) *
|
||||
(1.0 - step(0.5, rejection.r));
|
||||
// Premultiplication prevents rejected neighbors from corrupting bilinear flow at the
|
||||
// accepted boundary. The normalize shader divides RG by the interpolated gate.
|
||||
fragColor = vec4(inferredFlow.rgb * accepted, accepted);
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
@@ -107,8 +107,6 @@ internal object RawRadianceExposurePlanner {
|
||||
|
||||
internal data class RawRadianceHighlightFrame(
|
||||
val shortFrame: RawStackFrame,
|
||||
val anchorFrameIndex: Int,
|
||||
val anchorCandidateIndices: IntArray,
|
||||
val exposureRatio: Float,
|
||||
val baselineExposureEv: Float,
|
||||
)
|
||||
@@ -227,11 +225,12 @@ internal fun planRadianceLongAdmission(
|
||||
* Unified same-exposure RAW fusion.
|
||||
*
|
||||
* One optional one-third-exposure frame is identified and reserved for sparse highlight recovery.
|
||||
* It is aligned through the nearest accepted normal anchor, admitted only where clipped normal
|
||||
* observations have locally supported short-frame geometry, and composed using RAW clipping,
|
||||
* noise, and photometric evidence. Tagged long exposures are also isolated and planned against
|
||||
* the nearest accepted normal anchor. They enter Radiance RGB through an exposure-normalized,
|
||||
* noise-weighted auxiliary path and may not participate in the normal Radiance frame cluster.
|
||||
* The normal multi-frame output reference remains the only geometric and noise reference. Direct
|
||||
* normal-to-short flow is measured only outside clipping, then each connected clipped region is
|
||||
* either admitted in full from its observable collar or rejected in full. Tagged long exposures
|
||||
* are also isolated and planned against the nearest accepted normal anchor. They enter Radiance
|
||||
* RGB through an exposure-normalized, noise-weighted auxiliary path and may not participate in the
|
||||
* normal Radiance frame cluster.
|
||||
*
|
||||
* The reconstruction algorithm is independent of output scale: every accepted RAW frame
|
||||
* contributes a wide-kernel denoise estimate and a narrow-kernel detail estimate in the
|
||||
@@ -287,7 +286,6 @@ class GlesRawRadianceFusion(
|
||||
}
|
||||
val highlightFrame = shortFrame?.let { short ->
|
||||
createHighlightFrame(
|
||||
normalFrames = fusionFrames,
|
||||
shortFrame = short,
|
||||
baseExposureProduct = exposurePlan.baseExposureProduct,
|
||||
)
|
||||
@@ -299,8 +297,8 @@ class GlesRawRadianceFusion(
|
||||
"exposure=${highlightFrame.shortFrame.exposureProduct} " +
|
||||
"base=${exposurePlan.baseExposureProduct} " +
|
||||
"ratio=${highlightFrame.exposureRatio} " +
|
||||
"anchor=${highlightFrame.anchorFrameIndex} " +
|
||||
"normalFrames=${exposurePlan.normalIndices.size}; normal fusion excluded",
|
||||
"normalFrames=${exposurePlan.normalIndices.size}; " +
|
||||
"normal reference retained and short excluded from normal fusion",
|
||||
)
|
||||
} else if (shortFrame != null) {
|
||||
PLog.w(
|
||||
@@ -386,11 +384,9 @@ class GlesRawRadianceFusion(
|
||||
}
|
||||
|
||||
private fun createHighlightFrame(
|
||||
normalFrames: List<RawStackFrame>,
|
||||
shortFrame: RawStackFrame,
|
||||
baseExposureProduct: Double?,
|
||||
): RawRadianceHighlightFrame? {
|
||||
if (normalFrames.isEmpty()) return null
|
||||
val normalExposure = baseExposureProduct
|
||||
?.takeIf { it.isFinite() && it > 0.0 }
|
||||
?: return null
|
||||
@@ -403,19 +399,8 @@ class GlesRawRadianceFusion(
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val anchorCandidates = normalFrames.indices.sortedWith(
|
||||
compareBy<Int> { index ->
|
||||
timestampDistance(
|
||||
normalFrames[index].sensorTimestampNs,
|
||||
shortFrame.sensorTimestampNs,
|
||||
)
|
||||
}.thenBy { it },
|
||||
)
|
||||
val anchorIndex = anchorCandidates.firstOrNull() ?: return null
|
||||
return RawRadianceHighlightFrame(
|
||||
shortFrame = shortFrame.copy(role = RawBurstFrameRole.HIGHLIGHT_SHORT),
|
||||
anchorFrameIndex = anchorIndex,
|
||||
anchorCandidateIndices = anchorCandidates.toIntArray(),
|
||||
exposureRatio = ratio,
|
||||
baselineExposureEv = (ln(ratio.toDouble()) / ln(2.0)).toFloat(),
|
||||
)
|
||||
@@ -512,27 +497,29 @@ data class RawRadianceFusionTuning(
|
||||
val highlightMaxExposureRatio: Float = 8.0f,
|
||||
val highlightNormalClipStart: Float = 0.90f,
|
||||
val highlightNormalClipFull: Float = 0.985f,
|
||||
val highlightShortClipStart: Float = 0.94f,
|
||||
val highlightShortClipFull: Float = 0.99f,
|
||||
val highlightFlowFbConsistencyStartPx: Float = 0.75f,
|
||||
val highlightFlowFbConsistencyFullPx: Float = 2.0f,
|
||||
val highlightFlowPropagationPasses: Int = 6,
|
||||
val highlightFlowPropagationDecay: Float = 0.82f,
|
||||
val highlightFlowGuideEdgeSigma: Float = 0.08f,
|
||||
val highlightFlowSeedConfidence: Float = 0.05f,
|
||||
val highlightFlowMinimumConfidence: Float = 0.005f,
|
||||
val highlightFlowFullConfidence: Float = 0.05f,
|
||||
val highlightMinimumEligibleTiles: Int = 1,
|
||||
val highlightMinimumEligibleCoverage: Float = 0.20f,
|
||||
val highlightNeedTileThreshold: Float = 0.05f,
|
||||
val highlightShortValidityTileThreshold: Float = 0.20f,
|
||||
val highlightDirectFlowConfidence: Float = 0.05f,
|
||||
val highlightDirectFlowFullConfidence: Float = 0.35f,
|
||||
val highlightFlowMinimumConfidence: Float = 0.20f,
|
||||
val highlightFlowFullConfidence: Float = 0.75f,
|
||||
val highlightNeedTileStart: Float = 0.05f,
|
||||
val highlightNeedTileThreshold: Float = 0.20f,
|
||||
val highlightShortValidityTileThreshold: Float = 0.75f,
|
||||
val highlightPhotometricSigmaStart: Float = 3.0f,
|
||||
val highlightPhotometricSigmaFull: Float = 8.0f,
|
||||
val highlightCollarPhotometricThreshold: Float = 0.35f,
|
||||
val highlightCollarRadiusTiles: Int = 4,
|
||||
val highlightCollarMinimumWeight: Float = 4.0f,
|
||||
val highlightCollarFullWeight: Float = 10.0f,
|
||||
val highlightCollarMinimumSectorWeight: Float = 0.75f,
|
||||
val highlightCollarMinimumSectors: Int = 3,
|
||||
val highlightCollarFlowSigmaStartPx: Float = 0.20f,
|
||||
val highlightCollarFlowSigmaFullPx: Float = 0.60f,
|
||||
val highlightHoleAcceptanceConfidence: Float = 0.50f,
|
||||
val highlightHoleRejectionPropagationPasses: Int = 8,
|
||||
val highlightClipNoiseSigmaStart: Float = 8.0f,
|
||||
val highlightClipNoiseSigmaFull: Float = 2.0f,
|
||||
val highlightShortSignalSnrStart: Float = 3.0f,
|
||||
val highlightShortSignalSnrFull: Float = 8.0f,
|
||||
val highlightCoreReliabilityMinimum: Float = 0.65f,
|
||||
)
|
||||
|
||||
/** Returns a sensor-linear RGB value that becomes neutral after the capture WB is applied. */
|
||||
@@ -1731,10 +1718,8 @@ internal object GlesRawRadianceFusionShaders {
|
||||
val highlightDeclarations = if (reconstructHighlights) {
|
||||
"""
|
||||
uniform sampler2D uHighlightRgb;
|
||||
uniform highp usampler2D uHighlightRaw;
|
||||
uniform highp usampler2D uReferenceRaw;
|
||||
uniform sampler2D uHighlightFlow;
|
||||
uniform sampler2D uHighlightSupport;
|
||||
uniform ivec2 uHighlightSourceOrigin;
|
||||
uniform ivec2 uHighlightSourceSize;
|
||||
uniform ivec2 uHighlightFlowGridSize;
|
||||
@@ -1747,19 +1732,10 @@ internal object GlesRawRadianceFusionShaders {
|
||||
uniform float uHighlightExposureRatio;
|
||||
uniform float uHighlightNormalClipStart;
|
||||
uniform float uHighlightNormalClipFull;
|
||||
uniform float uHighlightShortClipStart;
|
||||
uniform float uHighlightShortClipFull;
|
||||
uniform float uHighlightFlowMinimumConfidence;
|
||||
uniform float uHighlightFlowFullConfidence;
|
||||
uniform float uHighlightShortNoiseAlpha[4];
|
||||
uniform float uHighlightShortNoiseBeta[4];
|
||||
uniform float uHighlightPhotometricSigmaStart;
|
||||
uniform float uHighlightPhotometricSigmaFull;
|
||||
uniform float uHighlightClipNoiseSigmaStart;
|
||||
uniform float uHighlightClipNoiseSigmaFull;
|
||||
uniform float uHighlightShortSignalSnrStart;
|
||||
uniform float uHighlightShortSignalSnrFull;
|
||||
uniform float uHighlightCoreReliabilityMinimum;
|
||||
""".trimIndent()
|
||||
} else {
|
||||
""
|
||||
@@ -1807,13 +1783,13 @@ internal object GlesRawRadianceFusionShaders {
|
||||
vec4 highlightFlowAt(vec2 planePosition) {
|
||||
vec2 grid = planePosition / float(uHighlightFlowTileSize) - vec2(0.5);
|
||||
vec2 uv = (grid + vec2(0.5)) / vec2(uHighlightFlowGridSize);
|
||||
return texture(uHighlightFlow, clamp(uv, vec2(0.0), vec2(1.0)));
|
||||
}
|
||||
|
||||
vec4 highlightSupportAt(vec2 planePosition) {
|
||||
vec2 grid = planePosition / float(uHighlightFlowTileSize) - vec2(0.5);
|
||||
vec2 uv = (grid + vec2(0.5)) / vec2(uHighlightFlowGridSize);
|
||||
return texture(uHighlightSupport, clamp(uv, vec2(0.0), vec2(1.0)));
|
||||
vec4 premultipliedFlow = texture(
|
||||
uHighlightFlow,
|
||||
clamp(uv, vec2(0.0), vec2(1.0))
|
||||
);
|
||||
premultipliedFlow.rg = premultipliedFlow.a > 1e-5 ?
|
||||
premultipliedFlow.rg / premultipliedFlow.a : vec2(0.0);
|
||||
return premultipliedFlow;
|
||||
}
|
||||
|
||||
vec3 highlightRgbAt(vec2 localRawPosition) {
|
||||
@@ -1824,19 +1800,6 @@ internal object GlesRawRadianceFusionShaders {
|
||||
return clamp(texture(uHighlightRgb, uv).rgb, 0.0, 1.0);
|
||||
}
|
||||
|
||||
float highlightRawNormAt(ivec2 localPosition) {
|
||||
localPosition = clamp(
|
||||
localPosition,
|
||||
ivec2(0),
|
||||
uHighlightSourceSize - ivec2(1)
|
||||
);
|
||||
ivec2 globalPosition = localPosition + uHighlightSourceOrigin;
|
||||
int bayerIndex = highlightBayerIndexAt(globalPosition);
|
||||
float raw = float(texelFetch(uHighlightRaw, localPosition, 0).r);
|
||||
float range = max(uWhiteLevel - uBlackLevel[bayerIndex], 1.0);
|
||||
return clamp((raw - uBlackLevel[bayerIndex]) / range, 0.0, 1.0);
|
||||
}
|
||||
|
||||
float referenceRawNormAt(ivec2 globalPosition) {
|
||||
globalPosition = clamp(globalPosition, ivec2(0), uInputSize - ivec2(1));
|
||||
int bayerIndex = highlightBayerIndexAt(globalPosition);
|
||||
@@ -1863,38 +1826,6 @@ internal object GlesRawRadianceFusionShaders {
|
||||
sampleCount[channel] += 1.0;
|
||||
}
|
||||
|
||||
HighlightRawStats highlightRawStatsAt(vec2 localRawPosition) {
|
||||
ivec2 globalCenter = ivec2(round(localRawPosition)) + uHighlightSourceOrigin;
|
||||
int period = 2 * highlightCfaBlockSize();
|
||||
ivec2 globalBlock = (globalCenter / period) * period;
|
||||
vec3 signalSum = vec3(0.0);
|
||||
vec3 peak = vec3(0.0);
|
||||
vec3 sampleCount = vec3(0.0);
|
||||
for (int y = 0; y < 8; ++y) {
|
||||
for (int x = 0; x < 8; ++x) {
|
||||
if (x >= period || y >= period) continue;
|
||||
ivec2 globalPosition = clamp(
|
||||
globalBlock + ivec2(x, y),
|
||||
uHighlightSourceOrigin,
|
||||
uHighlightSourceOrigin + uHighlightSourceSize - ivec2(1)
|
||||
);
|
||||
ivec2 localPosition = globalPosition - uHighlightSourceOrigin;
|
||||
int bayerIndex = highlightBayerIndexAt(globalPosition);
|
||||
addHighlightRawSample(
|
||||
bayerIndex,
|
||||
highlightRawNormAt(localPosition),
|
||||
signalSum,
|
||||
peak,
|
||||
sampleCount
|
||||
);
|
||||
}
|
||||
}
|
||||
return HighlightRawStats(
|
||||
signalSum / max(sampleCount, vec3(1.0)),
|
||||
peak
|
||||
);
|
||||
}
|
||||
|
||||
HighlightRawStats referenceRawStatsAt(vec2 globalRawPosition) {
|
||||
ivec2 globalCenter = ivec2(round(globalRawPosition));
|
||||
int period = 2 * highlightCfaBlockSize();
|
||||
@@ -1940,24 +1871,6 @@ internal object GlesRawRadianceFusionShaders {
|
||||
);
|
||||
}
|
||||
|
||||
vec3 shortHighlightNoiseVariance(vec3 signal) {
|
||||
return max(
|
||||
vec3(
|
||||
uHighlightShortNoiseAlpha[0] * signal.r +
|
||||
uHighlightShortNoiseBeta[0],
|
||||
0.5 * (
|
||||
uHighlightShortNoiseAlpha[1] * signal.g +
|
||||
uHighlightShortNoiseBeta[1] +
|
||||
uHighlightShortNoiseAlpha[2] * signal.g +
|
||||
uHighlightShortNoiseBeta[2]
|
||||
),
|
||||
uHighlightShortNoiseAlpha[3] * signal.b +
|
||||
uHighlightShortNoiseBeta[3]
|
||||
),
|
||||
vec3(1e-10)
|
||||
);
|
||||
}
|
||||
|
||||
vec3 noiseAwareClipProbability(
|
||||
vec3 peak,
|
||||
vec3 noiseSigma,
|
||||
@@ -2001,102 +1914,41 @@ internal object GlesRawRadianceFusionShaders {
|
||||
highlightLocalPosition.x <= float(uHighlightSourceSize.x - 1) &&
|
||||
highlightLocalPosition.y <= float(uHighlightSourceSize.y - 1) ? 1.0 : 0.0;
|
||||
vec3 highlightRgb = highlightRgbAt(highlightLocalPosition);
|
||||
vec4 localSupport = highlightSupportAt(referenceRawPosition * 0.5);
|
||||
HighlightRawStats shortRaw = highlightRawStatsAt(highlightLocalPosition);
|
||||
HighlightRawStats normalRaw = referenceRawStatsAt(referenceRawPosition);
|
||||
vec3 normalVariance = referenceHighlightNoiseVariance(normalRaw.signal);
|
||||
vec3 shortVariance = shortHighlightNoiseVariance(shortRaw.signal);
|
||||
vec3 calculationGainVarianceScale = uCalculationGains * uCalculationGains;
|
||||
normalVariance *= calculationGainVarianceScale;
|
||||
shortVariance *= calculationGainVarianceScale;
|
||||
vec3 normalClipProbability = noiseAwareClipProbability(
|
||||
normalRaw.peak,
|
||||
sqrt(normalVariance),
|
||||
min(uHighlightNormalClipStart, uHighlightNormalClipFull),
|
||||
max(uHighlightNormalClipStart, uHighlightNormalClipFull)
|
||||
);
|
||||
vec3 shortClipProbability = noiseAwareClipProbability(
|
||||
shortRaw.peak,
|
||||
sqrt(shortVariance),
|
||||
min(uHighlightShortClipStart, uHighlightShortClipFull),
|
||||
max(uHighlightShortClipStart, uHighlightShortClipFull)
|
||||
);
|
||||
float normalClipped = max(
|
||||
max(normalClipProbability.r, normalClipProbability.g),
|
||||
// Full-RGB short reconstruction is permitted only after every normal channel has
|
||||
// lost radiometric information. A single clipped channel must not replace the other
|
||||
// high-SNR normal channels with a geometrically displaced RGB triplet.
|
||||
float normalClipped = min(
|
||||
min(normalClipProbability.r, normalClipProbability.g),
|
||||
normalClipProbability.b
|
||||
);
|
||||
float shortHasHeadroom = min(
|
||||
min(1.0 - shortClipProbability.r, 1.0 - shortClipProbability.g),
|
||||
1.0 - shortClipProbability.b
|
||||
);
|
||||
const vec3 highlightLumaWeights = vec3(0.2126, 0.7152, 0.0722);
|
||||
float shortLuma = dot(shortRaw.signal, highlightLumaWeights);
|
||||
float shortLumaVariance = dot(
|
||||
shortVariance,
|
||||
highlightLumaWeights * highlightLumaWeights
|
||||
);
|
||||
float shortSnr = shortLuma / sqrt(max(shortLumaVariance, 1e-10));
|
||||
float shortHasSignal = smoothstep(
|
||||
min(uHighlightShortSignalSnrStart, uHighlightShortSignalSnrFull),
|
||||
max(uHighlightShortSignalSnrStart, uHighlightShortSignalSnrFull),
|
||||
shortSnr
|
||||
);
|
||||
float highlightFlowConfidence = smoothstep(
|
||||
uHighlightFlowMinimumConfidence,
|
||||
max(
|
||||
uHighlightFlowMinimumConfidence + 1e-4,
|
||||
uHighlightFlowFullConfidence
|
||||
),
|
||||
min(highlightFlow.a, localSupport.a)
|
||||
highlightFlow.a
|
||||
);
|
||||
float coarseShortValidity = smoothstep(0.05, 0.50, localSupport.g);
|
||||
float shortReliability = clamp(
|
||||
shortHasHeadroom * shortHasSignal * coarseShortValidity *
|
||||
highlightFlowConfidence * highlightInside,
|
||||
float highlightWeight = clamp(
|
||||
normalClipped * highlightFlowConfidence * highlightInside,
|
||||
0.0,
|
||||
1.0
|
||||
);
|
||||
vec3 normalInShortDomain = rgb / max(uHighlightExposureRatio, 1.0);
|
||||
vec3 radiometricDifference = normalInShortDomain - highlightRgb;
|
||||
vec3 radiometricVariance = normalVariance /
|
||||
max(uHighlightExposureRatio * uHighlightExposureRatio, 1.0) + shortVariance;
|
||||
float normalizedPhotometricResidual = dot(
|
||||
radiometricDifference * radiometricDifference /
|
||||
max(radiometricVariance, vec3(1e-8)),
|
||||
highlightLumaWeights
|
||||
);
|
||||
float photometricStart2 = uHighlightPhotometricSigmaStart *
|
||||
uHighlightPhotometricSigmaStart;
|
||||
float photometricFull2 = max(
|
||||
uHighlightPhotometricSigmaFull * uHighlightPhotometricSigmaFull,
|
||||
photometricStart2 + 1e-4
|
||||
);
|
||||
float pixelPhotometricConfidence = 1.0 - smoothstep(
|
||||
photometricStart2,
|
||||
photometricFull2,
|
||||
normalizedPhotometricResidual
|
||||
);
|
||||
float photometricConfidence = sqrt(clamp(
|
||||
pixelPhotometricConfidence * localSupport.b,
|
||||
0.0,
|
||||
1.0
|
||||
));
|
||||
// A confirmed RAW-clipped normal sample contains no radiance information. In that
|
||||
// core region choose one source: a sufficiently reliable short sample replaces it
|
||||
// completely; otherwise retain the normal fallback. Never average the two, because
|
||||
// the clipped normal value biases recovered highlights toward dirty gray.
|
||||
float saturatedCore = step(0.90, normalClipped);
|
||||
float coreShortSelection = saturatedCore * step(
|
||||
uHighlightCoreReliabilityMinimum,
|
||||
shortReliability
|
||||
);
|
||||
// The soft shoulder lies below confirmed sensor clipping, where the normal sample is
|
||||
// still physically meaningful. Require both pixel and block photometric agreement so
|
||||
// motion and occlusion cannot borrow detail merely because a flow vector exists.
|
||||
float shoulderNeed = smoothstep(0.01, 0.25, localSupport.r);
|
||||
float shoulderBlend = (1.0 - saturatedCore) * normalClipped * shoulderNeed *
|
||||
shortReliability * photometricConfidence;
|
||||
float highlightWeight = max(coreShortSelection, shoulderBlend);
|
||||
// The GPU hole decision has already tested short headroom conservatively for every
|
||||
// admitted tile. Its binary core gate is bilinearly sampled here, while the normal
|
||||
// clipping probability owns the pixel-level transition. No short-frame sample enters
|
||||
// a normal channel that still carries radiometric information.
|
||||
rgb = clamp(mix(normalInShortDomain, highlightRgb, highlightWeight), 0.0, 1.0);
|
||||
$highlightDebugOverlay
|
||||
""".trimIndent()
|
||||
|
||||
@@ -66,15 +66,11 @@ internal class GlesRawRadianceStacker(
|
||||
)
|
||||
private data class RadianceHighlightAlignment(
|
||||
val frame: RawRadianceHighlightFrame,
|
||||
val anchorFrameIndex: Int,
|
||||
val flowTexture: Int,
|
||||
val supportTexture: Int,
|
||||
val minFlowXPlanePx: Float,
|
||||
val maxFlowXPlanePx: Float,
|
||||
val minFlowYPlanePx: Float,
|
||||
val maxFlowYPlanePx: Float,
|
||||
val validTileFraction: Float,
|
||||
val coveredQuadrants: Int,
|
||||
) {
|
||||
fun flowBounds(): RadianceFlowBounds = RadianceFlowBounds(
|
||||
minXPlanePx = minFlowXPlanePx,
|
||||
@@ -346,6 +342,10 @@ internal class GlesRawRadianceStacker(
|
||||
private var radianceHighlightPropagateFlowProgram = 0
|
||||
private var radianceHighlightComposeFlowProgram = 0
|
||||
private var radianceHighlightSupportProgram = 0
|
||||
private var radianceHighlightInferFlowProgram = 0
|
||||
private var radianceHighlightRejectionSeedProgram = 0
|
||||
private var radianceHighlightRejectionPropagateProgram = 0
|
||||
private var radianceHighlightApplyHoleDecisionProgram = 0
|
||||
private var radianceLongEligibilityProgram = 0
|
||||
private var radianceLongObservabilityDiagnosticProgram = 0
|
||||
private var radianceReferenceBaseProgram = 0
|
||||
@@ -737,8 +737,6 @@ internal class GlesRawRadianceStacker(
|
||||
val highlightAlignment = activeRadianceHighlightFrame?.let { highlight ->
|
||||
prepareRadianceHighlightAlignment(
|
||||
highlight = highlight,
|
||||
frames = frames,
|
||||
acceptedFrames = acceptedSuperResolutionFrames,
|
||||
referencePyramid = refPyramid,
|
||||
currentPyramid = curPyramid,
|
||||
)
|
||||
@@ -1008,6 +1006,26 @@ internal class GlesRawRadianceStacker(
|
||||
GlesRadianceHighlightShaders.buildSupport,
|
||||
"raw_radiance_highlight_support",
|
||||
)
|
||||
radianceHighlightInferFlowProgram = linkGraphicsProgram(
|
||||
FULLSCREEN_VERTEX_SHADER,
|
||||
GlesRadianceHighlightShaders.inferFlowFromCollar,
|
||||
"raw_radiance_highlight_infer_flow",
|
||||
)
|
||||
radianceHighlightRejectionSeedProgram = linkGraphicsProgram(
|
||||
FULLSCREEN_VERTEX_SHADER,
|
||||
GlesRadianceHighlightShaders.buildHoleRejectionSeed,
|
||||
"raw_radiance_highlight_rejection_seed",
|
||||
)
|
||||
radianceHighlightRejectionPropagateProgram = linkGraphicsProgram(
|
||||
FULLSCREEN_VERTEX_SHADER,
|
||||
GlesRadianceHighlightShaders.propagateHoleRejection,
|
||||
"raw_radiance_highlight_rejection_propagate",
|
||||
)
|
||||
radianceHighlightApplyHoleDecisionProgram = linkGraphicsProgram(
|
||||
FULLSCREEN_VERTEX_SHADER,
|
||||
GlesRadianceHighlightShaders.applyHoleDecision,
|
||||
"raw_radiance_highlight_apply_hole_decision",
|
||||
)
|
||||
}
|
||||
}
|
||||
if (needsLongPrograms) {
|
||||
@@ -2654,45 +2672,14 @@ internal class GlesRawRadianceStacker(
|
||||
|
||||
private fun prepareRadianceHighlightAlignment(
|
||||
highlight: RawRadianceHighlightFrame,
|
||||
frames: List<RawStackFrame>,
|
||||
acceptedFrames: List<AcceptedSuperResolutionFrame>,
|
||||
referencePyramid: List<TextureLevel>,
|
||||
currentPyramid: List<TextureLevel>,
|
||||
): RadianceHighlightAlignment? {
|
||||
val acceptedAnchorIndices = buildSet {
|
||||
add(0)
|
||||
acceptedFrames.forEach { frame -> add(frame.frameIndex) }
|
||||
}
|
||||
val anchorFrameIndex = selectRadianceHighlightAnchor(
|
||||
candidateIndices = highlight.anchorCandidateIndices,
|
||||
frameCount = frames.size,
|
||||
acceptedFrameIndices = acceptedAnchorIndices,
|
||||
) ?: run {
|
||||
PLog.w(
|
||||
TAG,
|
||||
"Radiance highlight disabled: no accepted normal anchor from candidates=" +
|
||||
highlight.anchorCandidateIndices.joinToString(),
|
||||
)
|
||||
return null
|
||||
}
|
||||
if (anchorFrameIndex != highlight.anchorFrameIndex) {
|
||||
PLog.i(
|
||||
TAG,
|
||||
"Radiance highlight anchor fallback primary=${highlight.anchorFrameIndex} " +
|
||||
"selected=$anchorFrameIndex",
|
||||
)
|
||||
}
|
||||
val anchorIsReference = anchorFrameIndex == 0
|
||||
val anchorAlignment = if (anchorIsReference) {
|
||||
null
|
||||
} else {
|
||||
acceptedFrames.firstOrNull { it.frameIndex == anchorFrameIndex }
|
||||
?: return null
|
||||
}
|
||||
return runCatching {
|
||||
val anchor = frames[anchorFrameIndex]
|
||||
uploadRawTexture(anchor.image, curRaw, "Radiance highlight anchor")
|
||||
buildProxy(curRaw, refProxy, "Radiance highlight anchor")
|
||||
// Keep the normal multi-frame output reference as the only geometry reference. A
|
||||
// normal-anchor chain would compose two flow fields that are both unobservable inside
|
||||
// clipping. Region planning below uses only direct normal-reference/short collar flow.
|
||||
buildProxy(refRaw, refProxy, "Radiance highlight normal reference")
|
||||
buildPyramid(referencePyramid)
|
||||
|
||||
uploadRawTexture(highlight.shortFrame.image, curRaw, "Radiance highlight short")
|
||||
@@ -2714,7 +2701,7 @@ internal class GlesRawRadianceStacker(
|
||||
outputGridHeight = gridHeight,
|
||||
outputTileSpacing = flowGridSpacing,
|
||||
preAlignment = null,
|
||||
label = "Radiance highlight anchor-to-short",
|
||||
label = "Radiance highlight normal-reference-to-short",
|
||||
)
|
||||
refineFlow(
|
||||
referenceProxyTexture = refProxy,
|
||||
@@ -2733,7 +2720,7 @@ internal class GlesRawRadianceStacker(
|
||||
outputGridHeight = gridHeight,
|
||||
outputTileSpacing = flowGridSpacing,
|
||||
preAlignment = null,
|
||||
label = "Radiance highlight short-to-anchor",
|
||||
label = "Radiance highlight short-to-normal-reference",
|
||||
)
|
||||
refineFlow(
|
||||
referenceProxyTexture = curProxy,
|
||||
@@ -2743,48 +2730,24 @@ internal class GlesRawRadianceStacker(
|
||||
)
|
||||
smoothFlow(radianceHighlightReverseFlowTexture, flowScratchTexture)
|
||||
validateRadianceHighlightFlow()
|
||||
propagateRadianceHighlightFlow(
|
||||
targetTexture = flowTexture,
|
||||
guideProxyTexture = refProxy,
|
||||
label = "anchor-to-short",
|
||||
passes = radianceFusionTuning.highlightFlowPropagationPasses,
|
||||
confidenceDecay = radianceFusionTuning.highlightFlowPropagationDecay,
|
||||
directConfidence = radianceFusionTuning.highlightFlowSeedConfidence,
|
||||
minimumConfidence = radianceFusionTuning.highlightFlowMinimumConfidence,
|
||||
guideEdgeSigma = radianceFusionTuning.highlightFlowGuideEdgeSigma,
|
||||
allowInvalidGuidePropagation = false,
|
||||
)
|
||||
|
||||
if (!anchorIsReference) {
|
||||
copyRgbaTexture(
|
||||
checkNotNull(anchorAlignment).flowTexture,
|
||||
radianceHighlightAnchorFlowTexture,
|
||||
gridWidth,
|
||||
gridHeight,
|
||||
"Radiance highlight anchor flow copy",
|
||||
)
|
||||
buildProxy(refRaw, refProxy, "Radiance highlight reference guide")
|
||||
propagateRadianceHighlightFlow(
|
||||
targetTexture = radianceHighlightAnchorFlowTexture,
|
||||
guideProxyTexture = refProxy,
|
||||
label = "reference-to-anchor",
|
||||
passes = radianceFusionTuning.highlightFlowPropagationPasses,
|
||||
confidenceDecay = radianceFusionTuning.highlightFlowPropagationDecay,
|
||||
directConfidence = radianceFusionTuning.highlightFlowSeedConfidence,
|
||||
minimumConfidence = radianceFusionTuning.highlightFlowMinimumConfidence,
|
||||
guideEdgeSigma = radianceFusionTuning.highlightFlowGuideEdgeSigma,
|
||||
allowInvalidGuidePropagation = false,
|
||||
)
|
||||
}
|
||||
composeRadianceHighlightFlow(anchorIsReference)
|
||||
// The validated flow and support below form the only direct geometric evidence.
|
||||
// Saturated tiles are deliberately excluded as collar seeds.
|
||||
buildRadianceHighlightSupport(
|
||||
referenceProxyTexture = refProxy,
|
||||
shortProxyTexture = curProxy,
|
||||
flowFieldTexture = flowTexture,
|
||||
)
|
||||
summarizeRadianceHighlightAlignment(
|
||||
highlight = highlight,
|
||||
anchorFrameIndex = anchorFrameIndex,
|
||||
inferRadianceHighlightFlowFromCollar()
|
||||
buildRadianceHighlightSupport(
|
||||
referenceProxyTexture = refProxy,
|
||||
shortProxyTexture = curProxy,
|
||||
flowFieldTexture = radianceHighlightComposedFlowTexture,
|
||||
)
|
||||
buildRadianceHighlightHoleRejectionSeed()
|
||||
propagateRadianceHighlightHoleRejection()
|
||||
applyRadianceHighlightHoleDecision()
|
||||
summarizeRadianceHighlightAlignment(highlight)
|
||||
}.onFailure { error ->
|
||||
PLog.w(TAG, "Radiance highlight alignment failed; preserving normal fusion", error)
|
||||
}.getOrNull()
|
||||
@@ -3861,6 +3824,7 @@ internal class GlesRawRadianceStacker(
|
||||
private fun buildRadianceHighlightSupport(
|
||||
referenceProxyTexture: Int,
|
||||
shortProxyTexture: Int,
|
||||
flowFieldTexture: Int,
|
||||
) {
|
||||
val program = radianceHighlightSupportProgram
|
||||
check(program != 0)
|
||||
@@ -3872,7 +3836,7 @@ internal class GlesRawRadianceStacker(
|
||||
GLES30.glUseProgram(program)
|
||||
bindTexture(program, "uReferenceProxy", 0, referenceProxyTexture)
|
||||
bindTexture(program, "uShortProxy", 1, shortProxyTexture)
|
||||
bindTexture(program, "uComposedFlow", 2, radianceHighlightComposedFlowTexture)
|
||||
bindTexture(program, "uComposedFlow", 2, flowFieldTexture)
|
||||
GLES31.glUniform2i(uniformLocation(program, "uGridSize"), gridWidth, gridHeight)
|
||||
GLES31.glUniform2i(uniformLocation(program, "uPlaneSize"), planeWidth, planeHeight)
|
||||
GLES31.glUniform1i(uniformLocation(program, "uTileSize"), flowGridSpacing)
|
||||
@@ -3890,101 +3854,219 @@ internal class GlesRawRadianceStacker(
|
||||
finishFramebufferPass("Radiance highlight local support")
|
||||
}
|
||||
|
||||
private fun inferRadianceHighlightFlowFromCollar() {
|
||||
val program = radianceHighlightInferFlowProgram
|
||||
check(program != 0)
|
||||
bindFramebufferOutput(
|
||||
radianceHighlightComposedFlowTexture,
|
||||
"Radiance highlight collar flow inference",
|
||||
)
|
||||
GLES30.glViewport(0, 0, gridWidth, gridHeight)
|
||||
GLES30.glUseProgram(program)
|
||||
bindTexture(program, "uDirectFlow", 0, flowTexture)
|
||||
bindTexture(program, "uDirectSupport", 1, radianceHighlightSupportTexture)
|
||||
GLES31.glUniform2i(uniformLocation(program, "uGridSize"), gridWidth, gridHeight)
|
||||
GLES31.glUniform1i(
|
||||
uniformLocation(program, "uRadiusTiles"),
|
||||
radianceFusionTuning.highlightCollarRadiusTiles.coerceIn(1, 4),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uNeedStart"),
|
||||
radianceFusionTuning.highlightNeedTileStart.coerceIn(0f, 1f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uNeedFull"),
|
||||
radianceFusionTuning.highlightNeedTileThreshold.coerceIn(0f, 1f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uDirectConfidenceStart"),
|
||||
radianceFusionTuning.highlightDirectFlowConfidence.coerceIn(0f, 1f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uDirectConfidenceFull"),
|
||||
radianceFusionTuning.highlightDirectFlowFullConfidence.coerceIn(0f, 1f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uShortValidityThreshold"),
|
||||
radianceFusionTuning.highlightShortValidityTileThreshold.coerceIn(0f, 0.999f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uPhotometricThreshold"),
|
||||
radianceFusionTuning.highlightCollarPhotometricThreshold.coerceIn(0f, 0.999f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uMinimumSampleWeight"),
|
||||
radianceFusionTuning.highlightCollarMinimumWeight.coerceAtLeast(0f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uFullSampleWeight"),
|
||||
radianceFusionTuning.highlightCollarFullWeight.coerceAtLeast(
|
||||
radianceFusionTuning.highlightCollarMinimumWeight + 1e-3f,
|
||||
),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uMinimumSectorWeight"),
|
||||
radianceFusionTuning.highlightCollarMinimumSectorWeight.coerceAtLeast(0f),
|
||||
)
|
||||
GLES31.glUniform1i(
|
||||
uniformLocation(program, "uMinimumSectors"),
|
||||
radianceFusionTuning.highlightCollarMinimumSectors.coerceIn(1, 4),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uFlowSigmaStart"),
|
||||
radianceFusionTuning.highlightCollarFlowSigmaStartPx.coerceAtLeast(0f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uFlowSigmaFull"),
|
||||
radianceFusionTuning.highlightCollarFlowSigmaFullPx.coerceAtLeast(
|
||||
radianceFusionTuning.highlightCollarFlowSigmaStartPx + 1e-3f,
|
||||
),
|
||||
)
|
||||
GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3)
|
||||
finishFramebufferPass("Radiance highlight collar flow inference")
|
||||
}
|
||||
|
||||
private fun buildRadianceHighlightHoleRejectionSeed() {
|
||||
val program = radianceHighlightRejectionSeedProgram
|
||||
check(program != 0)
|
||||
bindFramebufferOutput(
|
||||
radianceHighlightAnchorFlowTexture,
|
||||
"Radiance highlight hole rejection seed",
|
||||
)
|
||||
GLES30.glViewport(0, 0, gridWidth, gridHeight)
|
||||
GLES30.glUseProgram(program)
|
||||
bindTexture(program, "uInferredFlow", 0, radianceHighlightComposedFlowTexture)
|
||||
bindTexture(program, "uCandidateSupport", 1, radianceHighlightSupportTexture)
|
||||
setRadianceHighlightHoleDecisionUniforms(program)
|
||||
GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3)
|
||||
finishFramebufferPass("Radiance highlight hole rejection seed")
|
||||
}
|
||||
|
||||
private fun propagateRadianceHighlightHoleRejection() {
|
||||
val program = radianceHighlightRejectionPropagateProgram
|
||||
check(program != 0)
|
||||
val passes = radianceFusionTuning.highlightHoleRejectionPropagationPasses
|
||||
.coerceIn(0, 16)
|
||||
repeat(passes) { pass ->
|
||||
val input = if ((pass and 1) == 0) {
|
||||
radianceHighlightAnchorFlowTexture
|
||||
} else {
|
||||
flowScratchTexture
|
||||
}
|
||||
val output = if ((pass and 1) == 0) {
|
||||
flowScratchTexture
|
||||
} else {
|
||||
radianceHighlightAnchorFlowTexture
|
||||
}
|
||||
bindFramebufferOutput(
|
||||
output,
|
||||
"Radiance highlight hole rejection propagation $pass",
|
||||
)
|
||||
GLES30.glViewport(0, 0, gridWidth, gridHeight)
|
||||
GLES30.glUseProgram(program)
|
||||
bindTexture(program, "uInputRejection", 0, input)
|
||||
GLES31.glUniform2i(uniformLocation(program, "uGridSize"), gridWidth, gridHeight)
|
||||
GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3)
|
||||
finishFramebufferPass("Radiance highlight hole rejection propagation $pass")
|
||||
}
|
||||
if ((passes and 1) != 0) {
|
||||
copyRgbaTexture(
|
||||
flowScratchTexture,
|
||||
radianceHighlightAnchorFlowTexture,
|
||||
gridWidth,
|
||||
gridHeight,
|
||||
"Radiance highlight propagated rejection copy",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun applyRadianceHighlightHoleDecision() {
|
||||
val program = radianceHighlightApplyHoleDecisionProgram
|
||||
check(program != 0)
|
||||
bindFramebufferOutput(flowTexture, "Radiance highlight apply hole decision")
|
||||
GLES30.glViewport(0, 0, gridWidth, gridHeight)
|
||||
GLES30.glUseProgram(program)
|
||||
bindTexture(program, "uInferredFlow", 0, radianceHighlightComposedFlowTexture)
|
||||
bindTexture(program, "uCandidateSupport", 1, radianceHighlightSupportTexture)
|
||||
bindTexture(program, "uRejection", 2, radianceHighlightAnchorFlowTexture)
|
||||
setRadianceHighlightHoleDecisionUniforms(program)
|
||||
GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3)
|
||||
finishFramebufferPass("Radiance highlight apply hole decision")
|
||||
}
|
||||
|
||||
private fun setRadianceHighlightHoleDecisionUniforms(program: Int) {
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uNeedThreshold"),
|
||||
radianceFusionTuning.highlightNeedTileThreshold.coerceIn(0f, 1f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uAcceptanceConfidence"),
|
||||
radianceFusionTuning.highlightHoleAcceptanceConfidence.coerceIn(0f, 1f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uShortValidityThreshold"),
|
||||
radianceFusionTuning.highlightShortValidityTileThreshold.coerceIn(0f, 1f),
|
||||
)
|
||||
}
|
||||
|
||||
private fun summarizeRadianceHighlightAlignment(
|
||||
highlight: RawRadianceHighlightFrame,
|
||||
anchorFrameIndex: Int,
|
||||
): RadianceHighlightAlignment? {
|
||||
val (flowValues, supportValues) = readFlowTextures(
|
||||
textures = listOf(
|
||||
radianceHighlightComposedFlowTexture,
|
||||
radianceHighlightSupportTexture,
|
||||
),
|
||||
// This is the only highlight GPU -> CPU transfer. It reads the low-resolution final gate
|
||||
// solely to bound later tiled demosaic work; no per-region fitting or classification is
|
||||
// performed on the CPU.
|
||||
val flowValues = readFlowTextures(
|
||||
textures = listOf(flowTexture),
|
||||
textureWidth = gridWidth,
|
||||
textureHeight = gridHeight,
|
||||
label = "Radiance highlight flow and support",
|
||||
)
|
||||
val confidenceThreshold = radianceFusionTuning.highlightFlowMinimumConfidence
|
||||
.coerceIn(0f, 1f)
|
||||
val needThreshold = radianceFusionTuning.highlightNeedTileThreshold.coerceIn(0f, 1f)
|
||||
val shortValidityThreshold = radianceFusionTuning.highlightShortValidityTileThreshold
|
||||
.coerceIn(0f, 1f)
|
||||
var eligibleTiles = 0
|
||||
var supportedTiles = 0
|
||||
label = "Radiance highlight final flow bounds",
|
||||
).single()
|
||||
var minX = 0f
|
||||
var maxX = 0f
|
||||
var minY = 0f
|
||||
var maxY = 0f
|
||||
val quadrants = BooleanArray(4)
|
||||
var acceptedTileCount = 0
|
||||
var offset = 0
|
||||
while (offset + 3 < flowValues.size && offset + 3 < supportValues.size) {
|
||||
val tileIndex = offset / 4
|
||||
while (offset + 3 < flowValues.size) {
|
||||
val flowX = flowValues[offset]
|
||||
val flowY = flowValues[offset + 1]
|
||||
val flowConfidence = minOf(flowValues[offset + 3], supportValues[offset + 3])
|
||||
val normalNeed = supportValues[offset]
|
||||
val shortValidity = supportValues[offset + 1]
|
||||
val eligible = normalNeed.isFinite() && shortValidity.isFinite() &&
|
||||
normalNeed >= needThreshold && shortValidity >= shortValidityThreshold
|
||||
if (eligible) eligibleTiles++
|
||||
if (eligible && flowX.isFinite() && flowY.isFinite() && flowConfidence.isFinite() &&
|
||||
flowConfidence >= confidenceThreshold
|
||||
val confidence = flowValues[offset + 3]
|
||||
if (flowX.isFinite() && flowY.isFinite() && confidence.isFinite() &&
|
||||
confidence >= 0.5f
|
||||
) {
|
||||
acceptedTileCount++
|
||||
minX = minOf(minX, flowX)
|
||||
maxX = maxOf(maxX, flowX)
|
||||
minY = minOf(minY, flowY)
|
||||
maxY = maxOf(maxY, flowY)
|
||||
supportedTiles++
|
||||
val tileX = tileIndex % gridWidth
|
||||
val tileY = tileIndex / gridWidth
|
||||
val quadrant = (if (tileY >= gridHeight / 2) 2 else 0) +
|
||||
if (tileX >= gridWidth / 2) 1 else 0
|
||||
quadrants[quadrant] = true
|
||||
}
|
||||
offset += 4
|
||||
}
|
||||
val totalTiles = (gridWidth * gridHeight).coerceAtLeast(1)
|
||||
val validFraction = supportedTiles.toFloat() / totalTiles
|
||||
val coveredQuadrants = quadrants.count { it }
|
||||
val admission = planRadianceHighlightAdmission(
|
||||
evidence = RawRadianceHighlightAdmissionEvidence(
|
||||
eligibleTileCount = eligibleTiles,
|
||||
supportedTileCount = supportedTiles,
|
||||
),
|
||||
requirements = RawRadianceHighlightAdmissionRequirements(
|
||||
minimumEligibleTiles = radianceFusionTuning.highlightMinimumEligibleTiles,
|
||||
minimumEligibleCoverage =
|
||||
radianceFusionTuning.highlightMinimumEligibleCoverage,
|
||||
),
|
||||
)
|
||||
if (!admission.accepted) {
|
||||
if (acceptedTileCount == 0) {
|
||||
PLog.w(
|
||||
TAG,
|
||||
"Radiance highlight alignment rejected eligible=$eligibleTiles/$totalTiles " +
|
||||
"supported=$supportedTiles coverage=${admission.eligibleCoverage} " +
|
||||
"needThreshold=$needThreshold shortThreshold=$shortValidityThreshold " +
|
||||
"anchor=$anchorFrameIndex",
|
||||
"Radiance highlight disabled: no saturated hole passed collar enclosure, " +
|
||||
"flow consistency, and short-headroom gates",
|
||||
)
|
||||
return null
|
||||
}
|
||||
val totalTiles = (gridWidth * gridHeight).coerceAtLeast(1)
|
||||
val admittedTileFraction = acceptedTileCount.toFloat() / totalTiles
|
||||
PLog.i(
|
||||
TAG,
|
||||
"Radiance highlight alignment accepted eligible=$eligibleTiles/$totalTiles " +
|
||||
"supported=$supportedTiles coverage=${admission.eligibleCoverage} " +
|
||||
"quadrants=$coveredQuadrants anchor=$anchorFrameIndex " +
|
||||
"Radiance highlight GPU hole decision admittedTiles=" +
|
||||
"$acceptedTileCount/$totalTiles admittedTileFraction=$admittedTileFraction " +
|
||||
"normalReference=true shortAsReference=false cpuRegionPlanning=false " +
|
||||
"flow=[$minX,$maxX]x[$minY,$maxY] " +
|
||||
"ratio=${highlight.exposureRatio} baseline=${highlight.baselineExposureEv}EV",
|
||||
)
|
||||
return RadianceHighlightAlignment(
|
||||
frame = highlight,
|
||||
anchorFrameIndex = anchorFrameIndex,
|
||||
flowTexture = radianceHighlightComposedFlowTexture,
|
||||
supportTexture = radianceHighlightSupportTexture,
|
||||
flowTexture = flowTexture,
|
||||
minFlowXPlanePx = minX,
|
||||
maxFlowXPlanePx = maxX,
|
||||
minFlowYPlanePx = minY,
|
||||
maxFlowYPlanePx = maxY,
|
||||
validTileFraction = validFraction,
|
||||
coveredQuadrants = coveredQuadrants,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6546,10 +6628,8 @@ internal class GlesRawRadianceStacker(
|
||||
}
|
||||
if (highlightAlignment != null && highlightSourceRegion != null) {
|
||||
bindTexture(program, "uHighlightRgb", 8, radianceRgbTileTexture)
|
||||
bindTexture(program, "uHighlightRaw", 9, rcdRawRegionTexture)
|
||||
bindTexture(program, "uHighlightFlow", 10, highlightAlignment.flowTexture)
|
||||
bindTexture(program, "uReferenceRaw", 11, refRaw)
|
||||
bindTexture(program, "uHighlightSupport", 13, highlightAlignment.supportTexture)
|
||||
GLES31.glUniform2i(
|
||||
uniformLocation(program, "uHighlightSourceOrigin"),
|
||||
highlightSourceRegion.left,
|
||||
@@ -6574,7 +6654,6 @@ internal class GlesRawRadianceStacker(
|
||||
setRadianceHighlightUniforms(
|
||||
program = program,
|
||||
exposureRatio = highlightAlignment.frame.exposureRatio,
|
||||
shortNoiseModel = frameNoiseModel(highlightAlignment.frame.shortFrame),
|
||||
)
|
||||
}
|
||||
setRadianceNormalizeUniforms(program)
|
||||
@@ -6618,7 +6697,6 @@ internal class GlesRawRadianceStacker(
|
||||
private fun setRadianceHighlightUniforms(
|
||||
program: Int,
|
||||
exposureRatio: Float,
|
||||
shortNoiseModel: RawNoiseModel,
|
||||
) {
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uHighlightExposureRatio"),
|
||||
@@ -6632,14 +6710,6 @@ internal class GlesRawRadianceStacker(
|
||||
uniformLocation(program, "uHighlightNormalClipFull"),
|
||||
radianceFusionTuning.highlightNormalClipFull.coerceIn(0f, 1f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uHighlightShortClipStart"),
|
||||
radianceFusionTuning.highlightShortClipStart.coerceIn(0f, 1f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uHighlightShortClipFull"),
|
||||
radianceFusionTuning.highlightShortClipFull.coerceIn(0f, 1f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uHighlightFlowMinimumConfidence"),
|
||||
radianceFusionTuning.highlightFlowMinimumConfidence.coerceIn(0f, 1f),
|
||||
@@ -6651,28 +6721,6 @@ internal class GlesRawRadianceStacker(
|
||||
1f,
|
||||
),
|
||||
)
|
||||
GLES31.glUniform1fv(
|
||||
uniformLocation(program, "uHighlightShortNoiseAlpha[0]"),
|
||||
4,
|
||||
shortNoiseModel.normalizedShotNoiseForShader(cfaPattern),
|
||||
0,
|
||||
)
|
||||
GLES31.glUniform1fv(
|
||||
uniformLocation(program, "uHighlightShortNoiseBeta[0]"),
|
||||
4,
|
||||
shortNoiseModel.normalizedReadNoiseForShader(cfaPattern),
|
||||
0,
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uHighlightPhotometricSigmaStart"),
|
||||
radianceFusionTuning.highlightPhotometricSigmaStart.coerceAtLeast(0f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uHighlightPhotometricSigmaFull"),
|
||||
radianceFusionTuning.highlightPhotometricSigmaFull.coerceAtLeast(
|
||||
radianceFusionTuning.highlightPhotometricSigmaStart + 1e-3f,
|
||||
),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uHighlightClipNoiseSigmaStart"),
|
||||
radianceFusionTuning.highlightClipNoiseSigmaStart.coerceAtLeast(0f),
|
||||
@@ -6684,20 +6732,6 @@ internal class GlesRawRadianceStacker(
|
||||
radianceFusionTuning.highlightClipNoiseSigmaStart.coerceAtLeast(0f),
|
||||
),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uHighlightShortSignalSnrStart"),
|
||||
radianceFusionTuning.highlightShortSignalSnrStart.coerceAtLeast(0f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uHighlightShortSignalSnrFull"),
|
||||
radianceFusionTuning.highlightShortSignalSnrFull.coerceAtLeast(
|
||||
radianceFusionTuning.highlightShortSignalSnrStart + 1e-3f,
|
||||
),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uHighlightCoreReliabilityMinimum"),
|
||||
radianceFusionTuning.highlightCoreReliabilityMinimum.coerceIn(0f, 1f),
|
||||
)
|
||||
}
|
||||
|
||||
private fun readRadianceOutputTile(
|
||||
|
||||
+39
-34
@@ -10,65 +10,66 @@ import java.io.File
|
||||
|
||||
class GlesRawRadianceFusionShadersTest {
|
||||
@Test
|
||||
fun highlightFlowRejectsForwardBackwardInconsistencyBeforePropagation() {
|
||||
fun highlightFlowUsesDirectContinuousCollarEvidenceWithoutRecursiveFlowPropagation() {
|
||||
val validation = GlesRawRadianceFusionShaders.validateHighlightFlow
|
||||
val propagation = GlesRawRadianceFusionShaders.propagateHighlightFlow
|
||||
val composition = GlesRawRadianceFusionShaders.composeHighlightFlow
|
||||
val inference = GlesRadianceHighlightShaders.inferFlowFromCollar
|
||||
|
||||
assertTrue(validation.contains("forward.rg + reverse.rg"))
|
||||
assertTrue(validation.contains("min(forward.a, reverse.a) * consistency"))
|
||||
assertTrue(propagation.contains("uConfidenceDecay"))
|
||||
assertTrue(propagation.contains("uMinimumConfidence"))
|
||||
assertTrue(propagation.contains("smoothstep("))
|
||||
assertTrue(propagation.contains("sampleValue.a * support"))
|
||||
assertTrue(propagation.contains("variance"))
|
||||
assertTrue(propagation.contains("uGuideProxy"))
|
||||
assertTrue(propagation.contains("uAllowInvalidGuidePropagation"))
|
||||
assertTrue(propagation.contains("mix(0.35, 1.0"))
|
||||
assertTrue(
|
||||
RawRadianceFusionTuning().highlightFlowPropagationPasses <
|
||||
RawRadianceFusionTuning().longFlowPropagationPasses,
|
||||
)
|
||||
assertTrue(
|
||||
composition.contains("referenceToAnchorFlow.rg + anchorToShortFlow.rg"),
|
||||
)
|
||||
assertTrue(
|
||||
composition.contains("float multipliedConfidence = referenceToAnchorFlow.a * anchorToShortFlow.a"),
|
||||
)
|
||||
assertTrue(composition.contains("uUseBottleneckConfidence"))
|
||||
assertTrue(composition.contains("normalizedEdgeConfidence"))
|
||||
assertTrue(composition.contains("float bottleneckConfidence = min("))
|
||||
assertTrue(inference.contains("uniform sampler2D uDirectFlow"))
|
||||
assertTrue(inference.contains("uniform sampler2D uDirectSupport"))
|
||||
assertTrue(inference.contains("normalObservable * flowConfidence"))
|
||||
assertTrue(inference.contains("sectorWeights"))
|
||||
assertTrue(inference.contains("flowVariance"))
|
||||
assertTrue(inference.contains("canBeEnclosed"))
|
||||
assertFalse(inference.contains("uInputFlow"))
|
||||
assertTrue(RawRadianceFusionTuning().highlightCollarMinimumSectors >= 3)
|
||||
assertTrue(RawRadianceFusionTuning().highlightCollarRadiusTiles > 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun highlightCompositionUsesLocalEvidenceAndShortExposureOutputDomain() {
|
||||
fun highlightHoleDecisionPropagatesOnlyRejectionAndProducesBinaryCoreGate() {
|
||||
val rejection = GlesRadianceHighlightShaders.propagateHoleRejection
|
||||
val decision = GlesRadianceHighlightShaders.applyHoleDecision
|
||||
|
||||
assertTrue(rejection.contains("uniform sampler2D uInputRejection"))
|
||||
assertTrue(rejection.contains("neighbor.r * step(0.5, neighbor.g)"))
|
||||
assertFalse(rejection.contains("flow.rg"))
|
||||
assertFalse(rejection.contains("uInferredFlow"))
|
||||
assertTrue(decision.contains("float accepted = core *"))
|
||||
assertTrue(decision.contains("(1.0 - step(0.5, rejection.r))"))
|
||||
assertTrue(decision.contains("inferredFlow.rgb * accepted"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun highlightCompositionUsesWholeRegionEvidenceAndShortExposureOutputDomain() {
|
||||
val shader = GlesRawRadianceFusionShaders.normalize(
|
||||
showRejections = false,
|
||||
reconstructHighlights = true,
|
||||
)
|
||||
|
||||
assertTrue(shader.contains("uniform sampler2D uHighlightSupport"))
|
||||
assertTrue(shader.contains("uniform highp usampler2D uReferenceRaw"))
|
||||
assertTrue(shader.contains("HighlightRawStats shortRaw"))
|
||||
assertTrue(shader.contains("noiseAwareClipProbability"))
|
||||
assertTrue(shader.contains("normalizedPhotometricResidual"))
|
||||
assertTrue(shader.contains("pixelPhotometricConfidence * localSupport.b"))
|
||||
assertTrue(shader.contains("uCalculationGains * uCalculationGains"))
|
||||
assertTrue(shader.contains("uHighlightCoreReliabilityMinimum"))
|
||||
assertTrue(shader.contains("float shoulderBlend = (1.0 - saturatedCore)"))
|
||||
assertTrue(shader.contains("uHighlightFlowFullConfidence"))
|
||||
assertTrue(shader.contains("min(normalClipProbability.r, normalClipProbability.g)"))
|
||||
assertTrue(shader.contains("vec3 normalInShortDomain = rgb /"))
|
||||
assertTrue(shader.contains("mix(normalInShortDomain, highlightRgb, highlightWeight)"))
|
||||
assertFalse(shader.contains("vec3 highlightWeight"))
|
||||
assertFalse(shader.contains("step(0.5, shortReliability)"))
|
||||
assertFalse(shader.contains("uHighlightSupport"))
|
||||
assertFalse(shader.contains("admittedRegionValidity"))
|
||||
assertFalse(shader.contains("normalizedPhotometricResidual"))
|
||||
assertFalse(shader.contains("uHighlightRaw"))
|
||||
assertFalse(shader.contains("saturatedCore = step"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun highlightSupportSeparatesNeedValidityPhotometryAndGeometry() {
|
||||
fun highlightSupportUsesDenseMinimumHeadroomForWholeRegionAdmission() {
|
||||
val shader = GlesRadianceHighlightShaders.buildSupport
|
||||
|
||||
assertTrue(shader.contains("normalNeedSum"))
|
||||
assertTrue(shader.contains("shortValiditySum"))
|
||||
assertTrue(shader.contains("shortValidityMin"))
|
||||
assertTrue(shader.contains("const int MAX_TILE_SIZE = 32"))
|
||||
assertTrue(shader.contains("normalizedResidual"))
|
||||
assertTrue(shader.contains("referenceSample.a + shortSample.a"))
|
||||
assertTrue(shader.contains("clamp(flow.a, 0.0, 1.0)"))
|
||||
@@ -342,6 +343,10 @@ class GlesRawRadianceFusionShadersTest {
|
||||
"fragment" to GlesRawRadianceFusionShaders.longEligibility,
|
||||
"fragment" to GlesRawRadianceFusionShaders.normalize(showRejections = false),
|
||||
"fragment" to GlesRadianceHighlightShaders.buildSupport,
|
||||
"fragment" to GlesRadianceHighlightShaders.inferFlowFromCollar,
|
||||
"fragment" to GlesRadianceHighlightShaders.buildHoleRejectionSeed,
|
||||
"fragment" to GlesRadianceHighlightShaders.propagateHoleRejection,
|
||||
"fragment" to GlesRadianceHighlightShaders.applyHoleDecision,
|
||||
"fragment" to GlesRawRadianceFusionShaders.normalize(
|
||||
showRejections = false,
|
||||
reconstructHighlights = true,
|
||||
|
||||
-70
@@ -2,80 +2,10 @@ package com.hinnka.mycamera.processor
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class RawRadianceHighlightAlignmentSupportTest {
|
||||
private val highlightRequirements = RawRadianceHighlightAdmissionRequirements(
|
||||
minimumEligibleTiles = 1,
|
||||
minimumEligibleCoverage = 0.20f,
|
||||
)
|
||||
|
||||
@Test
|
||||
fun acceptsSupportInsideSmallLocalizedHighlight() {
|
||||
val admission = planRadianceHighlightAdmission(
|
||||
evidence = RawRadianceHighlightAdmissionEvidence(
|
||||
eligibleTileCount = 5,
|
||||
supportedTileCount = 2,
|
||||
),
|
||||
requirements = highlightRequirements,
|
||||
)
|
||||
|
||||
assertTrue(admission.accepted)
|
||||
assertEquals(0.4f, admission.eligibleCoverage, 0f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rejectsGoodWholeFrameFlowWhenHighlightItselfIsUnsupported() {
|
||||
val admission = planRadianceHighlightAdmission(
|
||||
evidence = RawRadianceHighlightAdmissionEvidence(
|
||||
eligibleTileCount = 5,
|
||||
supportedTileCount = 0,
|
||||
),
|
||||
requirements = highlightRequirements,
|
||||
)
|
||||
|
||||
assertFalse(admission.accepted)
|
||||
assertEquals(0f, admission.eligibleCoverage, 0f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rejectsWhenEligibleCoverageIsTooSparse() {
|
||||
val admission = planRadianceHighlightAdmission(
|
||||
evidence = RawRadianceHighlightAdmissionEvidence(
|
||||
eligibleTileCount = 10,
|
||||
supportedTileCount = 1,
|
||||
),
|
||||
requirements = highlightRequirements,
|
||||
)
|
||||
|
||||
assertFalse(admission.accepted)
|
||||
assertEquals(0.1f, admission.eligibleCoverage, 0f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fallsBackToNextTimestampRankedAcceptedAnchor() {
|
||||
val selected = selectRadianceHighlightAnchor(
|
||||
candidateIndices = intArrayOf(3, 2, 1, 0),
|
||||
frameCount = 4,
|
||||
acceptedFrameIndices = setOf(0, 1),
|
||||
)
|
||||
|
||||
assertEquals(1, selected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rejectsHighlightWhenNoNormalAnchorSurvived() {
|
||||
val selected = selectRadianceHighlightAnchor(
|
||||
candidateIndices = intArrayOf(2, 1),
|
||||
frameCount = 3,
|
||||
acceptedFrameIndices = setOf(0),
|
||||
)
|
||||
|
||||
assertNull(selected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun acceptedLongFrameKeepsFullGlobalWeightDespiteSparseSeedCoverage() {
|
||||
val admission = planRadianceLongAdmission(
|
||||
|
||||
Reference in new issue
Block a user