fix: try fix rawmax highlight
This commit is contained in:
1 parent
b0a19a635a
commit
c6f3ed8117
9 files changed
+790
-172
No files matched your search
@@ -420,18 +420,15 @@ class Camera2Controller(private val context: Context) {
|
||||
): CapturedFrameMetadata? {
|
||||
val exposureTimeNs = result.get(CaptureResult.SENSOR_EXPOSURE_TIME) ?: return null
|
||||
val sensitivityIso = result.get(CaptureResult.SENSOR_SENSITIVITY) ?: return null
|
||||
val postRawBoost = result
|
||||
.get(CaptureResult.CONTROL_POST_RAW_SENSITIVITY_BOOST)
|
||||
?.coerceAtLeast(1)
|
||||
?: 100
|
||||
val exposureProduct = RawExposureMath.productOrNull(exposureTimeNs, sensitivityIso)
|
||||
?: return null
|
||||
val channelNoiseProfile = captureChannelNoiseProfile(result)
|
||||
return CapturedFrameMetadata(
|
||||
sensorTimestampNs = sensorTimestampNs,
|
||||
frameNumber = result.frameNumber,
|
||||
exposureTimeNs = exposureTimeNs,
|
||||
sensitivityIso = sensitivityIso,
|
||||
exposureProduct = exposureTimeNs.toDouble() * sensitivityIso.toDouble() *
|
||||
(postRawBoost.toDouble() / 100.0),
|
||||
exposureProduct = exposureProduct,
|
||||
focusDistanceDiopters = result.get(CaptureResult.LENS_FOCUS_DISTANCE) ?: Float.NaN,
|
||||
lensState = result.get(CaptureResult.LENS_STATE),
|
||||
rollingShutterSkewNs = result.get(CaptureResult.SENSOR_ROLLING_SHUTTER_SKEW),
|
||||
@@ -6582,10 +6579,6 @@ class Camera2Controller(private val context: Context) {
|
||||
val sensorTimestampNs = frameResult?.get(CaptureResult.SENSOR_TIMESTAMP) ?: image.timestamp
|
||||
val exposureTimeNs = frameResult?.get(CaptureResult.SENSOR_EXPOSURE_TIME) ?: 0L
|
||||
val sensitivityIso = frameResult?.get(CaptureResult.SENSOR_SENSITIVITY) ?: 0
|
||||
val postRawBoost = frameResult
|
||||
?.get(CaptureResult.CONTROL_POST_RAW_SENSITIVITY_BOOST)
|
||||
?.coerceAtLeast(1)
|
||||
?: 100
|
||||
val frozenMetadata = pendingFrameMetadata.remove(image.timestamp)
|
||||
val frameMetadata = if (image.format == ImageFormat.RAW_SENSOR && frameResult != null) {
|
||||
CapturedFrameMetadata(
|
||||
@@ -6593,8 +6586,10 @@ class Camera2Controller(private val context: Context) {
|
||||
frameNumber = frozenMetadata?.frameNumber ?: result?.frameNumber ?: -1L,
|
||||
exposureTimeNs = exposureTimeNs,
|
||||
sensitivityIso = sensitivityIso,
|
||||
exposureProduct = exposureTimeNs.toDouble() * sensitivityIso.toDouble() *
|
||||
(postRawBoost.toDouble() / 100.0),
|
||||
exposureProduct = RawExposureMath.productOrNull(
|
||||
exposureTimeNs,
|
||||
sensitivityIso,
|
||||
) ?: frozenMetadata?.exposureProduct ?: 0.0,
|
||||
focusDistanceDiopters = frameResult
|
||||
.get(CaptureResult.LENS_FOCUS_DISTANCE)
|
||||
?: Float.NaN,
|
||||
|
||||
@@ -6,6 +6,27 @@ enum class MultiFrameCaptureRole {
|
||||
LONG,
|
||||
}
|
||||
|
||||
/**
|
||||
* Exposure carried by a RAW sensor sample.
|
||||
*
|
||||
* Camera2 post-RAW sensitivity boost belongs to the processed YUV/JPEG pipeline and must not be
|
||||
* included here. Keeping the definition in one place prevents RAW registration and radiance
|
||||
* normalization from silently drifting apart on devices that report a boost other than 100.
|
||||
*/
|
||||
internal object RawExposureMath {
|
||||
fun product(exposureTimeNs: Long, sensitivityIso: Int): Double {
|
||||
require(exposureTimeNs > 0L) { "RAW exposure time must be positive" }
|
||||
require(sensitivityIso > 0) { "RAW sensitivity must be positive" }
|
||||
return exposureTimeNs.toDouble() * sensitivityIso.toDouble()
|
||||
}
|
||||
|
||||
fun productOrNull(exposureTimeNs: Long?, sensitivityIso: Int?): Double? {
|
||||
val exposure = exposureTimeNs?.takeIf { it > 0L } ?: return null
|
||||
val sensitivity = sensitivityIso?.takeIf { it > 0 } ?: return null
|
||||
return product(exposure, sensitivity)
|
||||
}
|
||||
}
|
||||
|
||||
data class CapturedFrameMetadata(
|
||||
val sensorTimestampNs: Long,
|
||||
val frameNumber: Long,
|
||||
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* R: fraction of normal samples lacking highlight headroom.
|
||||
* G: fraction of short samples retaining headroom.
|
||||
* B: exposure-normalized photometric agreement where both observations are valid.
|
||||
* A: final geometric path confidence.
|
||||
*/
|
||||
val buildSupport: String = """
|
||||
#version 300 es
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
uniform sampler2D uReferenceProxy;
|
||||
uniform sampler2D uShortProxy;
|
||||
uniform sampler2D uComposedFlow;
|
||||
uniform ivec2 uGridSize;
|
||||
uniform ivec2 uPlaneSize;
|
||||
uniform int uTileSize;
|
||||
uniform float uPhotometricSigmaStart;
|
||||
uniform float uPhotometricSigmaFull;
|
||||
out vec4 fragColor;
|
||||
|
||||
vec4 proxyAt(sampler2D proxyTexture, vec2 planePosition) {
|
||||
vec2 uv = (clamp(
|
||||
planePosition,
|
||||
vec2(0.0),
|
||||
vec2(uPlaneSize - ivec2(1))
|
||||
) + vec2(0.5)) / vec2(uPlaneSize);
|
||||
return texture(proxyTexture, uv);
|
||||
}
|
||||
|
||||
bool insidePlane(vec2 planePosition) {
|
||||
return planePosition.x >= 0.0 && planePosition.y >= 0.0 &&
|
||||
planePosition.x <= float(uPlaneSize.x - 1) &&
|
||||
planePosition.y <= float(uPlaneSize.y - 1);
|
||||
}
|
||||
|
||||
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 photometricSum = 0.0;
|
||||
float photometricWeightSum = 0.0;
|
||||
float sampleCount = 0.0;
|
||||
float sigmaStart2 = uPhotometricSigmaStart * uPhotometricSigmaStart;
|
||||
float sigmaFull2 = max(
|
||||
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);
|
||||
vec2 shortPosition = referencePosition + flow.rg;
|
||||
bool inside = insidePlane(referencePosition) &&
|
||||
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;
|
||||
float difference = referenceSample.r - shortSample.r;
|
||||
float differenceVariance = max(
|
||||
referenceSample.a + shortSample.a,
|
||||
1e-7
|
||||
);
|
||||
float normalizedResidual = difference * difference / differenceVariance;
|
||||
float agreement = 1.0 - smoothstep(
|
||||
sigmaStart2,
|
||||
sigmaFull2,
|
||||
normalizedResidual
|
||||
);
|
||||
photometricSum += agreement * overlap;
|
||||
photometricWeightSum += overlap;
|
||||
sampleCount += insideWeight;
|
||||
}
|
||||
}
|
||||
float denominator = max(sampleCount, 1.0);
|
||||
fragColor = vec4(
|
||||
normalNeedSum / denominator,
|
||||
shortValiditySum / denominator,
|
||||
photometricWeightSum > 1e-5 ?
|
||||
photometricSum / photometricWeightSum : 0.0,
|
||||
clamp(flow.a, 0.0, 1.0)
|
||||
);
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
@@ -108,6 +108,7 @@ internal object RawRadianceExposurePlanner {
|
||||
internal data class RawRadianceHighlightFrame(
|
||||
val shortFrame: RawStackFrame,
|
||||
val anchorFrameIndex: Int,
|
||||
val anchorCandidateIndices: IntArray,
|
||||
val exposureRatio: Float,
|
||||
val baselineExposureEv: Float,
|
||||
)
|
||||
@@ -121,16 +122,6 @@ internal data class RawRadianceLongFramePlan(
|
||||
val exposureDeltaEv: Float,
|
||||
)
|
||||
|
||||
internal fun hasRadianceHighlightAlignmentSupport(
|
||||
validTileCount: Int,
|
||||
coveredQuadrants: Int,
|
||||
minimumValidTiles: Int,
|
||||
minimumQuadrants: Int,
|
||||
): Boolean {
|
||||
return validTileCount >= minimumValidTiles.coerceAtLeast(1) &&
|
||||
coveredQuadrants >= minimumQuadrants.coerceIn(1, 4)
|
||||
}
|
||||
|
||||
internal enum class RawRadianceLongAdmissionMode {
|
||||
REJECTED,
|
||||
VALIDATED_FLOW,
|
||||
@@ -235,8 +226,10 @@ internal fun planRadianceLongAdmission(
|
||||
/**
|
||||
* Unified same-exposure RAW fusion.
|
||||
*
|
||||
* One optional one-third-exposure frame is identified and reserved for the dedicated
|
||||
* highlight-reconstruction stage. Tagged long exposures are also isolated and planned against
|
||||
* 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.
|
||||
*
|
||||
@@ -410,12 +403,19 @@ class GlesRawRadianceFusion(
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val anchorIndex = normalFrames.indices.minByOrNull { index ->
|
||||
timestampDistance(normalFrames[index].sensorTimestampNs, shortFrame.sensorTimestampNs)
|
||||
} ?: 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(),
|
||||
)
|
||||
@@ -504,24 +504,35 @@ data class RawRadianceFusionTuning(
|
||||
val longRegionalStructureSnrFull: Float = 2.0f,
|
||||
val longFineRefinementConfidenceStart: Float = 0.01f,
|
||||
val longFineRefinementConfidenceFull: Float = 0.05f,
|
||||
val longFlowPropagationPasses: Int = 48,
|
||||
val longFlowPropagationDecay: Float = 0.96f,
|
||||
val longFlowGuideEdgeSigma: Float = 0.08f,
|
||||
val longFlowSeedConfidence: Float = 0.05f,
|
||||
val highlightMinExposureRatio: Float = 1.2f,
|
||||
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 highlightShortSignalStart: Float = 0.01f,
|
||||
val highlightShortSignalFull: Float = 0.04f,
|
||||
val highlightFlowFbConsistencyStartPx: Float = 0.75f,
|
||||
val highlightFlowFbConsistencyFullPx: Float = 2.0f,
|
||||
val highlightFlowPropagationPasses: Int = 48,
|
||||
val highlightFlowPropagationDecay: Float = 0.96f,
|
||||
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 highlightFlowMinimumValidTiles: Int = 16,
|
||||
val highlightFlowMinimumQuadrants: Int = 2,
|
||||
val highlightMinimumEligibleTiles: Int = 1,
|
||||
val highlightMinimumEligibleCoverage: Float = 0.20f,
|
||||
val highlightNeedTileThreshold: Float = 0.05f,
|
||||
val highlightShortValidityTileThreshold: Float = 0.20f,
|
||||
val highlightPhotometricSigmaStart: Float = 3.0f,
|
||||
val highlightPhotometricSigmaFull: Float = 8.0f,
|
||||
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. */
|
||||
@@ -674,6 +685,7 @@ internal object GlesRawRadianceFusionShaders {
|
||||
uniform float uMinimumConfidence;
|
||||
uniform float uFlowConsistencySigma;
|
||||
uniform float uGuideEdgeSigma;
|
||||
uniform int uAllowInvalidGuidePropagation;
|
||||
out vec4 fragColor;
|
||||
|
||||
vec4 readFlow(ivec2 position) {
|
||||
@@ -724,8 +736,15 @@ internal object GlesRawRadianceFusionShaders {
|
||||
float spatial = (x == 0 || y == 0) ? 1.0 : 0.70710678;
|
||||
float guideDelta = neighborGuide.r - centerGuide.r;
|
||||
float edgeSigma = max(uGuideEdgeSigma, 1e-3);
|
||||
float edgeWeight = min(centerGuide.g, neighborGuide.g) < 0.5 ?
|
||||
1.0 : exp(-(guideDelta * guideDelta) / (edgeSigma * edgeSigma));
|
||||
float guideValidity = min(centerGuide.g, neighborGuide.g);
|
||||
float edgeWeight = exp(
|
||||
-(guideDelta * guideDelta) / (edgeSigma * edgeSigma)
|
||||
);
|
||||
if (uAllowInvalidGuidePropagation != 0 && guideValidity < 0.5) {
|
||||
edgeWeight = 1.0;
|
||||
} else {
|
||||
edgeWeight *= mix(0.35, 1.0, clamp(guideValidity, 0.0, 1.0));
|
||||
}
|
||||
float support = smoothstep(
|
||||
minimumConfidence,
|
||||
directConfidence,
|
||||
@@ -755,8 +774,15 @@ internal object GlesRawRadianceFusionShaders {
|
||||
float spatial = (x == 0 || y == 0) ? 1.0 : 0.70710678;
|
||||
float guideDelta = neighborGuide.r - centerGuide.r;
|
||||
float edgeSigma = max(uGuideEdgeSigma, 1e-3);
|
||||
float edgeWeight = min(centerGuide.g, neighborGuide.g) < 0.5 ?
|
||||
1.0 : exp(-(guideDelta * guideDelta) / (edgeSigma * edgeSigma));
|
||||
float guideValidity = min(centerGuide.g, neighborGuide.g);
|
||||
float edgeWeight = exp(
|
||||
-(guideDelta * guideDelta) / (edgeSigma * edgeSigma)
|
||||
);
|
||||
if (uAllowInvalidGuidePropagation != 0 && guideValidity < 0.5) {
|
||||
edgeWeight = 1.0;
|
||||
} else {
|
||||
edgeWeight *= mix(0.35, 1.0, clamp(guideValidity, 0.0, 1.0));
|
||||
}
|
||||
float support = smoothstep(
|
||||
minimumConfidence,
|
||||
directConfidence,
|
||||
@@ -1708,6 +1734,7 @@ internal object GlesRawRadianceFusionShaders {
|
||||
uniform highp usampler2D uHighlightRaw;
|
||||
uniform highp usampler2D uReferenceRaw;
|
||||
uniform sampler2D uHighlightFlow;
|
||||
uniform sampler2D uHighlightSupport;
|
||||
uniform ivec2 uHighlightSourceOrigin;
|
||||
uniform ivec2 uHighlightSourceSize;
|
||||
uniform ivec2 uHighlightFlowGridSize;
|
||||
@@ -1722,10 +1749,17 @@ internal object GlesRawRadianceFusionShaders {
|
||||
uniform float uHighlightNormalClipFull;
|
||||
uniform float uHighlightShortClipStart;
|
||||
uniform float uHighlightShortClipFull;
|
||||
uniform float uHighlightShortSignalStart;
|
||||
uniform float uHighlightShortSignalFull;
|
||||
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 {
|
||||
""
|
||||
@@ -1776,6 +1810,12 @@ internal object GlesRawRadianceFusionShaders {
|
||||
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)));
|
||||
}
|
||||
|
||||
vec3 highlightRgbAt(vec2 localRawPosition) {
|
||||
vec2 maximum = vec2(max(uHighlightSourceSize - ivec2(1), ivec2(0)));
|
||||
vec2 storageSize = vec2(textureSize(uHighlightRgb, 0));
|
||||
@@ -1805,31 +1845,136 @@ internal object GlesRawRadianceFusionShaders {
|
||||
return clamp((raw - uBlackLevel[bayerIndex]) / range, 0.0, 1.0);
|
||||
}
|
||||
|
||||
vec2 highlightRawSignalAndPeak(vec2 localRawPosition) {
|
||||
ivec2 center = ivec2(round(localRawPosition));
|
||||
ivec2 block = (center / 2) * 2;
|
||||
float signal = 0.0;
|
||||
float peak = 0.0;
|
||||
for (int y = 0; y <= 1; ++y) {
|
||||
for (int x = 0; x <= 1; ++x) {
|
||||
float sampleValue = highlightRawNormAt(block + ivec2(x, y));
|
||||
signal += sampleValue;
|
||||
peak = max(peak, sampleValue);
|
||||
}
|
||||
}
|
||||
return vec2(signal * 0.25, peak);
|
||||
struct HighlightRawStats {
|
||||
vec3 signal;
|
||||
vec3 peak;
|
||||
};
|
||||
|
||||
void addHighlightRawSample(
|
||||
int bayerIndex,
|
||||
float sampleValue,
|
||||
inout vec3 signalSum,
|
||||
inout vec3 peak,
|
||||
inout vec3 sampleCount
|
||||
) {
|
||||
int channel = bayerIndex == 0 ? 0 : (bayerIndex == 3 ? 2 : 1);
|
||||
signalSum[channel] += sampleValue;
|
||||
peak[channel] = max(peak[channel], sampleValue);
|
||||
sampleCount[channel] += 1.0;
|
||||
}
|
||||
|
||||
float referenceRawPeak(vec2 globalRawPosition) {
|
||||
ivec2 center = ivec2(round(globalRawPosition));
|
||||
ivec2 block = (center / 2) * 2;
|
||||
float peak = 0.0;
|
||||
for (int y = 0; y <= 1; ++y) {
|
||||
for (int x = 0; x <= 1; ++x) {
|
||||
peak = max(peak, referenceRawNormAt(block + ivec2(x, y)));
|
||||
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 peak;
|
||||
return HighlightRawStats(
|
||||
signalSum / max(sampleCount, vec3(1.0)),
|
||||
peak
|
||||
);
|
||||
}
|
||||
|
||||
HighlightRawStats referenceRawStatsAt(vec2 globalRawPosition) {
|
||||
ivec2 globalCenter = ivec2(round(globalRawPosition));
|
||||
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),
|
||||
ivec2(0),
|
||||
uInputSize - ivec2(1)
|
||||
);
|
||||
int bayerIndex = highlightBayerIndexAt(globalPosition);
|
||||
addHighlightRawSample(
|
||||
bayerIndex,
|
||||
referenceRawNormAt(globalPosition),
|
||||
signalSum,
|
||||
peak,
|
||||
sampleCount
|
||||
);
|
||||
}
|
||||
}
|
||||
return HighlightRawStats(
|
||||
signalSum / max(sampleCount, vec3(1.0)),
|
||||
peak
|
||||
);
|
||||
}
|
||||
|
||||
vec3 referenceHighlightNoiseVariance(vec3 signal) {
|
||||
return max(
|
||||
vec3(
|
||||
uNoiseAlphaByChannel[0] * signal.r + uNoiseBetaByChannel[0],
|
||||
0.5 * (
|
||||
uNoiseAlphaByChannel[1] * signal.g + uNoiseBetaByChannel[1] +
|
||||
uNoiseAlphaByChannel[2] * signal.g + uNoiseBetaByChannel[2]
|
||||
),
|
||||
uNoiseAlphaByChannel[3] * signal.b + uNoiseBetaByChannel[3]
|
||||
),
|
||||
vec3(1e-10)
|
||||
);
|
||||
}
|
||||
|
||||
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,
|
||||
float fixedStart,
|
||||
float fixedFull
|
||||
) {
|
||||
vec3 adaptiveStart = min(
|
||||
vec3(fixedStart),
|
||||
vec3(1.0) - noiseSigma * max(uHighlightClipNoiseSigmaStart, 0.0)
|
||||
);
|
||||
vec3 adaptiveFull = min(
|
||||
vec3(fixedFull),
|
||||
vec3(1.0) - noiseSigma * max(uHighlightClipNoiseSigmaFull, 0.0)
|
||||
);
|
||||
adaptiveStart = clamp(adaptiveStart, vec3(0.0), vec3(0.999));
|
||||
adaptiveFull = max(adaptiveFull, adaptiveStart + vec3(1e-4));
|
||||
return smoothstep(adaptiveStart, adaptiveFull, peak);
|
||||
}
|
||||
""".trimIndent()
|
||||
} else {
|
||||
@@ -1856,22 +2001,45 @@ internal object GlesRawRadianceFusionShaders {
|
||||
highlightLocalPosition.x <= float(uHighlightSourceSize.x - 1) &&
|
||||
highlightLocalPosition.y <= float(uHighlightSourceSize.y - 1) ? 1.0 : 0.0;
|
||||
vec3 highlightRgb = highlightRgbAt(highlightLocalPosition);
|
||||
vec2 highlightRawStats = highlightRawSignalAndPeak(highlightLocalPosition);
|
||||
float normalPeak = referenceRawPeak(referenceRawPosition);
|
||||
float normalClipped = smoothstep(
|
||||
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),
|
||||
normalPeak
|
||||
max(uHighlightNormalClipStart, uHighlightNormalClipFull)
|
||||
);
|
||||
float shortNotClipped = 1.0 - smoothstep(
|
||||
vec3 shortClipProbability = noiseAwareClipProbability(
|
||||
shortRaw.peak,
|
||||
sqrt(shortVariance),
|
||||
min(uHighlightShortClipStart, uHighlightShortClipFull),
|
||||
max(uHighlightShortClipStart, uHighlightShortClipFull),
|
||||
highlightRawStats.y
|
||||
max(uHighlightShortClipStart, uHighlightShortClipFull)
|
||||
);
|
||||
float normalClipped = max(
|
||||
max(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(uHighlightShortSignalStart, uHighlightShortSignalFull),
|
||||
max(uHighlightShortSignalStart, uHighlightShortSignalFull),
|
||||
highlightRawStats.x
|
||||
min(uHighlightShortSignalSnrStart, uHighlightShortSignalSnrFull),
|
||||
max(uHighlightShortSignalSnrStart, uHighlightShortSignalSnrFull),
|
||||
shortSnr
|
||||
);
|
||||
float highlightFlowConfidence = smoothstep(
|
||||
uHighlightFlowMinimumConfidence,
|
||||
@@ -1879,24 +2047,56 @@ internal object GlesRawRadianceFusionShaders {
|
||||
uHighlightFlowMinimumConfidence + 1e-4,
|
||||
uHighlightFlowFullConfidence
|
||||
),
|
||||
highlightFlow.a
|
||||
min(highlightFlow.a, localSupport.a)
|
||||
);
|
||||
float coarseShortValidity = smoothstep(0.05, 0.50, localSupport.g);
|
||||
float shortReliability = clamp(
|
||||
shortNotClipped * shortHasSignal * highlightFlowConfidence * highlightInside,
|
||||
shortHasHeadroom * shortHasSignal * coarseShortValidity *
|
||||
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(uHighlightNormalClipFull, normalPeak);
|
||||
float coreShortSelection = saturatedCore * step(0.5, shortReliability);
|
||||
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 and can safely hide exposure-boundary seams.
|
||||
float shoulderBlend = (1.0 - saturatedCore) * normalClipped * shortReliability;
|
||||
// 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);
|
||||
vec3 normalInShortDomain = rgb / max(uHighlightExposureRatio, 1.0);
|
||||
rgb = clamp(mix(normalInShortDomain, highlightRgb, highlightWeight), 0.0, 1.0);
|
||||
$highlightDebugOverlay
|
||||
""".trimIndent()
|
||||
|
||||
@@ -66,7 +66,9 @@ 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,
|
||||
@@ -343,6 +345,7 @@ internal class GlesRawRadianceStacker(
|
||||
private var radianceHighlightValidateFlowProgram = 0
|
||||
private var radianceHighlightPropagateFlowProgram = 0
|
||||
private var radianceHighlightComposeFlowProgram = 0
|
||||
private var radianceHighlightSupportProgram = 0
|
||||
private var radianceLongEligibilityProgram = 0
|
||||
private var radianceLongObservabilityDiagnosticProgram = 0
|
||||
private var radianceReferenceBaseProgram = 0
|
||||
@@ -379,6 +382,7 @@ internal class GlesRawRadianceStacker(
|
||||
private var radianceHighlightReverseFlowTexture = 0
|
||||
private var radianceHighlightAnchorFlowTexture = 0
|
||||
private var radianceHighlightComposedFlowTexture = 0
|
||||
private var radianceHighlightSupportTexture = 0
|
||||
private var kernelTexture = 0
|
||||
private var robustnessTexture = 0
|
||||
private var tileMaskTexture = 0
|
||||
@@ -998,6 +1002,13 @@ internal class GlesRawRadianceStacker(
|
||||
GlesRawRadianceFusionShaders.composeHighlightFlow,
|
||||
"raw_radiance_highlight_compose_flow",
|
||||
)
|
||||
if (needsHighlightPrograms) {
|
||||
radianceHighlightSupportProgram = linkGraphicsProgram(
|
||||
FULLSCREEN_VERTEX_SHADER,
|
||||
GlesRadianceHighlightShaders.buildSupport,
|
||||
"raw_radiance_highlight_support",
|
||||
)
|
||||
}
|
||||
}
|
||||
if (needsLongPrograms) {
|
||||
radianceLongEligibilityProgram = linkGraphicsProgram(
|
||||
@@ -1198,6 +1209,14 @@ internal class GlesRawRadianceStacker(
|
||||
GLES30.GL_RGBA16F,
|
||||
GLES30.GL_LINEAR,
|
||||
)
|
||||
if (activeRadianceHighlightFrame != null) {
|
||||
radianceHighlightSupportTexture = createTexture2D(
|
||||
gridWidth,
|
||||
gridHeight,
|
||||
GLES30.GL_RGBA16F,
|
||||
GLES30.GL_LINEAR,
|
||||
)
|
||||
}
|
||||
}
|
||||
kernelTexture = createTexture2D(planeWidth, planeHeight, GLES30.GL_RGBA16F, GLES30.GL_NEAREST)
|
||||
robustnessTexture = createTexture2D(planeWidth, planeHeight, GLES30.GL_R32F, GLES30.GL_NEAREST)
|
||||
@@ -2640,23 +2659,38 @@ internal class GlesRawRadianceStacker(
|
||||
referencePyramid: List<TextureLevel>,
|
||||
currentPyramid: List<TextureLevel>,
|
||||
): RadianceHighlightAlignment? {
|
||||
if (highlight.anchorFrameIndex !in frames.indices) return null
|
||||
val anchorIsReference = highlight.anchorFrameIndex == 0
|
||||
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 == highlight.anchorFrameIndex }
|
||||
?: run {
|
||||
PLog.w(
|
||||
TAG,
|
||||
"Radiance highlight disabled: adjacent normal anchor " +
|
||||
"${highlight.anchorFrameIndex} was rejected",
|
||||
)
|
||||
return null
|
||||
}
|
||||
acceptedFrames.firstOrNull { it.frameIndex == anchorFrameIndex }
|
||||
?: return null
|
||||
}
|
||||
return runCatching {
|
||||
val anchor = frames[highlight.anchorFrameIndex]
|
||||
val anchor = frames[anchorFrameIndex]
|
||||
uploadRawTexture(anchor.image, curRaw, "Radiance highlight anchor")
|
||||
buildProxy(curRaw, refProxy, "Radiance highlight anchor")
|
||||
buildPyramid(referencePyramid)
|
||||
@@ -2713,6 +2747,12 @@ internal class GlesRawRadianceStacker(
|
||||
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) {
|
||||
@@ -2728,10 +2768,23 @@ internal class GlesRawRadianceStacker(
|
||||
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)
|
||||
summarizeRadianceHighlightAlignment(highlight)
|
||||
buildRadianceHighlightSupport(
|
||||
referenceProxyTexture = refProxy,
|
||||
shortProxyTexture = curProxy,
|
||||
)
|
||||
summarizeRadianceHighlightAlignment(
|
||||
highlight = highlight,
|
||||
anchorFrameIndex = anchorFrameIndex,
|
||||
)
|
||||
}.onFailure { error ->
|
||||
PLog.w(TAG, "Radiance highlight alignment failed; preserving normal fusion", error)
|
||||
}.getOrNull()
|
||||
@@ -2842,6 +2895,12 @@ internal class GlesRawRadianceStacker(
|
||||
targetTexture = radianceHighlightAnchorFlowTexture,
|
||||
guideProxyTexture = referenceGuideProxyTexture,
|
||||
label = "long-reference-to-anchor",
|
||||
passes = radianceFusionTuning.longFlowPropagationPasses,
|
||||
confidenceDecay = radianceFusionTuning.longFlowPropagationDecay,
|
||||
directConfidence = radianceFusionTuning.longFlowSeedConfidence,
|
||||
minimumConfidence = radianceFusionTuning.longFlowMinimumConfidence,
|
||||
guideEdgeSigma = radianceFusionTuning.longFlowGuideEdgeSigma,
|
||||
allowInvalidGuidePropagation = true,
|
||||
)
|
||||
}
|
||||
activeAnchorFrameIndex = anchorFrameIndex
|
||||
@@ -2980,6 +3039,12 @@ internal class GlesRawRadianceStacker(
|
||||
targetTexture = flowTexture,
|
||||
guideProxyTexture = refProxy,
|
||||
label = "long-anchor-to-source",
|
||||
passes = radianceFusionTuning.longFlowPropagationPasses,
|
||||
confidenceDecay = radianceFusionTuning.longFlowPropagationDecay,
|
||||
directConfidence = radianceFusionTuning.longFlowSeedConfidence,
|
||||
minimumConfidence = radianceFusionTuning.longFlowMinimumConfidence,
|
||||
guideEdgeSigma = radianceFusionTuning.longFlowGuideEdgeSigma,
|
||||
allowInvalidGuidePropagation = true,
|
||||
)
|
||||
|
||||
// Admit the long frame on the direct anchor -> long edge. The normal anchor has
|
||||
@@ -3689,12 +3754,18 @@ internal class GlesRawRadianceStacker(
|
||||
targetTexture: Int,
|
||||
guideProxyTexture: Int,
|
||||
label: String,
|
||||
passes: Int,
|
||||
confidenceDecay: Float,
|
||||
directConfidence: Float,
|
||||
minimumConfidence: Float,
|
||||
guideEdgeSigma: Float,
|
||||
allowInvalidGuidePropagation: Boolean,
|
||||
) {
|
||||
val passes = radianceFusionTuning.highlightFlowPropagationPasses.coerceIn(0, 64)
|
||||
if (passes == 0) return
|
||||
val normalizedPasses = passes.coerceIn(0, 64)
|
||||
if (normalizedPasses == 0) return
|
||||
val program = radianceHighlightPropagateFlowProgram
|
||||
check(program != 0)
|
||||
repeat(passes) { pass ->
|
||||
repeat(normalizedPasses) { pass ->
|
||||
val input = if ((pass and 1) == 0) targetTexture else flowScratchTexture
|
||||
val output = if ((pass and 1) == 0) flowScratchTexture else targetTexture
|
||||
bindFramebufferOutput(output, "Radiance highlight propagate $label pass $pass")
|
||||
@@ -3707,15 +3778,15 @@ internal class GlesRawRadianceStacker(
|
||||
GLES31.glUniform1i(uniformLocation(program, "uTileSize"), flowGridSpacing)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uConfidenceDecay"),
|
||||
radianceFusionTuning.highlightFlowPropagationDecay.coerceIn(0f, 1f),
|
||||
confidenceDecay.coerceIn(0f, 1f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uDirectConfidence"),
|
||||
radianceFusionTuning.highlightFlowSeedConfidence.coerceIn(0f, 1f),
|
||||
directConfidence.coerceIn(0f, 1f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uMinimumConfidence"),
|
||||
radianceFusionTuning.highlightFlowMinimumConfidence.coerceIn(0f, 1f),
|
||||
minimumConfidence.coerceIn(0f, 1f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uFlowConsistencySigma"),
|
||||
@@ -3723,12 +3794,16 @@ internal class GlesRawRadianceStacker(
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uGuideEdgeSigma"),
|
||||
radianceFusionTuning.highlightFlowGuideEdgeSigma.coerceAtLeast(1e-3f),
|
||||
guideEdgeSigma.coerceAtLeast(1e-3f),
|
||||
)
|
||||
GLES31.glUniform1i(
|
||||
uniformLocation(program, "uAllowInvalidGuidePropagation"),
|
||||
if (allowInvalidGuidePropagation) 1 else 0,
|
||||
)
|
||||
GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3)
|
||||
finishFramebufferPass("Radiance highlight propagate $label pass $pass")
|
||||
}
|
||||
if ((passes and 1) != 0) {
|
||||
if ((normalizedPasses and 1) != 0) {
|
||||
copyRgbaTexture(
|
||||
flowScratchTexture,
|
||||
targetTexture,
|
||||
@@ -3783,37 +3858,82 @@ internal class GlesRawRadianceStacker(
|
||||
finishFramebufferPass("Radiance highlight compose flow")
|
||||
}
|
||||
|
||||
private fun buildRadianceHighlightSupport(
|
||||
referenceProxyTexture: Int,
|
||||
shortProxyTexture: Int,
|
||||
) {
|
||||
val program = radianceHighlightSupportProgram
|
||||
check(program != 0)
|
||||
bindFramebufferOutput(
|
||||
radianceHighlightSupportTexture,
|
||||
"Radiance highlight local support",
|
||||
)
|
||||
GLES30.glViewport(0, 0, gridWidth, gridHeight)
|
||||
GLES30.glUseProgram(program)
|
||||
bindTexture(program, "uReferenceProxy", 0, referenceProxyTexture)
|
||||
bindTexture(program, "uShortProxy", 1, shortProxyTexture)
|
||||
bindTexture(program, "uComposedFlow", 2, radianceHighlightComposedFlowTexture)
|
||||
GLES31.glUniform2i(uniformLocation(program, "uGridSize"), gridWidth, gridHeight)
|
||||
GLES31.glUniform2i(uniformLocation(program, "uPlaneSize"), planeWidth, planeHeight)
|
||||
GLES31.glUniform1i(uniformLocation(program, "uTileSize"), flowGridSpacing)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uPhotometricSigmaStart"),
|
||||
radianceFusionTuning.highlightPhotometricSigmaStart.coerceAtLeast(0f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uPhotometricSigmaFull"),
|
||||
radianceFusionTuning.highlightPhotometricSigmaFull.coerceAtLeast(
|
||||
radianceFusionTuning.highlightPhotometricSigmaStart + 1e-3f,
|
||||
),
|
||||
)
|
||||
GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3)
|
||||
finishFramebufferPass("Radiance highlight local support")
|
||||
}
|
||||
|
||||
private fun summarizeRadianceHighlightAlignment(
|
||||
highlight: RawRadianceHighlightFrame,
|
||||
anchorFrameIndex: Int,
|
||||
): RadianceHighlightAlignment? {
|
||||
val values = readFlowTexture(
|
||||
texture = radianceHighlightComposedFlowTexture,
|
||||
val (flowValues, supportValues) = readFlowTextures(
|
||||
textures = listOf(
|
||||
radianceHighlightComposedFlowTexture,
|
||||
radianceHighlightSupportTexture,
|
||||
),
|
||||
textureWidth = gridWidth,
|
||||
textureHeight = gridHeight,
|
||||
label = "Radiance highlight composed flow",
|
||||
label = "Radiance highlight flow and support",
|
||||
)
|
||||
val confidenceThreshold = radianceFusionTuning.highlightFlowMinimumConfidence
|
||||
.coerceIn(0f, 1f)
|
||||
var validTiles = 0
|
||||
val needThreshold = radianceFusionTuning.highlightNeedTileThreshold.coerceIn(0f, 1f)
|
||||
val shortValidityThreshold = radianceFusionTuning.highlightShortValidityTileThreshold
|
||||
.coerceIn(0f, 1f)
|
||||
var eligibleTiles = 0
|
||||
var supportedTiles = 0
|
||||
var minX = 0f
|
||||
var maxX = 0f
|
||||
var minY = 0f
|
||||
var maxY = 0f
|
||||
val quadrants = BooleanArray(4)
|
||||
var offset = 0
|
||||
while (offset + 3 < values.size) {
|
||||
while (offset + 3 < flowValues.size && offset + 3 < supportValues.size) {
|
||||
val tileIndex = offset / 4
|
||||
val flowX = values[offset]
|
||||
val flowY = values[offset + 1]
|
||||
val confidence = values[offset + 3]
|
||||
if (flowX.isFinite() && flowY.isFinite() && confidence.isFinite() &&
|
||||
confidence >= confidenceThreshold
|
||||
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
|
||||
) {
|
||||
minX = minOf(minX, flowX)
|
||||
maxX = maxOf(maxX, flowX)
|
||||
minY = minOf(minY, flowY)
|
||||
maxY = maxOf(maxY, flowY)
|
||||
validTiles++
|
||||
supportedTiles++
|
||||
val tileX = tileIndex % gridWidth
|
||||
val tileY = tileIndex / gridWidth
|
||||
val quadrant = (if (tileY >= gridHeight / 2) 2 else 0) +
|
||||
@@ -3823,37 +3943,42 @@ internal class GlesRawRadianceStacker(
|
||||
offset += 4
|
||||
}
|
||||
val totalTiles = (gridWidth * gridHeight).coerceAtLeast(1)
|
||||
val validFraction = validTiles.toFloat() / totalTiles
|
||||
val validFraction = supportedTiles.toFloat() / totalTiles
|
||||
val coveredQuadrants = quadrants.count { it }
|
||||
val minimumValidTiles = radianceFusionTuning.highlightFlowMinimumValidTiles
|
||||
.coerceAtLeast(1)
|
||||
val minimumQuadrants = radianceFusionTuning.highlightFlowMinimumQuadrants
|
||||
.coerceIn(1, 4)
|
||||
if (!hasRadianceHighlightAlignmentSupport(
|
||||
validTileCount = validTiles,
|
||||
coveredQuadrants = coveredQuadrants,
|
||||
minimumValidTiles = minimumValidTiles,
|
||||
minimumQuadrants = minimumQuadrants,
|
||||
)
|
||||
) {
|
||||
val admission = planRadianceHighlightAdmission(
|
||||
evidence = RawRadianceHighlightAdmissionEvidence(
|
||||
eligibleTileCount = eligibleTiles,
|
||||
supportedTileCount = supportedTiles,
|
||||
),
|
||||
requirements = RawRadianceHighlightAdmissionRequirements(
|
||||
minimumEligibleTiles = radianceFusionTuning.highlightMinimumEligibleTiles,
|
||||
minimumEligibleCoverage =
|
||||
radianceFusionTuning.highlightMinimumEligibleCoverage,
|
||||
),
|
||||
)
|
||||
if (!admission.accepted) {
|
||||
PLog.w(
|
||||
TAG,
|
||||
"Radiance highlight alignment rejected coverage=$validFraction " +
|
||||
"validTiles=$validTiles/$totalTiles requiredTiles=$minimumValidTiles " +
|
||||
"quadrants=$coveredQuadrants/$minimumQuadrants",
|
||||
"Radiance highlight alignment rejected eligible=$eligibleTiles/$totalTiles " +
|
||||
"supported=$supportedTiles coverage=${admission.eligibleCoverage} " +
|
||||
"needThreshold=$needThreshold shortThreshold=$shortValidityThreshold " +
|
||||
"anchor=$anchorFrameIndex",
|
||||
)
|
||||
return null
|
||||
}
|
||||
PLog.i(
|
||||
TAG,
|
||||
"Radiance highlight alignment accepted coverage=$validFraction " +
|
||||
"validTiles=$validTiles/$totalTiles quadrants=$coveredQuadrants " +
|
||||
"Radiance highlight alignment accepted eligible=$eligibleTiles/$totalTiles " +
|
||||
"supported=$supportedTiles coverage=${admission.eligibleCoverage} " +
|
||||
"quadrants=$coveredQuadrants anchor=$anchorFrameIndex " +
|
||||
"flow=[$minX,$maxX]x[$minY,$maxY] " +
|
||||
"ratio=${highlight.exposureRatio} baseline=${highlight.baselineExposureEv}EV",
|
||||
)
|
||||
return RadianceHighlightAlignment(
|
||||
frame = highlight,
|
||||
anchorFrameIndex = anchorFrameIndex,
|
||||
flowTexture = radianceHighlightComposedFlowTexture,
|
||||
supportTexture = radianceHighlightSupportTexture,
|
||||
minFlowXPlanePx = minX,
|
||||
maxFlowXPlanePx = maxX,
|
||||
minFlowYPlanePx = minY,
|
||||
@@ -6424,6 +6549,7 @@ internal class GlesRawRadianceStacker(
|
||||
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,
|
||||
@@ -6445,7 +6571,11 @@ internal class GlesRawRadianceStacker(
|
||||
uniformLocation(program, "uHighlightFlowTileSize"),
|
||||
flowGridSpacing,
|
||||
)
|
||||
setRadianceHighlightUniforms(program, highlightAlignment.frame.exposureRatio)
|
||||
setRadianceHighlightUniforms(
|
||||
program = program,
|
||||
exposureRatio = highlightAlignment.frame.exposureRatio,
|
||||
shortNoiseModel = frameNoiseModel(highlightAlignment.frame.shortFrame),
|
||||
)
|
||||
}
|
||||
setRadianceNormalizeUniforms(program)
|
||||
GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3)
|
||||
@@ -6485,7 +6615,11 @@ internal class GlesRawRadianceStacker(
|
||||
)
|
||||
}
|
||||
|
||||
private fun setRadianceHighlightUniforms(program: Int, exposureRatio: Float) {
|
||||
private fun setRadianceHighlightUniforms(
|
||||
program: Int,
|
||||
exposureRatio: Float,
|
||||
shortNoiseModel: RawNoiseModel,
|
||||
) {
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uHighlightExposureRatio"),
|
||||
exposureRatio.coerceAtLeast(1f),
|
||||
@@ -6506,14 +6640,6 @@ internal class GlesRawRadianceStacker(
|
||||
uniformLocation(program, "uHighlightShortClipFull"),
|
||||
radianceFusionTuning.highlightShortClipFull.coerceIn(0f, 1f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uHighlightShortSignalStart"),
|
||||
radianceFusionTuning.highlightShortSignalStart.coerceIn(0f, 1f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uHighlightShortSignalFull"),
|
||||
radianceFusionTuning.highlightShortSignalFull.coerceIn(0f, 1f),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uHighlightFlowMinimumConfidence"),
|
||||
radianceFusionTuning.highlightFlowMinimumConfidence.coerceIn(0f, 1f),
|
||||
@@ -6525,6 +6651,53 @@ 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),
|
||||
)
|
||||
GLES31.glUniform1f(
|
||||
uniformLocation(program, "uHighlightClipNoiseSigmaFull"),
|
||||
radianceFusionTuning.highlightClipNoiseSigmaFull.coerceIn(
|
||||
0f,
|
||||
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(
|
||||
|
||||
@@ -5563,15 +5563,10 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
|
||||
private fun captureExposureProduct(result: CaptureResult): Double? {
|
||||
val exposureTime = result.get(CaptureResult.SENSOR_EXPOSURE_TIME)
|
||||
?.takeIf { it > 0L }
|
||||
?: return null
|
||||
val iso = result.get(CaptureResult.SENSOR_SENSITIVITY)
|
||||
?.takeIf { it > 0 }
|
||||
?: return null
|
||||
val postRawBoost = (result.get(CaptureResult.CONTROL_POST_RAW_SENSITIVITY_BOOST) ?: 100)
|
||||
.coerceAtLeast(1) / 100.0
|
||||
return exposureTime.toDouble() * iso.toDouble() * postRawBoost
|
||||
return RawExposureMath.productOrNull(
|
||||
exposureTimeNs = result.get(CaptureResult.SENSOR_EXPOSURE_TIME),
|
||||
sensitivityIso = result.get(CaptureResult.SENSOR_SENSITIVITY),
|
||||
)
|
||||
}
|
||||
|
||||
private fun rebuildHdrMetadataCaptureInfo(
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.hinnka.mycamera.camera
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
class RawExposureMathTest {
|
||||
@Test
|
||||
fun rawExposureProductContainsOnlyTimeAndSensorSensitivity() {
|
||||
assertEquals(800_000_000.0, RawExposureMath.product(10_000_000L, 80), 0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun invalidRawExposureMetadataDoesNotProduceNormalizationScale() {
|
||||
assertNull(RawExposureMath.productOrNull(0L, 80))
|
||||
assertNull(RawExposureMath.productOrNull(10_000_000L, 0))
|
||||
assertNull(RawExposureMath.productOrNull(null, 80))
|
||||
}
|
||||
}
|
||||
+31
-5
@@ -23,7 +23,12 @@ class GlesRawRadianceFusionShadersTest {
|
||||
assertTrue(propagation.contains("sampleValue.a * support"))
|
||||
assertTrue(propagation.contains("variance"))
|
||||
assertTrue(propagation.contains("uGuideProxy"))
|
||||
assertTrue(propagation.contains("min(centerGuide.g, neighborGuide.g) < 0.5"))
|
||||
assertTrue(propagation.contains("uAllowInvalidGuidePropagation"))
|
||||
assertTrue(propagation.contains("mix(0.35, 1.0"))
|
||||
assertTrue(
|
||||
RawRadianceFusionTuning().highlightFlowPropagationPasses <
|
||||
RawRadianceFusionTuning().longFlowPropagationPasses,
|
||||
)
|
||||
assertTrue(
|
||||
composition.contains("referenceToAnchorFlow.rg + anchorToShortFlow.rg"),
|
||||
)
|
||||
@@ -36,21 +41,37 @@ class GlesRawRadianceFusionShadersTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun highlightCompositionUsesOneSharedMaskAndShortExposureOutputDomain() {
|
||||
fun highlightCompositionUsesLocalEvidenceAndShortExposureOutputDomain() {
|
||||
val shader = GlesRawRadianceFusionShaders.normalize(
|
||||
showRejections = false,
|
||||
reconstructHighlights = true,
|
||||
)
|
||||
|
||||
assertTrue(shader.contains("shortNotClipped * shortHasSignal * highlightFlowConfidence"))
|
||||
assertTrue(shader.contains("uniform sampler2D uHighlightSupport"))
|
||||
assertTrue(shader.contains("uniform highp usampler2D uReferenceRaw"))
|
||||
assertTrue(shader.contains("float normalPeak = referenceRawPeak(referenceRawPosition)"))
|
||||
assertTrue(shader.contains("float coreShortSelection = saturatedCore * step(0.5, shortReliability)"))
|
||||
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("vec3 normalInShortDomain = rgb /"))
|
||||
assertTrue(shader.contains("mix(normalInShortDomain, highlightRgb, highlightWeight)"))
|
||||
assertFalse(shader.contains("vec3 highlightWeight"))
|
||||
assertFalse(shader.contains("step(0.5, shortReliability)"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun highlightSupportSeparatesNeedValidityPhotometryAndGeometry() {
|
||||
val shader = GlesRadianceHighlightShaders.buildSupport
|
||||
|
||||
assertTrue(shader.contains("normalNeedSum"))
|
||||
assertTrue(shader.contains("shortValiditySum"))
|
||||
assertTrue(shader.contains("normalizedResidual"))
|
||||
assertTrue(shader.contains("referenceSample.a + shortSample.a"))
|
||||
assertTrue(shader.contains("clamp(flow.a, 0.0, 1.0)"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -321,6 +342,11 @@ class GlesRawRadianceFusionShadersTest {
|
||||
),
|
||||
"fragment" to GlesRawRadianceFusionShaders.longEligibility,
|
||||
"fragment" to GlesRawRadianceFusionShaders.normalize(showRejections = false),
|
||||
"fragment" to GlesRadianceHighlightShaders.buildSupport,
|
||||
"fragment" to GlesRawRadianceFusionShaders.normalize(
|
||||
showRejections = false,
|
||||
reconstructHighlights = true,
|
||||
),
|
||||
)
|
||||
sources.forEach { (stage, source) ->
|
||||
val sourceFile = File.createTempFile("radiance-long-", ".$stage")
|
||||
|
||||
+55
-21
@@ -2,44 +2,78 @@ 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 acceptsSparseButSpatiallyDistributedValidatedFlow() {
|
||||
assertTrue(
|
||||
hasRadianceHighlightAlignmentSupport(
|
||||
validTileCount = 166,
|
||||
coveredQuadrants = 3,
|
||||
minimumValidTiles = 16,
|
||||
minimumQuadrants = 2,
|
||||
fun acceptsSupportInsideSmallLocalizedHighlight() {
|
||||
val admission = planRadianceHighlightAdmission(
|
||||
evidence = RawRadianceHighlightAdmissionEvidence(
|
||||
eligibleTileCount = 5,
|
||||
supportedTileCount = 2,
|
||||
),
|
||||
requirements = highlightRequirements,
|
||||
)
|
||||
|
||||
assertTrue(admission.accepted)
|
||||
assertEquals(0.4f, admission.eligibleCoverage, 0f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rejectsTooFewValidatedCorrespondences() {
|
||||
assertFalse(
|
||||
hasRadianceHighlightAlignmentSupport(
|
||||
validTileCount = 15,
|
||||
coveredQuadrants = 4,
|
||||
minimumValidTiles = 16,
|
||||
minimumQuadrants = 2,
|
||||
fun rejectsGoodWholeFrameFlowWhenHighlightItselfIsUnsupported() {
|
||||
val admission = planRadianceHighlightAdmission(
|
||||
evidence = RawRadianceHighlightAdmissionEvidence(
|
||||
eligibleTileCount = 5,
|
||||
supportedTileCount = 0,
|
||||
),
|
||||
requirements = highlightRequirements,
|
||||
)
|
||||
|
||||
assertFalse(admission.accepted)
|
||||
assertEquals(0f, admission.eligibleCoverage, 0f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rejectsSpatiallyConcentratedCorrespondences() {
|
||||
assertFalse(
|
||||
hasRadianceHighlightAlignmentSupport(
|
||||
validTileCount = 166,
|
||||
coveredQuadrants = 1,
|
||||
minimumValidTiles = 16,
|
||||
minimumQuadrants = 2,
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user