feat: radiance (4)
This commit is contained in:
1 parent
4d61151058
commit
7335f17013
10 files changed
+3103
-323
No files matched your search
@@ -1,7 +1,10 @@
|
||||
package com.hinnka.mycamera.processor
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@@ -137,6 +140,21 @@ class GlesRawStackerShaderTest {
|
||||
true,
|
||||
)
|
||||
invokePrivate(stacker, "normalizeRadianceTile", tile, 1, 1)
|
||||
val chromaPostprocessor = readPrivateAny(stacker, "radianceVgnChromaPostprocessor")
|
||||
assertNotNull("Radiance must initialize its VGN chroma postprocessor", chromaPostprocessor)
|
||||
val postprocessor = checkNotNull(chromaPostprocessor)
|
||||
invokePrivate(
|
||||
postprocessor,
|
||||
"capture",
|
||||
readPrivateInt(stacker, "outputTexture"),
|
||||
tile,
|
||||
)
|
||||
val chromaOutput = ByteBuffer.allocateDirect(96 * 96 * 3 * 2)
|
||||
.order(ByteOrder.nativeOrder())
|
||||
assertNotNull(
|
||||
invokePrivate(postprocessor, "processAndReadback", chromaOutput),
|
||||
)
|
||||
assertEquals(0, chromaOutput.position())
|
||||
} finally {
|
||||
invokePrivate(stacker, "release")
|
||||
}
|
||||
@@ -258,6 +276,13 @@ class GlesRawStackerShaderTest {
|
||||
}
|
||||
}
|
||||
|
||||
private fun readPrivateAny(target: Any, fieldName: String): Any? {
|
||||
return target.javaClass.getDeclaredField(fieldName).run {
|
||||
isAccessible = true
|
||||
get(target)
|
||||
}
|
||||
}
|
||||
|
||||
private fun assertUnifiedRcdPpgInitialized(stacker: GlesRawStacker, mode: String) {
|
||||
assertTrue(
|
||||
"$mode must initialize the shared RCD photo-border PPG program",
|
||||
|
||||
@@ -48,33 +48,19 @@ internal data class RadianceVgnGeometry(
|
||||
* Radiance-only reconstruction adapters.
|
||||
*
|
||||
* The reference path adapts a RAW tile to the canonical VGN work domain and converts Pass 3
|
||||
* YCCD directly to un-white-balanced camera RGB. The non-reference path never interpolates CFA
|
||||
* samples across phases: it first creates dense G plus native R-G/B-G samples, then resolves
|
||||
* each opponent plane exclusively on its own global two-pixel lattice.
|
||||
* YCCD directly to un-white-balanced camera RGB. The non-reference path uses the exact same
|
||||
* black-level, LSC, and calculation-WB conditioning before it creates dense G plus native R-G/B-G
|
||||
* samples. Each opponent plane is resolved exclusively on its own global two-pixel lattice and
|
||||
* remains in the calculation-WB domain until the post-warp fusion decoder returns it to camera RGB.
|
||||
*/
|
||||
internal object GlesRadianceReconstructionShaders {
|
||||
val vgnPrepareRegion: String = """
|
||||
#version 310 es
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
precision highp image2D;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16) in;
|
||||
layout(binding = 0) uniform highp usampler2D uRawRegion;
|
||||
layout(binding = 1) uniform highp sampler2D uLensShadingMap;
|
||||
layout(rgba16f, binding = 0) writeonly uniform image2D uPackedRaw;
|
||||
|
||||
uniform ivec2 uRegionSize;
|
||||
uniform ivec2 uFullImageSize;
|
||||
uniform ivec2 uGlobalOrigin;
|
||||
uniform ivec2 uPackedSize;
|
||||
uniform ivec2 uSourceOffset;
|
||||
uniform int uCfaPattern;
|
||||
uniform vec4 uBlackLevel;
|
||||
uniform float uWhiteLevel;
|
||||
uniform vec4 uCalculationGains;
|
||||
uniform int uReconstructHighlights;
|
||||
|
||||
/**
|
||||
* Shared standard-Bayer RAW conditioning for every Radiance reconstruction backend.
|
||||
*
|
||||
* Keep this as one shader fragment: reference/non-reference differences start at demosaic,
|
||||
* never at black level, LSC channel selection, or calculation white balance.
|
||||
*/
|
||||
private val standardBayerCalculationHelpers: String = """
|
||||
int bayerIndexAt(int pattern, ivec2 p) {
|
||||
int phase = (p.x & 1) + ((p.y & 1) << 1);
|
||||
if (pattern == 0) return phase;
|
||||
@@ -144,6 +130,31 @@ internal object GlesRadianceReconstructionShaders {
|
||||
8.0
|
||||
);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val vgnPrepareRegion: String = """
|
||||
#version 310 es
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
precision highp image2D;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16) in;
|
||||
layout(binding = 0) uniform highp usampler2D uRawRegion;
|
||||
layout(binding = 1) uniform highp sampler2D uLensShadingMap;
|
||||
layout(rgba16f, binding = 0) writeonly uniform image2D uPackedRaw;
|
||||
|
||||
uniform ivec2 uRegionSize;
|
||||
uniform ivec2 uFullImageSize;
|
||||
uniform ivec2 uGlobalOrigin;
|
||||
uniform ivec2 uPackedSize;
|
||||
uniform ivec2 uSourceOffset;
|
||||
uniform int uCfaPattern;
|
||||
uniform vec4 uBlackLevel;
|
||||
uniform float uWhiteLevel;
|
||||
uniform vec4 uCalculationGains;
|
||||
uniform int uReconstructHighlights;
|
||||
|
||||
$standardBayerCalculationHelpers
|
||||
|
||||
float opposedEstimate(ivec2 local, int ownColor, float fallback) {
|
||||
vec3 sum = vec3(0.0);
|
||||
@@ -247,76 +258,25 @@ internal object GlesRadianceReconstructionShaders {
|
||||
uniform int uCfaPattern;
|
||||
uniform vec4 uBlackLevel;
|
||||
uniform float uWhiteLevel;
|
||||
uniform vec4 uCalculationGains;
|
||||
|
||||
int bayerIndexAt(int pattern, ivec2 p) {
|
||||
int phase = (p.x & 1) + ((p.y & 1) << 1);
|
||||
if (pattern == 0) return phase;
|
||||
if (pattern == 1) {
|
||||
if (phase == 0) return 1;
|
||||
if (phase == 1) return 0;
|
||||
if (phase == 2) return 3;
|
||||
return 2;
|
||||
}
|
||||
if (pattern == 2) {
|
||||
if (phase == 0) return 2;
|
||||
if (phase == 1) return 3;
|
||||
if (phase == 2) return 0;
|
||||
return 1;
|
||||
}
|
||||
if (phase == 0) return 3;
|
||||
if (phase == 1) return 2;
|
||||
if (phase == 2) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lensChannelAt(ivec2 global) {
|
||||
int channel = bayerIndexAt(uCfaPattern, global);
|
||||
if (channel == 0 || channel == 3) return channel;
|
||||
return (global.y & 1) == 0 ? 1 : 2;
|
||||
}
|
||||
|
||||
int mirrorIndex(int value, int size) {
|
||||
if (size <= 1) return 0;
|
||||
int period = 2 * (size - 1);
|
||||
int wrapped = value % period;
|
||||
if (wrapped < 0) wrapped += period;
|
||||
return wrapped < size ? wrapped : period - wrapped;
|
||||
}
|
||||
|
||||
ivec2 clampLocal(ivec2 p) {
|
||||
return ivec2(
|
||||
mirrorIndex(p.x, uRegionSize.x),
|
||||
mirrorIndex(p.y, uRegionSize.y)
|
||||
);
|
||||
}
|
||||
|
||||
float cameraAt(ivec2 local) {
|
||||
local = clampLocal(local);
|
||||
ivec2 global = local + uGlobalOrigin;
|
||||
int channel = bayerIndexAt(uCfaPattern, global);
|
||||
float raw = float(texelFetch(uRawRegion, local, 0).r);
|
||||
float sensor = max(raw - uBlackLevel[channel], 0.0) /
|
||||
max(uWhiteLevel - uBlackLevel[channel], 1.0);
|
||||
vec2 uv = (vec2(global) + vec2(0.5)) / vec2(uFullImageSize);
|
||||
vec4 lsc = texture(uLensShadingMap, clamp(uv, vec2(0.0), vec2(1.0)));
|
||||
return max(sensor * max(lsc[lensChannelAt(global)], 0.0), 0.0);
|
||||
}
|
||||
$standardBayerCalculationHelpers
|
||||
|
||||
float denseGreenAt(ivec2 p) {
|
||||
p = clampLocal(p);
|
||||
ivec2 global = p + uGlobalOrigin;
|
||||
int channel = bayerIndexAt(uCfaPattern, global);
|
||||
float center = cameraAt(p);
|
||||
float center = calculationAt(p);
|
||||
if (channel == 1 || channel == 2) return center;
|
||||
|
||||
float gL = cameraAt(p + ivec2(-1, 0));
|
||||
float gR = cameraAt(p + ivec2(1, 0));
|
||||
float gU = cameraAt(p + ivec2(0, -1));
|
||||
float gD = cameraAt(p + ivec2(0, 1));
|
||||
float cL2 = cameraAt(p + ivec2(-2, 0));
|
||||
float cR2 = cameraAt(p + ivec2(2, 0));
|
||||
float cU2 = cameraAt(p + ivec2(0, -2));
|
||||
float cD2 = cameraAt(p + ivec2(0, 2));
|
||||
float gL = calculationAt(p + ivec2(-1, 0));
|
||||
float gR = calculationAt(p + ivec2(1, 0));
|
||||
float gU = calculationAt(p + ivec2(0, -1));
|
||||
float gD = calculationAt(p + ivec2(0, 1));
|
||||
float cL2 = calculationAt(p + ivec2(-2, 0));
|
||||
float cR2 = calculationAt(p + ivec2(2, 0));
|
||||
float cU2 = calculationAt(p + ivec2(0, -2));
|
||||
float cD2 = calculationAt(p + ivec2(0, 2));
|
||||
float horizontalLinear = 0.5 * (gL + gR);
|
||||
float verticalLinear = 0.5 * (gU + gD);
|
||||
float horizontalCorrection = 0.25 * (2.0 * center - cL2 - cR2);
|
||||
@@ -352,9 +312,9 @@ internal object GlesRadianceReconstructionShaders {
|
||||
ivec2 global = local + uGlobalOrigin;
|
||||
int channel = bayerIndexAt(uCfaPattern, global);
|
||||
float green = denseGreenAt(local);
|
||||
float native = cameraAt(local);
|
||||
float redGreen = channel == 0 ? native - green : 0.0;
|
||||
float blueGreen = channel == 3 ? native - green : 0.0;
|
||||
float nativeCalculation = calculationAt(local);
|
||||
float redGreen = channel == 0 ? nativeCalculation - green : 0.0;
|
||||
float blueGreen = channel == 3 ? nativeCalculation - green : 0.0;
|
||||
imageStore(uSemanticSeed, local, vec4(green, redGreen, blueGreen, 1.0));
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
+1369
File diff suppressed because it is too large.
Load diff
@@ -131,39 +131,104 @@ internal fun hasRadianceHighlightAlignmentSupport(
|
||||
coveredQuadrants >= minimumQuadrants.coerceIn(1, 4)
|
||||
}
|
||||
|
||||
internal enum class RawRadianceLongAdmissionMode {
|
||||
REJECTED,
|
||||
VALIDATED_FLOW,
|
||||
}
|
||||
|
||||
internal data class RawRadianceLongAdmissionEvidence(
|
||||
val validTileCount: Int,
|
||||
val coveredQuadrants: Int,
|
||||
val eligibleTileCount: Int,
|
||||
val eligibleQuadrants: Int,
|
||||
val referenceObservableTileCount: Int,
|
||||
val currentObservableTileCount: Int,
|
||||
)
|
||||
|
||||
internal data class RawRadianceLongAdmissionRequirements(
|
||||
val minimumValidTiles: Int,
|
||||
val minimumQuadrants: Int,
|
||||
val minimumEligibleCoverage: Float,
|
||||
val validatedPrecisionWeightCap: Float,
|
||||
)
|
||||
|
||||
internal enum class RawRadianceLongRejectionReason {
|
||||
REFERENCE_PROXY_UNOBSERVABLE,
|
||||
LONG_PROXY_UNOBSERVABLE,
|
||||
MUTUAL_OBSERVABILITY_INSUFFICIENT,
|
||||
VALID_FLOW_INSUFFICIENT,
|
||||
SPATIAL_COVERAGE_INSUFFICIENT,
|
||||
ELIGIBLE_COVERAGE_INSUFFICIENT,
|
||||
}
|
||||
|
||||
internal data class RawRadianceLongAdmission(
|
||||
val mode: RawRadianceLongAdmissionMode,
|
||||
val frameWeight: Float,
|
||||
val precisionWeightCap: Float,
|
||||
val eligibleCoverage: Float,
|
||||
val requiredQuadrants: Int,
|
||||
val rejectionReasons: List<RawRadianceLongRejectionReason>,
|
||||
)
|
||||
|
||||
internal fun planRadianceLongAdmission(
|
||||
validTileCount: Int,
|
||||
coveredQuadrants: Int,
|
||||
eligibleTileCount: Int,
|
||||
eligibleQuadrants: Int,
|
||||
minimumValidTiles: Int,
|
||||
minimumQuadrants: Int,
|
||||
minimumEligibleCoverage: Float,
|
||||
evidence: RawRadianceLongAdmissionEvidence,
|
||||
requirements: RawRadianceLongAdmissionRequirements,
|
||||
): RawRadianceLongAdmission {
|
||||
val eligibleCoverage = if (eligibleTileCount > 0) {
|
||||
validTileCount.toFloat() / eligibleTileCount
|
||||
val eligibleCoverage = if (evidence.eligibleTileCount > 0) {
|
||||
evidence.validTileCount.toFloat() / evidence.eligibleTileCount
|
||||
} else {
|
||||
0f
|
||||
}
|
||||
val normalizedEligibleQuadrants = eligibleQuadrants.coerceIn(0, 4)
|
||||
val normalizedEligibleQuadrants = evidence.eligibleQuadrants.coerceIn(0, 4)
|
||||
val requiredQuadrants = minOf(
|
||||
minimumQuadrants.coerceIn(1, 4),
|
||||
requirements.minimumQuadrants.coerceIn(1, 4),
|
||||
normalizedEligibleQuadrants,
|
||||
).coerceAtLeast(2)
|
||||
val accepted = normalizedEligibleQuadrants >= 2 &&
|
||||
validTileCount >= minimumValidTiles.coerceAtLeast(1) &&
|
||||
coveredQuadrants >= requiredQuadrants &&
|
||||
eligibleCoverage >= minimumEligibleCoverage.coerceIn(0f, 1f)
|
||||
val validatedFlowAccepted = normalizedEligibleQuadrants >= 2 &&
|
||||
evidence.validTileCount >= requirements.minimumValidTiles.coerceAtLeast(1) &&
|
||||
evidence.coveredQuadrants >= requiredQuadrants &&
|
||||
eligibleCoverage >= requirements.minimumEligibleCoverage.coerceIn(0f, 1f)
|
||||
val minimumValidTiles = requirements.minimumValidTiles.coerceAtLeast(1)
|
||||
val rejectionReasons = if (validatedFlowAccepted) {
|
||||
emptyList()
|
||||
} else {
|
||||
buildList {
|
||||
if (evidence.referenceObservableTileCount < minimumValidTiles) {
|
||||
add(RawRadianceLongRejectionReason.REFERENCE_PROXY_UNOBSERVABLE)
|
||||
}
|
||||
if (evidence.currentObservableTileCount < minimumValidTiles) {
|
||||
add(RawRadianceLongRejectionReason.LONG_PROXY_UNOBSERVABLE)
|
||||
}
|
||||
if (evidence.eligibleTileCount < minimumValidTiles) {
|
||||
add(RawRadianceLongRejectionReason.MUTUAL_OBSERVABILITY_INSUFFICIENT)
|
||||
}
|
||||
if (evidence.validTileCount < minimumValidTiles) {
|
||||
add(RawRadianceLongRejectionReason.VALID_FLOW_INSUFFICIENT)
|
||||
}
|
||||
if (normalizedEligibleQuadrants < 2 || evidence.coveredQuadrants < requiredQuadrants) {
|
||||
add(RawRadianceLongRejectionReason.SPATIAL_COVERAGE_INSUFFICIENT)
|
||||
}
|
||||
if (eligibleCoverage < requirements.minimumEligibleCoverage.coerceIn(0f, 1f)) {
|
||||
add(RawRadianceLongRejectionReason.ELIGIBLE_COVERAGE_INSUFFICIENT)
|
||||
}
|
||||
}
|
||||
}
|
||||
val mode = if (validatedFlowAccepted) {
|
||||
RawRadianceLongAdmissionMode.VALIDATED_FLOW
|
||||
} else {
|
||||
RawRadianceLongAdmissionMode.REJECTED
|
||||
}
|
||||
return RawRadianceLongAdmission(
|
||||
frameWeight = if (accepted) 1f else 0f,
|
||||
mode = mode,
|
||||
frameWeight = if (validatedFlowAccepted) 1f else 0f,
|
||||
precisionWeightCap = if (validatedFlowAccepted) {
|
||||
requirements.validatedPrecisionWeightCap.coerceAtLeast(1f)
|
||||
} else {
|
||||
0f
|
||||
},
|
||||
eligibleCoverage = eligibleCoverage,
|
||||
requiredQuadrants = requiredQuadrants,
|
||||
rejectionReasons = rejectionReasons,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -394,6 +459,7 @@ enum class RawFusionPipeline {
|
||||
*/
|
||||
data class RawRadianceFusionTuning(
|
||||
val tileCoreSizeRawPx: Int = 1024,
|
||||
val vgnChromaPostprocessEnabled: Boolean = true,
|
||||
val denoiseSigmaRawPx: Float = 1.10f,
|
||||
val denoiseSteeringStrength: Float = 0.48f,
|
||||
val robustnessSpatialMix: Float = 0.68f,
|
||||
@@ -402,7 +468,6 @@ data class RawRadianceFusionTuning(
|
||||
val detailConfidenceStart: Float = 0.18f,
|
||||
val detailConfidenceFull: Float = 1.45f,
|
||||
val referenceDetailFloor: Float = 0.18f,
|
||||
val bilateralNoiseScale: Float = 8.0f,
|
||||
val detailChromaStrength: Float = 0.0f,
|
||||
val chromaConsistencySigmaStart: Float = 3.0f,
|
||||
val chromaConsistencySigmaFull: Float = 6.0f,
|
||||
@@ -416,11 +481,16 @@ data class RawRadianceFusionTuning(
|
||||
val longFlowFbConsistencyStartPx: Float = 0.75f,
|
||||
val longFlowFbConsistencyFullPx: Float = 2.0f,
|
||||
val longFlowMinimumConfidence: Float = 0.01f,
|
||||
val longFlowFullConfidence: Float = 0.05f,
|
||||
val longFlowMinimumValidTiles: Int = 64,
|
||||
val longFlowMinimumQuadrants: Int = 3,
|
||||
val longEligibilityMinimumSupport: Float = 0.02f,
|
||||
val longEligibilityMinimumTilesPerQuadrant: Int = 16,
|
||||
val longFlowMinimumEligibleCoverage: Float = 0.01f,
|
||||
val longRegionalStructureSnrStart: Float = 1.0f,
|
||||
val longRegionalStructureSnrFull: Float = 2.0f,
|
||||
val longFineRefinementConfidenceStart: Float = 0.01f,
|
||||
val longFineRefinementConfidenceFull: Float = 0.05f,
|
||||
val highlightMinExposureRatio: Float = 1.2f,
|
||||
val highlightMaxExposureRatio: Float = 8.0f,
|
||||
val highlightNormalClipStart: Float = 0.90f,
|
||||
@@ -499,8 +569,8 @@ internal object GlesRawRadianceFusionShaders {
|
||||
int sampleSpacing = max(uTileSize / 4, 1);
|
||||
float eligibilitySum = 0.0;
|
||||
float validitySum = 0.0;
|
||||
float observabilitySum = 0.0;
|
||||
float insideSum = 0.0;
|
||||
float referenceObservabilitySum = 0.0;
|
||||
float currentObservabilitySum = 0.0;
|
||||
float sampleCount = 0.0;
|
||||
for (int y = -2; y <= 2; ++y) {
|
||||
for (int x = -2; x <= 2; ++x) {
|
||||
@@ -513,20 +583,24 @@ internal object GlesRawRadianceFusionShaders {
|
||||
vec4 currentSample = proxyAt(uCurrentProxy, currentPosition);
|
||||
float validity = inside ?
|
||||
min(referenceSample.g, currentSample.g) : 0.0;
|
||||
float observability = inside ?
|
||||
min(referenceSample.b, currentSample.b) : 0.0;
|
||||
float referenceObservability = inside ? referenceSample.b : 0.0;
|
||||
float currentObservability = inside ? currentSample.b : 0.0;
|
||||
float observability = min(
|
||||
referenceObservability,
|
||||
currentObservability
|
||||
);
|
||||
eligibilitySum += validity * observability;
|
||||
validitySum += validity;
|
||||
observabilitySum += observability;
|
||||
insideSum += inside ? 1.0 : 0.0;
|
||||
referenceObservabilitySum += referenceObservability;
|
||||
currentObservabilitySum += currentObservability;
|
||||
sampleCount += 1.0;
|
||||
}
|
||||
}
|
||||
fragColor = vec4(
|
||||
eligibilitySum,
|
||||
validitySum,
|
||||
observabilitySum,
|
||||
insideSum
|
||||
referenceObservabilitySum,
|
||||
currentObservabilitySum
|
||||
) / max(sampleCount, 1.0);
|
||||
}
|
||||
""".trimIndent()
|
||||
@@ -703,6 +777,9 @@ internal object GlesRawRadianceFusionShaders {
|
||||
uniform ivec2 uPlaneSize;
|
||||
uniform int uTileSize;
|
||||
uniform int uAnchorIsReference;
|
||||
uniform int uUseBottleneckConfidence;
|
||||
uniform float uConfidenceStart;
|
||||
uniform float uConfidenceFull;
|
||||
out vec4 fragColor;
|
||||
|
||||
vec4 flowAt(sampler2D flowTexture, vec2 planePosition) {
|
||||
@@ -711,6 +788,14 @@ internal object GlesRawRadianceFusionShaders {
|
||||
return texture(flowTexture, clamp(uv, vec2(0.0), vec2(1.0)));
|
||||
}
|
||||
|
||||
float normalizedEdgeConfidence(float confidence) {
|
||||
return smoothstep(
|
||||
min(uConfidenceStart, uConfidenceFull),
|
||||
max(uConfidenceStart, uConfidenceFull),
|
||||
confidence
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
ivec2 tile = ivec2(gl_FragCoord.xy);
|
||||
vec2 referencePosition = min(
|
||||
@@ -726,11 +811,19 @@ internal object GlesRawRadianceFusionShaders {
|
||||
anchorPosition.y <= float(uPlaneSize.y - 1);
|
||||
vec4 anchorToShortFlow = inside ?
|
||||
flowAt(uAnchorToShortFlow, anchorPosition) : vec4(0.0);
|
||||
float multipliedConfidence = referenceToAnchorFlow.a * anchorToShortFlow.a;
|
||||
float bottleneckConfidence = min(
|
||||
uAnchorIsReference != 0 ? 1.0 :
|
||||
normalizedEdgeConfidence(referenceToAnchorFlow.a),
|
||||
normalizedEdgeConfidence(anchorToShortFlow.a)
|
||||
);
|
||||
float pathConfidence = uUseBottleneckConfidence != 0 ?
|
||||
bottleneckConfidence : multipliedConfidence;
|
||||
fragColor = vec4(
|
||||
referenceToAnchorFlow.rg + anchorToShortFlow.rg,
|
||||
max(referenceToAnchorFlow.b, anchorToShortFlow.b),
|
||||
clamp(
|
||||
referenceToAnchorFlow.a * anchorToShortFlow.a * (inside ? 1.0 : 0.0),
|
||||
pathConfidence * (inside ? 1.0 : 0.0),
|
||||
0.0,
|
||||
1.0
|
||||
)
|
||||
@@ -1054,6 +1147,7 @@ internal object GlesRawRadianceFusionShaders {
|
||||
uniform int uIsLongFrame;
|
||||
uniform int uSemanticEncoding;
|
||||
uniform int uCfaPattern;
|
||||
uniform vec3 uCalculationGains;
|
||||
uniform float uBlackLevel[4];
|
||||
uniform float uWhiteLevel;
|
||||
uniform float uNoiseAlphaByChannel[4];
|
||||
@@ -1104,10 +1198,10 @@ internal object GlesRawRadianceFusionShaders {
|
||||
vec2(uOutputSize) - vec2(0.5);
|
||||
}
|
||||
|
||||
vec2 flowAt(vec2 planePos) {
|
||||
vec4 flowEvidenceAt(vec2 planePos) {
|
||||
vec2 grid = planePos / float(uTileSize) - vec2(0.5);
|
||||
vec2 uv = (grid + vec2(0.5)) / vec2(uGridSize);
|
||||
return texture(uFlowGrid, clamp(uv, vec2(0.0), vec2(1.0))).rg;
|
||||
return texture(uFlowGrid, clamp(uv, vec2(0.0), vec2(1.0)));
|
||||
}
|
||||
|
||||
float mapAt(sampler2D tex, vec2 planePos, ivec2 size) {
|
||||
@@ -1162,12 +1256,27 @@ internal object GlesRawRadianceFusionShaders {
|
||||
storageSize;
|
||||
vec3 encoded = texture(uRcdRgbTile, uv).rgb;
|
||||
if (uIsReference != 0 || uSemanticEncoding == 0) {
|
||||
return clamp(encoded, 0.0, 1.0);
|
||||
// The reconstruction texture is FP16 and intentionally carries linear
|
||||
// overrange. A long exposure can exceed the normal-frame output domain after
|
||||
// LSC while every sensor sample is still below white level. Clamping here would
|
||||
// clip the channels independently before exposure normalization and permanently
|
||||
// turn a neutral bright sample magenta/green.
|
||||
return max(encoded, vec3(0.0));
|
||||
}
|
||||
// Non-reference tiles encode (G, R-G, B-G). Decoding only after the semantic
|
||||
// planes have been warped/interpolated keeps CFA phase out of the fusion domain.
|
||||
return clamp(vec3(encoded.r + encoded.g, encoded.r, encoded.r + encoded.b),
|
||||
0.0, 1.0);
|
||||
// Non-reference tiles encode calculation-WB (G, R-G, B-G). Keep that semantic
|
||||
// representation through texture interpolation and flow warping, then decode and
|
||||
// return to the same un-white-balanced camera-RGB contract as the VGN reference.
|
||||
vec3 calculationRgb = vec3(
|
||||
encoded.r + encoded.g,
|
||||
encoded.r,
|
||||
encoded.r + encoded.b
|
||||
);
|
||||
// Preserve the semantic proxy's overrange for the same reason. The caller applies
|
||||
// uExposureScale to both detail and denoise estimates before the only [0, 1] clamp.
|
||||
return max(
|
||||
calculationRgb / max(uCalculationGains, vec3(1e-6)),
|
||||
vec3(0.0)
|
||||
);
|
||||
}
|
||||
|
||||
vec3 kernelMatrix(vec4 params) {
|
||||
@@ -1336,9 +1445,11 @@ internal object GlesRawRadianceFusionShaders {
|
||||
vec2 planePos = refRaw * 0.5;
|
||||
vec2 sourceRaw = refRaw;
|
||||
vec4 tileConfidence = vec4(1.0, 1.0, 0.0, 0.0);
|
||||
vec4 flowEvidence = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
float robust = 1.0;
|
||||
if (uIsReference == 0) {
|
||||
sourceRaw += flowAt(planePos) * 2.0;
|
||||
flowEvidence = flowEvidenceAt(planePos);
|
||||
sourceRaw += flowEvidence.rg * 2.0;
|
||||
if (sourceRaw.x < -0.5 || sourceRaw.y < -0.5 ||
|
||||
sourceRaw.x > float(uImageSize.x) - 0.5 ||
|
||||
sourceRaw.y > float(uImageSize.y) - 0.5) {
|
||||
@@ -1431,9 +1542,17 @@ internal object GlesRawRadianceFusionShaders {
|
||||
float longNrRoleWeight = uIsLongFrame != 0 ? longClipConfidence : 1.0;
|
||||
float longDetailRoleWeight = uIsLongFrame != 0 ?
|
||||
longClipConfidence * clamp(uLongDetailWeightScale, 0.0, 1.0) : 1.0;
|
||||
// Long frames may be reached through reference -> normal anchor -> long. Their
|
||||
// composed confidence is normalized per validated edge and represents whether
|
||||
// the complete geometric path is locally supported. Applying it after final
|
||||
// reference-domain refinement prevents a high precision weight from reviving a
|
||||
// weak hand-shake alignment at static high-contrast edges.
|
||||
float longPathConfidence = uIsLongFrame != 0 ?
|
||||
clamp(flowEvidence.a, 0.0, 1.0) : 1.0;
|
||||
float nrCoverage = clamp(tileConfidence.r * robust, 0.0, 1.0) *
|
||||
clamp(uRegistrationNrWeight, 0.0, 1.0);
|
||||
float detailCoverage = clamp(tileConfidence.g * robust, 0.0, 1.0);
|
||||
clamp(uRegistrationNrWeight, 0.0, 1.0) * longPathConfidence;
|
||||
float detailCoverage = clamp(tileConfidence.g * robust, 0.0, 1.0) *
|
||||
longPathConfidence;
|
||||
$rejectionAssignment
|
||||
float staticConfidence = denoiseStaticConfidence(tileConfidence.r, robust);
|
||||
float sharedNrWeight = uFrameWeight * sharedPrecision * sharedConsistency *
|
||||
@@ -1864,12 +1983,6 @@ internal object GlesRawRadianceFusionShaders {
|
||||
uniform float uDetailConfidenceFull;
|
||||
uniform float uReferenceDetailFloor;
|
||||
uniform float uDetailChromaStrength;
|
||||
uniform float uBilateralNoiseScale;
|
||||
uniform float uFinalSmoothStrength;
|
||||
uniform float uLowLightSignalLow;
|
||||
uniform float uLowLightSignalHigh;
|
||||
uniform float uLowLightSmoothBoost;
|
||||
uniform float uMaxSmoothStrength;
|
||||
uniform vec3 uCalculationGains;
|
||||
uniform ivec2 uAccumulatorOrigin;
|
||||
uniform ivec2 uAccumulatorSize;
|
||||
@@ -1897,6 +2010,14 @@ internal object GlesRawRadianceFusionShaders {
|
||||
return clamp(p, ivec2(0), uAccumulatorSize - ivec2(1));
|
||||
}
|
||||
|
||||
vec3 referenceBaseAt(ivec2 p) {
|
||||
return clamp(
|
||||
texelFetch(uReferenceBase, clampAccumulatorPos(p), 0).rgb,
|
||||
0.0,
|
||||
1.0
|
||||
);
|
||||
}
|
||||
|
||||
vec3 sensorNoise(vec3 rgb) {
|
||||
return max(vec3(
|
||||
uNoiseAlphaByChannel[0] * rgb.r + uNoiseBetaByChannel[0],
|
||||
@@ -1933,7 +2054,7 @@ internal object GlesRawRadianceFusionShaders {
|
||||
|
||||
NrState nrStateAt(ivec2 p) {
|
||||
p = clampAccumulatorPos(p);
|
||||
vec3 base = clamp(texelFetch(uReferenceBase, p, 0).rgb, 0.0, 1.0);
|
||||
vec3 base = referenceBaseAt(p);
|
||||
WeightedRgb sampleValue = packedRgbWeightAt(
|
||||
uNrSumRg,
|
||||
uNrSumBw,
|
||||
@@ -1990,40 +2111,14 @@ internal object GlesRawRadianceFusionShaders {
|
||||
ivec2 outputP = ivec2(gl_FragCoord.xy) + uOutputOrigin;
|
||||
ivec2 p = outputP - uAccumulatorOrigin;
|
||||
NrState center = nrStateAt(p);
|
||||
// Keep normalization point-local. Post-fusion spatial denoise is owned exclusively by
|
||||
// GlesRadianceVgnChromaPostprocessor; neighboring reference samples below only classify
|
||||
// structure for detail confidence and never contribute color to this output pixel.
|
||||
vec3 safeCenter = mix(center.base, center.nr, center.confidence);
|
||||
float rangeVariance = max(
|
||||
dot(center.noise / center.effectiveSupport, vec3(0.3333333)) *
|
||||
max(uBilateralNoiseScale, 1.0),
|
||||
1e-7
|
||||
);
|
||||
vec3 bilateralSum = vec3(0.0);
|
||||
float bilateralWeight = 0.0;
|
||||
vec3 baseLeft = center.base;
|
||||
vec3 baseRight = center.base;
|
||||
vec3 baseUp = center.base;
|
||||
vec3 baseDown = center.base;
|
||||
for (int y = -1; y <= 1; ++y) {
|
||||
for (int x = -1; x <= 1; ++x) {
|
||||
ivec2 q = p + ivec2(x, y);
|
||||
NrState neighbor = nrStateAt(q);
|
||||
if (x == -1 && y == 0) baseLeft = neighbor.base;
|
||||
if (x == 1 && y == 0) baseRight = neighbor.base;
|
||||
if (x == 0 && y == -1) baseDown = neighbor.base;
|
||||
if (x == 0 && y == 1) baseUp = neighbor.base;
|
||||
vec3 guideDelta = neighbor.base - center.base;
|
||||
float spatial = (x == 0 && y == 0) ? 4.0 :
|
||||
((x == 0 || y == 0) ? 2.0 : 1.0);
|
||||
float range = exp(-dot(guideDelta, guideDelta) / rangeVariance);
|
||||
float weight = spatial * range;
|
||||
bilateralSum += mix(
|
||||
neighbor.base,
|
||||
neighbor.nr,
|
||||
neighbor.confidence
|
||||
) * weight;
|
||||
bilateralWeight += weight;
|
||||
}
|
||||
}
|
||||
vec3 bilateral = bilateralSum / max(bilateralWeight, 1e-6);
|
||||
vec3 baseLeft = referenceBaseAt(p + ivec2(-1, 0));
|
||||
vec3 baseRight = referenceBaseAt(p + ivec2(1, 0));
|
||||
vec3 baseUp = referenceBaseAt(p + ivec2(0, 1));
|
||||
vec3 baseDown = referenceBaseAt(p + ivec2(0, -1));
|
||||
vec3 gradientX = 0.5 * (baseRight - baseLeft);
|
||||
vec3 gradientY = 0.5 * (baseUp - baseDown);
|
||||
float gradient = sqrt(
|
||||
@@ -2038,18 +2133,6 @@ internal object GlesRawRadianceFusionShaders {
|
||||
6.0 * finalNoiseStd + 1e-5,
|
||||
gradient
|
||||
);
|
||||
float luma = dot(safeCenter, vec3(0.2126, 0.7152, 0.0722));
|
||||
float shadow = 1.0 - smoothstep(
|
||||
min(uLowLightSignalLow, uLowLightSignalHigh),
|
||||
max(uLowLightSignalLow, uLowLightSignalHigh),
|
||||
luma
|
||||
);
|
||||
float spatialSmooth = uFinalSmoothStrength *
|
||||
(0.35 + uLowLightSmoothBoost * shadow) *
|
||||
(1.0 - 0.82 * structure) *
|
||||
(1.0 + 0.35 * (1.0 - center.lumaConfidence));
|
||||
spatialSmooth = clamp(spatialSmooth, 0.0, uMaxSmoothStrength);
|
||||
vec3 nrSpatial = mix(safeCenter, bilateral, spatialSmooth);
|
||||
|
||||
WeightedRgb detailSample = packedRgbWeightAt(
|
||||
uDetailSumRg,
|
||||
@@ -2081,7 +2164,7 @@ internal object GlesRawRadianceFusionShaders {
|
||||
detailLumaSupport * centerLumaConsistency
|
||||
);
|
||||
vec3 calculationGains = max(uCalculationGains, vec3(1e-6));
|
||||
vec3 nrCalculation = nrSpatial * calculationGains;
|
||||
vec3 nrCalculation = safeCenter * calculationGains;
|
||||
vec3 detailCalculation = detail * calculationGains;
|
||||
float detailLumaDelta = abs(dot(
|
||||
detailCalculation - nrCalculation,
|
||||
@@ -2122,7 +2205,7 @@ internal object GlesRawRadianceFusionShaders {
|
||||
);
|
||||
vec3 lumaDetail =
|
||||
(nrCalculation + vec3(signedLumaDetail)) / calculationGains;
|
||||
vec3 fullRgbDetail = nrSpatial + detailConfidence * (detail - nrSpatial);
|
||||
vec3 fullRgbDetail = safeCenter + detailConfidence * (detail - safeCenter);
|
||||
float chromaConfidence = clamp(uDetailChromaStrength, 0.0, 1.0) *
|
||||
min(min(detailSupport.r, detailSupport.g), detailSupport.b) *
|
||||
min(min(center.consistency.r, center.consistency.g), center.consistency.b);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,8 +1,10 @@
|
||||
package com.hinnka.mycamera.processor
|
||||
|
||||
import java.io.File
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assume.assumeTrue
|
||||
import org.junit.Test
|
||||
|
||||
class GlesRadianceReconstructionTest {
|
||||
@@ -35,8 +37,9 @@ class GlesRadianceReconstructionTest {
|
||||
|
||||
assertTrue(seed.contains("ivec2 global = local + uGlobalOrigin"))
|
||||
assertTrue(seed.contains("int mirrorIndex(int value, int size)"))
|
||||
assertTrue(seed.contains("float redGreen = channel == 0 ? native - green : 0.0"))
|
||||
assertTrue(seed.contains("float blueGreen = channel == 3 ? native - green : 0.0"))
|
||||
assertTrue(seed.contains("float nativeCalculation = calculationAt(local)"))
|
||||
assertTrue(seed.contains("float redGreen = channel == 0 ? nativeCalculation - green : 0.0"))
|
||||
assertTrue(seed.contains("float blueGreen = channel == 3 ? nativeCalculation - green : 0.0"))
|
||||
assertTrue(resolve.contains("ivec2 channelPhase(int channel)"))
|
||||
assertTrue(resolve.contains("resolveOpponent(global, 0, 1, green)"))
|
||||
assertTrue(resolve.contains("resolveOpponent(global, 3, 2, green)"))
|
||||
@@ -44,6 +47,21 @@ class GlesRadianceReconstructionTest {
|
||||
assertFalse(resolve.contains("bayerIndexAt(uCfaPattern, local)"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun referenceAndSemanticPathsShareLscAndCalculationWhiteBalanceConditioning() {
|
||||
val reference = GlesRadianceReconstructionShaders.vgnPrepareRegion
|
||||
val semantic = GlesRadianceReconstructionShaders.semanticSeed
|
||||
|
||||
listOf(reference, semantic).forEach { shader ->
|
||||
assertTrue(shader.contains("uniform highp sampler2D uLensShadingMap"))
|
||||
assertTrue(shader.contains("uniform vec4 uCalculationGains"))
|
||||
assertTrue(shader.contains("float calculationAt(ivec2 local)"))
|
||||
assertTrue(shader.contains("max(lsc[lensChannelAt(global)], 0.0)"))
|
||||
assertTrue(shader.contains("max(uCalculationGains[channel], 1e-6)"))
|
||||
}
|
||||
assertFalse(semantic.contains("float cameraAt"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun semanticDenseGreenCannotCreateAnExtremumOutsideNativeGreenNeighbors() {
|
||||
val seed = GlesRadianceReconstructionShaders.semanticSeed
|
||||
@@ -85,4 +103,50 @@ class GlesRadianceReconstructionTest {
|
||||
assertFalse(prepare.contains("COLOR_NOISE"))
|
||||
assertFalse(finish.contains("IIR"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun generatedReconstructionShadersPassAvailableNdkValidator() {
|
||||
val sdkRoot = System.getenv("ANDROID_SDK_ROOT") ?: System.getenv("ANDROID_HOME")
|
||||
val validator = sdkRoot?.let(::File)
|
||||
?.resolve("ndk")
|
||||
?.listFiles()
|
||||
?.sortedByDescending { it.name }
|
||||
?.asSequence()
|
||||
?.mapNotNull { ndk ->
|
||||
ndk.resolve("shader-tools")
|
||||
.walkTopDown()
|
||||
.firstOrNull { it.name == "glslc" && it.canExecute() }
|
||||
}
|
||||
?.firstOrNull()
|
||||
assumeTrue("Android NDK glslc is unavailable", validator != null)
|
||||
|
||||
val sources = listOf(
|
||||
GlesRadianceReconstructionShaders.vgnPrepareRegion,
|
||||
GlesRadianceReconstructionShaders.vgnYccdToCameraRgb,
|
||||
GlesRadianceReconstructionShaders.semanticSeed,
|
||||
GlesRadianceReconstructionShaders.semanticResolve,
|
||||
)
|
||||
sources.forEachIndexed { index, source ->
|
||||
val sourceFile = File.createTempFile("radiance-reconstruction-$index-", ".compute")
|
||||
val outputFile = File.createTempFile("radiance-reconstruction-$index-", ".spv")
|
||||
try {
|
||||
sourceFile.writeText(source)
|
||||
val process = ProcessBuilder(
|
||||
checkNotNull(validator).absolutePath,
|
||||
"--target-env=opengl",
|
||||
"-fauto-map-locations",
|
||||
"-fauto-bind-uniforms",
|
||||
"-fshader-stage=compute",
|
||||
sourceFile.absolutePath,
|
||||
"-o",
|
||||
outputFile.absolutePath,
|
||||
).redirectErrorStream(true).start()
|
||||
val output = process.inputStream.bufferedReader().use { it.readText() }
|
||||
assertEquals("shader $index: $output", 0, process.waitFor())
|
||||
} finally {
|
||||
sourceFile.delete()
|
||||
outputFile.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
package com.hinnka.mycamera.processor
|
||||
|
||||
import java.io.File
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assume.assumeTrue
|
||||
import org.junit.Test
|
||||
|
||||
class GlesRadianceVgnChromaPostprocessorTest {
|
||||
@Test
|
||||
fun postprocessorKeepsWbPairedAndDoesNotReapplyLensShading() {
|
||||
val seed = GlesRadianceVgnChromaShaders.seed
|
||||
val finish = GlesRadianceVgnChromaShaders.finalCameraRgb
|
||||
|
||||
assertTrue(seed.contains("cameraRgb * uCalculationGains"))
|
||||
assertTrue(finish.contains("/\n max(uCalculationGains"))
|
||||
assertTrue(seed.contains("directionMaskAt(p)"))
|
||||
assertTrue(seed.contains("count << 8"))
|
||||
assertTrue(seed.contains("const float finiteScale = 65504.0 / 65535.0"))
|
||||
assertTrue(!seed.contains("vec3(imageLoad(uCameraRgb"))
|
||||
assertTrue(!seed.contains("LensShading"))
|
||||
assertTrue(!finish.contains("LensShading"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun everyFilterUsesGlobalCoordinatesOverTiledStorage() {
|
||||
val globalShaders = listOf(
|
||||
GlesRadianceVgnChromaShaders.seed,
|
||||
GlesRadianceVgnChromaShaders.colorNoise1,
|
||||
GlesRadianceVgnChromaShaders.colorNoise2,
|
||||
GlesRadianceVgnChromaShaders.colorNoise3Smooth,
|
||||
GlesRadianceVgnChromaShaders.restoreOriginal,
|
||||
GlesRadianceVgnChromaShaders.iirRgb,
|
||||
GlesRadianceVgnChromaShaders.calculateColorNoiseError,
|
||||
GlesRadianceVgnChromaShaders.iirError,
|
||||
GlesRadianceVgnChromaShaders.colorNoiseFilter,
|
||||
GlesRadianceVgnChromaShaders.finalCameraRgb,
|
||||
)
|
||||
|
||||
globalShaders.forEach { shader ->
|
||||
assertTrue(shader.contains("ivec3 tiledPosition"))
|
||||
assertTrue(shader.contains("uTileLefts"))
|
||||
assertTrue(shader.contains("uTileTops"))
|
||||
}
|
||||
assertTrue(GlesRadianceVgnChromaShaders.iirRgb.contains("innerSize = uAxis == 0 ? uImageSize.x"))
|
||||
assertTrue(GlesRadianceVgnChromaShaders.iirRgb.contains("for (int i = 0; i < innerSize; ++i)"))
|
||||
assertTrue(GlesRadianceVgnChromaShaders.iirError.contains("for (int i = 0; i < innerSize; ++i)"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nativeScaleRetainsReferenceVgnCoefficientsAndSrScaleLowersDigitalCutoff() {
|
||||
val native = RadianceVgnChromaIirCoefficients.forOutputScale(1f)
|
||||
val sr = RadianceVgnChromaIirCoefficients.forOutputScale(1.5f)
|
||||
|
||||
assertArrayEquals(
|
||||
floatArrayOf(0.0674552768f, 0.134910554f, 0.0674552768f, 0f),
|
||||
native.pass1.a10,
|
||||
0f,
|
||||
)
|
||||
assertArrayEquals(
|
||||
floatArrayOf(1f, -1.14298046f, 0.412801594f, 0f),
|
||||
native.pass1.b10,
|
||||
0f,
|
||||
)
|
||||
assertTrue(sr.pass1.a10[0] < native.pass1.a10[0])
|
||||
assertEquals(2f * sr.pass1.a10[0], sr.pass1.a10[1], 1e-6f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun generatedPostprocessorShadersPassAvailableNdkValidator() {
|
||||
val sdkRoot = System.getenv("ANDROID_SDK_ROOT") ?: System.getenv("ANDROID_HOME")
|
||||
val validator = sdkRoot?.let(::File)
|
||||
?.resolve("ndk")
|
||||
?.listFiles()
|
||||
?.sortedByDescending { it.name }
|
||||
?.asSequence()
|
||||
?.mapNotNull { ndk ->
|
||||
ndk.resolve("shader-tools")
|
||||
.walkTopDown()
|
||||
.firstOrNull { it.name == "glslc" && it.canExecute() }
|
||||
}
|
||||
?.firstOrNull()
|
||||
assumeTrue("Android NDK glslc is unavailable", validator != null)
|
||||
|
||||
val sources = listOf(
|
||||
GlesRadianceVgnChromaShaders.capture,
|
||||
GlesRadianceVgnChromaShaders.seed,
|
||||
GlesRadianceVgnChromaShaders.colorNoise1,
|
||||
GlesRadianceVgnChromaShaders.colorNoise2,
|
||||
GlesRadianceVgnChromaShaders.colorNoise3Smooth,
|
||||
GlesRadianceVgnChromaShaders.restoreOriginal,
|
||||
GlesRadianceVgnChromaShaders.iirRgb,
|
||||
GlesRadianceVgnChromaShaders.calculateColorNoiseError,
|
||||
GlesRadianceVgnChromaShaders.iirError,
|
||||
GlesRadianceVgnChromaShaders.colorNoiseFilter,
|
||||
GlesRadianceVgnChromaShaders.finalCameraRgb,
|
||||
)
|
||||
sources.forEachIndexed { index, source ->
|
||||
val sourceFile = File.createTempFile("radiance-vgn-chroma-$index-", ".compute")
|
||||
val outputFile = File.createTempFile("radiance-vgn-chroma-$index-", ".spv")
|
||||
try {
|
||||
sourceFile.writeText(source)
|
||||
val process = ProcessBuilder(
|
||||
checkNotNull(validator).absolutePath,
|
||||
"--target-env=opengl",
|
||||
"-fauto-map-locations",
|
||||
"-fauto-bind-uniforms",
|
||||
"-fshader-stage=compute",
|
||||
sourceFile.absolutePath,
|
||||
"-o",
|
||||
outputFile.absolutePath,
|
||||
).redirectErrorStream(true).start()
|
||||
val output = process.inputStream.bufferedReader().use { it.readText() }
|
||||
assertEquals("shader $index: $output", 0, process.waitFor())
|
||||
} finally {
|
||||
sourceFile.delete()
|
||||
outputFile.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+85
-10
@@ -28,8 +28,11 @@ class GlesRawRadianceFusionShadersTest {
|
||||
composition.contains("referenceToAnchorFlow.rg + anchorToShortFlow.rg"),
|
||||
)
|
||||
assertTrue(
|
||||
composition.contains("referenceToAnchorFlow.a * anchorToShortFlow.a"),
|
||||
composition.contains("float multipliedConfidence = referenceToAnchorFlow.a * anchorToShortFlow.a"),
|
||||
)
|
||||
assertTrue(composition.contains("uUseBottleneckConfidence"))
|
||||
assertTrue(composition.contains("normalizedEdgeConfidence"))
|
||||
assertTrue(composition.contains("float bottleneckConfidence = min("))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,6 +176,21 @@ class GlesRawRadianceFusionShadersTest {
|
||||
assertFalse(shader.contains("float sensorPrecision"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun semanticProxyStaysWhiteBalancedThroughWarpThenReturnsToCameraRgb() {
|
||||
val shader = GlesRawRadianceFusionShaders.accumulate("", trackRejections = false)
|
||||
|
||||
assertTrue(shader.contains("uniform vec3 uCalculationGains"))
|
||||
assertTrue(shader.contains("if (uIsReference != 0 || uSemanticEncoding == 0)"))
|
||||
assertTrue(shader.contains("vec3 calculationRgb = vec3("))
|
||||
assertTrue(shader.contains("calculationRgb / max(uCalculationGains, vec3(1e-6))"))
|
||||
assertFalse(
|
||||
shader.contains(
|
||||
"return clamp(vec3(encoded.r + encoded.g, encoded.r, encoded.r + encoded.b)",
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun longFramesNormalizeRadianceAndNoiseFromActualExposure() {
|
||||
val shader = GlesRawRadianceFusionShaders.accumulate("", trackRejections = false)
|
||||
@@ -185,6 +203,41 @@ class GlesRawRadianceFusionShadersTest {
|
||||
assertTrue(shader.contains("referenceRgb / max(radiometricScale, 1e-4)"))
|
||||
assertTrue(shader.contains("radiometricScale * radiometricScale"))
|
||||
assertTrue(shader.contains("uLongPrecisionWeightCap"))
|
||||
assertTrue(shader.contains("max(uLongPrecisionWeightCap, 1.0)"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun longFramesRequireFinalComposedPathConfidencePerPixel() {
|
||||
val shader = GlesRawRadianceFusionShaders.accumulate("", trackRejections = false)
|
||||
|
||||
assertTrue(shader.contains("vec4 flowEvidence = vec4(0.0, 0.0, 0.0, 1.0)"))
|
||||
assertTrue(shader.contains("flowEvidence = flowEvidenceAt(planePos)"))
|
||||
assertTrue(shader.contains("float longPathConfidence = uIsLongFrame != 0"))
|
||||
assertTrue(
|
||||
shader.contains(
|
||||
"clamp(uRegistrationNrWeight, 0.0, 1.0) * longPathConfidence",
|
||||
),
|
||||
)
|
||||
assertTrue(shader.contains("detailCoverage = clamp(tileConfidence.g * robust"))
|
||||
assertTrue(shader.contains("longPathConfidence;"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun longExposureNormalizationPreservesReconstructionOverrangeUntilScale() {
|
||||
val shader = GlesRawRadianceFusionShaders.accumulate("", trackRejections = false)
|
||||
|
||||
assertTrue(shader.contains("return max(encoded, vec3(0.0))"))
|
||||
assertTrue(
|
||||
Regex("""return max\(\s*calculationRgb / max\(uCalculationGains""")
|
||||
.containsMatchIn(shader),
|
||||
)
|
||||
assertFalse(shader.contains("return clamp(encoded, 0.0, 1.0)"))
|
||||
assertFalse(
|
||||
Regex("""return clamp\(\s*calculationRgb / max\(uCalculationGains""")
|
||||
.containsMatchIn(shader),
|
||||
)
|
||||
assertTrue(shader.contains("clamp(sourceRgb.detail * radiometricScale, 0.0, 1.0)"))
|
||||
assertTrue(shader.contains("clamp(sourceRgb.denoise * radiometricScale, 0.0, 1.0)"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -208,12 +261,16 @@ class GlesRawRadianceFusionShadersTest {
|
||||
assertTrue(shader.contains("uniform sampler2D uCurrentProxy"))
|
||||
assertTrue(shader.contains("uniform sampler2D uComposedFlow"))
|
||||
assertTrue(shader.contains("min(referenceSample.g, currentSample.g)"))
|
||||
assertTrue(shader.contains("min(referenceSample.b, currentSample.b)"))
|
||||
assertTrue(shader.contains("float observability = min("))
|
||||
assertTrue(shader.contains("eligibilitySum += validity * observability"))
|
||||
assertTrue(shader.contains("eligibilitySum,"))
|
||||
assertTrue(shader.contains("validitySum,"))
|
||||
assertTrue(shader.contains("referenceObservabilitySum,"))
|
||||
assertTrue(shader.contains("currentObservabilitySum"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun generatedLongFusionShadersPassAvailableNdkValidator() {
|
||||
fun generatedRadianceFusionShadersPassAvailableNdkValidator() {
|
||||
val sdkRoot = System.getenv("ANDROID_SDK_ROOT") ?: System.getenv("ANDROID_HOME")
|
||||
val validator = sdkRoot?.let(::File)
|
||||
?.resolve("ndk")
|
||||
@@ -237,6 +294,7 @@ class GlesRawRadianceFusionShadersTest {
|
||||
trackLongParticipation = true,
|
||||
),
|
||||
"fragment" to GlesRawRadianceFusionShaders.longEligibility,
|
||||
"fragment" to GlesRawRadianceFusionShaders.normalize(showRejections = false),
|
||||
)
|
||||
sources.forEach { (stage, source) ->
|
||||
val sourceFile = File.createTempFile("radiance-long-", ".$stage")
|
||||
@@ -276,11 +334,10 @@ class GlesRawRadianceFusionShadersTest {
|
||||
|
||||
assertTrue(shader.contains("uniform int uSemanticEncoding"))
|
||||
assertTrue(shader.contains("uIsReference != 0 || uSemanticEncoding == 0"))
|
||||
assertTrue(
|
||||
shader.contains(
|
||||
"vec3(encoded.r + encoded.g, encoded.r, encoded.r + encoded.b)",
|
||||
),
|
||||
)
|
||||
assertTrue(shader.contains("vec3 calculationRgb = vec3("))
|
||||
assertTrue(shader.contains("encoded.r + encoded.g"))
|
||||
assertTrue(shader.contains("encoded.r + encoded.b"))
|
||||
assertTrue(shader.contains("calculationRgb / max(uCalculationGains"))
|
||||
assertFalse(shader.contains("bayerIndexAt(uCfaPattern, outputP)"))
|
||||
}
|
||||
|
||||
@@ -347,7 +404,7 @@ class GlesRawRadianceFusionShadersTest {
|
||||
val shader = GlesRawRadianceFusionShaders.normalize(showRejections = false)
|
||||
|
||||
assertTrue(shader.contains("uniform vec3 uCalculationGains"))
|
||||
assertTrue(shader.contains("vec3 nrCalculation = nrSpatial * calculationGains"))
|
||||
assertTrue(shader.contains("vec3 nrCalculation = safeCenter * calculationGains"))
|
||||
assertTrue(shader.contains("vec3 detailCalculation = detail * calculationGains"))
|
||||
assertTrue(shader.contains("detailCalculation - nrCalculation"))
|
||||
assertTrue(
|
||||
@@ -355,7 +412,25 @@ class GlesRawRadianceFusionShadersTest {
|
||||
"(nrCalculation + vec3(signedLumaDetail)) / calculationGains",
|
||||
),
|
||||
)
|
||||
assertFalse(shader.contains("nrSpatial + vec3(signedLumaDetail)"))
|
||||
assertFalse(shader.contains("safeCenter + vec3(signedLumaDetail)"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun normalizeDoesNotApplyLegacySpatialPostfilter() {
|
||||
val shader = GlesRawRadianceFusionShaders.normalize(showRejections = false)
|
||||
|
||||
assertTrue(shader.contains("vec3 safeCenter = mix(center.base, center.nr, center.confidence)"))
|
||||
assertTrue(shader.contains("vec3 nrCalculation = safeCenter * calculationGains"))
|
||||
assertTrue(
|
||||
shader.contains(
|
||||
"vec3 fullRgbDetail = safeCenter + detailConfidence * (detail - safeCenter)",
|
||||
),
|
||||
)
|
||||
assertFalse(shader.contains("uBilateralNoiseScale"))
|
||||
assertFalse(shader.contains("uFinalSmoothStrength"))
|
||||
assertFalse(shader.contains("bilateralSum"))
|
||||
assertFalse(shader.contains("spatialSmooth"))
|
||||
assertFalse(shader.contains("nrSpatial"))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+104
-31
@@ -45,56 +45,129 @@ class RawRadianceHighlightAlignmentSupportTest {
|
||||
@Test
|
||||
fun acceptedLongFrameKeepsFullGlobalWeightDespiteSparseSeedCoverage() {
|
||||
val admission = planRadianceLongAdmission(
|
||||
validTileCount = 230,
|
||||
coveredQuadrants = 2,
|
||||
eligibleTileCount = 4_000,
|
||||
eligibleQuadrants = 2,
|
||||
minimumValidTiles = 64,
|
||||
minimumQuadrants = 3,
|
||||
minimumEligibleCoverage = 0.01f,
|
||||
evidence = longEvidence(
|
||||
validTileCount = 230,
|
||||
coveredQuadrants = 2,
|
||||
eligibleTileCount = 4_000,
|
||||
eligibleQuadrants = 2,
|
||||
),
|
||||
requirements = longRequirements(),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
1f,
|
||||
admission.frameWeight,
|
||||
0f,
|
||||
)
|
||||
assertEquals(1f, admission.frameWeight, 0f)
|
||||
assertEquals(RawRadianceLongAdmissionMode.VALIDATED_FLOW, admission.mode)
|
||||
assertEquals(24f, admission.precisionWeightCap, 0f)
|
||||
assertTrue(admission.rejectionReasons.isEmpty())
|
||||
assertEquals(2, admission.requiredQuadrants)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun longFrameStillRequiresThreeQuadrantsWhenFourAreEligible() {
|
||||
val admission = planRadianceLongAdmission(
|
||||
validTileCount = 230,
|
||||
coveredQuadrants = 2,
|
||||
eligibleTileCount = 4_000,
|
||||
eligibleQuadrants = 4,
|
||||
minimumValidTiles = 64,
|
||||
minimumQuadrants = 3,
|
||||
minimumEligibleCoverage = 0.01f,
|
||||
evidence = longEvidence(
|
||||
validTileCount = 230,
|
||||
coveredQuadrants = 2,
|
||||
eligibleTileCount = 4_000,
|
||||
eligibleQuadrants = 4,
|
||||
),
|
||||
requirements = longRequirements(),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
0f,
|
||||
admission.frameWeight,
|
||||
0f,
|
||||
)
|
||||
assertEquals(0f, admission.frameWeight, 0f)
|
||||
assertEquals(RawRadianceLongAdmissionMode.REJECTED, admission.mode)
|
||||
assertEquals(3, admission.requiredQuadrants)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun longFrameRejectsInsufficientCoverageOfEligibleTiles() {
|
||||
val admission = planRadianceLongAdmission(
|
||||
validTileCount = 64,
|
||||
coveredQuadrants = 3,
|
||||
eligibleTileCount = 10_000,
|
||||
eligibleQuadrants = 3,
|
||||
minimumValidTiles = 64,
|
||||
minimumQuadrants = 3,
|
||||
minimumEligibleCoverage = 0.01f,
|
||||
evidence = longEvidence(
|
||||
validTileCount = 64,
|
||||
coveredQuadrants = 3,
|
||||
eligibleTileCount = 10_000,
|
||||
eligibleQuadrants = 3,
|
||||
),
|
||||
requirements = longRequirements(),
|
||||
)
|
||||
|
||||
assertEquals(0f, admission.frameWeight, 0f)
|
||||
assertEquals(0.0064f, admission.eligibleCoverage, 1e-6f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lowObservabilityLongFrameIsRejectedEvenWithStrongPhotonGain() {
|
||||
val admission = planRadianceLongAdmission(
|
||||
evidence = longEvidence(
|
||||
validTileCount = 0,
|
||||
coveredQuadrants = 0,
|
||||
eligibleTileCount = 2,
|
||||
eligibleQuadrants = 0,
|
||||
referenceObservableTileCount = 2,
|
||||
currentObservableTileCount = 45_600,
|
||||
),
|
||||
requirements = longRequirements(),
|
||||
)
|
||||
|
||||
assertEquals(RawRadianceLongAdmissionMode.REJECTED, admission.mode)
|
||||
assertEquals(0f, admission.frameWeight, 0f)
|
||||
assertEquals(0f, admission.precisionWeightCap, 0f)
|
||||
assertTrue(
|
||||
RawRadianceLongRejectionReason.REFERENCE_PROXY_UNOBSERVABLE in
|
||||
admission.rejectionReasons,
|
||||
)
|
||||
assertTrue(
|
||||
RawRadianceLongRejectionReason.MUTUAL_OBSERVABILITY_INSUFFICIENT in
|
||||
admission.rejectionReasons,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun separatelyReportsLongProxyObservabilityFailure() {
|
||||
val admission = planRadianceLongAdmission(
|
||||
evidence = longEvidence(
|
||||
validTileCount = 0,
|
||||
coveredQuadrants = 0,
|
||||
eligibleTileCount = 0,
|
||||
eligibleQuadrants = 0,
|
||||
referenceObservableTileCount = 40_000,
|
||||
currentObservableTileCount = 0,
|
||||
),
|
||||
requirements = longRequirements(),
|
||||
)
|
||||
|
||||
assertEquals(RawRadianceLongAdmissionMode.REJECTED, admission.mode)
|
||||
assertEquals(0f, admission.frameWeight, 0f)
|
||||
assertEquals(0f, admission.precisionWeightCap, 0f)
|
||||
assertFalse(
|
||||
RawRadianceLongRejectionReason.REFERENCE_PROXY_UNOBSERVABLE in
|
||||
admission.rejectionReasons,
|
||||
)
|
||||
assertTrue(
|
||||
RawRadianceLongRejectionReason.LONG_PROXY_UNOBSERVABLE in
|
||||
admission.rejectionReasons,
|
||||
)
|
||||
}
|
||||
|
||||
private fun longEvidence(
|
||||
validTileCount: Int,
|
||||
coveredQuadrants: Int,
|
||||
eligibleTileCount: Int,
|
||||
eligibleQuadrants: Int,
|
||||
referenceObservableTileCount: Int = 40_000,
|
||||
currentObservableTileCount: Int = 40_000,
|
||||
) = RawRadianceLongAdmissionEvidence(
|
||||
validTileCount = validTileCount,
|
||||
coveredQuadrants = coveredQuadrants,
|
||||
eligibleTileCount = eligibleTileCount,
|
||||
eligibleQuadrants = eligibleQuadrants,
|
||||
referenceObservableTileCount = referenceObservableTileCount,
|
||||
currentObservableTileCount = currentObservableTileCount,
|
||||
)
|
||||
|
||||
private fun longRequirements() = RawRadianceLongAdmissionRequirements(
|
||||
minimumValidTiles = 64,
|
||||
minimumQuadrants = 3,
|
||||
minimumEligibleCoverage = 0.01f,
|
||||
validatedPrecisionWeightCap = 24f,
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user