From f154e877ade201a1f92ee45440370c426b5f78d6 Mon Sep 17 00:00:00 2001 From: Hinnka Date: Sat, 18 Jul 2026 16:37:48 +0800 Subject: [PATCH] research: phocus glsl --- .../00_common_io/FillWithBlack_0x307d438.frag | 15 + .../block_downsample_0x3065745.frag | 29 + .../00_common_io/commonVertex_0x3004aaf.vert | 17 + ...formatConvertHalfFloatToU16_0x300348f.comp | 24 + ...formatConvertU16ToHalfFloat_0x3078b02.comp | 24 + .../00_common_io/shader_0x30451f3.vert | 20 + .../00_common_io/shift_0x30aa376.frag | 44 + .../00_common_io/u16f28ui_0x302addd.frag | 22 + .../00_common_io/yuv2rgb_0x3016546.frag | 39 + .../bayerfastinterpolatefull_0x2ffd274.frag | 145 + .../bayerfastinterpolatehalf_0x302a606.frag | 85 + .../blackLevelSubstract_0x3068cdb.frag | 24 + .../highlightrecoveryscalarrgb_0x304d54d.frag | 133 + .../01_raw_sensor/hotPixelPlus_0x305adee.frag | 384 ++ .../01_raw_sensor/hotPixel_0x302af8e.frag | 364 ++ .../multi2bayer_ms2bayer3_0x303310c.frag | 46 + .../neutralisationBayer_0x30563ff.comp | 106 + .../neutralisationRgb_0x2ff8dfa.comp | 77 + .../orientation_180_0x3073882.frag | 50 + .../orientation_270_0x2ff9752.frag | 50 + .../orientation_90_0x301d6cf.frag | 51 + .../sceneCalibrationBayer_0x3060303.comp | 139 + .../sceneCalibrationGray_0x30b1366.comp | 122 + .../sceneCalibrationRgb_0x3008d0f.comp | 149 + ...calculate_color_noise_error_0x30062f5.comp | 77 + ...demosaic_color_noise_filter_0x3014da8.comp | 56 + ...demosaic_color_noise_pass_1_0x3081fb1.comp | 67 + ...demosaic_color_noise_pass_2_0x3024978.comp | 123 + ...demosaic_color_noise_pass_3_0x3049e97.comp | 183 + ...aic_color_noise_pass_3_yccd_0x303704a.comp | 159 + .../demosaic_iir2_pass1_0x3041e8f.comp | 85 + .../demosaic_iir2_pass1_init_0x3005a70.comp | 81 + .../demosaic_iir2_pass2_0x3006acc.comp | 65 + .../demosaic_iir2_pass3_0x3068458.comp | 80 + .../demosaic_pass_0a1_0x30410af.comp | 149 + .../demosaic_pass_0a2_0x30555c4.comp | 112 + .../demosaic_pass_0b_0x30325b5.comp | 80 + .../demosaic_pass_0c_0x306798d.comp | 100 + .../demosaic_pass_1_0x3097f8e.comp | 395 ++ .../demosaic_pass_2_0x30a5753.comp | 120 + .../demosaic_pass_3_0x30466e2.comp | 343 ++ .../demosaic_pass_neutral_0x308ec13.comp | 67 + .../demosaic_yuv_to_rgb_0x3007126.comp | 64 + .../03_denoise/cacheCmosCache0_0x30501d4.frag | 35 + .../03_denoise/cacheCmosCache1_0x30651c8.frag | 41 + .../03_denoise/cacheCmosCache2_0x300e390.frag | 35 + .../03_denoise/cacheCmosCache3_0x307c71b.frag | 41 + .../cacheCmosG1G2Cache0_0x3032df9.frag | 35 + .../cacheCmosG1G2Cache1_0x302135f.frag | 41 + .../cacheCmosG1G2Cache2_0x303b1b3.frag | 39 + .../cacheCmosG1G2Cache3_0x3064c8a.frag | 39 + .../cacheCmosRedBlueCache0_0x306db71.frag | 37 + .../cacheCmosRedBlueCache1_0x306decf.frag | 47 + .../cacheCmosRedBlueCache2_0x3038793.frag | 54 + .../03_denoise/denoiseCcd_0x304b7a0.comp | 164 + .../denoiseCmosCached_0x309c546.comp | 167 + .../denoiseCmosG1G2Cached_0x30a66a5.frag | 242 ++ .../denoiseCmosG1G2Cached_0x30ad00c.comp | 229 ++ .../denoiseCmosRedBlueCached_0x308f30f.frag | 182 + .../denoiseCmosRedBlueCached_0x30a8aac.comp | 173 + .../03_denoise/denoiseGray_0x3068e79.comp | 222 ++ .../03_denoise/noiseMinMax_0x3087ae6.frag | 57 + .../03_denoise/rgbNoise_0x3013e52.frag | 26 + .../03_denoise/rgbnr_0x3072e51.frag | 63 + .../03_denoise/rgbnrcdiff_0x309776e.frag | 73 + .../03_denoise/rgbnrcdiff_0x30a4eb3.comp | 76 + .../03_denoise/rgbnrsimple_0x30ac478.comp | 102 + .../rgbnrsimple_NoNR_0x30153ac.frag | 23 + .../rgbnrsimple_RGB16_16_0x307cc98.frag | 62 + .../rgbnrsimple_RGB_4_4_0x3090b73.frag | 62 + .../rgbnrsimple_RGB_8_8_0x3033552.frag | 62 + .../ColorCorrectAll_0x301a79e.frag | 261 ++ .../HighlightStrength_0x3019721.frag | 122 + .../colorCorrectAll_0x3027dea.frag | 256 ++ .../color_correct_0x303b6ab.comp | 150 + .../colorspaceconvert_0x2ff7cb6.frag | 154 + .../04_color_tone/customCmm_0x3011778.frag | 79 + .../customColorSpace_0x3034aab.frag | 83 + .../desatHighLight_0x308164a.frag | 109 + .../desatHighLight_0x308e22a.frag | 116 + .../04_color_tone/filmCurve_0x30a3daf.frag | 43 + .../04_color_tone/filmcurve_0x3040c4d.frag | 47 + .../gamma_hasselblad_0x30776ff.frag | 25 + .../04_color_tone/gamma_lstar_0x307356f.frag | 34 + .../04_color_tone/gradation_0x30778de.frag | 163 + .../highlightstrength_0x3035fd3.frag | 122 + .../04_color_tone/mark_hue_0x30504eb.frag | 65 + .../04_color_tone/rgb2GrayRgb_0x309e5f3.comp | 80 + .../04_color_tone/rgb2Gray_0x2ffe79a.comp | 84 + .../04_color_tone/sdr_icc_0x3073d21.frag | 64 + .../selectivecolor_0x3088ea2.frag | 178 + .../unattributed_0x30308d7_0x30308d7.frag | 22 + .../unattributed_0x30347c3_0x30347c3.frag | 18 + .../unattributed_0x3065982_0x3065982.frag | 18 + .../unattributed_0x3079cc5_0x3079cc5.frag | 94 + .../unattributed_0x307f4f7_0x307f4f7.frag | 18 + .../KeystoneBilinear_0x300f494.frag | 62 + .../05_lens_geometry/Keystone_0x30847c0.frag | 126 + .../05_lens_geometry/alignment_0x3025a0f.frag | 21 + .../grayVignetteCS_0x300a1ea.comp | 192 + .../grayVignetteHtsCS_0x306f136.comp | 200 + .../htsAberrationCS_0x309f9c3.comp | 189 + .../orientation_rgb180_0x306e4e6.frag | 26 + .../orientation_rgb270_0x303edb0.frag | 26 + .../orientation_rgb90_0x307d298.frag | 26 + .../repeatMargin_0x3084296.frag | 60 + .../05_lens_geometry/resize_0x3029cb8.frag | 78 + .../resizeintegraldown_0x2ffcdeb.frag | 52 + .../resizesplinehorizontal_0x30768a8.frag | 135 + .../resizesplinevertical_0x3063ecb.frag | 133 + .../rgbLensFilter_0x2fff342.frag | 413 +++ .../rgbLensFilter_0x3057352.comp | 347 ++ .../standardAberrationCS_0x300fbb3.comp | 181 + .../unattributed_0x2ffac4a_0x2ffac4a.frag | 25 + .../unattributed_0x2ffae7d_0x2ffae7d.frag | 51 + .../unattributed_0x3003732_0x3003732.frag | 28 + .../unattributed_0x300c4fc_0x300c4fc.frag | 30 + .../unattributed_0x30218ea_0x30218ea.frag | 73 + .../unattributed_0x3025d0b_0x3025d0b.frag | 30 + .../unattributed_0x303011d_0x303011d.frag | 63 + .../unattributed_0x3038f66_0x3038f66.frag | 26 + .../unattributed_0x303ca82_0x303ca82.frag | 27 + .../unattributed_0x303cd17_0x303cd17.frag | 25 + .../unattributed_0x3043a7a_0x3043a7a.frag | 75 + .../unattributed_0x3053268_0x3053268.frag | 23 + .../unattributed_0x3061f15_0x3061f15.frag | 24 + .../unattributed_0x306afe7_0x306afe7.frag | 104 + .../unattributed_0x3070da7_0x3070da7.frag | 29 + .../unattributed_0x3074cae_0x3074cae.frag | 29 + .../unattributed_0x30798c4_0x30798c4.frag | 28 + .../unattributed_0x307dbfe_0x307dbfe.frag | 32 + .../unattributed_0x307e06c_0x307e06c.frag | 33 + .../unattributed_0x309326d_0x309326d.frag | 32 + .../unattributed_0x30953e0_0x30953e0.frag | 49 + .../cikernel_create_film_grain_0x306e683.frag | 100 + ...nel_create_film_grain_blend_0x309ef57.frag | 94 + .../clarityBlendBlurU16_0x301683e.comp | 185 + .../clarityBlendGlobal2U16_0x307d4af.comp | 56 + .../clarityBlendGlobalNextU16_0x307923d.comp | 51 + .../clarityBlendLocal2F_0x308b9bd.comp | 53 + .../clarityBlendLocalNextF_0x3092c99.comp | 49 + .../clarityBlendNoLutU16_0x3051d04.comp | 142 + .../clarityCombineFinal4U16_0x301e906.comp | 103 + ...larityCreateFinalFactorsU16_0x30742e2.comp | 58 + ...tyDiscretImage4CenterValU16_0x2ffa214.comp | 89 + .../clarityDownScaleBlurU16_0x3050cc9.comp | 158 + .../clarityFastPreviewApply_0x30b231c.comp | 62 + ...arityGrayImage4CenterValU16_0x300bd4e.comp | 69 + .../clarityHRLut_0x3018545.comp | 43 + .../clarityPackedU16MaxToR32F_0x301ded0.comp | 37 + .../clarityReduceMaxFinalU16_0x3025b43.comp | 22 + .../clarityReduceMax_0x301db79.comp | 34 + .../clarityRgb2Gray4U16_0x301e2b0.comp | 45 + .../claritySFLut_0x3078d0e.comp | 54 + .../claritySubtractColTileU16_0x30a1fbe.comp | 91 + ...clarityUpScaleBlurSubAggU16_0x308a48a.comp | 140 + .../clarityUpScaleBlurSubU16_0x3011f91.comp | 147 + .../clarityUpScaleBlurU16_0x3042806.comp | 125 + .../create_film_grain_0x30881be.frag | 118 + .../create_film_grain_blend_0x30080d5.frag | 109 + .../06_detail_texture/highRes_0x300594b.frag | 22 + .../06_detail_texture/highRes_0x30a3c90.frag | 22 + .../unsharpMask_0x300e6ad.frag | 136 + .../unsharpMask_blend_0x3015512.frag | 130 + .../unsharpMask_ver_0x2ff9bfb.frag | 74 + .../CalculateGainMap_0x3007808.frag | 77 + .../applyhdrgainmapyuv_0x30a1626.frag | 101 + .../07_hdr_ultrahdr/hdr_0x30b046e.frag | 28 + .../hdr_gamma22_0x30878f3.frag | 28 + .../07_hdr_ultrahdr/hdr_lstar_0x30463fa.frag | 36 + .../99_unattributed/blend_film_0x3091172.frag | 219 ++ .../99_unattributed/ev_0x30b1024.frag | 36 + .../highlightRecover_0x307f63c.frag | 130 + .../99_unattributed/reversecc_0x3061507.frag | 102 + .../99_unattributed/shader_0x3066a62.frag | 21 + .../unattributed_0x308338f_0x308338f.vert | 15 + .../99_unattributed/usm_0x3023371.frag | 83 + research/phocus_glsl/NOTICE.md | 8 + research/phocus_glsl/README.md | 44 + research/phocus_glsl/manifest.csv | 178 + research/phocus_glsl/manifest.json | 3282 +++++++++++++++++ scripts/research/extract_phocus_glsl.py | 473 +++ 182 files changed, 19981 insertions(+) create mode 100644 research/phocus_glsl/00_common_io/FillWithBlack_0x307d438.frag create mode 100644 research/phocus_glsl/00_common_io/block_downsample_0x3065745.frag create mode 100644 research/phocus_glsl/00_common_io/commonVertex_0x3004aaf.vert create mode 100644 research/phocus_glsl/00_common_io/formatConvertHalfFloatToU16_0x300348f.comp create mode 100644 research/phocus_glsl/00_common_io/formatConvertU16ToHalfFloat_0x3078b02.comp create mode 100644 research/phocus_glsl/00_common_io/shader_0x30451f3.vert create mode 100644 research/phocus_glsl/00_common_io/shift_0x30aa376.frag create mode 100644 research/phocus_glsl/00_common_io/u16f28ui_0x302addd.frag create mode 100644 research/phocus_glsl/00_common_io/yuv2rgb_0x3016546.frag create mode 100644 research/phocus_glsl/01_raw_sensor/bayerfastinterpolatefull_0x2ffd274.frag create mode 100644 research/phocus_glsl/01_raw_sensor/bayerfastinterpolatehalf_0x302a606.frag create mode 100644 research/phocus_glsl/01_raw_sensor/blackLevelSubstract_0x3068cdb.frag create mode 100644 research/phocus_glsl/01_raw_sensor/highlightrecoveryscalarrgb_0x304d54d.frag create mode 100644 research/phocus_glsl/01_raw_sensor/hotPixelPlus_0x305adee.frag create mode 100644 research/phocus_glsl/01_raw_sensor/hotPixel_0x302af8e.frag create mode 100644 research/phocus_glsl/01_raw_sensor/multi2bayer_ms2bayer3_0x303310c.frag create mode 100644 research/phocus_glsl/01_raw_sensor/neutralisationBayer_0x30563ff.comp create mode 100644 research/phocus_glsl/01_raw_sensor/neutralisationRgb_0x2ff8dfa.comp create mode 100644 research/phocus_glsl/01_raw_sensor/orientation_180_0x3073882.frag create mode 100644 research/phocus_glsl/01_raw_sensor/orientation_270_0x2ff9752.frag create mode 100644 research/phocus_glsl/01_raw_sensor/orientation_90_0x301d6cf.frag create mode 100644 research/phocus_glsl/01_raw_sensor/sceneCalibrationBayer_0x3060303.comp create mode 100644 research/phocus_glsl/01_raw_sensor/sceneCalibrationGray_0x30b1366.comp create mode 100644 research/phocus_glsl/01_raw_sensor/sceneCalibrationRgb_0x3008d0f.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_calculate_color_noise_error_0x30062f5.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_color_noise_filter_0x3014da8.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_1_0x3081fb1.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_2_0x3024978.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_3_0x3049e97.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_3_yccd_0x303704a.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_iir2_pass1_0x3041e8f.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_iir2_pass1_init_0x3005a70.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_iir2_pass2_0x3006acc.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_iir2_pass3_0x3068458.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_pass_0a1_0x30410af.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_pass_0a2_0x30555c4.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_pass_0b_0x30325b5.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_pass_0c_0x306798d.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_pass_1_0x3097f8e.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_pass_2_0x30a5753.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_pass_3_0x30466e2.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_pass_neutral_0x308ec13.comp create mode 100644 research/phocus_glsl/02_demosaic/demosaic_yuv_to_rgb_0x3007126.comp create mode 100644 research/phocus_glsl/03_denoise/cacheCmosCache0_0x30501d4.frag create mode 100644 research/phocus_glsl/03_denoise/cacheCmosCache1_0x30651c8.frag create mode 100644 research/phocus_glsl/03_denoise/cacheCmosCache2_0x300e390.frag create mode 100644 research/phocus_glsl/03_denoise/cacheCmosCache3_0x307c71b.frag create mode 100644 research/phocus_glsl/03_denoise/cacheCmosG1G2Cache0_0x3032df9.frag create mode 100644 research/phocus_glsl/03_denoise/cacheCmosG1G2Cache1_0x302135f.frag create mode 100644 research/phocus_glsl/03_denoise/cacheCmosG1G2Cache2_0x303b1b3.frag create mode 100644 research/phocus_glsl/03_denoise/cacheCmosG1G2Cache3_0x3064c8a.frag create mode 100644 research/phocus_glsl/03_denoise/cacheCmosRedBlueCache0_0x306db71.frag create mode 100644 research/phocus_glsl/03_denoise/cacheCmosRedBlueCache1_0x306decf.frag create mode 100644 research/phocus_glsl/03_denoise/cacheCmosRedBlueCache2_0x3038793.frag create mode 100644 research/phocus_glsl/03_denoise/denoiseCcd_0x304b7a0.comp create mode 100644 research/phocus_glsl/03_denoise/denoiseCmosCached_0x309c546.comp create mode 100644 research/phocus_glsl/03_denoise/denoiseCmosG1G2Cached_0x30a66a5.frag create mode 100644 research/phocus_glsl/03_denoise/denoiseCmosG1G2Cached_0x30ad00c.comp create mode 100644 research/phocus_glsl/03_denoise/denoiseCmosRedBlueCached_0x308f30f.frag create mode 100644 research/phocus_glsl/03_denoise/denoiseCmosRedBlueCached_0x30a8aac.comp create mode 100644 research/phocus_glsl/03_denoise/denoiseGray_0x3068e79.comp create mode 100644 research/phocus_glsl/03_denoise/noiseMinMax_0x3087ae6.frag create mode 100644 research/phocus_glsl/03_denoise/rgbNoise_0x3013e52.frag create mode 100644 research/phocus_glsl/03_denoise/rgbnr_0x3072e51.frag create mode 100644 research/phocus_glsl/03_denoise/rgbnrcdiff_0x309776e.frag create mode 100644 research/phocus_glsl/03_denoise/rgbnrcdiff_0x30a4eb3.comp create mode 100644 research/phocus_glsl/03_denoise/rgbnrsimple_0x30ac478.comp create mode 100644 research/phocus_glsl/03_denoise/rgbnrsimple_NoNR_0x30153ac.frag create mode 100644 research/phocus_glsl/03_denoise/rgbnrsimple_RGB16_16_0x307cc98.frag create mode 100644 research/phocus_glsl/03_denoise/rgbnrsimple_RGB_4_4_0x3090b73.frag create mode 100644 research/phocus_glsl/03_denoise/rgbnrsimple_RGB_8_8_0x3033552.frag create mode 100644 research/phocus_glsl/04_color_tone/ColorCorrectAll_0x301a79e.frag create mode 100644 research/phocus_glsl/04_color_tone/HighlightStrength_0x3019721.frag create mode 100644 research/phocus_glsl/04_color_tone/colorCorrectAll_0x3027dea.frag create mode 100644 research/phocus_glsl/04_color_tone/color_correct_0x303b6ab.comp create mode 100644 research/phocus_glsl/04_color_tone/colorspaceconvert_0x2ff7cb6.frag create mode 100644 research/phocus_glsl/04_color_tone/customCmm_0x3011778.frag create mode 100644 research/phocus_glsl/04_color_tone/customColorSpace_0x3034aab.frag create mode 100644 research/phocus_glsl/04_color_tone/desatHighLight_0x308164a.frag create mode 100644 research/phocus_glsl/04_color_tone/desatHighLight_0x308e22a.frag create mode 100644 research/phocus_glsl/04_color_tone/filmCurve_0x30a3daf.frag create mode 100644 research/phocus_glsl/04_color_tone/filmcurve_0x3040c4d.frag create mode 100644 research/phocus_glsl/04_color_tone/gamma_hasselblad_0x30776ff.frag create mode 100644 research/phocus_glsl/04_color_tone/gamma_lstar_0x307356f.frag create mode 100644 research/phocus_glsl/04_color_tone/gradation_0x30778de.frag create mode 100644 research/phocus_glsl/04_color_tone/highlightstrength_0x3035fd3.frag create mode 100644 research/phocus_glsl/04_color_tone/mark_hue_0x30504eb.frag create mode 100644 research/phocus_glsl/04_color_tone/rgb2GrayRgb_0x309e5f3.comp create mode 100644 research/phocus_glsl/04_color_tone/rgb2Gray_0x2ffe79a.comp create mode 100644 research/phocus_glsl/04_color_tone/sdr_icc_0x3073d21.frag create mode 100644 research/phocus_glsl/04_color_tone/selectivecolor_0x3088ea2.frag create mode 100644 research/phocus_glsl/04_color_tone/unattributed_0x30308d7_0x30308d7.frag create mode 100644 research/phocus_glsl/04_color_tone/unattributed_0x30347c3_0x30347c3.frag create mode 100644 research/phocus_glsl/04_color_tone/unattributed_0x3065982_0x3065982.frag create mode 100644 research/phocus_glsl/04_color_tone/unattributed_0x3079cc5_0x3079cc5.frag create mode 100644 research/phocus_glsl/04_color_tone/unattributed_0x307f4f7_0x307f4f7.frag create mode 100644 research/phocus_glsl/05_lens_geometry/KeystoneBilinear_0x300f494.frag create mode 100644 research/phocus_glsl/05_lens_geometry/Keystone_0x30847c0.frag create mode 100644 research/phocus_glsl/05_lens_geometry/alignment_0x3025a0f.frag create mode 100644 research/phocus_glsl/05_lens_geometry/grayVignetteCS_0x300a1ea.comp create mode 100644 research/phocus_glsl/05_lens_geometry/grayVignetteHtsCS_0x306f136.comp create mode 100644 research/phocus_glsl/05_lens_geometry/htsAberrationCS_0x309f9c3.comp create mode 100644 research/phocus_glsl/05_lens_geometry/orientation_rgb180_0x306e4e6.frag create mode 100644 research/phocus_glsl/05_lens_geometry/orientation_rgb270_0x303edb0.frag create mode 100644 research/phocus_glsl/05_lens_geometry/orientation_rgb90_0x307d298.frag create mode 100644 research/phocus_glsl/05_lens_geometry/repeatMargin_0x3084296.frag create mode 100644 research/phocus_glsl/05_lens_geometry/resize_0x3029cb8.frag create mode 100644 research/phocus_glsl/05_lens_geometry/resizeintegraldown_0x2ffcdeb.frag create mode 100644 research/phocus_glsl/05_lens_geometry/resizesplinehorizontal_0x30768a8.frag create mode 100644 research/phocus_glsl/05_lens_geometry/resizesplinevertical_0x3063ecb.frag create mode 100644 research/phocus_glsl/05_lens_geometry/rgbLensFilter_0x2fff342.frag create mode 100644 research/phocus_glsl/05_lens_geometry/rgbLensFilter_0x3057352.comp create mode 100644 research/phocus_glsl/05_lens_geometry/standardAberrationCS_0x300fbb3.comp create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x2ffac4a_0x2ffac4a.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x2ffae7d_0x2ffae7d.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x3003732_0x3003732.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x300c4fc_0x300c4fc.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x30218ea_0x30218ea.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x3025d0b_0x3025d0b.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x303011d_0x303011d.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x3038f66_0x3038f66.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x303ca82_0x303ca82.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x303cd17_0x303cd17.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x3043a7a_0x3043a7a.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x3053268_0x3053268.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x3061f15_0x3061f15.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x306afe7_0x306afe7.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x3070da7_0x3070da7.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x3074cae_0x3074cae.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x30798c4_0x30798c4.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x307dbfe_0x307dbfe.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x307e06c_0x307e06c.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x309326d_0x309326d.frag create mode 100644 research/phocus_glsl/05_lens_geometry/unattributed_0x30953e0_0x30953e0.frag create mode 100644 research/phocus_glsl/06_detail_texture/cikernel_create_film_grain_0x306e683.frag create mode 100644 research/phocus_glsl/06_detail_texture/cikernel_create_film_grain_blend_0x309ef57.frag create mode 100644 research/phocus_glsl/06_detail_texture/clarityBlendBlurU16_0x301683e.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityBlendGlobal2U16_0x307d4af.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityBlendGlobalNextU16_0x307923d.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityBlendLocal2F_0x308b9bd.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityBlendLocalNextF_0x3092c99.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityBlendNoLutU16_0x3051d04.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityCombineFinal4U16_0x301e906.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityCreateFinalFactorsU16_0x30742e2.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityDiscretImage4CenterValU16_0x2ffa214.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityDownScaleBlurU16_0x3050cc9.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityFastPreviewApply_0x30b231c.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityGrayImage4CenterValU16_0x300bd4e.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityHRLut_0x3018545.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityPackedU16MaxToR32F_0x301ded0.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityReduceMaxFinalU16_0x3025b43.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityReduceMax_0x301db79.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityRgb2Gray4U16_0x301e2b0.comp create mode 100644 research/phocus_glsl/06_detail_texture/claritySFLut_0x3078d0e.comp create mode 100644 research/phocus_glsl/06_detail_texture/claritySubtractColTileU16_0x30a1fbe.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityUpScaleBlurSubAggU16_0x308a48a.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityUpScaleBlurSubU16_0x3011f91.comp create mode 100644 research/phocus_glsl/06_detail_texture/clarityUpScaleBlurU16_0x3042806.comp create mode 100644 research/phocus_glsl/06_detail_texture/create_film_grain_0x30881be.frag create mode 100644 research/phocus_glsl/06_detail_texture/create_film_grain_blend_0x30080d5.frag create mode 100644 research/phocus_glsl/06_detail_texture/highRes_0x300594b.frag create mode 100644 research/phocus_glsl/06_detail_texture/highRes_0x30a3c90.frag create mode 100644 research/phocus_glsl/06_detail_texture/unsharpMask_0x300e6ad.frag create mode 100644 research/phocus_glsl/06_detail_texture/unsharpMask_blend_0x3015512.frag create mode 100644 research/phocus_glsl/06_detail_texture/unsharpMask_ver_0x2ff9bfb.frag create mode 100644 research/phocus_glsl/07_hdr_ultrahdr/CalculateGainMap_0x3007808.frag create mode 100644 research/phocus_glsl/07_hdr_ultrahdr/applyhdrgainmapyuv_0x30a1626.frag create mode 100644 research/phocus_glsl/07_hdr_ultrahdr/hdr_0x30b046e.frag create mode 100644 research/phocus_glsl/07_hdr_ultrahdr/hdr_gamma22_0x30878f3.frag create mode 100644 research/phocus_glsl/07_hdr_ultrahdr/hdr_lstar_0x30463fa.frag create mode 100644 research/phocus_glsl/99_unattributed/blend_film_0x3091172.frag create mode 100644 research/phocus_glsl/99_unattributed/ev_0x30b1024.frag create mode 100644 research/phocus_glsl/99_unattributed/highlightRecover_0x307f63c.frag create mode 100644 research/phocus_glsl/99_unattributed/reversecc_0x3061507.frag create mode 100644 research/phocus_glsl/99_unattributed/shader_0x3066a62.frag create mode 100644 research/phocus_glsl/99_unattributed/unattributed_0x308338f_0x308338f.vert create mode 100644 research/phocus_glsl/99_unattributed/usm_0x3023371.frag create mode 100644 research/phocus_glsl/NOTICE.md create mode 100644 research/phocus_glsl/README.md create mode 100644 research/phocus_glsl/manifest.csv create mode 100644 research/phocus_glsl/manifest.json create mode 100644 scripts/research/extract_phocus_glsl.py diff --git a/research/phocus_glsl/00_common_io/FillWithBlack_0x307d438.frag b/research/phocus_glsl/00_common_io/FillWithBlack_0x307d438.frag new file mode 100644 index 00000000..b53db05b --- /dev/null +++ b/research/phocus_glsl/00_common_io/FillWithBlack_0x307d438.frag @@ -0,0 +1,15 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 70223e71cb5ac64567b5380e8fbaa255c1b38e255e8da0de9b80fec97863dd6e + * ELF offsets: 0x307d438 + * Symbols: FillWithBlack_fragmentShaderSource + */ + +#version 300 es +precision highp float; +out vec4 FragColor; + +void main() +{ + FragColor = vec4(0.0, 0.0, 0.0, 0.0); +} diff --git a/research/phocus_glsl/00_common_io/block_downsample_0x3065745.frag b/research/phocus_glsl/00_common_io/block_downsample_0x3065745.frag new file mode 100644 index 00000000..d9cab22c --- /dev/null +++ b/research/phocus_glsl/00_common_io/block_downsample_0x3065745.frag @@ -0,0 +1,29 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 0a3908a02d09d48093007d130c8f231301025cfc3890bab1224d325af566ca28 + * ELF offsets: 0x3065745 + * Symbols: block_downsample_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp int; +precision highp sampler2D; + +out vec4 FragColor; + +uniform sampler2D uInputTexture0; // 0..1 +uniform int uPreviewScale; + +void main() { + ivec2 gid = ivec2(gl_FragCoord.xy); + int s = max(uPreviewScale, 1); + + vec4 sum = vec4(0.0); + for (int dy = 0; dy < s; dy++) { + for (int dx = 0; dx < s; dx++) { + sum += texelFetch(uInputTexture0, gid * s + ivec2(dx, dy), 0); + } + } + FragColor = sum / float(s * s); +} diff --git a/research/phocus_glsl/00_common_io/commonVertex_0x3004aaf.vert b/research/phocus_glsl/00_common_io/commonVertex_0x3004aaf.vert new file mode 100644 index 00000000..f7f93584 --- /dev/null +++ b/research/phocus_glsl/00_common_io/commonVertex_0x3004aaf.vert @@ -0,0 +1,17 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 2cabc41351a224550887e53887d0bd2958eeeb6324ec7d02bc6f45ec0e7b30f5 + * ELF offsets: 0x3004aaf + * Symbols: commonVertexShaderSource + */ + +#version 300 es +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec2 aTexCoord; + +out vec2 TexCoord; + +void main() { + gl_Position = vec4(aPos, 1.0); + TexCoord = aTexCoord; +} diff --git a/research/phocus_glsl/00_common_io/formatConvertHalfFloatToU16_0x300348f.comp b/research/phocus_glsl/00_common_io/formatConvertHalfFloatToU16_0x300348f.comp new file mode 100644 index 00000000..d57aae4b --- /dev/null +++ b/research/phocus_glsl/00_common_io/formatConvertHalfFloatToU16_0x300348f.comp @@ -0,0 +1,24 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: bcce94a076806ceb2369010b6db78f96e941170b371e5b72615c3be5dc9134ad + * ELF offsets: 0x300348f + * Symbols: formatConvertHalfFloatToU16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; +precision highp uimage2D; + +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16f, binding = 0) readonly uniform image2D inTex; +layout(rgba16ui, binding = 1) writeonly uniform uimage2D outTex; + +void main() { + ivec2 coord = ivec2(gl_GlobalInvocationID.xy); + ivec2 size = imageSize(outTex); + if (coord.x >= size.x || coord.y >= size.y) return; + vec4 src = imageLoad(inTex, coord); + imageStore(outTex, coord, uvec4(clamp(round(src * 65535.0), vec4(0.0), vec4(65535.0)))); +} diff --git a/research/phocus_glsl/00_common_io/formatConvertU16ToHalfFloat_0x3078b02.comp b/research/phocus_glsl/00_common_io/formatConvertU16ToHalfFloat_0x3078b02.comp new file mode 100644 index 00000000..fe22c793 --- /dev/null +++ b/research/phocus_glsl/00_common_io/formatConvertU16ToHalfFloat_0x3078b02.comp @@ -0,0 +1,24 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: ea09e7937d80f293bd7655abc6e2abde296abeb033cc3b2d91dd064b9b4a5fc6 + * ELF offsets: 0x3078b02 + * Symbols: formatConvertU16ToHalfFloat_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; +precision highp uimage2D; + +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D inTex; +layout(rgba16f, binding = 1) writeonly uniform image2D outTex; + +void main() { + ivec2 coord = ivec2(gl_GlobalInvocationID.xy); + ivec2 size = imageSize(outTex); + if (coord.x >= size.x || coord.y >= size.y) return; + uvec4 src = imageLoad(inTex, coord); + imageStore(outTex, coord, vec4(src) / 65535.0); +} diff --git a/research/phocus_glsl/00_common_io/shader_0x30451f3.vert b/research/phocus_glsl/00_common_io/shader_0x30451f3.vert new file mode 100644 index 00000000..70ee286d --- /dev/null +++ b/research/phocus_glsl/00_common_io/shader_0x30451f3.vert @@ -0,0 +1,20 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 8b5fee15a4bd109c8dd4d558c7eea81e9fb81539cdd38698c736ae55f8644956 + * ELF offsets: 0x30451f3 + * Symbols: vertexShaderSource + */ + +#version 300 es +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec2 aTexCoord; + +uniform mat4 uProjectionMatrix; +uniform mat4 uModelViewMatrix; + +out vec2 TexCoord; + +void main() { + gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPos, 1.0); + TexCoord = aTexCoord; +} diff --git a/research/phocus_glsl/00_common_io/shift_0x30aa376.frag b/research/phocus_glsl/00_common_io/shift_0x30aa376.frag new file mode 100644 index 00000000..65703266 --- /dev/null +++ b/research/phocus_glsl/00_common_io/shift_0x30aa376.frag @@ -0,0 +1,44 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: ceeb71df7570cf8008284d9f509049a60ddc160aed621ed97e82a8a985a529b5 + * ELF offsets: 0x30aa376 + * Symbols: shift_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp int; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; + +uniform ivec2 margin; +uniform int amount; + +out vec4 FragColor; + +void main() +{ + ivec2 destCoord = ivec2(gl_FragCoord.xy); + int srcPixelX = destCoord.x * 2 + margin.x; + int srcCoordY = destCoord.y + margin.y; + int srcTexX = srcPixelX / 2; + + vec4 val; + if (srcPixelX % 2 == 0) { + val = texelFetch(uInputTexture0, ivec2(srcTexX, srcCoordY), 0); + } else { + vec4 t0 = texelFetch(uInputTexture0, ivec2(srcTexX, srcCoordY), 0); + vec4 t1 = texelFetch(uInputTexture0, ivec2(srcTexX + 1, srcCoordY), 0); + val = vec4(t0.ba, t1.rg); + } + + float multiplier = pow(2.0, float(amount)); + val *= multiplier; + + if (amount > 0) { + val = clamp(val, 0.0, 1.0); + } + + FragColor = val; +} diff --git a/research/phocus_glsl/00_common_io/u16f28ui_0x302addd.frag b/research/phocus_glsl/00_common_io/u16f28ui_0x302addd.frag new file mode 100644 index 00000000..69ec4e17 --- /dev/null +++ b/research/phocus_glsl/00_common_io/u16f28ui_0x302addd.frag @@ -0,0 +1,22 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: c5c354119ccc00f88f045a9b4300fd2d00e8bfabfeb9e4bb21433cf1bf76cc11 + * ELF offsets: 0x302addd + * Symbols: u16f28ui_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out uvec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform ivec2 uMargin; + +void main() { + ivec2 texCoord = ivec2(gl_FragCoord.xy) + uMargin; + vec4 pixel = texelFetch(uInputTexture0, texCoord, 0); + // float [0,1] → uint [0,255],clamp 防止越界 + vec3 rgb = clamp(pixel.rgb * 255.0 + 0.5, 0.0, 255.0); + FragColor = uvec4(uvec3(rgb), 255u); +} diff --git a/research/phocus_glsl/00_common_io/yuv2rgb_0x3016546.frag b/research/phocus_glsl/00_common_io/yuv2rgb_0x3016546.frag new file mode 100644 index 00000000..bba3b5af --- /dev/null +++ b/research/phocus_glsl/00_common_io/yuv2rgb_0x3016546.frag @@ -0,0 +1,39 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 5a8b0395d4fc2353a8e44245d6080723fe24656140f8bf28d5346c93ae6adb5d + * ELF offsets: 0x3016546 + * Symbols: yuv2rgb_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp int; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; + +uniform vec4 yuvCoeffs; +uniform ivec2 margin; + +out vec4 FragColor; + +void main() +{ + ivec2 coord = ivec2(gl_FragCoord.xy) + margin; + int packedX = coord.x / 2; + vec4 packed = texelFetch(uInputTexture0, ivec2(packedX, coord.y), 0); + + bool isEven = (coord.x % 2) == 0; + float y = isEven ? packed.r : packed.b; + float u = packed.g; + float v = packed.a; + + float cb = u - 0.5; + float cr = v - 0.5; + + float r = y + yuvCoeffs.x * cr; + float g = y + yuvCoeffs.y * cr + yuvCoeffs.z * cb; + float b = y + yuvCoeffs.w * cb; + + FragColor = vec4(clamp(r, 0.0, 1.0), clamp(g, 0.0, 1.0), clamp(b, 0.0, 1.0), 1.0); +} diff --git a/research/phocus_glsl/01_raw_sensor/bayerfastinterpolatefull_0x2ffd274.frag b/research/phocus_glsl/01_raw_sensor/bayerfastinterpolatefull_0x2ffd274.frag new file mode 100644 index 00000000..ce93869e --- /dev/null +++ b/research/phocus_glsl/01_raw_sensor/bayerfastinterpolatefull_0x2ffd274.frag @@ -0,0 +1,145 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 9d87df9b959daa41f5d8eb526f3af10c4fc082485de9a1b3cfc94a50fb9bd795 + * ELF offsets: 0x2ffd274 + * Symbols: bayerfastinterpolatefull_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform vec2 uMargins; +uniform bool uBlurGreen; + +uniform vec2 uTextureSize; + +in vec2 TexCoord; +out vec4 FragColor; + +float avgElem(vec4 v) { + return (v.x + v.y + v.z + v.w) / 4.0; +} + +vec2 mixUS2(vec2 a, vec2 b) { + return vec2((a.x+b.x)/2.0, (a.y+b.y)/2.0); +} + +vec4 rgbAtRed(float center, vec4 edges, vec4 corners) { + return vec4(center, avgElem(edges), avgElem(corners), 1.0); +} + +vec4 rgbAtGreen1(float center, vec4 edges, vec4 corners, bool blurGreen) { + float green = blurGreen ? (avgElem(corners) + center) / 2.0 : center; + float horizontal = (edges.x + edges.z) / 2.0; + float vertical = (edges.y + edges.w) / 2.0; + return vec4(horizontal, green, vertical, 1.0); +} + +vec4 rgbAtGreen2(float center, vec4 edges, vec4 corners, bool blurGreen) { + vec4 result = rgbAtGreen1(center, edges, corners, blurGreen); + return result.zyxw; +} + +vec4 rgbAtBlue(float center, vec4 edges, vec4 corners) { + vec4 result = rgbAtRed(center, edges, corners); + return result.zyxw; +} + +void main() { + vec2 outPos = gl_FragCoord.xy; + + vec2 blockIdx = vec2(outPos.x / 4.0, outPos.y / 2.0); + +// origin +// vec2 inBasePos = vec2(floor(blockIdx.x), floor(blockIdx.y) * 2.0) + vec2(float(uMargins.x), float(uMargins.y)); + + vec2 inBasePos = vec2(floor(blockIdx.x + floor(uMargins.x / 4.0)), floor(blockIdx.y) * 2.0 + uMargins.y); + + float pixelInBlockFloat = mod(outPos.x, 4.0); + float lineInBlockFloat = mod(outPos.y, 2.0); + + vec2 textureSize = uTextureSize; + vec2 inPos0 = (vec2(inBasePos.x, inBasePos.y - 1.0) + 0.5) / textureSize; + vec2 inPos1 = (vec2(inBasePos.x, inBasePos.y + 0.0) + 0.5) / textureSize; + vec2 inPos2 = (vec2(inBasePos.x, inBasePos.y + 1.0) + 0.5) / textureSize; + vec2 inPos3 = (vec2(inBasePos.x, inBasePos.y + 2.0) + 0.5) / textureSize; + + vec2 inPosL0 = (vec2(inBasePos.x - 1.0, inBasePos.y - 1.0) + 0.5) / textureSize; + vec2 inPosL1 = (vec2(inBasePos.x - 1.0, inBasePos.y + 0.0) + 0.5) / textureSize; + vec2 inPosL2 = (vec2(inBasePos.x - 1.0, inBasePos.y + 1.0) + 0.5) / textureSize; + vec2 inPosL3 = (vec2(inBasePos.x - 1.0, inBasePos.y + 2.0) + 0.5) / textureSize; + + vec2 inPosR0 = (vec2(inBasePos.x + 1.0, inBasePos.y - 1.0) + 0.5) / textureSize; + vec2 inPosR1 = (vec2(inBasePos.x + 1.0, inBasePos.y + 0.0) + 0.5) / textureSize; + vec2 inPosR2 = (vec2(inBasePos.x + 1.0, inBasePos.y + 1.0) + 0.5) / textureSize; + vec2 inPosR3 = (vec2(inBasePos.x + 1.0, inBasePos.y + 2.0) + 0.5) / textureSize; + + vec4 inCn1 = texture(uInputTexture0, inPos0); + vec4 inCp0 = texture(uInputTexture0, inPos1); + vec4 inCp1 = texture(uInputTexture0, inPos2); + vec4 inCp2 = texture(uInputTexture0, inPos3); + + vec4 inLn1 = texture(uInputTexture0, inPosL0); + vec4 inLp0 = texture(uInputTexture0, inPosL1); + vec4 inLp1 = texture(uInputTexture0, inPosL2); + vec4 inLp2 = texture(uInputTexture0, inPosL3); + + vec4 inRn1 = texture(uInputTexture0, inPosR0); + vec4 inRp0 = texture(uInputTexture0, inPosR1); + vec4 inRp1 = texture(uInputTexture0, inPosR2); + vec4 inRp2 = texture(uInputTexture0, inPosR3); + + vec4 center, tl, tr, bl, br, t, l, b, r; + vec4 result; + + int pixelInBlock = int(floor(pixelInBlockFloat)); + int lineInBlock = int(floor(lineInBlockFloat)); + + if (lineInBlock == 0) { + // RGRG line + center = inCp0; + tl = vec4(inLn1.w, inCn1.x, inCn1.y, inCn1.z); + tr = vec4(inCn1.y, inCn1.z, inCn1.w, inRn1.x); + bl = vec4(inLp1.w, inCp1.x, inCp1.y, inCp1.z); + br = vec4(inCp1.y, inCp1.z, inCp1.w, inRp1.x); + t = inCn1; + l = vec4(inLp0.w, inCp0.x, inCp0.y, inCp0.z); + b = inCp1; + r = vec4(inCp0.y, inCp0.z, inCp0.w, inRp0.x); + + if (pixelInBlock == 0) { + result = rgbAtRed(center.x, vec4(l.x, t.x, r.x, b.x), vec4(tl.x, tr.x, bl.x, br.x)); + } else if (pixelInBlock == 1) { + result = rgbAtGreen1(center.y, vec4(l.y, t.y, r.y, b.y), vec4(tl.y, tr.y, bl.y, br.y), uBlurGreen); + } else if (pixelInBlock == 2) { + result = rgbAtRed(center.z, vec4(l.z, t.z, r.z, b.z), vec4(tl.z, tr.z, bl.z, br.z)); + } else { // pixelInBlock == 3 + result = rgbAtGreen1(center.w, vec4(l.w, t.w, r.w, b.w), vec4(tl.w, tr.w, bl.w, br.w), uBlurGreen); + } + }else { + // GBGB line + center = inCp1; + tl = vec4(inLp0.w, inCp0.x, inCp0.y, inCp0.z); + tr = vec4(inCp0.y, inCp0.z, inCp0.w, inRp0.x); + bl = vec4(inLp2.w, inCp2.x, inCp2.y, inCp2.z); + br = vec4(inCp2.y, inCp2.z, inCp2.w, inRp2.x); + t = inCp0; + l = vec4(inLp1.w, inCp1.x, inCp1.y, inCp1.z); + b = inCp2; + r = vec4(inCp1.y, inCp1.z, inCp1.w, inRp1.x); + + if (pixelInBlock == 0) { + result = rgbAtGreen2(center.x, vec4(l.x, t.x, r.x, b.x), vec4(tl.x, tr.x, bl.x, br.x), uBlurGreen); + } else if (pixelInBlock == 1) { + result = rgbAtBlue(center.y, vec4(l.y, t.y, r.y, b.y), vec4(tl.y, tr.y, bl.y, br.y)); + } else if (pixelInBlock == 2) { + result = rgbAtGreen2(center.z, vec4(l.z, t.z, r.z, b.z), vec4(tl.z, tr.z, bl.z, br.z), uBlurGreen); + } else { // pixelInBlock == 3 + result = rgbAtBlue(center.w, vec4(l.w, t.w, r.w, b.w), vec4(tl.w, tr.w, bl.w, br.w)); + } + } + + FragColor = result; +} diff --git a/research/phocus_glsl/01_raw_sensor/bayerfastinterpolatehalf_0x302a606.frag b/research/phocus_glsl/01_raw_sensor/bayerfastinterpolatehalf_0x302a606.frag new file mode 100644 index 00000000..b6b730f5 --- /dev/null +++ b/research/phocus_glsl/01_raw_sensor/bayerfastinterpolatehalf_0x302a606.frag @@ -0,0 +1,85 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 805ab3ff49fd22152dce086812cac32e9062ddc56861d30aa04aa2b12c46def2 + * ELF offsets: 0x302a606 + * Symbols: bayerfastinterpolatehalf_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform vec2 uMargins; +uniform int uOrientation; +uniform bool uBlurGreen; + +uniform vec2 uTextureSize; +uniform vec2 uOutputSize; + +in vec2 TexCoord; +out vec4 FragColor; + + +vec2 mixUS2(vec2 a, vec2 b) { + return vec2(a.x / 2.0 + b.x / 2.0, a.y / 2.0 + b.y / 2.0); +} + +void main() { + vec2 outPos = gl_FragCoord.xy; + + vec2 blockPos = vec2(outPos.x / 2.0, outPos.y); + + vec2 inBasePos = vec2(floor(blockPos.x + (uMargins.x / 4.0)), floor(blockPos.y) * 2.0 + uMargins.y); + + float pixelInBlockFloat = mod(outPos.x, 2.0); + int pixelInBlock = int(floor(pixelInBlockFloat)); + + vec2 textureSize = uTextureSize; + vec2 inPos1 = (inBasePos + 0.5) / textureSize; + vec2 inPos2 = (vec2(inBasePos.x, inBasePos.y + 1.0) + 0.5) / textureSize; + + vec4 inPix1 = texture(uInputTexture0, inPos1); + vec4 inPix2 = texture(uInputTexture0, inPos2); + + vec2 block0 = vec2(inPix1.x, inPix1.z); + vec2 block1 = vec2(inPix1.y, inPix1.w); + vec2 block2 = vec2(inPix2.x, inPix2.z); + vec2 block3 = vec2(inPix2.y, inPix2.w); + + vec2 reds = vec2(0.0); + vec2 greens = vec2(0.0); + vec2 blues = vec2(0.0); + + switch (uOrientation) { + case 0: + reds = block0; + greens = mixUS2(block1, block2); + blues = block3; + break; + case 90: + reds = block1; + greens = mixUS2(block0, block3); + blues = block2; + break; + case 180: + reds = block3; + greens = mixUS2(block1, block2); + blues = block0; + break; + case 270: + reds = block2; + greens = mixUS2(block0, block3); + blues = block1; + break; + } + + vec4 result; + if (pixelInBlock == 0) { + result = vec4(reds.x, greens.x, blues.x, 0.0); + } else { + result = vec4(reds.y, greens.y, blues.y, 0.0); + } + + FragColor = result; +} diff --git a/research/phocus_glsl/01_raw_sensor/blackLevelSubstract_0x3068cdb.frag b/research/phocus_glsl/01_raw_sensor/blackLevelSubstract_0x3068cdb.frag new file mode 100644 index 00000000..44247c8d --- /dev/null +++ b/research/phocus_glsl/01_raw_sensor/blackLevelSubstract_0x3068cdb.frag @@ -0,0 +1,24 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 7181e8fe4ab1bebbe1039474ace74f997cc0ca1ee20e6e7aaec7ef86a4deb6ac + * ELF offsets: 0x3068cdb + * Symbols: blackLevelSubstract_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform vec2 uMargin; +uniform float uOffset; + +void main() { + vec2 srcPos = gl_FragCoord.xy + uMargin; + vec4 inValue = texelFetch(uInputTexture0, ivec2(srcPos), 0); + vec4 result = inValue * 65535.0 - uOffset; + result = result / 65535.0; + + FragColor = clamp(result, 0.0, 1.0); +} diff --git a/research/phocus_glsl/01_raw_sensor/highlightrecoveryscalarrgb_0x304d54d.frag b/research/phocus_glsl/01_raw_sensor/highlightrecoveryscalarrgb_0x304d54d.frag new file mode 100644 index 00000000..1de1bbac --- /dev/null +++ b/research/phocus_glsl/01_raw_sensor/highlightrecoveryscalarrgb_0x304d54d.frag @@ -0,0 +1,133 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 62a796eabf55c35aa9d70843c4c6670f47fc11b59a789fa59e3107a39383b2c4 + * ELF offsets: 0x304d54d + * Symbols: highlightrecoveryscalarrgb_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; + +uniform vec2 uTextureSize; + +uniform vec3 uBoScale; +uniform vec3 uBoLevel; +uniform vec3 uNeutral; +uniform vec3 uMidGrayScales; +uniform vec3 uFullScales; +uniform vec3 uRatioGreenBlue; +uniform vec3 uRatioRed; +uniform ivec3 uOrder; +uniform ivec3 uOrderBack; +uniform vec2 uMargin; + +in vec2 TexCoord; +out vec4 FragColor; + +float ProjectedPoint(vec3 params, vec2 p) { + float a = params[0]; + float b = params[1]; + float ref = params[2]; + float t = 1.0 / a; + float x = (t * p.x + p.y - b) / (a + t); + return x / ref; +} + +vec3 Forward(vec3 value) { + vec3 reordered = vec3(value[uOrder[0]], value[uOrder[1]], value[uOrder[2]]); + return min(reordered * uBoScale, 1.0); +} + +vec3 Backwards(vec3 value) { + vec3 scaled = min(value / uBoScale, uBoLevel); + return vec3(scaled[uOrderBack[0]], scaled[uOrderBack[1]], scaled[uOrderBack[2]]); +} + +vec3 ConvertEdge(vec3 value) { + if (value[0] < 1.0 && value[1] < 1.0 && value[2] < 1.0) { + return value * uNeutral; + } + + float greenScale; + float midGrayScale; + float fullScale; + + if (value[2] >= 1.0) { + greenScale = ProjectedPoint(uRatioGreenBlue, vec2(value[0], value[1])); + midGrayScale = uMidGrayScales[2]; + fullScale = uFullScales[2]; + } else if (value[1] >= 1.0) { + greenScale = ProjectedPoint(uRatioGreenBlue, vec2(value[0], value[2])); + midGrayScale = uMidGrayScales[1]; + fullScale = uFullScales[1]; + } else { + greenScale = ProjectedPoint(uRatioRed, vec2(value[1], value[2])); + midGrayScale = uMidGrayScales[0]; + fullScale = uFullScales[0]; + } + + vec3 missingGain = 1.0 / uNeutral; + float centerValue = missingGain[2] / missingGain[1]; + greenScale = max(1.0, greenScale); + float blueScale = 1.0; + + if (greenScale > midGrayScale) { + float distance = (greenScale - midGrayScale) / (fullScale - midGrayScale); + greenScale = mix(centerValue, missingGain[2], distance); + blueScale = mix(1.0, missingGain[1], distance); + } else { + greenScale = mix(1.0, centerValue, (greenScale - 1.0) / (midGrayScale - 1.0)); + } + + value[1] *= blueScale; + value[2] *= greenScale; + vec3 neutralized = value * uNeutral; + return neutralized; +} + +vec3 Convert(vec3 value) { + vec3 inputF = Forward(value); + + if (inputF[0] < 1.0 && inputF[1] < 1.0 && inputF[2] < 1.0) { + vec3 edge0 = vec3(1.0, inputF[1], inputF[2]); + vec3 edge1 = vec3(inputF[0], 1.0, inputF[2]); + vec3 edge2 = vec3(inputF[0], inputF[1], 1.0); + + vec3 diff0 = ConvertEdge(edge0) - edge0 * uNeutral; + vec3 diff1 = ConvertEdge(edge1) - edge1 * uNeutral; + vec3 diff2 = ConvertEdge(edge2) - edge2 * uNeutral; + + vec3 mixRatio = inputF / 1.0; + mixRatio = mixRatio * mixRatio; + mixRatio = mixRatio * mixRatio; + mixRatio = mixRatio * mixRatio; + + float sumRatio = mixRatio[0] + mixRatio[1] + mixRatio[2]; + + mixRatio = (sumRatio > 1e-6) ? mixRatio / sumRatio : vec3(0.0); + + vec3 mixedDiff = diff0 * mixRatio[0] + diff1 * mixRatio[1] + diff2 * mixRatio[2]; + + return Backwards(inputF * uNeutral + mixedDiff); + } else { + return Backwards(ConvertEdge(inputF)); + } +} + +void main() { + vec2 gid = gl_FragCoord.xy; + + vec2 inputPos = gid + uMargin; + + vec2 inputTexCoord = inputPos / uTextureSize; + + vec4 pix = texture(uInputTexture0, inputTexCoord); + + vec3 outVal = Convert(pix.rgb); + + vec3 clamped = clamp(outVal, 0.0, 1.0); + FragColor = vec4(clamped, pix.a); +} diff --git a/research/phocus_glsl/01_raw_sensor/hotPixelPlus_0x305adee.frag b/research/phocus_glsl/01_raw_sensor/hotPixelPlus_0x305adee.frag new file mode 100644 index 00000000..a711dca6 --- /dev/null +++ b/research/phocus_glsl/01_raw_sensor/hotPixelPlus_0x305adee.frag @@ -0,0 +1,384 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 0791fa8fdf096adab2e55a65c1b68b0f4b1e31529202eb0153f89882ee21b144 + * ELF offsets: 0x305adee + * Symbols: hotPixelPlus_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp int; +precision highp sampler2D; + +layout(location = 0) out vec4 FragColor; + +uniform sampler2D uInputTexture0; // Image +uniform sampler2D uInputTexture1; // Mask + +const float MAX_VAL = 65535.0; +const int eHpPepper = 0; +const int eHpOk = 32; +const int eHpHot = 255; + +// UBO 定义 (std140) +layout(std140) uniform HotPixelParams { + float trivialDiffThr; + float extraPolFact; + float meanLowFact; + float meanHighFact; + float sDFactLo; + float colorRatioModerator; + float colorMeanModerator; + float pad0; + int blacklevelOffset; + int extraPolTestCount; + float sDFactHiRedBlue; + float sDFactHiGreen; + int mapOfsX; + int mapOfsY; + uint marginX; + uint marginY; + int trivialPepperMinThr; + int cluster; + float pad1; + float pad2; +} uParams; + +uniform vec2 uTextureSize; + +struct float2x4 { vec4 m0; vec4 m1; }; + +float SumElem(vec4 v) { return v.x + v.y + v.z + v.w; } +float Sqr(float a) { return a * a; } +vec2 Sqr(vec2 a) { return a * a; } +vec3 Sqr(vec3 a) { return a * a; } +vec4 Sqr(vec4 a) { return a * a; } + +vec4 select_vec4(vec4 f, vec4 t, bvec4 c) { return mix(f, t, vec4(c)); } +uvec4 select_uvec4(uvec4 f, uvec4 t, bvec4 c) { return uvec4(mix(vec4(f), vec4(t), vec4(c))); } + +void SwapIfLarger(inout uint a, inout uint b) { if (a > b) { uint t = a; a = b; b = t; } } +uint DoMedian5(uint p[5]) { + SwapIfLarger(p[0], p[1]); SwapIfLarger(p[3], p[4]); + if (p[3] < p[0]) { uint t = p[1]; p[1] = p[4]; p[4] = t; p[3] = p[0]; } + p[0] = p[2]; SwapIfLarger(p[0], p[1]); + if (p[0] < p[3]) { uint t = p[1]; p[1] = p[4]; p[4] = t; p[0] = p[3]; } + if (p[4] < p[0]) return p[4]; return p[0]; +} +uint DoMedian9(uint p[9]) { + for (int i = 0; i < 9; ++i) { for (int j = i + 1; j < 9; ++j) { SwapIfLarger(p[i], p[j]); } } + return p[4]; +} + +vec4 readTex(sampler2D tex, ivec2 pos) { + pos = clamp(pos, ivec2(0), ivec2(uTextureSize) - 1); + return texelFetch(tex, pos, 0) * MAX_VAL; +} +uvec4 readTexU(sampler2D tex, ivec2 pos) { return uvec4(round(readTex(tex, pos))); } + +uint MedianFirstLeft(sampler2D tex, ivec2 pos, bool isRed) { + uvec4 c = readTexU(tex, pos); uvec4 l = readTexU(tex, pos - ivec2(1, 0)); + uvec4 t2 = readTexU(tex, pos - ivec2(0, 2)); uvec4 b2 = readTexU(tex, pos + ivec2(0, 2)); + if (isRed) { uint p[5] = uint[](t2.x, l.z, c.x, c.z, b2.x); return DoMedian5(p); } + else { + uvec4 t1l = readTexU(tex, pos + ivec2(-1, -1)); uvec4 t1c = readTexU(tex, pos + ivec2(0, -1)); + uvec4 b1l = readTexU(tex, pos + ivec2(-1, 1)); uvec4 b1c = readTexU(tex, pos + ivec2(0, 1)); + uint p[9] = uint[](t2.x, t1l.w, t1c.y, l.z, c.x, c.z, b1l.w, b1c.y, b2.x); return DoMedian9(p); + } +} +uint MedianSecondLeft(sampler2D tex, ivec2 pos, bool isRed) { + uvec4 c = readTexU(tex, pos); uvec4 l = readTexU(tex, pos - ivec2(1, 0)); + uvec4 t2 = readTexU(tex, pos - ivec2(0, 2)); uvec4 b2 = readTexU(tex, pos + ivec2(0, 2)); + if (isRed) { uint p[5] = uint[](t2.y, l.w, c.y, c.w, b2.y); return DoMedian5(p); } + else { + uvec4 t1c = readTexU(tex, pos + ivec2(0, -1)); uvec4 b1c = readTexU(tex, pos + ivec2(0, 1)); + uint p[9] = uint[](t2.y, t1c.x, t1c.z, l.w, c.y, c.w, b1c.x, b1c.z, b2.y); return DoMedian9(p); + } +} +uint MedianFirstRight(sampler2D tex, ivec2 pos, bool isRed) { + uvec4 c = readTexU(tex, pos); uvec4 r = readTexU(tex, pos + ivec2(1, 0)); + uvec4 t2 = readTexU(tex, pos - ivec2(0, 2)); uvec4 b2 = readTexU(tex, pos + ivec2(0, 2)); + if (isRed) { uint p[5] = uint[](t2.z, c.x, c.z, r.x, b2.z); return DoMedian5(p); } + else { + uvec4 t1c = readTexU(tex, pos + ivec2(0, -1)); uvec4 b1c = readTexU(tex, pos + ivec2(0, 1)); + uint p[9] = uint[](t2.z, t1c.y, t1c.w, c.x, c.z, r.x, b1c.y, b1c.w, b2.z); return DoMedian9(p); + } +} +uint MedianSecondRight(sampler2D tex, ivec2 pos, bool isRed) { + uvec4 c = readTexU(tex, pos); uvec4 r = readTexU(tex, pos + ivec2(1, 0)); + uvec4 t2 = readTexU(tex, pos - ivec2(0, 2)); uvec4 b2 = readTexU(tex, pos + ivec2(0, 2)); + if (isRed) { uint p[5] = uint[](t2.w, c.y, c.w, r.y, b2.w); return DoMedian5(p); } + else { + uvec4 t1c = readTexU(tex, pos + ivec2(0, -1)); uvec4 t1r = readTexU(tex, pos + ivec2(1, -1)); + uvec4 b1c = readTexU(tex, pos + ivec2(0, 1)); uvec4 b1r = readTexU(tex, pos + ivec2(1, 1)); + uint p[9] = uint[](t2.w, t1c.z, t1r.x, c.y, c.w, r.y, b1c.z, b1r.x, b2.w); return DoMedian9(p); + } +} + +vec4 GetDiff(sampler2D tex, ivec2 pos2, ivec2 pos, vec4 ratio) { + vec4 fPix = readTex(tex, pos); vec4 grgr = max(fPix - float(uParams.blacklevelOffset), 0.0); + vec4 r1 = grgr / ratio; + vec4 fPix2 = readTex(tex, pos2); vec4 rgrg = max(fPix2 - float(uParams.blacklevelOffset), 0.0); + return r1 + uParams.extraPolFact * (r1 - rgrg); +} +vec4 GetLeft(sampler2D tex, ivec2 pos) { vec4 c = readTex(tex, pos); vec4 l = readTex(tex, pos - ivec2(1,0)); return vec4(l.w, c.x, c.y, c.z); } +vec4 GetRight(sampler2D tex, ivec2 pos) { vec4 c = readTex(tex, pos); vec4 r = readTex(tex, pos + ivec2(1,0)); return vec4(c.y, c.z, c.w, r.x); } +vec4 GetLeft2(sampler2D tex, ivec2 pos) { vec4 c = readTex(tex, pos); vec4 l = readTex(tex, pos - ivec2(1,0)); return vec4(l.z, l.w, c.x, c.y); } +vec4 GetRight2(sampler2D tex, ivec2 pos) { vec4 c = readTex(tex, pos); vec4 r = readTex(tex, pos + ivec2(1,0)); return vec4(c.z, c.w, r.x, r.y); } + +vec4 GetDiffOfs(sampler2D tex, ivec2 pos2, ivec2 pos, vec4 ratio, bool left) { + vec4 grgr = left ? GetLeft(tex, pos) : GetRight(tex, pos); grgr = max(grgr - float(uParams.blacklevelOffset), 0.0); + vec4 r1 = grgr / ratio; + vec4 rgrg = left ? GetLeft2(tex, pos2) : GetRight2(tex, pos2); rgrg = max(rgrg - float(uParams.blacklevelOffset), 0.0); + return r1 + uParams.extraPolFact * (r1 - rgrg); +} + +uvec4 MedianThrTest(sampler2D tex, ivec2 pos, bool isRedRow, vec4 thrLoF, vec4 thrHiF, out uvec4 maskPix) { + uvec4 rC = readTexU(tex, pos); vec4 rCF = vec4(rC); + uvec4 opix = rC; + bvec4 isHigh = greaterThan(rCF, thrHiF); bvec4 isLow = lessThan(rCF, thrLoF); + bvec4 isOut = bvec4(isLow.x||isHigh.x, isLow.y||isHigh.y, isLow.z||isHigh.z, isLow.w||isHigh.w); + if(isOut.x) opix.x = MedianFirstLeft(tex, pos, isRedRow); + if(isOut.y) opix.y = MedianSecondLeft(tex, pos, !isRedRow); + if(isOut.z) opix.z = MedianFirstRight(tex, pos, isRedRow); + if(isOut.w) opix.w = MedianSecondRight(tex, pos, !isRedRow); + bvec4 vHigh = bvec4(isHigh.x && opix.x < rC.x, isHigh.y && opix.y < rC.y, isHigh.z && opix.z < rC.z, isHigh.w && opix.w < rC.w); + maskPix = select_uvec4(uvec4(eHpOk), uvec4(eHpHot), vHigh); + uvec4 opixHigh = select_uvec4(rC, opix, vHigh); + bvec4 vLow = bvec4(isLow.x && opix.x > rC.x, isLow.y && opix.y > rC.y, isLow.z && opix.z > rC.z, isLow.w && opix.w > rC.w); + maskPix = select_uvec4(maskPix, uvec4(eHpPepper), vLow); + return select_uvec4(opixHigh, opix, vLow); +} + +vec4 MinOrMean(vec4 t1, vec4 t2, bvec4 c) { return select_vec4(min(t1,t2), (t1+t2)*0.5, c); } +vec4 MeanOrMax(vec4 t1, vec4 t2, bvec4 c) { return select_vec4(max(t1,t2), (t1+t2)*0.5, c); } + +float2x4 ExtraPolTest(sampler2D tex, ivec2 pos, bool isRedRow, vec2 grRedRatio, vec2 grBlueRatio, bool cluster) { + vec4 gr_bg = vec4(isRedRow?grRedRatio.x:1.0/grBlueRatio.x, isRedRow?1.0/grBlueRatio.x:grRedRatio.x, isRedRow?grRedRatio.y:1.0/grBlueRatio.y, isRedRow?1.0/grBlueRatio.y:grRedRatio.y); + vec4 gr_rg = vec4(isRedRow?grRedRatio.x:1.0/grBlueRatio.x, isRedRow?1.0/grRedRatio.x:grBlueRatio.x, isRedRow?grRedRatio.y:1.0/grBlueRatio.y, isRedRow?1.0/grRedRatio.y:grBlueRatio.y); + ivec4 numR = ivec4(0); ivec4 numF = ivec4(0); + vec4 dT = GetDiff(tex, pos-ivec2(0,2), pos-ivec2(0,1), gr_bg); numR += ivec4(greaterThan(dT, vec4(1.0))); numF += ivec4(lessThan(dT, vec4(-1.0))); + vec4 dB = GetDiff(tex, pos+ivec2(0,2), pos+ivec2(0,1), gr_bg); numR += ivec4(greaterThan(dB, vec4(1.0))); numF += ivec4(lessThan(dB, vec4(-1.0))); + vec4 dL = GetDiffOfs(tex, pos, pos, gr_rg, true); numR += ivec4(greaterThan(dL, vec4(1.0))); numF += ivec4(lessThan(dL, vec4(-1.0))); + vec4 dR = GetDiffOfs(tex, pos, pos, gr_rg, false); numR += ivec4(greaterThan(dR, vec4(1.0))); numF += ivec4(lessThan(dR, vec4(-1.0))); + vec2 brR = vec2(grRedRatio.x/grBlueRatio.x, grRedRatio.y/grBlueRatio.y); + vec4 br_gg = vec4(isRedRow?brR.x:1.0, isRedRow?1.0:brR.x, isRedRow?brR.y:1.0, isRedRow?1.0:brR.y); + vec4 dTL = GetDiffOfs(tex, pos-ivec2(0,2), pos-ivec2(0,1), br_gg, true); numR += ivec4(greaterThan(dTL, vec4(1.0))); numF += ivec4(lessThan(dTL, vec4(-1.0))); + vec4 dTR = GetDiffOfs(tex, pos-ivec2(0,2), pos-ivec2(0,1), br_gg, false); numR += ivec4(greaterThan(dTR, vec4(1.0))); numF += ivec4(lessThan(dTR, vec4(-1.0))); + vec4 dBL = GetDiffOfs(tex, pos+ivec2(0,2), pos+ivec2(0,1), br_gg, true); numR += ivec4(greaterThan(dBL, vec4(1.0))); numF += ivec4(lessThan(dBL, vec4(-1.0))); + vec4 dBR = GetDiffOfs(tex, pos+ivec2(0,2), pos+ivec2(0,1), br_gg, false); numR += ivec4(greaterThan(dBR, vec4(1.0))); numF += ivec4(lessThan(dBR, vec4(-1.0))); + bvec4 isFall = greaterThan(numF, numR + ivec4(uParams.extraPolTestCount)); bvec4 isRise = lessThan(numF, numR - ivec4(uParams.extraPolTestCount)); + vec4 dHM, dVM, dD1M, dD2M, dHm, dVm, dD1m, dD2m; + if (cluster) { + dHM = MinOrMean(dL, dR, isFall); dVM = MinOrMean(dT, dB, isFall); dD1M = MinOrMean(dTL, dBR, isFall); dD2M = MinOrMean(dTR, dBL, isFall); + dHm = (dL+dR)*0.5; dVm = (dT+dB)*0.5; dD1m = (dTL+dBR)*0.5; dD2m = (dTR+dBL)*0.5; + } else { + dHM = MeanOrMax(dL, dR, isFall); dVM = MeanOrMax(dT, dB, isFall); dD1M = MeanOrMax(dTL, dBR, isFall); dD2M = MeanOrMax(dTR, dBL, isFall); + dHm = MinOrMean(dL, dR, isRise); dVm = MinOrMean(dT, dB, isRise); dD1m = MinOrMean(dTL, dBR, isRise); dD2m = MinOrMean(dTR, dBL, isRise); + } + vec4 epMax = max(max(dHM, dVM), max(dD1M, dD2M)) + float(uParams.blacklevelOffset); + vec4 epMin = min(cluster?(dHm+dVm)*0.5:min(dHm,dVm), cluster?(dD1m+dD2m)*0.5:min(dD1m,dD2m)) + float(uParams.blacklevelOffset); + return float2x4(epMin, epMax); +} + +vec4 GetRawMeanSD(sampler2D tex, ivec2 pos, bool isRedRow, out vec4 sdRG, out float rawMeanBlue, out float blueSD) { + vec3 sumRGB = vec3(0.0); + vec3 sumSqRGB = vec3(0.0); + + for (int j = -4; j < 4; ++j) { + // Red/Green Row (Loop 1) + for (int i = -1; i <= 1; ++i) { + vec4 s = readTex(tex, pos + ivec2(i, j)); + vec2 v = isRedRow ? (s.xy+s.zw) : (s.yx+s.wz); // R+R, G+G if RedRow + vec2 sq = isRedRow ? (Sqr(s.xy)+Sqr(s.zw)) : (Sqr(s.yx)+Sqr(s.wz)); + sumRGB.xy += v; // Accumulate R and G + sumSqRGB.xy += sq; + } + j++; + // Comp Row (Loop 2) + for (int k = -1; k <= 1; ++k) { + vec4 s = readTex(tex, pos + ivec2(k, j)); + vec2 v = isRedRow ? (s.xy+s.zw) : (s.yx+s.wz); // G+G, B+B if RedRow + vec2 sq = isRedRow ? (Sqr(s.xy)+Sqr(s.zw)) : (Sqr(s.yx)+Sqr(s.wz)); + sumRGB.yz += v; // Accumulate G and B + sumSqRGB.yz += sq; + } + } + + for (int i = -1; i <= 1; ++i) { + vec4 s = readTex(tex, pos + ivec2(i, 4)); + vec2 v = isRedRow ? (s.xy+s.zw) : (s.yx+s.wz); + vec2 sq = isRedRow ? (Sqr(s.xy)+Sqr(s.zw)) : (Sqr(s.yx)+Sqr(s.wz)); + sumRGB.xy += v; + sumSqRGB.xy += sq; + } + + vec4 c = readTex(tex, pos); + vec4 pc = isRedRow ? c : c.yxwz; // permuted center (R, G, R, G) or (G, B, G, B) + + vec4 totalRG = vec4(sumRGB.xy, sumRGB.xy); + vec4 totalSqRG = vec4(sumSqRGB.xy, sumSqRGB.xy); + + vec4 sumRG = totalRG - pc; + vec4 sumSqRG = totalSqRG - Sqr(pc); + + vec4 scale = vec4(1.0/29.0, 1.0/53.0, 1.0/29.0, 1.0/53.0); + vec4 rawMeanRG = sumRG * scale; + vec4 varRG = max((sumSqRG * scale) - Sqr(rawMeanRG), 0.0); + sdRG = sqrt(varRG); + + rawMeanBlue = sumRGB.z / 24.0; + float varB = max((sumSqRGB.z / 24.0) - Sqr(rawMeanBlue), 0.0); + blueSD = sqrt(varB); + + return rawMeanRG; +} + +float2x4 GetMeanSD4(vec2 sR, vec2 sSq, vec2 sLM, vec2 sRM, vec2 sOL, vec2 sOR, vec4 sc) { + vec4 sumR = vec4(sR.x-sOR.x, sR.y-sRM.x, sR.x-sOL.x, sR.y-sLM.x); + vec4 sumSq = vec4(sSq.x-sOR.y, sSq.y-sRM.y, sSq.x-sOL.y, sSq.y-sLM.y); + vec4 m = sumR * sc; vec4 v = max((sumSq * sc) - Sqr(m), 0.0); + return float2x4(m, sqrt(v)); +} + +mat4 GetColorRedMeanSD4(sampler2D tex, ivec2 pos) { + vec2 sumR = vec2(0.0), sumSq = vec2(0.0); + vec2 sBR_L = vec2(0.0), sBR_R = vec2(0.0), sRR_L = vec2(0.0), sRR_R = vec2(0.0), sGB_L = vec2(0.0), sGB_R = vec2(0.0), sGR_L = vec2(0.0), sGR_R = vec2(0.0); + for (int j = -3; j < 3; ++j) { + for (int i = -1; i <= 1; ++i) { + ivec2 p = pos + ivec2(i, j); vec4 px = readTex(tex, p); vec2 b = vec2(px.y, px.w) - float(uParams.blacklevelOffset); + vec4 p_up = readTex(tex, p + ivec2(0,-1)); vec4 p_dn = readTex(tex, p + ivec2(0,1)); vec4 p_rt = readTex(tex, p + ivec2(1,0)); + vec4 gL = vec4(p_up.y, px.x, px.z, p_dn.y); vec4 gR = vec4(p_up.w, px.z, p_rt.x, p_dn.w); + vec2 gSum = vec2(SumElem(gL), SumElem(gR)) - 4.0 * float(uParams.blacklevelOffset); + vec2 r = max(vec2(uParams.colorRatioModerator), 4.0 * b) / max(vec2(uParams.colorRatioModerator), gSum); vec2 sq = r * r; + sumR.y += r.x + r.y; sumSq.y += sq.x + sq.y; + if (i == -1) sBR_L += vec2(r.x, sq.x); if (i == 1) { sBR_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sBR_L += vec2(r.y, sq.y); } + if (i == 0 && j == 0) { sGB_R += vec2(r.x, sq.x); sGB_L += vec2(r.y, sq.y); } + if (i == -1) { sGB_L += vec2(r.x, sq.x) + vec2(r.y, sq.y); sGB_R += vec2(r.x, sq.x); } + if (i == 1) { sGB_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sGB_L += vec2(r.y, sq.y); } + } + j++; + for (int i = -1; i <= 1; ++i) { + ivec2 p = pos + ivec2(i, j); vec4 px = readTex(tex, p); vec2 rd = vec2(px.x, px.z) - float(uParams.blacklevelOffset); + vec4 p_up = readTex(tex, p + ivec2(0,-1)); vec4 p_dn = readTex(tex, p + ivec2(0,1)); vec4 p_lt = readTex(tex, p + ivec2(-1,0)); + vec4 gL = vec4(p_up.x, p_lt.w, px.y, p_dn.x); vec4 gR = vec4(p_up.z, px.y, px.w, p_dn.z); + vec2 gSum = vec2(SumElem(gL), SumElem(gR)) - 4.0 * float(uParams.blacklevelOffset); + vec2 r = max(vec2(uParams.colorRatioModerator), 4.0 * rd) / max(vec2(uParams.colorRatioModerator), gSum); vec2 sq = r * r; + sumR.x += r.x + r.y; sumSq.x += sq.x + sq.y; + if (i == 0 && j == 0) { sRR_R += vec2(r.x, sq.x); sRR_L += vec2(r.y, sq.y); } + if (i == -1) { sRR_L += vec2(r.x, sq.x) + vec2(r.y, sq.y); sRR_R += vec2(r.x, sq.x); } + if (i == 1) { sRR_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sRR_L += vec2(r.y, sq.y); } + if (i == -1) { sGR_R += vec2(r.x, sq.x); sGR_L += vec2(r.x, sq.x) + vec2(r.y, sq.y); } + if (i == 1) sGR_R += vec2(r.y, sq.y); + } + } + int j = 3; + for (int i = -1; i <= 1; ++i) { + ivec2 p = pos + ivec2(i, j); vec4 px = readTex(tex, p); vec2 b = vec2(px.y, px.w) - float(uParams.blacklevelOffset); + vec4 p_up = readTex(tex, p + ivec2(0,-1)); vec4 p_dn = readTex(tex, p + ivec2(0,1)); vec4 p_rt = readTex(tex, p + ivec2(1,0)); + vec4 gL = vec4(p_up.y, px.x, px.z, p_dn.y); vec4 gR = vec4(p_up.w, px.z, p_rt.x, p_dn.w); + vec2 gSum = vec2(SumElem(gL), SumElem(gR)) - 4.0 * float(uParams.blacklevelOffset); + vec2 r = max(vec2(uParams.colorRatioModerator), 4.0 * b) / max(vec2(uParams.colorRatioModerator), gSum); vec2 sq = r * r; + sumR.y += r.x + r.y; sumSq.y += sq.x + sq.y; + if (i == -1) sBR_L += vec2(r.x, sq.x); if (i == 1) { sBR_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sBR_L += vec2(r.y, sq.y); } + if (i == 0 && j == 0) { sGB_R += vec2(r.x, sq.x); sGB_L += vec2(r.y, sq.y); } + if (i == -1) { sGB_L += vec2(r.x, sq.x) + vec2(r.y, sq.y); sGB_R += vec2(r.x, sq.x); } + if (i == 1) { sGB_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sGB_L += vec2(r.y, sq.y); } + } + float2x4 msR = GetMeanSD4(sumR, sumSq, sBR_L, sBR_R, sRR_L, sRR_R, vec4(1.0/8.0, 1.0/16.0, 1.0/8.0, 1.0/16.0)); + float2x4 msG = GetMeanSD4(sumR, sumSq, sGB_L, sGB_R, sGR_L, sGR_R, vec4(1.0/12.0)); + return mat4(msR.m0, msG.m0, msR.m1, msG.m1); +} + +mat4 GetColorGreenMeanSD4(sampler2D tex, ivec2 pos) { + vec2 sumR = vec2(0.0), sumSq = vec2(0.0); + vec2 sBR_L = vec2(0.0), sBR_R = vec2(0.0), sRR_L = vec2(0.0), sRR_R = vec2(0.0), sGB_L = vec2(0.0), sGB_R = vec2(0.0), sGR_L = vec2(0.0), sGR_R = vec2(0.0); + for (int j = -3; j < 3; ++j) { + for (int i = -1; i <= 1; ++i) { + ivec2 p = pos + ivec2(i, j); vec4 px = readTex(tex, p); vec2 rd = vec2(px.x, px.z) - float(uParams.blacklevelOffset); + vec4 p_up = readTex(tex, p + ivec2(0,-1)); vec4 p_dn = readTex(tex, p + ivec2(0,1)); vec4 p_lt = readTex(tex, p + ivec2(-1,0)); + vec4 gL = vec4(p_up.x, p_lt.w, px.y, p_dn.x); vec4 gR = vec4(p_up.z, px.y, px.w, p_dn.z); + vec2 gSum = vec2(SumElem(gL), SumElem(gR)) - 4.0 * float(uParams.blacklevelOffset); + vec2 r = max(vec2(uParams.colorRatioModerator), 4.0 * rd) / max(vec2(uParams.colorRatioModerator), gSum); vec2 sq = r * r; + sumR.x += r.x + r.y; sumSq.x += sq.x + sq.y; + if (i == 0 && j == 0) { sRR_R += vec2(r.x, sq.x); sRR_L += vec2(r.y, sq.y); } + if (i == -1) { sRR_L += vec2(r.x, sq.x) + vec2(r.y, sq.y); sRR_R += vec2(r.x, sq.x); } + if (i == 1) { sRR_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sRR_L += vec2(r.y, sq.y); } + if (i == -1) { sGR_R += vec2(r.x, sq.x); sGR_L += vec2(r.x, sq.x) + vec2(r.y, sq.y); } + if (i == 1) sGR_R += vec2(r.y, sq.y); + } + j++; + for (int i = -1; i <= 1; ++i) { + ivec2 p = pos + ivec2(i, j); vec4 px = readTex(tex, p); vec2 b = vec2(px.y, px.w) - float(uParams.blacklevelOffset); + vec4 p_up = readTex(tex, p + ivec2(0,-1)); vec4 p_dn = readTex(tex, p + ivec2(0,1)); vec4 p_rt = readTex(tex, p + ivec2(1,0)); + vec4 gL = vec4(p_up.y, px.x, px.z, p_dn.y); vec4 gR = vec4(p_up.w, px.z, p_rt.x, p_dn.w); + vec2 gSum = vec2(SumElem(gL), SumElem(gR)) - 4.0 * float(uParams.blacklevelOffset); + vec2 r = max(vec2(uParams.colorRatioModerator), 4.0 * b) / max(vec2(uParams.colorRatioModerator), gSum); vec2 sq = r * r; + sumR.y += r.x + r.y; sumSq.y += sq.x + sq.y; + if (i == -1) sBR_L += vec2(r.x, sq.x); if (i == 1) { sBR_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sBR_L += vec2(r.y, sq.y); } + if (i == 0 && j == 0) { sGB_R += vec2(r.x, sq.x); sGB_L += vec2(r.y, sq.y); } + if (i == -1) { sGB_L += vec2(r.x, sq.x) + vec2(r.y, sq.y); sGB_R += vec2(r.x, sq.x); } + if (i == 1) { sGB_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sGB_L += vec2(r.y, sq.y); } + } + } + float2x4 msR = GetMeanSD4(sumR, sumSq, sBR_L, sBR_R, sRR_L, sRR_R, vec4(1.0/12.0)); + float2x4 msG = GetMeanSD4(sumR, sumSq, sGB_L, sGB_R, sGR_L, sGR_R, vec4(1.0/16.0, 1.0/8.0, 1.0/16.0, 1.0/8.0)); + return mat4(msR.m0, msG.m0, msR.m1, msG.m1); +} + +uvec4 readMask(ivec2 pos) { + ivec2 mp = pos + ivec2(uParams.mapOfsX / 4, uParams.mapOfsY); + return uvec4(round(texelFetch(uInputTexture1, mp, 0) * 255.0)); +} + +uvec4 doHotPixCluster(ivec2 pos, bool isRedRow) { + vec4 sdRG; float rawMeanB, blueSd; + vec4 rawMeanRG = GetRawMeanSD(uInputTexture0, pos, isRedRow, sdRG, rawMeanB, blueSd); + vec4 meanRG = max(rawMeanRG - float(uParams.blacklevelOffset), uParams.colorMeanModerator); + vec4 meanRGratio, meanBGratio; + if (isRedRow) { + mat4 ms = GetColorRedMeanSD4(uInputTexture0, pos); + meanRGratio = ms[0]; meanBGratio = ms[1]; + } else { + mat4 ms = GetColorGreenMeanSD4(uInputTexture0, pos); + meanBGratio = ms[0]; meanRGratio = ms[1]; + } + vec2 grRed = vec2(2.0/(meanRGratio.x+meanRGratio.y), 2.0/(meanRGratio.z+meanRGratio.w)); + vec2 grBlue = vec2(2.0/(meanBGratio.x+meanBGratio.y), 2.0/(meanBGratio.z+meanBGratio.w)); + vec4 sFactHi = vec4(uParams.sDFactHiRedBlue, uParams.sDFactHiGreen, uParams.sDFactHiRedBlue, uParams.sDFactHiGreen); + vec4 diffHi = max(max(sFactHi * sdRG, uParams.trivialDiffThr), meanRG * uParams.meanHighFact); + vec4 thrMeanRGHi = rawMeanRG + diffHi; + float2x4 ep = ExtraPolTest(uInputTexture0, pos, isRedRow, grRed, grBlue, true); + + uvec4 mL = uvec4(0), mT = uvec4(0), mR = uvec4(0), mB = uvec4(0); + if (uParams.mapOfsX != 0 || uParams.mapOfsY != 0) { + mT = readMask(pos + ivec2(0, -1)); mB = readMask(pos + ivec2(0, 1)); + uvec4 c = readMask(pos); uvec4 l = readMask(pos + ivec2(-1, 0)); uvec4 r = readMask(pos + ivec2(1, 0)); + mL = uvec4(l.w, c.x, c.y, c.z); mR = uvec4(c.y, c.z, c.w, r.x); + } + + bvec4 nL = notEqual(mL, uvec4(eHpHot)); + bvec4 nT = notEqual(mT, uvec4(eHpHot)); + bvec4 nR = notEqual(mR, uvec4(eHpHot)); + bvec4 nB = notEqual(mB, uvec4(eHpHot)); + + bvec4 mTest = bvec4(vec4(nL) * vec4(nT) * vec4(nR) * vec4(nB)); + + ep.m1 *= vec4(mTest); + + vec4 thrHi = max(min(isRedRow?thrMeanRGHi:thrMeanRGHi.yxwz, 65535.0), ep.m1); + vec4 diffLo = max(uParams.sDFactLo * sdRG, uParams.trivialDiffThr); + vec4 thrMeanRGLo = min(vec4(float(uParams.blacklevelOffset) + meanRG * uParams.meanLowFact), rawMeanRG - diffLo); + vec4 thrLo = min(isRedRow?thrMeanRGLo:thrMeanRGLo.yxwz, ep.m0); + + uvec4 dum; + return MedianThrTest(uInputTexture0, pos, isRedRow, thrLo, thrHi, dum); +} + +void main() { + ivec2 margin = ivec2(int(uParams.marginX) / 4, int(uParams.marginY)); + ivec2 srcCoord = ivec2(gl_FragCoord.xy) + margin; + bool leftmostisGreen = ((int(gl_FragCoord.y)) & 1) == 1; + uvec4 outColor = doHotPixCluster(srcCoord, !leftmostisGreen); + FragColor = vec4(outColor) / MAX_VAL; +} diff --git a/research/phocus_glsl/01_raw_sensor/hotPixel_0x302af8e.frag b/research/phocus_glsl/01_raw_sensor/hotPixel_0x302af8e.frag new file mode 100644 index 00000000..701a92d4 --- /dev/null +++ b/research/phocus_glsl/01_raw_sensor/hotPixel_0x302af8e.frag @@ -0,0 +1,364 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 8012955d7c0a1c85bc5fb7d07a3f289631214a7796b86283a33c7b201cd7ce76 + * ELF offsets: 0x302af8e + * Symbols: hotPixel_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp int; +precision highp sampler2D; + +layout(location = 0) out vec4 FragColor; +layout(location = 1) out vec4 FragMask; + +uniform sampler2D uInputTexture0; // Image (Packed Bayer RGBA) + +const float MAX_VAL = 65535.0; +const int eHpPepper = 0; +const int eHpOk = 32; +const int eHpHot = 255; + +// UBO 定义 (std140) +layout(std140) uniform HotPixelParams { + float trivialDiffThr; + float extraPolFact; + float meanLowFact; + float meanHighFact; + float sDFactLo; + float colorRatioModerator; + float colorMeanModerator; + float pad0; + int blacklevelOffset; + int extraPolTestCount; + float sDFactHiRedBlue; + float sDFactHiGreen; + int mapOfsX; + int mapOfsY; + uint marginX; + uint marginY; + int trivialPepperMinThr; + int cluster; + float pad1; + float pad2; +} uParams; + +uniform vec2 uTextureSize; + +struct float2x4 { vec4 m0; vec4 m1; }; + +float SumElem(vec4 v) { return v.x + v.y + v.z + v.w; } +float Sqr(float a) { return a * a; } +vec2 Sqr(vec2 a) { return a * a; } +vec3 Sqr(vec3 a) { return a * a; } +vec4 Sqr(vec4 a) { return a * a; } + +vec4 select_vec4(vec4 f, vec4 t, bvec4 c) { return mix(f, t, vec4(c)); } +uvec4 select_uvec4(uvec4 f, uvec4 t, bvec4 c) { return uvec4(mix(vec4(f), vec4(t), vec4(c))); } + +void SwapIfLarger(inout uint a, inout uint b) { if (a > b) { uint t = a; a = b; b = t; } } +uint DoMedian5(uint p[5]) { + SwapIfLarger(p[0], p[1]); SwapIfLarger(p[3], p[4]); + if (p[3] < p[0]) { uint t = p[1]; p[1] = p[4]; p[4] = t; p[3] = p[0]; } + p[0] = p[2]; SwapIfLarger(p[0], p[1]); + if (p[0] < p[3]) { uint t = p[1]; p[1] = p[4]; p[4] = t; p[0] = p[3]; } + if (p[4] < p[0]) return p[4]; return p[0]; +} +uint DoMedian9(uint p[9]) { + for (int i = 0; i < 9; ++i) { for (int j = i + 1; j < 9; ++j) { SwapIfLarger(p[i], p[j]); } } + return p[4]; +} + +vec4 readTex(sampler2D tex, ivec2 pos) { + pos = clamp(pos, ivec2(0), ivec2(uTextureSize) - 1); + return texelFetch(tex, pos, 0) * MAX_VAL; +} +uvec4 readTexU(sampler2D tex, ivec2 pos) { return uvec4(round(readTex(tex, pos))); } + +uint MedianFirstLeft(sampler2D tex, ivec2 pos, bool isRed) { + uvec4 c = readTexU(tex, pos); uvec4 l = readTexU(tex, pos - ivec2(1, 0)); + uvec4 t2 = readTexU(tex, pos - ivec2(0, 2)); uvec4 b2 = readTexU(tex, pos + ivec2(0, 2)); + if (isRed) { uint p[5] = uint[](t2.x, l.z, c.x, c.z, b2.x); return DoMedian5(p); } + else { + uvec4 t1l = readTexU(tex, pos + ivec2(-1, -1)); uvec4 t1c = readTexU(tex, pos + ivec2(0, -1)); + uvec4 b1l = readTexU(tex, pos + ivec2(-1, 1)); uvec4 b1c = readTexU(tex, pos + ivec2(0, 1)); + uint p[9] = uint[](t2.x, t1l.w, t1c.y, l.z, c.x, c.z, b1l.w, b1c.y, b2.x); return DoMedian9(p); + } +} + +uint MedianSecondLeft(sampler2D tex, ivec2 pos, bool isRed) { + uvec4 c = readTexU(tex, pos); uvec4 l = readTexU(tex, pos - ivec2(1, 0)); + uvec4 t2 = readTexU(tex, pos - ivec2(0, 2)); uvec4 b2 = readTexU(tex, pos + ivec2(0, 2)); + if (isRed) { uint p[5] = uint[](t2.y, l.w, c.y, c.w, b2.y); return DoMedian5(p); } + else { + uvec4 t1c = readTexU(tex, pos + ivec2(0, -1)); uvec4 b1c = readTexU(tex, pos + ivec2(0, 1)); + uint p[9] = uint[](t2.y, t1c.x, t1c.z, l.w, c.y, c.w, b1c.x, b1c.z, b2.y); return DoMedian9(p); + } +} + +uint MedianFirstRight(sampler2D tex, ivec2 pos, bool isRed) { + uvec4 c = readTexU(tex, pos); uvec4 r = readTexU(tex, pos + ivec2(1, 0)); + uvec4 t2 = readTexU(tex, pos - ivec2(0, 2)); uvec4 b2 = readTexU(tex, pos + ivec2(0, 2)); + if (isRed) { uint p[5] = uint[](t2.z, c.x, c.z, r.x, b2.z); return DoMedian5(p); } + else { + uvec4 t1c = readTexU(tex, pos + ivec2(0, -1)); uvec4 b1c = readTexU(tex, pos + ivec2(0, 1)); + uint p[9] = uint[](t2.z, t1c.y, t1c.w, c.x, c.z, r.x, b1c.y, b1c.w, b2.z); return DoMedian9(p); + } +} + +uint MedianSecondRight(sampler2D tex, ivec2 pos, bool isRed) { + uvec4 c = readTexU(tex, pos); uvec4 r = readTexU(tex, pos + ivec2(1, 0)); + uvec4 t2 = readTexU(tex, pos - ivec2(0, 2)); uvec4 b2 = readTexU(tex, pos + ivec2(0, 2)); + if (isRed) { uint p[5] = uint[](t2.w, c.y, c.w, r.y, b2.w); return DoMedian5(p); } + else { + uvec4 t1c = readTexU(tex, pos + ivec2(0, -1)); uvec4 t1r = readTexU(tex, pos + ivec2(1, -1)); + uvec4 b1c = readTexU(tex, pos + ivec2(0, 1)); uvec4 b1r = readTexU(tex, pos + ivec2(1, 1)); + uint p[9] = uint[](t2.w, t1c.z, t1r.x, c.y, c.w, r.y, b1c.z, b1r.x, b2.w); return DoMedian9(p); + } +} + +vec4 GetDiff(sampler2D tex, ivec2 pos2, ivec2 pos, vec4 ratio) { + vec4 fPix = readTex(tex, pos); vec4 grgr = max(fPix - float(uParams.blacklevelOffset), 0.0); + vec4 r1 = grgr / ratio; + vec4 fPix2 = readTex(tex, pos2); vec4 rgrg = max(fPix2 - float(uParams.blacklevelOffset), 0.0); + return r1 + uParams.extraPolFact * (r1 - rgrg); +} + +vec4 GetLeft(sampler2D tex, ivec2 pos) { vec4 c = readTex(tex, pos); vec4 l = readTex(tex, pos - ivec2(1,0)); return vec4(l.w, c.x, c.y, c.z); } +vec4 GetRight(sampler2D tex, ivec2 pos) { vec4 c = readTex(tex, pos); vec4 r = readTex(tex, pos + ivec2(1,0)); return vec4(c.y, c.z, c.w, r.x); } +vec4 GetLeft2(sampler2D tex, ivec2 pos) { vec4 c = readTex(tex, pos); vec4 l = readTex(tex, pos - ivec2(1,0)); return vec4(l.z, l.w, c.x, c.y); } +vec4 GetRight2(sampler2D tex, ivec2 pos) { vec4 c = readTex(tex, pos); vec4 r = readTex(tex, pos + ivec2(1,0)); return vec4(c.z, c.w, r.x, r.y); } + +vec4 GetDiffOfs(sampler2D tex, ivec2 pos2, ivec2 pos, vec4 ratio, bool left) { + vec4 grgr = left ? GetLeft(tex, pos) : GetRight(tex, pos); grgr = max(grgr - float(uParams.blacklevelOffset), 0.0); + vec4 r1 = grgr / ratio; + vec4 rgrg = left ? GetLeft2(tex, pos2) : GetRight2(tex, pos2); rgrg = max(rgrg - float(uParams.blacklevelOffset), 0.0); + return r1 + uParams.extraPolFact * (r1 - rgrg); +} + +uvec4 MedianThrTest(sampler2D tex, ivec2 pos, bool isRedRow, vec4 thrLoF, vec4 thrHiF, out uvec4 maskPix) { + uvec4 rC = readTexU(tex, pos); vec4 rCF = vec4(rC); + uvec4 opix = rC; + bvec4 isHigh = greaterThan(rCF, thrHiF); bvec4 isLow = lessThan(rCF, thrLoF); + bvec4 isOut = bvec4(isLow.x||isHigh.x, isLow.y||isHigh.y, isLow.z||isHigh.z, isLow.w||isHigh.w); + if(isOut.x) opix.x = MedianFirstLeft(tex, pos, isRedRow); + if(isOut.y) opix.y = MedianSecondLeft(tex, pos, !isRedRow); + if(isOut.z) opix.z = MedianFirstRight(tex, pos, isRedRow); + if(isOut.w) opix.w = MedianSecondRight(tex, pos, !isRedRow); + bvec4 vHigh = bvec4(isHigh.x && opix.x < rC.x, isHigh.y && opix.y < rC.y, isHigh.z && opix.z < rC.z, isHigh.w && opix.w < rC.w); + maskPix = select_uvec4(uvec4(eHpOk), uvec4(eHpHot), vHigh); + uvec4 opixHigh = select_uvec4(rC, opix, vHigh); + bvec4 vLow = bvec4(isLow.x && opix.x > rC.x, isLow.y && opix.y > rC.y, isLow.z && opix.z > rC.z, isLow.w && opix.w > rC.w); + maskPix = select_uvec4(maskPix, uvec4(eHpPepper), vLow); + return select_uvec4(opixHigh, opix, vLow); +} + +vec4 MinOrMean(vec4 t1, vec4 t2, bvec4 c) { return select_vec4(min(t1,t2), (t1+t2)*0.5, c); } +vec4 MeanOrMax(vec4 t1, vec4 t2, bvec4 c) { return select_vec4(max(t1,t2), (t1+t2)*0.5, c); } + +float2x4 ExtraPolTest(sampler2D tex, ivec2 pos, bool isRedRow, vec2 grRedRatio, vec2 grBlueRatio, bool cluster) { + vec4 gr_bg = vec4(isRedRow?grRedRatio.x:1.0/grBlueRatio.x, isRedRow?1.0/grBlueRatio.x:grRedRatio.x, isRedRow?grRedRatio.y:1.0/grBlueRatio.y, isRedRow?1.0/grBlueRatio.y:grRedRatio.y); + vec4 gr_rg = vec4(isRedRow?grRedRatio.x:1.0/grBlueRatio.x, isRedRow?1.0/grRedRatio.x:grBlueRatio.x, isRedRow?grRedRatio.y:1.0/grBlueRatio.y, isRedRow?1.0/grRedRatio.y:grBlueRatio.y); + ivec4 numR = ivec4(0); ivec4 numF = ivec4(0); + vec4 dT = GetDiff(tex, pos-ivec2(0,2), pos-ivec2(0,1), gr_bg); numR += ivec4(greaterThan(dT, vec4(1.0))); numF += ivec4(lessThan(dT, vec4(-1.0))); + vec4 dB = GetDiff(tex, pos+ivec2(0,2), pos+ivec2(0,1), gr_bg); numR += ivec4(greaterThan(dB, vec4(1.0))); numF += ivec4(lessThan(dB, vec4(-1.0))); + vec4 dL = GetDiffOfs(tex, pos, pos, gr_rg, true); numR += ivec4(greaterThan(dL, vec4(1.0))); numF += ivec4(lessThan(dL, vec4(-1.0))); + vec4 dR = GetDiffOfs(tex, pos, pos, gr_rg, false); numR += ivec4(greaterThan(dR, vec4(1.0))); numF += ivec4(lessThan(dR, vec4(-1.0))); + vec2 brR = vec2(grRedRatio.x/grBlueRatio.x, grRedRatio.y/grBlueRatio.y); + vec4 br_gg = vec4(isRedRow?brR.x:1.0, isRedRow?1.0:brR.x, isRedRow?brR.y:1.0, isRedRow?1.0:brR.y); + vec4 dTL = GetDiffOfs(tex, pos-ivec2(0,2), pos-ivec2(0,1), br_gg, true); numR += ivec4(greaterThan(dTL, vec4(1.0))); numF += ivec4(lessThan(dTL, vec4(-1.0))); + vec4 dTR = GetDiffOfs(tex, pos-ivec2(0,2), pos-ivec2(0,1), br_gg, false); numR += ivec4(greaterThan(dTR, vec4(1.0))); numF += ivec4(lessThan(dTR, vec4(-1.0))); + vec4 dBL = GetDiffOfs(tex, pos+ivec2(0,2), pos+ivec2(0,1), br_gg, true); numR += ivec4(greaterThan(dBL, vec4(1.0))); numF += ivec4(lessThan(dBL, vec4(-1.0))); + vec4 dBR = GetDiffOfs(tex, pos+ivec2(0,2), pos+ivec2(0,1), br_gg, false); numR += ivec4(greaterThan(dBR, vec4(1.0))); numF += ivec4(lessThan(dBR, vec4(-1.0))); + bvec4 isFall = greaterThan(numF, numR + ivec4(uParams.extraPolTestCount)); bvec4 isRise = lessThan(numF, numR - ivec4(uParams.extraPolTestCount)); + vec4 dHM, dVM, dD1M, dD2M, dHm, dVm, dD1m, dD2m; + if (cluster) { + dHM = MinOrMean(dL, dR, isFall); dVM = MinOrMean(dT, dB, isFall); dD1M = MinOrMean(dTL, dBR, isFall); dD2M = MinOrMean(dTR, dBL, isFall); + dHm = (dL+dR)*0.5; dVm = (dT+dB)*0.5; dD1m = (dTL+dBR)*0.5; dD2m = (dTR+dBL)*0.5; + } else { + dHM = MeanOrMax(dL, dR, isFall); dVM = MeanOrMax(dT, dB, isFall); dD1M = MeanOrMax(dTL, dBR, isFall); dD2M = MeanOrMax(dTR, dBL, isFall); + dHm = MinOrMean(dL, dR, isRise); dVm = MinOrMean(dT, dB, isRise); dD1m = MinOrMean(dTL, dBR, isRise); dD2m = MinOrMean(dTR, dBL, isRise); + } + vec4 epMax = max(max(dHM, dVM), max(dD1M, dD2M)) + float(uParams.blacklevelOffset); + vec4 epMin = min(cluster?(dHm+dVm)*0.5:min(dHm,dVm), cluster?(dD1m+dD2m)*0.5:min(dD1m,dD2m)) + float(uParams.blacklevelOffset); + return float2x4(epMin, epMax); +} + +vec4 GetRawMeanSD(sampler2D tex, ivec2 pos, bool isRedRow, out vec4 sdRG, out float rawMeanBlue, out float blueSD) { + vec3 sumRGB = vec3(0.0); + vec3 sumSqRGB = vec3(0.0); + + for (int j = -4; j < 4; ++j) { + // Red/Green Row (Loop 1) + for (int i = -1; i <= 1; ++i) { + vec4 s = readTex(tex, pos + ivec2(i, j)); + vec2 v = isRedRow ? (s.xy+s.zw) : (s.yx+s.wz); // R+R, G+G if RedRow + vec2 sq = isRedRow ? (Sqr(s.xy)+Sqr(s.zw)) : (Sqr(s.yx)+Sqr(s.wz)); + sumRGB.xy += v; // Accumulate R and G + sumSqRGB.xy += sq; + } + j++; + // Comp Row (Loop 2) + for (int k = -1; k <= 1; ++k) { + vec4 s = readTex(tex, pos + ivec2(k, j)); + vec2 v = isRedRow ? (s.xy+s.zw) : (s.yx+s.wz); // G+G, B+B if RedRow + vec2 sq = isRedRow ? (Sqr(s.xy)+Sqr(s.zw)) : (Sqr(s.yx)+Sqr(s.wz)); + sumRGB.yz += v; // Accumulate G and B + sumSqRGB.yz += sq; + } + } + for (int i = -1; i <= 1; ++i) { + vec4 s = readTex(tex, pos + ivec2(i, 4)); + vec2 v = isRedRow ? (s.xy+s.zw) : (s.yx+s.wz); + vec2 sq = isRedRow ? (Sqr(s.xy)+Sqr(s.zw)) : (Sqr(s.yx)+Sqr(s.wz)); + sumRGB.xy += v; + sumSqRGB.xy += sq; + } + + vec4 c = readTex(tex, pos); + vec4 pc = isRedRow ? c : c.yxwz; // permuted center (R, G, R, G) or (G, B, G, B) + + vec4 totalRG = vec4(sumRGB.xy, sumRGB.xy); + vec4 totalSqRG = vec4(sumSqRGB.xy, sumSqRGB.xy); + + vec4 sumRG = totalRG - pc; + vec4 sumSqRG = totalSqRG - Sqr(pc); + + vec4 scale = vec4(1.0/29.0, 1.0/53.0, 1.0/29.0, 1.0/53.0); + vec4 rawMeanRG = sumRG * scale; + vec4 varRG = max((sumSqRG * scale) - Sqr(rawMeanRG), 0.0); + sdRG = sqrt(varRG); + + rawMeanBlue = sumRGB.z / 24.0; + float varB = max((sumSqRGB.z / 24.0) - Sqr(rawMeanBlue), 0.0); + blueSD = sqrt(varB); + + return rawMeanRG; +} + +float2x4 GetMeanSD4(vec2 sR, vec2 sSq, vec2 sLM, vec2 sRM, vec2 sOL, vec2 sOR, vec4 sc) { + vec4 sumR = vec4(sR.x-sOR.x, sR.y-sRM.x, sR.x-sOL.x, sR.y-sLM.x); + vec4 sumSq = vec4(sSq.x-sOR.y, sSq.y-sRM.y, sSq.x-sOL.y, sSq.y-sLM.y); + vec4 m = sumR * sc; vec4 v = max((sumSq * sc) - Sqr(m), 0.0); + return float2x4(m, sqrt(v)); +} + +mat4 GetColorRedMeanSD4(sampler2D tex, ivec2 pos) { + vec2 sumR = vec2(0.0), sumSq = vec2(0.0); + vec2 sBR_L = vec2(0.0), sBR_R = vec2(0.0), sRR_L = vec2(0.0), sRR_R = vec2(0.0), sGB_L = vec2(0.0), sGB_R = vec2(0.0), sGR_L = vec2(0.0), sGR_R = vec2(0.0); + for (int j = -3; j < 3; ++j) { + for (int i = -1; i <= 1; ++i) { + ivec2 p = pos + ivec2(i, j); vec4 px = readTex(tex, p); vec2 b = vec2(px.y, px.w) - float(uParams.blacklevelOffset); + vec4 p_up = readTex(tex, p + ivec2(0,-1)); vec4 p_dn = readTex(tex, p + ivec2(0,1)); vec4 p_rt = readTex(tex, p + ivec2(1,0)); + vec4 gL = vec4(p_up.y, px.x, px.z, p_dn.y); vec4 gR = vec4(p_up.w, px.z, p_rt.x, p_dn.w); + vec2 gSum = vec2(SumElem(gL), SumElem(gR)) - 4.0 * float(uParams.blacklevelOffset); + vec2 r = max(vec2(uParams.colorRatioModerator), 4.0 * b) / max(vec2(uParams.colorRatioModerator), gSum); vec2 sq = r * r; + sumR.y += r.x + r.y; sumSq.y += sq.x + sq.y; + if (i == -1) sBR_L += vec2(r.x, sq.x); if (i == 1) { sBR_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sBR_L += vec2(r.y, sq.y); } + if (i == 0 && j == 0) { sGB_R += vec2(r.x, sq.x); sGB_L += vec2(r.y, sq.y); } + if (i == -1) { sGB_L += vec2(r.x, sq.x) + vec2(r.y, sq.y); sGB_R += vec2(r.x, sq.x); } + if (i == 1) { sGB_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sGB_L += vec2(r.y, sq.y); } + } + j++; + for (int i = -1; i <= 1; ++i) { + ivec2 p = pos + ivec2(i, j); vec4 px = readTex(tex, p); vec2 rd = vec2(px.x, px.z) - float(uParams.blacklevelOffset); + vec4 p_up = readTex(tex, p + ivec2(0,-1)); vec4 p_dn = readTex(tex, p + ivec2(0,1)); vec4 p_lt = readTex(tex, p + ivec2(-1,0)); + vec4 gL = vec4(p_up.x, p_lt.w, px.y, p_dn.x); vec4 gR = vec4(p_up.z, px.y, px.w, p_dn.z); + vec2 gSum = vec2(SumElem(gL), SumElem(gR)) - 4.0 * float(uParams.blacklevelOffset); + vec2 r = max(vec2(uParams.colorRatioModerator), 4.0 * rd) / max(vec2(uParams.colorRatioModerator), gSum); vec2 sq = r * r; + sumR.x += r.x + r.y; sumSq.x += sq.x + sq.y; + if (i == 0 && j == 0) { sRR_R += vec2(r.x, sq.x); sRR_L += vec2(r.y, sq.y); } + if (i == -1) { sRR_L += vec2(r.x, sq.x) + vec2(r.y, sq.y); sRR_R += vec2(r.x, sq.x); } + if (i == 1) { sRR_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sRR_L += vec2(r.y, sq.y); } + if (i == -1) { sGR_R += vec2(r.x, sq.x); sGR_L += vec2(r.x, sq.x) + vec2(r.y, sq.y); } + if (i == 1) sGR_R += vec2(r.y, sq.y); + } + } + int j = 3; + for (int i = -1; i <= 1; ++i) { + ivec2 p = pos + ivec2(i, j); vec4 px = readTex(tex, p); vec2 b = vec2(px.y, px.w) - float(uParams.blacklevelOffset); + vec4 p_up = readTex(tex, p + ivec2(0,-1)); vec4 p_dn = readTex(tex, p + ivec2(0,1)); vec4 p_rt = readTex(tex, p + ivec2(1,0)); + vec4 gL = vec4(p_up.y, px.x, px.z, p_dn.y); vec4 gR = vec4(p_up.w, px.z, p_rt.x, p_dn.w); + vec2 gSum = vec2(SumElem(gL), SumElem(gR)) - 4.0 * float(uParams.blacklevelOffset); + vec2 r = max(vec2(uParams.colorRatioModerator), 4.0 * b) / max(vec2(uParams.colorRatioModerator), gSum); vec2 sq = r * r; + sumR.y += r.x + r.y; sumSq.y += sq.x + sq.y; + if (i == -1) sBR_L += vec2(r.x, sq.x); if (i == 1) { sBR_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sBR_L += vec2(r.y, sq.y); } + if (i == 0 && j == 0) { sGB_R += vec2(r.x, sq.x); sGB_L += vec2(r.y, sq.y); } + if (i == -1) { sGB_L += vec2(r.x, sq.x) + vec2(r.y, sq.y); sGB_R += vec2(r.x, sq.x); } + if (i == 1) { sGB_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sGB_L += vec2(r.y, sq.y); } + } + float2x4 msR = GetMeanSD4(sumR, sumSq, sBR_L, sBR_R, sRR_L, sRR_R, vec4(1.0/8.0, 1.0/16.0, 1.0/8.0, 1.0/16.0)); + float2x4 msG = GetMeanSD4(sumR, sumSq, sGB_L, sGB_R, sGR_L, sGR_R, vec4(1.0/12.0)); + return mat4(msR.m0, msG.m0, msR.m1, msG.m1); +} + +mat4 GetColorGreenMeanSD4(sampler2D tex, ivec2 pos) { + vec2 sumR = vec2(0.0), sumSq = vec2(0.0); + vec2 sBR_L = vec2(0.0), sBR_R = vec2(0.0), sRR_L = vec2(0.0), sRR_R = vec2(0.0), sGB_L = vec2(0.0), sGB_R = vec2(0.0), sGR_L = vec2(0.0), sGR_R = vec2(0.0); + for (int j = -3; j < 3; ++j) { + for (int i = -1; i <= 1; ++i) { + ivec2 p = pos + ivec2(i, j); vec4 px = readTex(tex, p); vec2 rd = vec2(px.x, px.z) - float(uParams.blacklevelOffset); + vec4 p_up = readTex(tex, p + ivec2(0,-1)); vec4 p_dn = readTex(tex, p + ivec2(0,1)); vec4 p_lt = readTex(tex, p + ivec2(-1,0)); + vec4 gL = vec4(p_up.x, p_lt.w, px.y, p_dn.x); vec4 gR = vec4(p_up.z, px.y, px.w, p_dn.z); + vec2 gSum = vec2(SumElem(gL), SumElem(gR)) - 4.0 * float(uParams.blacklevelOffset); + vec2 r = max(vec2(uParams.colorRatioModerator), 4.0 * rd) / max(vec2(uParams.colorRatioModerator), gSum); vec2 sq = r * r; + sumR.x += r.x + r.y; sumSq.x += sq.x + sq.y; + if (i == 0 && j == 0) { sRR_R += vec2(r.x, sq.x); sRR_L += vec2(r.y, sq.y); } + if (i == -1) { sRR_L += vec2(r.x, sq.x) + vec2(r.y, sq.y); sRR_R += vec2(r.x, sq.x); } + if (i == 1) { sRR_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sRR_L += vec2(r.y, sq.y); } + if (i == -1) { sGR_R += vec2(r.x, sq.x); sGR_L += vec2(r.x, sq.x) + vec2(r.y, sq.y); } + if (i == 1) sGR_R += vec2(r.y, sq.y); + } + j++; + for (int i = -1; i <= 1; ++i) { + ivec2 p = pos + ivec2(i, j); vec4 px = readTex(tex, p); vec2 b = vec2(px.y, px.w) - float(uParams.blacklevelOffset); + vec4 p_up = readTex(tex, p + ivec2(0,-1)); vec4 p_dn = readTex(tex, p + ivec2(0,1)); vec4 p_rt = readTex(tex, p + ivec2(1,0)); + vec4 gL = vec4(p_up.y, px.x, px.z, p_dn.y); vec4 gR = vec4(p_up.w, px.z, p_rt.x, p_dn.w); + vec2 gSum = vec2(SumElem(gL), SumElem(gR)) - 4.0 * float(uParams.blacklevelOffset); + vec2 r = max(vec2(uParams.colorRatioModerator), 4.0 * b) / max(vec2(uParams.colorRatioModerator), gSum); vec2 sq = r * r; + sumR.y += r.x + r.y; sumSq.y += sq.x + sq.y; + if (i == -1) sBR_L += vec2(r.x, sq.x); if (i == 1) { sBR_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sBR_L += vec2(r.y, sq.y); } + if (i == 0 && j == 0) { sGB_R += vec2(r.x, sq.x); sGB_L += vec2(r.y, sq.y); } + if (i == -1) { sGB_L += vec2(r.x, sq.x) + vec2(r.y, sq.y); sGB_R += vec2(r.x, sq.x); } + if (i == 1) { sGB_R += vec2(r.x, sq.x) + vec2(r.y, sq.y); sGB_L += vec2(r.y, sq.y); } + } + } + float2x4 msR = GetMeanSD4(sumR, sumSq, sBR_L, sBR_R, sRR_L, sRR_R, vec4(1.0/12.0)); + float2x4 msG = GetMeanSD4(sumR, sumSq, sGB_L, sGB_R, sGR_L, sGR_R, vec4(1.0/16.0, 1.0/8.0, 1.0/16.0, 1.0/8.0)); + return mat4(msR.m0, msG.m0, msR.m1, msG.m1); +} + +uvec4 doHotPix(ivec2 pos, bool isRedRow, out uvec4 maskVal) { + vec4 sdRG; float rawMeanB, sdB; + vec4 rawMeanRG = GetRawMeanSD(uInputTexture0, pos, isRedRow, sdRG, rawMeanB, sdB); + vec4 meanRGratio, meanBGratio; + if (isRedRow) { + mat4 ms = GetColorRedMeanSD4(uInputTexture0, pos); + meanRGratio = ms[0]; meanBGratio = ms[1]; + } else { + mat4 ms = GetColorGreenMeanSD4(uInputTexture0, pos); + meanBGratio = ms[0]; meanRGratio = ms[1]; + } + vec2 grRed = vec2(2.0/(meanRGratio.x+meanRGratio.y), 2.0/(meanRGratio.z+meanRGratio.w)); + vec2 grBlue = vec2(2.0/(meanBGratio.x+meanBGratio.y), 2.0/(meanBGratio.z+meanBGratio.w)); + vec4 sFactHi = vec4(uParams.sDFactHiRedBlue, uParams.sDFactHiGreen, uParams.sDFactHiRedBlue, uParams.sDFactHiGreen); + vec4 diffHi = max(sFactHi * sdRG, uParams.trivialDiffThr); + vec4 thrMeanRGHi = rawMeanRG + diffHi; + float2x4 ep = ExtraPolTest(uInputTexture0, pos, isRedRow, grRed, grBlue, false); + vec4 thrHi = max(isRedRow ? thrMeanRGHi : thrMeanRGHi.yxwz, ep.m1); + vec4 diffLo = max(uParams.sDFactLo * sdRG, uParams.trivialDiffThr); + vec4 thrMeanRGLo = rawMeanRG - diffLo; + vec4 thrLo = min(isRedRow ? thrMeanRGLo : thrMeanRGLo.yxwz, min(ep.m0, float(uParams.trivialPepperMinThr))); + return MedianThrTest(uInputTexture0, pos, isRedRow, thrLo, thrHi, maskVal); +} + +void main() { + ivec2 margin = ivec2(int(uParams.marginX) / 4, int(uParams.marginY)); + ivec2 srcCoord = ivec2(gl_FragCoord.xy) + margin; + bool leftmostisGreen = ((int(gl_FragCoord.y)) & 1) == 1; + uvec4 outMask, outColor; + outColor = doHotPix(srcCoord, !leftmostisGreen, outMask); + FragColor = vec4(outColor) / MAX_VAL; + FragMask = vec4(outMask) / 255.0; +} diff --git a/research/phocus_glsl/01_raw_sensor/multi2bayer_ms2bayer3_0x303310c.frag b/research/phocus_glsl/01_raw_sensor/multi2bayer_ms2bayer3_0x303310c.frag new file mode 100644 index 00000000..7d6c9816 --- /dev/null +++ b/research/phocus_glsl/01_raw_sensor/multi2bayer_ms2bayer3_0x303310c.frag @@ -0,0 +1,46 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 772e7494a86ba3a7164e9b369e45dd64a1104e56361efa9f6396d5ea49c6a7a9 + * ELF offsets: 0x303310c + * Symbols: multi2bayer_ms2bayer3_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform vec2 uTextureSize; +uniform ivec2 uMargin; +uniform ivec2 uOffset; + +out vec4 FragColor; + +void main(){ + ivec2 gid = ivec2(gl_FragCoord.xy); + + ivec2 pos = ivec2(gid.x * 4, gid.y) + uMargin; + ivec2 bayerPos = gid + uOffset; + + if(pos.x >= int(uTextureSize.x) || pos.y < 0 || pos.y >= int(uTextureSize.y)){ + FragColor = vec4(0.0); + return; + } + int limitX = int(uTextureSize.x) - 1; + + int x0 = clamp(pos.x + 0, 0, limitX); + int x1 = clamp(pos.x + 1, 0, limitX); + int x2 = clamp(pos.x + 2, 0, limitX); + int x3 = clamp(pos.x + 3, 0, limitX); + + vec4 v0 = texelFetch(uInputTexture0, ivec2(x0, pos.y), 0); + vec4 v1 = texelFetch(uInputTexture0, ivec2(x1, pos.y), 0); + vec4 v2 = texelFetch(uInputTexture0, ivec2(x2, pos.y), 0); + vec4 v3 = texelFetch(uInputTexture0, ivec2(x3, pos.y), 0); + + if ((bayerPos.y & 1) == 0) { + FragColor = vec4(v0.r, v1.g, v2.r, v3.g); + } else { + FragColor = vec4(v0.g, v1.b, v2.g, v3.b); + } +} diff --git a/research/phocus_glsl/01_raw_sensor/neutralisationBayer_0x30563ff.comp b/research/phocus_glsl/01_raw_sensor/neutralisationBayer_0x30563ff.comp new file mode 100644 index 00000000..78125dde --- /dev/null +++ b/research/phocus_glsl/01_raw_sensor/neutralisationBayer_0x30563ff.comp @@ -0,0 +1,106 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 54c8e19ec4e856f0546700e84db38fd1983f139aaf7c43e3323fb08650dcd9d4 + * ELF offsets: 0x30563ff + * Symbols: neutralisationBayer_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; + +// Input: 16-bit half float texture (PackedBayer, stored as RGBA16F) +layout(rgba16f, binding = 0) readonly uniform image2D uInputImage; +// Output: 16-bit half float texture +layout(rgba16f, binding = 1) writeonly uniform image2D uOutputImage; + +// Uniform buffer object for parameters +struct NeutralisationBayerParams { + vec4 gain; // RGGB gains (R, G1, G2, B) + ivec2 margin; // Texture coordinate margin (pre-divided by 4 for x) + ivec2 rectOffset; // rect.left, rect.top for gain index calculation + float blackLevel; // Black level offset (normalized to [0,1]) + int debugMode; // Debug mode: 0=normal, 1=pass-through, 2=gain viz, 3+=boundary + int pad0; // Padding for std140 alignment + int pad1; +}; + +layout(std140, binding = 2) uniform NeutralisationBayerParams_UBO { + NeutralisationBayerParams params; +} uParams; + +layout(local_size_x = 16, local_size_y = 16) in; + +// Apply gain to pixel value (matching iOS Metal logic) +// Input: half float normalized [0,1] +// Processing: directly in [0,1] space to avoid precision loss +// Output: half float normalized [0,1] +// +// iOS Metal logic (in uint16 space [0,65535]): +// result = blackLevel + (input - blackLevel) * gain +// Normalized to [0,1]: +// result_norm = blackLevel_norm + (input_norm - blackLevel_norm) * gain +vec4 ApplyGain(vec4 val, vec4 gain, float blackLevel) { + // Apply gain directly in normalized [0,1] space + // v = blackLevel + (val - blackLevel) * gain + vec4 result = blackLevel + (val - blackLevel) * gain; + // Clamp to valid range [0,1] + return clamp(result, 0.0, 1.0); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + int debugMode = uParams.params.debugMode; + + // Boundary check for output + ivec2 outputSize = imageSize(uOutputImage); + if (gid.x >= outputSize.x || gid.y >= outputSize.y || gid.x < 0 || gid.y < 0) { + return; // Skip out-of-bounds pixels + } + + // Calculate source position with margin + ivec2 srcPos = gid + uParams.params.margin; + + // Boundary check for input texture + ivec2 inputSize = imageSize(uInputImage); + if (srcPos.x < 0 || srcPos.y < 0 || srcPos.x >= inputSize.x || srcPos.y >= inputSize.y) { + if (debugMode > 2) { + imageStore(uOutputImage, gid, vec4(1.0, 0.0, 1.0, 1.0)); // Magenta for boundary error + return; + } + srcPos = clamp(srcPos, ivec2(0), inputSize - ivec2(1)); + } + + vec4 val = imageLoad(uInputImage, srcPos); + + // Debug mode 1: Pass-through input + if (debugMode == 1) { + imageStore(uOutputImage, gid, val); + return; + } + + // Calculate gain index based on Bayer pattern (matching iOS Metal lines 46-50) + // iOS: int yOffset = opts.rectOffset.y & 1; + // int xOffset = opts.rectOffset.x & 1; + // gainRed = xOffset == 0 ? gain.xyxy : gain.yxyx; + // gainGreen = xOffset == 0 ? gain.zwzw : gain.wzwz; + // gain = (yOffset+gid.y) % 2 == 0 ? gainRed : gainGreen; + int yOffset = uParams.params.rectOffset.y & 1; + int xOffset = uParams.params.rectOffset.x & 1; + vec4 gainRed = (xOffset == 0) ? uParams.params.gain.xyxy : uParams.params.gain.yxyx; + vec4 gainGreen = (xOffset == 0) ? uParams.params.gain.zwzw : uParams.params.gain.wzwz; + vec4 gain = ((yOffset + gid.y) % 2 == 0) ? gainRed : gainGreen; + + // Debug mode 2: Visualize gain values + if (debugMode == 2) { + // Normalize gain to [0,1] for visualization (assuming gain is around 0.5-1.5) + vec4 gainViz = (gain - 0.5) / 1.0; // Map [0.5, 1.5] → [0, 1] + imageStore(uOutputImage, gid, clamp(gainViz, 0.0, 1.0)); + return; + } + + // Apply gain and black level correction + vec4 result = ApplyGain(val, gain, uParams.params.blackLevel); + + imageStore(uOutputImage, gid, result); +} diff --git a/research/phocus_glsl/01_raw_sensor/neutralisationRgb_0x2ff8dfa.comp b/research/phocus_glsl/01_raw_sensor/neutralisationRgb_0x2ff8dfa.comp new file mode 100644 index 00000000..6e32b3d4 --- /dev/null +++ b/research/phocus_glsl/01_raw_sensor/neutralisationRgb_0x2ff8dfa.comp @@ -0,0 +1,77 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: f139a1b07826c300489b4392699d94238e6f34a998d4dba8d9ca80bf605e6539 + * ELF offsets: 0x2ff8dfa + * Symbols: neutralisationRgb_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; + +// Input: 16-bit half float texture (RGB, stored as RGBA16F) +layout(rgba16f, binding = 0) readonly uniform image2D uInputImage; +// Output: 16-bit half float texture +layout(rgba16f, binding = 1) writeonly uniform image2D uOutputImage; + +// Uniform buffer object for parameters +struct NeutralisationRgbParams { + vec4 gain; // RGB gains (R, G, B, 1.0) + ivec2 margin; // Texture coordinate margin + int debugMode; // Debug mode + int pad; // Padding for std140 alignment +}; + +layout(std140, binding = 2) uniform NeutralisationRgbParams_UBO { + NeutralisationRgbParams params; +} uParams; + +layout(local_size_x = 16, local_size_y = 16) in; + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + int debugMode = uParams.params.debugMode; + + // Boundary check for output + ivec2 outputSize = imageSize(uOutputImage); + if (gid.x >= outputSize.x || gid.y >= outputSize.y || gid.x < 0 || gid.y < 0) { + return; // Skip out-of-bounds pixels + } + + // Calculate source position with margin + ivec2 srcPos = gid + uParams.params.margin; + + // Boundary check for input texture + ivec2 inputSize = imageSize(uInputImage); + if (srcPos.x < 0 || srcPos.y < 0 || srcPos.x >= inputSize.x || srcPos.y >= inputSize.y) { + if (debugMode > 2) { + imageStore(uOutputImage, gid, vec4(1.0, 0.0, 1.0, 1.0)); // Magenta for boundary error + return; + } + srcPos = clamp(srcPos, ivec2(0), inputSize - ivec2(1)); + } + + vec4 val = imageLoad(uInputImage, srcPos); + + // Debug mode 1: Pass-through input + if (debugMode == 1) { + imageStore(uOutputImage, gid, val); + return; + } + + // Debug mode 2: Visualize gain values + if (debugMode == 2) { + vec4 gainViz = (uParams.params.gain - 0.5) / 1.0; // Map [0.5, 1.5] → [0, 1] + imageStore(uOutputImage, gid, clamp(gainViz, 0.0, 1.0)); + return; + } + + // Apply gain (iOS Metal: gain * input, then clamp) + // Note: iOS uses ushort [0,65535], Android uses half float [0,1] + // So we multiply/clamp in [0,1] space directly + vec4 gain = vec4(uParams.params.gain.rgb, 1.0); // Preserve alpha + vec4 result = val * gain; + result = clamp(result, 0.0, 1.0); + + imageStore(uOutputImage, gid, result); +} diff --git a/research/phocus_glsl/01_raw_sensor/orientation_180_0x3073882.frag b/research/phocus_glsl/01_raw_sensor/orientation_180_0x3073882.frag new file mode 100644 index 00000000..7a222367 --- /dev/null +++ b/research/phocus_glsl/01_raw_sensor/orientation_180_0x3073882.frag @@ -0,0 +1,50 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 84412000fe0b6f27def36bdbb611fafd17343363c7d23dbecb0505ce87fad666 + * ELF offsets: 0x3073882 + * Symbols: orientation_180_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform ivec2 uMargin; +uniform int uWidth; // Source Bayer Width limit +uniform int uHeight; // Source Bayer Height limit + +float getComponent(vec4 v, int index) { + if (index == 0) return v.r; + if (index == 1) return v.g; + if (index == 2) return v.b; + return v.a; +} + +void main() { + ivec2 gid = ivec2(gl_FragCoord.xy); + int out_bx_start = gid.x * 4; + int out_by = gid.y; + + vec4 outColor; + + int src_by = uHeight - out_by; + int src_tex_y = src_by; + + for (int i = 0; i < 4; ++i) { + int curr_out_bx = out_bx_start + i; + int src_bx = uWidth - curr_out_bx; + + int src_tex_x = src_bx >> 2; + int src_comp = src_bx & 3; + + vec4 srcPixel = texelFetch(uInputTexture0, ivec2(src_tex_x, src_tex_y), 0); + + if (i == 0) outColor.r = getComponent(srcPixel, src_comp); + else if (i == 1) outColor.g = getComponent(srcPixel, src_comp); + else if (i == 2) outColor.b = getComponent(srcPixel, src_comp); + else outColor.a = getComponent(srcPixel, src_comp); + } + FragColor = outColor; +} diff --git a/research/phocus_glsl/01_raw_sensor/orientation_270_0x2ff9752.frag b/research/phocus_glsl/01_raw_sensor/orientation_270_0x2ff9752.frag new file mode 100644 index 00000000..37ad010e --- /dev/null +++ b/research/phocus_glsl/01_raw_sensor/orientation_270_0x2ff9752.frag @@ -0,0 +1,50 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 2fe79b91d74441a5a0d8daeb34f87e445ac128112c56008290fceab12d1311ab + * ELF offsets: 0x2ff9752 + * Symbols: orientation_270_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform ivec2 uMargin; +uniform int uWidth; // Source Bayer Width limit +uniform int uHeight; // Source Bayer Height limit + +float getComponent(vec4 v, int index) { + if (index == 0) return v.r; + if (index == 1) return v.g; + if (index == 2) return v.b; + return v.a; +} + +void main() { + ivec2 gid = ivec2(gl_FragCoord.xy); + int out_bx_start = gid.x * 4; + int out_by = gid.y; + + vec4 outColor; + + for (int i = 0; i < 4; ++i) { + int curr_out_bx = out_bx_start + i; + + int src_bx = uWidth - out_by; + int src_by = curr_out_bx + uMargin.y; + + int src_tex_x = src_bx >> 2; + int src_comp = src_bx & 3; + int src_tex_y = src_by; + + vec4 srcPixel = texelFetch(uInputTexture0, ivec2(src_tex_x, src_tex_y), 0); + + if (i == 0) outColor.r = getComponent(srcPixel, src_comp); + else if (i == 1) outColor.g = getComponent(srcPixel, src_comp); + else if (i == 2) outColor.b = getComponent(srcPixel, src_comp); + else outColor.a = getComponent(srcPixel, src_comp); + } + FragColor = outColor; +} diff --git a/research/phocus_glsl/01_raw_sensor/orientation_90_0x301d6cf.frag b/research/phocus_glsl/01_raw_sensor/orientation_90_0x301d6cf.frag new file mode 100644 index 00000000..1b86419a --- /dev/null +++ b/research/phocus_glsl/01_raw_sensor/orientation_90_0x301d6cf.frag @@ -0,0 +1,51 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 4802e80060871fd646ac34d63fa30b3779d034e42b559dc1054f76757737e36f + * ELF offsets: 0x301d6cf + * Symbols: orientation_90_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform ivec2 uMargin; +uniform int uWidth; +uniform int uHeight; // Source Bayer Height limit + +float getComponent(vec4 v, int index) { + if (index == 0) return v.r; + if (index == 1) return v.g; + if (index == 2) return v.b; + return v.a; +} + +void main() { + ivec2 gid = ivec2(gl_FragCoord.xy); + + int out_bx_start = gid.x * 4; + int out_by = gid.y; + + vec4 outColor; + + for (int i = 0; i < 4; ++i) { + int curr_out_bx = out_bx_start + i; + + int src_bx = out_by + uMargin.x; + int src_by = uHeight - curr_out_bx; + + int src_tex_x = src_bx >> 2; // divide by 4 + int src_comp = src_bx & 3; // modulo 4 + int src_tex_y = src_by; + + vec4 srcPixel = texelFetch(uInputTexture0, ivec2(src_tex_x, src_tex_y), 0); + + if (i == 0) outColor.r = getComponent(srcPixel, src_comp); + else if (i == 1) outColor.g = getComponent(srcPixel, src_comp); + else if (i == 2) outColor.b = getComponent(srcPixel, src_comp); + else outColor.a = getComponent(srcPixel, src_comp); + } + FragColor = outColor; +} diff --git a/research/phocus_glsl/01_raw_sensor/sceneCalibrationBayer_0x3060303.comp b/research/phocus_glsl/01_raw_sensor/sceneCalibrationBayer_0x3060303.comp new file mode 100644 index 00000000..22f3607c --- /dev/null +++ b/research/phocus_glsl/01_raw_sensor/sceneCalibrationBayer_0x3060303.comp @@ -0,0 +1,139 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: ad02e35cd008c247df53d43a9649af52f9063e142b0515ad179780c11c18585c + * ELF offsets: 0x3060303 + * Symbols: sceneCalibrationBayer_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; + +// Input: 16-bit half float texture (Bayer, stored as RGBA16F) +layout(rgba16f, binding = 0) readonly uniform image2D uInputImage; +// Gain map: float RGBA texture +layout(rgba32f, binding = 1) readonly uniform image2D uGainMap; +// Output: 16-bit half float texture +layout(rgba16f, binding = 2) writeonly uniform image2D uOutputImage; + +// Uniform buffer object for parameters +struct SceneCorrParams { + vec2 scale; + vec2 offset; + ivec2 margin; + ivec2 mapSize; + int blackOffset; + int orientation; + int debugMode; + int pad; +}; + +layout(std140, binding = 3) uniform SceneCalibrationParams { + SceneCorrParams params; +} uParams; + +layout(local_size_x = 16, local_size_y = 16) in; + +// Apply gain to pixel value +// Input values are in [0, 1] range (half float normalized) +vec4 ApplyGain(vec4 val, vec4 gain, int blackOffset) { + // Convert from normalized [0,1] to [0,65535] range + vec4 valScaled = val * 65535.0; + vec4 gained = clamp(vec4(blackOffset) + (valScaled - vec4(blackOffset)) * gain, 0.0, 65535.0); + // Preserve saturated pixels (65535, which is ~1.0 in normalized) + vec4 result = mix(gained, valScaled, step(0.9999, val)); + // Convert back to normalized [0,1] range + return result / 65535.0; +} + +// Bilinear interpolation for gain map sampling +vec4 scaleLinear(vec2 pos, ivec2 maxPos) { + ivec2 basePos = ivec2(pos); + vec2 delta = pos - vec2(basePos); + + ivec2 p00 = clamp(basePos + ivec2(0, 0), ivec2(0), maxPos); + ivec2 p10 = clamp(basePos + ivec2(1, 0), ivec2(0), maxPos); + ivec2 p01 = clamp(basePos + ivec2(0, 1), ivec2(0), maxPos); + ivec2 p11 = clamp(basePos + ivec2(1, 1), ivec2(0), maxPos); + + vec4 v00 = imageLoad(uGainMap, p00); + vec4 v10 = imageLoad(uGainMap, p10); + vec4 v01 = imageLoad(uGainMap, p01); + vec4 v11 = imageLoad(uGainMap, p11); + + vec4 h0 = mix(v00, v10, delta.x); + vec4 h1 = mix(v01, v11, delta.x); + return mix(h0, h1, delta.y); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + int debugMode = uParams.params.debugMode; + + // Calculate map position for this tile (4x2 pixels per tile) + vec2 mapPos = (vec2(gid.x * 4.0, gid.y * 2.0) + uParams.params.offset) * uParams.params.scale; + vec4 gain = scaleLinear(mapPos, uParams.params.mapSize - ivec2(1)); + + // Split gain for RGGB pattern: gain0 = (R, G), gain1 = (G, B) + vec4 gain0 = vec4(gain.xy, gain.xy); + vec4 gain1 = vec4(gain.zw, gain.zw); + + // Process two rows of pixels + ivec2 gid0 = ivec2(gid.x, gid.y * 2 + 0); + ivec2 gid1 = ivec2(gid.x, gid.y * 2 + 1); + + // Boundary check for output + ivec2 outputSize = imageSize(uOutputImage); + if (gid0.x >= outputSize.x || gid0.y >= outputSize.y || + gid1.x >= outputSize.x || gid1.y >= outputSize.y || + gid0.x < 0 || gid0.y < 0 || gid1.x < 0 || gid1.y < 0) { + return; // Skip out-of-bounds pixels + } + + ivec2 srcPos0 = gid0 + uParams.params.margin; + ivec2 srcPos1 = gid1 + uParams.params.margin; + bool boundaryError = false; // only take place when debugMode > 3 + + // Boundary check for input texture + ivec2 inputSize = imageSize(uInputImage); + if (srcPos0.x < 0 || srcPos0.y < 0 || srcPos0.x >= inputSize.x || srcPos0.y >= inputSize.y) { + if (debugMode > 3) { + imageStore(uOutputImage, gid0, vec4(0.5, 0.0, 1.0, 1.0)); // purple error + boundaryError = true; + } else { + srcPos0 = clamp(srcPos0, ivec2(0), inputSize - ivec2(1)); + } + } + if (srcPos1.x < 0 || srcPos1.y < 0 || srcPos1.x >= inputSize.x || srcPos1.y >= inputSize.y) { + if (debugMode > 3) { + imageStore(uOutputImage, gid1, vec4(1.0, 0.0, 1.0, 1.0); // cyan error + boundaryError = true; + } else { + srcPos1 = clamp(srcPos1, ivec2(0), inputSize - ivec2(1)); + } + } + + if (boundaryError) { + return; + } + + vec4 val0 = imageLoad(uInputImage, srcPos0); + vec4 val1 = imageLoad(uInputImage, srcPos1); + + vec4 result0 = ApplyGain(val0, gain0, uParams.params.blackOffset); + vec4 result1 = ApplyGain(val1, gain1, uParams.params.blackOffset); + + // Debug mode support + if (debugMode == 1) { + // Output original values + result0 = val0; + result1 = val1; + } else if (debugMode == 2) { + // Output gain values (normalized to [0,1]) + result0 = gain0; + result1 = gain1; + } + + imageStore(uOutputImage, gid0, result0); + imageStore(uOutputImage, gid1, result1); +} diff --git a/research/phocus_glsl/01_raw_sensor/sceneCalibrationGray_0x30b1366.comp b/research/phocus_glsl/01_raw_sensor/sceneCalibrationGray_0x30b1366.comp new file mode 100644 index 00000000..98aacddf --- /dev/null +++ b/research/phocus_glsl/01_raw_sensor/sceneCalibrationGray_0x30b1366.comp @@ -0,0 +1,122 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: b37680e4d072169a7a53fcdc209523e90d1154e05d5d45d437005db9c3ad2a47 + * ELF offsets: 0x30b1366 + * Symbols: sceneCalibrationGray_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; + +// Input: 16-bit half float texture (Gray, packed as RGBA16F) +layout(rgba16f, binding = 0) readonly uniform image2D uInputImage; +// Gain map: float RGBA texture +layout(rgba32f, binding = 1) readonly uniform image2D uGainMap; +// Output: 16-bit half float texture +layout(rgba16f, binding = 2) writeonly uniform image2D uOutputImage; + +// Uniform buffer object for parameters +struct SceneCorrParams { + vec2 scale; + vec2 offset; + ivec2 margin; + ivec2 mapSize; + int blackOffset; + int orientation; + int debugMode; + int pad; +}; + +layout(std140, binding = 3) uniform SceneCalibrationParams { + SceneCorrParams params; +} uParams; + +layout(local_size_x = 16, local_size_y = 16) in; + +// Apply gain to pixel value +// Input values are in [0, 1] range (half float normalized) +vec4 ApplyGain(vec4 val, vec4 gain, int blackOffset) { + // Convert from normalized [0,1] to [0,65535] range + vec4 valScaled = val * 65535.0; + vec4 gained = clamp(vec4(blackOffset) + (valScaled - vec4(blackOffset)) * gain, 0.0, 65535.0); + // Preserve saturated pixels (65535, which is ~1.0 in normalized) + vec4 result = mix(gained, valScaled, step(0.9999, val)); + // Convert back to normalized [0,1] range + return result / 65535.0; +} + +// Bilinear interpolation for gain map sampling +vec4 scaleLinear(vec2 pos, ivec2 maxPos) { + ivec2 basePos = ivec2(pos); + vec2 delta = pos - vec2(basePos); + + ivec2 p00 = clamp(basePos + ivec2(0, 0), ivec2(0), maxPos); + ivec2 p10 = clamp(basePos + ivec2(1, 0), ivec2(0), maxPos); + ivec2 p01 = clamp(basePos + ivec2(0, 1), ivec2(0), maxPos); + ivec2 p11 = clamp(basePos + ivec2(1, 1), ivec2(0), maxPos); + + vec4 v00 = imageLoad(uGainMap, p00); + vec4 v10 = imageLoad(uGainMap, p10); + vec4 v01 = imageLoad(uGainMap, p01); + vec4 v11 = imageLoad(uGainMap, p11); + + vec4 h0 = mix(v00, v10, delta.x); + vec4 h1 = mix(v01, v11, delta.x); + return mix(h0, h1, delta.y); +} + +// Calculate gray gain for packed pixel at specific offset +float ScaledPackedLinear(ivec2 srcgid, int packedOffset) { + vec2 fGid = vec2(float(srcgid.x) * 4.0 + float(packedOffset), float(srcgid.y)); + vec2 mapPos = (fGid + uParams.params.offset) * uParams.params.scale; + vec4 gainRgb = scaleLinear(mapPos, uParams.params.mapSize - ivec2(1)); + + // Convert RGB gain to gray using weights + vec4 grayWeights = vec4(0.333333333, 0.333333334, 0.333333333, 0.0); + return dot(gainRgb, grayWeights); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + int debugMode = uParams.params.debugMode; + + // Boundary check - must check BEFORE using gid + ivec2 outputSize = imageSize(uOutputImage); + if (gid.x >= outputSize.x || gid.y >= outputSize.y || gid.x < 0 || gid.y < 0) { + return; // Skip out-of-bounds pixels + } + + ivec2 srcPos = gid + uParams.params.margin; + + // Boundary check for srcPos to prevent reading from invalid texture regions + ivec2 inputSize = imageSize(uInputImage); + if (srcPos.x < 0 || srcPos.y < 0 || srcPos.x >= inputSize.x || srcPos.y >= inputSize.y) { + if (debugMode > 3) { + imageStore(uOutputImage, gid, vec4(1.0, 0.0, 1.0, 1.0)); // cyan error + return; + } + // clamp to valid positions + srcPos = clamp(srcPos, ivec2(0), inputSize - ivec2(1)); + } + + // Calculate gray gain for each of the 4 packed pixels + vec4 gainGray = vec4( + ScaledPackedLinear(srcPos, 0), + ScaledPackedLinear(srcPos, 1), + ScaledPackedLinear(srcPos, 2), + ScaledPackedLinear(srcPos, 3) + ); + + vec4 val = imageLoad(uInputImage, srcPos); + vec4 result = ApplyGain(val, gainGray, uParams.params.blackOffset); + + // Debug mode support + if (debugMode == 1) { + result = val; // Output original + } else if (debugMode == 2) { + result = gainGray; // Output gain (normalized) + } + + imageStore(uOutputImage, gid, result); +} diff --git a/research/phocus_glsl/01_raw_sensor/sceneCalibrationRgb_0x3008d0f.comp b/research/phocus_glsl/01_raw_sensor/sceneCalibrationRgb_0x3008d0f.comp new file mode 100644 index 00000000..bb2e9660 --- /dev/null +++ b/research/phocus_glsl/01_raw_sensor/sceneCalibrationRgb_0x3008d0f.comp @@ -0,0 +1,149 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 4e7ff25df3d5cf99208ee46fa417954a190ec2909af7bfb1eac95f363023f221 + * ELF offsets: 0x3008d0f + * Symbols: sceneCalibrationRgb_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; + +// Input: 16-bit half float texture (RGB, stored as RGBA16F) +layout(rgba16f, binding = 0) readonly uniform image2D uInputImage; +// Gain map: float RGBA texture +layout(rgba32f, binding = 1) readonly uniform image2D uGainMap; +// Output: 16-bit half float texture +layout(rgba16f, binding = 2) writeonly uniform image2D uOutputImage; + +// Uniform buffer object for parameters +struct SceneCorrParams { + vec2 scale; + vec2 offset; + ivec2 margin; + ivec2 mapSize; + int blackOffset; + int orientation; + int debugMode; + int pad; +}; + +layout(std140, binding = 3) uniform SceneCalibrationParams { + SceneCorrParams params; +} uParams; + +layout(local_size_x = 16, local_size_y = 16) in; + +// Apply gain to pixel value +// Input values are in [0, 1] range (half float normalized) +vec4 ApplyGain(vec4 val, vec4 gain, int blackOffset) { + // Convert from normalized [0,1] to [0,65535] range + vec4 valScaled = val * 65535.0; + vec4 gained = clamp(vec4(blackOffset) + (valScaled - vec4(blackOffset)) * gain, 0.0, 65535.0); + // Preserve saturated pixels (65535, which is ~1.0 in normalized) + vec4 result = mix(gained, valScaled, step(0.9999, val)); + // Convert back to normalized [0,1] range + return result / 65535.0; +} + +// Bilinear interpolation for gain map sampling +vec4 scaleLinear(vec2 pos, ivec2 maxPos) { + ivec2 basePos = ivec2(pos); + vec2 delta = pos - vec2(basePos); + + ivec2 p00 = clamp(basePos + ivec2(0, 0), ivec2(0), maxPos); + ivec2 p10 = clamp(basePos + ivec2(1, 0), ivec2(0), maxPos); + ivec2 p01 = clamp(basePos + ivec2(0, 1), ivec2(0), maxPos); + ivec2 p11 = clamp(basePos + ivec2(1, 1), ivec2(0), maxPos); + + vec4 v00 = imageLoad(uGainMap, p00); + vec4 v10 = imageLoad(uGainMap, p10); + vec4 v01 = imageLoad(uGainMap, p01); + vec4 v11 = imageLoad(uGainMap, p11); + + vec4 h0 = mix(v00, v10, delta.x); + vec4 h1 = mix(v01, v11, delta.x); + return mix(h0, h1, delta.y); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + int debugMode = uParams.params.debugMode; + + // Boundary check - must check BEFORE using gid + ivec2 outputSize = imageSize(uOutputImage); + if (gid.x >= outputSize.x || gid.y >= outputSize.y || gid.x < 0 || gid.y < 0) { + return; // Skip out-of-bounds pixels + } + + ivec2 srcPos = gid + uParams.params.margin; + vec4 val = imageLoad(uInputImage, srcPos); + vec4 result = val; + + // Boundary check for srcPos to prevent reading from invalid texture regions + // This is critical when previous filter (RgbNr) uses tile rendering + ivec2 inputSize = imageSize(uInputImage); + if (srcPos.x < 0 || srcPos.y < 0 || srcPos.x >= inputSize.x || srcPos.y >= inputSize.y) { + if (debugMode > 3) { + imageStore(uOutputImage, gid, vec4(1.0, 0.0, 1.0, 1.0)); // Output magenta for error pixels + return; + } + // clamp to valid positions + srcPos = clamp(srcPos, ivec2(0), inputSize - ivec2(1)); + } + + // Debug option 1: Output original texture + if (debugMode == 1) { + imageStore(uOutputImage, gid, result); + return; + } + + // Debug option 2: Check calculated gain values (with proper scaling) + if (debugMode == 2) { + vec2 mapPos = (vec2(srcPos) + uParams.params.offset) * uParams.params.scale; + vec4 gain = scaleLinear(mapPos, uParams.params.mapSize - ivec2(1)); + + // Check for invalid gain values + if (any(isnan(gain)) || any(isinf(gain))) { + imageStore(uOutputImage, gid, vec4(1.0, 0.0, 1.0, 1.0)); // Magenta for NaN/Inf + return; + } + + // Visualize gain values in different ranges + float avgGain = (gain.r + gain.g + gain.b) / 3.0; + if (avgGain < 0.5) { + imageStore(uOutputImage, gid, vec4(1.0, 0.0, 0.0, 1.0)); // Red for very low gain + } else if (avgGain > 1.5) { + imageStore(uOutputImage, gid, vec4(0.0, 0.0, 1.0, 1.0)); // Blue for very high gain + } else { + // Green channel shows normalized gain in [0.5, 1.5] range + float normalizedGain = avgGain - 0.5; + imageStore(uOutputImage, gid, vec4(0.0, normalizedGain, 0.0, 1.0)); + } + return; + } + + // Debug option 3: Visualize gain map sampling coordinates + if (debugMode == 3) { + vec2 mapPos = (vec2(srcPos) + uParams.params.offset) * uParams.params.scale; + ivec2 mapSize = uParams.params.mapSize; + + // Visualize normalized map coordinates + vec4 mapCoordColor = vec4(mapPos.x / float(mapSize.x), mapPos.y / float(mapSize.y), 0.0, 1.0); + + // Check if map coordinates are out of bounds + if (mapPos.x < 0.0 || mapPos.y < 0.0 || mapPos.x >= float(mapSize.x) || mapPos.y >= float(mapSize.y)) { + imageStore(uOutputImage, gid, vec4(0.0, 1.0, 1.0, 1.0)); // Cyan for out of bounds + } else { + imageStore(uOutputImage, gid, mapCoordColor); + } + return; + } + + // Calculate map position + vec2 mapPos = (vec2(srcPos) + uParams.params.offset) * uParams.params.scale; + vec4 gainRgb = scaleLinear(mapPos, uParams.params.mapSize - ivec2(1)); + + result = ApplyGain(val, gainRgb, uParams.params.blackOffset); + imageStore(uOutputImage, gid, result); +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_calculate_color_noise_error_0x30062f5.comp b/research/phocus_glsl/02_demosaic/demosaic_calculate_color_noise_error_0x30062f5.comp new file mode 100644 index 00000000..a266ccac --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_calculate_color_noise_error_0x30062f5.comp @@ -0,0 +1,77 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 6da3783cd147005c2750b1fe352a0110d3ca2c22e32c35691f4087f45ac1b17b + * ELF offsets: 0x30062f5 + * Symbols: demosaic_calculate_color_noise_error_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D yccdTex; +layout(rgba16ui, binding = 1) readonly uniform uimage2D ycceSmoothTex; +layout(rgba16ui, binding = 2) writeonly uniform uimage2D dstTex; + +int chromaSigned(uint c) { + int ic = int(c); + return (ic > 32767) ? (ic - 65536) : ic; +} + +uint chromaUnsigned(int v) { + return uint(v & 0xFFFF); +} + +int DirMask2Count(int a) { + return (a >> 8) & 0x0F; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + + uvec4 pix1 = imageLoad(yccdTex, gid); + uvec4 pix2 = imageLoad(ycceSmoothTex, gid); + + int dir = int(pix1.a); + uint ySmooth = pix2.r; + int crSmooth = chromaSigned(pix2.g); + int cbSmooth = chromaSigned(pix2.b); + uint error = pix2.a; + + ivec2 dirStep[8] = ivec2[8]( + ivec2( 0, -1), + ivec2(+1, 0), + ivec2( 0, +1), + ivec2(-1, 0), + ivec2(+1, -1), + ivec2(+1, +1), + ivec2(-1, +1), + ivec2(-1, -1) + ); + + int ySum = 0, rSum = 0, bSum = 0; + for (int i = 0; i < 8; i++) { + int mask = (1 << i); + if ((dir & mask) != 0) { + uvec4 pix = imageLoad(yccdTex, gid + dirStep[i]); + ySum += int(pix1.r) - int(pix.r); + rSum += chromaSigned(pix1.g) - chromaSigned(pix.g); + bSum += chromaSigned(pix1.b) - chromaSigned(pix.b); + } + } + int count = DirMask2Count(dir); + int dirBits = dir & 0xFF; + bool diagPenalty = (dirBits == 0x50 || dirBits == 0xA0); + int newError = diagPenalty ? abs(rSum + bSum) : 0; + if (count > 0) { + newError += abs(ySum); + newError /= count; + } + + float minLevel = 0.05 * float(ySmooth); + float scaledError = float(error) * max(0.0, min(float(newError) - minLevel, 1.0)); + + imageStore(dstTex, gid, uvec4(ySmooth, chromaUnsigned(crSmooth), chromaUnsigned(cbSmooth), uint(scaledError))); +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_color_noise_filter_0x3014da8.comp b/research/phocus_glsl/02_demosaic/demosaic_color_noise_filter_0x3014da8.comp new file mode 100644 index 00000000..4c2545dd --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_color_noise_filter_0x3014da8.comp @@ -0,0 +1,56 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: d2230d98ddb2e920f96ff833d6b2b064edfe1fd367f3f1b7a1e0dae591238f06 + * ELF offsets: 0x3014da8 + * Symbols: demosaic_color_noise_filter_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D yccdTex; +layout(rgba16ui, binding = 1) writeonly uniform uimage2D dstTex; +layout(rgba16ui, binding = 2) readonly uniform uimage2D ycceSmoothTex; + +int chromaSigned(uint c) { + int ic = int(c); + return (ic > 32767) ? (ic - 65536) : ic; +} + +uint chromaUnsigned(int v) { + return uint(v & 0xFFFF); +} + +float minMaxScale(float low, float value, float high) { + float clip = max(low, min(value, high)); + return (clip - low) / (high - low); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + + uvec4 pix1 = imageLoad(yccdTex, gid); + uvec4 pix2 = imageLoad(ycceSmoothTex, gid); + + uint y = pix1.r; + int cr = chromaSigned(pix1.g); + int cb = chromaSigned(pix1.b); + int crSmooth = chromaSigned(pix2.g); + int cbSmooth = chromaSigned(pix2.b); + uint error = pix2.a; + + float errorScale = minMaxScale(100.0, float(error) / 4.0, 300.0); + + float smoothSat = 1.0 + float(abs(crSmooth)) + float(abs(cbSmooth)); + float normalSat = float(abs(cr)) + float(abs(cb)); + float satScale = minMaxScale(0.5, normalSat / smoothSat, 1.0); + + float factor = errorScale * satScale; + float finalCr = mix(float(cr), float(crSmooth), factor); + float finalCb = mix(float(cb), float(cbSmooth), factor); + + imageStore(dstTex, gid, uvec4(y, chromaUnsigned(int(finalCr)), chromaUnsigned(int(finalCb)), error)); +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_1_0x3081fb1.comp b/research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_1_0x3081fb1.comp new file mode 100644 index 00000000..8e0db072 --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_1_0x3081fb1.comp @@ -0,0 +1,67 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 626b18a415bd88111972b31b26529cbc4c3f0fe86f066c6da8e5ba9b77c0052d + * ELF offsets: 0x3081fb1 + * Symbols: demosaic_color_noise_pass_1_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; + +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D inTex; +layout(rgba16ui, binding = 1) writeonly uniform uimage2D outTex; + +layout(std140, binding = 2) uniform DemosaicColorNoisePass1Params_UBO { + int uParams_l; + int uParams_t; + int uParams_r; + int uParams_b; +}; + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + + uvec4 outV = uvec4(0u); + if (gid.x >= uParams_l && gid.x +1 < uParams_r && + gid.y >= uParams_t && gid.y + 1 < uParams_b) { + uvec4 res = imageLoad(inTex, gid); + float yCtr = float(res.r); + + float tmp1 = float(imageLoad(inTex, gid + ivec2(-1, -1)).r); + float tmp = float(imageLoad(inTex, gid + ivec2(0, -1)).r); + float yMax = max(tmp, tmp1); + float yMin = min(tmp, tmp1); + + tmp = float(imageLoad(inTex, gid + ivec2(1, -1)).r); + yMax = max(tmp, yMax); + yMin = min(tmp, yMin); + + tmp = float(imageLoad(inTex, gid + ivec2(1, 0)).r); + yMax = max(tmp, yMax); + yMin = min(tmp, yMin); + + tmp = float(imageLoad(inTex, gid + ivec2(1, 1)).r); + yMax = max(tmp, yMax); + yMin = min(tmp, yMin); + + tmp = float(imageLoad(inTex, gid + ivec2(0, 1)).r); + yMax = max(tmp, yMax); + yMin = min(tmp, yMin); + + tmp = float(imageLoad(inTex, gid + ivec2(-1, 1)).r); + yMax = max(tmp, yMax); + yMin = min(tmp, yMin); + + tmp = float(imageLoad(inTex, gid + ivec2(-1, 0)).r); + yMax = max(tmp, yMax); + yMin = min(tmp, yMin); + + res.r = uint(clamp(yCtr, yMin, yMax)); + outV = res; + } + imageStore(outTex, gid, outV); +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_2_0x3024978.comp b/research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_2_0x3024978.comp new file mode 100644 index 00000000..9fb592eb --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_2_0x3024978.comp @@ -0,0 +1,123 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 77ecea4a4085c9678c82864b7a3a1633b9a173a2746a1c4fae420049edf24f6c + * ELF offsets: 0x3024978 + * Symbols: demosaic_color_noise_pass_2_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; + +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D inTex; +layout(rgba16ui, binding = 1) writeonly uniform uimage2D outTex; + +layout(std140, binding = 2) uniform DemosaicColorNoisePass2Params_UBO { + int uParams_l; + int uParams_t; + int uParams_r; + int uParams_b; +}; + +int chromaSigned(uint c) { + int ic = int(c); + return (ic > 32767) ? (ic - 65536) : ic; +} + +uint chromaUnsigned(int v) { + return uint(v & 0xFFFF); +} + +void fetchYCbCr(ivec2 pos, out int y, out int cr, out int cb) { + uvec4 t = imageLoad(inTex, pos); + y = int(t.r); + cr = chromaSigned(t.g); + cb = chromaSigned(t.b); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + + uvec4 outV = uvec4(0u); + if (gid.x >= uParams_l && gid.x < uParams_r && + gid.y >= uParams_t && gid.y < uParams_b) { + + uvec4 res0 = imageLoad(inTex, gid); + ivec2 pixelCoord = gid; + + int y; int cr; int cb; + uvec4 cornerNN = imageLoad(inTex, pixelCoord + ivec2(-1, -1)); + y = int(cornerNN.r); + cr = chromaSigned(cornerNN.g); + cb = chromaSigned(cornerNN.b); + ivec4 ycbcrTmp1_short = ivec4(y, cr, cb, int(cornerNN.a)); + + fetchYCbCr(pixelCoord + ivec2(0, -1), y, cr, cb); + ivec4 ycbcrTmp_short = ivec4(y, cr, cb, 0); + + ivec4 cbcrMax = max(ycbcrTmp_short, ycbcrTmp1_short); + ivec4 cbcrMin = min(ycbcrTmp_short, ycbcrTmp1_short); + ivec2 cbcrSum = ivec2(ycbcrTmp1_short.y + ycbcrTmp_short.y, ycbcrTmp1_short.z + ycbcrTmp_short.z); + int ySum = ycbcrTmp1_short.x + 2 * ycbcrTmp_short.x; + + fetchYCbCr(pixelCoord + ivec2(1, -1), y, cr, cb); + ycbcrTmp_short = ivec4(y, cr, cb, 0); + cbcrMax = max(ycbcrTmp_short, cbcrMax); + cbcrMin = min(ycbcrTmp_short, cbcrMin); + cbcrSum.x += ycbcrTmp_short.y - cbcrMax.y - cbcrMin.y; + cbcrSum.y += ycbcrTmp_short.z - cbcrMax.z - cbcrMin.z; + ivec2 cbcrMinG = cbcrSum; + ivec2 cbcrMaxG = cbcrSum; + ivec2 cbcrSumG = cbcrSum; + ySum += ycbcrTmp_short.x; + + fetchYCbCr(pixelCoord + ivec2(-1, 0), y, cr, cb); + ycbcrTmp1_short = ivec4(y, cr, cb, 0); + + fetchYCbCr(pixelCoord + ivec2(0, 0), y, cr, cb); + ycbcrTmp_short = ivec4(y, cr, cb, 0); + cbcrMax = max(ycbcrTmp_short, ycbcrTmp1_short); + cbcrMin = min(ycbcrTmp_short, ycbcrTmp1_short); + cbcrSum = ivec2(ycbcrTmp1_short.y + ycbcrTmp_short.y, ycbcrTmp1_short.z + ycbcrTmp_short.z); + ySum += 2 * ycbcrTmp1_short.x + 4 * ycbcrTmp_short.x; + + fetchYCbCr(pixelCoord + ivec2(1, 0), y, cr, cb); + ycbcrTmp_short = ivec4(y, cr, cb, 0); + cbcrMax = max(ycbcrTmp_short, cbcrMax); + cbcrMin = min(ycbcrTmp_short, cbcrMin); + cbcrSum.x += ycbcrTmp_short.y - cbcrMax.y - cbcrMin.y; + cbcrSum.y += ycbcrTmp_short.z - cbcrMax.z - cbcrMin.z; + cbcrSumG += cbcrSum; + cbcrMinG = min(cbcrMinG, cbcrSum); + cbcrMaxG = max(cbcrMaxG, cbcrSum); + ySum += 2 * ycbcrTmp_short.x; + + fetchYCbCr(pixelCoord + ivec2(-1, 1), y, cr, cb); + ycbcrTmp1_short = ivec4(y, cr, cb, 0); + + fetchYCbCr(pixelCoord + ivec2(0, 1), y, cr, cb); + ycbcrTmp_short = ivec4(y, cr, cb, 0); + cbcrMax = max(ycbcrTmp_short, ycbcrTmp1_short); + cbcrMin = min(ycbcrTmp_short, ycbcrTmp1_short); + cbcrSum = ivec2(ycbcrTmp1_short.y + ycbcrTmp_short.y, ycbcrTmp1_short.z + ycbcrTmp_short.z); + ySum += ycbcrTmp1_short.x + 2 * ycbcrTmp_short.x; + + fetchYCbCr(pixelCoord + ivec2(1, 1), y, cr, cb); + ycbcrTmp_short = ivec4(y, cr, cb, 0); + cbcrMax = max(ycbcrTmp_short, cbcrMax); + cbcrMin = min(ycbcrTmp_short, cbcrMin); + cbcrSum.x += ycbcrTmp_short.y - cbcrMax.y - cbcrMin.y; + cbcrSum.y += ycbcrTmp_short.z - cbcrMax.z - cbcrMin.z; + cbcrSumG += cbcrSum - min(cbcrMinG, cbcrSum) - max(cbcrMaxG, cbcrSum); + ySum += ycbcrTmp_short.x; + + outV.r = uint(ySum / 16); + outV.g = chromaUnsigned(cbcrSumG.x); + outV.b = chromaUnsigned(cbcrSumG.y); + outV.a = res0.a; + } + imageStore(outTex, gid, outV); +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_3_0x3049e97.comp b/research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_3_0x3049e97.comp new file mode 100644 index 00000000..ba2050b7 --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_3_0x3049e97.comp @@ -0,0 +1,183 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 9f0f02155a6f509830d6ddc3afa540da03684b8c9d752d96012957f74090786e + * ELF offsets: 0x3049e97 + * Symbols: demosaic_color_noise_pass_3_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; +precision highp image2D; +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D yccdTex; +layout(rgba16ui, binding = 1) readonly uniform uimage2D smoothTex; +layout(rgba16f, binding = 2) writeonly uniform image2D outTex; + +layout(std140, binding = 3) uniform DemosaicColorNoisePass3Params_UBO { + int uParams_l; + int uParams_t; + int uParams_r; + int uParams_b; + float uParams_gain; + float uPad0; + float uPad1; + float uPad2; +}; + +float hadd(float a, float b) { + return (a + b) * 0.5; +} + +int convert2compliment(int x) { + return ((x & (1 << 15)) != 0) ? (x | ~((1 << 16) - 1)) : x; +} + +vec4 ycc2rgb(vec4 ycc, float gain) { + vec4 res; + float ly = clamp(gain * ycc.r, 0.0, 65534.0); + int lr = int(round(ycc.g)); + int lb = int(round(ycc.b)); + lr = convert2compliment(lr); + lb = convert2compliment(lb); + res.r = clamp(ly * 3.0 * float(lr) / 32768.0 - ly * float(lb) / 32768.0 + ly, 0.0, 65535.0); + res.b = clamp(ly * 3.0 * float(lb) / 32768.0 - ly * float(lr) / 32768.0 + ly, 0.0, 65535.0); + res.g = clamp((4.0 * ly - (res.r + res.b)) / 2.0, 0.0, 65535.0); + res.a = ycc.a; + return res; +} + +void loadSmoothYCbCr(ivec2 p, out int yv, out int cr, out int cb) { + uvec4 u = imageLoad(smoothTex, p); + yv = int(u.r); + int g = int(u.g); + int b = int(u.b); + cr = (g > 32767) ? (g - 65536) : g; + cb = (b > 32767) ? (b - 65536) : b; +} + +vec4 colorFilter3(vec4 pix, ivec2 imgPos) { + ivec4 yA, yB, crA, cbA, crB, cbB; + + int yv; int cr; int cb; + loadSmoothYCbCr(imgPos + ivec2(-1, 0), yv, cr, cb); + yA[0] = yv; crA[0] = cr; cbA[0] = cb; + + loadSmoothYCbCr(imgPos + ivec2(1, 0), yv, cr, cb); + yB[0] = yv; crB[0] = cr; cbB[0] = cb; + + loadSmoothYCbCr(imgPos + ivec2(0, -1), yv, cr, cb); + yA[1] = yv; crA[1] = cr; cbA[1] = cb; + + loadSmoothYCbCr(imgPos + ivec2(0, 1), yv, cr, cb); + yB[1] = yv; crB[1] = cr; cbB[1] = cb; + + loadSmoothYCbCr(imgPos + ivec2(1, -1), yv, cr, cb); + yA[2] = yv; crA[2] = cr; cbA[2] = cb; + + loadSmoothYCbCr(imgPos + ivec2(-1, 1), yv, cr, cb); + yB[2] = yv; crB[2] = cr; cbB[2] = cb; + + loadSmoothYCbCr(imgPos + ivec2(-1, -1), yv, cr, cb); + yA[3] = yv; crA[3] = cr; cbA[3] = cb; + + loadSmoothYCbCr(imgPos + ivec2(1, 1), yv, cr, cb); + yB[3] = yv; crB[3] = cr; cbB[3] = cb; + + vec4 yP = vec4(pix.x); + vec4 crP = vec4(pix.y > 32767.0 ? (pix.y - 65536.0) : pix.y); + vec4 cbP = vec4(pix.z > 32767.0 ? (pix.z - 65536.0) : pix.z); + + vec4 difA = (abs(yP - vec4(float(yA[0]), float(yA[1]), float(yA[2]), float(yA[3]))) + + abs(crP - vec4(float(crA[0]), float(crA[1]), float(crA[2]), float(crA[3]))) + + abs(cbP - vec4(float(cbA[0]), float(cbA[1]), float(cbA[2]), float(cbA[3])))) * (1.0 / 6.0); + vec4 difB = (abs(yP - vec4(float(yB[0]), float(yB[1]), float(yB[2]), float(yB[3]))) + + abs(crP - vec4(float(crB[0]), float(crB[1]), float(crB[2]), float(crB[3]))) + + abs(cbP - vec4(float(cbB[0]), float(cbB[1]), float(cbB[2]), float(cbB[3])))) * (1.0 / 6.0); + + vec4 ly, lcr, lcb; + vec4 nom = difA + difB; + + for (int i = 0; i < 4; i++) { + if (nom[i] != 0.0) { + ly[i] = (float(yA[i]) * difB[i] + float(yB[i]) * difA[i]) / nom[i]; + lcr[i] = (float(crA[i]) * difB[i] + float(crB[i]) * difA[i]) / nom[i]; + lcb[i] = (float(cbA[i]) * difB[i] + float(cbB[i]) * difA[i]) / nom[i]; + } else { + ly[i] = hadd(float(yA[i]), float(yB[i])); + lcr[i] = hadd(float(crA[i]), float(crB[i])); + lcb[i] = hadd(float(cbA[i]), float(cbB[i])); + } + } + + vec4 scaleArr = min(abs(yP - ly) / (yP + ly) * 2.0, 1.0); + vec4 crArr = mix(crP, lcr, scaleArr); + vec4 cbArr = mix(cbP, lcb, scaleArr); + + vec4 dir0 = vec4(0.0, crArr[0], cbArr[0], scaleArr[0]); + vec4 dir1 = vec4(0.0, crArr[1], cbArr[1], scaleArr[1]); + vec4 dir2 = vec4(0.0, crArr[2], cbArr[2], scaleArr[2]); + vec4 dir3 = vec4(0.0, crArr[3], cbArr[3], scaleArr[3]); + + vec4 crcbe = vec4(0.0); + int pixw = int(pix.w); + int count = 0; + if ((pixw & (1 << 0)) != 0) { crcbe += dir0; count++; } + if ((pixw & (1 << 1)) != 0) { crcbe += dir0; count++; } + if ((pixw & (1 << 2)) != 0) { crcbe += dir1; count++; } + if ((pixw & (1 << 3)) != 0) { crcbe += dir1; count++; } + if ((pixw & (1 << 4)) != 0) { crcbe += dir2; count++; } + if ((pixw & (1 << 5)) != 0) { crcbe += dir2; count++; } + if ((pixw & (1 << 6)) != 0) { crcbe += dir3; count++; } + if ((pixw & (1 << 7)) != 0) { crcbe += dir3; count++; } + + if (count > 0) { + crcbe /= float(count); + } + + pix.w = crcbe.w * 65535.0; + + float scale = min(min(scaleArr.x, scaleArr.y), min(scaleArr.z, scaleArr.w)); + float yScale = clamp(1.0 - (yP.x / 16384.0 * scale), 0.0, 1.0); + pix.y = yScale * crcbe.y; + pix.z = yScale * crcbe.z; + + return pix; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + + ivec2 srcPos = gid + ivec2(uParams_l, uParams_t); + uvec4 uYccd = imageLoad(yccdTex, srcPos); + vec4 yccdPix = vec4(float(uYccd.r), float(uYccd.g), float(uYccd.b), float(uYccd.a)); + yccdPix.yz = vec2(yccdPix.y > 32767.0 ? (yccdPix.y - 65536.0) : yccdPix.y, + yccdPix.z > 32767.0 ? (yccdPix.z - 65536.0) : yccdPix.z); + + if (yccdPix.x != 0.0 && yccdPix.w != 0.0) { + yccdPix = colorFilter3(yccdPix, srcPos); + } + + uvec4 uSmooth = imageLoad(smoothTex, srcPos); + vec4 smoothPix = vec4(float(uSmooth.r), float(uSmooth.g), float(uSmooth.b), float(uSmooth.a)); + float smoothY = smoothPix.y > 32767.0 ? (smoothPix.y - 65536.0) : smoothPix.y; + float smoothZ = smoothPix.z > 32767.0 ? (smoothPix.z - 65536.0) : smoothPix.z; + float yccdY = yccdPix.y > 32767.0 ? (yccdPix.y - 65536.0) : yccdPix.y; + float yccdZ = yccdPix.z > 32767.0 ? (yccdPix.z - 65536.0) : yccdPix.z; + + if (abs(smoothY) + abs(smoothZ) < abs(yccdY) + abs(yccdZ)) { + yccdPix.y = smoothPix.y; + yccdPix.z = smoothPix.z; + } + + vec4 result = ycc2rgb(yccdPix, uParams_gain); + vec4 outF = vec4( + clamp(result.r, 0.0, 65535.0), + clamp(result.g, 0.0, 65535.0), + clamp(result.b, 0.0, 65535.0), + clamp(result.a, 0.0, 65535.0) + ) / 65535.0; + imageStore(outTex, gid, outF); +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_3_yccd_0x303704a.comp b/research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_3_yccd_0x303704a.comp new file mode 100644 index 00000000..4db954f2 --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_color_noise_pass_3_yccd_0x303704a.comp @@ -0,0 +1,159 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: b3af96dca2b14851ada4f1cd7cad4b9e9bfa6c4f499fe6edf9e4367e6fe2246d + * ELF offsets: 0x303704a + * Symbols: demosaic_color_noise_pass_3_yccd_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D yccdTex; +layout(rgba16ui, binding = 1) readonly uniform uimage2D smoothTex; +layout(rgba16ui, binding = 2) writeonly uniform uimage2D outYccd; +layout(rgba16ui, binding = 3) writeonly uniform uimage2D outSmooth; + +layout(std140, binding = 4) uniform DemosaicColorNoisePass3YccdParams_UBO { + int uParams_l; + int uParams_t; + int uParams_r; + int uParams_b; +}; + +float hadd(float a, float b) { + return (a + b) * 0.5; +} + +int chromaSigned(uint c) { + int ic = int(c); + return (ic > 32767) ? (ic - 65536) : ic; +} + +uint chromaUnsigned(int v) { + return uint(v & 0xFFFF); +} + +void loadSmoothYCbCr(ivec2 p, out int yv, out int cr, out int cb) { + uvec4 u = imageLoad(smoothTex, p); + yv = int(u.r); + cr = chromaSigned(u.g); + cb = chromaSigned(u.b); +} + +vec4 colorFilter3(vec4 pix, ivec2 imgPos) { + ivec4 yA, yB, crA, cbA, crB, cbB; + + int yv, cr, cb; + loadSmoothYCbCr(imgPos + ivec2(-1, 0), yv, cr, cb); + yA[0] = yv; crA[0] = cr; cbA[0] = cb; + loadSmoothYCbCr(imgPos + ivec2(1, 0), yv, cr, cb); + yB[0] = yv; crB[0] = cr; cbB[0] = cb; + loadSmoothYCbCr(imgPos + ivec2(0, -1), yv, cr, cb); + yA[1] = yv; crA[1] = cr; cbA[1] = cb; + loadSmoothYCbCr(imgPos + ivec2(0, 1), yv, cr, cb); + yB[1] = yv; crB[1] = cr; cbB[1] = cb; + loadSmoothYCbCr(imgPos + ivec2(1, -1), yv, cr, cb); + yA[2] = yv; crA[2] = cr; cbA[2] = cb; + loadSmoothYCbCr(imgPos + ivec2(-1, 1), yv, cr, cb); + yB[2] = yv; crB[2] = cr; cbB[2] = cb; + loadSmoothYCbCr(imgPos + ivec2(-1, -1), yv, cr, cb); + yA[3] = yv; crA[3] = cr; cbA[3] = cb; + loadSmoothYCbCr(imgPos + ivec2(1, 1), yv, cr, cb); + yB[3] = yv; crB[3] = cr; cbB[3] = cb; + + vec4 yP = vec4(pix.x); + vec4 crP = vec4(pix.y > 32767.0 ? (pix.y - 65536.0) : pix.y); + vec4 cbP = vec4(pix.z > 32767.0 ? (pix.z - 65536.0) : pix.z); + + vec4 difA = (abs(yP - vec4(float(yA[0]), float(yA[1]), float(yA[2]), float(yA[3]))) + + abs(crP - vec4(float(crA[0]), float(crA[1]), float(crA[2]), float(crA[3]))) + + abs(cbP - vec4(float(cbA[0]), float(cbA[1]), float(cbA[2]), float(cbA[3])))) * (1.0 / 6.0); + vec4 difB = (abs(yP - vec4(float(yB[0]), float(yB[1]), float(yB[2]), float(yB[3]))) + + abs(crP - vec4(float(crB[0]), float(crB[1]), float(crB[2]), float(crB[3]))) + + abs(cbP - vec4(float(cbB[0]), float(cbB[1]), float(cbB[2]), float(cbB[3])))) * (1.0 / 6.0); + + vec4 ly, lcr, lcb; + vec4 nom = difA + difB; + for (int i = 0; i < 4; i++) { + if (nom[i] != 0.0) { + ly[i] = (float(yA[i]) * difB[i] + float(yB[i]) * difA[i]) / nom[i]; + lcr[i] = (float(crA[i]) * difB[i] + float(crB[i]) * difA[i]) / nom[i]; + lcb[i] = (float(cbA[i]) * difB[i] + float(cbB[i]) * difA[i]) / nom[i]; + } else { + ly[i] = hadd(float(yA[i]), float(yB[i])); + lcr[i] = hadd(float(crA[i]), float(crB[i])); + lcb[i] = hadd(float(cbA[i]), float(cbB[i])); + } + } + + vec4 scaleArr = min(abs(yP - ly) / (yP + ly) * 2.0, 1.0); + vec4 crArr = mix(crP, lcr, scaleArr); + vec4 cbArr = mix(cbP, lcb, scaleArr); + + vec4 dir0 = vec4(0.0, crArr[0], cbArr[0], scaleArr[0]); + vec4 dir1 = vec4(0.0, crArr[1], cbArr[1], scaleArr[1]); + vec4 dir2 = vec4(0.0, crArr[2], cbArr[2], scaleArr[2]); + vec4 dir3 = vec4(0.0, crArr[3], cbArr[3], scaleArr[3]); + + vec4 crcbe = vec4(0.0); + int pixw = int(pix.w); + int count = 0; + if ((pixw & (1 << 0)) != 0) { crcbe += dir0; count++; } + if ((pixw & (1 << 1)) != 0) { crcbe += dir0; count++; } + if ((pixw & (1 << 2)) != 0) { crcbe += dir1; count++; } + if ((pixw & (1 << 3)) != 0) { crcbe += dir1; count++; } + if ((pixw & (1 << 4)) != 0) { crcbe += dir2; count++; } + if ((pixw & (1 << 5)) != 0) { crcbe += dir2; count++; } + if ((pixw & (1 << 6)) != 0) { crcbe += dir3; count++; } + if ((pixw & (1 << 7)) != 0) { crcbe += dir3; count++; } + + if (count > 0) { + crcbe /= float(count); + } + + pix.w = crcbe.w * 65535.0; + + float scale = min(min(scaleArr.x, scaleArr.y), min(scaleArr.z, scaleArr.w)); + float yScale = clamp(1.0 - (yP.x / 16384.0 * scale), 0.0, 1.0); + pix.y = yScale * crcbe.y; + pix.z = yScale * crcbe.z; + + return pix; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + if (gid.x < uParams_l || gid.x >= uParams_r || + gid.y < uParams_t || gid.y >= uParams_b) return; + + uvec4 uYccd = imageLoad(yccdTex, gid); + vec4 yccdPix = vec4(float(uYccd.r), float(uYccd.g), float(uYccd.b), float(uYccd.a)); + yccdPix.yz = vec2(yccdPix.y > 32767.0 ? (yccdPix.y - 65536.0) : yccdPix.y, + yccdPix.z > 32767.0 ? (yccdPix.z - 65536.0) : yccdPix.z); + uint dir = uYccd.a; + if (yccdPix.x != 0.0 && yccdPix.w != 0.0) { + yccdPix = colorFilter3(yccdPix, gid); + } else { + yccdPix.w = 0.0; + } + uint error = uint(yccdPix.w); + + uvec4 uSmooth = imageLoad(smoothTex, gid); + float smoothY = float(uSmooth.g) > 32767.0 ? (float(uSmooth.g) - 65536.0) : float(uSmooth.g); + float smoothZ = float(uSmooth.b) > 32767.0 ? (float(uSmooth.b) - 65536.0) : float(uSmooth.b); + float yccdY = yccdPix.y > 32767.0 ? (yccdPix.y - 65536.0) : yccdPix.y; + float yccdZ = yccdPix.z > 32767.0 ? (yccdPix.z - 65536.0) : yccdPix.z; + + if (abs(smoothY) + abs(smoothZ) < abs(yccdY) + abs(yccdZ)) { + yccdPix.y = float(uSmooth.g); + yccdPix.z = float(uSmooth.b); + } + + // Output YCCD: (Y, Cr, Cb, dir) + imageStore(outYccd, gid, uvec4(uint(yccdPix.x), chromaUnsigned(int(yccdPix.y)), chromaUnsigned(int(yccdPix.z)), dir)); + // Output Smooth: (Y, Cr, Cb, error) + imageStore(outSmooth, gid, uvec4(uint(yccdPix.x), chromaUnsigned(int(yccdPix.y)), chromaUnsigned(int(yccdPix.z)), error)); +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_iir2_pass1_0x3041e8f.comp b/research/phocus_glsl/02_demosaic/demosaic_iir2_pass1_0x3041e8f.comp new file mode 100644 index 00000000..cbb11dcc --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_iir2_pass1_0x3041e8f.comp @@ -0,0 +1,85 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 9c22e56ab98ccba2df1047cf363f263ad92e146700c596b8622b03af6ca5233b + * ELF offsets: 0x3041e8f + * Symbols: demosaic_iir2_pass1_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; +layout(local_size_x = 1, local_size_y = 1) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D srcTex; +layout(rgba16ui, binding = 1) writeonly uniform uimage2D dstTex; + +layout(std140, binding = 2) uniform IIR2Coefs_UBO { + vec4 a_10; + vec4 b_10; + vec4 a_dyn_1; + vec4 b_dyn_1; + vec4 a_dyn_2; + vec4 b_dyn_2; + int uWidth; + int uHeight; + int uDirection; + int uAxis; +}; + +struct Delayer { + float x0, x1, y0, y1; +}; + +float delayerApply(inout Delayer d, float val, vec4 pCoefA, vec4 pCoefB, bool useShort) { + float sum = pCoefA[0] * val; + sum += pCoefA[1] * d.x0 - pCoefB[1] * d.y0; + sum += pCoefA[2] * d.x1 - pCoefB[2] * d.y1; + d.x1 = d.x0; + d.y1 = d.y0; + d.x0 = val; + if (useShort) + d.y0 = sum; + else + d.y0 = max(0.0, min(sum, 65535.0)); + return d.y0; +} + +int chromaSigned(uint c) { + int ic = int(c); + return (ic > 32767) ? (ic - 65536) : ic; +} + +uint chromaUnsigned(int v) { + return uint(v & 0xFFFF); +} + +void main() { + int outerIdx = (uAxis == 0) ? int(gl_GlobalInvocationID.y) : int(gl_GlobalInvocationID.x); + int outerLimit = (uAxis == 0) ? uHeight : uWidth; + int innerSize = (uAxis == 0) ? uWidth : uHeight; + if (outerIdx >= outerLimit) return; + + int start = (uDirection == 0) ? 0 : innerSize - 1; + int step = (uDirection == 0) ? 1 : -1; + + Delayer d_p10 = Delayer(0.0, 0.0, 0.0, 0.0); + Delayer d_norm1r = Delayer(0.0, 0.0, 0.0, 0.0); + Delayer d_norm1b = Delayer(0.0, 0.0, 0.0, 0.0); + Delayer d_norm2r = Delayer(0.0, 0.0, 0.0, 0.0); + Delayer d_norm2b = Delayer(0.0, 0.0, 0.0, 0.0); + + for (int i = 0; i < innerSize; i++) { + int innerIdx = start + i * step; + ivec2 pos = (uAxis == 0) ? ivec2(innerIdx, outerIdx) : ivec2(outerIdx, innerIdx); + uvec4 pix = imageLoad(srcTex, pos); + + float Y = delayerApply(d_p10, float(pix.r), a_10, b_10, false); + float cr = delayerApply(d_norm1r, float(chromaSigned(pix.g)), a_dyn_1, b_dyn_1, true); + float cb = delayerApply(d_norm1b, float(chromaSigned(pix.b)), a_dyn_1, b_dyn_1, true); + cr = delayerApply(d_norm2r, cr, a_dyn_2, b_dyn_2, true); + cb = delayerApply(d_norm2b, cb, a_dyn_2, b_dyn_2, true); + + imageStore(dstTex, pos, uvec4(uint(Y), chromaUnsigned(int(cr)), chromaUnsigned(int(cb)), pix.a)); + } +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_iir2_pass1_init_0x3005a70.comp b/research/phocus_glsl/02_demosaic/demosaic_iir2_pass1_init_0x3005a70.comp new file mode 100644 index 00000000..92d072d7 --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_iir2_pass1_init_0x3005a70.comp @@ -0,0 +1,81 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: b4203de6cb2b2a0d2d45bf31b94709bcbe51958985b0a49d92728ed4bdeedad2 + * ELF offsets: 0x3005a70 + * Symbols: demosaic_iir2_pass1_init_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; +layout(local_size_x = 1, local_size_y = 1) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D srcTex; +layout(rgba16ui, binding = 1) readonly uniform uimage2D srcSmoothTex; +layout(rgba16ui, binding = 2) writeonly uniform uimage2D dstTex; + +layout(std140, binding = 3) uniform IIR2Coefs_UBO { + vec4 a_10; + vec4 b_10; + vec4 a_dyn_1; + vec4 b_dyn_1; + vec4 a_dyn_2; + vec4 b_dyn_2; + int uWidth; + int uHeight; + int uDirection; + int uAxis; +}; + +struct Delayer { + float x0, x1, y0, y1; +}; + +float delayerApply(inout Delayer d, float val, vec4 pCoefA, vec4 pCoefB, bool useShort) { + float sum = pCoefA[0] * val; + sum += pCoefA[1] * d.x0 - pCoefB[1] * d.y0; + sum += pCoefA[2] * d.x1 - pCoefB[2] * d.y1; + d.x1 = d.x0; + d.y1 = d.y0; + d.x0 = val; + if (useShort) + d.y0 = sum; + else + d.y0 = max(0.0, min(sum, 65535.0)); + return d.y0; +} + +int chromaSigned(uint c) { + int ic = int(c); + return (ic > 32767) ? (ic - 65536) : ic; +} + +uint chromaUnsigned(int v) { + return uint(v & 0xFFFF); +} + +void main() { + int row = int(gl_GlobalInvocationID.y); + if (row >= uHeight) return; + + Delayer d_p10 = Delayer(0.0, 0.0, 0.0, 0.0); + Delayer d_norm1r = Delayer(0.0, 0.0, 0.0, 0.0); + Delayer d_norm1b = Delayer(0.0, 0.0, 0.0, 0.0); + Delayer d_norm2r = Delayer(0.0, 0.0, 0.0, 0.0); + Delayer d_norm2b = Delayer(0.0, 0.0, 0.0, 0.0); + + for (int x = 0; x < uWidth; x++) { + ivec2 pos = ivec2(x, row); + uvec4 pix = imageLoad(srcTex, pos); + uvec4 pix2 = imageLoad(srcSmoothTex, pos); + + float y = delayerApply(d_p10, float(pix.r), a_10, b_10, false); + float cr = delayerApply(d_norm1r, float(chromaSigned(pix.g)), a_dyn_1, b_dyn_1, true); + float cb = delayerApply(d_norm1b, float(chromaSigned(pix.b)), a_dyn_1, b_dyn_1, true); + cr = delayerApply(d_norm2r, cr, a_dyn_2, b_dyn_2, true); + cb = delayerApply(d_norm2b, cb, a_dyn_2, b_dyn_2, true); + + imageStore(dstTex, pos, uvec4(uint(y), chromaUnsigned(int(cr)), chromaUnsigned(int(cb)), pix2.a)); + } +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_iir2_pass2_0x3006acc.comp b/research/phocus_glsl/02_demosaic/demosaic_iir2_pass2_0x3006acc.comp new file mode 100644 index 00000000..e283e941 --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_iir2_pass2_0x3006acc.comp @@ -0,0 +1,65 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 3880b76927b8cd1ca8c15558912f032c8594312e3180834b0fc36a1c55bd64b0 + * ELF offsets: 0x3006acc + * Symbols: demosaic_iir2_pass2_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; +layout(local_size_x = 1, local_size_y = 1) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D srcTex; +layout(rgba16ui, binding = 1) writeonly uniform uimage2D dstTex; + +layout(std140, binding = 2) uniform IIR2Coefs_UBO { + vec4 a_10; + vec4 b_10; + vec4 a_dyn_1; + vec4 b_dyn_1; + vec4 a_dyn_2; + vec4 b_dyn_2; + int uWidth; + int uHeight; + int uDirection; + int uAxis; +}; + +struct Delayer { + float x0, x1, y0, y1; +}; + +float delayerApply(inout Delayer d, float val, vec4 pCoefA, vec4 pCoefB) { + float sum = pCoefA[0] * val; + sum += pCoefA[1] * d.x0 - pCoefB[1] * d.y0; + sum += pCoefA[2] * d.x1 - pCoefB[2] * d.y1; + d.x1 = d.x0; + d.y1 = d.y0; + d.x0 = val; + d.y0 = max(0.0, min(sum, 65535.0)); + return d.y0; +} + +void main() { + int outerIdx = (uAxis == 0) ? int(gl_GlobalInvocationID.y) : int(gl_GlobalInvocationID.x); + int outerLimit = (uAxis == 0) ? uHeight : uWidth; + int innerSize = (uAxis == 0) ? uWidth : uHeight; + if (outerIdx >= outerLimit) return; + + int start = (uDirection == 0) ? 0 : innerSize - 1; + int step = (uDirection == 0) ? 1 : -1; + + Delayer d_p10 = Delayer(0.0, 0.0, 0.0, 0.0); + + for (int i = 0; i < innerSize; i++) { + int innerIdx = start + i * step; + ivec2 pos = (uAxis == 0) ? ivec2(innerIdx, outerIdx) : ivec2(outerIdx, innerIdx); + uvec4 pix = imageLoad(srcTex, pos); + + float err = delayerApply(d_p10, float(pix.a), a_10, b_10); + + imageStore(dstTex, pos, uvec4(pix.r, pix.g, pix.b, uint(err))); + } +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_iir2_pass3_0x3068458.comp b/research/phocus_glsl/02_demosaic/demosaic_iir2_pass3_0x3068458.comp new file mode 100644 index 00000000..cb650d2e --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_iir2_pass3_0x3068458.comp @@ -0,0 +1,80 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: e665176d25d909367a134dd38315c49c97b9157836dc8165b0225cb611582e96 + * ELF offsets: 0x3068458 + * Symbols: demosaic_iir2_pass3_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; +layout(local_size_x = 1, local_size_y = 1) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D srcTex; +layout(rgba16ui, binding = 1) writeonly uniform uimage2D dstTex; + +layout(std140, binding = 2) uniform IIR2Coefs_UBO { + vec4 a_10; + vec4 b_10; + vec4 a_dyn_1; + vec4 b_dyn_1; + vec4 a_dyn_2; + vec4 b_dyn_2; + int uWidth; + int uHeight; + int uDirection; + int uAxis; +}; + +struct Delayer { + float x0, x1, y0, y1; +}; + +float delayerApply(inout Delayer d, float val, vec4 pCoefA, vec4 pCoefB) { + float sum = pCoefA[0] * val; + sum += pCoefA[1] * d.x0 - pCoefB[1] * d.y0; + sum += pCoefA[2] * d.x1 - pCoefB[2] * d.y1; + d.x1 = d.x0; + d.y1 = d.y0; + d.x0 = val; + d.y0 = sum; + return d.y0; +} + +int chromaSigned(uint c) { + int ic = int(c); + return (ic > 32767) ? (ic - 65536) : ic; +} + +uint chromaUnsigned(int v) { + return uint(v & 0xFFFF); +} + +void main() { + int outerIdx = (uAxis == 0) ? int(gl_GlobalInvocationID.y) : int(gl_GlobalInvocationID.x); + int outerLimit = (uAxis == 0) ? uHeight : uWidth; + int innerSize = (uAxis == 0) ? uWidth : uHeight; + if (outerIdx >= outerLimit) return; + + int start = (uDirection == 0) ? 0 : innerSize - 1; + int step = (uDirection == 0) ? 1 : -1; + + Delayer d_norm1r = Delayer(0.0, 0.0, 0.0, 0.0); + Delayer d_norm1b = Delayer(0.0, 0.0, 0.0, 0.0); + Delayer d_norm2r = Delayer(0.0, 0.0, 0.0, 0.0); + Delayer d_norm2b = Delayer(0.0, 0.0, 0.0, 0.0); + + for (int i = 0; i < innerSize; i++) { + int innerIdx = start + i * step; + ivec2 pos = (uAxis == 0) ? ivec2(innerIdx, outerIdx) : ivec2(outerIdx, innerIdx); + uvec4 pix = imageLoad(srcTex, pos); + + float cr = delayerApply(d_norm1r, float(chromaSigned(pix.g)), a_dyn_1, b_dyn_1); + float cb = delayerApply(d_norm1b, float(chromaSigned(pix.b)), a_dyn_1, b_dyn_1); + cr = delayerApply(d_norm2r, cr, a_dyn_2, b_dyn_2); + cb = delayerApply(d_norm2b, cb, a_dyn_2, b_dyn_2); + + imageStore(dstTex, pos, uvec4(pix.r, chromaUnsigned(int(cr)), chromaUnsigned(int(cb)), pix.a)); + } +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_pass_0a1_0x30410af.comp b/research/phocus_glsl/02_demosaic/demosaic_pass_0a1_0x30410af.comp new file mode 100644 index 00000000..3d275a29 --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_pass_0a1_0x30410af.comp @@ -0,0 +1,149 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 54604631e2fdfb4d993170190d5b8dab390379a81b500e43d337af975cade411 + * ELF offsets: 0x30410af + * Symbols: demosaic_pass_0a1_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; + +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D inTex; +layout(rgba16ui, binding = 1) writeonly uniform uimage2D outTex; +layout(std140, binding = 2) uniform DemosaicPass0a1Params_UBO { + int uParams_lq; + int uParams_tq; + int uParams_rq; + int uParams_bq; +}; + +ivec4 loadI(ivec2 p) { + return ivec4(imageLoad(inTex, p)); +} + +uvec4 toU16FromI(ivec4 v) { + return uvec4(clamp(v, ivec4(0), ivec4(65535))); +} + +ivec4 smoothFilterFlt(ivec2 imgPos) { + ivec4 sum = ivec4(0); + + ivec4 v1 = loadI(imgPos + ivec2(-1, -1)); + sum.r = v1.a; + + ivec4 v2 = loadI(imgPos + ivec2(-1, 0)); + sum.r += 2 * v2.a; + + ivec4 v3 = loadI(imgPos + ivec2(-1, 1)); + sum.r += v3.a; + + ivec4 v4 = loadI(imgPos + ivec2(0, -1)); + sum.r += 2 * v4.r + v4.g; + sum.g = v4.r + 2 * v4.g + v4.b; + sum.b = v4.g + 2 * v4.b + v4.a; + sum.a = v4.b + 2 * v4.a; + + ivec4 v5 = loadI(imgPos + ivec2(0, 0)); + sum.r += 4 * v5.r + 2 * v5.g; + sum.g += 2 * v5.r + 4 * v5.g + 2 * v5.b; + sum.b += 2 * v5.g + 4 * v5.b + 2 * v5.a; + sum.a += 2 * v5.b + 4 * v5.a; + + ivec4 v6 = loadI(imgPos + ivec2(0, 1)); + sum.r += 2 * v6.r + v6.g; + sum.g += v6.r + 2 * v6.g + v6.b; + sum.b += v6.g + 2 * v6.b + v6.a; + sum.a += v6.b + 2 * v6.a; + + ivec4 v7 = loadI(imgPos + ivec2(1, -1)); + sum.a += v7.r; + + ivec4 v8 = loadI(imgPos + ivec2(1, 0)); + sum.a += 2 * v8.r; + + ivec4 v9 = loadI(imgPos + ivec2(1, 1)); + sum.a += v9.r; + + return sum >> 4; +} + +ivec4 smoothFilterLR(ivec2 imgPos, bool skipL, bool skipR) { + ivec4 sum = ivec4(0); + + if (skipL) { + sum.r = 0; + imgPos.y += 1; + } else { + imgPos.x -= 1; + imgPos.y -= 1; + ivec4 v = loadI(imgPos); + sum.r = v.a; + + imgPos.y += 1; + v = loadI(imgPos); + sum.r += 2 * v.a; + + imgPos.y += 1; + v = loadI(imgPos); + sum.r += v.a; + imgPos.x += 1; + } + + ivec4 v4 = loadI(imgPos); + sum.r += 2 * v4.r + v4.g; + sum.g = v4.r + 2 * v4.g + v4.b; + sum.b = v4.g + 2 * v4.b + v4.a; + sum.a = v4.b + 2 * v4.a; + + imgPos.y -= 1; + ivec4 v5 = loadI(imgPos); + sum.r += 4 * v5.r + 2 * v5.g; + sum.g += 2 * v5.r + 4 * v5.g + 2 * v5.b; + sum.b += 2 * v5.g + 4 * v5.b + 2 * v5.a; + sum.a += 2 * v5.b + 4 * v5.a; + + imgPos.y -= 1; + ivec4 v6 = loadI(imgPos); + sum.r += 2 * v6.r + v6.g; + sum.g += v6.r + 2 * v6.g + v6.b; + sum.b += v6.g + 2 * v6.b + v6.a; + sum.a += v6.b + 2 * v6.a; + + if (skipR) { + sum.a = 0; + } else { + imgPos.x += 1; + ivec4 v7 = loadI(imgPos); + sum.a += v7.r; + + imgPos.y += 1; + ivec4 v8 = loadI(imgPos); + sum.a += 2 * v8.r; + + imgPos.y += 1; + ivec4 v9 = loadI(imgPos); + sum.a += v9.r; + } + + if (skipL) sum.r = 0; + return sum >> 4; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + + ivec4 result = ivec4(0); + if (gid.x > uParams_lq && gid.y >= uParams_tq && gid.x < uParams_rq && gid.y < uParams_bq) { + result = smoothFilterFlt(gid); + } else if (gid.x == uParams_lq && gid.y >= uParams_tq && gid.x < uParams_rq && gid.y < uParams_bq) { + result = smoothFilterLR(gid, true, false); + } else if (gid.x > uParams_lq && gid.y >= uParams_tq && gid.x == uParams_rq && gid.y < uParams_bq) { + result = smoothFilterLR(gid, false, true); + } + + imageStore(outTex, gid, toU16FromI(result)); +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_pass_0a2_0x30555c4.comp b/research/phocus_glsl/02_demosaic/demosaic_pass_0a2_0x30555c4.comp new file mode 100644 index 00000000..9681cced --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_pass_0a2_0x30555c4.comp @@ -0,0 +1,112 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 0efa5c950f6502ed9836a8cd18dc935a686aa8e8033e3d36d9cb96ca7d92b347 + * ELF offsets: 0x30555c4 + * Symbols: demosaic_pass_0a2_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp image2D; +precision highp uimage2D; + +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D inTex; +layout(rgba16f, binding = 1) writeonly uniform image2D outTex; +layout(std140, binding = 2) uniform DemosaicPass0a2Params_UBO { + int uParams_l; + int uParams_t; + int uParams_r; + int uParams_b; + float uParams_stdDeviation; + float uParams_pad0; + float uParams_pad1; + float uParams_pad2; +}; + +vec4 loadU(ivec2 p) { + return vec4(imageLoad(inTex, p)); +} + +vec2 scaleFilterFlt(float v_2, float v_1, float v0, float v1, float v2, float stdDeviation) { + float minG = min(min(v0, v_2), v2); + if (minG < stdDeviation) + return vec2(1.0, 0.0); + + float rbSum = v_1 + v1; + float rbDif = abs(v_1 - v1); + float greenSum0 = v_2 + v0; + float greenDif0 = abs(v_2 - v0); + float greenSum2 = v0 + v2; + float greenDif2 = abs(v0 - v2); + + vec2 gsr = vec2(1.0 / (greenSum0 + 1.0), 1.0 / (greenSum2 + 1.0)); + float rgScale0 = v_1 * 2.0 * gsr.x; + float rgScale1 = rbSum / (v0 * 2.0 + 1.0); + float rgScale2 = v1 * 2.0 * gsr.y; + + float difScale1 = rbDif / (rbSum + 1.0); + float difScale0 = greenDif0 * gsr.x; + float difScale2 = greenDif2 * gsr.y; + + vec2 res; + res.y = difScale0 + difScale1 + difScale2; + if (res.y > 0.05) { + float ryr = 1.5 / res.y; + rgScale0 = rgScale0 * ryr * (res.y - difScale0); + rgScale1 = rgScale1 * ryr * (res.y - difScale1); + rgScale2 = rgScale2 * ryr * (res.y - difScale2); + } + + res.x = rgScale0 + rgScale1 + rgScale2; + if (res.x != 0.0) res.x = 3.0 / res.x; + return res; +} + +void main() { + ivec2 outputPos = ivec2(gl_GlobalInvocationID.xy); + + int gid_x = outputPos.x / 4; + int gid_y = outputPos.y; + int outputIndex = outputPos.x % 4; + + if (gid_x <= uParams_l || gid_x >= uParams_r || + gid_y < uParams_t || gid_y >= uParams_b) { + return; + } + + ivec2 inputPixelCoord = ivec2(gid_x, gid_y * 2); + vec4 v_2 = loadU(inputPixelCoord + ivec2(0, -2)); + vec4 v_1 = loadU(inputPixelCoord + ivec2(0, -1)); + vec4 v0 = loadU(inputPixelCoord + ivec2(0, 0)); + vec4 v1 = loadU(inputPixelCoord + ivec2(0, 1)); + vec4 v2 = loadU(inputPixelCoord + ivec2(0, 2)); + vec4 v3 = loadU(inputPixelCoord + ivec2(0, 3)); + + vec2 out_h, out_v; + if (outputIndex == 0) { + out_v = scaleFilterFlt(v_1.r, v0.r, v1.r, v2.r, v3.r, uParams_stdDeviation); + vec4 in_1 = loadU(inputPixelCoord + ivec2(-1, 1)); + vec4 in0 = v1; + out_h = scaleFilterFlt(in_1.b, in_1.a, in0.r, in0.g, in0.b, uParams_stdDeviation); + } else if (outputIndex == 1) { + out_v = scaleFilterFlt(v_2.g, v_1.g, v0.g, v1.g, v2.g, uParams_stdDeviation); + vec4 in_1 = loadU(inputPixelCoord + ivec2(-1, 0)); + vec4 in0 = v0; + out_h = scaleFilterFlt(in_1.a, in0.r, in0.g, in0.b, in0.a, uParams_stdDeviation); + } else if (outputIndex == 2) { + out_v = scaleFilterFlt(v_1.b, v0.b, v1.b, v2.b, v3.b, uParams_stdDeviation); + vec4 in0 = v1; + vec4 in1 = loadU(inputPixelCoord + ivec2(1, 1)); + out_h = scaleFilterFlt(in0.r, in0.g, in0.b, in0.a, in1.r, uParams_stdDeviation); + } else { + out_v = scaleFilterFlt(v_2.a, v_1.a, v0.a, v1.a, v2.a, uParams_stdDeviation); + vec4 in0 = v0; + vec4 in1 = loadU(inputPixelCoord + ivec2(1, 0)); + out_h = scaleFilterFlt(in0.g, in0.b, in0.a, in1.r, in1.g, uParams_stdDeviation); + } + + imageStore(outTex, outputPos, vec4(out_h.x, out_v.x, out_h.y, out_v.y)); +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_pass_0b_0x30325b5.comp b/research/phocus_glsl/02_demosaic/demosaic_pass_0b_0x30325b5.comp new file mode 100644 index 00000000..485601ae --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_pass_0b_0x30325b5.comp @@ -0,0 +1,80 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 6ebfd8f9386e94f8fc0090d4b6379e8ac599ae6581c15edb35a0c1ed5981e6c5 + * ELF offsets: 0x30325b5 + * Symbols: demosaic_pass_0b_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp image2D; +precision highp uimage2D; + +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16f, binding = 0) readonly uniform image2D inTex; // textureScale (width, height/2) +layout(rgba16f, binding = 1) writeonly uniform image2D outTex; // textureMedian (width/4, height/2) + +layout(std140, binding = 2) uniform DemosaicPass0bParams_UBO { + int uParams_l; + int uParams_t; + int uParams_r; + int uParams_b; +}; + +vec2 medianFilter(ivec2 imgPos) { + ivec2 pos1 = ivec2(imgPos.x, (imgPos.y - 1) / 2); + ivec2 pos2 = ivec2(imgPos.x + 2, (imgPos.y - 1) / 2); + + float scale0 = imageLoad(inTex, pos1).g; + float scale1 = imageLoad(inTex, pos2).g; + vec2 v = vec2(scale0, scale1); + vec2 sum = v; + + pos1 = ivec2(imgPos.x, (imgPos.y - 1) / 2 + 1); + pos2 = ivec2(imgPos.x + 2, (imgPos.y - 1) / 2 + 1); + scale0 = imageLoad(inTex, pos1).g; + scale1 = imageLoad(inTex, pos2).g; + v = vec2(scale0, scale1); + vec2 minv = min(sum, v); + vec2 maxv = max(sum, v); + sum += v; + + pos1 = ivec2(imgPos.x - 1, imgPos.y / 2); + pos2 = ivec2(imgPos.x + 1, imgPos.y / 2); + scale0 = imageLoad(inTex, pos1).r; + scale1 = imageLoad(inTex, pos2).r; + v = vec2(scale0, scale1); + minv = min(minv, v); + maxv = max(maxv, v); + sum += v; + + pos2 = ivec2(imgPos.x + 3, imgPos.y / 2); + scale0 = imageLoad(inTex, pos2).r; + v = vec2(scale1, scale0); + minv = min(minv, v); + maxv = max(maxv, v); + sum += v; + return (sum - minv - maxv) / 2.0; +} + +void main() { + ivec2 outputPos = ivec2(gl_GlobalInvocationID.xy); + + if (outputPos.x < uParams_l || outputPos.x >= uParams_r || + outputPos.y * 2 < uParams_t || outputPos.y * 2 >= uParams_b) { + return; + } + + int inputX = outputPos.x * 4; + int inputY = outputPos.y; + + ivec2 pos1 = ivec2(inputX + 0, inputY * 2 + 0); + ivec2 pos2 = ivec2(inputX + 1, inputY * 2 + 1); + + vec2 med1 = medianFilter(pos1); + vec2 med2 = medianFilter(pos2); + + imageStore(outTex, outputPos, vec4(med1.x, med2.x, med1.y, med2.y)); +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_pass_0c_0x306798d.comp b/research/phocus_glsl/02_demosaic/demosaic_pass_0c_0x306798d.comp new file mode 100644 index 00000000..aa980af5 --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_pass_0c_0x306798d.comp @@ -0,0 +1,100 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: cbbd4fee1875088d68c839eb922dffa6be9b1c175ff33941b4465deb990dca95 + * ELF offsets: 0x306798d + * Symbols: demosaic_pass_0c_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp iimage2D; +precision highp uimage2D; + +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D inTex; +layout(rgba16i, binding = 1) writeonly uniform iimage2D outTex; + +layout(std140, binding = 2) uniform DemosaicPass0cParams_UBO { + int uParams_l; + int uParams_t; + int uParams_r; + int uParams_b; +}; + +ivec4 sobelFlt(ivec2 pos) { + ivec4 v1 = ivec4(imageLoad(inTex, pos + ivec2(-1, -1))); + ivec4 v2 = ivec4(imageLoad(inTex, pos + ivec2(-1, 1))); + ivec4 v3 = ivec4(imageLoad(inTex, pos + ivec2( 0, 1))); + ivec4 v4 = ivec4(imageLoad(inTex, pos + ivec2( 1, 1))); + ivec4 v5 = ivec4(imageLoad(inTex, pos + ivec2( 0, 0))); + ivec4 v6 = ivec4(imageLoad(inTex, pos + ivec2( 0, -1))); + ivec4 v7 = ivec4(imageLoad(inTex, pos + ivec2( 1, -1))); + + ivec4 sum; + sum.r = -v1.a - v2.a - v3.g + 4 * v5.r - v6.g; + sum.g = -v3.r - v3.b + 4 * v5.g - v6.r - v6.b; + sum.b = -v3.g - v3.a + 4 * v5.b - v6.g - v6.a; + sum.a = -v3.b - v4.r + 4 * v5.a - v6.b - v7.r; + + return clamp(sum >> 3, ivec4(-32768), ivec4(32767)); +} + +ivec4 sobelLR(ivec2 pos, bool skipL, bool skipR) { + ivec4 sum = ivec4(0); + + if (!skipL) { + ivec4 v1 = ivec4(imageLoad(inTex, pos + ivec2(-1, -1))); + ivec4 v2 = ivec4(imageLoad(inTex, pos + ivec2(-1, 1))); + sum.r -= v1.a + v2.a; + } + + ivec4 v3 = ivec4(imageLoad(inTex, pos + ivec2(0, 1))); + sum.r -= v3.g; + sum.g = -v3.r - v3.b; + sum.b = -v3.g - v3.a; + sum.a = -v3.b; + + ivec4 v4 = ivec4(imageLoad(inTex, pos)); + sum += 4 * v4; + + ivec4 v5 = ivec4(imageLoad(inTex, pos + ivec2(0, -1))); + sum.r -= v5.g; + sum.g -= v5.r + v5.b; + sum.b -= v5.g + v5.a; + sum.a -= v5.b; + + if (!skipR) { + ivec4 v6 = ivec4(imageLoad(inTex, pos + ivec2(1, -1))); + ivec4 v7 = ivec4(imageLoad(inTex, pos + ivec2(1, 1))); + sum.a -= v6.r + v7.r; + } + if (skipR) + sum.a = 0; + if (skipL) + sum.r = 0; + + return clamp(sum >> 3, ivec4(-32768), ivec4(32767)); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + + ivec4 result = ivec4(0); + + bool inV = (gid.y >= uParams_t && gid.y < uParams_b); + bool inH = (gid.x > uParams_l && gid.x < uParams_r); + bool onL = (gid.x == uParams_l && gid.y >= uParams_t && gid.y < uParams_b); + bool onR = (gid.x == uParams_r && gid.y >= uParams_t && gid.y < uParams_b); + + if (inH && inV) { + result = sobelFlt(gid); + } else if (onL && gid.x < uParams_r) { + result = sobelLR(gid, true, false); + } else if (onR && gid.x > uParams_l) { + result = sobelLR(gid, false, true); + } + + imageStore(outTex, gid, result); +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_pass_1_0x3097f8e.comp b/research/phocus_glsl/02_demosaic/demosaic_pass_1_0x3097f8e.comp new file mode 100644 index 00000000..2caa2203 --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_pass_1_0x3097f8e.comp @@ -0,0 +1,395 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 16b1675cddccc6ef185afa37b2b9d4f5af38b3c64e51ec7b0854b474c678221a + * ELF offsets: 0x3097f8e + * Symbols: demosaic_pass_1_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp image2D; +precision highp uimage2D; +precision highp iimage2D; + +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D uInputTexture0; +layout(rgba16i, binding = 1) readonly uniform iimage2D uInputTexture1; +layout(rgba16f, binding = 2) readonly uniform image2D uInputTexture2; +layout(rgba16f, binding = 3) readonly uniform image2D uInputTexture3; +layout(rgba16ui, binding = 4) writeonly uniform uimage2D uOutputTexture; + +layout(std140, binding = 5) uniform DemosaicPass1Params_UBO { + int ubo_uParams_l; + int ubo_uParams_t; + int ubo_uParams_r; + int ubo_uParams_b; + int ubo_uParams_minThresholdEdge; + int ubo_uParams_minThresholdVNG; + int ubo_uParams_pad0; + int ubo_uParams_pad1; +}; + +#define texelFetch(tex, coord, lod) imageLoad(tex, coord) + +void shiftInts(out vec4 out_vec4, out float out_val, vec4 a, vec4 b, int offset) { + if (offset == 0) { + out_vec4 = vec4(a.x, a.y, a.z, a.w); + out_val = b.x; + } else if (offset == 1) { + out_vec4 = vec4(a.y, a.z, a.w, b.x); + out_val = b.y; + } else if (offset == 2) { + out_vec4 = vec4(a.z, a.w, b.x, b.y); + out_val = b.z; + } else { + out_vec4 = vec4(a.w, b.x, b.y, b.z); + out_val = b.w; + } +} + +void gradientSingleStep(out vec4 edgGrad0, out vec4 edgGrad1, ivec2 imgPos) { + int offset = (imgPos.x - 2) & 3; + int x = (imgPos.x - 2) / 4; + int y = imgPos.y; + + vec4 edg_2_v4, edg_1_v4, edg0_v4, edg1_v4, edg2_v4; + float edg_2_f, edg_1_f, edg0_f, edg1_f, edg2_f; + + vec4 a = vec4(texelFetch(uInputTexture1, ivec2(x, y-2), 0)); + vec4 b = vec4(texelFetch(uInputTexture1, ivec2(x+1, y-2), 0)); + shiftInts(edg_2_v4, edg_2_f, a, b, offset); + + a = vec4(texelFetch(uInputTexture1, ivec2(x, y-1), 0)); + b = vec4(texelFetch(uInputTexture1, ivec2(x+1, y-1), 0)); + shiftInts(edg_1_v4, edg_1_f, a, b, offset); + + a = vec4(texelFetch(uInputTexture1, ivec2(x, y), 0)); + b = vec4(texelFetch(uInputTexture1, ivec2(x+1, y), 0)); + shiftInts(edg0_v4, edg0_f, a, b, offset); + + a = vec4(texelFetch(uInputTexture1, ivec2(x, y+1), 0)); + b = vec4(texelFetch(uInputTexture1, ivec2(x+1, y+1), 0)); + shiftInts(edg1_v4, edg1_f, a, b, offset); + + a = vec4(texelFetch(uInputTexture1, ivec2(x, y+2), 0)); + b = vec4(texelFetch(uInputTexture1, ivec2(x+1, y+2), 0)); + shiftInts(edg2_v4, edg2_f, a, b, offset); + + float hGrad = abs(edg0_v4.y - edg0_v4.z) + abs(edg0_v4.z - edg0_v4.w) + + (abs(edg_1_v4.y - edg_1_v4.z) + abs(edg_1_v4.z - edg_1_v4.w) + + abs(edg1_v4.y - edg1_v4.z) + abs(edg1_v4.z - edg1_v4.w)) * 0.5; + + float vGrad = abs(edg_1_v4.z - edg0_v4.z) + abs(edg0_v4.z - edg1_v4.z) + + (abs(edg_1_v4.y - edg0_v4.y) + abs(edg0_v4.y - edg1_v4.y) + + abs(edg_1_v4.w - edg0_v4.w) + abs(edg0_v4.w - edg1_v4.w)) * 0.5; + + edgGrad0.x = (vGrad + abs(edg_2_v4.z - edg_1_v4.z) + (abs(edg_2_v4.y - edg_1_v4.y) + abs(edg_2_v4.w - edg_1_v4.w)) * 0.5) * 0.25; + edgGrad0.z = (vGrad + abs(edg2_v4.z - edg1_v4.z) + (abs(edg2_v4.y - edg1_v4.y) + abs(edg2_v4.w - edg1_v4.w)) * 0.5) * 0.25; + edgGrad0.w = (hGrad + abs(edg0_v4.x - edg0_v4.y) + (abs(edg_1_v4.x - edg_1_v4.y) + abs(edg1_v4.x - edg1_v4.y)) * 0.5) * 0.25; + edgGrad0.y = (hGrad + abs(edg0_f - edg0_v4.w) + (abs(edg_1_f - edg_1_v4.w) + abs(edg1_f - edg1_v4.w)) * 0.5) * 0.25; + + float senwGrad = abs(edg_1_v4.y - edg0_v4.z) + abs(edg0_v4.z - edg1_v4.w) + abs(edg_1_v4.z - edg0_v4.w) + abs(edg0_v4.y - edg1_v4.z); + float neswGrad = abs(edg_1_v4.w - edg0_v4.z) + abs(edg0_v4.z - edg1_v4.y) + abs(edg0_v4.y - edg_1_v4.z) + abs(edg0_v4.w - edg1_v4.z); + + edgGrad1.w = (senwGrad + abs(edg_1_v4.y - edg_2_v4.x) + (abs(edg_1_v4.z - edg_2_v4.y) + abs(edg0_v4.y - edg_1_v4.x)) * 0.5) * 0.25; + edgGrad1.z = (neswGrad + abs(edg1_v4.y - edg2_v4.x) + (abs(edg0_v4.y - edg1_v4.x) + abs(edg1_v4.z - edg2_v4.y)) * 0.5) * 0.25; + edgGrad1.y = (senwGrad + abs(edg1_v4.w - edg2_f) + (abs(edg0_v4.w - edg1_f) + abs(edg1_v4.z - edg2_v4.w)) * 0.5) * 0.25; + edgGrad1.x = (neswGrad + abs(edg_1_v4.w - edg_2_f) + (abs(edg_1_v4.z - edg_2_v4.w) + abs(edg0_v4.w - edg_1_f)) * 0.5) * 0.25; +} + +void gradientVNG_RB(out vec4 bayGrad0, out vec4 bayGrad1, ivec2 imgPos) { + int offset = (imgPos.x - 2) & 3; + int x = (imgPos.x - 2) / 4; + int y = imgPos.y; + + vec4 bayer_2_v4, bayer_1_v4, bayer0_v4, bayer1_v4, bayer2_v4; + float bayer_2_f, bayer_1_f, bayer0_f, bayer1_f, bayer2_f; + + vec4 a = vec4(texelFetch(uInputTexture0, ivec2(x, y-2), 0)); + vec4 b = vec4(texelFetch(uInputTexture0, ivec2(x+1, y-2), 0)); + shiftInts(bayer_2_v4, bayer_2_f, a, b, offset); + + a = vec4(texelFetch(uInputTexture0, ivec2(x, y-1), 0)); + b = vec4(texelFetch(uInputTexture0, ivec2(x+1, y-1), 0)); + shiftInts(bayer_1_v4, bayer_1_f, a, b, offset); + + a = vec4(texelFetch(uInputTexture0, ivec2(x, y), 0)); + b = vec4(texelFetch(uInputTexture0, ivec2(x+1, y), 0)); + shiftInts(bayer0_v4, bayer0_f, a, b, offset); + + a = vec4(texelFetch(uInputTexture0, ivec2(x, y+1), 0)); + b = vec4(texelFetch(uInputTexture0, ivec2(x+1, y+1), 0)); + shiftInts(bayer1_v4, bayer1_f, a, b, offset); + + a = vec4(texelFetch(uInputTexture0, ivec2(x, y+2), 0)); + b = vec4(texelFetch(uInputTexture0, ivec2(x+1, y+2), 0)); + shiftInts(bayer2_v4, bayer2_f, a, b, offset); + + float vGrad = abs(bayer_1_v4.z - bayer1_v4.z) + (abs(bayer_1_v4.y - bayer1_v4.y) + abs(bayer_1_v4.w - bayer1_v4.w))*0.5; + float hGrad = abs(bayer0_v4.w - bayer0_v4.y) + (abs(bayer_1_v4.w - bayer_1_v4.y) + abs(bayer1_v4.w - bayer1_v4.y))*0.5; + + bayGrad0.x = (vGrad + abs(bayer_2_v4.z - bayer0_v4.z) + (abs(bayer_2_v4.y - bayer0_v4.y) + abs(bayer_2_v4.w - bayer0_v4.w))*0.5) / 8.0; + bayGrad0.z = (vGrad + abs(bayer2_v4.z - bayer0_v4.z) + (abs(bayer2_v4.y - bayer0_v4.y) + abs(bayer2_v4.w - bayer0_v4.w))*0.5) / 8.0; + bayGrad0.w = (hGrad + abs(bayer0_v4.x - bayer0_v4.z) + (abs(bayer_1_v4.x - bayer_1_v4.z) + abs(bayer1_v4.x - bayer1_v4.z))*0.5) / 8.0; + bayGrad0.y = (hGrad + abs(bayer0_f - bayer0_v4.z) + (abs(bayer_1_f - bayer_1_v4.z) + abs(bayer1_f - bayer1_v4.z))*0.5) / 8.0; + + float neswGrad = abs(bayer_1_v4.w - bayer1_v4.y) + abs(bayer0_v4.y - bayer_1_v4.z) + abs(bayer0_v4.w - bayer1_v4.z); + float senwGrad = abs(bayer1_v4.w - bayer_1_v4.y) + abs(bayer_1_v4.z - bayer0_v4.w) + abs(bayer0_v4.y - bayer1_v4.z); + + bayGrad1.x = (neswGrad + abs(bayer_2_f - bayer0_v4.z) + abs(bayer_2_v4.w - bayer_1_v4.z) + abs(bayer_1_f - bayer0_v4.w)) / 8.0; + bayGrad1.z = (neswGrad + abs(bayer2_v4.x - bayer0_v4.z) + abs(bayer1_v4.x - bayer0_v4.y) + abs(bayer2_v4.y - bayer1_v4.z)) / 8.0; + bayGrad1.y = (senwGrad + abs(bayer2_f - bayer0_v4.z) + abs(bayer1_f - bayer0_v4.w) + abs(bayer2_v4.w - bayer1_v4.z)) / 8.0; + bayGrad1.w = (senwGrad + abs(bayer_2_v4.x - bayer0_v4.z) + abs(bayer_2_v4.y - bayer_1_v4.z) + abs(bayer_1_v4.x - bayer0_v4.y)) / 8.0; +} + + +uvec4 greenAtRedBlue(ivec2 pos, int offsetBayer, int rbIndex) { + vec4 edgGrad0, edgGrad1, bayGrad0, bayGrad1; + gradientSingleStep(edgGrad0, edgGrad1, pos); + gradientVNG_RB(bayGrad0, bayGrad1, pos); + + float minGradient = edgGrad0.x; + int minGradientIndex = 0; + if (edgGrad0.y < minGradient) { minGradient = edgGrad0.y; minGradientIndex = 1; } + if (edgGrad0.z < minGradient) { minGradient = edgGrad0.z; minGradientIndex = 2; } + if (edgGrad0.w < minGradient) { minGradient = edgGrad0.w; minGradientIndex = 3; } + if (edgGrad1.x < minGradient) { minGradient = edgGrad1.x; minGradientIndex = 4; } + if (edgGrad1.y < minGradient) { minGradient = edgGrad1.y; minGradientIndex = 5; } + if (edgGrad1.z < minGradient) { minGradient = edgGrad1.z; minGradientIndex = 6; } + if (edgGrad1.w < minGradient) { minGradient = edgGrad1.w; minGradientIndex = 7; } + + float maxG = max(max(edgGrad0.x, edgGrad0.y), max(edgGrad0.z, edgGrad0.w)); + maxG = max(maxG, max(max(edgGrad1.x, edgGrad1.y), max(edgGrad1.z, edgGrad1.w))); + + float dif = (maxG - minGradient) / 8.0; + float dif1 = (maxG - minGradient) / 32.0; + dif = dif - dif1; + float threshold = 1.5 * minGradient + dif + 8.0; + threshold = max(threshold, float(ubo_uParams_minThresholdEdge)); + + float maxGVNG = max(max(bayGrad0.x, bayGrad0.y), max(bayGrad0.z, bayGrad0.w)); + maxGVNG = max(maxGVNG, max(max(bayGrad1.x, bayGrad1.y), max(bayGrad1.z, bayGrad1.w))); + float minGVNG = min(min(bayGrad0.x, bayGrad0.y), min(bayGrad0.z, bayGrad0.w)); + minGVNG = min(minGVNG, min(min(bayGrad1.x, bayGrad1.y), min(bayGrad1.z, bayGrad1.w))); + maxGVNG *= 0.5; + minGVNG *= 0.5; + dif = maxGVNG - minGVNG; + float thresholdVNG = 3.0 * minGVNG + dif + 8.0; + thresholdVNG = max(thresholdVNG, float(ubo_uParams_minThresholdVNG)); + + int offset = (pos.x - 2) & 3; + int x = (pos.x - 2) / 4; + int y = pos.y; + + vec4 bayer_1_v4, bayer0_v4, bayer1_v4; + float bayer_1_f, bayer0_f, bayer1_f; + + vec4 a = vec4(texelFetch(uInputTexture0, ivec2(x, y-1), 0)); + vec4 b = vec4(texelFetch(uInputTexture0, ivec2(x+1, y-1), 0)); + shiftInts(bayer_1_v4, bayer_1_f, a, b, offset); + + a = vec4(texelFetch(uInputTexture0, ivec2(x, y), 0)); + b = vec4(texelFetch(uInputTexture0, ivec2(x+1, y), 0)); + shiftInts(bayer0_v4, bayer0_f, a, b, offset); + + a = vec4(texelFetch(uInputTexture0, ivec2(x, y+1), 0)); + b = vec4(texelFetch(uInputTexture0, ivec2(x+1, y+1), 0)); + shiftInts(bayer1_v4, bayer1_f, a, b, offset); + + vec4 medianY_2_v4, medianY_1_v4, medianY0_v4, medianY1_v4, medianY2_v4; + float medianY_2_f, medianY_1_f, medianY0_f, medianY1_f, medianY2_f; + + a = texelFetch(uInputTexture3, ivec2(x, (y-2)/2), 0); + b = texelFetch(uInputTexture3, ivec2(x+1, (y-2)/2), 0); + shiftInts(medianY_2_v4, medianY_2_f, a, b, offset); + + a = texelFetch(uInputTexture3, ivec2(x, y/2), 0); + b = texelFetch(uInputTexture3, ivec2(x+1, y/2), 0); + shiftInts(medianY0_v4, medianY0_f, a, b, offset); + + a = texelFetch(uInputTexture3, ivec2(x, (y+2)/2), 0); + b = texelFetch(uInputTexture3, ivec2(x+1, (y+2)/2), 0); + shiftInts(medianY2_v4, medianY2_f, a, b, offset); + + if (offsetBayer == 1) { + medianY_1_v4 = medianY0_v4; + medianY_1_f = medianY0_f; + medianY1_v4 = medianY2_v4; + medianY1_f = medianY2_f; + } else { + medianY_1_v4 = medianY_2_v4; + medianY_1_f = medianY_2_f; + medianY1_v4 = medianY0_v4; + medianY1_f = medianY0_f; + } + + float target = bayer0_v4.z; + float greenTest[8]; + + greenTest[0] = texelFetch(uInputTexture2, ivec2(pos.x, (pos.y - 1) / 2), 0).g * target; + greenTest[1] = texelFetch(uInputTexture2, ivec2(pos.x + 1, pos.y / 2), 0).r * target; + greenTest[2] = texelFetch(uInputTexture2, ivec2(pos.x, (pos.y + 1) / 2), 0).g * target; + greenTest[3] = texelFetch(uInputTexture2, ivec2(pos.x - 1, pos.y / 2), 0).r * target; + { + float scaleA = medianY2_f; + float scaleB = medianY_2_v4.x; + float scaleMax = max(1.0, max(scaleA, scaleB)); + float scaleMin = min(1.0, min(scaleA, scaleB)); + + float medScale = medianY0_v4.z; + float scaleC = clamp(medScale, scaleMin, scaleMax); + + float sum = (bayer_1_v4.w + bayer1_v4.y) * 0.5; + float minDif = min(abs(sum - bayer1_v4.w), abs(sum - bayer_1_v4.y)); + if (minDif < sum / 4.0) scaleC = medScale; + float greenC = scaleC * target; + + scaleA = medianY1_v4.w; + scaleB = medianY_1_v4.y; + scaleMax = max(1.0, max(scaleA, scaleB)); + scaleMin = min(1.0, min(scaleA, scaleB)); + + greenTest[4] = (greenC + bayer_1_v4.w * clamp(medianY_1_v4.w, scaleMin, scaleMax)) * 0.5; // NorthEast + greenTest[6] = (greenC + bayer1_v4.y * clamp(medianY1_v4.y, scaleMin, scaleMax)) * 0.5; // SouthWest + + scaleA = medianY_2_f; + scaleB = medianY2_v4.x; + scaleMax = max(1.0, max(scaleA, scaleB)); + scaleMin = min(1.0, min(scaleA, scaleB)); + + scaleC = clamp(medScale, scaleMin, scaleMax); + + sum = (bayer_1_v4.y + bayer1_v4.w)*0.5; + minDif = min(abs(sum - bayer_1_v4.w), abs(sum - bayer1_v4.y)); + if (minDif < sum / 4.0) scaleC = medScale; + greenC = scaleC * target; + + scaleA = medianY_1_v4.w; + scaleB = medianY1_v4.y; + scaleMax = max(1.0, max(scaleA, scaleB)); + scaleMin = min(1.0, min(scaleA, scaleB)); + + greenTest[5] = (greenC + bayer1_v4.w * clamp(medianY1_v4.w, scaleMin, scaleMax)) * 0.5; + greenTest[7] = (greenC + bayer_1_v4.y * clamp(medianY_1_v4.y, scaleMin, scaleMax)) * 0.5; + } + + int mask = 0; + float maxGreen = 0.0; + float minGreen = 65535.0; + float maxUsedGradient = 0.0; + + if (threshold > edgGrad0.x && thresholdVNG > bayGrad0.x) { maxUsedGradient = max(edgGrad0.x, maxUsedGradient); maxGreen = max(maxGreen, greenTest[0]); minGreen = min(minGreen, greenTest[0]); mask |= (1 << 0); } + if (threshold > edgGrad0.y && thresholdVNG > bayGrad0.y) { maxUsedGradient = max(edgGrad0.y, maxUsedGradient); maxGreen = max(maxGreen, greenTest[1]); minGreen = min(minGreen, greenTest[1]); mask |= (1 << 1); } + if (threshold > edgGrad0.z && thresholdVNG > bayGrad0.z) { maxUsedGradient = max(edgGrad0.z, maxUsedGradient); maxGreen = max(maxGreen, greenTest[2]); minGreen = min(minGreen, greenTest[2]); mask |= (1 << 2); } + if (threshold > edgGrad0.w && thresholdVNG > bayGrad0.w) { maxUsedGradient = max(edgGrad0.w, maxUsedGradient); maxGreen = max(maxGreen, greenTest[3]); minGreen = min(minGreen, greenTest[3]); mask |= (1 << 3); } + if (threshold > edgGrad1.x && thresholdVNG > bayGrad1.x) { maxUsedGradient = max(edgGrad1.x, maxUsedGradient); maxGreen = max(maxGreen, greenTest[4]); minGreen = min(minGreen, greenTest[4]); mask |= (1 << 4); } + if (threshold > edgGrad1.y && thresholdVNG > bayGrad1.y) { maxUsedGradient = max(edgGrad1.y, maxUsedGradient); maxGreen = max(maxGreen, greenTest[5]); minGreen = min(minGreen, greenTest[5]); mask |= (1 << 5); } + if (threshold > edgGrad1.z && thresholdVNG > bayGrad1.z) { maxUsedGradient = max(edgGrad1.z, maxUsedGradient); maxGreen = max(maxGreen, greenTest[6]); minGreen = min(minGreen, greenTest[6]); mask |= (1 << 6); } + if (threshold > edgGrad1.w && thresholdVNG > bayGrad1.w) { maxUsedGradient = max(edgGrad1.w, maxUsedGradient); maxGreen = max(maxGreen, greenTest[7]); minGreen = min(minGreen, greenTest[7]); mask |= (1 << 7); } + + bool bDitch = false; + float lGreen = 0.0; + int count = 0; + for (int i = 0; i < 32; i++) { + if ((mask & (1 << i)) != 0) count++; + } + + if (minGradientIndex < 4 && 2 < count && count < 6 && + maxUsedGradient < 2.0 * minGradient && (mask & 15) == 15) { + lGreen = (greenTest[0] + greenTest[1] + greenTest[2] + greenTest[3]) / 4.0; + float sign0 = lGreen - greenTest[0]; + float sign1 = lGreen - greenTest[1]; + float sign2 = lGreen - greenTest[2]; + float sign3 = lGreen - greenTest[3]; + bDitch = (sign0 * sign2 >= 0.0 && sign1 * sign3 >= 0.0); + } + + float minDif2 = 65535.0; + if (bDitch) { + const float kScaleThreshold = 1.3; + const float kScaleDifThreshold = (kScaleThreshold - (1.0 / kScaleThreshold)) / + (kScaleThreshold + (1.0 / kScaleThreshold)); + bDitch = ((maxGreen - minGreen) > kScaleDifThreshold * (maxGreen + minGreen)); + + if (bDitch) { + int minDifIndex = 0; + for (int i = 0; i < 4; i++) { + if ((mask & (1 << i)) != 0) { + float difLoc = abs(greenTest[i] - target); + if (difLoc < minDif2) { + minDif2 = difLoc; + minDifIndex = i; + } + } + } + lGreen = greenTest[minDifIndex]; + if (minDif2 > 0.0) { + mask = 1 << minDifIndex; + count = 1; + } + } + } + + if (minDif2 == 65535.0) { + if (count > 0) { + float sum2 = 0.0; + for (int i = 0; i < 8; i++) { + if ((mask & (1 << i)) != 0) sum2 += greenTest[i]; + } + lGreen = clamp(sum2 / float(count), 0.0, 65534.0); + } else { + lGreen = (bayer0_v4.w + bayer0_v4.y + bayer1_v4.z + bayer_1_v4.z) * 0.25; + } + } + + uvec4 result; + result.g = uint(clamp(min(lGreen, 65534.0), 0.0, 65534.0)); + result[rbIndex] = uint(clamp(target, 0.0, 65535.0)); + result[2 - rbIndex] = 0u; + uint encodedValue; + if (mask == 0) { + encodedValue = uint(0xFF | (8 << 8)); + } else + { + count = 0; + for (int i = 0; i < 32; i++) { + if ((mask & (1 << i)) != 0) count++; + } + encodedValue = uint(mask | (count << 8)); + } + result.a = encodedValue; + return result; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + + int x = gid.x & 1; + int y = gid.y & 1; + int bayerIndex = x + y * 2; + + uvec4 result = uvec4(0u); + + if (bayerIndex == 0) { + result = greenAtRedBlue(gid, 0, 0); + } else if (bayerIndex == 1) { + int bayX = gid.x / 4; + int bayChannel = gid.x & 3; + uvec4 bayPixel = texelFetch(uInputTexture0, ivec2(bayX, gid.y), 0); + result = uvec4(0u, bayPixel[bayChannel], 0u, 0u); + } else if (bayerIndex == 2) { + int bayX = gid.x / 4; + int bayChannel = gid.x & 3; + uvec4 bayPixel = texelFetch(uInputTexture0, ivec2(bayX, gid.y), 0); + result = uvec4(0u, bayPixel[bayChannel], 0u, 0u); + } else { + result = greenAtRedBlue(gid, 1, 2); + } + + if (gid.x >= ubo_uParams_l && gid.x < ubo_uParams_r && + gid.y >= ubo_uParams_t && gid.y < ubo_uParams_b) { + imageStore(uOutputTexture, gid, result); + } +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_pass_2_0x30a5753.comp b/research/phocus_glsl/02_demosaic/demosaic_pass_2_0x30a5753.comp new file mode 100644 index 00000000..5e1927c9 --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_pass_2_0x30a5753.comp @@ -0,0 +1,120 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: f6a0ccf9154f8a51129f18a76bfbc63bcb960c646805b2511dbe5ec8c0e90f3d + * ELF offsets: 0x30a5753 + * Symbols: demosaic_pass_2_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; + +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D inTex; +layout(rgba16ui, binding = 1) writeonly uniform uimage2D outTex; + +layout(std140, binding = 2) uniform DemosaicPass2Params_UBO { + int uParams_l; + int uParams_t; + int uParams_r; + int uParams_b; +}; + +uvec4 oppositeColor(ivec2 pos, int rbIndex) { + uvec4 rgbd = imageLoad(inTex, pos); + + uvec4 inNN = imageLoad(inTex, pos + ivec2(-1, -1)); + uvec4 inPN = imageLoad(inTex, pos + ivec2(1, -1)); + uvec4 inNP = imageLoad(inTex, pos + ivec2(-1, 1)); + uvec4 inPP = imageLoad(inTex, pos + ivec2(1, 1)); + + if (rgbd.w != 0u) { + vec4 g4 = vec4(float(inNN.g), float(inPN.g), float(inNP.g), float(inPP.g)); + vec4 rb4 = vec4(float(inNN[rbIndex]), float(inPN[rbIndex]), float(inNP[rbIndex]), float(inPP[rbIndex])); + float gc = float(rgbd.g); + vec4 dif4 = vec4(1.0) + abs(vec4(gc) - g4) / 4.0; + + vec4 g1 = g4.yyzz * dif4.xwwx + g4.xwwx * dif4.yyzz; + vec4 rb1 = rb4.yyzz * dif4.xwwx + rb4.xwwx * dif4.yyzz; + int rgbdW = int(rgbd.w); + bvec4 g1NonZero = notEqual(g1, vec4(0.0)); + bvec4 mask1 = bvec4( + (rgbdW & (1 << 0)) != 0, + (rgbdW & (1 << 1)) != 0, + (rgbdW & (1 << 2)) != 0, + (rgbdW & (1 << 3)) != 0 + ); + vec4 b1 = vec4( + g1NonZero.x && mask1.x ? 1.0 : 0.0, + g1NonZero.y && mask1.y ? 1.0 : 0.0, + g1NonZero.z && mask1.z ? 1.0 : 0.0, + g1NonZero.w && mask1.w ? 1.0 : 0.0 + ); + // NaN guard: Metal's select(0, gc*rb1/g1, b1) discards the unpicked operand, so + // g1==0 (→ Inf) is harmless there. GLSL float-mix computes 0*(1-b1)+(Inf)*b1, and + // where b1==0 this is Inf*0 = NaN, which contaminates the bc sum and zeroes R + // (severe in low-green regions like red neon). Guard the denominator to stay finite. + vec4 g1safe = mix(vec4(1.0), g1, b1); + vec4 bc1 = mix(vec4(0.0), gc * rb1 / g1safe, b1); + vec4 c1 = mix(vec4(0.0), vec4(1.0), b1); + + vec4 g2 = g4.ywyw * dif4.zxzx + g4.zxzx * dif4.ywyw; + vec4 rb2 = rb4.ywyw * dif4.zxzx + rb4.zxzx * dif4.ywyw; + bvec4 g2NonZero = notEqual(g2, vec4(0.0)); + bvec4 mask2 = bvec4( + (rgbdW & (1 << 4)) != 0, + (rgbdW & (1 << 5)) != 0, + (rgbdW & (1 << 6)) != 0, + (rgbdW & (1 << 7)) != 0 + ); + + vec4 b2 = vec4( + (g2NonZero.x && mask2.x) ? 1.0 : 0.0, + (g2NonZero.y && mask2.y) ? 1.0 : 0.0, + (g2NonZero.z && mask2.z) ? 1.0 : 0.0, + (g2NonZero.w && mask2.w) ? 1.0 : 0.0 + ); + + vec4 g2safe = mix(vec4(1.0), g2, b2); // NaN guard, see g1safe above + vec4 bc2 = mix(vec4(0.0), gc * rb2 / g2safe, b2); + vec4 c2 = mix(vec4(0.0), vec4(1.0), b2); + + float count = c1.x + c1.y + c1.z + c1.w + c2.x + c2.y + c2.z + c2.w; + float bc = bc1.x + bc1.y + bc1.z + bc1.w + bc2.x + bc2.y + bc2.z + bc2.w; + + if (count > 0.0) { + bc /= count; + } else { + bc = (rb4.x + rb4.y + rb4.z + rb4.w) / 4.0; + } + + rgbd[rbIndex] = uint(clamp(bc, 0.0, 65534.0)); + } else { + rgbd[rbIndex] = 0u; + } + + return rgbd; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + + uvec4 outV; + if (gid.x < uParams_l || gid.x+1 >= uParams_r || + gid.y < uParams_t || gid.y+1 >= uParams_b) { + outV = uvec4(0u); + } else { + int x = gid.x & 1; + int y = gid.y & 1; + if (x == 0 && y == 0) { + outV = oppositeColor(gid, 2); + } else if (x == 1 && y == 1) { + outV = oppositeColor(gid, 0); + } else { + outV = imageLoad(inTex, gid); + } + } + imageStore(outTex, gid, outV); +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_pass_3_0x30466e2.comp b/research/phocus_glsl/02_demosaic/demosaic_pass_3_0x30466e2.comp new file mode 100644 index 00000000..eee4c1b2 --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_pass_3_0x30466e2.comp @@ -0,0 +1,343 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: f5810f8bf53819324502a8696d7d0bdb94238280be29b7f72139e9701e276111 + * ELF offsets: 0x30466e2 + * Symbols: demosaic_pass_3_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; +precision highp iimage2D; + +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D rgbdTex; +layout(rgba16ui, binding = 1) readonly uniform uimage2D bayerTex; +layout(rgba16i, binding = 2) readonly uniform iimage2D edgeTex; +layout(rgba16ui, binding = 3) writeonly uniform uimage2D outTex; + +layout(std140, binding = 4) uniform DemosaicPass3Params_UBO { + int ubo_uParams_l; + int ubo_uParams_t; + int ubo_uParams_r; + int ubo_uParams_b; + int ubo_uParams_minThresholdEdge; + int ubo_uParams_minThresholdVNG; + int ubo_uParams_pad0; + int ubo_uParams_pad1; +}; + +void shiftInts(out vec4 out_vec4, out float out_val, vec4 a, vec4 b, int offset) { + if (offset == 0) { + out_vec4 = vec4(a.x, a.y, a.z, a.w); + out_val = b.x; + } else if (offset == 1) { + out_vec4 = vec4(a.y, a.z, a.w, b.x); + out_val = b.y; + } else if (offset == 2) { + out_vec4 = vec4(a.z, a.w, b.x, b.y); + out_val = b.z; + } else { + out_vec4 = vec4(a.w, b.x, b.y, b.z); + out_val = b.w; + } +} + +void gradientSingleStep(out vec4 edgGrad0, out vec4 edgGrad1, ivec2 imgPos) { + int offset = (imgPos.x - 2) & 3; + int x = (imgPos.x - 2) / 4; + int y = imgPos.y; + + vec4 edg_2_v4, edg_1_v4, edg0_v4, edg1_v4, edg2_v4; + float edg_2_f, edg_1_f, edg0_f, edg1_f, edg2_f; + + vec4 a = vec4(imageLoad(edgeTex, ivec2(x, y-2))); + vec4 b = vec4(imageLoad(edgeTex, ivec2(x+1, y-2))); + shiftInts(edg_2_v4, edg_2_f, a, b, offset); + + a = vec4(imageLoad(edgeTex, ivec2(x, y-1))); + b = vec4(imageLoad(edgeTex, ivec2(x+1, y-1))); + shiftInts(edg_1_v4, edg_1_f, a, b, offset); + + a = vec4(imageLoad(edgeTex, ivec2(x, y))); + b = vec4(imageLoad(edgeTex, ivec2(x+1, y))); + shiftInts(edg0_v4, edg0_f, a, b, offset); + + a = vec4(imageLoad(edgeTex, ivec2(x, y+1))); + b = vec4(imageLoad(edgeTex, ivec2(x+1, y+1))); + shiftInts(edg1_v4, edg1_f, a, b, offset); + + a = vec4(imageLoad(edgeTex, ivec2(x, y+2))); + b = vec4(imageLoad(edgeTex, ivec2(x+1, y+2))); + shiftInts(edg2_v4, edg2_f, a, b, offset); + + float hGrad = abs(edg0_v4.y - edg0_v4.z) + abs(edg0_v4.z - edg0_v4.w) + + (abs(edg_1_v4.y - edg_1_v4.z) + abs(edg_1_v4.z - edg_1_v4.w) + + abs(edg1_v4.y - edg1_v4.z) + abs(edg1_v4.z - edg1_v4.w)) * 0.5; + + float vGrad = abs(edg_1_v4.z - edg0_v4.z) + abs(edg0_v4.z - edg1_v4.z) + + (abs(edg_1_v4.y - edg0_v4.y) + abs(edg0_v4.y - edg1_v4.y) + + abs(edg_1_v4.w - edg0_v4.w) + abs(edg0_v4.w - edg1_v4.w)) * 0.5; + + edgGrad0.x = (vGrad + abs(edg_2_v4.z - edg_1_v4.z) + (abs(edg_2_v4.y - edg_1_v4.y) + abs(edg_2_v4.w - edg_1_v4.w)) * 0.5) * 0.25; + edgGrad0.z = (vGrad + abs(edg2_v4.z - edg1_v4.z) + (abs(edg2_v4.y - edg1_v4.y) + abs(edg2_v4.w - edg1_v4.w)) * 0.5) * 0.25; + edgGrad0.w = (hGrad + abs(edg0_v4.x - edg0_v4.y) + (abs(edg_1_v4.x - edg_1_v4.y) + abs(edg1_v4.x - edg1_v4.y)) * 0.5) * 0.25; + edgGrad0.y = (hGrad + abs(edg0_f - edg0_v4.w) + (abs(edg_1_f - edg_1_v4.w) + abs(edg1_f - edg1_v4.w)) * 0.5) * 0.25; + + float senwGrad = abs(edg_1_v4.y - edg0_v4.z) + abs(edg0_v4.z - edg1_v4.w) + abs(edg_1_v4.z - edg0_v4.w) + abs(edg0_v4.y - edg1_v4.z); + float neswGrad = abs(edg_1_v4.w - edg0_v4.z) + abs(edg0_v4.z - edg1_v4.y) + abs(edg0_v4.y - edg_1_v4.z) + abs(edg0_v4.w - edg1_v4.z); + + edgGrad1.w = (senwGrad + abs(edg_1_v4.y - edg_2_v4.x) + (abs(edg_1_v4.z - edg_2_v4.y) + abs(edg0_v4.y - edg_1_v4.x)) * 0.5) * 0.25; + edgGrad1.z = (neswGrad + abs(edg1_v4.y - edg2_v4.x) + (abs(edg0_v4.y - edg1_v4.x) + abs(edg1_v4.z - edg2_v4.y)) * 0.5) * 0.25; + edgGrad1.y = (senwGrad + abs(edg1_v4.w - edg2_f) + (abs(edg0_v4.w - edg1_f) + abs(edg1_v4.z - edg2_v4.w)) * 0.5) * 0.25; + edgGrad1.x = (neswGrad + abs(edg_1_v4.w - edg_2_f) + (abs(edg_1_v4.z - edg_2_v4.w) + abs(edg0_v4.w - edg_1_f)) * 0.5) * 0.25; +} + +void gradientVNG_G(out vec4 bayGrad0, out vec4 bayGrad1, ivec2 imgPos) { + int offset = (imgPos.x - 2) & 3; + int x = (imgPos.x - 2) / 4; + int y = imgPos.y; + + vec4 bayer_2_v4, bayer_1_v4, bayer0_v4, bayer1_v4, bayer2_v4; + float bayer_2_f, bayer_1_f, bayer0_f, bayer1_f, bayer2_f; + + vec4 a = vec4(imageLoad(bayerTex, ivec2(x, y-2))); + vec4 b = vec4(imageLoad(bayerTex, ivec2(x+1, y-2))); + shiftInts(bayer_2_v4, bayer_2_f, a, b, offset); + + a = vec4(imageLoad(bayerTex, ivec2(x, y-1))); + b = vec4(imageLoad(bayerTex, ivec2(x+1, y-1))); + shiftInts(bayer_1_v4, bayer_1_f, a, b, offset); + + a = vec4(imageLoad(bayerTex, ivec2(x, y))); + b = vec4(imageLoad(bayerTex, ivec2(x+1, y))); + shiftInts(bayer0_v4, bayer0_f, a, b, offset); + + a = vec4(imageLoad(bayerTex, ivec2(x, y+1))); + b = vec4(imageLoad(bayerTex, ivec2(x+1, y+1))); + shiftInts(bayer1_v4, bayer1_f, a, b, offset); + + a = vec4(imageLoad(bayerTex, ivec2(x, y+2))); + b = vec4(imageLoad(bayerTex, ivec2(x+1, y+2))); + shiftInts(bayer2_v4, bayer2_f, a, b, offset); + + float vGrad = abs(bayer_1_v4.z - bayer1_v4.z) + (abs(bayer_1_v4.y - bayer1_v4.y) + abs(bayer_1_v4.w - bayer1_v4.w)) * 0.5; + float hGrad = abs(bayer0_v4.w - bayer0_v4.y) + (abs(bayer_1_v4.w - bayer_1_v4.y) + abs(bayer1_v4.w - bayer1_v4.y)) * 0.5; + + bayGrad0.x = (vGrad + abs(bayer_2_v4.z - bayer0_v4.z) + (abs(bayer_2_v4.y - bayer0_v4.y) + abs(bayer_2_v4.w - bayer0_v4.w)) * 0.5) / 8.0; + bayGrad0.z = (vGrad + abs(bayer2_v4.z - bayer0_v4.z) + (abs(bayer2_v4.y - bayer0_v4.y) + abs(bayer2_v4.w - bayer0_v4.w)) * 0.5) / 8.0; + bayGrad0.w = (hGrad + abs(bayer0_v4.x - bayer0_v4.z) + (abs(bayer_1_v4.x - bayer_1_v4.z) + abs(bayer1_v4.x - bayer1_v4.z)) * 0.5) / 8.0; + bayGrad0.y = (hGrad + abs(bayer0_f - bayer0_v4.z) + (abs(bayer_1_f - bayer_1_v4.z) + abs(bayer1_f - bayer1_v4.z)) * 0.5) / 8.0; + + bayGrad1.z = (abs(bayer2_v4.x - bayer0_v4.z) + abs(bayer1_v4.y - bayer_1_v4.w) + abs(bayer_1_v4.z - bayer1_v4.x) + abs(bayer2_v4.y - bayer0_v4.w)) / 8.0; + bayGrad1.w = (abs(bayer_2_v4.x - bayer0_v4.z) + abs(bayer_1_v4.y - bayer1_v4.w) + abs(bayer1_v4.z - bayer_1_v4.x) + abs(bayer_2_v4.y - bayer0_v4.w)) / 8.0; + bayGrad1.x = (abs(bayer_2_f - bayer0_v4.z) + abs(bayer_1_v4.w - bayer1_v4.y) + abs(bayer1_v4.z - bayer_1_f) + abs(bayer_2_v4.w - bayer0_v4.y)) / 8.0; + bayGrad1.y = (abs(bayer2_f - bayer0_v4.z) + abs(bayer1_v4.w - bayer_1_v4.y) + abs(bayer_1_v4.z - bayer1_f) + abs(bayer2_v4.w - bayer0_v4.y)) / 8.0; +} + +vec4 gradientMask(vec4 rgbd, ivec2 imgPos) { + vec4 edgGrad0, edgGrad1; + gradientSingleStep(edgGrad0, edgGrad1, imgPos); + + vec4 bayGrad0, bayGrad1; + gradientVNG_G(bayGrad0, bayGrad1, imgPos); + + float maxGradient = max(max(edgGrad0.x, edgGrad0.y), max(edgGrad0.z, edgGrad0.w)); + maxGradient = max(maxGradient, max(max(edgGrad1.x, edgGrad1.y), max(edgGrad1.z, edgGrad1.w))); + float minGradient = min(min(edgGrad0.x, edgGrad0.y), min(edgGrad0.z, edgGrad0.w)); + minGradient = min(minGradient, min(min(edgGrad1.x, edgGrad1.y), min(edgGrad1.z, edgGrad1.w))); + + float maxGradientVNG = max(max(bayGrad0.x, bayGrad0.y), max(bayGrad0.z, bayGrad0.w)); + maxGradientVNG = max(maxGradientVNG, max(max(bayGrad1.x, bayGrad1.y), max(bayGrad1.z, bayGrad1.w))); + float minGradientVNG = min(min(bayGrad0.x, bayGrad0.y), min(bayGrad0.z, bayGrad0.w)); + minGradientVNG = min(minGradientVNG, min(min(bayGrad1.x, bayGrad1.y), min(bayGrad1.z, bayGrad1.w))); + + float dif = (maxGradient - minGradient) / 8.0; + float dif1 = (maxGradient - minGradient) / 32.0; + dif = dif - dif1; + float threshold = 1.5 * minGradient + dif; + threshold = max(threshold, float(ubo_uParams_minThresholdEdge)) + 8.0; + float max2 = maxGradientVNG * 0.5; + float min2 = minGradientVNG * 0.5; + dif = max2 - min2; + float thresholdVNG = 3.0 * min2 + dif + 8.0; + thresholdVNG = max(thresholdVNG, float(ubo_uParams_minThresholdVNG)); + + maxGradient = max(maxGradient, maxGradientVNG); + + int mask = 0; + int count = 0; + if ((edgGrad0.x < threshold) && (bayGrad0.x < thresholdVNG)) { mask |= (1 << 0); count++; } + if ((edgGrad0.y < threshold) && (bayGrad0.y < thresholdVNG)) { mask |= (1 << 1); count++; } + if ((edgGrad0.z < threshold) && (bayGrad0.z < thresholdVNG)) { mask |= (1 << 2); count++; } + if ((edgGrad0.w < threshold) && (bayGrad0.w < thresholdVNG)) { mask |= (1 << 3); count++; } + if ((edgGrad1.x < threshold) && (bayGrad1.x < thresholdVNG)) { mask |= (1 << 4); count++; } + if ((edgGrad1.y < threshold) && (bayGrad1.y < thresholdVNG)) { mask |= (1 << 5); count++; } + if ((edgGrad1.z < threshold) && (bayGrad1.z < thresholdVNG)) { mask |= (1 << 6); count++; } + if ((edgGrad1.w < threshold) && (bayGrad1.w < thresholdVNG)) { mask |= (1 << 7); count++; } + + if (mask == 0) { + + if (edgGrad0.x < threshold) { mask |= (1 << 0); count++; } + if (edgGrad0.y < threshold) { mask |= (1 << 1); count++; } + if (edgGrad0.z < threshold) { mask |= (1 << 2); count++; } + if (edgGrad0.w < threshold) { mask |= (1 << 3); count++; } + if (edgGrad1.x < threshold) { mask |= (1 << 4); count++; } + if (edgGrad1.y < threshold) { mask |= (1 << 5); count++; } + if (edgGrad1.z < threshold) { mask |= (1 << 6); count++; } + if (edgGrad1.w < threshold) { mask |= (1 << 7); count++; } + + if (count == 0) { + mask = 0xff; + count = 8; + } + } + rgbd.w = float(mask | (count << 8)); + return rgbd; +} + +vec4 redBlueAtGreen(ivec2 imgPos, vec4 rgbd) { + float llGreen = rgbd.y; + uint w = uint(clamp(rgbd.w, 0.0, 65535.0)); + float bc = 0.0, rc = 0.0, count = 0.0; + + ivec2 pos = imgPos; + pos.y--; + vec4 over = vec4(imageLoad(rgbdTex, pos)); + pos.y += 2; + vec4 under = vec4(imageLoad(rgbdTex, pos)); + pos.x--; + pos.y--; + vec4 left = vec4(imageLoad(rgbdTex, pos)); + pos.x += 2; + vec4 right = vec4(imageLoad(rgbdTex, pos)); + + vec4 r4 = vec4(over.x, left.x, right.x, under.x); + vec4 g4 = vec4(over.y, left.y, right.y, under.y); + vec4 b4 = vec4(over.z, left.z, right.z, under.z); + + vec4 dif4 = vec4(1.0) + abs(vec4(rgbd.y) - g4) * 0.25; + + float greenScale = g4[3] * dif4[0] + g4[0] * dif4[3]; + float blueScale = b4[3] * dif4[0] + b4[0] * dif4[3]; + float redScale = r4[3] * dif4[0] + r4[0] * dif4[3]; + if ((w & (1u << 0)) != 0u && greenScale != 0.0) { + bc += llGreen * blueScale / greenScale; + rc += llGreen * redScale / greenScale; + count += 1.0; + } + + if ((w & (1u << 2)) != 0u && greenScale != 0.0) { + bc += llGreen * blueScale / greenScale; + rc += llGreen * redScale / greenScale; + count += 1.0; + } + + greenScale = g4[1] * dif4[2] + g4[2] * dif4[1]; + blueScale = b4[1] * dif4[2] + b4[2] * dif4[1]; + redScale = r4[1] * dif4[2] + r4[2] * dif4[1]; + if ((w & (1u << 1)) != 0u && greenScale != 0.0) { + bc += llGreen * blueScale / greenScale; + rc += llGreen * redScale / greenScale; + count += 1.0; + } + + if ((w & (1u << 3)) != 0u && greenScale != 0.0) { + bc += llGreen * blueScale / greenScale; + rc += llGreen * redScale / greenScale; + count += 1.0; + } + + greenScale = g4[2] * dif4[0] + g4[0] * dif4[2]; + blueScale = b4[2] * dif4[0] + b4[0] * dif4[2]; + redScale = r4[2] * dif4[0] + r4[0] * dif4[2]; + if ((w & (1u << 4)) != 0u && greenScale != 0.0) { + bc += llGreen * blueScale / greenScale; + rc += llGreen * redScale / greenScale; + count += 1.0; + } + + greenScale = g4[2] * dif4[3] + g4[3] * dif4[2]; + blueScale = b4[2] * dif4[3] + b4[3] * dif4[2]; + redScale = r4[2] * dif4[3] + r4[3] * dif4[2]; + if ((w & (1u << 5)) != 0u && greenScale != 0.0) { + bc += llGreen * blueScale / greenScale; + rc += llGreen * redScale / greenScale; + count += 1.0; + } + + greenScale = g4[1] * dif4[0] + g4[0] * dif4[1]; + blueScale = b4[1] * dif4[0] + b4[0] * dif4[1]; + redScale = r4[1] * dif4[0] + r4[0] * dif4[1]; + if ((w & (1u << 7)) != 0u && greenScale != 0.0) { + bc += llGreen * blueScale / greenScale; + rc += llGreen * redScale / greenScale; + count += 1.0; + } + + greenScale = g4[1] * dif4[3] + g4[3] * dif4[1]; + blueScale = b4[1] * dif4[3] + b4[3] * dif4[1]; + redScale = r4[1] * dif4[3] + r4[3] * dif4[1]; + if ((w & (1u << 6)) != 0u && greenScale != 0.0) { + bc += llGreen * blueScale / greenScale; + rc += llGreen * redScale / greenScale; + count += 1.0; + } + + float redVal = (count > 0.0) ? rc / count : (r4[0] + r4[1] + r4[2] + r4[3]) * 0.25; + float blueVal = (count > 0.0) ? bc / count : (b4[0] + b4[1] + b4[2] + b4[3]) * 0.25; + + rgbd.x = min(redVal, 65534.0); + rgbd.z = min(blueVal, 65534.0); + return rgbd; +} + +vec4 rgb2ycc(vec4 rgbx) { + float ly = rgbx.x + rgbx.y * 2.0 + rgbx.z + 1.0; + vec2 c = vec2(rgbx.x - rgbx.y, rgbx.z - rgbx.y); + c *= 32768.0 / ly; + vec4 res; + res.y = (c.x >= 0.0) ? min(32767.0, c.x) : min(65535.0, 65536.0 + c.x); + res.z = (c.y >= 0.0) ? min(32767.0, c.y) : min(65535.0, 65536.0 + c.y); + res.x = 0.25 * (ly - 1.0); + res.w = rgbx.w; + return res; +} + +uvec4 rgb2ycc_u16(vec4 rgbx) { + vec4 ycc = rgb2ycc(rgbx); + return uvec4( + uint(ycc.x), + uint(ycc.y), + uint(ycc.z), + uint(ycc.w) + ); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + + uvec4 outV = uvec4(0u); + if (gid.x >= ubo_uParams_l && gid.x < ubo_uParams_r && + gid.y >= ubo_uParams_t && gid.y < ubo_uParams_b) { + int x = gid.x & 1; + int y = gid.y & 1; + vec4 rgbDPix = vec4(imageLoad(rgbdTex, gid)); + if (x == 1 && y == 0) { + rgbDPix = gradientMask(rgbDPix, gid); + rgbDPix = redBlueAtGreen(gid, rgbDPix); + outV = rgb2ycc_u16(rgbDPix); + } else if (x == 0 && y == 1) { + rgbDPix = gradientMask(rgbDPix, gid); + rgbDPix = redBlueAtGreen(gid, rgbDPix); + outV = rgb2ycc_u16(rgbDPix); + } else if (x == 0 && y == 0) { + outV = rgb2ycc_u16(rgbDPix); + } else if (x == 1 && y == 1){ + outV = rgb2ycc_u16(rgbDPix); + } + } + imageStore(outTex, gid, outV); +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_pass_neutral_0x308ec13.comp b/research/phocus_glsl/02_demosaic/demosaic_pass_neutral_0x308ec13.comp new file mode 100644 index 00000000..527f4b52 --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_pass_neutral_0x308ec13.comp @@ -0,0 +1,67 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: ca62ac0831390a5415c5703b3a22c344faf8cc3de01c9665783d1ce6a6790da0 + * ELF offsets: 0x308ec13 + * Symbols: demosaic_pass_neutral_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp image2D; +precision highp uimage2D; + +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16f, binding = 0) readonly uniform image2D inTex; +layout(rgba16ui, binding = 1) writeonly uniform uimage2D outTex; +layout(std140, binding = 2) uniform DemosaicPassNeutralParams_UBO { + int uParams_l; + int uParams_t; + int uParams_r; + int uParams_b; + int uParams_rNeutral; + int uParams_gNeutral; + int uParams_bNeutral; + int uParams_clampAllowZero; + int uParams_gainScaleBits; + int pad1; + int pad2; + int pad3; +}; + +uint shiftRightRoundUint(float v, int shiftBits) { + int divisor = 1 << shiftBits; + float roundUp = float(divisor + 1) * 0.5; + return uint(clamp((v + roundUp) / float(divisor), 0.0, 65535.0)); +} + +void main() { + ivec2 coord = ivec2(gl_GlobalInvocationID.xy); + + if (coord.x < uParams_l || coord.x >= uParams_r || + coord.y < uParams_t || coord.y >= uParams_b) { + return; + } + + vec4 pix4 = imageLoad(inTex, coord); + vec4 pix4Scaled = pix4 * 65535.0; + + vec4 mul4; + if ((coord.y & 1) == 0) { + mul4 = vec4(float(uParams_rNeutral), float(uParams_gNeutral), + float(uParams_rNeutral), float(uParams_gNeutral)); + } else { + mul4 = vec4(float(uParams_gNeutral), float(uParams_bNeutral), + float(uParams_gNeutral), float(uParams_bNeutral)); + } + + vec4 res = pix4Scaled * mul4; + + uvec4 uout = uvec4( + shiftRightRoundUint(res.r, uParams_gainScaleBits), + shiftRightRoundUint(res.g, uParams_gainScaleBits), + shiftRightRoundUint(res.b, uParams_gainScaleBits), + shiftRightRoundUint(res.a, uParams_gainScaleBits)); + imageStore(outTex, coord, uout); +} diff --git a/research/phocus_glsl/02_demosaic/demosaic_yuv_to_rgb_0x3007126.comp b/research/phocus_glsl/02_demosaic/demosaic_yuv_to_rgb_0x3007126.comp new file mode 100644 index 00000000..f7d05d13 --- /dev/null +++ b/research/phocus_glsl/02_demosaic/demosaic_yuv_to_rgb_0x3007126.comp @@ -0,0 +1,64 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: dd4384ae8724f2c7edb40a44214966d9d390cba0e9fa00329be17c814ff0e1c7 + * ELF offsets: 0x3007126 + * Symbols: demosaic_yuv_to_rgb_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; +precision highp image2D; +layout(local_size_x = 16, local_size_y = 16) in; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D yccdTex; +layout(rgba16f, binding = 1) writeonly uniform image2D outTex; + +layout(std140, binding = 2) uniform DemosaicYuvToRgbParams_UBO { + int uParams_l; + int uParams_t; + int uParams_r; + int uParams_b; + float uParams_gain; + float uPad0; + float uPad1; + float uPad2; +}; + +int convert2compliment(int x) { + return ((x & (1 << 15)) != 0) ? (x | ~((1 << 16) - 1)) : x; +} + +vec4 ycc2rgb(vec4 ycc, float gain) { + vec4 res; + float ly = clamp(gain * ycc.r, 0.0, 65534.0); + int lr = int(round(ycc.g)); + int lb = int(round(ycc.b)); + lr = convert2compliment(lr); + lb = convert2compliment(lb); + res.r = clamp(ly * 3.0 * float(lr) / 32768.0 - ly * float(lb) / 32768.0 + ly, 0.0, 65535.0); + res.b = clamp(ly * 3.0 * float(lb) / 32768.0 - ly * float(lr) / 32768.0 + ly, 0.0, 65535.0); + res.g = clamp((4.0 * ly - (res.r + res.b)) / 2.0, 0.0, 65535.0); + res.a = ycc.a; + return res; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 srcPos = gid + ivec2(uParams_l, uParams_t); + + if (gid.x >= (uParams_r - uParams_l) || gid.y >= (uParams_b - uParams_t)) return; + + uvec4 uYcc = imageLoad(yccdTex, srcPos); + vec4 yccdPix = vec4(float(uYcc.r), float(uYcc.g), float(uYcc.b), float(uYcc.a)); + + vec4 result = ycc2rgb(yccdPix, uParams_gain); + vec4 outF = vec4( + clamp(result.r, 0.0, 65535.0), + clamp(result.g, 0.0, 65535.0), + clamp(result.b, 0.0, 65535.0), + clamp(result.a, 0.0, 65535.0) + ) / 65535.0; + imageStore(outTex, gid, outF); +} diff --git a/research/phocus_glsl/03_denoise/cacheCmosCache0_0x30501d4.frag b/research/phocus_glsl/03_denoise/cacheCmosCache0_0x30501d4.frag new file mode 100644 index 00000000..0b8bd6d3 --- /dev/null +++ b/research/phocus_glsl/03_denoise/cacheCmosCache0_0x30501d4.frag @@ -0,0 +1,35 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: c7f420d715f7cf77f2a9e4f39d3a91210a32fb7ae3f3bb76eb54060c35dbb03a + * ELF offsets: 0x30501d4 + * Symbols: cacheCmosCache0_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform vec2 uInvTextureSize; + +in vec2 TexCoord; +out vec4 FragColor; + +void main() { + vec4 center = texture(uInputTexture0, TexCoord); + vec4 left = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, 0.0)); + vec4 right = texture(uInputTexture0, TexCoord + vec2( uInvTextureSize.x, 0.0)); + + bool isRedRow = (int(gl_FragCoord.y) & 1) == 0; + vec2 redValRed, grSumHRed; + + if (isRedRow) { + redValRed = center.xz; + grSumHRed = vec2(left.w + center.y, center.y + center.w); + } else { + redValRed = center.yw; + grSumHRed = vec2(center.x + center.z, center.z + right.x); + } + + FragColor = vec4(redValRed / 1.0, grSumHRed / 2.0); +} diff --git a/research/phocus_glsl/03_denoise/cacheCmosCache1_0x30651c8.frag b/research/phocus_glsl/03_denoise/cacheCmosCache1_0x30651c8.frag new file mode 100644 index 00000000..b401a442 --- /dev/null +++ b/research/phocus_glsl/03_denoise/cacheCmosCache1_0x30651c8.frag @@ -0,0 +1,41 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 75b79c1ff7a65dce4caaa4a318e8831830581262ba3641abbc911404105fd626 + * ELF offsets: 0x30651c8 + * Symbols: cacheCmosCache1_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform vec2 uInvTextureSize; + +in vec2 TexCoord; +out vec4 FragColor; + +void main() { + vec4 center = texture(uInputTexture0, TexCoord); + vec4 top = texture(uInputTexture0, TexCoord + vec2(0.0, -uInvTextureSize.y)); + vec4 bottom = texture(uInputTexture0, TexCoord + vec2(0.0, uInvTextureSize.y)); + vec4 topLeft = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, -uInvTextureSize.y)); + vec4 topRight = texture(uInputTexture0, TexCoord + vec2( uInvTextureSize.x, -uInvTextureSize.y)); + vec4 bottomLeft = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, uInvTextureSize.y)); + vec4 bottomRight = texture(uInputTexture0, TexCoord + vec2( uInvTextureSize.x, uInvTextureSize.y)); + + bool isRedRow = (int(gl_FragCoord.y) & 1) == 0; + vec2 grSumVRed, blueSumRed; + + if (isRedRow) { + grSumVRed = vec2(top.x + bottom.x, top.z + bottom.z); + float bgMC = top.y + bottom.y; + blueSumRed = vec2(topLeft.w + bottomLeft.w + bgMC, top.w + bottom.w + bgMC); + } else { + grSumVRed = vec2(bottom.y + top.y, bottom.w + top.w); + float bgMC = top.z + bottom.z; + blueSumRed = vec2(top.x + bottom.x + bgMC, topRight.x + bottomRight.x + bgMC); + } + + FragColor = vec4(grSumVRed / 2.0, blueSumRed / 4.0); +} diff --git a/research/phocus_glsl/03_denoise/cacheCmosCache2_0x300e390.frag b/research/phocus_glsl/03_denoise/cacheCmosCache2_0x300e390.frag new file mode 100644 index 00000000..aa1dc698 --- /dev/null +++ b/research/phocus_glsl/03_denoise/cacheCmosCache2_0x300e390.frag @@ -0,0 +1,35 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: c54309c364704060a762899687cb5552463b112200ba20e6380dfabef41cf04a + * ELF offsets: 0x300e390 + * Symbols: cacheCmosCache2_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform vec2 uInvTextureSize; + +in vec2 TexCoord; +out vec4 FragColor; + +void main() { + vec4 center = texture(uInputTexture0, TexCoord); + vec4 left = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, 0.0)); + vec4 right = texture(uInputTexture0, TexCoord + vec2( uInvTextureSize.x, 0.0)); + + bool isRedRow = (int(gl_FragCoord.y) & 1) == 0; + vec2 green1ValG1, redSumG1; + + if (isRedRow) { + green1ValG1 = center.yw; + redSumG1 = vec2(center.x + center.z, center.z + right.x); + } else { + green1ValG1 = center.xz; + redSumG1 = vec2(left.w + center.y, center.y + center.w); + } + + FragColor = vec4(green1ValG1 / 1.0, redSumG1 / 2.0); +} diff --git a/research/phocus_glsl/03_denoise/cacheCmosCache3_0x307c71b.frag b/research/phocus_glsl/03_denoise/cacheCmosCache3_0x307c71b.frag new file mode 100644 index 00000000..5c1f4f66 --- /dev/null +++ b/research/phocus_glsl/03_denoise/cacheCmosCache3_0x307c71b.frag @@ -0,0 +1,41 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: ea3760a5920497c1d661adf7132a31d29544b34d386deb1d87ba6b3d41b935a7 + * ELF offsets: 0x307c71b + * Symbols: cacheCmosCache3_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform vec2 uInvTextureSize; + +in vec2 TexCoord; +out vec4 FragColor; + +void main() { + vec4 center = texture(uInputTexture0, TexCoord); + vec4 top = texture(uInputTexture0, TexCoord + vec2(0.0, -uInvTextureSize.y)); + vec4 bottom = texture(uInputTexture0, TexCoord + vec2(0.0, uInvTextureSize.y)); + vec4 topLeft = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, -uInvTextureSize.y)); + vec4 topRight = texture(uInputTexture0, TexCoord + vec2( uInvTextureSize.x, -uInvTextureSize.y)); + vec4 bottomLeft = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, uInvTextureSize.y)); + vec4 bottomRight = texture(uInputTexture0, TexCoord + vec2( uInvTextureSize.x, uInvTextureSize.y)); + + bool isRedRow = (int(gl_FragCoord.y) & 1) == 0; + vec2 blueSumG1, greenSumG1; + + if (isRedRow) { + blueSumG1 = vec2(bottom.y + top.y, bottom.w + top.w); + float bgMC = top.z + bottom.z; + greenSumG1 = vec2(top.x + bottom.x + bgMC, topRight.x + bottomRight.x + bgMC); + } else { + blueSumG1 = vec2(bottom.x + top.x, bottom.z + top.z); + float bgMC = top.y + bottom.y; + greenSumG1 = vec2(topLeft.w + bottomLeft.w + bgMC, top.w + bottom.w + bgMC); + } + + FragColor = vec4(blueSumG1 / 2.0, greenSumG1 / 4.0); +} diff --git a/research/phocus_glsl/03_denoise/cacheCmosG1G2Cache0_0x3032df9.frag b/research/phocus_glsl/03_denoise/cacheCmosG1G2Cache0_0x3032df9.frag new file mode 100644 index 00000000..be751edd --- /dev/null +++ b/research/phocus_glsl/03_denoise/cacheCmosG1G2Cache0_0x3032df9.frag @@ -0,0 +1,35 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 07200b7b375227e9abc24cb9bc8583f5977e8c9e89f6bc9e3363bf04aca6c348 + * ELF offsets: 0x3032df9 + * Symbols: cacheCmosG1G2Cache0_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform vec2 uInvTextureSize; + +in vec2 TexCoord; +out vec4 FragColor; + +void main() { + vec4 center = texture(uInputTexture0, TexCoord); + vec4 left = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, 0.0)); + vec4 right = texture(uInputTexture0, TexCoord + vec2(uInvTextureSize.x, 0.0)); + + bool isRedRow = (int(gl_FragCoord.y) & 1) == 0; + vec2 green1ValG1, redSumG1; + + if (isRedRow) { + green1ValG1 = center.yw; + redSumG1 = vec2(center.x + center.z, center.z + right.x); + } else { + green1ValG1 = center.xz; + redSumG1 = vec2(left.w + center.y, center.y + center.w); + } + + FragColor = vec4(green1ValG1 / 1.0, redSumG1 / 2.0); +} diff --git a/research/phocus_glsl/03_denoise/cacheCmosG1G2Cache1_0x302135f.frag b/research/phocus_glsl/03_denoise/cacheCmosG1G2Cache1_0x302135f.frag new file mode 100644 index 00000000..d878599b --- /dev/null +++ b/research/phocus_glsl/03_denoise/cacheCmosG1G2Cache1_0x302135f.frag @@ -0,0 +1,41 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 9f177bedb3419c59f2297600453a289d254763433b0bb6c83256845c271b1cb6 + * ELF offsets: 0x302135f + * Symbols: cacheCmosG1G2Cache1_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform vec2 uInvTextureSize; + +in vec2 TexCoord; +out vec4 FragColor; + +void main() { + vec4 center = texture(uInputTexture0, TexCoord); + vec4 top = texture(uInputTexture0, TexCoord + vec2(0.0, -uInvTextureSize.y)); + vec4 bottom = texture(uInputTexture0, TexCoord + vec2(0.0, uInvTextureSize.y)); + vec4 topLeft = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, -uInvTextureSize.y)); + vec4 topRight = texture(uInputTexture0, TexCoord + vec2(uInvTextureSize.x, -uInvTextureSize.y)); + vec4 bottomLeft = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, uInvTextureSize.y)); + vec4 bottomRight = texture(uInputTexture0, TexCoord + vec2(uInvTextureSize.x, uInvTextureSize.y)); + + bool isRedRow = (int(gl_FragCoord.y) & 1) == 0; + vec2 blueSumG1, greenSumG1; + + if (isRedRow) { + blueSumG1 = vec2(bottom.y + top.y, bottom.w + top.w); + float green2Sum = top.z + bottom.z; + greenSumG1 = vec2(top.x + bottom.x, topRight.x + bottomRight.x) + vec2(green2Sum); + } else { + blueSumG1 = vec2(bottom.x + top.x, bottom.z + top.z); + float green2Sum = top.y + bottom.y; + greenSumG1 = vec2(topLeft.w + bottomLeft.w, top.w + bottom.w) + vec2(green2Sum); + } + + FragColor = vec4(blueSumG1 / 2.0, greenSumG1 / 4.0); +} diff --git a/research/phocus_glsl/03_denoise/cacheCmosG1G2Cache2_0x303b1b3.frag b/research/phocus_glsl/03_denoise/cacheCmosG1G2Cache2_0x303b1b3.frag new file mode 100644 index 00000000..217da4d7 --- /dev/null +++ b/research/phocus_glsl/03_denoise/cacheCmosG1G2Cache2_0x303b1b3.frag @@ -0,0 +1,39 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: f3fe5f3c34819255ebb82f092eed86346a1e31b351c6d54b2771b7866d3492f7 + * ELF offsets: 0x303b1b3 + * Symbols: cacheCmosG1G2Cache2_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform vec2 uInvTextureSize; + +in vec2 TexCoord; +out vec4 FragColor; + +void main() { + vec4 center = texture(uInputTexture0, TexCoord); + vec4 left = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, 0.0)); + vec4 right = texture(uInputTexture0, TexCoord + vec2(uInvTextureSize.x, 0.0)); + vec4 top = texture(uInputTexture0, TexCoord + vec2(0.0, -uInvTextureSize.y)); + vec4 bottom = texture(uInputTexture0, TexCoord + vec2(0.0, uInvTextureSize.y)); + vec4 top2 = texture(uInputTexture0, TexCoord + vec2(0.0, -2.0 * uInvTextureSize.y)); + vec4 bottom2 = texture(uInputTexture0, TexCoord + vec2(0.0, 2.0 * uInvTextureSize.y)); + + bool isRedRow = (int(gl_FragCoord.y) & 1) == 0; + vec2 horizSum, vertSum; + + if (isRedRow) { + horizSum = vec2(left.w + center.y + center.w, center.y + center.w + right.y); + vertSum = vec2(top2.y + center.y + bottom2.y, top2.w + center.w + bottom2.w); + } else { + horizSum = vec2(left.z + center.x + center.z, center.x + center.z + right.x); + vertSum = vec2(top2.x + center.x + bottom2.x, top2.z + center.z + bottom2.z); + } + + FragColor = vec4(horizSum / 3.0, vertSum / 3.0); +} diff --git a/research/phocus_glsl/03_denoise/cacheCmosG1G2Cache3_0x3064c8a.frag b/research/phocus_glsl/03_denoise/cacheCmosG1G2Cache3_0x3064c8a.frag new file mode 100644 index 00000000..7ddeb5ec --- /dev/null +++ b/research/phocus_glsl/03_denoise/cacheCmosG1G2Cache3_0x3064c8a.frag @@ -0,0 +1,39 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 63a9a7da2c59cdee8169bf505f93bba4d04bcb1f4bf20c9acff24ab92b7975de + * ELF offsets: 0x3064c8a + * Symbols: cacheCmosG1G2Cache3_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform vec2 uInvTextureSize; + +in vec2 TexCoord; +out vec4 FragColor; + +void main() { + vec4 center = texture(uInputTexture0, TexCoord); + vec4 top = texture(uInputTexture0, TexCoord + vec2(0.0, -uInvTextureSize.y)); + vec4 bottom = texture(uInputTexture0, TexCoord + vec2(0.0, uInvTextureSize.y)); + vec4 topLeft = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, -uInvTextureSize.y)); + vec4 topRight = texture(uInputTexture0, TexCoord + vec2(uInvTextureSize.x, -uInvTextureSize.y)); + vec4 bottomRight = texture(uInputTexture0, TexCoord + vec2(uInvTextureSize.x, uInvTextureSize.y)); + vec4 bottomLeft = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, uInvTextureSize.y)); + + bool isRedRow = (int(gl_FragCoord.y) & 1) == 0; + vec2 diagRSum, diagLSum; + + if (isRedRow) { + diagRSum = vec2(top.x + center.y + bottom.z, top.z + center.w + bottomRight.x); + diagLSum = vec2(bottom.x + center.y + top.z, bottom.z + center.w + topRight.x); + } else { + diagRSum = vec2(topLeft.w + center.x + bottom.y, top.y + center.z + bottom.w); + diagLSum = vec2(bottomLeft.w + center.x + top.y, bottom.y + center.z + top.w); + } + + FragColor = vec4(diagRSum / 3.0, diagLSum / 3.0); +} diff --git a/research/phocus_glsl/03_denoise/cacheCmosRedBlueCache0_0x306db71.frag b/research/phocus_glsl/03_denoise/cacheCmosRedBlueCache0_0x306db71.frag new file mode 100644 index 00000000..e797d541 --- /dev/null +++ b/research/phocus_glsl/03_denoise/cacheCmosRedBlueCache0_0x306db71.frag @@ -0,0 +1,37 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 25d520100eef854bba77d939159fe21fd7680371cc3f7b6f62e6585458e055d6 + * ELF offsets: 0x306db71 + * Symbols: cacheCmosRedBlueCache0_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform vec2 uInvTextureSize; + +in vec2 TexCoord; +out vec4 FragColor; + +void main() { + vec4 center = texture(uInputTexture0, TexCoord); + vec4 left = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, 0.0)); + vec4 right = texture(uInputTexture0, TexCoord + vec2(uInvTextureSize.x, 0.0)); + + bool isRedRow = (int(gl_FragCoord.y) & 1) == 0; + vec2 redvalRed, horizSum; + + if (isRedRow) { + redvalRed = center.xz; + float redSumM = center.x + center.z; + horizSum = vec2(left.z + redSumM, redSumM + right.x); + } else { + redvalRed = center.yw; + float redSumM = center.y + center.w; + horizSum = vec2(left.w + redSumM, redSumM + right.y); + } + + FragColor = vec4(redvalRed / 1.0, horizSum / 3.0); +} diff --git a/research/phocus_glsl/03_denoise/cacheCmosRedBlueCache1_0x306decf.frag b/research/phocus_glsl/03_denoise/cacheCmosRedBlueCache1_0x306decf.frag new file mode 100644 index 00000000..be631225 --- /dev/null +++ b/research/phocus_glsl/03_denoise/cacheCmosRedBlueCache1_0x306decf.frag @@ -0,0 +1,47 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 1fd2aa77c9667d8cfdce32d82f263caaefb216a28936ea7e2864847063731a33 + * ELF offsets: 0x306decf + * Symbols: cacheCmosRedBlueCache1_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform vec2 uInvTextureSize; + +in vec2 TexCoord; +out vec4 FragColor; + +void main() { + vec4 center = texture(uInputTexture0, TexCoord); + vec4 left = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, 0.0)); + vec4 right = texture(uInputTexture0, TexCoord + vec2(uInvTextureSize.x, 0.0)); + vec4 top = texture(uInputTexture0, TexCoord + vec2(0.0, -uInvTextureSize.y)); + vec4 bottom = texture(uInputTexture0, TexCoord + vec2(0.0, uInvTextureSize.y)); + vec4 top2 = texture(uInputTexture0, TexCoord + vec2(0.0, -2.0 * uInvTextureSize.y)); + vec4 bottom2 = texture(uInputTexture0, TexCoord + vec2(0.0, 2.0 * uInvTextureSize.y)); + + bool isRedRow = (int(gl_FragCoord.y) & 1) == 0; + vec2 vertSum, grAveRed; + vec2 grSumHRed, grSumVRed; + + if (isRedRow) { + grSumHRed = vec2(left.w + center.y, center.y + center.w); + grSumVRed = vec2(top.x + bottom.x, top.z + bottom.z); + float redSumM = center.x + center.z; + vertSum = vec2(top2.x + center.x + bottom2.x, top2.z + center.z + bottom2.z); + } else { + grSumHRed = vec2(center.x + center.z, center.z + right.x); + grSumVRed = vec2(bottom.y + top.y, bottom.w + top.w); + float redSumM = center.y + center.w; + vertSum = vec2(top2.y + center.y + bottom2.y, top2.w + center.w + bottom2.w); + } + + vec2 greenSumRed = grSumHRed + grSumVRed; + grAveRed = greenSumRed / 4.0; + + FragColor = vec4(vertSum / 3.0, grAveRed / 1.0); +} diff --git a/research/phocus_glsl/03_denoise/cacheCmosRedBlueCache2_0x3038793.frag b/research/phocus_glsl/03_denoise/cacheCmosRedBlueCache2_0x3038793.frag new file mode 100644 index 00000000..8456da70 --- /dev/null +++ b/research/phocus_glsl/03_denoise/cacheCmosRedBlueCache2_0x3038793.frag @@ -0,0 +1,54 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: d3fc268abeb04b0953757c16d8bafcb1907a30fe349cc7f5417371eb5af0aa65 + * ELF offsets: 0x3038793 + * Symbols: cacheCmosRedBlueCache2_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform vec2 uInvTextureSize; + +in vec2 TexCoord; +out vec4 FragColor; + +void main() { + vec4 center = texture(uInputTexture0, TexCoord); + vec4 left = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, 0.0)); + vec4 right = texture(uInputTexture0, TexCoord + vec2(uInvTextureSize.x, 0.0)); + vec4 top = texture(uInputTexture0, TexCoord + vec2(0.0, -uInvTextureSize.y)); + vec4 bottom = texture(uInputTexture0, TexCoord + vec2(0.0, uInvTextureSize.y)); + vec4 topLeft = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, -uInvTextureSize.y)); + vec4 topRight = texture(uInputTexture0, TexCoord + vec2(uInvTextureSize.x, -uInvTextureSize.y)); + vec4 bottomLeft = texture(uInputTexture0, TexCoord + vec2(-uInvTextureSize.x, uInvTextureSize.y)); + vec4 bottomRight = texture(uInputTexture0, TexCoord + vec2(uInvTextureSize.x, uInvTextureSize.y)); + + bool isRedRow = (int(gl_FragCoord.y) & 1) == 0; + vec2 blueAveRed, lumaRed; + vec2 grSumHRed, grSumVRed, blueSumRed; + vec2 redvalRed, grAveRed; + + if (isRedRow) { + redvalRed = center.xz; + grSumHRed = vec2(left.w + center.y, center.y + center.w); + grSumVRed = vec2(top.x + bottom.x, top.z + bottom.z); + float blueSumM = top.y + bottom.y; + blueSumRed = vec2(topLeft.w + bottomLeft.w, top.w + bottom.w) + vec2(blueSumM); + } else { + redvalRed = center.yw; + grSumHRed = vec2(center.x + center.z, center.z + right.x); + grSumVRed = vec2(bottom.y + top.y, bottom.w + top.w); + float blueSumM = top.z + bottom.z; + blueSumRed = vec2(top.x + bottom.x, topRight.x + bottomRight.x) + vec2(blueSumM); + } + + vec2 greenSumRed = grSumHRed + grSumVRed; + grAveRed = greenSumRed / 4.0; + blueAveRed = blueSumRed / 4.0; + lumaRed = redvalRed + 2.0 * grAveRed + blueAveRed; + + FragColor = vec4(blueAveRed / 1.0, lumaRed / 4.0); +} diff --git a/research/phocus_glsl/03_denoise/denoiseCcd_0x304b7a0.comp b/research/phocus_glsl/03_denoise/denoiseCcd_0x304b7a0.comp new file mode 100644 index 00000000..df05ebd5 --- /dev/null +++ b/research/phocus_glsl/03_denoise/denoiseCcd_0x304b7a0.comp @@ -0,0 +1,164 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 38ce78e7205eab385f083a58771fba7efdf84e98ab3e79ef6643a7ef0e7c3653 + * ELF offsets: 0x304b7a0 + * Symbols: denoiseCcd_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; + +layout(rgba16f, binding = 0) readonly restrict uniform image2D uInputImage; +layout(rgba16f, binding = 1) writeonly uniform image2D outputImage; + +uniform float uLumaSqThr; // used as lumaThr (absolute, not sqrt-based) for CCD +uniform float uChannelThr; +uniform float uPatternThr; +uniform float uPatternThr2; +uniform float uOffset; +uniform int uKernSizeX; +uniform int uKernSizeY; +uniform ivec2 uImageSize; +uniform ivec2 uMargin; + +layout(local_size_x = 16, local_size_y = 16) in; + +struct NLMCheckOldCCD { + vec2 redValRed; + vec2 grAveRed; + vec2 blueAveRed; + vec2 lumaRed; + vec2 green1ValG1; + vec2 redAveG1; + vec2 blueAveG1; + vec2 lumaG1; +}; + +NLMCheckOldCCD getFromDirect(ivec2 pos) { + vec4 center = imageLoad(uInputImage, pos ) * 65535.0; + vec4 left = imageLoad(uInputImage, pos + ivec2(-1, 0) ) * 65535.0; + vec4 right = imageLoad(uInputImage, pos + ivec2( 1, 0) ) * 65535.0; + vec4 top = imageLoad(uInputImage, pos + ivec2( 0,-1) ) * 65535.0; + vec4 bottom = imageLoad(uInputImage, pos + ivec2( 0, 1) ) * 65535.0; + vec4 topLeft = imageLoad(uInputImage, pos + ivec2(-1,-1) ) * 65535.0; + vec4 topRight = imageLoad(uInputImage, pos + ivec2( 1,-1) ) * 65535.0; + vec4 bottomLeft = imageLoad(uInputImage, pos + ivec2(-1, 1) ) * 65535.0; + vec4 bottomRight = imageLoad(uInputImage, pos + ivec2( 1, 1) ) * 65535.0; + + bool evenRow = (pos.y & 1) == 0; + vec2 redValRed, grSumHRed, grSumVRed, blueSumRed; + vec2 green1ValG1, redSumG1, blueSumG1, greenSumG1; + + if (evenRow) { + redValRed = vec2(center.x, center.z); + grSumHRed = vec2(left.w + center.y, center.y + center.w); + grSumVRed = vec2(top.x + bottom.x, top.z + bottom.z); + float bgx = top.y + bottom.y; + float bgy = top.z + bottom.z; + blueSumRed = vec2(topLeft.w + bottomLeft.w + bgx, top.w + bottom.w + bgx); + green1ValG1 = vec2(center.y, center.w); + redSumG1 = vec2(center.x + center.z, center.z + right.x); + blueSumG1 = vec2(bottom.y + top.y, bottom.w + top.w); + greenSumG1 = vec2(top.x + bottom.x + bgy, topRight.x + bottomRight.x + bgy); + } else { + redValRed = vec2(center.y, center.w); + grSumHRed = vec2(center.x + center.z, center.z + right.x); + grSumVRed = vec2(bottom.y + top.y, bottom.w + top.w); + float bgx = top.z + bottom.z; + float bgy = top.y + bottom.y; + blueSumRed = vec2(top.x + bottom.x + bgx, topRight.x + bottomRight.x + bgx); + green1ValG1 = vec2(center.x, center.z); + redSumG1 = vec2(left.w + center.y, center.y + center.w); + blueSumG1 = vec2(bottom.x + top.x, bottom.z + top.z); + greenSumG1 = vec2(topLeft.w + bottomLeft.w + bgy, top.w + bottom.w + bgy); + } + + NLMCheckOldCCD res; + res.redValRed = redValRed; + vec2 grSumRed = grSumHRed + grSumVRed; + res.grAveRed = grSumRed / 4.0; + res.blueAveRed = blueSumRed / 4.0; + res.lumaRed = res.redValRed + res.grAveRed + res.blueAveRed; + res.green1ValG1 = green1ValG1; + res.redAveG1 = redSumG1 / 2.0; + res.blueAveG1 = blueSumG1 / 2.0; + res.lumaG1 = res.redAveG1 + green1ValG1 + res.blueAveG1; + return res; +} + +vec4 NonLocalMeansCCD(ivec2 pos) { + NLMCheckOldCCD c = getFromDirect(pos); + + float lumaThr = uLumaSqThr; + float channelThr = uChannelThr; + float patternThr = uPatternThr; + float patternThr2 = uPatternThr2; + + // sum.xy = red, sum.zw = green + vec4 sum = vec4(0.0); + vec4 count = vec4(0.0); + + for (int j = -uKernSizeY; j <= uKernSizeY; j += 2) { + for (int i = -uKernSizeX; i <= uKernSizeX; i++) { + NLMCheckOldCCD s = getFromDirect(pos + ivec2(i, j)); + + bvec4 r_check = bvec4( + abs(s.lumaRed.x - c.lumaRed.x) <= lumaThr && abs(s.redValRed.x - c.redValRed.x) <= channelThr && abs(s.grAveRed.x - c.grAveRed.x) <= patternThr && abs(s.blueAveRed.x - c.blueAveRed.x) <= patternThr, + abs(s.lumaRed.y - c.lumaRed.y) <= lumaThr && abs(s.redValRed.y - c.redValRed.y) <= channelThr && abs(s.grAveRed.y - c.grAveRed.y) <= patternThr && abs(s.blueAveRed.y - c.blueAveRed.y) <= patternThr, + abs(s.lumaRed.y - c.lumaRed.x) <= lumaThr && abs(s.redValRed.y - c.redValRed.x) <= channelThr && abs(s.grAveRed.y - c.grAveRed.x) <= patternThr && abs(s.blueAveRed.y - c.blueAveRed.x) <= patternThr, + abs(s.lumaRed.x - c.lumaRed.y) <= lumaThr && abs(s.redValRed.x - c.redValRed.y) <= channelThr && abs(s.grAveRed.x - c.grAveRed.y) <= patternThr && abs(s.blueAveRed.x - c.blueAveRed.y) <= patternThr + ); + if (r_check.x) { sum.x += s.redValRed.x; count.x += 1.0; } + if (r_check.y) { sum.y += s.redValRed.y; count.y += 1.0; } + if (r_check.z) { sum.x += s.redValRed.y; count.x += 1.0; } + if (r_check.w) { sum.y += s.redValRed.x; count.y += 1.0; } + + bvec4 g_check = bvec4( + abs(s.lumaG1.x - c.lumaG1.x) <= lumaThr && abs(s.green1ValG1.x - c.green1ValG1.x) <= channelThr && abs(s.redAveG1.x - c.redAveG1.x) <= patternThr2 && abs(s.blueAveG1.x - c.blueAveG1.x) <= patternThr2, + abs(s.lumaG1.y - c.lumaG1.y) <= lumaThr && abs(s.green1ValG1.y - c.green1ValG1.y) <= channelThr && abs(s.redAveG1.y - c.redAveG1.y) <= patternThr2 && abs(s.blueAveG1.y - c.blueAveG1.y) <= patternThr2, + abs(s.lumaG1.y - c.lumaG1.x) <= lumaThr && abs(s.green1ValG1.y - c.green1ValG1.x) <= channelThr && abs(s.redAveG1.y - c.redAveG1.x) <= patternThr2 && abs(s.blueAveG1.y - c.blueAveG1.x) <= patternThr2, + abs(s.lumaG1.x - c.lumaG1.y) <= lumaThr && abs(s.green1ValG1.x - c.green1ValG1.y) <= channelThr && abs(s.redAveG1.x - c.redAveG1.y) <= patternThr2 && abs(s.blueAveG1.x - c.blueAveG1.y) <= patternThr2 + ); + if (g_check.x) { sum.z += s.green1ValG1.x; count.z += 1.0; } + if (g_check.y) { sum.w += s.green1ValG1.y; count.w += 1.0; } + if (g_check.z) { sum.z += s.green1ValG1.y; count.z += 1.0; } + if (g_check.w) { sum.w += s.green1ValG1.x; count.w += 1.0; } + } + } + + // Read full original pixel + vec4 opix = imageLoad(uInputImage, pos) * 65535.0; + bool evenRow = (pos.y & 1) == 0; + + if (evenRow) { + if (count.x > 1.0) opix.x = round(sum.x / count.x); + if (count.z > 1.0) opix.y = round(sum.z / count.z); + if (count.y > 1.0) opix.z = round(sum.y / count.y); + if (count.w > 1.0) opix.w = round(sum.w / count.w); + } else { + if (count.z > 1.0) opix.x = round(sum.z / count.z); + if (count.x > 1.0) opix.y = round(sum.x / count.x); + if (count.w > 1.0) opix.z = round(sum.w / count.w); + if (count.y > 1.0) opix.w = round(sum.y / count.y); + } + + opix = max(opix - vec4(uOffset), vec4(0.0)); + return opix / 65535.0; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 globalPos = gid + uMargin; + + if (globalPos.x >= uImageSize.x - uKernSizeX || + globalPos.y >= uImageSize.y - uKernSizeY || + globalPos.x < 0 || globalPos.y < 0) { + vec4 pixel = imageLoad(uInputImage, globalPos); + imageStore(outputImage, gid, pixel); + return; + } + + vec4 result = NonLocalMeansCCD(globalPos); + imageStore(outputImage, gid, result); +} diff --git a/research/phocus_glsl/03_denoise/denoiseCmosCached_0x309c546.comp b/research/phocus_glsl/03_denoise/denoiseCmosCached_0x309c546.comp new file mode 100644 index 00000000..5277878b --- /dev/null +++ b/research/phocus_glsl/03_denoise/denoiseCmosCached_0x309c546.comp @@ -0,0 +1,167 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 5a71694ed199c558d517899590d5a2c72f4d49e457ccf781e467e7c35119ad30 + * ELF offsets: 0x309c546 + * Symbols: denoiseCmosCached_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; + +layout(rgba16f, binding = 0) readonly restrict uniform image2D uInputImage0; +layout(rgba16f, binding = 1) readonly restrict uniform image2D uInputImage1; +layout(rgba16f, binding = 2) readonly restrict uniform image2D uInputImage2; +layout(rgba16f, binding = 3) readonly restrict uniform image2D uInputImage3; +layout(rgba16f, binding = 4) writeonly uniform image2D outputImage; + +uniform float uLumaSqThr; +uniform float uOffset; +uniform int uKernSizeX; +uniform int uKernSizeY; +uniform ivec2 uImageSize; +uniform ivec2 uMargin; + +layout(local_size_x = 16, local_size_y = 16) in; + +struct NLMCheckOld { + vec2 redValRed; + vec2 grSumHRed; + vec2 grSumVRed; + vec2 blueSumRed; + vec2 green1ValG1; + vec2 redSumG1; + vec2 blueSumG1; + vec2 greenSumG1; +}; + +NLMCheckOld getCmosCached(ivec2 pos) { + vec4 p0 = imageLoad(uInputImage0, pos) * 65535.0; + vec4 p1 = imageLoad(uInputImage1, pos) * 65535.0; + vec4 p2 = imageLoad(uInputImage2, pos) * 65535.0; + vec4 p3 = imageLoad(uInputImage3, pos) * 65535.0; + + NLMCheckOld r; + r.redValRed = p0.xy * 1.0; + r.grSumHRed = p0.zw * 2.0; + r.grSumVRed = p1.xy * 2.0; + r.blueSumRed = p1.zw * 4.0; + r.green1ValG1 = p2.xy * 1.0; + r.redSumG1 = p2.zw * 2.0; + r.blueSumG1 = p3.xy * 2.0; + r.greenSumG1 = p3.zw * 4.0; + return r; +} + +vec4 NonLocalMeans(ivec2 pos, bool evenRow) { + NLMCheckOld c = getCmosCached(pos); + + // Red center derived quantities + vec2 grSumRedC = c.grSumHRed + c.grSumVRed; + vec2 grAveRedC = grSumRedC / 4.0; + vec2 blueAveRedC = c.blueSumRed / 4.0; + vec2 lumaRedC = c.redValRed + grAveRedC + blueAveRedC; + vec2 grBlueDiffRedC = grSumRedC - c.blueSumRed; + vec2 redGrDiffRedC = grAveRedC - c.redValRed; + + vec2 redAveG1C = c.redSumG1 / 2.0; + vec2 blueAveG1C = c.blueSumG1 / 2.0; + vec2 greenAveG1C = c.greenSumG1 / 4.0; + vec2 lumaG1C = redAveG1C + c.green1ValG1 + blueAveG1C; + vec2 grRedDiffG1C = redAveG1C - greenAveG1C; + vec2 grBlueDiffG1C = blueAveG1C - greenAveG1C; + + const float fGrGrAtRedRelThr = 0.5; + const float fBlBlAtRedRelThr = 0.5; + const float fGrGrAtGrRelThr = 0.5; + const float fRdRdAtGreenRelThr = 1.0; + const float fBlBlAtGreenRelThr = 1.0; + const float fDiff4Thr = 3.0; + const float fDiff24Thr = 3.0; + const float fDiff14Thr = 3.0; + + vec2 lumaRThr = sqrt(lumaRedC) * uLumaSqThr; + vec2 patternGRThr = lumaRThr * fGrGrAtRedRelThr; + vec2 patternBRThr = lumaRThr * fBlBlAtRedRelThr; + vec2 gBDiffRThr = lumaRThr * fDiff4Thr; + vec2 redGrDiffRThr = lumaRThr * fDiff14Thr; + + vec2 lumaG1Thr = sqrt(lumaG1C) * uLumaSqThr; + vec2 patternRG1Thr2 = lumaG1Thr * fRdRdAtGreenRelThr; + vec2 patternBG1Thr2 = lumaG1Thr * fBlBlAtGreenRelThr; + vec2 patternGG1Thr = lumaG1Thr * fGrGrAtGrRelThr; + vec2 gRDiffG1Thr = lumaG1Thr * fDiff24Thr; + vec2 gBDiffG1Thr = lumaG1Thr * fDiff24Thr; + + vec2 sumR = vec2(0.0); vec2 countR = vec2(0.0); + vec2 sumG1 = vec2(0.0); vec2 countG1 = vec2(0.0); + + for (int j = -uKernSizeY; j <= uKernSizeY; j += 2) { + for (int i = -uKernSizeX; i <= uKernSizeX; i++) { + NLMCheckOld s = getCmosCached(pos + ivec2(i, j)); + + vec2 grSumRedS = s.grSumHRed + s.grSumVRed; + vec2 grAveRedS = grSumRedS / 4.0; + vec2 blueAveRedS = s.blueSumRed / 4.0; + vec2 lumaRedS = s.redValRed + grAveRedS + blueAveRedS; + vec2 grBlueDiffRedS = grSumRedS - s.blueSumRed; + vec2 redGrDiffRedS = grAveRedS - s.redValRed; + + bvec4 r0 = bvec4( + abs(lumaRedS.x - lumaRedC.x) <= lumaRThr.x && abs(grAveRedS.x - grAveRedC.x) <= patternGRThr.x && abs(blueAveRedS.x - blueAveRedC.x) <= patternBRThr.x && abs(grBlueDiffRedS.x - grBlueDiffRedC.x) <= gBDiffRThr.x && abs(redGrDiffRedS.x - redGrDiffRedC.x) <= redGrDiffRThr.x, + abs(lumaRedS.y - lumaRedC.y) <= lumaRThr.y && abs(grAveRedS.y - grAveRedC.y) <= patternGRThr.y && abs(blueAveRedS.y - blueAveRedC.y) <= patternBRThr.y && abs(grBlueDiffRedS.y - grBlueDiffRedC.y) <= gBDiffRThr.y && abs(redGrDiffRedS.y - redGrDiffRedC.y) <= redGrDiffRThr.y, + abs(lumaRedS.y - lumaRedC.x) <= lumaRThr.x && abs(grAveRedS.y - grAveRedC.x) <= patternGRThr.x && abs(blueAveRedS.y - blueAveRedC.x) <= patternBRThr.x && abs(grBlueDiffRedS.y - grBlueDiffRedC.x) <= gBDiffRThr.x && abs(redGrDiffRedS.y - redGrDiffRedC.x) <= redGrDiffRThr.x, + abs(lumaRedS.x - lumaRedC.y) <= lumaRThr.y && abs(grAveRedS.x - grAveRedC.y) <= patternGRThr.y && abs(blueAveRedS.x - blueAveRedC.y) <= patternBRThr.y && abs(grBlueDiffRedS.x - grBlueDiffRedC.y) <= gBDiffRThr.y && abs(redGrDiffRedS.x - redGrDiffRedC.y) <= redGrDiffRThr.y + ); + if (r0.x) { sumR.x += s.redValRed.x; countR.x += 1.0; } + if (r0.y) { sumR.y += s.redValRed.y; countR.y += 1.0; } + if (r0.z) { sumR.x += s.redValRed.y; countR.x += 1.0; } + if (r0.w) { sumR.y += s.redValRed.x; countR.y += 1.0; } + + vec2 redAveG1S = s.redSumG1 / 2.0; + vec2 blueAveG1S = s.blueSumG1 / 2.0; + vec2 greenAveG1S = s.greenSumG1 / 4.0; + vec2 lumaG1S = redAveG1S + s.green1ValG1 + blueAveG1S; + vec2 grRedDiffG1S = redAveG1S - greenAveG1S; + vec2 grBlueDiffG1S = blueAveG1S - greenAveG1S; + + bvec4 g0 = bvec4( + abs(lumaG1S.x - lumaG1C.x) <= lumaG1Thr.x && abs(redAveG1S.x - redAveG1C.x) <= patternRG1Thr2.x && abs(blueAveG1S.x - blueAveG1C.x) <= patternBG1Thr2.x && abs(grRedDiffG1S.x - grRedDiffG1C.x) <= gRDiffG1Thr.x && abs(grBlueDiffG1S.x - grBlueDiffG1C.x) <= gBDiffG1Thr.x && abs(greenAveG1S.x - greenAveG1C.x) <= patternGG1Thr.x, + abs(lumaG1S.y - lumaG1C.y) <= lumaG1Thr.y && abs(redAveG1S.y - redAveG1C.y) <= patternRG1Thr2.y && abs(blueAveG1S.y - blueAveG1C.y) <= patternBG1Thr2.y && abs(grRedDiffG1S.y - grRedDiffG1C.y) <= gRDiffG1Thr.y && abs(grBlueDiffG1S.y - grBlueDiffG1C.y) <= gBDiffG1Thr.y && abs(greenAveG1S.y - greenAveG1C.y) <= patternGG1Thr.y, + abs(lumaG1S.y - lumaG1C.x) <= lumaG1Thr.x && abs(redAveG1S.y - redAveG1C.x) <= patternRG1Thr2.x && abs(blueAveG1S.y - blueAveG1C.x) <= patternBG1Thr2.x && abs(grRedDiffG1S.y - grRedDiffG1C.x) <= gRDiffG1Thr.x && abs(grBlueDiffG1S.y - grBlueDiffG1C.x) <= gBDiffG1Thr.x && abs(greenAveG1S.y - greenAveG1C.x) <= patternGG1Thr.x, + abs(lumaG1S.x - lumaG1C.y) <= lumaG1Thr.y && abs(redAveG1S.x - redAveG1C.y) <= patternRG1Thr2.y && abs(blueAveG1S.x - blueAveG1C.y) <= patternBG1Thr2.y && abs(grRedDiffG1S.x - grRedDiffG1C.y) <= gRDiffG1Thr.y && abs(grBlueDiffG1S.x - grBlueDiffG1C.y) <= gBDiffG1Thr.y && abs(greenAveG1S.x - greenAveG1C.y) <= patternGG1Thr.y + ); + if (g0.x) { sumG1.x += s.green1ValG1.x; countG1.x += 1.0; } + if (g0.y) { sumG1.y += s.green1ValG1.y; countG1.y += 1.0; } + if (g0.z) { sumG1.x += s.green1ValG1.y; countG1.x += 1.0; } + if (g0.w) { sumG1.y += s.green1ValG1.x; countG1.y += 1.0; } + } + } + + vec4 opix = vec4(c.redValRed.x, c.green1ValG1.x, c.redValRed.y, c.green1ValG1.y); + if (countR.x > 1.0) opix.x = round(sumR.x / countR.x); + if (countG1.x > 1.0) opix.y = round(sumG1.x / countG1.x); + if (countR.y > 1.0) opix.z = round(sumR.y / countR.y); + if (countG1.y > 1.0) opix.w = round(sumG1.y / countG1.y); + + if (!evenRow) + opix = opix.yxwz; + + opix = max(opix - vec4(uOffset), vec4(0.0)); + return opix / 65535.0; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 globalPos = gid + uMargin; + + if (globalPos.x >= uImageSize.x - uKernSizeX || + globalPos.y >= uImageSize.y - uKernSizeY || + globalPos.x < 0 || globalPos.y < 0) { + return; + } + + bool isRedRow = (globalPos.y & 1) == 0; + vec4 result = NonLocalMeans(globalPos, isRedRow); + imageStore(outputImage, gid, result); +} diff --git a/research/phocus_glsl/03_denoise/denoiseCmosG1G2Cached_0x30a66a5.frag b/research/phocus_glsl/03_denoise/denoiseCmosG1G2Cached_0x30a66a5.frag new file mode 100644 index 00000000..f13b404e --- /dev/null +++ b/research/phocus_glsl/03_denoise/denoiseCmosG1G2Cached_0x30a66a5.frag @@ -0,0 +1,242 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 1ea9327fd1b1ce2257eca7ed7bca44ffa74b5d5ba71f8203df26436cd3713f9e + * ELF offsets: 0x30a66a5 + * Symbols: denoiseCmosG1G2Cached_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; // 原始图像 +uniform sampler2D uInputTexture1; // 缓存数据1 (cache0: green1ValG1, redSumG1) +uniform sampler2D uInputTexture2; // 缓存数据2 (cache1: blueSumG1, greenSumG1) +uniform sampler2D uInputTexture3; // 缓存数据3 (cache2: horizSum, vertSum) +uniform sampler2D uInputTexture4; // 缓存数据4 (cache3: diagRSum, diagLSum) + +uniform float uLumaSqThr; +uniform float uDarkLumaMinThr; +uniform float uAvg2RedAtGreenRelThr; +uniform float uAvg4GreenAtGreenRelThr; +uniform float uCrossGreenThr; +uniform float uColorDifferenceLow; +uniform float uColorDifferenceHigh; +uniform float uOfsSub; +uniform float uOfsAdd; +uniform int uKernSizeX; +uniform int uKernSizeY; + +uniform vec2 uTextureSize; +uniform vec2 uInvTextureSize; +uniform vec2 uMargin; + +in vec2 TexCoord; +out vec4 FragColor; + +struct NLMCheckG1G2 { + vec2 green1ValG1; + vec2 redSumG1; + vec2 blueSumG1; + vec2 greenSumG1; + vec2 horizSum; + vec2 vertSum; + vec2 diagRSum; + vec2 diagLSum; +}; + +NLMCheckG1G2 getG1G2Cached(vec2 pos) { + vec2 texCoord = pos * uInvTextureSize; + + vec4 val0 = texture(uInputTexture1, texCoord) * 65535.0; + vec4 val1 = texture(uInputTexture2, texCoord) * 65535.0; + vec4 val2 = texture(uInputTexture3, texCoord) * 65535.0; + vec4 val3 = texture(uInputTexture4, texCoord) * 65535.0; + + NLMCheckG1G2 res; + res.green1ValG1 = val0.xy * 1.0; // green1ValG1 + res.redSumG1 = val0.zw * 2.0; // redSumG1 + res.blueSumG1 = val1.xy * 2.0; // blueSumG1 + res.greenSumG1 = val1.zw * 4.0; // greenSumG1 + res.horizSum = val2.xy * 3.0; // horizSum + res.vertSum = val2.zw * 3.0; // vertSum + res.diagRSum = val3.xy * 3.0; // diagRSum + res.diagLSum = val3.zw * 3.0; // diagLSum + return res; +} + +vec2 noiseThreshold(vec2 value, float ofsSub, float ofsAdd) { + return sqrt(max(value - vec2(ofsSub), vec2(0.0))) + vec2(ofsAdd); +} + +vec4 doG1G2BNR(vec2 pos, bool isRedRow) { + NLMCheckG1G2 c = getG1G2Cached(pos); + + vec2 redAveG1C = c.redSumG1 / 2.0; + vec2 blueAveG1C = c.blueSumG1 / 2.0; + vec2 greenAveG1C = c.greenSumG1 / 4.0; + vec2 lumaG1C = redAveG1C + c.green1ValG1 + greenAveG1C + blueAveG1C; + vec2 redBlueRatioG1C = (c.redSumG1 + vec2(1.0)) / (c.blueSumG1 + vec2(1.0)); + + vec2 lumaG1Thr = noiseThreshold(lumaG1C, uOfsSub, uOfsAdd) * vec2(uLumaSqThr); + lumaG1Thr = max(lumaG1Thr, vec2(uDarkLumaMinThr)); + vec2 avg2RedatG1Thr = lumaG1Thr * vec2(uAvg2RedAtGreenRelThr); + vec2 avg4GreenAtG1Thr = lumaG1Thr * vec2(uAvg4GreenAtGreenRelThr); + vec2 crossGG1CThr = lumaG1Thr * vec2(uCrossGreenThr); + + vec2 sum = vec2(0.0); + vec2 count = vec2(0.0); + + int kernSizeY = uKernSizeY; + int kernSizeX = uKernSizeX; + for (int j = -kernSizeY; j <= kernSizeY; j++) { + for (int i = -kernSizeX; i <= kernSizeX; i++) { + vec2 searchPos = pos + vec2(float(i), float(j)); + NLMCheckG1G2 s = getG1G2Cached(searchPos); + + vec2 redAveG1S = s.redSumG1 / 2.0; + vec2 blueAveG1S = s.blueSumG1 / 2.0; + vec2 greenAveG1S = s.greenSumG1 / 4.0; + vec2 lumaG1S = redAveG1S + s.green1ValG1 + greenAveG1S + blueAveG1S; + + bvec4 g_check = bvec4( + abs(lumaG1S.x - lumaG1C.x) <= lumaG1Thr.x, + abs(lumaG1S.y - lumaG1C.y) <= lumaG1Thr.y, + abs(lumaG1S.y - lumaG1C.x) <= lumaG1Thr.x, + abs(lumaG1S.x - lumaG1C.y) <= lumaG1Thr.y + ); + + bvec4 temp = bvec4( + abs(greenAveG1S.x - greenAveG1C.x) <= avg4GreenAtG1Thr.x, + abs(greenAveG1S.y - greenAveG1C.y) <= avg4GreenAtG1Thr.y, + abs(greenAveG1S.y - greenAveG1C.x) <= avg4GreenAtG1Thr.x, + abs(greenAveG1S.x - greenAveG1C.y) <= avg4GreenAtG1Thr.y + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + + temp = bvec4( + abs(s.horizSum.x - c.horizSum.x) <= crossGG1CThr.x, + abs(s.horizSum.y - c.horizSum.y) <= crossGG1CThr.y, + abs(s.horizSum.y - c.horizSum.x) <= crossGG1CThr.x, + abs(s.horizSum.x - c.horizSum.y) <= crossGG1CThr.y + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + + temp = bvec4( + abs(s.vertSum.x - c.vertSum.x) <= crossGG1CThr.x, + abs(s.vertSum.y - c.vertSum.y) <= crossGG1CThr.y, + abs(s.vertSum.y - c.vertSum.x) <= crossGG1CThr.x, + abs(s.vertSum.x - c.vertSum.y) <= crossGG1CThr.y + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + + temp = bvec4( + abs(s.diagRSum.x - c.diagRSum.x) <= crossGG1CThr.x, + abs(s.diagRSum.y - c.diagRSum.y) <= crossGG1CThr.y, + abs(s.diagRSum.y - c.diagRSum.x) <= crossGG1CThr.x, + abs(s.diagRSum.x - c.diagRSum.y) <= crossGG1CThr.y + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + + temp = bvec4( + abs(s.diagLSum.x - c.diagLSum.x) <= crossGG1CThr.x, + abs(s.diagLSum.y - c.diagLSum.y) <= crossGG1CThr.y, + abs(s.diagLSum.y - c.diagLSum.x) <= crossGG1CThr.x, + abs(s.diagLSum.x - c.diagLSum.y) <= crossGG1CThr.y + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + + if (i == -kernSizeX) { + g_check.w = false; + } + if (i == kernSizeX) { + g_check.z = false; + } + + if ((j & 1) == 0) { + temp = bvec4( + abs(redAveG1S.x - redAveG1C.x) <= avg2RedatG1Thr.x, + abs(redAveG1S.y - redAveG1C.y) <= avg2RedatG1Thr.y, + abs(redAveG1S.y - redAveG1C.x) <= avg2RedatG1Thr.x, + abs(redAveG1S.x - redAveG1C.y) <= avg2RedatG1Thr.y + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + + temp = bvec4( + abs(blueAveG1S.x - blueAveG1C.x) <= avg2RedatG1Thr.x, + abs(blueAveG1S.y - blueAveG1C.y) <= avg2RedatG1Thr.y, + abs(blueAveG1S.y - blueAveG1C.x) <= avg2RedatG1Thr.x, + abs(blueAveG1S.x - blueAveG1C.y) <= avg2RedatG1Thr.y + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + } else { + vec2 redBlueRatioG1S = (s.blueSumG1 + vec2(1.0)) / (s.redSumG1 + vec2(1.0)); + vec4 colorDifference = vec4( + redBlueRatioG1S.x / redBlueRatioG1C.x, + redBlueRatioG1S.y / redBlueRatioG1C.y, + redBlueRatioG1S.y / redBlueRatioG1C.x, + redBlueRatioG1S.x / redBlueRatioG1C.y + ); + + temp = bvec4( + uColorDifferenceLow < colorDifference.x && colorDifference.x < uColorDifferenceHigh, + uColorDifferenceLow < colorDifference.y && colorDifference.y < uColorDifferenceHigh, + uColorDifferenceLow < colorDifference.z && colorDifference.z < uColorDifferenceHigh, + uColorDifferenceLow < colorDifference.w && colorDifference.w < uColorDifferenceHigh + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + } + + if (g_check.x) { + sum.x += s.green1ValG1.x; + count.x += 1.0; + } + if (g_check.y) { + sum.y += s.green1ValG1.y; + count.y += 1.0; + } + if (g_check.z) { + sum.x += s.green1ValG1.y; + count.x += 1.0; + } + if (g_check.w) { + sum.y += s.green1ValG1.x; + count.y += 1.0; + } + } + } + + vec4 opix = texture(uInputTexture0, pos * uInvTextureSize) * 65535.0; + + if (isRedRow) { + if (count.y > 1.0) { + opix.w = round(sum.y / count.y); + } + if (count.x > 1.0) { + opix.y = round(sum.x / count.x); + } + } else { + if (count.x > 1.0) { + opix.x = round(sum.x / count.x); + } + if (count.y > 1.0) { + opix.z = round(sum.y / count.y); + } + } + + return opix / 65535.0; +} + +void main() { + vec2 pixelPos = gl_FragCoord.xy; + vec2 globalPos = pixelPos + uMargin; + + if (globalPos.x >= uTextureSize.x - float(uKernSizeX) || + globalPos.y >= uTextureSize.y - float(uKernSizeY)) { + FragColor = texture(uInputTexture0, globalPos * uInvTextureSize); + return; + } + + bool isRedRow = (int(globalPos.y) & 1) == 0; + FragColor = doG1G2BNR(globalPos, isRedRow); +} diff --git a/research/phocus_glsl/03_denoise/denoiseCmosG1G2Cached_0x30ad00c.comp b/research/phocus_glsl/03_denoise/denoiseCmosG1G2Cached_0x30ad00c.comp new file mode 100644 index 00000000..2f3f2c84 --- /dev/null +++ b/research/phocus_glsl/03_denoise/denoiseCmosG1G2Cached_0x30ad00c.comp @@ -0,0 +1,229 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: e1cd535a47146b36cb176de8b5658dc74be20180f1c78f78e4e09924d3fd964f + * ELF offsets: 0x30ad00c + * Symbols: denoiseCmosG1G2Cached_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; + +layout(rgba16f, binding = 0) readonly restrict uniform image2D uInputImage0; // 原始图像 +layout(rgba16f, binding = 1) readonly restrict uniform image2D uInputImage1; // cache0 +layout(rgba16f, binding = 2) readonly restrict uniform image2D uInputImage2; // cache1 +layout(rgba16f, binding = 3) readonly restrict uniform image2D uInputImage3; // cache2 +layout(rgba16f, binding = 4) readonly restrict uniform image2D uInputImage4; // cache3 +layout(rgba16f, binding = 5) writeonly uniform image2D outputImage; + +uniform float uLumaSqThr; +uniform float uDarkLumaMinThr; +uniform float uAvg2RedAtGreenRelThr; +uniform float uAvg4GreenAtGreenRelThr; +uniform float uCrossGreenThr; +uniform float uColorDifferenceLow; +uniform float uColorDifferenceHigh; +uniform float uOfsSub; +uniform float uOfsAdd; +uniform int uKernSizeX; // = 2 +uniform int uKernSizeY; // = 8 +uniform ivec2 uImageSize; +uniform ivec2 uMargin; + +layout(local_size_x = 16, local_size_y = 16) in; +struct NLMCheckG1G2 { + vec2 green1ValG1; + vec2 redSumG1; + vec2 blueSumG1; + vec2 greenSumG1; + vec2 horizSum; + vec2 vertSum; + vec2 diagRSum; + vec2 diagLSum; +}; + + +NLMCheckG1G2 getG1G2Cached(ivec2 pos) { + vec4 val0 = imageLoad(uInputImage1, pos) * 65535.0; + vec4 val1 = imageLoad(uInputImage2, pos) * 65535.0; + vec4 val2 = imageLoad(uInputImage3, pos) * 65535.0; + vec4 val3 = imageLoad(uInputImage4, pos) * 65535.0; + + NLMCheckG1G2 res; + res.green1ValG1 = val0.xy * 1.0; // green1ValG1 + res.redSumG1 = val0.zw * 2.0; // redSumG1 + res.blueSumG1 = val1.xy * 2.0; // blueSumG1 + res.greenSumG1 = val1.zw * 4.0; // greenSumG1 + res.horizSum = val2.xy * 3.0; // horizSum + res.vertSum = val2.zw * 3.0; // vertSum + res.diagRSum = val3.xy * 3.0; // diagRSum + res.diagLSum = val3.zw * 3.0; // diagLSum + return res; +} + +vec2 noiseThreshold(vec2 value, float ofsSub, float ofsAdd) { + return sqrt(max(value - vec2(ofsSub), vec2(0.0))) + vec2(ofsAdd); +} + +vec4 doG1G2BNR(ivec2 pos, bool isRedRow) { + NLMCheckG1G2 c = getG1G2Cached(pos); + + vec2 redAveG1C = c.redSumG1 / 2.0; + vec2 blueAveG1C = c.blueSumG1 / 2.0; + vec2 greenAveG1C = c.greenSumG1 / 4.0; + vec2 lumaG1C = redAveG1C + c.green1ValG1 + greenAveG1C + blueAveG1C; + vec2 redBlueRatioG1C = (c.redSumG1 + vec2(1.0)) / (c.blueSumG1 + vec2(1.0)); + + vec2 lumaG1Thr = noiseThreshold(lumaG1C, uOfsSub, uOfsAdd) * vec2(uLumaSqThr); + lumaG1Thr = max(lumaG1Thr, vec2(uDarkLumaMinThr)); + vec2 avg2RedatG1Thr = lumaG1Thr * vec2(uAvg2RedAtGreenRelThr); + vec2 avg4GreenAtG1Thr = lumaG1Thr * vec2(uAvg4GreenAtGreenRelThr); + vec2 crossGG1CThr = lumaG1Thr * vec2(uCrossGreenThr); + + vec2 sum = vec2(0.0); + vec2 count = vec2(0.0); + + for (int j = -uKernSizeY; j <= uKernSizeY; j++) { + for (int i = -uKernSizeX; i <= uKernSizeX; i++) { + ivec2 searchPos = pos + ivec2(i, j); + NLMCheckG1G2 s = getG1G2Cached(searchPos); + + vec2 redAveG1S = s.redSumG1 / 2.0; + vec2 blueAveG1S = s.blueSumG1 / 2.0; + vec2 greenAveG1S = s.greenSumG1 / 4.0; + vec2 lumaG1S = redAveG1S + s.green1ValG1 + greenAveG1S + blueAveG1S; + + bvec4 g_check = bvec4( + abs(lumaG1S.x - lumaG1C.x) <= lumaG1Thr.x, + abs(lumaG1S.y - lumaG1C.y) <= lumaG1Thr.y, + abs(lumaG1S.y - lumaG1C.x) <= lumaG1Thr.x, + abs(lumaG1S.x - lumaG1C.y) <= lumaG1Thr.y + ); + + bvec4 temp = bvec4( + abs(greenAveG1S.x - greenAveG1C.x) <= avg4GreenAtG1Thr.x, + abs(greenAveG1S.y - greenAveG1C.y) <= avg4GreenAtG1Thr.y, + abs(greenAveG1S.y - greenAveG1C.x) <= avg4GreenAtG1Thr.x, + abs(greenAveG1S.x - greenAveG1C.y) <= avg4GreenAtG1Thr.y + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + + temp = bvec4( + abs(s.horizSum.x - c.horizSum.x) <= crossGG1CThr.x, + abs(s.horizSum.y - c.horizSum.y) <= crossGG1CThr.y, + abs(s.horizSum.y - c.horizSum.x) <= crossGG1CThr.x, + abs(s.horizSum.x - c.horizSum.y) <= crossGG1CThr.y + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + + temp = bvec4( + abs(s.vertSum.x - c.vertSum.x) <= crossGG1CThr.x, + abs(s.vertSum.y - c.vertSum.y) <= crossGG1CThr.y, + abs(s.vertSum.y - c.vertSum.x) <= crossGG1CThr.x, + abs(s.vertSum.x - c.vertSum.y) <= crossGG1CThr.y + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + + temp = bvec4( + abs(s.diagRSum.x - c.diagRSum.x) <= crossGG1CThr.x, + abs(s.diagRSum.y - c.diagRSum.y) <= crossGG1CThr.y, + abs(s.diagRSum.y - c.diagRSum.x) <= crossGG1CThr.x, + abs(s.diagRSum.x - c.diagRSum.y) <= crossGG1CThr.y + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + + temp = bvec4( + abs(s.diagLSum.x - c.diagLSum.x) <= crossGG1CThr.x, + abs(s.diagLSum.y - c.diagLSum.y) <= crossGG1CThr.y, + abs(s.diagLSum.y - c.diagLSum.x) <= crossGG1CThr.x, + abs(s.diagLSum.x - c.diagLSum.y) <= crossGG1CThr.y + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + + if (i == -uKernSizeX) { + g_check.w = false; + } + if (i == uKernSizeX) { + g_check.z = false; + } + + if ((j & 1) == 0) { + temp = bvec4( + abs(redAveG1S.x - redAveG1C.x) <= avg2RedatG1Thr.x, + abs(redAveG1S.y - redAveG1C.y) <= avg2RedatG1Thr.y, + abs(redAveG1S.y - redAveG1C.x) <= avg2RedatG1Thr.x, + abs(redAveG1S.x - redAveG1C.y) <= avg2RedatG1Thr.y + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + + temp = bvec4( + abs(blueAveG1S.x - blueAveG1C.x) <= avg2RedatG1Thr.x, + abs(blueAveG1S.y - blueAveG1C.y) <= avg2RedatG1Thr.y, + abs(blueAveG1S.y - blueAveG1C.x) <= avg2RedatG1Thr.x, + abs(blueAveG1S.x - blueAveG1C.y) <= avg2RedatG1Thr.y + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + } else { + vec2 redBlueRatioG1S = (s.blueSumG1 + vec2(1.0)) / (s.redSumG1 + vec2(1.0)); + vec4 colorDifference = vec4( + redBlueRatioG1S.x / redBlueRatioG1C.x, + redBlueRatioG1S.y / redBlueRatioG1C.y, + redBlueRatioG1S.y / redBlueRatioG1C.x, + redBlueRatioG1S.x / redBlueRatioG1C.y + ); + + temp = bvec4( + uColorDifferenceLow < colorDifference.x && colorDifference.x < uColorDifferenceHigh, + uColorDifferenceLow < colorDifference.y && colorDifference.y < uColorDifferenceHigh, + uColorDifferenceLow < colorDifference.z && colorDifference.z < uColorDifferenceHigh, + uColorDifferenceLow < colorDifference.w && colorDifference.w < uColorDifferenceHigh + ); + g_check = bvec4(g_check.x && temp.x, g_check.y && temp.y, g_check.z && temp.z, g_check.w && temp.w); + } + + if (g_check.x) { + sum.x += s.green1ValG1.x; + count.x += 1.0; + } + if (g_check.y) { + sum.y += s.green1ValG1.y; + count.y += 1.0; + } + if (g_check.z) { + sum.x += s.green1ValG1.y; + count.x += 1.0; + } + if (g_check.w) { + sum.y += s.green1ValG1.x; + count.y += 1.0; + } + } + } + + vec4 opix = imageLoad(uInputImage0, pos) * 65535.0; + if (isRedRow) { + if (count.y > 1.0) opix.w = round(sum.y / count.y); + if (count.x > 1.0) opix.y = round(sum.x / count.x); + } else { + if (count.x > 1.0) opix.x = round(sum.x / count.x); + if (count.y > 1.0) opix.z = round(sum.y / count.y); + } + return opix / 65535.0; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 globalPos = gid + uMargin; + + if (globalPos.x >= uImageSize.x - uKernSizeX || + globalPos.y >= uImageSize.y - uKernSizeY || + globalPos.x < 0 || globalPos.y < 0) { + vec4 pixel = imageLoad(uInputImage0, globalPos); + imageStore(outputImage, gid, pixel); + return; + } + + bool isRedRow = (globalPos.y & 1) == 0; + vec4 result = doG1G2BNR(globalPos, isRedRow); + imageStore(outputImage, gid, result); +} diff --git a/research/phocus_glsl/03_denoise/denoiseCmosRedBlueCached_0x308f30f.frag b/research/phocus_glsl/03_denoise/denoiseCmosRedBlueCached_0x308f30f.frag new file mode 100644 index 00000000..e9d181a6 --- /dev/null +++ b/research/phocus_glsl/03_denoise/denoiseCmosRedBlueCached_0x308f30f.frag @@ -0,0 +1,182 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: ddf06024ffc6b97bd6e48447543b6b33c79c45a80b2ffdd786f6eaff24177058 + * ELF offsets: 0x308f30f + * Symbols: denoiseCmosRedBlueCached_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; // 原始图像 +uniform sampler2D uInputTexture1; // 缓存数据1 (cache0: redvalRed/1, horizSum/3) +uniform sampler2D uInputTexture2; // 缓存数据2 (cache1: vertSum/3, grAveRed/1) +uniform sampler2D uInputTexture3; // 缓存数据3 (cache2: blueAveRed/1, lumaRed/4) + +uniform float uLumaSqThr; +uniform float uDarkLumaMinThr; +uniform float uAvg4GreenAtRedRelThr; +uniform float uAvg4BlueAtRedRelThr; +uniform float uCrossRedBlueThr; +uniform float uOffset; +uniform float uOfsSub; +uniform float uOfsAdd; +uniform int uKernSizeX; +uniform int uKernSizeY; + +uniform vec2 uTextureSize; +uniform vec2 uInvTextureSize; +uniform vec2 uMargin; + +in vec2 TexCoord; +out vec4 FragColor; + +struct NLMCheckRedBlue { + vec2 redvalRed; + vec2 horizSum; + vec2 vertSum; + vec2 grAveRed; + vec2 blueAveRed; + vec2 lumaRed; +}; + +NLMCheckRedBlue getRedBlueCached(vec2 pos) { + vec2 texCoord = pos * uInvTextureSize; + + vec4 val0 = texture(uInputTexture1, texCoord) * 65535.0; + vec4 val1 = texture(uInputTexture2, texCoord) * 65535.0; + vec4 val2 = texture(uInputTexture3, texCoord) * 65535.0; + + NLMCheckRedBlue res; + res.redvalRed = val0.xy * 1.0; // redvalRed + res.horizSum = val0.zw * 3.0; // horizSum + res.vertSum = val1.xy * 3.0; // vertSum + res.grAveRed = val1.zw * 1.0; // grAveRed + res.blueAveRed = val2.xy * 1.0; // blueAveRed + res.lumaRed = val2.zw * 4.0; // lumaRed + return res; +} + +vec2 noiseThreshold(vec2 value, float ofsSub, float ofsAdd) { + return sqrt(max(value - vec2(ofsSub), vec2(0.0))) + vec2(ofsAdd); +} + +vec4 doRedBlueBNR(vec2 pos, bool isRedRow) { + NLMCheckRedBlue c = getRedBlueCached(pos); + + vec2 avg4GreenAtRedThr = noiseThreshold(c.grAveRed * 4.0, uOfsSub, uOfsAdd) * vec2(uLumaSqThr * uAvg4GreenAtRedRelThr); + vec2 avg4BlueAtRedThr = noiseThreshold(c.blueAveRed * 4.0, uOfsSub, uOfsAdd) * vec2(uLumaSqThr * uAvg4BlueAtRedRelThr); + vec2 lumaRThr = noiseThreshold(c.lumaRed, uOfsSub, uOfsAdd) * vec2(uLumaSqThr); + lumaRThr = max(lumaRThr, vec2(uDarkLumaMinThr)); + vec2 crossRedCThr = lumaRThr * vec2(uCrossRedBlueThr); + + vec2 sum = vec2(0.0); + vec2 count = vec2(0.0); + + int kernSizeY = uKernSizeY; + int kernSizeX = uKernSizeX; + for (int j = -kernSizeY; j <= kernSizeY; j += 2) { + for (int i = -kernSizeX; i <= kernSizeX; i++) { + vec2 searchPos = pos + vec2(float(i), float(j)); + NLMCheckRedBlue s = getRedBlueCached(searchPos); + + bvec4 rb_check = bvec4( + abs(s.lumaRed.x - c.lumaRed.x) <= lumaRThr.x, + abs(s.lumaRed.y - c.lumaRed.y) <= lumaRThr.y, + abs(s.lumaRed.y - c.lumaRed.x) <= lumaRThr.x, + abs(s.lumaRed.x - c.lumaRed.y) <= lumaRThr.y + ); + + bvec4 temp = bvec4( + abs(s.grAveRed.x - c.grAveRed.x) <= avg4GreenAtRedThr.x, + abs(s.grAveRed.y - c.grAveRed.y) <= avg4GreenAtRedThr.y, + abs(s.grAveRed.y - c.grAveRed.x) <= avg4GreenAtRedThr.x, + abs(s.grAveRed.x - c.grAveRed.y) <= avg4GreenAtRedThr.y + ); + rb_check = bvec4(rb_check.x && temp.x, rb_check.y && temp.y, rb_check.z && temp.z, rb_check.w && temp.w); + + temp = bvec4( + abs(s.blueAveRed.x - c.blueAveRed.x) <= avg4BlueAtRedThr.x, + abs(s.blueAveRed.y - c.blueAveRed.y) <= avg4BlueAtRedThr.y, + abs(s.blueAveRed.y - c.blueAveRed.x) <= avg4BlueAtRedThr.x, + abs(s.blueAveRed.x - c.blueAveRed.y) <= avg4BlueAtRedThr.y + ); + rb_check = bvec4(rb_check.x && temp.x, rb_check.y && temp.y, rb_check.z && temp.z, rb_check.w && temp.w); + + temp = bvec4( + abs(s.horizSum.x - c.horizSum.x) <= crossRedCThr.x, + abs(s.horizSum.y - c.horizSum.y) <= crossRedCThr.y, + abs(s.horizSum.y - c.horizSum.x) <= crossRedCThr.x, + abs(s.horizSum.x - c.horizSum.y) <= crossRedCThr.y + ); + rb_check = bvec4(rb_check.x && temp.x, rb_check.y && temp.y, rb_check.z && temp.z, rb_check.w && temp.w); + + temp = bvec4( + abs(s.vertSum.x - c.vertSum.x) <= crossRedCThr.x, + abs(s.vertSum.y - c.vertSum.y) <= crossRedCThr.y, + abs(s.vertSum.y - c.vertSum.x) <= crossRedCThr.x, + abs(s.vertSum.x - c.vertSum.y) <= crossRedCThr.y + ); + rb_check = bvec4(rb_check.x && temp.x, rb_check.y && temp.y, rb_check.z && temp.z, rb_check.w && temp.w); + + if (i == -kernSizeX) { + rb_check.w = false; + } + if (i == kernSizeX) { + rb_check.z = false; + } + + if (rb_check.x) { + sum.x += s.redvalRed.x; + count.x += 1.0; + } + if (rb_check.y) { + sum.y += s.redvalRed.y; + count.y += 1.0; + } + if (rb_check.z) { + sum.x += s.redvalRed.y; + count.x += 1.0; + } + if (rb_check.w) { + sum.y += s.redvalRed.x; + count.y += 1.0; + } + } + } + + vec4 opix = texture(uInputTexture0, pos * uInvTextureSize) * 65535.0; + + if (isRedRow) { + if (count.x > 1.0) { + opix.x = round(sum.x / count.x); + } + if (count.y > 1.0) { + opix.z = round(sum.y / count.y); + } + } else { + if (count.x > 1.0) { + opix.y = round(sum.x / count.x); + } + if (count.y > 1.0) { + opix.w = round(sum.y / count.y); + } + } + opix = max(opix - vec4(uOffset), vec4(0.0)); + + return opix / 65535.0; +} + +void main() { + vec2 pixelPos = gl_FragCoord.xy; + vec2 globalPos = pixelPos + uMargin; + + if (globalPos.x >= uTextureSize.x - float(uKernSizeX) || + globalPos.y >= uTextureSize.y - float(uKernSizeY)) { + FragColor = texture(uInputTexture0, globalPos * uInvTextureSize); + return; + } + bool isRedRow = (int(globalPos.y) & 1) == 0; + FragColor = doRedBlueBNR(globalPos, isRedRow); +} diff --git a/research/phocus_glsl/03_denoise/denoiseCmosRedBlueCached_0x30a8aac.comp b/research/phocus_glsl/03_denoise/denoiseCmosRedBlueCached_0x30a8aac.comp new file mode 100644 index 00000000..e249e1c8 --- /dev/null +++ b/research/phocus_glsl/03_denoise/denoiseCmosRedBlueCached_0x30a8aac.comp @@ -0,0 +1,173 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: ca61491ffb337d564307251c8a95970840228afdc8555f3bb23f75210ea13c12 + * ELF offsets: 0x30a8aac + * Symbols: denoiseCmosRedBlueCached_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; + +// 输入纹理(使用 GL_RGBA16F 格式,半精度浮点) +layout(rgba16f, binding = 0) readonly restrict uniform image2D uInputImage0; +layout(rgba16f, binding = 1) readonly restrict uniform image2D uInputImage1; +layout(rgba16f, binding = 2) readonly restrict uniform image2D uInputImage2; +layout(rgba16f, binding = 3) readonly restrict uniform image2D uInputImage3; +layout(rgba16f, binding = 4) writeonly uniform image2D outputImage; + +// Uniforms(完全一致) +uniform float uLumaSqThr; +uniform float uDarkLumaMinThr; +uniform float uAvg4GreenAtRedRelThr; +uniform float uAvg4BlueAtRedRelThr; +uniform float uCrossRedBlueThr; +uniform float uOffset; +uniform float uOfsSub; +uniform float uOfsAdd; +uniform int uKernSizeX; // = 2 +uniform int uKernSizeY; // = 8 +uniform ivec2 uImageSize; +uniform ivec2 uMargin; + +layout(local_size_x = 16, local_size_y = 16) in; + +struct NLMCheckRedBlue { + vec2 redvalRed; + vec2 horizSum; + vec2 vertSum; + vec2 grAveRed; + vec2 blueAveRed; + vec2 lumaRed; +}; + +NLMCheckRedBlue getRedBlueCached(ivec2 pos) { + vec4 val0 = imageLoad(uInputImage1, pos) * 65535.0; + vec4 val1 = imageLoad(uInputImage2, pos) * 65535.0; + vec4 val2 = imageLoad(uInputImage3, pos) * 65535.0; + + NLMCheckRedBlue res; + res.redvalRed = val0.xy * 1.0; // redvalRed + res.horizSum = val0.zw * 3.0; // horizSum + res.vertSum = val1.xy * 3.0; // vertSum + res.grAveRed = val1.zw * 1.0; // grAveRed + res.blueAveRed = val2.xy * 1.0; // blueAveRed + res.lumaRed = val2.zw * 4.0; // lumaRed + return res; +} + +vec2 noiseThreshold(vec2 value, float ofsSub, float ofsAdd) { + return sqrt(max(value - vec2(ofsSub), vec2(0.0))) + vec2(ofsAdd); +} + +vec4 doRedBlueBNR(ivec2 pos, bool isRedRow) { + NLMCheckRedBlue c = getRedBlueCached(pos); + + vec2 avg4GreenAtRedThr = noiseThreshold(c.grAveRed * 4.0, uOfsSub, uOfsAdd) * vec2(uLumaSqThr * uAvg4GreenAtRedRelThr); + vec2 avg4BlueAtRedThr = noiseThreshold(c.blueAveRed * 4.0, uOfsSub, uOfsAdd) * vec2(uLumaSqThr * uAvg4BlueAtRedRelThr); + vec2 lumaRThr = noiseThreshold(c.lumaRed, uOfsSub, uOfsAdd) * vec2(uLumaSqThr); + lumaRThr = max(lumaRThr, vec2(uDarkLumaMinThr)); + vec2 crossRedCThr = lumaRThr * vec2(uCrossRedBlueThr); + + vec2 sum = vec2(0.0); + vec2 count = vec2(0.0); + + for (int j = -uKernSizeY; j <= uKernSizeY; j += 2) { + for (int i = -uKernSizeX; i <= uKernSizeX; i++) { + ivec2 searchPos = pos + ivec2(i, j); + NLMCheckRedBlue s = getRedBlueCached(searchPos); + + bvec4 rb_check = bvec4( + abs(s.lumaRed.x - c.lumaRed.x) <= lumaRThr.x, + abs(s.lumaRed.y - c.lumaRed.y) <= lumaRThr.y, + abs(s.lumaRed.y - c.lumaRed.x) <= lumaRThr.x, + abs(s.lumaRed.x - c.lumaRed.y) <= lumaRThr.y + ); + + bvec4 temp = bvec4( + abs(s.grAveRed.x - c.grAveRed.x) <= avg4GreenAtRedThr.x, + abs(s.grAveRed.y - c.grAveRed.y) <= avg4GreenAtRedThr.y, + abs(s.grAveRed.y - c.grAveRed.x) <= avg4GreenAtRedThr.x, + abs(s.grAveRed.x - c.grAveRed.y) <= avg4GreenAtRedThr.y + ); + rb_check = bvec4(rb_check.x && temp.x, rb_check.y && temp.y, rb_check.z && temp.z, rb_check.w && temp.w); + + temp = bvec4( + abs(s.blueAveRed.x - c.blueAveRed.x) <= avg4BlueAtRedThr.x, + abs(s.blueAveRed.y - c.blueAveRed.y) <= avg4BlueAtRedThr.y, + abs(s.blueAveRed.y - c.blueAveRed.x) <= avg4BlueAtRedThr.x, + abs(s.blueAveRed.x - c.blueAveRed.y) <= avg4BlueAtRedThr.y + ); + rb_check = bvec4(rb_check.x && temp.x, rb_check.y && temp.y, rb_check.z && temp.z, rb_check.w && temp.w); + + temp = bvec4( + abs(s.horizSum.x - c.horizSum.x) <= crossRedCThr.x, + abs(s.horizSum.y - c.horizSum.y) <= crossRedCThr.y, + abs(s.horizSum.y - c.horizSum.x) <= crossRedCThr.x, + abs(s.horizSum.x - c.horizSum.y) <= crossRedCThr.y + ); + rb_check = bvec4(rb_check.x && temp.x, rb_check.y && temp.y, rb_check.z && temp.z, rb_check.w && temp.w); + + temp = bvec4( + abs(s.vertSum.x - c.vertSum.x) <= crossRedCThr.x, + abs(s.vertSum.y - c.vertSum.y) <= crossRedCThr.y, + abs(s.vertSum.y - c.vertSum.x) <= crossRedCThr.x, + abs(s.vertSum.x - c.vertSum.y) <= crossRedCThr.y + ); + rb_check = bvec4(rb_check.x && temp.x, rb_check.y && temp.y, rb_check.z && temp.z, rb_check.w && temp.w); + + if (i == -uKernSizeX) { + rb_check.w = false; + } + if (i == uKernSizeX) { + rb_check.z = false; + } + + if (rb_check.x) { + sum.x += s.redvalRed.x; + count.x += 1.0; + } + if (rb_check.y) { + sum.y += s.redvalRed.y; + count.y += 1.0; + } + if (rb_check.z) { + sum.x += s.redvalRed.y; + count.x += 1.0; + } + if (rb_check.w) { + sum.y += s.redvalRed.x; + count.y += 1.0; + } + } + } + + vec4 opix = imageLoad(uInputImage0, pos) * 65535.0; + if (isRedRow) { + if (count.x > 1.0) opix.x = round(sum.x / count.x); + if (count.y > 1.0) opix.z = round(sum.y / count.y); + } else { + if (count.x > 1.0) opix.y = round(sum.x / count.x); + if (count.y > 1.0) opix.w = round(sum.y / count.y); + } + opix = max(opix - vec4(uOffset), vec4(0.0)); + return opix / 65535.0; +} + + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 globalPos = gid + uMargin; + + if (globalPos.x >= uImageSize.x - uKernSizeX || + globalPos.y >= uImageSize.y - uKernSizeY || + globalPos.x < 0 || globalPos.y < 0) { + vec4 pixel = imageLoad(uInputImage0, globalPos); + imageStore(outputImage, gid, pixel); + return; + } + + bool isRedRow = (globalPos.y & 1) == 0; + vec4 result = doRedBlueBNR(globalPos, isRedRow); + imageStore(outputImage, gid, result); +} diff --git a/research/phocus_glsl/03_denoise/denoiseGray_0x3068e79.comp b/research/phocus_glsl/03_denoise/denoiseGray_0x3068e79.comp new file mode 100644 index 00000000..c10ec8c8 --- /dev/null +++ b/research/phocus_glsl/03_denoise/denoiseGray_0x3068e79.comp @@ -0,0 +1,222 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 3b723b58db314faac1498ff32b0957b78e2656ad65c28e36e11f52941507401f + * ELF offsets: 0x3068e79 + * Symbols: denoiseGray_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp image2D; + +layout(rgba16f, binding = 0) readonly uniform image2D uInputImage; +layout(rgba16f, binding = 1) writeonly uniform image2D uOutputImage; + +layout(std140, binding = 2) uniform DenoiseGrayParams_UBO { + int marginX; // packed texel units (pixel margin / 4) + int marginY; + int offset; // fSubtractOffset in uint16 space + float lumaSqThr; // CMOS: sqrt-luma threshold / CCD: channel threshold + float patternThr; // pattern threshold + int kernelSizeX; // search window X in pixel units + int kernelSizeY; // search window Y in pixel units + int useCmos; // 1=CMOS, 0=CCD + int debugMode; // debug mode (0=normal, 1-5=debug) + int pad; + int pad1; + int pad2; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +// ============================================================================ +// Read a packed texel and convert from [0,1] to uint16 [0,65535] integer space +// ============================================================================ +ivec4 readTexel(ivec2 pos) { + vec4 val = imageLoad(uInputImage, pos); + return ivec4(val * 65535.0 + 0.5); +} + +// ============================================================================ +// addWithOffset: combines two rows with a 2 sub-pixel offset +// Matches Metal: int4(leftA.w, int3(middleA.xyz)) + int4(int3(middleB.yzw), rightB.x) +// ============================================================================ +ivec4 addWithOffset(ivec4 leftA, ivec4 middleA, ivec4 middleB, ivec4 rightB) { + return ivec4(leftA.w, middleA.x, middleA.y, middleA.z) + + ivec4(middleB.y, middleB.z, middleB.w, rightB.x); +} + +// ============================================================================ +// PatchFeatures: precomputed features for a 3x3 neighborhood +// ============================================================================ +struct PatchFeatures { + ivec4 center; + ivec4 lum; + ivec4 hor; + ivec4 ver; + ivec4 diagN; + ivec4 diagZ; +}; + +PatchFeatures loadPatch(ivec2 pos) { + ivec4 c = readTexel(pos); + ivec4 l = readTexel(pos + ivec2(-1, 0)); + ivec4 r = readTexel(pos + ivec2( 1, 0)); + ivec4 t = readTexel(pos + ivec2( 0, -1)); + ivec4 b = readTexel(pos + ivec2( 0, 1)); + ivec4 lt = readTexel(pos + ivec2(-1, -1)); + ivec4 rt = readTexel(pos + ivec2( 1, -1)); + ivec4 lb = readTexel(pos + ivec2(-1, 1)); + ivec4 rb = readTexel(pos + ivec2( 1, 1)); + + PatchFeatures f; + f.center = c; + f.ver = t + b; + f.hor = addWithOffset(l, c, c, r); + f.diagN = addWithOffset(lt, t, b, rb); + f.diagZ = addWithOffset(lb, b, t, rt); + // luminance: (center*8 + horizontal + vertical + diagN + diagZ) / 2 / 2 / 4 + f.lum = (c * 8 + f.hor + f.ver + f.diagN + f.diagZ) / 2 / 2 / 4; + return f; +} + +// ============================================================================ +// Component-wise AND for bvec4 (GLSL doesn't support && on bvec4) +// ============================================================================ +bvec4 band(bvec4 a, bvec4 b) { + return bvec4(ivec4(a) * ivec4(b)); +} + +// ============================================================================ +// Similarity tests +// Broadcasting: source's channel [ch] is broadcast, compared against center's full vector +// This matches Metal: abs(Left::get(source.feature()) - center.feature()) < threshold +// Result[i] = true means source's channel[ch] is similar to center's channel[i] +// ============================================================================ + +// CMOS similarity: luminance + pattern features +bvec4 isSimilarCmos(int ch, PatchFeatures src, PatchFeatures ctr, ivec4 lumaThr, ivec4 patThr) { + bvec4 r = lessThan(abs(ivec4(src.lum[ch]) - ctr.lum), lumaThr); + r = band(r, lessThan(abs(ivec4(src.hor[ch]) - ctr.hor), patThr * 2)); + r = band(r, lessThan(abs(ivec4(src.ver[ch]) - ctr.ver), patThr * 2)); + r = band(r, lessThan(abs(ivec4(src.diagN[ch]) - ctr.diagN), patThr)); + r = band(r, lessThan(abs(ivec4(src.diagZ[ch]) - ctr.diagZ), patThr)); + return r; +} + +// CCD similarity: center value + pattern features +bvec4 isSimilarCcd(int ch, PatchFeatures src, PatchFeatures ctr, ivec4 chThr, ivec4 patThr) { + bvec4 r = lessThan(abs(ivec4(src.center[ch]) - ctr.center), chThr); + r = band(r, lessThan(abs(ivec4(src.hor[ch]) - ctr.hor), patThr)); + r = band(r, lessThan(abs(ivec4(src.ver[ch]) - ctr.ver), patThr)); + r = band(r, lessThan(abs(ivec4(src.diagN[ch]) - ctr.diagN), patThr)); + r = band(r, lessThan(abs(ivec4(src.diagZ[ch]) - ctr.diagZ), patThr)); + return r; +} + +// ============================================================================ +// Main kernel +// ============================================================================ +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + + // Boundary check for output texture + ivec2 outputSize = imageSize(uOutputImage); + if (gid.x >= outputSize.x || gid.y >= outputSize.y) { + return; + } + + // Calculate source position (in packed texel coords) + ivec2 pos = gid + ivec2(marginX, marginY); + + // Load center kernel (3x3 patch) and precompute features + PatchFeatures ctr = loadPatch(pos); + + // ---- Debug mode 1: Pass-through (output original input) ---- + if (debugMode == 1) { + imageStore(uOutputImage, gid, vec4(ctr.center) / 65535.0); + return; + } + + // ---- Debug mode 2: Visualize luminance feature ---- + if (debugMode == 2) { + imageStore(uOutputImage, gid, vec4(ctr.lum) / 65535.0); + return; + } + + // ---- Compute thresholds (matching iOS Metal exactly in uint16 space) ---- + ivec4 lumaThr; + ivec4 pat2Thr; + if (useCmos != 0) { + // CMOS: lumaThr = floor(sqrt(luminance) * lumaSqThr) + // pat2Thr = floor(lumaThr * patternThr) + lumaThr = ivec4(floor(sqrt(vec4(ctr.lum)) * lumaSqThr)); + pat2Thr = ivec4(floor(vec4(lumaThr) * patternThr)); + } else { + // CCD: fixed thresholds + lumaThr = ivec4(int(lumaSqThr)); + pat2Thr = ivec4(int(patternThr)); + } + + // ---- Non-Local Means loop over search window ---- + // Metal: for iy in [-kernelSizeY, kernelSizeY], ix in [-kernelSizeX/4, kernelSizeX/4] + // skipX = skipY = 1 (matching Metal) + int halfKX = kernelSizeX / 4; + + vec4 sumVal = vec4(0.0); + vec4 countVal = vec4(0.0); + + for (int iy = -kernelSizeY; iy <= kernelSizeY; iy++) { + for (int ix = -halfKX; ix <= halfKX; ix++) { + // Load source kernel and precompute features + PatchFeatures src = loadPatch(pos + ivec2(ix, iy)); + + // Per-channel similarity test and accumulation + // Matches Metal: sum.add(source.isSimilar(center, ...), source.center.x/y/z/w) + for (int ch = 0; ch < 4; ch++) { + bvec4 sim; + if (useCmos != 0) { + sim = isSimilarCmos(ch, src, ctr, lumaThr, pat2Thr); + } else { + sim = isSimilarCcd(ch, src, ctr, lumaThr, pat2Thr); + } + // Add source.center[ch] (scalar broadcast) to each output channel where similar + sumVal += vec4(sim) * float(src.center[ch]); + countVal += vec4(sim); + } + } + } + + // ---- Debug mode 3: Visualize match count ratio ---- + if (debugMode == 3) { + int totalSearched = (2 * kernelSizeY + 1) * (2 * halfKX + 1) * 4; + vec4 ratio = countVal / float(totalSearched); + imageStore(uOutputImage, gid, ratio); + return; + } + + // ---- Debug mode 4: Visualize threshold (lumaThr normalized) ---- + if (debugMode == 4) { + vec4 thrViz = vec4(lumaThr) / 65535.0; + imageStore(uOutputImage, gid, thrViz); + return; + } + + // ---- Average and subtract offset ---- + // Matches Metal: ushort4(sum.average() - offset) + vec4 avg = sumVal / max(countVal, vec4(1.0)); + ivec4 result = ivec4(avg) - offset; + result = max(result, ivec4(0)); + + // ---- Debug mode 5: Output with offset subtraction only (no denoising) ---- + if (debugMode == 5) { + ivec4 noDenoiseResult = max(ctr.center - offset, ivec4(0)); + imageStore(uOutputImage, gid, vec4(noDenoiseResult) / 65535.0); + return; + } + + // Convert back to normalized [0,1] for half float output + vec4 outVal = vec4(result) / 65535.0; + imageStore(uOutputImage, gid, outVal); +} diff --git a/research/phocus_glsl/03_denoise/noiseMinMax_0x3087ae6.frag b/research/phocus_glsl/03_denoise/noiseMinMax_0x3087ae6.frag new file mode 100644 index 00000000..5ff231c8 --- /dev/null +++ b/research/phocus_glsl/03_denoise/noiseMinMax_0x3087ae6.frag @@ -0,0 +1,57 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 55a11b0d14cc518110a0c76d9f01a7fb64092fddbc6f6996b1c321964bd9d0fe + * ELF offsets: 0x3087ae6 + * Symbols: noiseMinMax_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp int; +precision highp sampler2D; + +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform vec2 uMargin; +uniform float uSumThreshold; + +vec4 fetch(ivec2 p, ivec2 ts) { + return texelFetch(uInputTexture0, clamp(p, ivec2(0), ts - 1), 0) * 65535.0; +} + +void main() { + ivec2 texSize = textureSize(uInputTexture0, 0); + ivec2 pos = ivec2(gl_FragCoord.xy) + ivec2(uMargin); + + vec4 tL = fetch(pos + ivec2(-1, -2), texSize); + vec4 tC = fetch(pos + ivec2( 0, -2), texSize); + vec4 tR = fetch(pos + ivec2( 1, -2), texSize); + vec4 mL = fetch(pos + ivec2(-1, 0), texSize); + vec4 mC = fetch(pos, texSize); + vec4 mR = fetch(pos + ivec2( 1, 0), texSize); + vec4 bL = fetch(pos + ivec2(-1, 2), texSize); + vec4 bC = fetch(pos + ivec2( 0, 2), texSize); + vec4 bR = fetch(pos + ivec2( 1, 2), texSize); + + vec4 n0 = vec4(tL.zw, tC.xy); // top-left + vec4 n1 = tC; // top-center + vec4 n2 = vec4(tC.zw, tR.xy); // top-right + vec4 n3 = vec4(mL.zw, mC.xy); // mid-left + vec4 n4 = vec4(mC.zw, mR.xy); // mid-right + vec4 n5 = vec4(bL.zw, bC.xy); // bot-left + vec4 n6 = bC; // bot-center + vec4 n7 = vec4(bC.zw, bR.xy); // bot-right + + vec4 sum = n0 + n1 + n2 + n3 + n4 + n5 + n6 + n7; + + vec4 nMin = min(min(min(n0, n1), min(n2, n3)), min(min(n4, n5), min(n6, n7))); + vec4 nMax = max(max(max(n0, n1), max(n2, n3)), max(max(n4, n5), max(n6, n7))); + + // Only clamp in dark regions (per channel: sum < threshold) + bvec4 isDark = lessThan(sum, vec4(uSumThreshold)); + vec4 clamped = clamp(mC, nMin, nMax); + vec4 result = mix(mC, clamped, vec4(isDark)); + + FragColor = result / 65535.0; +} diff --git a/research/phocus_glsl/03_denoise/rgbNoise_0x3013e52.frag b/research/phocus_glsl/03_denoise/rgbNoise_0x3013e52.frag new file mode 100644 index 00000000..93bbeb7e --- /dev/null +++ b/research/phocus_glsl/03_denoise/rgbNoise_0x3013e52.frag @@ -0,0 +1,26 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 7487a80208c3945d4a0dbdefb2ae83b6696e263985891ee717e0b57ee421b82a + * ELF offsets: 0x3013e52 + * Symbols: rgbNoiseShader + */ + +#version 300 es +precision highp float; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D inputTexture; +uniform float blackOffset; +//uniform vec4 compVecThr; + +void main() { + vec4 res = texture(inputTexture, TexCoord); + + // 对应kernel0: res.rgb = max(vec3(.0), res.rgb - blackOffset); + res.rgb = max(vec3(0.0), res.rgb - blackOffset); + // res.rgb = max(res.rgb, compVecThr.rgb); + + FragColor = res; +} diff --git a/research/phocus_glsl/03_denoise/rgbnr_0x3072e51.frag b/research/phocus_glsl/03_denoise/rgbnr_0x3072e51.frag new file mode 100644 index 00000000..8de90f2a --- /dev/null +++ b/research/phocus_glsl/03_denoise/rgbnr_0x3072e51.frag @@ -0,0 +1,63 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 0e308203f748e9d878cfd3e0006993f4df8c422e6922b8ad5118a91254fc4103 + * ELF offsets: 0x3072e51 + * Symbols: rgbnr_fragmentShaderSource + */ + +#version 300 es +precision highp float; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; + +uniform float uMarginX; +uniform float uMarginY; +uniform int uBlackOffset; +uniform int uKernSize; +uniform int uSkip; +uniform float uLumaThr; +uniform float uChannelThr; + +vec4 CnrRGB(vec2 pos, int kernSize, int skip, float lumaThr, float channelThr, float blackOffset) { + vec4 sum = vec4(0.0); + float count = 0.0; + + vec2 texSize = vec2(textureSize(uInputTexture0, 0)); + + vec4 center = texture(uInputTexture0, pos); + float lumaC = center.r + center.g + center.b; + vec4 lumRgbDiffC = vec4(lumaC, center.r, center.g, center.b); + vec4 lumRgbDiffThr = vec4(lumaThr, channelThr, channelThr, channelThr); + + for (int j = -kernSize; j < kernSize; j += skip) { + for (int i = -kernSize; i < kernSize; i += skip) { + vec2 pixelOffset = vec2(float(i), float(j)); + vec2 texOffset = pixelOffset / texSizeF; + vec2 searchPos = pos + texOffset; + vec4 candidate = texture(uInputTexture0, searchPos); + float luma = candidate.r + candidate.g + candidate.b; + vec4 lumRgbDiffS = vec4(luma, candidate.r, candidate.g, candidate.b); + + bvec4 cond = lessThan(abs(lumRgbDiffS - lumRgbDiffC), lumRgbDiffThr); + if (all(cond)) { + sum += candidate; + count += 1.0; + } + } + } + + vec4 avg = (count > 0.0) ? (sum / count) : center; + vec4 res = avg - blackOffset / 65535.0; + res.a = center.a; + return res; +} + +void main() { + vec2 texSize = vec2(textureSize(uInputTexture0, 0)); + vec2 posPx = TexCoord * texSize + vec2(uMarginX, uMarginY); + vec2 pos = posPx / texSize; + FragColor = CnrRGB(pos, uKernSize, uSkip, uLumaThr, uChannelThr, float(uBlackOffset)); +} diff --git a/research/phocus_glsl/03_denoise/rgbnrcdiff_0x309776e.frag b/research/phocus_glsl/03_denoise/rgbnrcdiff_0x309776e.frag new file mode 100644 index 00000000..de34c248 --- /dev/null +++ b/research/phocus_glsl/03_denoise/rgbnrcdiff_0x309776e.frag @@ -0,0 +1,73 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 54386a68d91b8e178b310919a8c991f2752bdd840fe5a53f4c855be5f7a4f8fb + * ELF offsets: 0x309776e + * Symbols: rgbnrcdiff_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; + +uniform float uMarginX; +uniform float uMarginY; +uniform int uBlackOffset; +uniform int uKernSize; +uniform int uSkip; +uniform float uLumaThr; +uniform float uChannelThr; + +vec4 CnrDiffColor(vec2 pos, int kernSize, int skip, float lumaThr, float channelThr, float blackOffset) { + vec4 sum = vec4(0.0); + float count = 0.0; + + ivec2 texSize = textureSize(uInputTexture0, 0); + vec2 texSizeF = vec2(texSize); + + vec4 center = texture(uInputTexture0, pos); + center = center * 65535.0; + + float lumaC = center.r + center.g + center.b; + vec3 lumGrDiffC = vec3(lumaC, center.g - center.r, center.g - center.b); + vec3 lumCDiffThr = vec3(lumaThr, channelThr, channelThr); + + for (int j = -kernSize; j < kernSize; j += skip) { + for (int i = -kernSize; i < kernSize; i += skip) { + vec2 pixelOffset = vec2(float(i), float(j)); + vec2 texOffset = pixelOffset / texSizeF; + vec2 searchPos = pos + texOffset; + searchPos = clamp(searchPos, vec2(0.0), vec2(1.0)); + + vec4 candidate = texture(uInputTexture0, searchPos); + candidate = candidate * 65535.0; + + float luma = candidate.r + candidate.g + candidate.b; + vec3 lumGrDiffS = vec3(luma, candidate.g - candidate.r, candidate.g - candidate.b); + + bvec3 cond = lessThan(abs(lumGrDiffS - lumGrDiffC), lumCDiffThr); + if (all(cond)) { + sum += candidate; + count += 1.0; + } + } + } + + vec4 avg = (count > 0.0) ? (sum / count) : center; + vec4 res = avg - blackOffset; + res = max(res, vec4(0.0)); + res.a = center.a; + + return res / 65535.0; +} + +void main() { + vec2 inputTexSize = vec2(textureSize(uInputTexture0, 0)); + vec2 posPx = gl_FragCoord.xy + vec2(uMarginX, uMarginY); + vec2 pos = posPx / inputTexSize; + FragColor = CnrDiffColor(pos, uKernSize, uSkip, uLumaThr, uChannelThr, float(uBlackOffset)); +} diff --git a/research/phocus_glsl/03_denoise/rgbnrcdiff_0x30a4eb3.comp b/research/phocus_glsl/03_denoise/rgbnrcdiff_0x30a4eb3.comp new file mode 100644 index 00000000..d9374c93 --- /dev/null +++ b/research/phocus_glsl/03_denoise/rgbnrcdiff_0x30a4eb3.comp @@ -0,0 +1,76 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 52a7d714fa3dcf908389eec8b53aa2dff3e506042127e90909b014dae1708afd + * ELF offsets: 0x30a4eb3 + * Symbols: rgbnrcdiff_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; + +layout(rgba16f, binding = 0) readonly uniform image2D uInputImage; +layout(rgba16f, binding = 1) writeonly uniform image2D outputImage; + +uniform float uMarginX; +uniform float uMarginY; +uniform int uBlackOffset; +uniform int uKernSize; +uniform int uSkip; +uniform float uLumaThr; +uniform float uChannelThr; +uniform ivec2 uImageSize; + +layout(local_size_x = 16, local_size_y = 16) in; +shared vec4 s_cache[41][41]; + +vec4 CnrDiffColor(ivec2 globalPos) { + vec4 sum = vec4(0.0); + float count = 0.0; + vec2 texSizeF = vec2(uImageSize); + + vec4 center = imageLoad(uInputImage, globalPos) * 65535.0; + + float lumaC = center.r + center.g + center.b; + vec3 lumGrDiffC = vec3(lumaC, center.g - center.r, center.g - center.b); + vec3 lumCDiffThr = vec3(uLumaThr, uChannelThr, uChannelThr); + + for (int j = -uKernSize; j <= uKernSize; j += uSkip) { + for (int i = -uKernSize; i <= uKernSize; i += uSkip) { + ivec2 searchPos = globalPos + ivec2(i, j); + // 边界 clamp + searchPos = clamp(searchPos, ivec2(0), uImageSize - ivec2(1)); + vec4 candidate = imageLoad(uInputImage, searchPos) * 65535.0; + + float luma = candidate.r + candidate.g + candidate.b; + vec3 lumGrDiffS = vec3(luma, candidate.g - candidate.r, candidate.g - candidate.b); + + bvec3 cond = lessThan(abs(lumGrDiffS - lumGrDiffC), lumCDiffThr); + if (all(cond)) { + sum += candidate; + count += 1.0; + } + } + } + + vec4 avg = (count > 0.0) ? (sum / count) : center; + vec4 res = avg - float(uBlackOffset); + res = max(res, vec4(0.0)); + res.a = center.a; + return res / 65535.0; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 globalPos = gid + ivec2(uMarginX, uMarginY); + + // 边界检查(如果 margin 足够,可省略) + if (globalPos.x >= uImageSize.x || globalPos.y >= uImageSize.y || + globalPos.x < 0 || globalPos.y < 0) { + imageStore(outputImage, gid, vec4(0.0)); + return; + } + + vec4 result = CnrDiffColor(globalPos); + imageStore(outputImage, gid, result); +} diff --git a/research/phocus_glsl/03_denoise/rgbnrsimple_0x30ac478.comp b/research/phocus_glsl/03_denoise/rgbnrsimple_0x30ac478.comp new file mode 100644 index 00000000..26213f45 --- /dev/null +++ b/research/phocus_glsl/03_denoise/rgbnrsimple_0x30ac478.comp @@ -0,0 +1,102 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 9069bc90a27a2f0b5a7724407e599df01fe3ff0bcd1e09204c41b787eca9886e + * ELF offsets: 0x30ac478 + * Symbols: rgbnrsimple_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; + +layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in; + +layout(rgba16f, binding = 0) readonly uniform image2D inputImage; +layout(rgba16f, binding = 1) writeonly uniform image2D outputImage; + +uniform float blackOffset; +uniform vec4 compVecThr; +uniform int uKernelRadius; +uniform ivec2 uImageSize; + +shared vec4 sharedTile[32][32]; // Max tile: (16 + 2*8) = 32 + +float Luminance(vec4 pix) { + return pix.r + pix.g + pix.b; +} + +vec4 thrCompare(vec4 pix, vec4 pixS, vec4 vecThr) { + vec4 diff = abs(pix - pixS); + vec4 compare = step(diff, vecThr); // step(edge, x): 0.0 if x < edge, else 1.0 + return compare; +} + +vec4 CheckPositionFromShared(ivec2 centerLocal, ivec2 offset, vec4 refPix, vec4 compVecThr) { + ivec2 searchLocal = centerLocal + offset; + // Bounds are guaranteed safe due to shared tile padding + vec4 searchPix = sharedTile[searchLocal.y][searchLocal.x]; + float searchLuma = Luminance(searchPix); + searchPix.a = searchLuma; // overwrite alpha with luminance for compare + + vec4 comp = thrCompare(refPix, searchPix, compVecThr); + float compVal = comp.r * comp.g * comp.b * comp.a; + + searchPix.a = 1.0; // fake count + return compVal * searchPix; +} + +// Calculate mean from sum and count, apply black offset +vec4 CalculateMean(vec4 sumCount, float alpha, float blackOffset) { + vec3 avg = sumCount.rgb / sumCount.a; + avg -= blackOffset; + avg = max(vec3(0.0), avg); // Clamp to non-negative + return vec4(avg, alpha); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 lid = ivec2(gl_LocalInvocationID.xy); + ivec2 groupID = ivec2(gl_WorkGroupID.xy); + + vec4 pixel = imageLoad(inputImage, gid); + + int R = uKernelRadius; + int TILE_SIZE = 16 + 2 * R; + ivec2 tileBase = groupID * 16 - ivec2(R); + + for (int dy = 0; dy < TILE_SIZE; dy += 16) { + for (int dx = 0; dx < TILE_SIZE; dx += 16) { + ivec2 loadPos = lid + ivec2(dx, dy); + ivec2 globalPos = tileBase + loadPos; + // Clamp to image bounds + globalPos = clamp(globalPos, ivec2(0), uImageSize - ivec2(1)); + sharedTile[loadPos.y][loadPos.x] = imageLoad(inputImage, globalPos); + } + } + + // Synchronize: ensure all data is loaded + groupMemoryBarrier(); + barrier(); + + if (gid.x >= uImageSize.x || gid.y >= uImageSize.y) { + return; + } + + ivec2 centerLocal = lid + ivec2(R, R); + vec4 res = sharedTile[centerLocal.y][centerLocal.x]; + + float alpha = res.a; + res.a = Luminance(res); + + vec4 sumCount = vec4(res.r, res.g, res.b, 1.0); + int k = uKernelRadius; + + for (int j = -R; j <= R; ++j) { + for (int i = -R; i <= R; ++i) { + sumCount += CheckPositionFromShared(centerLocal, ivec2(i, j), res, compVecThr); + } + } + + vec4 result = CalculateMean(sumCount, alpha, blackOffset); + imageStore(outputImage, gid, result); +} diff --git a/research/phocus_glsl/03_denoise/rgbnrsimple_NoNR_0x30153ac.frag b/research/phocus_glsl/03_denoise/rgbnrsimple_NoNR_0x30153ac.frag new file mode 100644 index 00000000..e5618419 --- /dev/null +++ b/research/phocus_glsl/03_denoise/rgbnrsimple_NoNR_0x30153ac.frag @@ -0,0 +1,23 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 0c10fd81f389dc085b1747e60fd9c8c89771230c59cddaa9e8abd4092f901a70 + * ELF offsets: 0x30153ac + * Symbols: rgbnrsimple_NoNR_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform vec2 uImageSize; +uniform float blackOffset; +uniform vec4 compVecThr; +void main() { + vec4 res = texture(uInputTexture0, TexCoord); + res.rgb = max(vec3(0.0), res.rgb - blackOffset); + FragColor = res; +} diff --git a/research/phocus_glsl/03_denoise/rgbnrsimple_RGB16_16_0x307cc98.frag b/research/phocus_glsl/03_denoise/rgbnrsimple_RGB16_16_0x307cc98.frag new file mode 100644 index 00000000..9cb8cc5b --- /dev/null +++ b/research/phocus_glsl/03_denoise/rgbnrsimple_RGB16_16_0x307cc98.frag @@ -0,0 +1,62 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: e920533ef360bffa8007445902f5797a221900d0bb56e70312ee08e9ad0135ce + * ELF offsets: 0x307cc98 + * Symbols: rgbnrsimple_RGB16_16_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform vec2 uImageSize; +uniform float blackOffset; +uniform vec4 compVecThr; + +float Luminance(vec4 pix) { + float lum = pix.r + pix.g + pix.b; + return lum; +} + +vec4 thrCompare(vec4 pix, vec4 pixS, vec4 vecThr) { + vec4 diff = abs(pix - pixS); + vec4 compare = step(diff, vecThr); + return compare; +} + +vec4 CheckPosition(vec4 res, vec2 offset) { + vec2 searchcoord = gl_FragCoord.xy + offset; + searchcoord = clamp(searchcoord, vec2(0.0), uImageSize - vec2(1.0)); + vec2 texCoord = searchcoord / uImageSize; + vec4 searchPix = texture(uInputTexture0, texCoord); + searchPix.a = Luminance(searchPix); + vec4 comp = thrCompare(res, searchPix, compVecThr); + float compVal = comp.r * comp.g * comp.b * comp.a; + searchPix.a = 1.0; + return compVal * searchPix; +} + +vec4 CalculateMean(vec4 sumCount, float alpha, float blackOffset) { + vec3 avg = sumCount.rgb / sumCount.a; + avg -= blackOffset; + avg = max(vec3(0.0), avg); + return vec4(avg, alpha); +} + +void main() { + vec4 res = texture(uInputTexture0, TexCoord); + float alpha = res.a; + res.a = Luminance(res); + vec4 sumCount = vec4(res.r, res.g, res.b, 1.0); + int k = 12; + for (int j = -k; j <= k; ++j) { + for (int i = -k; i <= k; ++i) { + sumCount += CheckPosition(res, vec2(float(i), float(j))); + } + } + FragColor = CalculateMean(sumCount, alpha, blackOffset); +} diff --git a/research/phocus_glsl/03_denoise/rgbnrsimple_RGB_4_4_0x3090b73.frag b/research/phocus_glsl/03_denoise/rgbnrsimple_RGB_4_4_0x3090b73.frag new file mode 100644 index 00000000..f4d614b0 --- /dev/null +++ b/research/phocus_glsl/03_denoise/rgbnrsimple_RGB_4_4_0x3090b73.frag @@ -0,0 +1,62 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 47f84ed81f1b2e6cbf16d0263c68697e45353b60ae7299e49cc0614268962284 + * ELF offsets: 0x3090b73 + * Symbols: rgbnrsimple_RGB_4_4_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform vec2 uImageSize; +uniform float blackOffset; +uniform vec4 compVecThr; + +float Luminance(vec4 pix) { + float lum = pix.r + pix.g + pix.b; + return lum; +} + +vec4 thrCompare(vec4 pix, vec4 pixS, vec4 vecThr) { + vec4 diff = abs(pix - pixS); + vec4 compare = step(diff, vecThr); + return compare; +} + +vec4 CheckPosition(vec4 res, vec2 offset) { + vec2 searchcoord = gl_FragCoord.xy + offset; + searchcoord = clamp(searchcoord, vec2(0.0), uImageSize - vec2(1.0)); + vec2 texCoord = searchcoord / uImageSize; + vec4 searchPix = texture(uInputTexture0, texCoord); + searchPix.a = Luminance(searchPix); + vec4 comp = thrCompare(res, searchPix, compVecThr); + float compVal = comp.r * comp.g * comp.b * comp.a; + searchPix.a = 1.0; + return compVal * searchPix; +} + +vec4 CalculateMean(vec4 sumCount, float alpha, float blackOffset) { + vec3 avg = sumCount.rgb / sumCount.a; + avg -= blackOffset; + avg = max(vec3(0.0), avg); + return vec4(avg, alpha); +} + +void main() { + vec4 res = texture(uInputTexture0, TexCoord); + float alpha = res.a; + res.a = Luminance(res); + vec4 sumCount = vec4(res.r, res.g, res.b, 1.0); + int k = 4; + for (int j = -k; j <= k; ++j) { + for (int i = -k; i <= k; ++i) { + sumCount += CheckPosition(res, vec2(float(i), float(j))); + } + } + FragColor = CalculateMean(sumCount, alpha, blackOffset); +} diff --git a/research/phocus_glsl/03_denoise/rgbnrsimple_RGB_8_8_0x3033552.frag b/research/phocus_glsl/03_denoise/rgbnrsimple_RGB_8_8_0x3033552.frag new file mode 100644 index 00000000..64cec348 --- /dev/null +++ b/research/phocus_glsl/03_denoise/rgbnrsimple_RGB_8_8_0x3033552.frag @@ -0,0 +1,62 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 17b63bef6865200eff7286b24f7f02ed3f28adf656a0f7402779fce3e2a77488 + * ELF offsets: 0x3033552 + * Symbols: rgbnrsimple_RGB_8_8_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform vec2 uImageSize; +uniform float blackOffset; +uniform vec4 compVecThr; + +float Luminance(vec4 pix) { + float lum = pix.r + pix.g + pix.b; + return lum; +} + +vec4 thrCompare(vec4 pix, vec4 pixS, vec4 vecThr) { + vec4 diff = abs(pix - pixS); + vec4 compare = step(diff, vecThr); + return compare; +} + +vec4 CheckPosition(vec4 res, vec2 offset) { + vec2 searchcoord = gl_FragCoord.xy + offset; + searchcoord = clamp(searchcoord, vec2(0.0), uImageSize - vec2(1.0)); + vec2 texCoord = searchcoord / uImageSize; + vec4 searchPix = texture(uInputTexture0, texCoord); + searchPix.a = Luminance(searchPix); + vec4 comp = thrCompare(res, searchPix, compVecThr); + float compVal = comp.r * comp.g * comp.b * comp.a; + searchPix.a = 1.0; + return compVal * searchPix; +} + +vec4 CalculateMean(vec4 sumCount, float alpha, float blackOffset) { + vec3 avg = sumCount.rgb / sumCount.a; + avg -= blackOffset; + avg = max(vec3(0.0), avg); + return vec4(avg, alpha); +} + +void main() { + vec4 res = texture(uInputTexture0, TexCoord); + float alpha = res.a; + res.a = Luminance(res); + vec4 sumCount = vec4(res.r, res.g, res.b, 1.0); + int k = 8; + for (int j = -k; j <= k; ++j) { + for (int i = -k; i <= k; ++i) { + sumCount += CheckPosition(res, vec2(float(i), float(j))); + } + } + FragColor = CalculateMean(sumCount, alpha, blackOffset); +} diff --git a/research/phocus_glsl/04_color_tone/ColorCorrectAll_0x301a79e.frag b/research/phocus_glsl/04_color_tone/ColorCorrectAll_0x301a79e.frag new file mode 100644 index 00000000..237564b2 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/ColorCorrectAll_0x301a79e.frag @@ -0,0 +1,261 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: e88d1cf208ed2067ae4d435a12d1f7cc5ff1367b004315b1c823a6c99f7ee6bf + * ELF offsets: 0x301a79e + * Symbols: ColorCorrectAllShader + */ + +#version 300 es +precision highp float; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D inputTexture; +uniform sampler2D colorMap; +uniform sampler2D gradation; +uniform sampler2D localEVMap; +uniform sampler2D localTempMap; +uniform sampler2D localTintMap; +uniform sampler2D tempTable; + +uniform vec4 inputMatrix1; // inputColumn1 +uniform vec4 inputMatrix2; // inputColumn2 +uniform vec4 inputMatrix3; // inputColumn3 +uniform vec4 outputMatrix1; // inputOutColumn1 +uniform vec4 outputMatrix2; // inputOutColumn2 +uniform vec4 outputMatrix3; // inputOutColumn3 + +uniform vec4 gain; // inputGain +uniform vec2 startCbCr; // inputStartCbCr +uniform vec2 cbCrLimits; // inputCbCrLimits +uniform float divFactor; // inputDivFactor +uniform vec2 desatGray; // inputDesatGray +uniform vec4 desatParams; // inputDesatParams +uniform float inputEV; // inputEV +uniform float inputHRFactor; // inputHRFactor +uniform float hrTrunc; // hrTrunc +uniform float hrMax; // hrMax + +uniform float inputTemp; // inputTemp +uniform float inputTint; // inputTint +uniform float tempScale; // inputTempScale +uniform float tintScale; // inputTintScale +uniform vec3 xyzColumn1; // inputXYZColumn1 +uniform vec3 xyzColumn2; // inputXYZColumn2 +uniform vec3 xyzColumn3; // inputXYZColumn3 +uniform float localEV; // inputLocalEV + +uniform int useColorMap; +uniform int useGradation; +uniform int useLocalEV; +uniform int useLocalWB; + + +//参考locEvKernel +vec4 applyLocalEV(vec4 color, sampler2D map, float baseEV, float localEV, float invEV) { + float alpha = color.a; + float factor = (texture(map, TexCoord).a - 0.5) * 2.0; + float locEV = invEV * (factor * localEV); + float displayEV = baseEV + locEV; + color = pow(2.0, displayEV) * color; + color.a = alpha; + return color; +} + +// 参考localWBKernel +vec4 applyLocalWB(vec4 color, sampler2D tempMap, sampler2D tintMap, sampler2D tempTable, + float baseTemp, float baseTint, float tempScale, float tintScale, + vec3 xyzCol1, vec3 xyzCol2, vec3 xyzCol3, float normalize, float hrFactor, vec4 neutralGain) { + + float tempFactor = (texture(tempMap, TexCoord).a - 0.5) * 2.0; + float tintFactor = (texture(tintMap, TexCoord).a - 0.5) * 2.0; + float temp = baseTemp + (tempFactor * tempScale); + temp = min(50000.0, max(2000.0, temp)); + float tint = baseTint + (tintFactor * tintScale); + tint = min(100.0, max(-100.0, tint)); + float internalTint = tint / -3000.0; + + float revTemp = 1000000.0 / temp; + int ix = int(min(revTemp, 100.0) / 10.0); + ix = ix + int((max(100.0, revTemp) - 100.0) / 25.0); + + vec4 ttLow = texture(tempTable, vec2(0.5 + float(ix), 0.5)); + vec4 ttHigh = texture(tempTable, vec2(1.5 + float(ix), 0.5)); + + + float lowW = (ttHigh.r - revTemp) / (ttHigh.r - ttLow.r); + float u = mix(ttHigh.g, ttLow.g, lowW); + float v = mix(ttHigh.b, ttLow.b, lowW); + + float uu1 = 1.0; + float vv1 = ttLow.a; + float uu2 = 1.0; + float vv2 = ttHigh.a; + + float len1 = sqrt(1.0 + vv1 * vv1); + float len2 = sqrt(1.0 + vv2 * vv2); + + uu1 /= len1; + vv1 /= len1; + uu2 /= len2; + vv2 /= len2; + + float uu3 = mix(uu2, uu1, lowW); + float vv3 = mix(vv2, vv1, lowW); + + float len3 = sqrt(uu3 * uu3 + vv3 * vv3); + uu3 /= len3; + vv3 /= len3; + + u += uu3 * internalTint; + v += vv3 * internalTint; + + float x = 1.5 * u / (u - 4.0 * v + 2.0); + float y = v / (u - 4.0 * v + 2.0); + + vec3 xyz = vec3(x, y, 1.0 - x - y); + vec3 gain = vec3(dot(xyz, xyzCol1), dot(xyz, xyzCol2), dot(xyz, xyzCol3)); + + gain.r = max(0.001, gain.r); + gain.g = max(0.001, gain.g); + gain.b = max(0.001, gain.b); + + float minGain = min(min(gain.r, gain.g), gain.b); + float maxGain = max(max(gain.r, gain.g), gain.b); + float refVal = normalize > 0.0 ? minGain : maxGain; + gain = refVal / gain; + + float minGain2 = min(min(gain.r, gain.g), gain.b); + float maxGain2 = max(max(gain.r, gain.g), gain.b); + float locLumScale = maxGain2 / minGain2; + + float maxneutralgain = max(max(neutralGain.r, neutralGain.g), neutralGain.b); + float minneutralgain = min(min(neutralGain.r, neutralGain.g), neutralGain.b); + float globLumScale = maxneutralgain / minneutralgain; + + float locLumFactor = (normalize > 0.0) ? locLumScale / globLumScale : 1.0; + + neutralGain /= maxneutralgain; + + gain.r /= neutralGain.r; + gain.g /= neutralGain.g; + gain.b /= neutralGain.b; + + gain *= locLumFactor; + + color.r *= gain.r; + color.g *= gain.g; + color.b *= gain.b; + + return color; +} + +// 参考boTruncKernel +vec4 applyBoTrunc(vec4 color, vec4 gain, float ev, float hrTrunc, float hrMax) { + float alpha = color.a; + color = color * gain; + color = color / hrTrunc; + color = clamp(color, 0.0, hrMax); + color = color * ev; + color.a = alpha; + return color; +} + +vec2 bilinearLookupPx(sampler2D tex, vec2 coordPx) { + ivec2 size = textureSize(tex, 0); + ivec2 g = ivec2(floor(coordPx)); // grid point + vec2 d = fract(coordPx); // fractional part + + ivec2 clampMax = size - ivec2(2); + g = clamp(g, ivec2(0), clampMax); + + // 四个像素(整数索引) + vec4 sw = texelFetch(tex, g, 0); // (x, y) + vec4 se = texelFetch(tex, g + ivec2(1,0), 0); + vec4 nw = texelFetch(tex, g + ivec2(0,1), 0); + vec4 ne = texelFetch(tex, g + ivec2(1,1), 0); + + vec4 tmpX = mix(sw, se, d.x); + vec4 tmpY = mix(nw, ne, d.x); + vec4 res = mix(tmpX, tmpY, d.y); + + return res.xy; +} + +void main() { + vec4 smp = texture(inputTexture, TexCoord); + float alpha = smp.a; + + smp = applyBoTrunc(smp, gain, inputEV, hrTrunc, hrMax); + + if (useLocalEV > 0) { + smp = applyLocalEV(smp, localEVMap, inputEV, localEV, 1.0 / inputEV); + } + + if (useLocalWB > 0) { + vec4 neutralGain = gain; + smp = applyLocalWB(smp, localTempMap, localTintMap, tempTable, + inputTemp, inputTint, tempScale, tintScale, + xyzColumn1, xyzColumn2, xyzColumn3, 1.0, inputHRFactor, neutralGain); + } + + if (useGradation > 0) { + // todo + } + + smp *= 65535.0; + smp = min(smp, vec4(65535.0, 65535.0, 65535.0, 65535.0)); + + float average = (smp.r + smp.g + smp.b) * 0.3333333; + vec4 vMax = abs(smp - average); + float dMax = max(max(vMax.r, vMax.g), vMax.b); + + float grayWeight = ((dMax / average) - desatGray.x) / (desatGray.y - desatGray.x); + grayWeight = max(min(grayWeight, 1.0), 0.0); + + vec4 YCbCr = vec4(1.0); + YCbCr.x = dot(smp, inputMatrix1); + YCbCr.y = dot(smp, inputMatrix2); + YCbCr.z = dot(smp, inputMatrix3); + + float lowDesatLow = float(YCbCr.x < desatParams.x) * (desatParams.y * YCbCr.x * YCbCr.x + desatParams.z * YCbCr.x + desatParams.w); + float lowDesatHigh = float(YCbCr.x >= desatParams.x); + grayWeight = max(min(grayWeight, lowDesatLow + lowDesatHigh), 0.0); + + YCbCr.x = (YCbCr.x <= 1e-10) ? 1e-10 : YCbCr.x; + float invYxDiv = divFactor / YCbCr.x; + vec2 CbCr = vec2(YCbCr.y, YCbCr.z); + CbCr = CbCr * invYxDiv; + + // ******* Look Up ********* // + if (useColorMap > 0) { + CbCr = CbCr - startCbCr; + vec2 minLimits = vec2(0.5); + vec2 maxLimits = cbCrLimits - vec2(0.5); + vec2 clamped = clamp(CbCr, minLimits, maxLimits); + vec2 pxCoord = clamped - vec2(0.5); + + vec2 CbCrResult = bilinearLookupPx(colorMap, pxCoord); + CbCrResult = CbCrResult * YCbCr.x * grayWeight; + vec4 res = vec4(1.0); + res.x = YCbCr.x + CbCrResult.x * outputMatrix1.y + CbCrResult.y * outputMatrix1.z; + res.y = YCbCr.x + CbCrResult.x * outputMatrix2.y + CbCrResult.y * outputMatrix2.z; + res.z = YCbCr.x + CbCrResult.x * outputMatrix3.y + CbCrResult.y * outputMatrix3.z; + + res = res / 65535.0; + res.a = alpha; + FragColor = res; + } else { + YCbCr.y = YCbCr.y * divFactor; + YCbCr.z = YCbCr.z * divFactor; + + vec4 res = vec4(1.0); + res.x = YCbCr.x + YCbCr.y * outputMatrix1.y + YCbCr.z * outputMatrix1.z; + res.y = YCbCr.x + YCbCr.y * outputMatrix2.y + YCbCr.z * outputMatrix2.z; + res.z = YCbCr.x + YCbCr.y * outputMatrix3.y + YCbCr.z * outputMatrix3.z; + res /= 65535.0; + res.a = alpha; + FragColor = res; + } +} diff --git a/research/phocus_glsl/04_color_tone/HighlightStrength_0x3019721.frag b/research/phocus_glsl/04_color_tone/HighlightStrength_0x3019721.frag new file mode 100644 index 00000000..2272c522 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/HighlightStrength_0x3019721.frag @@ -0,0 +1,122 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 7e01c980ca698783302664399c9fbbf037d161e4df32398671c1faab48b60701 + * ELF offsets: 0x3019721 + * Symbols: HighlightStrengthShader + */ + +#version 300 es +precision highp float; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D inputTexture; + +uniform vec2 uX; // x1, x2 +uniform vec3 uP; // pA, pB, pC +uniform vec3 uPh; // phA, phB, phC +uniform vec2 uL; // lA, lB +uniform float uStrengthBlend; +uniform float uSaturationBlend; +uniform float uAmountSatFact; + +const float kGammaHasselbladRgb = 2.2; + +vec3 rgb2hsl(vec3 rgb) { + float min1 = min(rgb.r, min(rgb.g, rgb.b)); + float max1 = max(rgb.r, max(rgb.g, rgb.b)); + + float precis = 0.00001; + float l = clamp((max1 + min1) / 2.0, precis, 1.0 - precis); + float max_min = max1 - min1; + float absMax_min = abs(max_min); + max_min = (absMax_min > precis) ? absMax_min : precis; + + float s = step(l, 0.5) * (max_min * 0.5) / l + (1.0 - step(l, 0.5)) * max_min / (2.0 - 2.0 * l); + if (absMax_min < precis) { + s = 0.0; + } + + float hr = step(max1, rgb.r) * (1.0 - step(max1, rgb.b)) * (60.0 * ((rgb.g - rgb.b) / (max_min) + step(rgb.g, rgb.b) * 6.0)); + float hg = step(max1, rgb.g) * (1.0 - step(max1, rgb.r)) * (60.0 * (rgb.b - rgb.r) / (max_min) + 120.0); + float hb = step(max1, rgb.b) * (1.0 - step(max1, rgb.g)) * (60.0 * (rgb.r - rgb.g) / (max_min) + 240.0); + float h = step(min1, max1) * (hr + hg + hb); + + return vec3(h, s, l); +} + +vec3 hsl2rgb(vec3 hsl) { + float h = hsl.r; + float s = hsl.g; + float l = hsl.b; + + float q = step(l, 0.5) * l * (1.0 + s) + (1.0 - step(l, 0.5)) * (l + s - l * s); + float p = 2.0 * l - q; + float hk = fract(h / 360.0); + + vec4 tc = vec4(hk + step(hk, 2.0/3.0)/3.0 - (1.0 - step(hk, 2.0/3.0)) * 2.0/3.0, + hk, + hk - (1.0 - step(hk, 1.0/3.0)) * 1.0/3.0 + step(hk, 1.0/3.0) * 2.0/3.0, + 1.0); + + float r = tc.r; + float g = tc.g; + float b = tc.b; + + float r1 = step(r, 1.0/6.0) * (p + (q - p) * 6.0 * r) + (1.0 - step(r, 1.0/6.0)) * (step(r, 0.5) * q + (1.0 - step(r, 0.5)) * (step(r, 2.0/3.0) * (p + (q - p) * 6.0 * (2.0/3.0 - r)) + (1.0 - step(r, 2.0/3.0)) * p)); + float g1 = step(g, 1.0/6.0) * (p + (q - p) * 6.0 * g) + (1.0 - step(g, 1.0/6.0)) * (step(g, 0.5) * q + (1.0 - step(g, 0.5)) * (step(g, 2.0/3.0) * (p + (q - p) * 6.0 * (2.0/3.0 - g)) + (1.0 - step(g, 2.0/3.0)) * p)); + float b1 = step(b, 1.0/6.0) * (p + (q - p) * 6.0 * b) + (1.0 - step(b, 1.0/6.0)) * (step(b, 0.5) * q + (1.0 - step(b, 0.5)) * (step(b, 2.0/3.0) * (p + (q - p) * 6.0 * (2.0/3.0 - b)) + (1.0 - step(b, 2.0/3.0)) * p)); + + return vec3(r1, g1, b1); +} + +vec3 HighlightL(vec3 input, vec2 X, vec3 P, vec2 L) { + vec3 resP = input * input * P.x + input * P.y + P.z; + vec3 resL = input * L.x + L.y; + return mix(mix(resL, resP, step(X.y, input)), input, step(X.x, input)); +} + +vec3 HighlightP(vec3 input, vec2 X, vec3 P, vec3 Ph) { + vec3 resP = input * input * P.x + input * P.y + P.z; + vec3 resPh = input * input * Ph.x + input * Ph.y + Ph.z; + return mix(mix(resPh, resP, step(X.y, input)), input, step(X.x, input)); +} + +vec3 ApplyHighlightStrength(vec3 rgbIn, vec2 X, vec3 P, vec3 Ph, vec2 L, float strengthBlend, float saturationBlend, float amountSatFact) { +// rgbIn = pow(rgbIn, vec3(kGammaHasselbladRgb)); + + vec3 rgbHStrength; + if (strengthBlend > 0.0) { + rgbHStrength = HighlightP(rgbIn, X, P, Ph); + } else { + rgbHStrength = HighlightL(rgbIn, X, P, L); + } + + rgbIn = clamp(rgbIn, 0.0, 1.0); + rgbHStrength = clamp(rgbHStrength, 0.0, 1.0); + + vec3 hslIn = rgb2hsl(rgbIn); + vec3 hslOut = rgb2hsl(rgbHStrength); + + float a = hslOut[1] - hslIn[1]; + float b = hslIn[1] - (a / 2.0) * amountSatFact; + float blendSat = max(a * saturationBlend + b, 0.0); + + float blendLum = (1.0 - strengthBlend) * hslIn[2] + strengthBlend * hslOut[2]; + + vec3 rgbOut = hsl2rgb(vec3(hslIn[0], blendSat, blendLum)); + rgbHStrength = rgbOut; + +// rgbHStrength = pow(rgbHStrength, vec3(1.0 / kGammaHasselbladRgb)); + + return rgbHStrength; +} + +void main() { + vec4 pixelColor = texture(inputTexture, TexCoord); + + vec3 result = ApplyHighlightStrength(pixelColor.rgb, uX, uP, uPh, uL, uStrengthBlend, uSaturationBlend, uAmountSatFact); + + FragColor = vec4(result, pixelColor.a); +} diff --git a/research/phocus_glsl/04_color_tone/colorCorrectAll_0x3027dea.frag b/research/phocus_glsl/04_color_tone/colorCorrectAll_0x3027dea.frag new file mode 100644 index 00000000..ad555bf5 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/colorCorrectAll_0x3027dea.frag @@ -0,0 +1,256 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: dbaac65ca38e9a2fc2156b3cdce40f6bc9ef41150a8e7c5e2473b7556f7de8e7 + * ELF offsets: 0x3027dea + * Symbols: colorCorrectAll_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform sampler2D uInputTexture1; +//uniform sampler2D uInputTexture2; +//uniform sampler2D uInputTexture3; +//uniform sampler2D uInputTexture4; +//uniform sampler2D uInputTexture5; +//uniform sampler2D uInputTexture6; + + +uniform vec4 uInputMatrix1; +uniform vec4 uInputMatrix2; +uniform vec4 uInputMatrix3; +uniform vec4 uOutputMatrix1; +uniform vec4 uOutputMatrix2; +uniform vec4 uOutputMatrix3; + +uniform vec4 uGain; +uniform vec2 uStartCbCr; +uniform vec2 uCbCrLimits; +uniform float uDivFactor; +uniform vec2 uDesatGray; +uniform vec4 uDesatParams; +uniform float uInputEV; +//uniform float uInputHRFactor; +uniform float uHrTrunc; +uniform float uHrMax; + +//uniform float uInputTemp; +//uniform float uInputTint; +//uniform float uTempScale; +//uniform float uTintScale; +//uniform vec3 uXYZColumn1; +//uniform vec3 uXYZColumn2; +//uniform vec3 uXYZColumn3; +//uniform float uLocalEV; + +uniform int uUseColorMap; +//uniform int uUseGradation; +//uniform int uUseLocalEV; +//uniform int uUseLocalWB; + + +//参考locEvKernel +vec4 applyLocalEV(vec4 color, sampler2D map, float baseEV, float localEV, float invEV) { + float alpha = color.a; + float factor = (texture(map, TexCoord).a - 0.5) * 2.0; + float locEV = invEV * (factor * localEV); + float displayEV = baseEV + locEV; + color = pow(2.0, displayEV) * color; + color.a = alpha; + return color; +} + +// 参考localWBKernel +vec4 applyLocalWB(vec4 color, sampler2D tempMap, sampler2D tintMap, sampler2D tempTable, + float baseTemp, float baseTint, float tempScale, float tintScale, + vec3 xyzCol1, vec3 xyzCol2, vec3 xyzCol3, float normalize, float hrFactor, vec4 neutralGain) { + + float tempFactor = (texture(tempMap, TexCoord).a - 0.5) * 2.0; + float tintFactor = (texture(tintMap, TexCoord).a - 0.5) * 2.0; + float temp = baseTemp + (tempFactor * tempScale); + temp = min(50000.0, max(2000.0, temp)); + float tint = baseTint + (tintFactor * tintScale); + tint = min(100.0, max(-100.0, tint)); + float internalTint = tint / -3000.0; + + float revTemp = 1000000.0 / temp; + int ix = int(min(revTemp, 100.0) / 10.0); + ix = ix + int((max(100.0, revTemp) - 100.0) / 25.0); + + vec4 ttLow = texture(tempTable, vec2(0.5 + float(ix), 0.5)); + vec4 ttHigh = texture(tempTable, vec2(1.5 + float(ix), 0.5)); + + + float lowW = (ttHigh.r - revTemp) / (ttHigh.r - ttLow.r); + float u = mix(ttHigh.g, ttLow.g, lowW); + float v = mix(ttHigh.b, ttLow.b, lowW); + + float uu1 = 1.0; + float vv1 = ttLow.a; + float uu2 = 1.0; + float vv2 = ttHigh.a; + + float len1 = sqrt(1.0 + vv1 * vv1); + float len2 = sqrt(1.0 + vv2 * vv2); + + uu1 /= len1; + vv1 /= len1; + uu2 /= len2; + vv2 /= len2; + + float uu3 = mix(uu2, uu1, lowW); + float vv3 = mix(vv2, vv1, lowW); + + float len3 = sqrt(uu3 * uu3 + vv3 * vv3); + uu3 /= len3; + vv3 /= len3; + + u += uu3 * internalTint; + v += vv3 * internalTint; + + float x = 1.5 * u / (u - 4.0 * v + 2.0); + float y = v / (u - 4.0 * v + 2.0); + + vec3 xyz = vec3(x, y, 1.0 - x - y); + vec3 gain = vec3(dot(xyz, xyzCol1), dot(xyz, xyzCol2), dot(xyz, xyzCol3)); + + gain.r = max(0.001, gain.r); + gain.g = max(0.001, gain.g); + gain.b = max(0.001, gain.b); + + float minGain = min(min(gain.r, gain.g), gain.b); + float maxGain = max(max(gain.r, gain.g), gain.b); + float refVal = normalize > 0.0 ? minGain : maxGain; + gain = refVal / gain; + + float minGain2 = min(min(gain.r, gain.g), gain.b); + float maxGain2 = max(max(gain.r, gain.g), gain.b); + float locLumScale = maxGain2 / minGain2; + + float maxneutralgain = max(max(neutralGain.r, neutralGain.g), neutralGain.b); + float minneutralgain = min(min(neutralGain.r, neutralGain.g), neutralGain.b); + float globLumScale = maxneutralgain / minneutralgain; + + float locLumFactor = (normalize > 0.0) ? locLumScale / globLumScale : 1.0; + + neutralGain /= maxneutralgain; + + gain.r /= neutralGain.r; + gain.g /= neutralGain.g; + gain.b /= neutralGain.b; + + gain *= locLumFactor; + + color.r *= gain.r; + color.g *= gain.g; + color.b *= gain.b; + + return color; +} + +// 参考boTruncKernel +vec4 applyBoTrunc(vec4 color, float ev, float hrTrunc, float hrMax) { + float alpha = color.a; + color = color / hrTrunc; + color = clamp(color, 0.0, hrMax); + color = color * ev; + color.a = alpha; + return color; +} + +vec2 bilinearLookupPx(sampler2D tex, vec2 coordPx) { + ivec2 size = textureSize(tex, 0); + ivec2 g = ivec2(floor(coordPx)); // grid point + vec2 d = fract(coordPx); // fractional part + + ivec2 clampMax = size - ivec2(2); + g = clamp(g, ivec2(0), clampMax); + + // 四个像素(整数索引) + vec4 sw = texelFetch(tex, g, 0); // (x, y) + vec4 se = texelFetch(tex, g + ivec2(1,0), 0); + vec4 nw = texelFetch(tex, g + ivec2(0,1), 0); + vec4 ne = texelFetch(tex, g + ivec2(1,1), 0); + + vec4 tmpX = mix(sw, se, d.x); + vec4 tmpY = mix(nw, ne, d.x); + vec4 res = mix(tmpX, tmpY, d.y); + + return res.xy; +} + +void main() { + vec4 smp = texture(uInputTexture0, TexCoord); + float alpha = smp.a; + smp = applyBoTrunc(smp, uInputEV, uHrTrunc, uHrMax); + +// if (uUseLocalEV > 0) { +// smp = applyLocalEV(smp, uInputTexture3, uInputEV, uLocalEV, 1.0 / uInputEV); +// } +// +// if (uUseLocalWB > 0) { +// vec4 neutralGain = uGain; +// smp = applyLocalWB(smp, uInputTexture4, uInputTexture5, uInputTexture6, +// uInputTemp, uInputTint, uTempScale, uTintScale, +// uXYZColumn1, uXYZColumn2, uXYZColumn3, 1.0, uInputHRFactor, neutralGain); +// } +// +// if (uUseGradation > 0) { +// // todo +// } + + smp *= 65535.0; + smp = min(smp, vec4(65535.0, 65535.0, 65535.0, 65535.0)); + + float average = (smp.r + smp.g + smp.b) * 0.3333333; + vec4 vMax = abs(smp - average); + float dMax = max(max(vMax.r, vMax.g), vMax.b); + + float grayWeight = ((dMax / average) - uDesatGray.x) / (uDesatGray.y - uDesatGray.x); + grayWeight = max(min(grayWeight, 1.0), 0.0); + + vec4 YCbCr = vec4(1.0); + YCbCr.x = dot(smp, uInputMatrix1); + YCbCr.y = dot(smp, uInputMatrix2); + YCbCr.z = dot(smp, uInputMatrix3); + + float lowDesatLow = float(YCbCr.x < uDesatParams.x) * (uDesatParams.y * YCbCr.x * YCbCr.x + uDesatParams.z * YCbCr.x + uDesatParams.w); + float lowDesatHigh = float(YCbCr.x >= uDesatParams.x); + grayWeight = max(min(grayWeight, lowDesatLow + lowDesatHigh), 0.0); + + YCbCr.x = (YCbCr.x <= 1e-10) ? 1e-10 : YCbCr.x; + float invYxDiv = uDivFactor / YCbCr.x; + vec2 CbCr = vec2(YCbCr.y, YCbCr.z); + CbCr = CbCr * invYxDiv; + // ******* Look Up ********* // + if (uUseColorMap > 0) { + CbCr = CbCr - uStartCbCr; + CbCr = clamp(CbCr, vec2(0.0), uCbCrLimits); + vec2 CbCrResult = bilinearLookupPx(uInputTexture1, CbCr); + CbCrResult = CbCrResult * YCbCr.x * grayWeight; + vec4 res = vec4(1.0); + res.x = YCbCr.x + CbCrResult.x * uOutputMatrix1.y + CbCrResult.y * uOutputMatrix1.z; + res.y = YCbCr.x + CbCrResult.x * uOutputMatrix2.y + CbCrResult.y * uOutputMatrix2.z; + res.z = YCbCr.x + CbCrResult.x * uOutputMatrix3.y + CbCrResult.y * uOutputMatrix3.z; + + res = res / 65535.0; + res.a = alpha; + FragColor = res; + } else { + YCbCr.y = YCbCr.y * uDivFactor; + YCbCr.z = YCbCr.z * uDivFactor; + + vec4 res = vec4(1.0); + res.x = YCbCr.x + YCbCr.y * uOutputMatrix1.y + YCbCr.z * uOutputMatrix1.z; + res.y = YCbCr.x + YCbCr.y * uOutputMatrix2.y + YCbCr.z * uOutputMatrix2.z; + res.z = YCbCr.x + YCbCr.y * uOutputMatrix3.y + YCbCr.z * uOutputMatrix3.z; + res /= 65535.0; + res.a = alpha; + FragColor = res; + } +} diff --git a/research/phocus_glsl/04_color_tone/color_correct_0x303b6ab.comp b/research/phocus_glsl/04_color_tone/color_correct_0x303b6ab.comp new file mode 100644 index 00000000..d8dfd392 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/color_correct_0x303b6ab.comp @@ -0,0 +1,150 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 708bb034bd1ad908db5512e780831df43eae055e5b1752f29d49d8710d1ed0b5 + * ELF offsets: 0x303b6ab + * Symbols: color_correct_computeShaderSource + */ + +#version 310 es +layout(local_size_x = 16, local_size_y = 16) in; +precision highp float; +precision highp int; +precision highp uimage2D; + +layout(std140, binding = 5) uniform ColorCorrectParams { + vec4 uRgb2YccR; // 0-16 + vec4 uRgb2YccG; // 16-32 + vec4 uRgb2YccB; // 32-48 + vec4 uCbVec; // 48-64 + vec4 uCrVec; // 64-80 + vec4 uDesatParabel; // 80-96 + + float uOutputScale; // 96 + float uGrayLow; // 100 + float uGrayHigh; // 104 + float uNoDesatLimit; // 108 + + float uCbStart; // 112 + float uCrStart; // 116 + float uEv; // 120 + int uIsRepo; // 124 + + int uMarginX; // 128 + int uMarginY; // 132 + int uHasLinearization;// 136 + int uLutW; // 140 — CbCrLut width (passed explicitly; imageSize unreliable on IMG) + int uLutH; // 144 — CbCrLut height + int pad0; // 148 + int pad1; // 152 (total 160 bytes) +} params; + +layout(rgba16f, binding = 0) readonly uniform highp image2D uInput; +layout(rgba16ui,binding = 1) readonly uniform highp uimage2D uLinearization; +layout(rgba16ui,binding = 2) readonly uniform highp uimage2D uLinearizationF; +layout(rgba16f, binding = 3) readonly uniform highp image2D uCbCrLut; +layout(rgba16f, binding = 4) writeonly uniform highp image2D uOutput; + +float getLinearizationSample(float value) { + int base = clamp(int(value), 0, 65535); + int next = min(base + 1, 65535); + float delta = value - float(base); + float res0 = float(imageLoad(uLinearization, ivec2(base % 256, base / 256)).r); + float res1 = float(imageLoad(uLinearization, ivec2(next % 256, next / 256)).r); + return mix(res0, res1, delta); +} + +float getLinearizationFSample(float value) { + int base = clamp(int(value), 0, 65535); + int next = min(base + 1, 65535); + float delta = value - float(base); + float res0 = float(imageLoad(uLinearizationF, ivec2(base % 256, base / 256)).r); + float res1 = float(imageLoad(uLinearizationF, ivec2(next % 256, next / 256)).r); + return mix(res0, res1, delta); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 outSize = imageSize(uOutput); + if (gid.x >= outSize.x || gid.y >= outSize.y) return; + + ivec2 inputCoord = gid + ivec2(params.uMarginX, params.uMarginY); + vec4 inputPixel = imageLoad(uInput, inputCoord) * 65535.0; + + if (params.uHasLinearization == 1) { + vec3 fnoEV = inputPixel.rgb / params.uEv; + + if (fnoEV.r <= 65535.0) { + float lin = getLinearizationSample(fnoEV.r); + inputPixel.r = clamp(lin * params.uEv, 0.0, 65535.0); + } + if (fnoEV.g <= 65535.0) { + float lin = getLinearizationSample(fnoEV.g); + inputPixel.g = clamp(lin * params.uEv, 0.0, 65535.0); + } + if (fnoEV.b <= 65535.0) { + float lin = getLinearizationSample(fnoEV.b); + inputPixel.b = clamp(lin * params.uEv, 0.0, 65535.0); + } + } + + float averageRaw = (inputPixel.r + inputPixel.g + inputPixel.b) / 3.0; + vec3 d = abs(inputPixel.rgb - averageRaw); + float dMax = max(d.r, max(d.g, d.b)); + + float grayWeight = 1.0; + if (dMax < params.uGrayHigh * averageRaw) { + grayWeight = (dMax / averageRaw - params.uGrayLow) / (params.uGrayHigh - params.uGrayLow); + } + + vec4 yccVec = inputPixel.r * params.uRgb2YccR + + inputPixel.g * params.uRgb2YccG + + inputPixel.b * params.uRgb2YccB; + + vec3 ycc = yccVec.xyz; + float Y = ycc.x; + + if (params.uIsRepo == 0) { + float lowDesat = 1.0; + if (ycc.x > params.uNoDesatLimit) { + lowDesat = 1.0; + } else { + lowDesat = params.uDesatParabel.x * Y * Y + params.uDesatParabel.y * Y + params.uDesatParabel.z; + } + grayWeight = min(lowDesat, grayWeight); + } + grayWeight = max(0.0, grayWeight); + + float invYxDiv = params.uOutputScale / Y; + + float Cbo = ycc.y; + float Cro = ycc.z; + + ivec2 lutSize = ivec2(params.uLutW, params.uLutH) - 1; + + vec2 lutIdx = vec2(Cbo * invYxDiv - params.uCbStart, Cro * invYxDiv - params.uCrStart); + lutIdx = clamp(lutIdx, vec2(0.0), vec2(lutSize)); + + ivec2 lutIdx0 = ivec2(lutIdx); + ivec2 lutIdx1 = clamp(lutIdx0 + 1, ivec2(0), lutSize); + vec2 delta = lutIdx - vec2(lutIdx0); + + vec2 v00 = imageLoad(uCbCrLut, ivec2(lutIdx0.x, lutIdx0.y)).xy; + vec2 v10 = imageLoad(uCbCrLut, ivec2(lutIdx1.x, lutIdx0.y)).xy; + vec2 v01 = imageLoad(uCbCrLut, ivec2(lutIdx0.x, lutIdx1.y)).xy; + vec2 v11 = imageLoad(uCbCrLut, ivec2(lutIdx1.x, lutIdx1.y)).xy; + + vec2 resY = mix(v00, v10, delta.x); + vec2 resX = mix(v01, v11, delta.x); + vec2 cbcr = mix(resY, resX, delta.y); + + ycc.yz = cbcr * grayWeight * Y; + + vec3 rgb; + rgb = vec3(ycc.x) + (params.uCbVec.rgb * ycc.y) + (params.uCrVec.rgb * ycc.z); + + rgb.r = getLinearizationFSample(rgb.r); + rgb.g = getLinearizationFSample(rgb.g); + rgb.b = getLinearizationFSample(rgb.b); + + imageStore(uOutput, gid, vec4(rgb / 65535.0, 1.0)); +} diff --git a/research/phocus_glsl/04_color_tone/colorspaceconvert_0x2ff7cb6.frag b/research/phocus_glsl/04_color_tone/colorspaceconvert_0x2ff7cb6.frag new file mode 100644 index 00000000..be7b0c1d --- /dev/null +++ b/research/phocus_glsl/04_color_tone/colorspaceconvert_0x2ff7cb6.frag @@ -0,0 +1,154 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 4af76a0e1e5dc2e9d4788f439d2c1615d0e1086a480d91d016b8d12d9a51f5d6 + * ELF offsets: 0x2ff7cb6 + * Symbols: colorspaceconvert_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +// define white color chroma adaptation conversion types +const int CHROMA_CONVERT_IGNORE = 0; +const int CHROMA_CONVERT_D50_TO_D65 = 1; +const int CHROMA_CONVERT_D65_TO_D50 = 2; + +// define target transfer function value +const int E_TRANSFER_FUNC_GAMMA22 = 0; +const int E_TRANSFER_FUNC_SRGB = 1; +const int E_TRANSFER_FUNC_PQ = 2; +const int E_TRANSFER_FUNC_NONE = 3; +const int E_TRANSFER_FUNC_GAMMA2199 = 4; + +// define const matrices, GLSL mat3() uses COLUMN-MAJOR order +// Bradford chromatic adaptation D50 -> D65 +const mat3 kChromaMatrixD50ToD65 = mat3( + 0.9555766, -0.0282895, 0.0122982, // column 0 + -0.0230393, 1.0099416, -0.0204830, // column 1 + 0.0631636, 0.0210077, 1.3299098 // column 2 +); + +// Bradford chromatic adaptation D65 -> D50 +const mat3 kChromaMatrixD65ToD50 = mat3( + 1.0478112, 0.0295424, -0.0092345, // column 0 + 0.0228866, 0.9904844, 0.0150436, // column 1 + -0.0501270, -0.0170491, 0.7521316 // column 2 +); + + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; + +// -- color space conversion matrices -- // +// source color space RGB -> XYZ matrix +uniform mat3 uSrcToXYZMatrix; +// XYZ -> target color space RGB matrix (need to be inverted from standard icc profile) +uniform mat3 uXYZToDstMatrix; + +// chromatic adaption option +uniform int uChromaOption; +// target transfer function option +uniform int uTargetTF; + +// process hdr option +uniform int uProcessHdr; +// hdr parameters +// const max value +uniform float uHdrMaxGain; +// limited value from color correction settings +uniform float uHdrLimitGain; +// configurable gamma encode value (e.g. 2.19921875 for Adobe RGB) +uniform float uGammaEncode; + + +// Transfer functions +// encode linear rgb +void Gamma22_EOTF(inout vec3 color) { + // for hdr only clamp 0 + color = max(color, vec3(0.0f)); + color = pow(color, vec3(2.2f)); +} + +void Gamma22_EOTF_Inverse(inout vec3 color) { + // for hdr only clamp 0 + color = max(color, vec3(0.0f)); + color = pow(color, vec3(1.0f / 2.2f)); +} + +void PQ_EOTF_Inverse(inout vec3 color) { + // Normalize linear light [0, maxGain] to PQ input [0, 1] where 1.0 = 10000 nits + color = color / uHdrMaxGain; + color = max(color, vec3(0.0)); + vec3 m1 = vec3(0.1593017578125f); + vec3 m2 = vec3(78.84375f); + vec3 c1 = vec3(0.8359375f); + float c2 = 18.8515625f; + float c3 = 18.6875f; + vec3 linear_m1 = pow(color, m1); + color = pow((c1 + linear_m1 * c2) / (vec3(1.0f) + linear_m1 * c3), m2); +} + +// Configurable gamma encode (e.g. gamma 2.19921875 for Adobe RGB) +void GammaCustom_EOTF_Inverse(inout vec3 color) { + color = max(color, vec3(0.0)); + color = pow(color, vec3(1.0 / uGammaEncode)); +} + +// 颜色空间转换主函数 +// Todo - 目前不支持处理输入为LStar色域的流程 +void ConvertColorSpace(inout vec3 rgb) { + // 步骤1: 输入解码,目前HDR流程中已经是Linear RGB色域,因此不需要进行解码;而SDR为gamma编码,需要对应解码 + if (uProcessHdr == 0) { + Gamma22_EOTF(rgb); + } + + // 步骤2: Source RGB -> XYZ (相对于Hasselblad白点) + rgb = uSrcToXYZMatrix * rgb; + + // 步骤3: 色度适配 Bradford变换, 目前支持D50与D65之间互转 + switch (uChromaOption) { + case CHROMA_CONVERT_D50_TO_D65: + rgb = kChromaMatrixD50ToD65 * rgb; + break; + + case CHROMA_CONVERT_D65_TO_D50: + rgb = kChromaMatrixD65ToD50 * rgb; + break; + + case CHROMA_CONVERT_IGNORE: + default: + break; + } + + // 步骤4:XYZ -> Target RGB + rgb = uXYZToDstMatrix * rgb; + + // 步骤5:Encode transfer function + switch (uTargetTF) { + case E_TRANSFER_FUNC_GAMMA22: + Gamma22_EOTF_Inverse(rgb); + break; + case E_TRANSFER_FUNC_PQ: + PQ_EOTF_Inverse(rgb); + break; + case E_TRANSFER_FUNC_GAMMA2199: + GammaCustom_EOTF_Inverse(rgb); + break; + case E_TRANSFER_FUNC_SRGB: // not support yet + case E_TRANSFER_FUNC_NONE: + default: + break; + } +} + +void main() { + vec4 pixelColor = texture(uInputTexture0, TexCoord); + float alpha = pixelColor.a; + + // 应用颜色空间转换 + ConvertColorSpace(pixelColor.rgb); + FragColor = vec4(pixelColor.rgb, alpha); +} diff --git a/research/phocus_glsl/04_color_tone/customCmm_0x3011778.frag b/research/phocus_glsl/04_color_tone/customCmm_0x3011778.frag new file mode 100644 index 00000000..6ce266a2 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/customCmm_0x3011778.frag @@ -0,0 +1,79 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 1d2a52b7d24ec0b6d2d2b4100a2c467d18b50a73cd46a5570e77fd86788fe7a7 + * ELF offsets: 0x3011778 + * Symbols: customCmm_fragmentShaderSource + */ + +#version 300 es +precision highp float; + +uniform sampler2D uInputTexture0; +uniform mat3 uMat; // Color conversion matrix (same layout as FromSRgb) +uniform ivec2 uMargin; // rect.Offset() - srcRect.Offset() +uniform float uScaleIn; +uniform float uScaleOut; +uniform float uGammaIn; +uniform float uGammaOut; +uniform int uTransferIn; // TransferCurve enum: 0=Linear, 1=Gamma, 2=sRGB +uniform int uTransferOut; + +out vec4 FragColor; + +// --- sRGB transfer functions (same as FromSRgbShader.h + Metal sRgb2linear/linear2sRgb) --- + +float sRgbToLinear(float v) { + if (v <= 0.04045) return v / 12.92; + return pow((v + 0.055) / 1.055, 2.4); +} + +float linearToSRgb(float v) { + if (v <= 0.0031308) return v * 12.92; + return pow(v, 1.0 / 2.4) * 1.055 - 0.055; +} + +// --- ConvertFloat — mirrors Metal ConvertFloat() in FromSRgb.metal:122-154 --- + +vec3 ConvertFloat(vec3 value) { + // Step 1: scaleIn + value *= uScaleIn; + + // Step 2: transferIn (linearize) + if (uTransferIn == 1) { + value = pow(value, vec3(uGammaIn)); + } else if (uTransferIn == 2) { + value.r = sRgbToLinear(value.r); + value.g = sRgbToLinear(value.g); + value.b = sRgbToLinear(value.b); + } + // uTransferIn == 0 (Linear): passthrough + + // Step 3: matrix + value = uMat * value; + + // Step 4: scaleOut + value *= uScaleOut; + + // Step 5: transferOut (encode) + if (uTransferOut == 1) { + value = pow(value, vec3(1.0 / uGammaOut)); + } else if (uTransferOut == 2) { + value.r = linearToSRgb(value.r); + value.g = linearToSRgb(value.g); + value.b = linearToSRgb(value.b); + } + // uTransferOut == 0 (Linear): passthrough + + return value; +} + +// --- main --- +// Android uses RgbX (GL_RGBA16F, [0,1] range) — no PixelCast/65535 needed. +// Alpha channel is preserved unchanged (same as Metal kernel). + +void main() { + ivec2 coord = ivec2(gl_FragCoord.xy) + uMargin; + vec4 pix = texelFetch(uInputTexture0, coord, 0); + vec3 converted = ConvertFloat(pix.rgb); + FragColor = vec4(converted, pix.a); +} diff --git a/research/phocus_glsl/04_color_tone/customColorSpace_0x3034aab.frag b/research/phocus_glsl/04_color_tone/customColorSpace_0x3034aab.frag new file mode 100644 index 00000000..d433f760 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/customColorSpace_0x3034aab.frag @@ -0,0 +1,83 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: a2290578fd48972ba0cb065428ae5307ac013d2b0d0f4607d20014b480e3c842 + * ELF offsets: 0x3034aab + * Symbols: customColorSpaceShader + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D inputTexture; +uniform mat3 combinedMatrix; +uniform vec3 gamma; +uniform vec3 whitePoint; +uniform vec3 blackPoint; +uniform int isLinearized; // 0=原始自定义空间, 1=已线性化 + +// 应用自定义gamma校正 +vec3 applyCustomGamma(vec3 color, vec3 gamma) { + return pow(max(color, vec3(0.0)), gamma); +} + +// 应用逆gamma校正(从自定义空间到线性) +vec3 applyInverseGamma(vec3 color, vec3 gamma) { + vec3 invGamma = vec3(1.0) / gamma; + return pow(max(color, vec3(0.0)), invGamma); +} + +// 应用白点和黑点校正 +vec3 applyWhiteBlackPoint(vec3 color, vec3 whitePoint, vec3 blackPoint) { + // 从黑点到白点的线性映射,添加除零保护 + vec3 diff = whitePoint - blackPoint; + vec3 result; + for (int i = 0; i < 3; i++) { + if (abs(diff[i]) < 0.001) { + result[i] = color[i]; // 如果差值为0,保持原值 + } else { + result[i] = (color[i] - blackPoint[i]) / diff[i]; + } + } + return result; +} + +void main() { + vec4 inputColor = texture(inputTexture, TexCoord); + vec3 color = inputColor.rgb; + + // 调试:在左上角显示输入颜色 + if (TexCoord.x < 0.1 && TexCoord.y < 0.1) { + FragColor = vec4(color, 1.0); + return; + } + + if (isLinearized == 0) { + // 原始自定义空间:需要先线性化 + // 1. 应用逆gamma校正,将自定义gamma空间转换为线性空间 + // color = applyInverseGamma(color, gamma); + + // 2. 应用白点和黑点校正 + color = applyWhiteBlackPoint(color, whitePoint, blackPoint); + } else { + // 已经线性化:直接应用白点和黑点校正 + color = applyWhiteBlackPoint(color, whitePoint, blackPoint); + } + + // 3. 应用组合转换矩阵(自定义RGB -> XYZ -> Extended Linear Display P3) + color = combinedMatrix * color; + + // 4. 确保结果在有效范围内 + color = max(color, vec3(0.0)); + + // 调试:在右上角显示输出颜色 + if (TexCoord.x > 0.9 && TexCoord.y < 0.1) { + FragColor = vec4(color, 1.0); + return; + } + + FragColor = vec4(color, inputColor.a); +} diff --git a/research/phocus_glsl/04_color_tone/desatHighLight_0x308164a.frag b/research/phocus_glsl/04_color_tone/desatHighLight_0x308164a.frag new file mode 100644 index 00000000..20e691eb --- /dev/null +++ b/research/phocus_glsl/04_color_tone/desatHighLight_0x308164a.frag @@ -0,0 +1,109 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 22ee7adff61fc23e5f879983fa06ae574dbfc040734178d2c83992d4f2350fcc + * ELF offsets: 0x308164a + * Symbols: desatHighLight_computeShaderSource + */ + +#version 300 es +precision highp float; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; + +uniform vec3 uLumC; // 亮度系数 [0.2, 0.6, 0.2] +uniform float uLumMin; // 最小亮度阈值 (0-65535范围) +uniform float uLumDyn; // 动态范围 (0-65535范围) +uniform float uAlpha; // 混合系数 (0-1范围) +uniform float uMaxValue; // 最大值 (65535) +uniform vec2 uMarginOffset; // 偏移量 + +vec3 rgb2hsv(vec3 rgb) { + float r = rgb.r; + float g = rgb.g; + float b = rgb.b; + + float minVal = min(min(r, g), b); + float maxVal = max(max(r, g), b); + float delta = maxVal - minVal; + + vec3 hsv = vec3(0.0, 0.0, maxVal); + + if (maxVal != 0.0) { + hsv.y = delta / maxVal; + } + + if (delta != 0.0) { + if (maxVal == r) { + if (g >= b) { + hsv.x = 60.0 * (g - b) / delta; + } else { + hsv.x = 60.0 * (g - b) / delta + 360.0; + } + } else if (maxVal == g) { + hsv.x = 60.0 * (b - r) / delta + 120.0; + } else { + hsv.x = 60.0 * (r - g) / delta + 240.0; + } + } + + return hsv; +} + +vec3 hsv2rgb(vec3 hsv) { + float hue = hsv.x / 60.0; + int i = int(floor(hue)); + float f = fract(hue); + if ((i & 1) == 0) { + f = 1.0 - f; + } + + float m = hsv.z * (1.0 - hsv.y); + float n = hsv.z * (1.0 - hsv.y * f); + + vec3 rgb = vec3(0.0); + + if (i == 0 || i == 6) { + rgb = vec3(hsv.z, n, m); + } else if (i == 1) { + rgb = vec3(n, hsv.z, m); + } else if (i == 2) { + rgb = vec3(m, hsv.z, n); + } else if (i == 3) { + rgb = vec3(m, n, hsv.z); + } else if (i == 4) { + rgb = vec3(n, m, hsv.z); + } else if (i == 5) { + rgb = vec3(hsv.z, m, n); + } + + return rgb; +} + +void main() { + vec4 inputPixel = texture(uInputTexture0, TexCoord); + + vec3 rgbScaled = inputPixel.rgb * uMaxValue; + + float lum = dot(rgbScaled, uLumC); + + vec3 result = rgbScaled; + + if (lum > uLumMin) { + vec3 hsv = rgb2hsv(rgbScaled); + + float relLum = clamp((lum - uLumMin) / uLumDyn, 0.0, 1.0); + + float sDesat = clamp((1.0 - relLum) * hsv.y, 0.0, 1.0); + + vec3 rgbDesat = hsv2rgb(vec3(hsv.x, sDesat, hsv.z)); + + result = mix(rgbScaled, rgbDesat, uAlpha); + } + + result = result / uMaxValue; + + FragColor = vec4(result, inputPixel.a); +} diff --git a/research/phocus_glsl/04_color_tone/desatHighLight_0x308e22a.frag b/research/phocus_glsl/04_color_tone/desatHighLight_0x308e22a.frag new file mode 100644 index 00000000..9c61db32 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/desatHighLight_0x308e22a.frag @@ -0,0 +1,116 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 992c5335469160b73bcabb680b1cead43a5e0c7669ac3aad4f3c196eb8ac55c3 + * ELF offsets: 0x308e22a + * Symbols: desatHighLight_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; + +uniform vec3 uLumC; +uniform float uLumMin; +uniform float uLumDyn; +uniform float uAlpha; +uniform float uMaxValue; +uniform vec2 uMarginOffset; + +// RGB到HSV转换函数 (基于Metal实现,使用0-360度色相范围) +vec3 rgb2hsv(vec3 rgb) { + float r = rgb.r; + float g = rgb.g; + float b = rgb.b; + + float minVal = min(min(r, g), b); + float maxVal = max(max(r, g), b); + float delta = maxVal - minVal; + + vec3 hsv = vec3(0.0, 0.0, maxVal); + + if (maxVal != 0.0) { + hsv.y = delta / maxVal; + } + + if (delta != 0.0) { + if (maxVal == r) { + if (g >= b) { + hsv.x = 60.0 * (g - b) / delta; + } else { + hsv.x = 60.0 * (g - b) / delta + 360.0; + } + } else if (maxVal == g) { + hsv.x = 60.0 * (b - r) / delta + 120.0; + } else { + hsv.x = 60.0 * (r - g) / delta + 240.0; + } + } + + return hsv; +} + +// HSV到RGB转换函数 (基于Metal实现,使用0-360度色相范围) +vec3 hsv2rgb(vec3 hsv) { + float hue = hsv.x / 60.0; + int i = int(floor(hue)); + float f = fract(hue); + + if ((i & 1) == 0) { + f = 1.0 - f; + } + + float m = hsv.z * (1.0 - hsv.y); + float n = hsv.z * (1.0 - hsv.y * f); + + vec3 rgb = vec3(0.0); + + if (i == 0 || i == 6) { + rgb = vec3(hsv.z, n, m); + } else if (i == 1) { + rgb = vec3(n, hsv.z, m); + } else if (i == 2) { + rgb = vec3(m, hsv.z, n); + } else if (i == 3) { + rgb = vec3(m, n, hsv.z); + } else if (i == 4) { + rgb = vec3(n, m, hsv.z); + } else if (i == 5) { + rgb = vec3(hsv.z, m, n); + } + + return rgb; +} + +void main() { + ivec2 inputSize = textureSize(uInputTexture0, 0); + vec2 inputPixelCoord = gl_FragCoord.xy + uMarginOffset; + vec2 uv = inputPixelCoord / vec2(inputSize); + vec4 inputPixel = texture(uInputTexture0, uv); + + vec3 rgbScaled = inputPixel.rgb * uMaxValue; + + float lum = dot(rgbScaled, uLumC); + + vec3 result = rgbScaled; + + if (lum > uLumMin) { + vec3 hsv = rgb2hsv(rgbScaled); + + float relLum = clamp((lum - uLumMin) / uLumDyn, 0.0, 1.0); + + float sDesat = clamp((1.0 - relLum) * hsv.y, 0.0, 1.0); + + vec3 rgbDesat = hsv2rgb(vec3(hsv.x, sDesat, hsv.z)); + + result = mix(rgbScaled, rgbDesat, uAlpha); + } + + result = result / uMaxValue; + + FragColor = vec4(result, inputPixel.a); +} diff --git a/research/phocus_glsl/04_color_tone/filmCurve_0x30a3daf.frag b/research/phocus_glsl/04_color_tone/filmCurve_0x30a3daf.frag new file mode 100644 index 00000000..3c4b10e8 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/filmCurve_0x30a3daf.frag @@ -0,0 +1,43 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 7272d4bc97a33ee3855b9d2a7cad4d0843a6480c8fa8cd2341f65b3e6c429e8c + * ELF offsets: 0x30a3daf + * Symbols: filmCurveShader + */ + +#version 300 es +precision highp float; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D inputTexture; +uniform sampler2D filmCurveTexture; +uniform vec2 dimensions; + +vec4 ApplyGradation(vec4 rgb) { + float extentW = dimensions.x; + float extentH = dimensions.y; + float fullRes = extentW * extentH; + vec4 index = clamp(rgb * fullRes, 0.0, fullRes - 1.0); + + vec2 coordR = vec2(0.5 + floor(mod(index.r, extentW)), 0.5 + floor(index.r / extentW)); + vec2 coordG = vec2(0.5 + floor(mod(index.g, extentW)), 0.5 + floor(index.g / extentW)); + vec2 coordB = vec2(0.5 + floor(mod(index.b, extentW)), 0.5 + floor(index.b / extentW)); + + coordR = coordR / dimensions; + coordG = coordG / dimensions; + coordB = coordB / dimensions; + + rgb.r = texture(filmCurveTexture, coordR).r; + rgb.g = texture(filmCurveTexture, coordG).g; + rgb.b = texture(filmCurveTexture, coordB).b; + + return rgb; +} + +void main() { + vec4 rgb = texture(inputTexture, TexCoord); + rgb = ApplyGradation(rgb); + FragColor = rgb; +} diff --git a/research/phocus_glsl/04_color_tone/filmcurve_0x3040c4d.frag b/research/phocus_glsl/04_color_tone/filmcurve_0x3040c4d.frag new file mode 100644 index 00000000..1862d55b --- /dev/null +++ b/research/phocus_glsl/04_color_tone/filmcurve_0x3040c4d.frag @@ -0,0 +1,47 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: c678f85151e14960313ee0e0b16fa1ed9c6041ac3144a9f1174a76853e540d17 + * ELF offsets: 0x3040c4d + * Symbols: filmcurve_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform sampler2D uInputTexture1; + +uniform vec2 uDimensions; +uniform float uGain; + +vec4 ApplyGradation(vec4 rgb) { + float extentW = uDimensions.x; + float extentH = uDimensions.y; + float fullRes = extentW * extentH; + vec4 index = clamp(rgb * fullRes, 0.0, fullRes - 1.0); + + vec2 coordR = vec2(0.5 + floor(mod(index.r, extentW)), 0.5 + floor(index.r / extentW)); + vec2 coordG = vec2(0.5 + floor(mod(index.g, extentW)), 0.5 + floor(index.g / extentW)); + vec2 coordB = vec2(0.5 + floor(mod(index.b, extentW)), 0.5 + floor(index.b / extentW)); + + coordR = coordR / uDimensions; + coordG = coordG / uDimensions; + coordB = coordB / uDimensions; + + rgb.r = texture(uInputTexture1, coordR).r; + rgb.g = texture(uInputTexture1, coordG).g; + rgb.b = texture(uInputTexture1, coordB).b; + + return rgb; +} + +void main() { + vec4 rgb = texture(uInputTexture0, TexCoord); + rgb.rgb = rgb.rgb / uGain; + rgb = ApplyGradation(rgb); + FragColor = rgb; +} diff --git a/research/phocus_glsl/04_color_tone/gamma_hasselblad_0x30776ff.frag b/research/phocus_glsl/04_color_tone/gamma_hasselblad_0x30776ff.frag new file mode 100644 index 00000000..f72fb15d --- /dev/null +++ b/research/phocus_glsl/04_color_tone/gamma_hasselblad_0x30776ff.frag @@ -0,0 +1,25 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 121ebee892224e11b60d72f04e14bd10e2c685e2fdc66d5f4f8dae647bd0e421 + * ELF offsets: 0x30776ff + * Symbols: gamma_hasselblad_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform float uHDRMaxGain; +uniform float uHasselbladHdrRgbLimit; +uniform float uGammaHasselbladRgb; + +void main() { + vec4 res = texture(uInputTexture0, TexCoord); + vec3 pixProc = res.rgb * uHDRMaxGain; + pixProc = pow(pixProc, vec3(1.0 / uGammaHasselbladRgb)); + res.rgb = pixProc / uHasselbladHdrRgbLimit; + FragColor = res; +} diff --git a/research/phocus_glsl/04_color_tone/gamma_lstar_0x307356f.frag b/research/phocus_glsl/04_color_tone/gamma_lstar_0x307356f.frag new file mode 100644 index 00000000..4d667b60 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/gamma_lstar_0x307356f.frag @@ -0,0 +1,34 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 3bdbd36600685c42e163ed2aed8e89cb2135cb71e3601d7b002681c923cdcaaf + * ELF offsets: 0x307356f + * Symbols: gamma_lstar_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform float uHDRMaxGain; +uniform float uHasselbladHdrRgbLimit; +uniform float uLStarEpsilon; +uniform float uLStarKappa; + +void main() { + const float eps = uLStarEpsilon; + const float kap = uLStarKappa; + vec4 res = texture(uInputTexture0, TexCoord); + vec3 pixProc = res.rgb * uHDRMaxGain; + vec3 vLo = pixProc * kap / 100.0; + vec3 vHi = 1.16 * pow(pixProc, vec3(1.0 / 3.0)) - 0.16; + vec3 pixGamma; + pixGamma.r = pixProc.r <= eps ? vLo.r : vHi.r; + pixGamma.g = pixProc.g <= eps ? vLo.g : vHi.g; + pixGamma.b = pixProc.b <= eps ? vLo.b : vHi.b; + res.rgb = pixGamma / uHasselbladHdrRgbLimit; + + FragColor = res; +} diff --git a/research/phocus_glsl/04_color_tone/gradation_0x30778de.frag b/research/phocus_glsl/04_color_tone/gradation_0x30778de.frag new file mode 100644 index 00000000..aebaddc2 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/gradation_0x30778de.frag @@ -0,0 +1,163 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: c6952101afd99df4bc3bb0f5b3061b5b7dfaca6392921b3758889f0a6b1aa926 + * ELF offsets: 0x30778de + * Symbols: gradation_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; // 原始图像 +uniform sampler2D uRgbCurve; // RGB 基础曲线 LUT +uniform sampler2D uContrastCurve; // 对比度 LUT +uniform sampler2D uLumaUserCurve; // 亮度 LUT + +uniform int uHasContrast; +uniform int uLumaPoints; +uniform int uVersion; + +const float bitscale = 65536.0; +const float eps = 1e-7; + +// 更稳定的 LUT 查找函数 +vec3 lookupCurve(sampler2D lut, vec3 inputColor) { + inputColor = clamp(inputColor, 0.0, 1.0); + + // 映射到 [0, 65535] + vec3 scaled = inputColor * (bitscale - 1.0); + + // 分别获取 R/G/B 对应的坐标 (x, y),范围是 [0, 255] + float rIndex = scaled.r; + float gIndex = scaled.g; + float bIndex = scaled.b; + + // 整数部分作为 Y 坐标,余数作为 X 坐标 + float ry = floor(rIndex / 256.0); + float rx = mod(rIndex, 256.0); + float gy = floor(gIndex / 256.0); + float gx = mod(gIndex, 256.0); + float by = floor(bIndex / 256.0); + float bx = mod(bIndex, 256.0); + + // 归一化 UV 坐标用于 texture() + vec2 ruv = vec2((rx + 0.5)/256.0, (ry + 0.5)/256.0); + vec2 guv = vec2((gx + 0.5)/256.0, (gy + 0.5)/256.0); + vec2 buv = vec2((bx + 0.5)/256.0, (by + 0.5)/256.0); + + float r = texture(lut, ruv).r; + float g = texture(lut, guv).g; + float b = texture(lut, buv).b; + + return vec3(r, g, b); +} + +// 安全除法 +float safeDivide(float a, float b) { + return (abs(b) > eps) ? a / b : 0.0; +} + +vec3 safeDivideVec(vec3 a, vec3 b) { + return vec3( + safeDivide(a.r, b.r), + safeDivide(a.g, b.g), + safeDivide(a.b, b.b) + ); +} + +vec3 RecoverHue(vec3 rgb0, vec3 rgb1) { + float r0 = rgb0.r, g0 = rgb0.g, b0 = rgb0.b; + float r1 = rgb1.r, g1 = rgb1.g, b1 = rgb1.b; + + float min0 = min(min(r0, g0), b0); + float max0 = max(max(r0, g0), b0); + float delta0 = max0 - min0; + + float h = 0.0; + if (delta0 > 1e-9) { + if (max0 == r0) { + h = 60.0 * ((g0 - b0) / delta0); + if (g0 < b0) h += 360.0; + } else if (max0 == g0) { + h = 60.0 * ((b0 - r0) / delta0 + 2.0); + } else { + h = 60.0 * ((r0 - g0) / delta0 + 4.0); + } + h = mod(h, 360.0); + } + + float min1 = min(min(r1, g1), b1); + float max1 = max(max(r1, g1), b1); + float l = (max1 + min1) * 0.5; + + float s = 0.0; + float delta1 = max1 - min1; + + const float threshold = 1.0 / 65536.0; + + if (l > threshold && l < (1.0 - threshold)) { + float denom = (l < 0.5) ? (2.0 * l) : (2.0 - 2.0 * l); + if (denom > eps) + s = delta1 / denom; + } + + s = clamp(s, 0.0, 1.0); + + // HSL -> RGB conversion + float c = (1.0 - abs(2.0 * l - 1.0)) * s; + float x = c * (1.0 - abs(mod(h / 60.0, 2.0) - 1.0)); + float m = l - c * 0.5; + + vec3 cc = vec3(0.0); + if (h >= 0.0 && h < 60.0) cc = vec3(c, x, 0.0); + else if (h < 120.0) cc = vec3(x, c, 0.0); + else if (h < 180.0) cc = vec3(0.0, c, x); + else if (h < 240.0) cc = vec3(0.0, x, c); + else if (h < 300.0) cc = vec3(x, 0.0, c); + else cc = vec3(c, 0.0, x); + + return clamp(cc + m, 0.0, 1.0); +} + +void main() { + ivec2 gid = ivec2(gl_FragCoord.xy); + vec4 texVal = texelFetch(uInputTexture0, gid, 0); + vec3 srcPixel = texVal.rgb; + + // Step 1: RGB Curve + srcPixel = lookupCurve(uRgbCurve, srcPixel); + srcPixel = clamp(srcPixel, 0.0, 1.0); + + // Step 2: Contrast Curve + vec3 factorContrast = vec3(1.0); + if (uHasContrast != 0) { + vec3 newValue = lookupCurve(uContrastCurve, srcPixel); + newValue = clamp(newValue, 0.0, 1.0); + + if (uVersion != 0) { + vec3 huePreserved = RecoverHue(srcPixel, newValue); + factorContrast = safeDivideVec(huePreserved, srcPixel); + } else { + factorContrast = safeDivideVec(newValue, srcPixel); + } + factorContrast = clamp(factorContrast, 0.0, 10.0); // Prevent extreme boost + } + + // Step 3: Luma User Curve + vec3 factorLumaCurve = vec3(1.0); + if (uLumaPoints > 2) { + vec3 newValue = lookupCurve(uLumaUserCurve, srcPixel); + newValue = clamp(newValue, 0.0, 1.0); + vec3 huePreserved = RecoverHue(srcPixel, newValue); + factorLumaCurve = safeDivideVec(huePreserved, srcPixel); + factorLumaCurve = clamp(factorLumaCurve, 0.0, 10.0); + } + + // Final combine with clamping + vec3 result = srcPixel * factorContrast * factorLumaCurve; + result = clamp(result, 0.0, 1.0); + + FragColor = vec4(result, texVal.a); +} diff --git a/research/phocus_glsl/04_color_tone/highlightstrength_0x3035fd3.frag b/research/phocus_glsl/04_color_tone/highlightstrength_0x3035fd3.frag new file mode 100644 index 00000000..25faaac1 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/highlightstrength_0x3035fd3.frag @@ -0,0 +1,122 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 8c19ed4877e76b4394bb4dd802c890a081f0ba79a1ebcc68ea39c5c5ecfce6b7 + * ELF offsets: 0x3035fd3 + * Symbols: highlightstrength_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; + +uniform vec2 uX; // x1, x2 +uniform vec3 uP; // pA, pB, pC +uniform vec3 uPh; // phA, phB, phC +uniform vec2 uL; // lA, lB +uniform float uStrengthBlend; +uniform float uSaturationBlend; +uniform float uAmountSatFact; + +const float kGammaHasselbladRgb = 2.2; + +vec3 rgb2hsl(vec3 rgb) { + float min1 = min(rgb.r, min(rgb.g, rgb.b)); + float max1 = max(rgb.r, max(rgb.g, rgb.b)); + + float precis = 0.00001; + float l = clamp((max1 + min1) / 2.0, precis, 1.0 - precis); + float max_min = max1 - min1; + float absMax_min = abs(max_min); + max_min = (absMax_min > precis) ? absMax_min : precis; + + float s = step(l, 0.5) * (max_min * 0.5) / l + (1.0 - step(l, 0.5)) * max_min / (2.0 - 2.0 * l); + if (absMax_min < precis) { + s = 0.0; + } + + float hr = step(max1, rgb.r) * (1.0 - step(max1, rgb.b)) * (60.0 * ((rgb.g - rgb.b) / (max_min) + step(rgb.g, rgb.b) * 6.0)); + float hg = step(max1, rgb.g) * (1.0 - step(max1, rgb.r)) * (60.0 * (rgb.b - rgb.r) / (max_min) + 120.0); + float hb = step(max1, rgb.b) * (1.0 - step(max1, rgb.g)) * (60.0 * (rgb.r - rgb.g) / (max_min) + 240.0); + float h = step(min1, max1) * (hr + hg + hb); + + return vec3(h, s, l); +} + +vec3 hsl2rgb(vec3 hsl) { + float h = hsl.r; + float s = hsl.g; + float l = hsl.b; + + float q = step(l, 0.5) * l * (1.0 + s) + (1.0 - step(l, 0.5)) * (l + s - l * s); + float p = 2.0 * l - q; + float hk = fract(h / 360.0); + + vec4 tc = vec4(hk + step(hk, 2.0/3.0)/3.0 - (1.0 - step(hk, 2.0/3.0)) * 2.0/3.0, + hk, + hk - (1.0 - step(hk, 1.0/3.0)) * 1.0/3.0 + step(hk, 1.0/3.0) * 2.0/3.0, + 1.0); + + float r = tc.r; + float g = tc.g; + float b = tc.b; + + float r1 = step(r, 1.0/6.0) * (p + (q - p) * 6.0 * r) + (1.0 - step(r, 1.0/6.0)) * (step(r, 0.5) * q + (1.0 - step(r, 0.5)) * (step(r, 2.0/3.0) * (p + (q - p) * 6.0 * (2.0/3.0 - r)) + (1.0 - step(r, 2.0/3.0)) * p)); + float g1 = step(g, 1.0/6.0) * (p + (q - p) * 6.0 * g) + (1.0 - step(g, 1.0/6.0)) * (step(g, 0.5) * q + (1.0 - step(g, 0.5)) * (step(g, 2.0/3.0) * (p + (q - p) * 6.0 * (2.0/3.0 - g)) + (1.0 - step(g, 2.0/3.0)) * p)); + float b1 = step(b, 1.0/6.0) * (p + (q - p) * 6.0 * b) + (1.0 - step(b, 1.0/6.0)) * (step(b, 0.5) * q + (1.0 - step(b, 0.5)) * (step(b, 2.0/3.0) * (p + (q - p) * 6.0 * (2.0/3.0 - b)) + (1.0 - step(b, 2.0/3.0)) * p)); + + return vec3(r1, g1, b1); +} + +vec3 HighlightL(vec3 rgbVal, vec2 X, vec3 P, vec2 L) { + vec3 resP = rgbVal * rgbVal * P.x + rgbVal * P.y + P.z; + vec3 resL = rgbVal * L.x + L.y; + vec3 inner = mix(resP, resL, step(X.y, rgbVal)); + return mix(rgbVal, inner, step(X.x, rgbVal)); +} + +vec3 HighlightP(vec3 rgbVal, vec2 X, vec3 P, vec3 Ph) { + vec3 resP = rgbVal * rgbVal * P.x + rgbVal * P.y + P.z; + vec3 resPh = rgbVal * rgbVal * Ph.x + rgbVal * Ph.y + Ph.z; + vec3 inner = mix(resP, resPh, step(X.y, rgbVal)); + return mix(rgbVal, inner, step(X.x, rgbVal)); +} + +vec3 ApplyHighlightStrength(vec3 rgbIn, vec2 X, vec3 P, vec3 Ph, vec2 L, float strengthBlend, float saturationBlend, float amountSatFact) { + vec3 rgbHStrength; + if (strengthBlend > 0.0) { + rgbHStrength = HighlightP(rgbIn, X, P, Ph); + } else { + rgbHStrength = HighlightL(rgbIn, X, P, L); + } + + rgbIn = clamp(rgbIn, 0.0, 1.0); + rgbHStrength = clamp(rgbHStrength, 0.0, 1.0); + + vec3 hslIn = rgb2hsl(rgbIn); + vec3 hslOut = rgb2hsl(rgbHStrength); + + float a = hslOut[1] - hslIn[1]; + float b = hslIn[1] - (a / 2.0) * amountSatFact; + float blendSat = max(a * saturationBlend + b, 0.0); + + float blendLum = (1.0 - strengthBlend) * hslIn[2] + strengthBlend * hslOut[2]; + + vec3 rgbOut = hsl2rgb(vec3(hslIn[0], blendSat, blendLum)); + rgbHStrength = rgbOut; + + return rgbHStrength; +} + +void main() { + vec4 pixelColor = texture(uInputTexture0, TexCoord); + float alpha = pixelColor.a; + + vec3 result = ApplyHighlightStrength(pixelColor.rgb, uX, uP, uPh, uL, uStrengthBlend, uSaturationBlend, uAmountSatFact); + + FragColor = vec4(result, alpha); +} diff --git a/research/phocus_glsl/04_color_tone/mark_hue_0x30504eb.frag b/research/phocus_glsl/04_color_tone/mark_hue_0x30504eb.frag new file mode 100644 index 00000000..5f4ccc05 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/mark_hue_0x30504eb.frag @@ -0,0 +1,65 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 6db1863654d4ec5103e4bc0fdf6e1fddc612afed52d72e114956e65562b7e359 + * ELF offsets: 0x30504eb + * Symbols: mark_hue_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform ivec2 uInMargin; +uniform float uRange; +uniform float uHue; +uniform float uThresholdFactor; + +out vec4 FragColor; + +vec3 rgb2hsl(vec3 rgb) +{ + float min1 = min(rgb.r, rgb.g); min1 = min(min1, rgb.b); + float max1 = max(rgb.r, rgb.g); max1 = max(max1, rgb.b); + float min_val = min1; + float max_val = max1; + float l = clamp((max_val + min_val) / 2.0, 0.00001, 0.99999); + + float max_min = max_val - min_val; + max_min = (abs(max_min) > 0.00001) ? max_min : 0.00001; + + float s = step(l, 0.50) * (max_min) / 2.0 / l + (1.0 - step(l, 0.50)) * (max_min) / (2.0 - 2.0 * l); + if ((abs(rgb.r - rgb.g) < 0.00001) && (abs(rgb.g - rgb.b) < 0.00001)) { + s = 0.0; + } + + float hr = step(max_val, rgb.r) * (1.0 - step(max_val, rgb.b)) * (60.0 * ((rgb.g - rgb.b) / (max_min) + step(rgb.g, rgb.b) * 6.0)); + float hg = step(max_val, rgb.g) * (1.0 - step(max_val, rgb.r)) * (60.0 * (rgb.b - rgb.r) / max_min + 120.0); + float hb = step(max_val, rgb.b) * (1.0 - step(max_val, rgb.g)) * (60.0 * (rgb.r - rgb.g) / max_min + 240.0); + float h = step(min_val, max_val) * (hr + hg + hb); + + return vec3(h / 360.0, s, l); +} + +void main() +{ + ivec2 outCoord = ivec2(gl_FragCoord.xy); + ivec2 inCoord = outCoord + uInMargin; + + vec4 res = texelFetch(uInputTexture0, inCoord, 0); + + float maxChannel = max(max(res.r, res.g), max(res.b, 1.0)); + vec3 normalizedRgb = res.rgb / maxChannel; + vec3 hsl = rgb2hsl(normalizedRgb); + + float hueDistance = abs(hsl.r - uHue); + hueDistance = min(hueDistance, 1.0 - hueDistance) / uRange; + + float mixFactor = 1.0 - min(1.0, pow(hueDistance, 6.0)); + + mixFactor = smoothstep(0.08 / uThresholdFactor, 0.15 / uThresholdFactor, hsl.g) * mixFactor; + + float gainCompensation = uThresholdFactor * uThresholdFactor; + vec4 markColor = vec4(vec3(0.9, 0.1, 0.1) / gainCompensation, 1.0); + FragColor = mix(res, markColor, mixFactor); +} diff --git a/research/phocus_glsl/04_color_tone/rgb2GrayRgb_0x309e5f3.comp b/research/phocus_glsl/04_color_tone/rgb2GrayRgb_0x309e5f3.comp new file mode 100644 index 00000000..5614f6dd --- /dev/null +++ b/research/phocus_glsl/04_color_tone/rgb2GrayRgb_0x309e5f3.comp @@ -0,0 +1,80 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: b781b236056b8b51679cea5da2e98b07839ed5db74eedbec1a0123685792bff7 + * ELF offsets: 0x309e5f3 + * Symbols: rgb2GrayRgb_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; + +// Input: 16-bit half float texture (RGB, stored as RGBA16F) +layout(rgba16f, binding = 0) readonly uniform image2D uInputImage; +// Output: 16-bit half float texture (RGB, stored as RGBA16F) +layout(rgba16f, binding = 1) writeonly uniform image2D uOutputImage; + +// Uniform buffer object for parameters +struct GrayParams { + vec4 factors; // RGB factors (R, G, B, unused) + ivec2 margin; // Texture coordinate margin + int debugMode; // Debug mode + int pad; // Padding for std140 alignment +}; + +layout(std140, binding = 2) uniform GrayParams_UBO { + GrayParams params; +} uParams; + +layout(local_size_x = 16, local_size_y = 16) in; + +// Convert RGB to grayscale +float AsGray(vec4 rgb, vec3 factors) { + return clamp(dot(rgb.rgb, factors), 0.0, 1.0); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + int debugMode = uParams.params.debugMode; + + // Boundary check for output + ivec2 outputSize = imageSize(uOutputImage); + if (gid.x >= outputSize.x || gid.y >= outputSize.y || gid.x < 0 || gid.y < 0) { + return; // Skip out-of-bounds pixels + } + + // Calculate input position with margin + ivec2 inPos = gid + uParams.params.margin; + + // Boundary check for input texture + ivec2 inputSize = imageSize(uInputImage); + if (inPos.x < 0 || inPos.y < 0 || inPos.x >= inputSize.x || inPos.y >= inputSize.y) { + if (debugMode > 2) { + imageStore(uOutputImage, gid, vec4(1.0, 0.0, 1.0, 1.0)); // Magenta for boundary error + return; + } + inPos = clamp(inPos, ivec2(0), inputSize - ivec2(1)); + } + + vec4 rgb = imageLoad(uInputImage, inPos); + + // Debug mode 1: Pass-through input RGB + if (debugMode == 1) { + imageStore(uOutputImage, gid, rgb); + return; + } + + // Debug mode 2: Visualize factors as color + if (debugMode == 2) { + vec4 factorViz = vec4(uParams.params.factors.rgb, 1.0); + imageStore(uOutputImage, gid, factorViz); + return; + } + + // Convert RGB to grayscale + float gray = AsGray(rgb, uParams.params.factors.rgb); + + // Output as RGB with all channels set to gray value (alpha = 0) + // Matching iOS Metal: output.write(ushort4(gray, gray, gray, 0), gid) + imageStore(uOutputImage, gid, vec4(gray, gray, gray, 0.0)); +} diff --git a/research/phocus_glsl/04_color_tone/rgb2Gray_0x2ffe79a.comp b/research/phocus_glsl/04_color_tone/rgb2Gray_0x2ffe79a.comp new file mode 100644 index 00000000..7040e222 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/rgb2Gray_0x2ffe79a.comp @@ -0,0 +1,84 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 69b2e3e5510029dac6d1416980e258fdf5c924a43de19e2cb36feb8bc223dd34 + * ELF offsets: 0x2ffe79a + * Symbols: rgb2Gray_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; + +// Input: 16-bit half float texture (RGB, stored as RGBA16F) +layout(rgba16f, binding = 0) readonly uniform image2D uInputImage; +// Output: 16-bit half float texture (PackedBayer format - 4 gray values per texel) +layout(rgba16f, binding = 1) writeonly uniform image2D uOutputImage; + +// Uniform buffer object for parameters +struct GrayParams { + vec4 factors; // RGB factors (R, G, B, unused) + ivec2 margin; // Texture coordinate margin + int debugMode; // Debug mode + int pad; // Padding for std140 alignment +}; + +layout(std140, binding = 2) uniform GrayParams_UBO { + GrayParams params; +} uParams; + +layout(local_size_x = 16, local_size_y = 16) in; + +// Convert RGB to grayscale +// iOS Metal: ushort(clamp(dot(float3(value.rgb), factors), 0., 65535.)) +// Android: operates in normalized [0,1] space +float AsGray(vec4 rgb, vec3 factors) { + return clamp(dot(rgb.rgb, factors), 0.0, 1.0); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + int debugMode = uParams.params.debugMode; + + // Boundary check for output (PackedBayer texture coordinates) + ivec2 outputSize = imageSize(uOutputImage); + if (gid.x >= outputSize.x || gid.y >= outputSize.y || gid.x < 0 || gid.y < 0) { + return; // Skip out-of-bounds pixels + } + + // Calculate input position (each output texel corresponds to 4 input pixels) + // gid is in packed texture space, need to expand to pixel space + ivec2 inBasePos = ivec2(gid.x * 4, gid.y) + uParams.params.margin; + + // Boundary check for input texture + ivec2 inputSize = imageSize(uInputImage); + + // Read 4 consecutive RGB pixels + vec4 rgb0 = imageLoad(uInputImage, clamp(inBasePos + ivec2(0, 0), ivec2(0), inputSize - ivec2(1))); + vec4 rgb1 = imageLoad(uInputImage, clamp(inBasePos + ivec2(1, 0), ivec2(0), inputSize - ivec2(1))); + vec4 rgb2 = imageLoad(uInputImage, clamp(inBasePos + ivec2(2, 0), ivec2(0), inputSize - ivec2(1))); + vec4 rgb3 = imageLoad(uInputImage, clamp(inBasePos + ivec2(3, 0), ivec2(0), inputSize - ivec2(1))); + + // Debug mode 1: Pass-through first pixel's RGB (for debugging) + if (debugMode == 1) { + imageStore(uOutputImage, gid, rgb0); + return; + } + + // Debug mode 2: Visualize factors as color + if (debugMode == 2) { + vec4 factorViz = vec4(uParams.params.factors.rgb, 1.0); + imageStore(uOutputImage, gid, factorViz); + return; + } + + // Convert each RGB pixel to grayscale + float gray0 = AsGray(rgb0, uParams.params.factors.rgb); + float gray1 = AsGray(rgb1, uParams.params.factors.rgb); + float gray2 = AsGray(rgb2, uParams.params.factors.rgb); + float gray3 = AsGray(rgb3, uParams.params.factors.rgb); + + // Pack 4 grayscale values into one RGBA texel (PackedBayer format) + vec4 packed = vec4(gray0, gray1, gray2, gray3); + + imageStore(uOutputImage, gid, packed); +} diff --git a/research/phocus_glsl/04_color_tone/sdr_icc_0x3073d21.frag b/research/phocus_glsl/04_color_tone/sdr_icc_0x3073d21.frag new file mode 100644 index 00000000..3754ffed --- /dev/null +++ b/research/phocus_glsl/04_color_tone/sdr_icc_0x3073d21.frag @@ -0,0 +1,64 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 9f2ec2781a1b115048553c5aba7b729e60c43f6332cc9e4046a4866da43e658e + * ELF offsets: 0x3073d21 + * Symbols: sdr_icc_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +uniform sampler2D uInputTexture0; +uniform ivec2 uInMargin; +uniform int uIsHdr; +out vec4 FragColor; + +const float kLim = 0.04045; +const float kLimInv = 0.0031308; +const float kDiv = 12.92; +const float kOffset = 0.055; +const float kScale = 1.055; +const float kGamma = 2.4; + +const float kLStarEpsilon = 216.0 / 24389.0; +const float kLStarKappa = 24389.0 / 27.0; + +const mat3 convertSdr = mat3( + vec3( 1.548623, -0.062141, -0.014745), + vec3(-0.491106, 1.075171, -0.076391), + vec3(-0.057517, -0.013030, 1.091137) +); + +const mat3 convertHdr = mat3( + vec3( 1.262651, -0.008673, 0.008529), + vec3(-0.213032, 1.023180, -0.000106), + vec3(-0.049619, -0.014507, 0.991576) +); + +vec3 linear2sRgb(vec3 val) { + vec3 linearPart = kDiv * val; + vec3 exponentialPart = kScale * pow(max(val, vec3(0.0)), vec3(1.0 / kGamma)) - kOffset; + bvec3 condition = lessThanEqual(val, vec3(kLimInv)); + vec3 selector = vec3(condition); + return mix(exponentialPart, linearPart, selector); +} + +void main() { + ivec2 gid = ivec2(gl_FragCoord.xy); + ivec2 sdrPos = gid + uInMargin; + + vec3 rawSdr = texelFetch(uInputTexture0, sdrPos, 0).rgb; + + vec3 sdrLiner= pow(rawSdr, vec3(2.2)); + + vec3 sdrP3 = sdrLiner; + if (uIsHdr == 1) { + sdrP3 = convertHdr * sdrLiner; + } else { + sdrP3 = convertSdr * sdrLiner; + } + + vec3 sRgb = linear2sRgb(sdrP3); + + FragColor = vec4(sRgb, 1.0); +} diff --git a/research/phocus_glsl/04_color_tone/selectivecolor_0x3088ea2.frag b/research/phocus_glsl/04_color_tone/selectivecolor_0x3088ea2.frag new file mode 100644 index 00000000..20c1bd12 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/selectivecolor_0x3088ea2.frag @@ -0,0 +1,178 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 23d9a908fe2ae5baf5f578bac46cbcbb30f711900eef5851e42d60c8441dcc24 + * ELF offsets: 0x3088ea2 + * Symbols: selectivecolor_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +precision highp int; + +layout(std140) uniform SelectiveColorParams { + int marginX; + int marginY; + float vibrancy; + float saturationFactor; + int needsSelective; + int useLocalSaturation; + float globalSaturation; + int _padding; +} params; + +uniform sampler2D uInputTexture0; // Input RGB Image +uniform sampler2D uInputTexture1; // Saturation LUT (128x128 Rgba16F) +uniform sampler2D uInputTexture2; // Hue LUT (128x128 Rgba16F) +uniform sampler2D uInputTexture3; // Lightness LUT (128x128 Rgba16F) + +out vec4 fragColor; + +const int kVibrancyTableSize = 65536; +const int cHighresPieCount = 65536; + +vec3 rgb2hsl(vec3 rgb) { + float minVal = min(rgb.r, min(rgb.g, rgb.b)); + float maxVal = max(rgb.r, max(rgb.g, rgb.b)); + + float precis = 0.00001; + float l = clamp((maxVal + minVal) / 2.0, precis, 1.0 - precis); + float maxMin = maxVal - minVal; + float absMaxMin = abs(maxMin); + maxMin = (absMaxMin > precis) ? absMaxMin : precis; + + float s = step(l, 0.5) * (maxMin * 0.5) / l + (1.0 - step(l, 0.5)) * maxMin / (2.0 - 2.0 * l); + if (absMaxMin < precis) { + s = 0.0; + } + + float hr = step(maxVal, rgb.r) * (1.0 - step(maxVal, rgb.b)) * (60.0 * ((rgb.g - rgb.b) / (maxMin) + step(rgb.g, rgb.b) * 6.0)); + float hg = step(maxVal, rgb.g) * (1.0 - step(maxVal, rgb.r)) * (60.0 * (rgb.b - rgb.r) / (maxMin) + 120.0); + float hb = step(maxVal, rgb.b) * (1.0 - step(maxVal, rgb.g)) * (60.0 * (rgb.r - rgb.g) / (maxMin) + 240.0); + float h = step(minVal, maxVal) * (hr + hg + hb); + + return vec3(h, s, l); +} + +vec3 hsl2rgb(vec3 hsl) { + float h = hsl.r; + float s = hsl.g; + float l = hsl.b; + + float q = step(l, 0.5) * l * (1.0 + s) + (1.0 - step(l, 0.5)) * (l + s - l * s); + float p = 2.0 * l - q; + float hk = fract(h / 360.0); + + vec4 tc = vec4(hk + step(hk, 2.0/3.0)/3.0 - (1.0 - step(hk, 2.0/3.0)) * 2.0/3.0, + hk, + hk - (1.0 - step(hk, 1.0/3.0)) * 1.0/3.0 + step(hk, 1.0/3.0) * 2.0/3.0, + 1.0); + + float r = tc.r; + float g = tc.g; + float b = tc.b; + + float r1 = step(r, 1.0/6.0) * (p + (q - p) * 6.0 * r) + (1.0 - step(r, 1.0/6.0)) * (step(r, 0.5) * q + (1.0 - step(r, 0.5)) * (step(r, 2.0/3.0) * (p + (q - p) * 6.0 * (2.0/3.0 - r)) + (1.0 - step(r, 2.0/3.0)) * p)); + float g1 = step(g, 1.0/6.0) * (p + (q - p) * 6.0 * g) + (1.0 - step(g, 1.0/6.0)) * (step(g, 0.5) * q + (1.0 - step(g, 0.5)) * (step(g, 2.0/3.0) * (p + (q - p) * 6.0 * (2.0/3.0 - g)) + (1.0 - step(g, 2.0/3.0)) * p)); + float b1 = step(b, 1.0/6.0) * (p + (q - p) * 6.0 * b) + (1.0 - step(b, 1.0/6.0)) * (step(b, 0.5) * q + (1.0 - step(b, 0.5)) * (step(b, 2.0/3.0) * (p + (q - p) * 6.0 * (2.0/3.0 - b)) + (1.0 - step(b, 2.0/3.0)) * p)); + + return vec3(r1, g1, b1); +} + +float hermiteInterpolation(float t) { + return t * t * (3.0 - 2.0 * t); +} + +float calculateVibrancyFactor(float saturation) { + const float kVBegin = 0.1 * float(kVibrancyTableSize); + const float kVMid = 0.3 * float(kVibrancyTableSize); + const float kVEnd = 0.6 * float(kVibrancyTableSize); + + float sIndex = saturation * float(kVibrancyTableSize - 1); + + if (sIndex >= kVBegin && sIndex < kVMid) { + float fraction = (sIndex - kVBegin) / (kVMid - kVBegin); + return hermiteInterpolation(fraction); + } else if (sIndex >= kVMid && sIndex < kVEnd) { + float fraction = 1.0 - (sIndex - kVMid) / (kVEnd - kVMid); + return hermiteInterpolation(fraction); + } + + return 0.0; +} + +float fetchLUTValue(sampler2D lutTexture, int index) { + index = clamp(index, 0, cHighresPieCount - 1); + + int pixelIndex = index / 4; + int component = index % 4; + + int texX = pixelIndex % 128; + int texY = pixelIndex / 128; + + vec4 pixel = texelFetch(lutTexture, ivec2(texX, texY), 0); + return pixel[component]; +} + +vec3 applySelectiveColorAdjustment( + vec3 hsl, + float hueOffset, + float selectiveSaturationFactor, + float lightnessBase, + float vibrancy, + float saturationFactor) +{ + float h = hsl.x; + float s = hsl.y; + float l = hsl.z; + + h += hueOffset; + if (h >= 360.0) h -= 360.0; + if (h < 0.0) h += 360.0; + + s = clamp(s * selectiveSaturationFactor * saturationFactor, 0.0, 1.0); + + float vf = vibrancy / 4.0; + float vibrancyFactor = calculateVibrancyFactor(s); + + s = s + vf * vibrancyFactor; + s = clamp(s, 0.0, 1.0); + + float lightnessOffset = s * (lightnessBase / 100.0); + + l = l * (1.0 + lightnessOffset); + l = clamp(l, 0.0, 1.0); + + return vec3(h, s, l); +} + +void main() { + ivec2 inputCoord = ivec2(gl_FragCoord.xy); + inputCoord += ivec2(params.marginX, params.marginY); + + vec4 inputPixel = texelFetch(uInputTexture0, inputCoord, 0); + vec3 rgb = inputPixel.rgb; + + if (params.needsSelective == 1) { + vec3 hsl = rgb2hsl(rgb); + + // Calculate LUT lookup index from hue + int lookup = clamp(int(round(hsl.x * float(cHighresPieCount) / 360.0)), 0, cHighresPieCount - 1); + + float hueOffset = fetchLUTValue(uInputTexture2, lookup); + float selectiveSaturationFactor = fetchLUTValue(uInputTexture1, lookup); + float lightnessBase = fetchLUTValue(uInputTexture3, lookup); + + hsl = applySelectiveColorAdjustment( + hsl, + hueOffset, + selectiveSaturationFactor, + lightnessBase, + params.vibrancy, + params.saturationFactor); + + rgb = hsl2rgb(hsl); + } + + fragColor = vec4(rgb, inputPixel.a); +} diff --git a/research/phocus_glsl/04_color_tone/unattributed_0x30308d7_0x30308d7.frag b/research/phocus_glsl/04_color_tone/unattributed_0x30308d7_0x30308d7.frag new file mode 100644 index 00000000..0a37c7e2 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/unattributed_0x30308d7_0x30308d7.frag @@ -0,0 +1,22 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 0019263ccb2e3a738b9c6014820b560dc84c5c474955760e2baaf968fab453f0 + * ELF offsets: 0x30308d7 + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; +void main() { + ivec2 p = ivec2(gl_FragCoord.xy); + vec4 e = texelFetch(uInputTexture0, p, 0); + // fcfr_erode (and fcfr_edge) store 0.0 for edge pixels, 1.0 for non-edge. + // Seed the JFA with edge pixels (e.r < 0.5). + if (e.r < 0.5) + FragColor = vec4(float(p.x) + 0.5, float(p.y) + 0.5, 0.0, 1.0); + else + FragColor = vec4(-1.0, -1.0, 0.0, 0.0); +} diff --git a/research/phocus_glsl/04_color_tone/unattributed_0x30347c3_0x30347c3.frag b/research/phocus_glsl/04_color_tone/unattributed_0x30347c3_0x30347c3.frag new file mode 100644 index 00000000..592f4731 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/unattributed_0x30347c3_0x30347c3.frag @@ -0,0 +1,18 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 555706c2932277ee62b250ebd2625afe9c4e80de00db5e77c6dd38e9bdccd000 + * ELF offsets: 0x30347c3 + * Symbols: unattributed + */ + +#version 300 es +precision mediump float; +in vec2 vTextureCoord; +out vec4 fragColor; +uniform sampler2D base; + + +void main() { + vec3 srgb = texture(base, vTextureCoord).rgb; + fragColor = vec4(srgb, 1.0); +} diff --git a/research/phocus_glsl/04_color_tone/unattributed_0x3065982_0x3065982.frag b/research/phocus_glsl/04_color_tone/unattributed_0x3065982_0x3065982.frag new file mode 100644 index 00000000..a17e0c07 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/unattributed_0x3065982_0x3065982.frag @@ -0,0 +1,18 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 6f90e80f6193d57e5ee7d79a3beb75aa77d22320d0ecdea771c7580ea2a3cb29 + * ELF offsets: 0x3065982 + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; + +void main() { + vec4 res = texelFetch(uInputTexture0, ivec2(gl_FragCoord.xy), 0); + FragColor = (res.a <= 0.0) ? vec4(0.0, 0.0, 0.0, 1.0) + : vec4(res.rgb / res.a, 1.0); +} diff --git a/research/phocus_glsl/04_color_tone/unattributed_0x3079cc5_0x3079cc5.frag b/research/phocus_glsl/04_color_tone/unattributed_0x3079cc5_0x3079cc5.frag new file mode 100644 index 00000000..6fa73f59 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/unattributed_0x3079cc5_0x3079cc5.frag @@ -0,0 +1,94 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: d54349859e4310755952cd52a6dce6eacd6e4a8f4cb54b3824a086bd397d19b8 + * ELF offsets: 0x3079cc5 + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; +uniform sampler2D uInputTexture1; +uniform sampler2D uInputTexture2; +uniform int uSrcOffsetX; +uniform int uSrcOffsetY; +uniform float uPurpleStart; +uniform float uPurpleStop; +uniform float uGreenStart; +uniform float uGreenStop; +uniform float uPurpleAmount; +uniform float uGreenAmount; + +float hueOf(vec4 v) { + float mx = max(v.r, max(v.g, v.b)); + float mn = min(v.r, min(v.g, v.b)); + if (mx <= 0.0 || (mx-mn)/mx <= 0.05) return -1.0; + float c60 = 60.0/(mx-mn); + if (mx == v.r) return (v.g >= v.b) ? c60*(v.g-v.b) : c60*(v.g-v.b)+360.0; + if (mx == v.g) return c60*(v.b-v.r)+120.0; + return c60*(v.r-v.g)+240.0; +} +bool hueInRange(float h, float hStart, float hStop) { + if (h < 0.0) return false; + return (hStart < hStop) ? (hStart <= h && h <= hStop) + : !(hStop < h && h < hStart); +} +float rgbSum(vec4 v) { return v.r + v.g + v.b; } +float simpSat(vec4 c) { return max(c.r,max(c.g,c.b)) - min(c.r,min(c.g,c.b)); } + +vec4 limitSaturation(vec4 color, vec4 limitColor) { + float satNew = simpSat(color), satOld = simpSat(limitColor); + float sat = satOld * min(1.1, (satOld > 0.0) ? satNew/satOld : 0.0); + float factor = (satNew > 0.0) ? sat/satNew : 0.0; + float c = (color.r+color.g+color.b)/3.0; + return (color - vec4(c,c,c,color.a)) * factor + vec4(c,c,c,color.a); +} +float clampedSlope(float x, float x1, float y1, float x2, float y2) { + float a = (y2-y1)/(x2-x1); + return clamp(a*x + (y1-a*x1), min(y1,y2), max(y1,y2)); +} + +void main() { + ivec2 p = ivec2(gl_FragCoord.xy); + ivec2 srcSz = textureSize(uInputTexture0, 0); + + vec4 res = texelFetch(uInputTexture0, + clamp(p + ivec2(uSrcOffsetX, uSrcOffsetY), ivec2(0), srcSz-1), 0); + vec4 premul = texelFetch(uInputTexture1, p, 0); + vec4 lr = texelFetch(uInputTexture2, clamp(p, ivec2(0), textureSize(uInputTexture2,0)-1), 0); + + // Fringe mask: premul.a = (1 − fringeMask) → fringeMask = 1 − premul.a + float fringeMask = 1.0 - premul.a; + + // Amount (recompute inline from source hue) + float h = hueOf(res); + float aVal = 0.0; + if (hueInRange(h, uPurpleStart, uPurpleStop)) aVal = clamp(uPurpleAmount, 0.0, 100.0); + else if (hueInRange(h, uGreenStart, uGreenStop)) aVal = clamp(uGreenAmount, 0.0, 100.0); + + // Colour recovery + vec4 k = vec4(0.3, 0.6, 0.1, 1.0); + float oldY = rgbSum(res * k); + float newY = rgbSum(lr * k); + vec4 g = vec4(oldY, oldY, oldY, 1.0); + + vec4 color = (newY > 0.0) ? lr * (oldY / newY) : g; + color = limitSaturation(color, res); + + float factor = (newY > 0.0) ? oldY/newY : 1.0; + float denom = rgbSum(k * color / max(factor, 1e-6)); + if (denom > 0.0) color *= k * newY / denom; + color.a = 1.0; + + // balance × 3 (iOS step() semantics → clamp to k) + color = clamp(color, vec4(0.0), k); + color = clamp(color, vec4(0.0), k); + color = clamp(color, vec4(0.0), k); + + float recovery = clampedSlope(aVal, 90.0, 1.0, 100.0, 0.7); + float alpha = clampedSlope(aVal, 0.0, 0.85, 100.0, 1.0); + vec4 colorPerK = vec4(color.r/k.r, color.g/k.g, color.b/k.b, 1.0); + FragColor = mix(res, mix(g, colorPerK, recovery), min(alpha, fringeMask)); +} diff --git a/research/phocus_glsl/04_color_tone/unattributed_0x307f4f7_0x307f4f7.frag b/research/phocus_glsl/04_color_tone/unattributed_0x307f4f7_0x307f4f7.frag new file mode 100644 index 00000000..cb4385a0 --- /dev/null +++ b/research/phocus_glsl/04_color_tone/unattributed_0x307f4f7_0x307f4f7.frag @@ -0,0 +1,18 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 93d00d0f37ad0f65522194209275aab523fabc1c8173df5550ca7e0c94a46613 + * ELF offsets: 0x307f4f7 + * Symbols: unattributed + */ + +#version 300 es +precision highp float; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D inputTexture; + +void main() { + FragColor = texture(inputTexture, TexCoord); +} diff --git a/research/phocus_glsl/05_lens_geometry/KeystoneBilinear_0x300f494.frag b/research/phocus_glsl/05_lens_geometry/KeystoneBilinear_0x300f494.frag new file mode 100644 index 00000000..046fc133 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/KeystoneBilinear_0x300f494.frag @@ -0,0 +1,62 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 6e41522c4cdf78a589f1e2d7a5cefc0ba1ed514b23edd3369992f0cf90c97e98 + * ELF offsets: 0x300f494 + * Symbols: KeystoneBilinear_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform mat3 uTransformMatrix; +uniform ivec2 uOffset; +uniform ivec2 uSrcOffset; +uniform ivec2 uSize; +uniform ivec2 uLimit; + +out vec4 FragColor; + +vec4 sampleTextureBilinear(sampler2D tex, vec2 pixelPos, vec2 texSize) +{ + vec2 floorPos = floor(pixelPos); + vec2 fracPos = pixelPos - floorPos; + + ivec2 p00 = ivec2(floorPos); + ivec2 p10 = ivec2(floorPos) + ivec2(1, 0); + ivec2 p01 = ivec2(floorPos) + ivec2(0, 1); + ivec2 p11 = ivec2(floorPos) + ivec2(1, 1); + + p00 = clamp(p00, ivec2(0), ivec2(texSize) - ivec2(1)); + p10 = clamp(p10, ivec2(0), ivec2(texSize) - ivec2(1)); + p01 = clamp(p01, ivec2(0), ivec2(texSize) - ivec2(1)); + p11 = clamp(p11, ivec2(0), ivec2(texSize) - ivec2(1)); + + vec4 sample00 = texelFetch(tex, p00, 0); + vec4 sample10 = texelFetch(tex, p10, 0); + vec4 sample01 = texelFetch(tex, p01, 0); + vec4 sample11 = texelFetch(tex, p11, 0); + + vec4 sample0 = mix(sample00, sample10, fracPos.x); + vec4 sample1 = mix(sample01, sample11, fracPos.x); + return mix(sample0, sample1, fracPos.y); +} + +void main() +{ + ivec2 gid = ivec2(gl_FragCoord.xy); + + vec3 pos = vec3(float(gid.x) + float(uOffset.x), float(gid.y) + float(uOffset.y), 1.0); + vec3 transformed = uTransformMatrix * pos; + vec2 wanted = vec2(transformed.x / transformed.z, transformed.y / transformed.z); + + if (wanted.x < 0.0 || wanted.y < 0.0 || wanted.x > float(uLimit.x) || wanted.y > float(uLimit.y)) { + FragColor = vec4(0.0, 0.0, 0.0, 0.0); + return; + } + vec2 inputPixelPos = wanted - vec2(float(uSrcOffset.x), float(uSrcOffset.y)); + vec2 texSize = vec2(float(uSize.x), float(uSize.y)); + + FragColor = sampleTextureBilinear(uInputTexture0, inputPixelPos, texSize); +} diff --git a/research/phocus_glsl/05_lens_geometry/Keystone_0x30847c0.frag b/research/phocus_glsl/05_lens_geometry/Keystone_0x30847c0.frag new file mode 100644 index 00000000..050a1db9 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/Keystone_0x30847c0.frag @@ -0,0 +1,126 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: d3956e2b1df06d05398033f10af7f36f5651d91db0173fa1dc2232390ff8b8dd + * ELF offsets: 0x30847c0 + * Symbols: Keystone_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform mat3 uTransformMatrix; +uniform ivec2 uOffset; +uniform ivec2 uSrcOffset; +uniform ivec2 uSize; +uniform ivec2 uLimit; + +out vec4 FragColor; + +// Lanczos kernel function, matching Metal: Lanczos(x, a=4) +float Lanczos(float x, float a) +{ + float PI = 3.14; + if (x == 0.0) + return 1.0; + return a * sin(PI * x) * sin(PI * x / a) / (PI * PI * x * x); +} + +vec4 MixRgbLanczosLine(sampler2D tex, ivec2 pos, vec2 delta, ivec2 margin, ivec2 maxSize, bool blackOOB, + inout float sum_f, inout vec4 vmin, inout vec4 vmax) +{ + if (blackOOB) + if (pos.y < margin.y || pos.y >= maxSize.y) + return vec4(0.0); + + float fy = Lanczos(delta.y, 4.0); + float f_3 = Lanczos(delta.x + 3.0, 4.0); + float f_2 = Lanczos(delta.x + 2.0, 4.0); + float f_1 = Lanczos(delta.x + 1.0, 4.0); + float f0 = Lanczos(delta.x + 0.0, 4.0); + float f1 = Lanczos(delta.x - 1.0, 4.0); + float f2 = Lanczos(delta.x - 2.0, 4.0); + float f3 = Lanczos(delta.x - 3.0, 4.0); + float f4 = Lanczos(delta.x - 4.0, 4.0); + + if (pos.x - 3 < margin.x || pos.x - 3 >= maxSize.x) f_3 = 0.0; + if (pos.x - 2 < margin.x || pos.x - 2 >= maxSize.x) f_2 = 0.0; + if (pos.x - 1 < margin.x || pos.x - 1 >= maxSize.x) f_1 = 0.0; + if (pos.x + 0 < margin.x || pos.x + 0 >= maxSize.x) f0 = 0.0; + if (pos.x + 1 < margin.x || pos.x + 1 >= maxSize.x) f1 = 0.0; + if (pos.x + 2 < margin.x || pos.x + 2 >= maxSize.x) f2 = 0.0; + if (pos.x + 3 < margin.x || pos.x + 3 >= maxSize.x) f3 = 0.0; + if (pos.x + 4 < margin.x || pos.x + 4 >= maxSize.x) f4 = 0.0; + + sum_f += fy * (f_3 + f_2 + f_1 + f0 + f1 + f2 + f3 + f4); + + vec4 p_3 = texelFetch(tex, ivec2(pos.x - 3, pos.y), 0); + vec4 p_2 = texelFetch(tex, ivec2(pos.x - 2, pos.y), 0); + vec4 p_1 = texelFetch(tex, ivec2(pos.x - 1, pos.y), 0); + vec4 p0 = texelFetch(tex, ivec2(pos.x + 0, pos.y), 0); + vec4 p1 = texelFetch(tex, ivec2(pos.x + 1, pos.y), 0); + vec4 p2 = texelFetch(tex, ivec2(pos.x + 2, pos.y), 0); + vec4 p3 = texelFetch(tex, ivec2(pos.x + 3, pos.y), 0); + vec4 p4 = texelFetch(tex, ivec2(pos.x + 4, pos.y), 0); + + vmin = min(vmin, min(p0, p1)); + vmax = max(vmax, max(p0, p1)); + + return fy * ( f_3 * p_3 + + f_2 * p_2 + + f_1 * p_1 + + f0 * p0 + + f1 * p1 + + f2 * p2 + + f3 * p3 + + f4 * p4); +} + +vec4 interpolateLanczosRgb(sampler2D tex, ivec2 imgSize, vec2 offset, ivec2 pos, bool blackOOB) +{ + ivec2 margin = max(pos, ivec2(0)); + vec2 indexPos = vec2(pos) + offset; + if (blackOOB) + if (indexPos.x < float(margin.x) || indexPos.y < float(margin.y) + || indexPos.x >= float(imgSize.x) || indexPos.y >= float(imgSize.y)) + return vec4(0.0); + + vec2 resPos = indexPos; + ivec2 base = ivec2(floor(resPos)); + + vec2 delta = resPos - vec2(base); + float sum_f = 0.0; + vec4 maximum = vec4(0.0), minimum = vec4(65535.0); + vec4 unused_min = vec4(65535.0), unused_max = vec4(0.0); + vec4 sum_p = + MixRgbLanczosLine(tex, ivec2(base.x, base.y - 3), vec2(delta.x, delta.y + 3.0), margin, imgSize, blackOOB, sum_f, unused_min, unused_max) + + MixRgbLanczosLine(tex, ivec2(base.x, base.y - 2), vec2(delta.x, delta.y + 2.0), margin, imgSize, blackOOB, sum_f, unused_min, unused_max) + + MixRgbLanczosLine(tex, ivec2(base.x, base.y - 1), vec2(delta.x, delta.y + 1.0), margin, imgSize, blackOOB, sum_f, unused_min, unused_max) + + MixRgbLanczosLine(tex, ivec2(base.x, base.y + 0), vec2(delta.x, delta.y + 0.0), margin, imgSize, blackOOB, sum_f, minimum, maximum) + + MixRgbLanczosLine(tex, ivec2(base.x, base.y + 1), vec2(delta.x, delta.y - 1.0), margin, imgSize, blackOOB, sum_f, minimum, maximum) + + MixRgbLanczosLine(tex, ivec2(base.x, base.y + 2), vec2(delta.x, delta.y - 2.0), margin, imgSize, blackOOB, sum_f, unused_min, unused_max) + + MixRgbLanczosLine(tex, ivec2(base.x, base.y + 3), vec2(delta.x, delta.y - 3.0), margin, imgSize, blackOOB, sum_f, unused_min, unused_max) + + MixRgbLanczosLine(tex, ivec2(base.x, base.y + 4), vec2(delta.x, delta.y - 4.0), margin, imgSize, blackOOB, sum_f, unused_min, unused_max) + ; + + vec4 h = sum_f != 0.0 ? sum_p / sum_f : vec4(0.0); + h = clamp(h, minimum, maximum); + return h; +} + +void main() +{ + ivec2 gid = ivec2(gl_FragCoord.xy); + + vec3 pos = vec3(float(gid.x) + float(uOffset.x), float(gid.y) + float(uOffset.y), 1.0); + vec3 transformed = uTransformMatrix * pos; + + vec2 wanted = vec2(transformed.x / transformed.z, transformed.y / transformed.z); + + if (wanted.x < 0.0 || wanted.y < 0.0 || wanted.x > float(uLimit.x) || wanted.y > float(uLimit.y)) { + FragColor = vec4(0.0, 0.0, 0.0, 1.0); + return; + } + FragColor = interpolateLanczosRgb(uInputTexture0, uSize, wanted, -uSrcOffset, true); +} diff --git a/research/phocus_glsl/05_lens_geometry/alignment_0x3025a0f.frag b/research/phocus_glsl/05_lens_geometry/alignment_0x3025a0f.frag new file mode 100644 index 00000000..6f346e23 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/alignment_0x3025a0f.frag @@ -0,0 +1,21 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 4f0ff853370d74ed985ade5b3f8e5a403962af5789f8eca38a4b97cdc1863fa0 + * ELF offsets: 0x3025a0f + * Symbols: alignment_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +uniform ivec2 uMargin; + +out vec4 FragColor; + +void main() { + ivec2 destCoord = ivec2(gl_FragCoord.xy); + ivec2 srcCoord = destCoord + uMargin; + FragColor = texelFetch(uInputTexture0, srcCoord, 0); +} diff --git a/research/phocus_glsl/05_lens_geometry/grayVignetteCS_0x300a1ea.comp b/research/phocus_glsl/05_lens_geometry/grayVignetteCS_0x300a1ea.comp new file mode 100644 index 00000000..f3f62825 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/grayVignetteCS_0x300a1ea.comp @@ -0,0 +1,192 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 76ab07ae2bc82a0a7f67d73044d2eff9fdda40e911b98645b3cb935129eeef0c + * ELF offsets: 0x300a1ea + * Symbols: grayVignetteCS_computeShaderSource + */ + +#version 310 es +precision highp float; +//precision highp int; +precision highp image2D; + +layout(rgba16f, binding = 0) readonly uniform image2D uInputImage; +layout(r32f, binding = 1) readonly uniform image2D uVignetteTable; +layout(rgba16f, binding = 2) writeonly uniform image2D uOutputImage; + +layout(std140, binding = 0) uniform VignetteParams { + vec3 matA; + float redOffset; + vec3 matB; + float greenOffset; + vec3 matC; + float blueOffset; + vec4 redParam; + vec4 greenParam; + vec4 blueParam; + + vec2 centerOffset; + ivec2 srcRectLeftTop; + ivec2 dstRectLeftTop; + ivec2 maxRectSize; + ivec2 keystoneLimit; + float pixelSize; + float vignAmount; + float imageScale; + int vignTableDiv; + bool blackOutOfBounds; + int padding; +} uParams; + +uniform int uDebugMode; + +layout(local_size_x = 16, local_size_y = 16) in; + + +// Cubic interpolation function (Catmull-Rom spline) +vec4 cubic(vec4 v_1, vec4 v0, vec4 v1, vec4 v2, float delta) { + vec4 a = v2 * (1.0/6.0) - v1 * 0.5 + v0 * 0.5 - v_1 * (1.0/6.0); + vec4 b = v_1 * 0.5 + v1 * 0.5 - v0; + vec4 c = -v2 * (1.0/6.0) + v1 - v0 * 0.5 - v_1 * (1.0/3.0); + vec4 d = v0; + + return a * (delta * delta * delta) + b * (delta * delta) + c * delta + d; +} + +vec2 cubic2(vec2 v_1, vec2 v0, vec2 v1, vec2 v2, float delta) { + vec2 a = v2 * (1.0/6.0) - v1 * 0.5 + v0 * 0.5 - v_1 * (1.0/6.0); + vec2 b = v_1 * 0.5 + v1 * 0.5 - v0; + vec2 c = -v2 * (1.0/6.0) + v1 - v0 * 0.5 - v_1 * (1.0/3.0); + vec2 d = v0; + + return a * (delta * delta * delta) + b * (delta * delta) + c * delta + d; +} + +// Keystone transform (homogeneous 3x3 matrix) +vec2 keystoneTransform(vec3 matA, vec3 matB, vec3 matC, vec2 pos) { + vec3 posH = vec3(pos.x, pos.y, 1.0); + vec3 transformed; + transformed.x = dot(matA, posH); + transformed.y = dot(matB, posH); + transformed.z = dot(matC, posH); + return vec2(transformed.x / transformed.z, transformed.y / transformed.z); +} + +// Select red or blue channel from packed bayer (match Metal: .xz/.yw = 1st+3rd / 2nd+4th = .rb/.ga) +vec2 selectRedBlue(vec4 packed, bool isRed) { + return isRed ? packed.rb : packed.ga; +} + +// Mix cubic line for packed bayer format +vec2 mixCubicLine(ivec2 pos, float delta, bool isRed, inout vec2 minimum, inout vec2 maximum) { + // cubic2 algorithm is in data format ushort + vec2 l = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x - 1, pos.y)), isRed) * vec2(65535.0); + vec2 m = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x + 0, pos.y)), isRed) * vec2(65535.0); + vec2 r = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x + 1, pos.y)), isRed) * vec2(65535.0); + vec2 r2 = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x + 2, pos.y)), isRed) * vec2(65535.0); + + if (delta < 1.0) { + vec2 p0 = m.xy; + vec2 p1 = vec2(m.y, r.x); + minimum = min(minimum, min(p0, p1)); + maximum = max(maximum, max(p0, p1)); + return cubic2(vec2(l.y, m.x), p0, p1, r.xy, delta); + } else { + vec2 p0 = vec2(m.y, r.x); + vec2 p1 = r.xy; + minimum = min(minimum, min(p0, p1)); + maximum = max(maximum, max(p0, p1)); + return cubic2(m.xy, p0, p1, vec2(r.y, r2.x), delta - 1.0); + } +} + +// Interpolate cubic packed bayer +vec4 interpolateCubicPacked(vec2 offset, ivec2 pos, bool isRed) { + ivec2 inputSize = imageSize(uInputImage); + vec2 indexPos = vec2(pos) + vec2(offset.x / 4.0, offset.y); + vec2 maxPos = vec2(inputSize.x - 3, inputSize.y - 5); + vec2 resPos = clamp(indexPos, vec2(1.0, 2.0), maxPos); + + int blueOffset = isRed ? 0 : 1; + ivec2 base = ivec2(resPos.x, int((resPos.y - float(blueOffset)) / 2.0) * 2 + blueOffset); + + vec2 delta = resPos - vec2(base); + vec2 maximum = vec2(0.0); + vec2 minimum = vec2(65535.0); + vec2 unused = vec2(0.0); + vec2 v_1 = mixCubicLine(ivec2(base.x, base.y - 2), delta.x * 2.0, isRed, unused, unused); + vec2 v0 = mixCubicLine(ivec2(base.x, base.y + 0), delta.x * 2.0, isRed, minimum, maximum); + vec2 v1 = mixCubicLine(ivec2(base.x, base.y + 2), delta.x * 2.0, isRed, minimum, maximum); + vec2 v2 = mixCubicLine(ivec2(base.x, base.y + 4), delta.x * 2.0, isRed, unused, unused); + + vec2 h = cubic2(v_1, v0.xy, v1.xy, v2, delta.y / 2.0); + h = clamp(round(h), minimum, maximum) / vec2(65535.0); + + vec4 inVal = imageLoad(uInputImage, pos); + if (isRed) { + // Red line: replace R only (1st and 3rd), keep G (2nd and 4th) - match Metal + return vec4(h.x, inVal.y, h.y, inVal.w); + } else { + // Blue line: replace B only (2nd and 4th), keep G (1st and 3rd) - match Metal + return vec4(inVal.x, h.x, inVal.z, h.y); + } + +} + + + +// Calculate vignetting factor from lookup table +float calculateVignFactor(vec2 gid) { + vec2 rad = gid / uParams.imageScale * uParams.pixelSize; + float radius = length(rad) * float(uParams.vignTableDiv); + float readVal = imageLoad(uVignetteTable, ivec2(radius, 0)).r; + float factor = 1.0 + (readVal - 1.0) * uParams.vignAmount; + return factor; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 outputSize = imageSize(uOutputImage); + + // Boundary check + if (gid.x >= outputSize.x || gid.y >= outputSize.y) { + return; + } + + // Calculate positions for 4 pixels in packed bayer + vec2 pos0 = keystoneTransform(uParams.matA, uParams.matB, uParams.matC, + vec2(4.0 * float(gid.x) + 0.0, float(gid.y)) + vec2(uParams.dstRectLeftTop)); + vec2 pos1 = keystoneTransform(uParams.matA, uParams.matB, uParams.matC, + vec2(4.0 * float(gid.x) + 1.0, float(gid.y)) + vec2(uParams.dstRectLeftTop)); + vec2 pos2 = keystoneTransform(uParams.matA, uParams.matB, uParams.matC, + vec2(4.0 * float(gid.x) + 2.0, float(gid.y)) + vec2(uParams.dstRectLeftTop)); + vec2 pos3 = keystoneTransform(uParams.matA, uParams.matB, uParams.matC, + vec2(4.0 * float(gid.x) + 3.0, float(gid.y)) + vec2(uParams.dstRectLeftTop)); + + vec2 lensPos0 = pos0 + uParams.centerOffset; + vec2 lensPos1 = pos1 + uParams.centerOffset; + vec2 lensPos2 = pos2 + uParams.centerOffset; + vec2 lensPos3 = pos3 + uParams.centerOffset; + + vec4 cor = vec4(calculateVignFactor(lensPos0), + calculateVignFactor(lensPos1), + calculateVignFactor(lensPos2), + calculateVignFactor(lensPos3)); + + vec4 inVal = imageLoad(uInputImage, gid); + + // Debug mode handling + if (uDebugMode == 1) { + // Pass through + imageStore(uOutputImage, gid, inVal); + } else if (uDebugMode == 2) { + // Visualize vignetting factors + float avgCor = (cor.r + cor.g + cor.b + cor.a) / 4.0; + vec4 color = vec4(avgCor, avgCor, avgCor, 1.0); + imageStore(uOutputImage, gid, color); + } else { + // Normal processing + vec4 result = inVal * cor; + imageStore(uOutputImage, gid, result); + } +} diff --git a/research/phocus_glsl/05_lens_geometry/grayVignetteHtsCS_0x306f136.comp b/research/phocus_glsl/05_lens_geometry/grayVignetteHtsCS_0x306f136.comp new file mode 100644 index 00000000..2abb17ef --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/grayVignetteHtsCS_0x306f136.comp @@ -0,0 +1,200 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: a462ddc6676773abca3e4f28156aaafddc7924aeab527f6b5d0b63026dd585f5 + * ELF offsets: 0x306f136 + * Symbols: grayVignetteHtsCS_computeShaderSource + */ + +#version 310 es +precision highp float; +//precision highp int; +precision highp image2D; + +layout(rgba16f, binding = 0) readonly uniform image2D uInputImage; +layout(rgba32f, binding = 1) readonly uniform image2D uHtsDistTexture; +layout(rgba16f, binding = 2) writeonly uniform image2D uOutputImage; + +layout(std140, binding = 0) uniform HtsVignetteParams { + vec3 matA; + float vignAmount; + vec3 matB; + float imageScale; + vec3 matC; + float offsetScale; + ivec2 srcRectLeftTop; + ivec2 dstRectLeftTop; + ivec2 maxRectSize; + ivec2 keystoneLimit; + ivec2 maskMapSize; + bool blackOutOfBounds; + int padding; +} uParams; + +uniform int uDebugMode; + +layout(local_size_x = 16, local_size_y = 16) in; + + +// Cubic interpolation function (Catmull-Rom spline) +vec4 cubic(vec4 v_1, vec4 v0, vec4 v1, vec4 v2, float delta) { + vec4 a = v2 * (1.0/6.0) - v1 * 0.5 + v0 * 0.5 - v_1 * (1.0/6.0); + vec4 b = v_1 * 0.5 + v1 * 0.5 - v0; + vec4 c = -v2 * (1.0/6.0) + v1 - v0 * 0.5 - v_1 * (1.0/3.0); + vec4 d = v0; + + return a * (delta * delta * delta) + b * (delta * delta) + c * delta + d; +} + +vec2 cubic2(vec2 v_1, vec2 v0, vec2 v1, vec2 v2, float delta) { + vec2 a = v2 * (1.0/6.0) - v1 * 0.5 + v0 * 0.5 - v_1 * (1.0/6.0); + vec2 b = v_1 * 0.5 + v1 * 0.5 - v0; + vec2 c = -v2 * (1.0/6.0) + v1 - v0 * 0.5 - v_1 * (1.0/3.0); + vec2 d = v0; + + return a * (delta * delta * delta) + b * (delta * delta) + c * delta + d; +} + +// Keystone transform (homogeneous 3x3 matrix) +vec2 keystoneTransform(vec3 matA, vec3 matB, vec3 matC, vec2 pos) { + vec3 posH = vec3(pos.x, pos.y, 1.0); + vec3 transformed; + transformed.x = dot(matA, posH); + transformed.y = dot(matB, posH); + transformed.z = dot(matC, posH); + return vec2(transformed.x / transformed.z, transformed.y / transformed.z); +} + +// Select red or blue channel from packed bayer (match Metal: .xz/.yw = 1st+3rd / 2nd+4th = .rb/.ga) +vec2 selectRedBlue(vec4 packed, bool isRed) { + return isRed ? packed.rb : packed.ga; +} + +// Mix cubic line for packed bayer format +vec2 mixCubicLine(ivec2 pos, float delta, bool isRed, inout vec2 minimum, inout vec2 maximum) { + // cubic2 algorithm is in data format ushort + vec2 l = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x - 1, pos.y)), isRed) * vec2(65535.0); + vec2 m = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x + 0, pos.y)), isRed) * vec2(65535.0); + vec2 r = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x + 1, pos.y)), isRed) * vec2(65535.0); + vec2 r2 = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x + 2, pos.y)), isRed) * vec2(65535.0); + + if (delta < 1.0) { + vec2 p0 = m.xy; + vec2 p1 = vec2(m.y, r.x); + minimum = min(minimum, min(p0, p1)); + maximum = max(maximum, max(p0, p1)); + return cubic2(vec2(l.y, m.x), p0, p1, r.xy, delta); + } else { + vec2 p0 = vec2(m.y, r.x); + vec2 p1 = r.xy; + minimum = min(minimum, min(p0, p1)); + maximum = max(maximum, max(p0, p1)); + return cubic2(m.xy, p0, p1, vec2(r.y, r2.x), delta - 1.0); + } +} + +// Interpolate cubic packed bayer +vec4 interpolateCubicPacked(vec2 offset, ivec2 pos, bool isRed) { + ivec2 inputSize = imageSize(uInputImage); + vec2 indexPos = vec2(pos) + vec2(offset.x / 4.0, offset.y); + vec2 maxPos = vec2(inputSize.x - 3, inputSize.y - 5); + vec2 resPos = clamp(indexPos, vec2(1.0, 2.0), maxPos); + + int blueOffset = isRed ? 0 : 1; + ivec2 base = ivec2(resPos.x, int((resPos.y - float(blueOffset)) / 2.0) * 2 + blueOffset); + + vec2 delta = resPos - vec2(base); + vec2 maximum = vec2(0.0); + vec2 minimum = vec2(65535.0); + vec2 unused = vec2(0.0); + vec2 v_1 = mixCubicLine(ivec2(base.x, base.y - 2), delta.x * 2.0, isRed, unused, unused); + vec2 v0 = mixCubicLine(ivec2(base.x, base.y + 0), delta.x * 2.0, isRed, minimum, maximum); + vec2 v1 = mixCubicLine(ivec2(base.x, base.y + 2), delta.x * 2.0, isRed, minimum, maximum); + vec2 v2 = mixCubicLine(ivec2(base.x, base.y + 4), delta.x * 2.0, isRed, unused, unused); + + vec2 h = cubic2(v_1, v0.xy, v1.xy, v2, delta.y / 2.0); + h = clamp(round(h), minimum, maximum) / vec2(65535.0); + + vec4 inVal = imageLoad(uInputImage, pos); + if (isRed) { + // Red line: replace R only (1st and 3rd), keep G (2nd and 4th) - match Metal + return vec4(h.x, inVal.y, h.y, inVal.w); + } else { + // Blue line: replace B only (2nd and 4th), keep G (1st and 3rd) - match Metal + return vec4(inVal.x, h.x, inVal.z, h.y); + } + +} + + + +// Bilinear interpolation +vec4 bilinearSample(image2D tex, vec2 pos, ivec2 maxPos) { + pos = clamp(pos, vec2(0.0), vec2(maxPos)); + ivec2 basePos = ivec2(pos); + vec2 delta = pos - vec2(basePos); + + ivec2 p00 = clamp(basePos + ivec2(0, 0), ivec2(0), maxPos); + ivec2 p10 = clamp(basePos + ivec2(1, 0), ivec2(0), maxPos); + ivec2 p01 = clamp(basePos + ivec2(0, 1), ivec2(0), maxPos); + ivec2 p11 = clamp(basePos + ivec2(1, 1), ivec2(0), maxPos); + + vec4 v00 = imageLoad(tex, p00); + vec4 v10 = imageLoad(tex, p10); + vec4 v01 = imageLoad(tex, p01); + vec4 v11 = imageLoad(tex, p11); + + vec4 h0 = mix(v00, v10, delta.x); + vec4 h1 = mix(v01, v11, delta.x); + return mix(h0, h1, delta.y); +} + +// Calculate HTS vignetting factor +float htsVign(vec2 pos) { + ivec2 maxPos = uParams.maskMapSize - ivec2(1); + vec4 map = bilinearSample(uHtsDistTexture, pos * uParams.imageScale, maxPos); + return 1.0 + map.z * uParams.vignAmount; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 outputSize = imageSize(uOutputImage); + + // Boundary check - processing packed bayer tiles + if (gid.x >= outputSize.x || gid.y >= outputSize.y) { + return; + } + + // Calculate input positions for 4 pixels (one packed tile) + vec2 inPos0 = vec2(4.0 * float(gid.x) + 0.0, float(gid.y)) + vec2(uParams.dstRectLeftTop); + vec2 inPos1 = vec2(4.0 * float(gid.x) + 1.0, float(gid.y)) + vec2(uParams.dstRectLeftTop); + vec2 inPos2 = vec2(4.0 * float(gid.x) + 2.0, float(gid.y)) + vec2(uParams.dstRectLeftTop); + vec2 inPos3 = vec2(4.0 * float(gid.x) + 3.0, float(gid.y)) + vec2(uParams.dstRectLeftTop); + + vec2 pos0 = keystoneTransform(uParams.matA, uParams.matB, uParams.matC, inPos0); + vec2 pos1 = keystoneTransform(uParams.matA, uParams.matB, uParams.matC, inPos1); + vec2 pos2 = keystoneTransform(uParams.matA, uParams.matB, uParams.matC, inPos2); + vec2 pos3 = keystoneTransform(uParams.matA, uParams.matB, uParams.matC, inPos3); + + float f0 = htsVign(pos0); + float f1 = htsVign(pos1); + float f2 = htsVign(pos2); + float f3 = htsVign(pos3); + vec4 factor = vec4(f0, f1, f2, f3); + + vec4 inVal = imageLoad(uInputImage, gid); + + // Debug mode handling + if (uDebugMode == 1) { + // Pass through + imageStore(uOutputImage, gid, inVal); + } else if (uDebugMode == 2) { + // Visualize vignetting factors + float avgFactor = (factor.r + factor.g + factor.b + factor.a) / 4.0; + vec4 color = vec4(avgFactor, avgFactor, avgFactor, 1.0); + imageStore(uOutputImage, gid, color); + } else { + // Normal processing + vec4 result = inVal * factor; + imageStore(uOutputImage, gid, result); + } +} diff --git a/research/phocus_glsl/05_lens_geometry/htsAberrationCS_0x309f9c3.comp b/research/phocus_glsl/05_lens_geometry/htsAberrationCS_0x309f9c3.comp new file mode 100644 index 00000000..06e6565b --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/htsAberrationCS_0x309f9c3.comp @@ -0,0 +1,189 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: a7d6c853553ca43a007eca52070267af41ea92582da3e951654cd68728e732c2 + * ELF offsets: 0x309f9c3 + * Symbols: htsAberrationCS_computeShaderSource + */ + +#version 310 es +precision highp float; +//precision highp int; +precision highp image2D; + +layout(rgba16f, binding = 0) readonly uniform image2D uInputImage; +layout(rgba32f, binding = 1) readonly uniform image2D uHtsTexture; +layout(rgba16f, binding = 2) writeonly uniform image2D uOutputImage; + +layout(std140, binding = 0) uniform AberrationParams { + vec4 redParam; + vec4 blueParam; + float redOffset; + float blueOffset; + vec2 offsetFromCenter; + ivec2 marginToSrcRect; + ivec2 fullImageSize; +} uParams; + +uniform int uDebugMode; + +layout(local_size_x = 16, local_size_y = 16) in; + + +// Cubic interpolation function (Catmull-Rom spline) +vec4 cubic(vec4 v_1, vec4 v0, vec4 v1, vec4 v2, float delta) { + vec4 a = v2 * (1.0/6.0) - v1 * 0.5 + v0 * 0.5 - v_1 * (1.0/6.0); + vec4 b = v_1 * 0.5 + v1 * 0.5 - v0; + vec4 c = -v2 * (1.0/6.0) + v1 - v0 * 0.5 - v_1 * (1.0/3.0); + vec4 d = v0; + + return a * (delta * delta * delta) + b * (delta * delta) + c * delta + d; +} + +vec2 cubic2(vec2 v_1, vec2 v0, vec2 v1, vec2 v2, float delta) { + vec2 a = v2 * (1.0/6.0) - v1 * 0.5 + v0 * 0.5 - v_1 * (1.0/6.0); + vec2 b = v_1 * 0.5 + v1 * 0.5 - v0; + vec2 c = -v2 * (1.0/6.0) + v1 - v0 * 0.5 - v_1 * (1.0/3.0); + vec2 d = v0; + + return a * (delta * delta * delta) + b * (delta * delta) + c * delta + d; +} + +// Keystone transform (homogeneous 3x3 matrix) +vec2 keystoneTransform(vec3 matA, vec3 matB, vec3 matC, vec2 pos) { + vec3 posH = vec3(pos.x, pos.y, 1.0); + vec3 transformed; + transformed.x = dot(matA, posH); + transformed.y = dot(matB, posH); + transformed.z = dot(matC, posH); + return vec2(transformed.x / transformed.z, transformed.y / transformed.z); +} + +// Select red or blue channel from packed bayer (match Metal: .xz/.yw = 1st+3rd / 2nd+4th = .rb/.ga) +vec2 selectRedBlue(vec4 packed, bool isRed) { + return isRed ? packed.rb : packed.ga; +} + +// Mix cubic line for packed bayer format +vec2 mixCubicLine(ivec2 pos, float delta, bool isRed, inout vec2 minimum, inout vec2 maximum) { + // cubic2 algorithm is in data format ushort + vec2 l = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x - 1, pos.y)), isRed) * vec2(65535.0); + vec2 m = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x + 0, pos.y)), isRed) * vec2(65535.0); + vec2 r = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x + 1, pos.y)), isRed) * vec2(65535.0); + vec2 r2 = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x + 2, pos.y)), isRed) * vec2(65535.0); + + if (delta < 1.0) { + vec2 p0 = m.xy; + vec2 p1 = vec2(m.y, r.x); + minimum = min(minimum, min(p0, p1)); + maximum = max(maximum, max(p0, p1)); + return cubic2(vec2(l.y, m.x), p0, p1, r.xy, delta); + } else { + vec2 p0 = vec2(m.y, r.x); + vec2 p1 = r.xy; + minimum = min(minimum, min(p0, p1)); + maximum = max(maximum, max(p0, p1)); + return cubic2(m.xy, p0, p1, vec2(r.y, r2.x), delta - 1.0); + } +} + +// Interpolate cubic packed bayer +vec4 interpolateCubicPacked(vec2 offset, ivec2 pos, bool isRed) { + ivec2 inputSize = imageSize(uInputImage); + vec2 indexPos = vec2(pos) + vec2(offset.x / 4.0, offset.y); + vec2 maxPos = vec2(inputSize.x - 3, inputSize.y - 5); + vec2 resPos = clamp(indexPos, vec2(1.0, 2.0), maxPos); + + int blueOffset = isRed ? 0 : 1; + ivec2 base = ivec2(resPos.x, int((resPos.y - float(blueOffset)) / 2.0) * 2 + blueOffset); + + vec2 delta = resPos - vec2(base); + vec2 maximum = vec2(0.0); + vec2 minimum = vec2(65535.0); + vec2 unused = vec2(0.0); + vec2 v_1 = mixCubicLine(ivec2(base.x, base.y - 2), delta.x * 2.0, isRed, unused, unused); + vec2 v0 = mixCubicLine(ivec2(base.x, base.y + 0), delta.x * 2.0, isRed, minimum, maximum); + vec2 v1 = mixCubicLine(ivec2(base.x, base.y + 2), delta.x * 2.0, isRed, minimum, maximum); + vec2 v2 = mixCubicLine(ivec2(base.x, base.y + 4), delta.x * 2.0, isRed, unused, unused); + + vec2 h = cubic2(v_1, v0.xy, v1.xy, v2, delta.y / 2.0); + h = clamp(round(h), minimum, maximum) / vec2(65535.0); + + vec4 inVal = imageLoad(uInputImage, pos); + if (isRed) { + // Red line: replace R only (1st and 3rd), keep G (2nd and 4th) - match Metal + return vec4(h.x, inVal.y, h.y, inVal.w); + } else { + // Blue line: replace B only (2nd and 4th), keep G (1st and 3rd) - match Metal + return vec4(inVal.x, h.x, inVal.z, h.y); + } + +} + + + +// Get HTS aberration offsets from lookup texture +vec4 getHtsAberrationOffsets(vec2 pos) { + ivec2 htsSize = imageSize(uHtsTexture); + vec2 adjustedPos = pos + uParams.offsetFromCenter + + vec2(uParams.fullImageSize) / 2.0; + vec2 htsSizeF = vec2(htsSize - ivec2(1)); + vec2 relative0 = adjustedPos / vec2(uParams.fullImageSize - ivec2(1)) * htsSizeF; + vec2 relative1 = clamp(relative0 + vec2(1.0), vec2(0.0), htsSizeF); + + ivec2 base0 = ivec2(relative0); + ivec2 base1 = ivec2(relative1); + vec2 delta = relative0 - vec2(base0); + + // Bilinear interpolation + vec4 p00 = imageLoad(uHtsTexture, ivec2(base0.x, base0.y)); + vec4 p10 = imageLoad(uHtsTexture, ivec2(base1.x, base0.y)); + vec4 p01 = imageLoad(uHtsTexture, ivec2(base0.x, base1.y)); + vec4 p11 = imageLoad(uHtsTexture, ivec2(base1.x, base1.y)); + + vec4 p0 = mix(p00, p10, delta.x); + vec4 p1 = mix(p01, p11, delta.x); + vec4 result = mix(p0, p1, delta.y); + + // Order is rY, bY, rX, bX -> rearrange to rX, rY, bX, bY + return result.zwxy; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 outputSize = imageSize(uOutputImage); + + // Boundary check + if (gid.x >= outputSize.x || gid.y >= (outputSize.y + 1) / 2) { + return; + } + + vec2 realPos = vec2(gid.x * 4, gid.y * 2); + vec4 offsets = getHtsAberrationOffsets(realPos); + + ivec2 inOffset = ivec2(uParams.marginToSrcRect.x / 4, uParams.marginToSrcRect.y); + ivec2 posRed = ivec2(gid.x, gid.y * 2 + 0); + ivec2 posBlue = ivec2(gid.x, gid.y * 2 + 1); + + // Debug: 0 = normal + // 1 = pass-through + // 2 = green overlay (after BayerFastInterpolation, bright green = where correction was applied) + if (uDebugMode == 1) { + imageStore(uOutputImage, posRed, imageLoad(uInputImage, posRed + inOffset)); + imageStore(uOutputImage, posBlue, imageLoad(uInputImage, posBlue + inOffset)); + } else if (uDebugMode == 2) { + vec4 inRed = imageLoad(uInputImage, posRed + inOffset); + vec4 inBlue = imageLoad(uInputImage, posBlue + inOffset); + vec4 resultRed = interpolateCubicPacked(offsets.xy, posRed + inOffset, true); + vec4 resultBlue = interpolateCubicPacked(offsets.zw, posBlue + inOffset, false); + float diffR = length(resultRed - inRed); + float diffB = length(resultBlue - inBlue); + float v = clamp(max(diffR, diffB) * 20.0, 0.0, 1.0); + imageStore(uOutputImage, posRed, vec4(0.0, v, 0.0, v)); + imageStore(uOutputImage, posBlue, vec4(v, 0.0, v, 0.0)); + } else { + vec4 resultRed = interpolateCubicPacked(offsets.xy, posRed + inOffset, true); + vec4 resultBlue = interpolateCubicPacked(offsets.zw, posBlue + inOffset, false); + imageStore(uOutputImage, posRed, resultRed); + imageStore(uOutputImage, posBlue, resultBlue); + } +} diff --git a/research/phocus_glsl/05_lens_geometry/orientation_rgb180_0x306e4e6.frag b/research/phocus_glsl/05_lens_geometry/orientation_rgb180_0x306e4e6.frag new file mode 100644 index 00000000..7f51f9f9 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/orientation_rgb180_0x306e4e6.frag @@ -0,0 +1,26 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 81dae8448e22d2a50d7394fbb542a5d64f9d534f5b32b392979fed8612b174d5 + * ELF offsets: 0x306e4e6 + * Symbols: orientation_rgb180_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform ivec2 uMargin; +uniform int uWidth; +uniform int uHeight; + +void main() { + ivec2 gid = ivec2(gl_FragCoord.xy); + + ivec2 srcPixel = ivec2(uWidth - gid.x, uHeight - gid.y); + + vec4 inColor = texelFetch(uInputTexture0, srcPixel, 0); + + FragColor = vec4(inColor.rgb, inColor.a); +} diff --git a/research/phocus_glsl/05_lens_geometry/orientation_rgb270_0x303edb0.frag b/research/phocus_glsl/05_lens_geometry/orientation_rgb270_0x303edb0.frag new file mode 100644 index 00000000..c86c1d7c --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/orientation_rgb270_0x303edb0.frag @@ -0,0 +1,26 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: b20405eac1c785d1a0359002535ad92b2338a72100b12fd83c800123eb490e83 + * ELF offsets: 0x303edb0 + * Symbols: orientation_rgb270_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform ivec2 uMargin; +uniform int uWidth; +uniform int uHeight; + +void main() { + ivec2 gid = ivec2(gl_FragCoord.xy); + + ivec2 srcPixel = ivec2(uWidth - gid.y, gid.x + uMargin.y); + + vec4 inColor = texelFetch(uInputTexture0, srcPixel, 0); + + FragColor = vec4(inColor.rgb, inColor.a); +} diff --git a/research/phocus_glsl/05_lens_geometry/orientation_rgb90_0x307d298.frag b/research/phocus_glsl/05_lens_geometry/orientation_rgb90_0x307d298.frag new file mode 100644 index 00000000..dcaf43a1 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/orientation_rgb90_0x307d298.frag @@ -0,0 +1,26 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: b379afb58ea22e4d0d0f4fa880dc1ee053d527d3a82fdb86881459b5a8aee522 + * ELF offsets: 0x307d298 + * Symbols: orientation_rgb90_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform ivec2 uMargin; +uniform int uWidth; +uniform int uHeight; + +void main() { + ivec2 gid = ivec2(gl_FragCoord.xy); + + ivec2 srcPixel = ivec2(gid.y + uMargin.x, uHeight - gid.x); + + vec4 inColor = texelFetch(uInputTexture0, srcPixel, 0); + + FragColor = vec4(inColor.rgb, inColor.a); +} diff --git a/research/phocus_glsl/05_lens_geometry/repeatMargin_0x3084296.frag b/research/phocus_glsl/05_lens_geometry/repeatMargin_0x3084296.frag new file mode 100644 index 00000000..d2b978c1 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/repeatMargin_0x3084296.frag @@ -0,0 +1,60 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 9373e67d9d551351332bb5ad0d8727a1e3a8524bd8cf1d63d27a92baab843eb5 + * ELF offsets: 0x3084296 + * Symbols: repeatMargin_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +precision highp int; + +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform bool uDirectCopy; +uniform vec4 uValidArea; +uniform vec2 uMargin; + +void main() { + ivec2 pixelCoord = ivec2(gl_FragCoord.xy); + + if (uDirectCopy) { + FragColor = texelFetch(uInputTexture0, pixelCoord, 0); + return; + } + + int validL = int(uValidArea.x); + int validT = int(uValidArea.y); + int validR = int(uValidArea.z); + int validB = int(uValidArea.w); + ivec2 marginI = ivec2(uMargin); + + if (validR <= validL || validB <= validT) { + FragColor = texelFetch(uInputTexture0, pixelCoord + marginI, 0); + return; + } + + int srcX = pixelCoord.x; + if (srcX < validL) { + srcX = validL + (abs(validL - pixelCoord.x) % 2); + } + else if (srcX >= validR) { + int edge = validR - 1; + srcX = edge - (abs(edge - pixelCoord.x) % 2); + } + + int srcY = pixelCoord.y; + if (srcY < validT) { + srcY = validT + (abs(validT - pixelCoord.y) % 2); + } + else if (srcY >= validB) { + int edge = validB - 1; + srcY = edge - (abs(edge - pixelCoord.y) % 2); + } + + ivec2 finalSourceCoord = ivec2(srcX, srcY) + marginI; + + FragColor = texelFetch(uInputTexture0, finalSourceCoord, 0); +} diff --git a/research/phocus_glsl/05_lens_geometry/resize_0x3029cb8.frag b/research/phocus_glsl/05_lens_geometry/resize_0x3029cb8.frag new file mode 100644 index 00000000..1139d508 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/resize_0x3029cb8.frag @@ -0,0 +1,78 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 8c44c4f649d107b2346725d1b018d85e426fded06bd05fbb5a836dbeaf45e569 + * ELF offsets: 0x3029cb8 + * Symbols: resize_fragmentShaderSource + */ + +#version 300 es +precision highp float; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; + +uniform ivec2 uInputSize; +uniform ivec2 uOutputSize; +uniform ivec2 uMargin; +uniform int uAlgorithmType; +uniform ivec2 uMidSize; + +void main() { + ivec2 outputPos = ivec2(gl_FragCoord.xy); + + if (outputPos.x >= uOutputSize.x || outputPos.y >= uOutputSize.y) { + FragColor = vec4(0.0); + return; + } + + ivec2 inputPos = outputPos + uMargin; + + if (uAlgorithmType == 0) { // IntegralDown + ivec2 scale = uInputSize / uOutputSize; + ivec2 startPos = outputPos * scale; + ivec2 endPos = min(startPos + scale, uInputSize); + + vec3 sum = vec3(0.0); + int count = 0; + + for (int y = startPos.y; y < endPos.y; y++) { + for (int x = startPos.x; x < endPos.x; x++) { + if (x < uInputSize.x && y < uInputSize.y) { + vec2 texCoord = (vec2(x, y) + vec2(0.5)) / vec2(uInputSize); + vec4 pixel = texture(uInputTexture0, texCoord); + sum += pixel.rgb; + count++; + } + } + } + + vec3 result = sum / float(count); + FragColor = vec4(result, 0.0); + } else { + vec2 scale = vec2(uInputSize) / vec2(uOutputSize); + vec2 sourcePos = (vec2(outputPos) + 0.5) * scale - 0.5; + + ivec2 base = ivec2(sourcePos); + vec2 offset = sourcePos - vec2(base); + + ivec2 p00 = clamp(base, ivec2(0), uInputSize - 1); + ivec2 p10 = clamp(base + ivec2(1, 0), ivec2(0), uInputSize - 1); + ivec2 p01 = clamp(base + ivec2(0, 1), ivec2(0), uInputSize - 1); + ivec2 p11 = clamp(base + ivec2(1, 1), ivec2(0), uInputSize - 1); + + vec4 pix00 = texture(uInputTexture0, (vec2(p00) + vec2(0.5)) / vec2(uInputSize)); + vec4 pix10 = texture(uInputTexture0, (vec2(p10) + vec2(0.5)) / vec2(uInputSize)); + vec4 pix01 = texture(uInputTexture0, (vec2(p01) + vec2(0.5)) / vec2(uInputSize)); + vec4 pix11 = texture(uInputTexture0, (vec2(p11) + vec2(0.5)) / vec2(uInputSize)); + + vec3 result = mix( + mix(pix00.rgb, pix10.rgb, offset.x), + mix(pix01.rgb, pix11.rgb, offset.x), + offset.y + ); + + FragColor = vec4(result, 1.0); + } +} diff --git a/research/phocus_glsl/05_lens_geometry/resizeintegraldown_0x2ffcdeb.frag b/research/phocus_glsl/05_lens_geometry/resizeintegraldown_0x2ffcdeb.frag new file mode 100644 index 00000000..13817cab --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/resizeintegraldown_0x2ffcdeb.frag @@ -0,0 +1,52 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: abc100e93094e15844f1aac7761b8b78aa5ac10d1fc122c86a131473eb3c0293 + * ELF offsets: 0x2ffcdeb + * Symbols: resizeintegraldown_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; + +uniform ivec2 uInputSize; +uniform ivec2 uOutputSize; +uniform int uDownHFactor; +uniform int uDownVFactor; + +void main() { + + ivec2 outputPos = ivec2(gl_FragCoord.xy); + + if (outputPos.x >= uOutputSize.x || outputPos.y >= uOutputSize.y) { + FragColor = vec4(0.0); + return; + } + + int startX = outputPos.x * uDownHFactor; + int endX = min(startX + uDownHFactor, uInputSize.x); + int startY = outputPos.y * uDownVFactor; + int endY = min(startY + uDownVFactor, uInputSize.y); + + vec3 sum = vec3(0.0); + int count = 0; + + for (int y = startY; y < endY; y++) { + for (int x = startX; x < endX; x++) { + if (x < uInputSize.x && y < uInputSize.y) { + vec2 texCoord = (vec2(x, y) + vec2(0.5)) / vec2(uInputSize); + vec4 pixel = texture(uInputTexture0, texCoord); + sum += pixel.rgb; + count++; + } + } + } + + vec3 result = count > 0 ? sum / float(count) : vec3(0.0); + FragColor = vec4(result, 1.0); +} diff --git a/research/phocus_glsl/05_lens_geometry/resizesplinehorizontal_0x30768a8.frag b/research/phocus_glsl/05_lens_geometry/resizesplinehorizontal_0x30768a8.frag new file mode 100644 index 00000000..ebad80e7 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/resizesplinehorizontal_0x30768a8.frag @@ -0,0 +1,135 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: b89be0128b31698dc01785802e45d89a1313909f8f829e4c5e008788151cdaaa + * ELF offsets: 0x30768a8 + * Symbols: resizesplinehorizontal_fragmentShaderSource + */ + +#version 300 es +precision highp float; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform ivec2 uInputSize; +uniform ivec2 uOutputSize; +uniform ivec2 uMargin; +uniform ivec2 uJumpOffset; +uniform ivec2 uCoefOffset; +uniform int uCurrentLineJump; +uniform int uVIndex; +uniform int uLineInCounter; +uniform int uLineOutCounter; + +// Conservative version for mobile GPU compatibility. +// Avoids in-place mutation patterns that may be misoptimized on some Mali/PowerVR drivers. +vec4 CalcCoefAramini23(float t) { + float one = 1.0; + float two = 2.0; + float three = 3.0; + + float tm1 = t - one; + float t2 = t * t; + + float k0 = two / three; + float k1 = tm1 * t; + float base23 = k0 * k1; + + float a = base23 * t; + float b = base23 * tm1; + + float c0 = two * t; + float c1 = c0 - three; + float c = c1 * t2; + + float w0 = -b; + float w1 = one - a + c; + float w2 = b - c; + float w3 = a; + + return vec4(w0, w1, w2, w3); +} + +void main() { + ivec2 outputPos = ivec2(floor(gl_FragCoord.xy)); + + if (outputPos.x < 0 || outputPos.y < 0 || + outputPos.x >= uOutputSize.x || outputPos.y >= uOutputSize.y) { + FragColor = vec4(0.0, 0.0, 0.0, 1.0); + return; + } + + ivec2 inputPos = outputPos + uMargin; + inputPos = clamp(inputPos, ivec2(0), uInputSize - 1); + + float inputW = float(uInputSize.x); + float outputW = float(uOutputSize.x); + float outX = float(outputPos.x); + + float srcX = (inputW * (outX + 0.5)) / outputW - 0.5; + + float srcXFloor = floor(srcX); + int base = int(srcXFloor); + float offset = srcX - srcXFloor; + + // Safety clamp to reduce risk of bad intermediate values on buggy drivers. + offset = clamp(offset, 0.0, 1.0); + + vec4 coefs = CalcCoefAramini23(offset); + + ivec2 p0; + ivec2 p1; + ivec2 p2; + ivec2 p3; + + if (base <= 0) { + p0 = ivec2(0, inputPos.y); + p1 = ivec2(0, inputPos.y); + p2 = ivec2(0, inputPos.y); + p3 = ivec2(1, inputPos.y); + } else if (base == 1) { + p0 = ivec2(0, inputPos.y); + p1 = ivec2(1, inputPos.y); + p2 = ivec2(2, inputPos.y); + p3 = ivec2(3, inputPos.y); + } else if (base >= uInputSize.x - 1) { + p0 = ivec2(uInputSize.x - 3, inputPos.y); + p1 = ivec2(uInputSize.x - 2, inputPos.y); + p2 = ivec2(uInputSize.x - 1, inputPos.y); + p3 = ivec2(uInputSize.x - 1, inputPos.y); + } else { + p0 = ivec2(base - 1, inputPos.y); + p1 = ivec2(base, inputPos.y); + p2 = ivec2(base + 1, inputPos.y); + p3 = ivec2(base + 2, inputPos.y); + } + + p0 = clamp(p0, ivec2(0), uInputSize - 1); + p1 = clamp(p1, ivec2(0), uInputSize - 1); + p2 = clamp(p2, ivec2(0), uInputSize - 1); + p3 = clamp(p3, ivec2(0), uInputSize - 1); + + vec2 invSize = 1.0 / vec2(float(uInputSize.x), float(uInputSize.y)); + + vec2 uv0 = (vec2(float(p0.x), float(p0.y)) + vec2(0.5, 0.5)) * invSize; + vec2 uv1 = (vec2(float(p1.x), float(p1.y)) + vec2(0.5, 0.5)) * invSize; + vec2 uv2 = (vec2(float(p2.x), float(p2.y)) + vec2(0.5, 0.5)) * invSize; + vec2 uv3 = (vec2(float(p3.x), float(p3.y)) + vec2(0.5, 0.5)) * invSize; + + vec4 pix0 = texture(uInputTexture0, uv0); + vec4 pix1 = texture(uInputTexture0, uv1); + vec4 pix2 = texture(uInputTexture0, uv2); + vec4 pix3 = texture(uInputTexture0, uv3); + + vec3 result = vec3(0.0, 0.0, 0.0); + result += pix0.rgb * coefs.x; + result += pix1.rgb * coefs.y; + result += pix2.rgb * coefs.z; + result += pix3.rgb * coefs.w; + + // Robustness guard for mobile GPUs / half-float intermediates. + result = clamp(result, 0.0, 1.0); + + FragColor = vec4(result, 1.0); +} diff --git a/research/phocus_glsl/05_lens_geometry/resizesplinevertical_0x3063ecb.frag b/research/phocus_glsl/05_lens_geometry/resizesplinevertical_0x3063ecb.frag new file mode 100644 index 00000000..481ae9b2 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/resizesplinevertical_0x3063ecb.frag @@ -0,0 +1,133 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 11d86a505f5d8f109ce72cdb0b7391d559cf63aeaf7e3b6be57081bf47852d81 + * ELF offsets: 0x3063ecb + * Symbols: resizesplinevertical_fragmentShaderSource + */ + +#version 300 es +precision highp float; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform ivec2 uInputSize; +uniform ivec2 uOutputSize; +uniform ivec2 uMargin; +uniform ivec2 uJumpOffset; +uniform ivec2 uCoefOffset; +uniform int uCurrentLineJump; +uniform int uVIndex; +uniform int uLineInCounter; +uniform int uLineOutCounter; + +// Conservative version for mobile GPU compatibility. +// Avoids in-place mutation patterns that may be misoptimized on some Mali/PowerVR drivers. +vec4 CalcCoefAramini23(float t) { + float one = 1.0; + float two = 2.0; + float three = 3.0; + + float tm1 = t - one; + float t2 = t * t; + + float k0 = two / three; + float k1 = tm1 * t; + float base23 = k0 * k1; + + float a = base23 * t; + float b = base23 * tm1; + + float c0 = two * t; + float c1 = c0 - three; + float c = c1 * t2; + + float w0 = -b; + float w1 = one - a + c; + float w2 = b - c; + float w3 = a; + + return vec4(w0, w1, w2, w3); +} + +void main() { + ivec2 outputPos = ivec2(floor(gl_FragCoord.xy)); + + if (outputPos.x < 0 || outputPos.y < 0 || + outputPos.x >= uOutputSize.x || outputPos.y >= uOutputSize.y) { + FragColor = vec4(0.0, 0.0, 0.0, 1.0); + return; + } + + ivec2 inputPos = outputPos + uMargin; + inputPos = clamp(inputPos, ivec2(0), uInputSize - 1); + + float inputH = float(uInputSize.y); + float outputH = float(uOutputSize.y); + float outY = float(outputPos.y); + + float srcY = (inputH * (outY + 0.5)) / outputH - 0.5; + + float srcYFloor = floor(srcY); + int base = int(srcYFloor); + float offset = srcY - srcYFloor; + + offset = clamp(offset, 0.0, 1.0); + + vec4 coefs = CalcCoefAramini23(offset); + + ivec2 p0; + ivec2 p1; + ivec2 p2; + ivec2 p3; + + if (base <= 0) { + p0 = ivec2(inputPos.x, 0); + p1 = ivec2(inputPos.x, 0); + p2 = ivec2(inputPos.x, 0); + p3 = ivec2(inputPos.x, 1); + } else if (base == 1) { + p0 = ivec2(inputPos.x, 0); + p1 = ivec2(inputPos.x, 1); + p2 = ivec2(inputPos.x, 2); + p3 = ivec2(inputPos.x, 3); + } else if (base >= uInputSize.y - 1) { + p0 = ivec2(inputPos.x, uInputSize.y - 3); + p1 = ivec2(inputPos.x, uInputSize.y - 2); + p2 = ivec2(inputPos.x, uInputSize.y - 1); + p3 = ivec2(inputPos.x, uInputSize.y - 1); + } else { + p0 = ivec2(inputPos.x, base - 1); + p1 = ivec2(inputPos.x, base); + p2 = ivec2(inputPos.x, base + 1); + p3 = ivec2(inputPos.x, base + 2); + } + + p0 = clamp(p0, ivec2(0), uInputSize - 1); + p1 = clamp(p1, ivec2(0), uInputSize - 1); + p2 = clamp(p2, ivec2(0), uInputSize - 1); + p3 = clamp(p3, ivec2(0), uInputSize - 1); + + vec2 invSize = 1.0 / vec2(float(uInputSize.x), float(uInputSize.y)); + + vec2 uv0 = (vec2(float(p0.x), float(p0.y)) + vec2(0.5, 0.5)) * invSize; + vec2 uv1 = (vec2(float(p1.x), float(p1.y)) + vec2(0.5, 0.5)) * invSize; + vec2 uv2 = (vec2(float(p2.x), float(p2.y)) + vec2(0.5, 0.5)) * invSize; + vec2 uv3 = (vec2(float(p3.x), float(p3.y)) + vec2(0.5, 0.5)) * invSize; + + vec4 pix0 = texture(uInputTexture0, uv0); + vec4 pix1 = texture(uInputTexture0, uv1); + vec4 pix2 = texture(uInputTexture0, uv2); + vec4 pix3 = texture(uInputTexture0, uv3); + + vec3 result = vec3(0.0, 0.0, 0.0); + result += pix0.rgb * coefs.x; + result += pix1.rgb * coefs.y; + result += pix2.rgb * coefs.z; + result += pix3.rgb * coefs.w; + + result = clamp(result, 0.0, 1.0); + + FragColor = vec4(result, 1.0); +} diff --git a/research/phocus_glsl/05_lens_geometry/rgbLensFilter_0x2fff342.frag b/research/phocus_glsl/05_lens_geometry/rgbLensFilter_0x2fff342.frag new file mode 100644 index 00000000..5837df81 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/rgbLensFilter_0x2fff342.frag @@ -0,0 +1,413 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 242f8a575c32fa3e5b0867f2b2fc3f678bbc86df9650b329650917b3773fc73a + * ELF offsets: 0x2fff342 + * Symbols: rgbLensFilter_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +in vec2 TexCoord; +out vec4 FragColor; + +// input textures +uniform sampler2D uInputTexture0; +// extra textures +uniform sampler2D uHtsDistTexture; // 1 +uniform sampler2D uHtsAberTexture; // 2 +uniform sampler2D uVignetteTableTexture; // 3 + +struct RGBLensParams { + // the arrangement of members are for alignment purpose + // keystone matrix in 'mat', using vec3 or vec4 requires 16-byte alignment in std140 + vec3 matA; + float redOffset; + vec3 matB; + float greenOffset; + vec3 matC; + float blueOffset; + + vec4 redParam; + vec4 greenParam; + vec4 blueParam; + float pixelSize; + float xOffset; + float yOffset; + float xCenterOffset; + float yCenterOffset; + int xMargin; + int yMargin; + int xMax; + int yMax; + int xKeystoneLimit; + int yKeystoneLimit; + float vignAmount; + float imageScale; + int vignTableDiv; + + float offsetScale; + int xMaxMap; + int yMaxMap; + + int doVignetting; + int doDistortion; + int doAberration; + int doHts; + int blackOutOfBounds; + vec2 padding; +}; + +// UBO - gl es version matters for ubo binding keyword +#if (__VERSION__ >= 310) +layout(std140, binding = 0) uniform ShaderParams { +#else +layout(std140) uniform ShaderParams { +#endif + RGBLensParams params; +} uParams; + +uniform int uEnableFastMode; + +vec2 KeystoneTransform(in mat3 mat, in vec2 pos) +{ + vec3 posF = vec3(pos.x, pos.y, 1.0); + vec3 keystonePos = mat * posF; + return vec2(keystonePos.x / keystonePos.z, keystonePos.y / keystonePos.z); +} + +vec2 ApplyParams(in vec2 pos, in vec4 param, in float paramOffset) +{ + float radiusP2 = pos.x * pos.x + pos.y * pos.y; + float radius = sqrt(radiusP2); + vec4 coeffs = vec4(radius, radiusP2, radiusP2 * radius, radiusP2 * radiusP2); + vec4 cors = param * coeffs; + float cor = cors.x + cors.y + cors.z + cors.w + paramOffset; + return pos * cor; +} + +float CalculateVignFactor(const in sampler2D texVign, in vec2 offPos, in RGBLensParams params) +{ + vec2 rad = offPos / params.imageScale * params.pixelSize; + float radius = sqrt(rad.x * rad.x + rad.y * rad.y) * float(params.vignTableDiv); + int radiusIndex = int(floor(radius)); + // length is 4500 + radiusIndex = clamp(radiusIndex, 0, 4500 - 1); + float factor = 1.0f + (texelFetch(texVign, ivec2(radiusIndex, 0), 0).x - 1.0f) * params.vignAmount; + return factor; +} + +// Bicubic interpolation weight function (Catmull-Rom spline) +// Significantly faster than Lanczos with minimal visual quality difference +float CubicWeight(float x) +{ + x = abs(x); + if (x <= 1.0f) { + return 1.5f * x * x * x - 2.5f * x * x + 1.0f; + } else if (x < 2.0f) { + return -0.5f * x * x * x + 2.5f * x * x - 4.0f * x + 2.0f; + } + return 0.0f; +} + +// Note: Lanczos is much slower due to sin() and pow() calls +float Lanczos(float x) +{ + float PI = 3.14f; + float a = 4.0f; + if (abs(x) < 1e-6) { + return 1.0f; + } + return a * sin(PI * x) * sin(PI * x / a) / (pow(PI, 2.0f) * pow(x, 2.0f)); +} + +// Bicubic interpolation - single line (4x4 kernel, much faster than Lanczos 8x8) +vec4 MixRgbBicubicLine(const in sampler2D inTexture, in ivec2 pos, in vec2 delta, in ivec2 margin, in ivec2 maxSize, + inout float sum_f, inout vec4 minimum, inout vec4 maximum) +{ + // Calculate pixel contribution weight using Bicubic + float fy = CubicWeight(delta.y); + + // check for y offset + if (pos.y < margin.y || pos.y >= maxSize.y) fy = 0.0f; + + // Only 4 samples per line instead of 8 (Lanczos) + float f_1 = CubicWeight(delta.x + 1.0f); + float f0 = CubicWeight(delta.x + 0.0f); + float f1 = CubicWeight(delta.x - 1.0f); + float f2 = CubicWeight(delta.x - 2.0f); + + // set pixel contribution weight to 0 for out-of-bound positions + if (pos.x - 1 < margin.x || pos.x - 1 >= maxSize.x) f_1 = 0.0f; + if (pos.x + 0 < margin.x || pos.x + 0 >= maxSize.x) f0 = 0.0f; + if (pos.x + 1 < margin.x || pos.x + 1 >= maxSize.x) f1 = 0.0f; + if (pos.x + 2 < margin.x || pos.x + 2 >= maxSize.x) f2 = 0.0f; + + sum_f += fy * (f_1 + f0 + f1 + f2); + + vec4 p_1 = texelFetch(inTexture, ivec2(pos.x - 1, pos.y), 0); + vec4 p0 = texelFetch(inTexture, ivec2(pos.x + 0, pos.y), 0); + vec4 p1 = texelFetch(inTexture, ivec2(pos.x + 1, pos.y), 0); + vec4 p2 = texelFetch(inTexture, ivec2(pos.x + 2, pos.y), 0); + + minimum = min(minimum, min(p0, p1)); + maximum = max(maximum, max(p0, p1)); + + return fy * (f_1 * p_1 + f0 * p0 + f1 * p1 + f2 * p2); +} + +// Lanczos 8x8 kernel +vec4 MixRgbLanczosLine(const in sampler2D inTexture, in ivec2 pos, in vec2 delta, in ivec2 margin, in ivec2 maxSize, + inout float sum_f, inout vec4 minimum, inout vec4 maximum) +{ + // Calculate pixel contribution weight + float fy = Lanczos(delta.y); + + // check for y offset + if (pos.y < margin.y || pos.y >= maxSize.y) fy = 0.0f; + + float f_3 = Lanczos(delta.x + 3.0f); + float f_2 = Lanczos(delta.x + 2.0f); + float f_1 = Lanczos(delta.x + 1.0f); + float f0 = Lanczos(delta.x + 0.0f); + float f1 = Lanczos(delta.x - 1.0f); + float f2 = Lanczos(delta.x - 2.0f); + float f3 = Lanczos(delta.x - 3.0f); + float f4 = Lanczos(delta.x - 4.0f); + + // set pixel contribution weight to 0 for out-of-bound positions + if (pos.x - 3 < margin.x || pos.x - 3 >= maxSize.x) f_3 = 0.0f; + if (pos.x - 2 < margin.x || pos.x - 2 >= maxSize.x) f_2 = 0.0f; + if (pos.x - 1 < margin.x || pos.x - 1 >= maxSize.x) f_1 = 0.0f; + if (pos.x + 0 < margin.x || pos.x + 0 >= maxSize.x) f0 = 0.0f; + if (pos.x + 1 < margin.x || pos.x + 1 >= maxSize.x) f1 = 0.0f; + if (pos.x + 2 < margin.x || pos.x + 2 >= maxSize.x) f2 = 0.0f; + if (pos.x + 3 < margin.x || pos.x + 3 >= maxSize.x) f3 = 0.0f; + if (pos.x + 4 < margin.x || pos.x + 4 >= maxSize.x) f4 = 0.0f; + + sum_f += fy * (f_3 + f_2 + f_1 + f0 + f1 + f2 + f3 + f4); + + vec4 p_3 = texelFetch(inTexture, ivec2(pos.x - 3, pos.y), 0); + vec4 p_2 = texelFetch(inTexture, ivec2(pos.x - 2, pos.y), 0); + vec4 p_1 = texelFetch(inTexture, ivec2(pos.x - 1, pos.y), 0); + vec4 p0 = texelFetch(inTexture, ivec2(pos.x + 0, pos.y), 0); + vec4 p1 = texelFetch(inTexture, ivec2(pos.x + 1, pos.y), 0); + vec4 p2 = texelFetch(inTexture, ivec2(pos.x + 2, pos.y), 0); + vec4 p3 = texelFetch(inTexture, ivec2(pos.x + 3, pos.y), 0); + vec4 p4 = texelFetch(inTexture, ivec2(pos.x + 4, pos.y), 0); + + minimum = min(minimum, min(p0, p1)); + maximum = max(maximum, max(p0, p1)); + + return fy * (f_3 * p_3 + f_2 * p_2 + f_1 * p_1 + f0 * p0 + f1 * p1 + f2 * p2 + f3 * p3 + f4 * p4); +} + +// Bicubic interpolation - 4x4 kernel (75% fewer samples than Lanczos) +vec4 InterpolateBicubicRgb(const in sampler2D inTexture, in ivec2 imgSize, in vec2 offset, in ivec2 pos, in float factor) +{ + ivec2 margin = ivec2(max(pos.x, 0), max(pos.y, 0)); + vec2 indexPos = vec2(pos) + offset; + + vec2 base = floor(indexPos); + vec2 delta = indexPos - base; + float sum_f = 0.0f; + vec4 maximum = vec4(0.0f); + vec4 minimum = vec4(1.0f); + vec4 unused = vec4(0.0f); + + // Only 4 lines instead of 8 (Lanczos uses 8 lines) + vec4 sum_p = MixRgbBicubicLine(inTexture, ivec2(base.x, base.y - 1.0f), vec2(delta.x, delta.y + 1.0f), margin, imgSize, sum_f, unused, unused) + + MixRgbBicubicLine(inTexture, ivec2(base.x, base.y + 0.0f), vec2(delta.x, delta.y + 0.0f), margin, imgSize, sum_f, minimum, maximum) + + MixRgbBicubicLine(inTexture, ivec2(base.x, base.y + 1.0f), vec2(delta.x, delta.y - 1.0f), margin, imgSize, sum_f, minimum, maximum) + + MixRgbBicubicLine(inTexture, ivec2(base.x, base.y + 2.0f), vec2(delta.x, delta.y - 2.0f), margin, imgSize, sum_f, unused, unused) + ; + + // be careful with precision of different chip devices + const float minFloatVal = 1e-6; + vec4 h = abs(sum_f) > minFloatVal ? sum_p / sum_f : vec4(0.0f); + h = clamp(h, minimum, maximum); + return h * factor; +} + +// Lanczos interpolation - 8x8 kernel +vec4 InterpolateLanczosRgb(const in sampler2D inTexture, in ivec2 imgSize, in vec2 offset, in ivec2 pos, in float factor) +{ + ivec2 margin = ivec2(max(pos.x, 0), max(pos.y, 0)); + vec2 indexPos = vec2(pos) + offset; + + vec2 base = floor(indexPos); + vec2 delta = indexPos - base; + float sum_f = 0.0f; + vec4 maximum = vec4(0.0f); + vec4 minimum = vec4(1.0f); + vec4 unused = vec4(0.0f); + + vec4 sum_p = MixRgbLanczosLine(inTexture, ivec2(base.x, base.y - 3.0f), vec2(delta.x, delta.y + 3.0f), margin, imgSize, sum_f, unused, unused) + + MixRgbLanczosLine(inTexture, ivec2(base.x, base.y - 2.0f), vec2(delta.x, delta.y + 2.0f), margin, imgSize, sum_f, unused, unused) + + MixRgbLanczosLine(inTexture, ivec2(base.x, base.y - 1.0f), vec2(delta.x, delta.y + 1.0f), margin, imgSize, sum_f, unused, unused) + + MixRgbLanczosLine(inTexture, ivec2(base.x, base.y + 0.0f), vec2(delta.x, delta.y + 0.0f), margin, imgSize, sum_f, minimum, maximum) + + MixRgbLanczosLine(inTexture, ivec2(base.x, base.y + 1.0f), vec2(delta.x, delta.y - 1.0f), margin, imgSize, sum_f, minimum, maximum) + + MixRgbLanczosLine(inTexture, ivec2(base.x, base.y + 2.0f), vec2(delta.x, delta.y - 2.0f), margin, imgSize, sum_f, unused, unused) + + MixRgbLanczosLine(inTexture, ivec2(base.x, base.y + 3.0f), vec2(delta.x, delta.y - 3.0f), margin, imgSize, sum_f, unused, unused) + + MixRgbLanczosLine(inTexture, ivec2(base.x, base.y + 4.0f), vec2(delta.x, delta.y - 4.0f), margin, imgSize, sum_f, unused, unused) + ; + + // be careful with precision of different chip devices + const float minFloatVal = 1e-6; + vec4 h = abs(sum_f) > minFloatVal ? sum_p / sum_f : vec4(0.0f); + h = clamp(h, minimum, maximum); + return h * factor; +} + +// Main RGB interpolation function - uses Bicubic by default for best performance +vec3 RgbLensInterpolationFastCubic(const in sampler2D inTexture, in vec2 wantedR, in vec2 wantedG, + in vec2 wantedB, in vec3 factor, in RGBLensParams params, bool greenOnly) +{ + vec3 rgb = vec3(0.0f); + ivec2 margin = ivec2(params.xMargin, params.yMargin); + ivec2 imgSize = ivec2(params.xMax, params.yMax); + if (greenOnly) { + // When no chromatic aberration, only interpolate green channel + rgb = InterpolateBicubicRgb(inTexture, imgSize, wantedG, -margin, factor.g).rgb; + } else { + // Separate interpolation for each channel (chromatic aberration correction) + rgb.r = InterpolateBicubicRgb(inTexture, imgSize, wantedR, -margin, factor.r).r; + rgb.g = InterpolateBicubicRgb(inTexture, imgSize, wantedG, -margin, factor.g).g; + rgb.b = InterpolateBicubicRgb(inTexture, imgSize, wantedB, -margin, factor.b).b; + } + return rgb; +} + +// Legacy Lanczos version (for comparison/fallback if needed) +vec3 RgbLensInterpolationLanczos(const in sampler2D inTexture, in vec2 wantedR, in vec2 wantedG, + in vec2 wantedB, in vec3 factor, in RGBLensParams params, bool greenOnly) +{ + vec3 rgb = vec3(0.0f); + ivec2 margin = ivec2(params.xMargin, params.yMargin); + ivec2 imgSize = ivec2(params.xMax, params.yMax); + if (greenOnly) { + rgb = InterpolateLanczosRgb(inTexture, imgSize, wantedG, -margin, factor.g).rgb; + } else { + rgb.r = InterpolateLanczosRgb(inTexture, imgSize, wantedR, -margin, factor.r).r; + rgb.g = InterpolateLanczosRgb(inTexture, imgSize, wantedG, -margin, factor.g).g; + rgb.b = InterpolateLanczosRgb(inTexture, imgSize, wantedB, -margin, factor.b).b; + } + return rgb; +} + +// texVign is the vignette lookup texture +void CalculateRGBFactor(in RGBLensParams params, in vec2 pos, const in sampler2D texVign, + inout vec2 wantedG, inout vec4 wantedRB, inout vec3 factor) +{ + vec2 lensPos = pos + vec2(params.xCenterOffset, params.yCenterOffset); + if (params.doDistortion == 1) { + wantedG = pos - ApplyParams(lensPos / params.imageScale, params.greenParam, params.greenOffset) * params.imageScale; + } + + if (params.doAberration == 1) { + wantedRB.xy = pos - ApplyParams(lensPos / params.imageScale, params.redParam, params.redOffset) * params.imageScale; + wantedRB.zw = pos - ApplyParams(lensPos / params.imageScale, params.blueParam, params.blueOffset) * params.imageScale; + } + + if (params.doVignetting == 1) { + float calcVal = CalculateVignFactor(texVign, wantedG + vec2(params.xCenterOffset, params.yCenterOffset), params); + factor = vec3(calcVal); + } + if (params.doVignetting == 1 && params.doAberration == 1) { + factor.r = CalculateVignFactor(texVign, wantedRB.xy + vec2(params.xCenterOffset, params.yCenterOffset), params); + factor.b = CalculateVignFactor(texVign, wantedRB.zw + vec2(params.xCenterOffset, params.yCenterOffset), params); + } +} + +vec4 HtsLookup(const in sampler2D textureMap, in vec2 pos, in ivec2 mapSize) +{ + // manually bi-linear sampling + // 检查进行插值时的边界与坐标平滑的值, 确保不会出错 + vec2 maxPos = vec2(mapSize - 1); + pos = clamp(pos, vec2(0.0f), maxPos); + + ivec2 basePos = ivec2(floor(pos)); + ivec2 basePos1 = clamp(basePos + 1, ivec2(0), ivec2(maxPos)); + vec2 delta = pos - vec2(basePos); + + vec4 p00 = texelFetch(textureMap, basePos, 0); + vec4 p10 = texelFetch(textureMap, ivec2(basePos1.x, basePos.y), 0); + vec4 p01 = texelFetch(textureMap, ivec2(basePos.x, basePos1.y), 0); + vec4 p11 = texelFetch(textureMap, basePos1, 0); + + vec4 h0 = mix(p00, p10, delta.x); + vec4 h1 = mix(p01, p11, delta.x); + return mix(h0, h1, delta.y); + + // using sampler2D - must set as linear sampling + // vec2 texCoord = (pos + 0.5) / vec2(mapSize); + // return texture(textureMap, texCoord); +} + +// texMapGV is the green distortion and vignetting texture, texMapRB is the aberration lookup texture +void CalculateRGBFactorHts(in RGBLensParams params, in vec2 pos, const in sampler2D texMapGV, const in sampler2D texMapRB, + inout vec2 wantedG, inout vec4 wantedRB, inout vec3 factor) +{ + ivec2 mapSize = ivec2(params.xMaxMap, params.yMaxMap); + if (params.doDistortion == 1) { + wantedG += HtsLookup(texMapGV, pos * params.imageScale, mapSize).xy * params.offsetScale; + } + wantedRB = vec4(wantedG, wantedG); + if (params.doAberration == 1) { + wantedRB += HtsLookup(texMapRB, pos * params.imageScale, mapSize) * params.offsetScale; + } + + if (params.doVignetting == 1) { + factor.g += HtsLookup(texMapGV, wantedG * params.imageScale, mapSize).z * params.vignAmount; + } + + if (params.doVignetting == 1 && params.doAberration == 1) { + factor.r += HtsLookup(texMapGV, wantedRB.xy * params.imageScale, mapSize).z * params.vignAmount; + factor.b += HtsLookup(texMapGV, wantedRB.zw * params.imageScale, mapSize).z * params.vignAmount; + } +} + +void main() { + RGBLensParams params = uParams.params; + // Match the pixel indices offset of 0.5 in OpenGL + vec2 outLocalPos = gl_FragCoord.xy - 0.5; + + // offset is calculated with actual pixel indices + ivec2 marginOffset = ivec2(int(params.xOffset) - params.xMargin, int(params.yOffset) - params.yMargin); + ivec2 srcPos = ivec2(outLocalPos) + marginOffset; + vec4 pixelColor = texelFetch(uInputTexture0, srcPos, 0); + + vec2 outGlobalPos = outLocalPos + vec2(float(params.xOffset), float(params.yOffset)); + + // col-based matrix + mat3 mat = mat3(params.matA, params.matB, params.matC); + vec2 pos = KeystoneTransform(mat, outGlobalPos); + float alpha = pixelColor.a; + + // check for out-of-bound coordinates + if (params.blackOutOfBounds == 1 && (any(lessThan(pos, vec2(0.0))) || any(greaterThan(pos, vec2(params.xKeystoneLimit, params.yKeystoneLimit))))) { + FragColor = vec4(vec3(0.0), alpha); + return; + } + + // init position values + vec2 wantedG = pos; + vec4 wantedRB = vec4(pos, pos); + vec3 factor = vec3(1.0f); + + if (params.doHts == 1) { + CalculateRGBFactorHts(params, pos, uHtsDistTexture, uHtsAberTexture, wantedG, wantedRB, factor); + } else { + CalculateRGBFactor(params, pos, uVignetteTableTexture, wantedG, wantedRB, factor); + } + + bool greenOnly = params.doAberration == 0; + vec3 rgb = vec3(0.0); + if (uEnableFastMode == 1) { + rgb = RgbLensInterpolationFastCubic(uInputTexture0, wantedRB.xy, wantedG, wantedRB.zw, factor, params, greenOnly); + } else { + rgb = RgbLensInterpolationLanczos(uInputTexture0, wantedRB.xy, wantedG, wantedRB.zw, factor, params, greenOnly); + } + FragColor = vec4(rgb, alpha); +} diff --git a/research/phocus_glsl/05_lens_geometry/rgbLensFilter_0x3057352.comp b/research/phocus_glsl/05_lens_geometry/rgbLensFilter_0x3057352.comp new file mode 100644 index 00000000..477293e4 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/rgbLensFilter_0x3057352.comp @@ -0,0 +1,347 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: a21099023c7ef59d903395303ee0c0bfdfe05463d171713e599ee2d21d390291 + * ELF offsets: 0x3057352 + * Symbols: rgbLensFilter_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp sampler2D; +precision highp image2D; + +// input textures (sampler2D — RGBA16F works on all GPUs) +layout(binding = 0) uniform sampler2D uInputTexture0; + +// vignette table (image2D — Mali-safe, imageLoad works with float formats) +layout(r32f, binding = 1) readonly uniform image2D uVignetteTable; +// output image +layout(rgba16f, binding = 2) writeonly uniform image2D uOutputImage; +// extra textures (sampler2D — HTS distortion/aberration maps) +layout(binding = 3) uniform sampler2D uHtsDistTexture; +layout(binding = 4) uniform sampler2D uHtsAberTexture; + +layout(local_size_x = 8, local_size_y = 8) in; + +struct RGBLensParams { + vec3 matA; + float redOffset; + vec3 matB; + float greenOffset; + vec3 matC; + float blueOffset; + + vec4 redParam; + vec4 greenParam; + vec4 blueParam; + float pixelSize; + float xOffset; + float yOffset; + float xCenterOffset; + float yCenterOffset; + int xMargin; + int yMargin; + int xMax; + int yMax; + int xKeystoneLimit; + int yKeystoneLimit; + float vignAmount; + float imageScale; + int vignTableDiv; + + float offsetScale; + int xMaxMap; + int yMaxMap; + + int doVignetting; + int doDistortion; + int doAberration; + int doHts; + int blackOutOfBounds; + vec2 padding; +}; + +layout(std140, binding = 0) uniform ShaderParams { + RGBLensParams params; +} uParams; + +uniform int uEnableFastMode; + +vec2 KeystoneTransform(in mat3 mat, in vec2 pos) +{ + vec3 posF = vec3(pos.x, pos.y, 1.0); + vec3 keystonePos = mat * posF; + return vec2(keystonePos.x / keystonePos.z, keystonePos.y / keystonePos.z); +} + +vec2 ApplyParams(in vec2 pos, in vec4 param, in float paramOffset) +{ + float radiusP2 = pos.x * pos.x + pos.y * pos.y; + float radius = sqrt(radiusP2); + vec4 coeffs = vec4(radius, radiusP2, radiusP2 * radius, radiusP2 * radiusP2); + vec4 cors = param * coeffs; + float cor = cors.x + cors.y + cors.z + cors.w + paramOffset; + return pos * cor; +} + +float CalculateVignFactor(in vec2 offPos, in RGBLensParams params) +{ + vec2 rad = offPos / params.imageScale * params.pixelSize; + float radius = sqrt(rad.x * rad.x + rad.y * rad.y) * float(params.vignTableDiv); + int radiusIndex = int(floor(radius)); + radiusIndex = clamp(radiusIndex, 0, 4500 - 1); + // imageLoad — Mali-safe for float textures (directly accesses global uVignetteTable) + float tv = imageLoad(uVignetteTable, ivec2(radiusIndex, 0)).r; + float factor = 1.0f + (tv - 1.0f) * params.vignAmount; + return factor; +} + +float CubicWeight(float x) +{ + x = abs(x); + if (x <= 1.0f) { return 1.5f * x * x * x - 2.5f * x * x + 1.0f; } + else if (x < 2.0f) { return -0.5f * x * x * x + 2.5f * x * x - 4.0f * x + 2.0f; } + return 0.0f; +} + +float Lanczos(float x) +{ + float PI = 3.14f; + float a = 4.0f; + if (abs(x) < 1e-6) { return 1.0f; } + return a * sin(PI * x) * sin(PI * x / a) / (pow(PI, 2.0f) * pow(x, 2.0f)); +} + +vec4 MixRgbBicubicLine(const in sampler2D inTexture, in ivec2 pos, in vec2 delta, in ivec2 margin, in ivec2 maxSize, + inout float sum_f, inout vec4 minimum, inout vec4 maximum) +{ + float fy = CubicWeight(delta.y); + if (pos.y < margin.y || pos.y >= maxSize.y) fy = 0.0f; + float f_1 = CubicWeight(delta.x + 1.0f); + float f0 = CubicWeight(delta.x + 0.0f); + float f1 = CubicWeight(delta.x - 1.0f); + float f2 = CubicWeight(delta.x - 2.0f); + if (pos.x - 1 < margin.x || pos.x - 1 >= maxSize.x) f_1 = 0.0f; + if (pos.x + 0 < margin.x || pos.x + 0 >= maxSize.x) f0 = 0.0f; + if (pos.x + 1 < margin.x || pos.x + 1 >= maxSize.x) f1 = 0.0f; + if (pos.x + 2 < margin.x || pos.x + 2 >= maxSize.x) f2 = 0.0f; + sum_f += fy * (f_1 + f0 + f1 + f2); + vec4 p_1 = texelFetch(inTexture, ivec2(pos.x - 1, pos.y), 0); + vec4 p0 = texelFetch(inTexture, ivec2(pos.x + 0, pos.y), 0); + vec4 p1 = texelFetch(inTexture, ivec2(pos.x + 1, pos.y), 0); + vec4 p2 = texelFetch(inTexture, ivec2(pos.x + 2, pos.y), 0); + minimum = min(minimum, min(p0, p1)); + maximum = max(maximum, max(p0, p1)); + return fy * (f_1 * p_1 + f0 * p0 + f1 * p1 + f2 * p2); +} + +vec4 MixRgbLanczosLine(const in sampler2D inTexture, in ivec2 pos, in vec2 delta, in ivec2 margin, in ivec2 maxSize, + inout float sum_f, inout vec4 minimum, inout vec4 maximum) +{ + float fy = Lanczos(delta.y); + if (pos.y < margin.y || pos.y >= maxSize.y) fy = 0.0f; + float f_3 = Lanczos(delta.x + 3.0f); + float f_2 = Lanczos(delta.x + 2.0f); + float f_1 = Lanczos(delta.x + 1.0f); + float f0 = Lanczos(delta.x + 0.0f); + float f1 = Lanczos(delta.x - 1.0f); + float f2 = Lanczos(delta.x - 2.0f); + float f3 = Lanczos(delta.x - 3.0f); + float f4 = Lanczos(delta.x - 4.0f); + if (pos.x - 3 < margin.x || pos.x - 3 >= maxSize.x) f_3 = 0.0f; + if (pos.x - 2 < margin.x || pos.x - 2 >= maxSize.x) f_2 = 0.0f; + if (pos.x - 1 < margin.x || pos.x - 1 >= maxSize.x) f_1 = 0.0f; + if (pos.x + 0 < margin.x || pos.x + 0 >= maxSize.x) f0 = 0.0f; + if (pos.x + 1 < margin.x || pos.x + 1 >= maxSize.x) f1 = 0.0f; + if (pos.x + 2 < margin.x || pos.x + 2 >= maxSize.x) f2 = 0.0f; + if (pos.x + 3 < margin.x || pos.x + 3 >= maxSize.x) f3 = 0.0f; + if (pos.x + 4 < margin.x || pos.x + 4 >= maxSize.x) f4 = 0.0f; + sum_f += fy * (f_3 + f_2 + f_1 + f0 + f1 + f2 + f3 + f4); + vec4 p_3 = texelFetch(inTexture, ivec2(pos.x - 3, pos.y), 0); + vec4 p_2 = texelFetch(inTexture, ivec2(pos.x - 2, pos.y), 0); + vec4 p_1 = texelFetch(inTexture, ivec2(pos.x - 1, pos.y), 0); + vec4 p0 = texelFetch(inTexture, ivec2(pos.x + 0, pos.y), 0); + vec4 p1 = texelFetch(inTexture, ivec2(pos.x + 1, pos.y), 0); + vec4 p2 = texelFetch(inTexture, ivec2(pos.x + 2, pos.y), 0); + vec4 p3 = texelFetch(inTexture, ivec2(pos.x + 3, pos.y), 0); + vec4 p4 = texelFetch(inTexture, ivec2(pos.x + 4, pos.y), 0); + minimum = min(minimum, min(p0, p1)); + maximum = max(maximum, max(p0, p1)); + return fy * (f_3 * p_3 + f_2 * p_2 + f_1 * p_1 + f0 * p0 + f1 * p1 + f2 * p2 + f3 * p3 + f4 * p4); +} + +vec4 InterpolateBicubicRgb(const in sampler2D inTexture, in ivec2 imgSize, in vec2 offset, in ivec2 pos, in float factor) +{ + ivec2 margin = ivec2(max(pos.x, 0), max(pos.y, 0)); + vec2 indexPos = vec2(pos) + offset; + vec2 base = floor(indexPos); + vec2 delta = indexPos - base; + float sum_f = 0.0f; + vec4 maximum = vec4(0.0f); + vec4 minimum = vec4(1.0f); + vec4 unused = vec4(0.0f); + vec4 sum_p = MixRgbBicubicLine(inTexture, ivec2(base.x, base.y - 1.0f), vec2(delta.x, delta.y + 1.0f), margin, imgSize, sum_f, unused, unused) + + MixRgbBicubicLine(inTexture, ivec2(base.x, base.y + 0.0f), vec2(delta.x, delta.y + 0.0f), margin, imgSize, sum_f, minimum, maximum) + + MixRgbBicubicLine(inTexture, ivec2(base.x, base.y + 1.0f), vec2(delta.x, delta.y - 1.0f), margin, imgSize, sum_f, minimum, maximum) + + MixRgbBicubicLine(inTexture, ivec2(base.x, base.y + 2.0f), vec2(delta.x, delta.y - 2.0f), margin, imgSize, sum_f, unused, unused); + const float minFloatVal = 1e-6; + vec4 h = abs(sum_f) > minFloatVal ? sum_p / sum_f : vec4(0.0f); + h = clamp(h, minimum, maximum); + return h * factor; +} + +vec4 InterpolateLanczosRgb(const in sampler2D inTexture, in ivec2 imgSize, in vec2 offset, in ivec2 pos, in float factor) +{ + ivec2 margin = ivec2(max(pos.x, 0), max(pos.y, 0)); + vec2 indexPos = vec2(pos) + offset; + vec2 base = floor(indexPos); + vec2 delta = indexPos - base; + float sum_f = 0.0f; + vec4 maximum = vec4(0.0f); + vec4 minimum = vec4(1.0f); + vec4 unused = vec4(0.0f); + vec4 sum_p = MixRgbLanczosLine(inTexture, ivec2(base.x, base.y - 3.0f), vec2(delta.x, delta.y + 3.0f), margin, imgSize, sum_f, unused, unused) + + MixRgbLanczosLine(inTexture, ivec2(base.x, base.y - 2.0f), vec2(delta.x, delta.y + 2.0f), margin, imgSize, sum_f, unused, unused) + + MixRgbLanczosLine(inTexture, ivec2(base.x, base.y - 1.0f), vec2(delta.x, delta.y + 1.0f), margin, imgSize, sum_f, unused, unused) + + MixRgbLanczosLine(inTexture, ivec2(base.x, base.y + 0.0f), vec2(delta.x, delta.y + 0.0f), margin, imgSize, sum_f, minimum, maximum) + + MixRgbLanczosLine(inTexture, ivec2(base.x, base.y + 1.0f), vec2(delta.x, delta.y - 1.0f), margin, imgSize, sum_f, minimum, maximum) + + MixRgbLanczosLine(inTexture, ivec2(base.x, base.y + 2.0f), vec2(delta.x, delta.y - 2.0f), margin, imgSize, sum_f, unused, unused) + + MixRgbLanczosLine(inTexture, ivec2(base.x, base.y + 3.0f), vec2(delta.x, delta.y - 3.0f), margin, imgSize, sum_f, unused, unused) + + MixRgbLanczosLine(inTexture, ivec2(base.x, base.y + 4.0f), vec2(delta.x, delta.y - 4.0f), margin, imgSize, sum_f, unused, unused); + const float minFloatVal = 1e-6; + vec4 h = abs(sum_f) > minFloatVal ? sum_p / sum_f : vec4(0.0f); + h = clamp(h, minimum, maximum); + return h * factor; +} + +vec3 RgbLensInterpolationFastCubic(const in sampler2D inTexture, in vec2 wantedR, in vec2 wantedG, + in vec2 wantedB, in vec3 factor, in RGBLensParams params, bool greenOnly) +{ + vec3 rgb = vec3(0.0f); + ivec2 margin = ivec2(params.xMargin, params.yMargin); + ivec2 imgSize = ivec2(params.xMax, params.yMax); + if (greenOnly) { + rgb = InterpolateBicubicRgb(inTexture, imgSize, wantedG, -margin, factor.g).rgb; + } else { + rgb.r = InterpolateBicubicRgb(inTexture, imgSize, wantedR, -margin, factor.r).r; + rgb.g = InterpolateBicubicRgb(inTexture, imgSize, wantedG, -margin, factor.g).g; + rgb.b = InterpolateBicubicRgb(inTexture, imgSize, wantedB, -margin, factor.b).b; + } + return rgb; +} + +vec3 RgbLensInterpolationLanczos(const in sampler2D inTexture, in vec2 wantedR, in vec2 wantedG, + in vec2 wantedB, in vec3 factor, in RGBLensParams params, bool greenOnly) +{ + vec3 rgb = vec3(0.0f); + ivec2 margin = ivec2(params.xMargin, params.yMargin); + ivec2 imgSize = ivec2(params.xMax, params.yMax); + if (greenOnly) { + rgb = InterpolateLanczosRgb(inTexture, imgSize, wantedG, -margin, factor.g).rgb; + } else { + rgb.r = InterpolateLanczosRgb(inTexture, imgSize, wantedR, -margin, factor.r).r; + rgb.g = InterpolateLanczosRgb(inTexture, imgSize, wantedG, -margin, factor.g).g; + rgb.b = InterpolateLanczosRgb(inTexture, imgSize, wantedB, -margin, factor.b).b; + } + return rgb; +} + +void CalculateRGBFactor(in RGBLensParams params, in vec2 pos, + inout vec2 wantedG, inout vec4 wantedRB, inout vec3 factor) +{ + vec2 lensPos = pos + vec2(params.xCenterOffset, params.yCenterOffset); + if (params.doDistortion == 1) { + wantedG = pos - ApplyParams(lensPos / params.imageScale, params.greenParam, params.greenOffset) * params.imageScale; + } + if (params.doAberration == 1) { + wantedRB.xy = pos - ApplyParams(lensPos / params.imageScale, params.redParam, params.redOffset) * params.imageScale; + wantedRB.zw = pos - ApplyParams(lensPos / params.imageScale, params.blueParam, params.blueOffset) * params.imageScale; + } + if (params.doVignetting == 1) { + float calcVal = CalculateVignFactor(wantedG + vec2(params.xCenterOffset, params.yCenterOffset), params); + factor = vec3(calcVal); + } + if (params.doVignetting == 1 && params.doAberration == 1) { + factor.r = CalculateVignFactor(wantedRB.xy + vec2(params.xCenterOffset, params.yCenterOffset), params); + factor.b = CalculateVignFactor(wantedRB.zw + vec2(params.xCenterOffset, params.yCenterOffset), params); + } +} + +vec4 HtsLookup(const in sampler2D textureMap, in vec2 pos, in ivec2 mapSize) +{ + vec2 maxPos = vec2(mapSize - 1); + pos = clamp(pos, vec2(0.0f), maxPos); + ivec2 basePos = ivec2(floor(pos)); + ivec2 basePos1 = clamp(basePos + 1, ivec2(0), ivec2(maxPos)); + vec2 delta = pos - vec2(basePos); + vec4 p00 = texelFetch(textureMap, basePos, 0); + vec4 p10 = texelFetch(textureMap, ivec2(basePos1.x, basePos.y), 0); + vec4 p01 = texelFetch(textureMap, ivec2(basePos.x, basePos1.y), 0); + vec4 p11 = texelFetch(textureMap, basePos1, 0); + vec4 h0 = mix(p00, p10, delta.x); + vec4 h1 = mix(p01, p11, delta.x); + return mix(h0, h1, delta.y); +} + +void CalculateRGBFactorHts(in RGBLensParams params, in vec2 pos, const in sampler2D texMapGV, const in sampler2D texMapRB, + inout vec2 wantedG, inout vec4 wantedRB, inout vec3 factor) +{ + ivec2 mapSize = ivec2(params.xMaxMap, params.yMaxMap); + if (params.doDistortion == 1) { + wantedG += HtsLookup(texMapGV, pos * params.imageScale, mapSize).xy * params.offsetScale; + } + wantedRB = vec4(wantedG, wantedG); + if (params.doAberration == 1) { + wantedRB += HtsLookup(texMapRB, pos * params.imageScale, mapSize) * params.offsetScale; + } + if (params.doVignetting == 1) { + factor.g += HtsLookup(texMapGV, wantedG * params.imageScale, mapSize).z * params.vignAmount; + } + if (params.doVignetting == 1 && params.doAberration == 1) { + factor.r += HtsLookup(texMapGV, wantedRB.xy * params.imageScale, mapSize).z * params.vignAmount; + factor.b += HtsLookup(texMapGV, wantedRB.zw * params.imageScale, mapSize).z * params.vignAmount; + } +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 outSize = imageSize(uOutputImage); + if (gid.x >= outSize.x || gid.y >= outSize.y) return; + + vec2 outLocalPos = vec2(gid); + + RGBLensParams params = uParams.params; + ivec2 marginOffset = ivec2(int(params.xOffset) - params.xMargin, int(params.yOffset) - params.yMargin); + ivec2 srcPos = ivec2(outLocalPos) + marginOffset; + vec4 pixelColor = texelFetch(uInputTexture0, srcPos, 0); + + vec2 outGlobalPos = outLocalPos + vec2(float(params.xOffset), float(params.yOffset)); + + mat3 mat = mat3(params.matA, params.matB, params.matC); + vec2 pos = KeystoneTransform(mat, outGlobalPos); + float alpha = pixelColor.a; + + if (params.blackOutOfBounds == 1 && (any(lessThan(pos, vec2(0.0))) || any(greaterThan(pos, vec2(params.xKeystoneLimit, params.yKeystoneLimit))))) { + imageStore(uOutputImage, gid, vec4(vec3(0.0), alpha)); + return; + } + + vec2 wantedG = pos; + vec4 wantedRB = vec4(pos, pos); + vec3 factor = vec3(1.0f); + + if (params.doHts == 1) { + CalculateRGBFactorHts(params, pos, uHtsDistTexture, uHtsAberTexture, wantedG, wantedRB, factor); + } else { + CalculateRGBFactor(params, pos, wantedG, wantedRB, factor); + } + + bool greenOnly = params.doAberration == 0; + vec3 rgb = vec3(0.0); + if (uEnableFastMode == 1) { + rgb = RgbLensInterpolationFastCubic(uInputTexture0, wantedRB.xy, wantedG, wantedRB.zw, factor, params, greenOnly); + } else { + rgb = RgbLensInterpolationLanczos(uInputTexture0, wantedRB.xy, wantedG, wantedRB.zw, factor, params, greenOnly); + } + imageStore(uOutputImage, gid, vec4(rgb, alpha)); +} diff --git a/research/phocus_glsl/05_lens_geometry/standardAberrationCS_0x300fbb3.comp b/research/phocus_glsl/05_lens_geometry/standardAberrationCS_0x300fbb3.comp new file mode 100644 index 00000000..f64182ce --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/standardAberrationCS_0x300fbb3.comp @@ -0,0 +1,181 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: c17ca8323bf2ae866a700a7e8c03b26006646dc582b747033507adcf8e4295bb + * ELF offsets: 0x300fbb3 + * Symbols: standardAberrationCS_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; + +layout(rgba16f, binding = 0) readonly uniform image2D uInputImage; +layout(rgba16f, binding = 1) writeonly uniform image2D uOutputImage; + +layout(std140, binding = 0) uniform AberrationParams { + vec4 redParam; + vec4 blueParam; + float redOffset; + float blueOffset; + vec2 offsetFromCenter; + ivec2 marginToSrcRect; + ivec2 fullImageSize; +} uParams; + +uniform int uDebugMode; + +layout(local_size_x = 16, local_size_y = 16) in; + + +// Cubic interpolation function (Catmull-Rom spline) +vec4 cubic(vec4 v_1, vec4 v0, vec4 v1, vec4 v2, float delta) { + vec4 a = v2 * (1.0/6.0) - v1 * 0.5 + v0 * 0.5 - v_1 * (1.0/6.0); + vec4 b = v_1 * 0.5 + v1 * 0.5 - v0; + vec4 c = -v2 * (1.0/6.0) + v1 - v0 * 0.5 - v_1 * (1.0/3.0); + vec4 d = v0; + + return a * (delta * delta * delta) + b * (delta * delta) + c * delta + d; +} + +vec2 cubic2(vec2 v_1, vec2 v0, vec2 v1, vec2 v2, float delta) { + vec2 a = v2 * (1.0/6.0) - v1 * 0.5 + v0 * 0.5 - v_1 * (1.0/6.0); + vec2 b = v_1 * 0.5 + v1 * 0.5 - v0; + vec2 c = -v2 * (1.0/6.0) + v1 - v0 * 0.5 - v_1 * (1.0/3.0); + vec2 d = v0; + + return a * (delta * delta * delta) + b * (delta * delta) + c * delta + d; +} + +// Keystone transform (homogeneous 3x3 matrix) +vec2 keystoneTransform(vec3 matA, vec3 matB, vec3 matC, vec2 pos) { + vec3 posH = vec3(pos.x, pos.y, 1.0); + vec3 transformed; + transformed.x = dot(matA, posH); + transformed.y = dot(matB, posH); + transformed.z = dot(matC, posH); + return vec2(transformed.x / transformed.z, transformed.y / transformed.z); +} + +// Select red or blue channel from packed bayer (match Metal: .xz/.yw = 1st+3rd / 2nd+4th = .rb/.ga) +vec2 selectRedBlue(vec4 packed, bool isRed) { + return isRed ? packed.rb : packed.ga; +} + +// Mix cubic line for packed bayer format +vec2 mixCubicLine(ivec2 pos, float delta, bool isRed, inout vec2 minimum, inout vec2 maximum) { + // cubic2 algorithm is in data format ushort + vec2 l = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x - 1, pos.y)), isRed) * vec2(65535.0); + vec2 m = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x + 0, pos.y)), isRed) * vec2(65535.0); + vec2 r = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x + 1, pos.y)), isRed) * vec2(65535.0); + vec2 r2 = selectRedBlue(imageLoad(uInputImage, ivec2(pos.x + 2, pos.y)), isRed) * vec2(65535.0); + + if (delta < 1.0) { + vec2 p0 = m.xy; + vec2 p1 = vec2(m.y, r.x); + minimum = min(minimum, min(p0, p1)); + maximum = max(maximum, max(p0, p1)); + return cubic2(vec2(l.y, m.x), p0, p1, r.xy, delta); + } else { + vec2 p0 = vec2(m.y, r.x); + vec2 p1 = r.xy; + minimum = min(minimum, min(p0, p1)); + maximum = max(maximum, max(p0, p1)); + return cubic2(m.xy, p0, p1, vec2(r.y, r2.x), delta - 1.0); + } +} + +// Interpolate cubic packed bayer +vec4 interpolateCubicPacked(vec2 offset, ivec2 pos, bool isRed) { + ivec2 inputSize = imageSize(uInputImage); + vec2 indexPos = vec2(pos) + vec2(offset.x / 4.0, offset.y); + vec2 maxPos = vec2(inputSize.x - 3, inputSize.y - 5); + vec2 resPos = clamp(indexPos, vec2(1.0, 2.0), maxPos); + + int blueOffset = isRed ? 0 : 1; + ivec2 base = ivec2(resPos.x, int((resPos.y - float(blueOffset)) / 2.0) * 2 + blueOffset); + + vec2 delta = resPos - vec2(base); + vec2 maximum = vec2(0.0); + vec2 minimum = vec2(65535.0); + vec2 unused = vec2(0.0); + vec2 v_1 = mixCubicLine(ivec2(base.x, base.y - 2), delta.x * 2.0, isRed, unused, unused); + vec2 v0 = mixCubicLine(ivec2(base.x, base.y + 0), delta.x * 2.0, isRed, minimum, maximum); + vec2 v1 = mixCubicLine(ivec2(base.x, base.y + 2), delta.x * 2.0, isRed, minimum, maximum); + vec2 v2 = mixCubicLine(ivec2(base.x, base.y + 4), delta.x * 2.0, isRed, unused, unused); + + vec2 h = cubic2(v_1, v0.xy, v1.xy, v2, delta.y / 2.0); + h = clamp(round(h), minimum, maximum) / vec2(65535.0); + + vec4 inVal = imageLoad(uInputImage, pos); + if (isRed) { + // Red line: replace R only (1st and 3rd), keep G (2nd and 4th) - match Metal + return vec4(h.x, inVal.y, h.y, inVal.w); + } else { + // Blue line: replace B only (2nd and 4th), keep G (1st and 3rd) - match Metal + return vec4(inVal.x, h.x, inVal.z, h.y); + } + +} + + + +// Apply radial polynomial to calculate offset +vec2 applyParams(vec2 pos, vec4 params, float paramOffset) { + float radiusP2 = pos.x * pos.x + pos.y * pos.y; + float radius = sqrt(radiusP2); + + vec4 coeffs = vec4(radius, radiusP2, radiusP2 * radius, radiusP2 * radiusP2); + vec4 corrections = params * coeffs; + float corrSum = corrections.x + corrections.y + corrections.z + corrections.w + paramOffset; + return pos * corrSum; +} + +// Calculate standard aberration offsets for red and blue channels +vec4 getStandardAberrationOffsets(vec2 pos) { + vec2 rad = pos + uParams.offsetFromCenter + vec2(0.5); + vec2 redOff = applyParams(rad, uParams.redParam, uParams.redOffset); + vec2 blueOff = applyParams(rad, uParams.blueParam, uParams.blueOffset); + return -vec4(redOff, blueOff); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 outputSize = imageSize(uOutputImage); + + // Boundary check + if (gid.x >= outputSize.x || gid.y >= (outputSize.y + 1) / 2) { + return; + } + + vec2 realPos = vec2(gid.x * 4, gid.y * 2); + vec4 offsets = getStandardAberrationOffsets(realPos); + + ivec2 inOffset = ivec2(uParams.marginToSrcRect.x / 4, uParams.marginToSrcRect.y); + ivec2 posRed = ivec2(gid.x, gid.y * 2 + 0); + ivec2 posBlue = ivec2(gid.x, gid.y * 2 + 1); + + // Debug: 0 = normal + // 1 = pass-through + // 2 = green overlay (after BayerFastInterpolation, bright green = where correction was applied) + if (uDebugMode == 1) { + imageStore(uOutputImage, posRed, imageLoad(uInputImage, posRed + inOffset)); + imageStore(uOutputImage, posBlue, imageLoad(uInputImage, posBlue + inOffset)); + } else if (uDebugMode == 2) { + vec4 inRed = imageLoad(uInputImage, posRed + inOffset); + vec4 inBlue = imageLoad(uInputImage, posBlue + inOffset); + vec4 resultRed = interpolateCubicPacked(offsets.xy, posRed + inOffset, true); + vec4 resultBlue = interpolateCubicPacked(offsets.zw, posBlue + inOffset, false); + float diffR = length(resultRed - inRed); + float diffB = length(resultBlue - inBlue); + float v = clamp(max(diffR, diffB) * 20.0, 0.0, 1.0); + // PackedBayer: red row = R G R G, blue row = G B G B. Write green only so demosaic shows bright green where corrected. + imageStore(uOutputImage, posRed, vec4(0.0, v, 0.0, v)); + imageStore(uOutputImage, posBlue, vec4(v, 0.0, v, 0.0)); + } else { + // Normal processing (debugMode 0 or any other) + vec4 resultRed = interpolateCubicPacked(offsets.xy, posRed + inOffset, true); + vec4 resultBlue = interpolateCubicPacked(offsets.zw, posBlue + inOffset, false); + imageStore(uOutputImage, posRed, resultRed); + imageStore(uOutputImage, posBlue, resultBlue); + } +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x2ffac4a_0x2ffac4a.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x2ffac4a_0x2ffac4a.frag new file mode 100644 index 00000000..f19797f6 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x2ffac4a_0x2ffac4a.frag @@ -0,0 +1,25 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: cf8cb93c8b2a90f34a0a41f45509b621135134b1785a57f49437fb5e1813b76b + * ELF offsets: 0x2ffac4a + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; + +void main() { + ivec2 sz = textureSize(uInputTexture0, 0); + ivec2 p = ivec2(gl_FragCoord.xy); + const float STEP = 1.0 / 255.0; + float res = 1.0; + for (int off = -8; off <= 8; off++) { + ivec2 sp = clamp(p + ivec2(0, off), ivec2(0), sz-1); + res = min(res, abs(float(off)) * STEP + texelFetch(uInputTexture0, sp, 0).r); + } + float yDist = (res < 1.0) ? 0.0 : 1.0; + FragColor = vec4(res, yDist, 1.0, 1.0); +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x2ffae7d_0x2ffae7d.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x2ffae7d_0x2ffae7d.frag new file mode 100644 index 00000000..53e685cc --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x2ffae7d_0x2ffae7d.frag @@ -0,0 +1,51 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: e9f99a8ec73e205e70886530d9f6f60bedd45a4817119e988b77824e84df52db + * ELF offsets: 0x2ffae7d + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; + +float hueOf(vec4 v) { + float mx = max(v.r, max(v.g, v.b)); + float mn = min(v.r, min(v.g, v.b)); + if (mx <= 0.0 || (mx-mn)/mx <= 0.05) return -1.0; + float c60 = 60.0/(mx-mn); + if (mx == v.r) return (v.g >= v.b) ? c60*(v.g-v.b) : c60*(v.g-v.b)+360.0; + if (mx == v.g) return c60*(v.b-v.r)+120.0; + return c60*(v.r-v.g)+240.0; +} +float diffFn(float a, float b) { + if (a < 0.0 || b < 0.0) return -1.0; // grey pixel → -1 (CPU behaviour) + float d = min(abs(a-b), 360.0-abs(a-b)); + return (d > 3.0) ? 1.0 : -1.0; // 3° threshold (CPU) +} +void main() { + ivec2 sz = textureSize(uInputTexture0, 0); + ivec2 p = ivec2(gl_FragCoord.xy); + // S = 1, fixed (CPU uses step 1) + float lt = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2(-1,-1), ivec2(0), sz-1), 0)); + float mt = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2( 0,-1), ivec2(0), sz-1), 0)); + float rt = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2( 1,-1), ivec2(0), sz-1), 0)); + float lm = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2(-1, 0), ivec2(0), sz-1), 0)); + float rm = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2( 1, 0), ivec2(0), sz-1), 0)); + float lb = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2(-1, 1), ivec2(0), sz-1), 0)); + float mb = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2( 0, 1), ivec2(0), sz-1), 0)); + float rb = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2( 1, 1), ivec2(0), sz-1), 0)); + // Sobel Gradient — matches CPU DetectEdges() formula exactly: + // qx = hueDist(rt,lt) + 2*hueDist(mb,mt) + hueDist(rb,rt) + // qy = hueDist(rt,lt) + 2*hueDist(rm,lm) + hueDist(rb,lb) + // mx = hueDist(lm,mt) + 2*hueDist(lb,rt) + hueDist(mb,rm) + // my = hueDist(lm,mb) + 2*hueDist(lt,rb) + hueDist(mt,rm) + float mag = diffFn(rt,lt)+diffFn(rb,lb)+2.0*diffFn(rm,lm) + + diffFn(rt,lt)+diffFn(rb,rt)+2.0*diffFn(mt,mb) + + diffFn(lm,mt)+diffFn(mb,rm)+2.0*diffFn(lb,rt) + + diffFn(lm,mb)+diffFn(mt,rm)+2.0*diffFn(lt,rb); + float res = (mag > 0.0) ? 0.0 : 1.0; + FragColor = vec4(res, res, res, 1.0); +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x3003732_0x3003732.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x3003732_0x3003732.frag new file mode 100644 index 00000000..48164997 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x3003732_0x3003732.frag @@ -0,0 +1,28 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: e42cf5f03a11d8eac27fcc414f6c9d09ee9fd18432530f1d574e0269b8e3139a + * ELF offsets: 0x3003732 + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; // half-res fringe mask (R channel) + +void main() { + ivec2 p = ivec2(gl_FragCoord.xy); // full-res output coord + ivec2 inSz = textureSize(uInputTexture0, 0); + // Upscale2xMask: x1=x/2, x2=min(x1+1,W-1), y1=y/2, y2=min(y1+1,H-1), out=max of 4 + int x1 = min(p.x / 2, inSz.x - 1); + int x2 = min(x1 + 1, inSz.x - 1); + int y1 = min(p.y / 2, inSz.y - 1); + int y2 = min(y1 + 1, inSz.y - 1); + float m00 = texelFetch(uInputTexture0, ivec2(x1, y1), 0).r; + float m10 = texelFetch(uInputTexture0, ivec2(x2, y1), 0).r; + float m01 = texelFetch(uInputTexture0, ivec2(x1, y2), 0).r; + float m11 = texelFetch(uInputTexture0, ivec2(x2, y2), 0).r; + float m = max(max(m00, m10), max(m01, m11)); + FragColor = vec4(m, 0.0, 0.0, 1.0); +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x300c4fc_0x300c4fc.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x300c4fc_0x300c4fc.frag new file mode 100644 index 00000000..c9e4ffe2 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x300c4fc_0x300c4fc.frag @@ -0,0 +1,30 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 68a09bfc4c6bdfd4c327b840a8fe3d2810a7e7b3bb1ccabd50f31c7bdb1461ad + * ELF offsets: 0x300c4fc + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; +uniform int uSrcOffsetX; +uniform int uSrcOffsetY; + +vec4 conductionFn(vec4 g) { + vec4 kg = g * 1310.7; kg = kg*kg; kg = kg*kg; + return g / (kg + 1.0); +} +void main() { + ivec2 sz = textureSize(uInputTexture0, 0); + ivec2 p = ivec2(gl_FragCoord.xy) + ivec2(uSrcOffsetX, uSrcOffsetY); + vec4 c = texelFetch(uInputTexture0, clamp(p, ivec2(0), sz-1), 0); + vec4 cN = texelFetch(uInputTexture0, clamp(p+ivec2( 0,-1), ivec2(0), sz-1), 0); + vec4 cS = texelFetch(uInputTexture0, clamp(p+ivec2( 0, 1), ivec2(0), sz-1), 0); + vec4 cW = texelFetch(uInputTexture0, clamp(p+ivec2(-1, 0), ivec2(0), sz-1), 0); + vec4 cE = texelFetch(uInputTexture0, clamp(p+ivec2( 1, 0), ivec2(0), sz-1), 0); + vec4 s = (conductionFn(cN-c)+conductionFn(cS-c)+conductionFn(cW-c)+conductionFn(cE-c))/4.0; + FragColor = clamp(c + s, 0.0, 1.0); +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x30218ea_0x30218ea.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x30218ea_0x30218ea.frag new file mode 100644 index 00000000..aef057b3 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x30218ea_0x30218ea.frag @@ -0,0 +1,73 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 45417504420c2e766d3dc2ace48fc785e9aa1f665d9aa42a7968dd9d0117a8b6 + * ELF offsets: 0x30218ea + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; // texProcess (RGBX) +uniform sampler2D uInputTexture1; // texDist (RgbaF) +uniform float uPurpleStart; +uniform float uPurpleStop; +uniform float uGreenStart; +uniform float uGreenStop; +uniform float uPurpleAmount; +uniform float uGreenAmount; +uniform float uZoom; + +float hueOf(vec4 v) { + float mx = max(v.r, max(v.g, v.b)); + float mn = min(v.r, min(v.g, v.b)); + if (mx <= 0.0 || (mx-mn)/mx <= 0.05) return -1.0; + float c60 = 60.0/(mx-mn); + if (mx == v.r) return (v.g >= v.b) ? c60*(v.g-v.b) : c60*(v.g-v.b)+360.0; + if (mx == v.g) return c60*(v.b-v.r)+120.0; + return c60*(v.r-v.g)+240.0; +} +bool hueInRange(float h, float hStart, float hStop) { + if (h < 0.0) return false; + float hAdj = h; + if (hAdj < hStart) hAdj += 360.0; + return (hStart < hAdj && hAdj <= hStop); +} +// Gradient mask with ±0.5 amount transition band (mirrors GenerateFringeMask). +// dist = sqrt(R²+G²) where R=|dx|/255, G=|dy|/255, so dist_pixels = dist*255. +// uZoom = 1/previewScale; uZoom/255 scales amount → normalised dist units. +float computeGrad(float dist, float amount) { + float scale = (1.0 + sqrt(2.0)) * 0.1 * uZoom / 255.0; + float amt0 = clamp(amount - 0.5, 0.0, 90.0) * scale; + float amt1 = clamp(amount + 0.5, 0.0, 90.0) * scale; + if (dist < amt0) return 1.0; + if (amt1 > amt0 && dist <= amt1) return (amt1 - dist) / (amt1 - amt0); + return 0.0; +} +void main() { + ivec2 sz = textureSize(uInputTexture0, 0); + ivec2 p = ivec2(gl_FragCoord.xy); + vec4 src = texelFetch(uInputTexture0, clamp(p, ivec2(0), sz-1), 0); + + // 3×3 MAX filter on JFA distance field to suppress staircase artefacts. + // Isolated pixels with artificially small JFA distance are corrected to the + // correct larger value from their neighbours; normal fringe-zone pixels are unaffected. + float dist = 0.0; + for (int dy = -1; dy <= 1; dy++) { + for (int dx = -1; dx <= 1; dx++) { + vec2 d = texelFetch(uInputTexture1, clamp(p + ivec2(dx, dy), ivec2(0), sz-1), 0).rg; + dist = max(dist, sqrt(d.x*d.x + d.y*d.y)); + } + } + + float h = hueOf(src); + float purpleGrad = 0.0, greenGrad = 0.0; + if (uPurpleAmount > 0.0 && hueInRange(h, uPurpleStart, uPurpleStop)) + purpleGrad = computeGrad(dist, uPurpleAmount); + if (uGreenAmount > 0.0 && hueInRange(h, uGreenStart, uGreenStop)) + greenGrad = computeGrad(dist, uGreenAmount); + + float fringeMask = min(1.0, purpleGrad + greenGrad); + FragColor = vec4(fringeMask, 0.0, 0.0, 1.0); +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x3025d0b_0x3025d0b.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x3025d0b_0x3025d0b.frag new file mode 100644 index 00000000..054adda5 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x3025d0b_0x3025d0b.frag @@ -0,0 +1,30 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: be7df9e0bd89a0467177c64df289d56f33585086266c451a570a4e8f93d011b4 + * ELF offsets: 0x3025d0b + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; +uniform int uSrcOffsetX; +uniform int uSrcOffsetY; + +vec4 conductionFn(vec4 g) { + vec4 kg = g * 655.35; kg = kg*kg; kg = kg*kg; + return g / (kg + 1.0); +} +void main() { + ivec2 sz = textureSize(uInputTexture0, 0); + ivec2 p = ivec2(gl_FragCoord.xy) + ivec2(uSrcOffsetX, uSrcOffsetY); + vec4 c = texelFetch(uInputTexture0, clamp(p, ivec2(0), sz-1), 0); + vec4 cN = texelFetch(uInputTexture0, clamp(p+ivec2( 0,-1), ivec2(0), sz-1), 0); + vec4 cS = texelFetch(uInputTexture0, clamp(p+ivec2( 0, 1), ivec2(0), sz-1), 0); + vec4 cW = texelFetch(uInputTexture0, clamp(p+ivec2(-1, 0), ivec2(0), sz-1), 0); + vec4 cE = texelFetch(uInputTexture0, clamp(p+ivec2( 1, 0), ivec2(0), sz-1), 0); + vec4 s = (conductionFn(cN-c)+conductionFn(cS-c)+conductionFn(cW-c)+conductionFn(cE-c))/4.0; + FragColor = clamp(c + s, 0.0, 1.0); +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x303011d_0x303011d.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x303011d_0x303011d.frag new file mode 100644 index 00000000..e0fa00ee --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x303011d_0x303011d.frag @@ -0,0 +1,63 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 4788646eb655664ed70590e8ac61a52dd2bb31df68599569683e0569158980a0 + * ELF offsets: 0x303011d + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; +uniform sampler2D uInputTexture1; +uniform int uSrcOffsetX; +uniform int uSrcOffsetY; +uniform float uPurpleStart; +uniform float uPurpleStop; +uniform float uGreenStart; +uniform float uGreenStop; +uniform float uPurpleAmount; +uniform float uGreenAmount; +uniform float uZoom; + +float hueOf(vec4 v) { + float mx = max(v.r, max(v.g, v.b)); + float mn = min(v.r, min(v.g, v.b)); + if (mx <= 0.0 || (mx-mn)/mx <= 0.05) return -1.0; + float c60 = 60.0/(mx-mn); + if (mx == v.r) return (v.g >= v.b) ? c60*(v.g-v.b) : c60*(v.g-v.b)+360.0; + if (mx == v.g) return c60*(v.b-v.r)+120.0; + return c60*(v.r-v.g)+240.0; +} +bool hueInRange(float h, float hStart, float hStop) { + if (h < 0.0) return false; + bool r1 = (hStart <= h && h <= hStop); + bool r2 = !(hStop < h && h < hStart); + return (hStart < hStop) ? r1 : r2; +} +void main() { + ivec2 srcSz = textureSize(uInputTexture0, 0); + ivec2 dstSz = textureSize(uInputTexture1, 0); + ivec2 p = ivec2(gl_FragCoord.xy); + + // Sample source and distance + vec4 src = texelFetch(uInputTexture0, + clamp(p + ivec2(uSrcOffsetX, uSrcOffsetY), ivec2(0), srcSz-1), 0); + vec2 dxy = texelFetch(uInputTexture1, clamp(p, ivec2(0), dstSz-1), 0).rg; + + // Hue masks + amount + float h = hueOf(src); + float amount = 0.0; + if (hueInRange(h, uPurpleStart, uPurpleStop)) amount = clamp(uPurpleAmount, 0.0, 100.0); + else if (hueInRange(h, uGreenStart, uGreenStop)) amount = clamp(uGreenAmount, 0.0, 100.0); + + // Compare distances → fringe mask + float dist = sqrt(dxy.x*dxy.x + dxy.y*dxy.y); + float scaled = (1.0 + sqrt(2.0)) * min(90.0, amount) * 0.1 * uZoom; + float fringeMask = (dist <= scaled / 255.0) ? 1.0 : 0.0; + + // Premultiply by (1 − mask) + float m = 1.0 - fringeMask; + FragColor = vec4(src.r*m, src.g*m, src.b*m, m); +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x3038f66_0x3038f66.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x3038f66_0x3038f66.frag new file mode 100644 index 00000000..12e8cddb --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x3038f66_0x3038f66.frag @@ -0,0 +1,26 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 05317b455a0d1d6d9afaa741b05bc34fe23073556dabb500068780abae76dd1c + * ELF offsets: 0x3038f66 + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; // texProcess (RGBX at processRes) +uniform sampler2D uInputTexture1; // texHalfMask (R = fringeMask at processRes) + +void main() { + ivec2 p = ivec2(gl_FragCoord.xy); + float fringeMask = texelFetch(uInputTexture1, p, 0).r; + // Seed ALL non-fringe pixels as potential color sources. + // CPU InpaintTexture uses all non-fringe (Done) boundary pixels regardless of hue, + // so the GPU should do the same to get neutral boundary colors for replacement. + if (fringeMask < 0.01) { + FragColor = vec4(float(p.x) + 0.5, float(p.y) + 0.5, 0.0, 1.0); + } else { + FragColor = vec4(-1.0, -1.0, 0.0, 0.0); + } +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x303ca82_0x303ca82.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x303ca82_0x303ca82.frag new file mode 100644 index 00000000..2108c77c --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x303ca82_0x303ca82.frag @@ -0,0 +1,27 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: eca183311e10a8a3832fb3b176a9a9df0b7c91c53f8ffdba2ea6c20302d050a1 + * ELF offsets: 0x303ca82 + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; + +void main() { + ivec2 sz = textureSize(uInputTexture0, 0); + ivec2 p = ivec2(gl_FragCoord.xy); + const float STEP = 1.0 / 255.0; + vec2 res = texelFetch(uInputTexture0, p, 0).rg; + for (int off = -8; off <= 8; off++) { + ivec2 sp = clamp(p + ivec2(off, 0), ivec2(0), sz-1); + vec2 pix = texelFetch(uInputTexture0, sp, 0).rg; + pix.g += abs(float(off)) * STEP; + if ((pix.x*pix.x + pix.y*pix.y) < (res.x*res.x + res.y*res.y)) + res = pix; + } + FragColor = vec4(res.x, res.y, 1.0, 1.0); +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x303cd17_0x303cd17.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x303cd17_0x303cd17.frag new file mode 100644 index 00000000..9b506723 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x303cd17_0x303cd17.frag @@ -0,0 +1,25 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 5edd39c1c209941815ef719ebd68a0ad5b9d44e5c6af1634e7dc3d0fbeb2a469 + * ELF offsets: 0x303cd17 + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; +void main() { + ivec2 p = ivec2(gl_FragCoord.xy); + vec4 seed = texelFetch(uInputTexture0, p, 0); + if (seed.a < 0.5) { + // No seed reachable: output large distance so this pixel is never treated as fringe. + FragColor = vec4(1.0, 1.0, 0.0, 1.0); + return; + } + vec2 me = vec2(float(p.x) + 0.5, float(p.y) + 0.5); + vec2 dxy = me - seed.rg; + // Normalise by 255: dist = sqrt(dxy.x²+dxy.y²) in [0,1] where 1.0 = 255 pixels. + FragColor = vec4(abs(dxy.x) / 255.0, abs(dxy.y) / 255.0, 0.0, 1.0); +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x3043a7a_0x3043a7a.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x3043a7a_0x3043a7a.frag new file mode 100644 index 00000000..522769d9 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x3043a7a_0x3043a7a.frag @@ -0,0 +1,75 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 5032f05ce79cbaba7a0539c9611235df091957795672a17f3d77457625d85336 + * ELF offsets: 0x3043a7a + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; +uniform sampler2D uInputTexture1; +uniform int uSrcOffsetX; +uniform int uSrcOffsetY; +uniform float uPurpleStart; +uniform float uPurpleStop; +uniform float uGreenStart; +uniform float uGreenStop; +uniform float uPurpleAmount; +uniform float uGreenAmount; +uniform float uZoom; + +float hueOf(vec4 v) { + float mx = max(v.r, max(v.g, v.b)); + float mn = min(v.r, min(v.g, v.b)); + if (mx <= 0.0 || (mx-mn)/mx <= 0.05) return -1.0; + float c60 = 60.0/(mx-mn); + if (mx == v.r) return (v.g >= v.b) ? c60*(v.g-v.b) : c60*(v.g-v.b)+360.0; + if (mx == v.g) return c60*(v.b-v.r)+120.0; + return c60*(v.r-v.g)+240.0; +} +bool hueInRange(float h, float hStart, float hStop) { + if (h < 0.0) return false; + float hAdj = h; + if (hAdj < hStart) hAdj += 360.0; + return (hStart < hAdj && hAdj <= hStop); +} +float computeGrad(float dist, float amount) { + float scale = (1.0 + sqrt(2.0)) * 0.1 * uZoom / 255.0; + float amt0 = clamp(amount - 0.5, 0.0, 90.0) * scale; + float amt1 = clamp(amount + 0.5, 0.0, 90.0) * scale; + if (dist < amt0) return 1.0; + if (amt1 > amt0 && dist <= amt1) return (amt1 - dist) / (amt1 - amt0); + return 0.0; +} +void main() { + ivec2 srcSz = textureSize(uInputTexture0, 0); + ivec2 dstSz = textureSize(uInputTexture1, 0); + ivec2 p = ivec2(gl_FragCoord.xy); + + vec4 src = texelFetch(uInputTexture0, + clamp(p + ivec2(uSrcOffsetX, uSrcOffsetY), ivec2(0), srcSz-1), 0); + + float dist = 0.0; + ivec2 distBase = p + ivec2(uSrcOffsetX, uSrcOffsetY); + for (int dy = -1; dy <= 1; dy++) { + for (int dx = -1; dx <= 1; dx++) { + vec2 d = texelFetch(uInputTexture1, + clamp(distBase + ivec2(dx, dy), ivec2(0), dstSz-1), 0).rg; + dist = max(dist, sqrt(d.x*d.x + d.y*d.y)); + } + } + + float h = hueOf(src); + float purpleGrad = 0.0, greenGrad = 0.0; + if (uPurpleAmount > 0.0 && hueInRange(h, uPurpleStart, uPurpleStop)) + purpleGrad = computeGrad(dist, uPurpleAmount); + if (uGreenAmount > 0.0 && hueInRange(h, uGreenStart, uGreenStop)) + greenGrad = computeGrad(dist, uGreenAmount); + + float fringeMask = min(1.0, purpleGrad + greenGrad); + float m = 1.0 - fringeMask; + FragColor = vec4(src.r*m, src.g*m, src.b*m, m); +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x3053268_0x3053268.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x3053268_0x3053268.frag new file mode 100644 index 00000000..e0971b7f --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x3053268_0x3053268.frag @@ -0,0 +1,23 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 64f9d74a6693cf3660eb633e889e91c4f7e549865bbd55d05ca1472287c93990 + * ELF offsets: 0x3053268 + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; // full-res texSrc + +void main() { + ivec2 p = ivec2(gl_FragCoord.xy); // half-res output coord + ivec2 srcSz = textureSize(uInputTexture0, 0); + ivec2 s = p * 2; + vec4 s00 = texelFetch(uInputTexture0, clamp(s + ivec2(0, 0), ivec2(0), srcSz-1), 0); + vec4 s10 = texelFetch(uInputTexture0, clamp(s + ivec2(1, 0), ivec2(0), srcSz-1), 0); + vec4 s01 = texelFetch(uInputTexture0, clamp(s + ivec2(0, 1), ivec2(0), srcSz-1), 0); + vec4 s11 = texelFetch(uInputTexture0, clamp(s + ivec2(1, 1), ivec2(0), srcSz-1), 0); + FragColor = (s00 + s10 + s01 + s11) * 0.25; +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x3061f15_0x3061f15.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x3061f15_0x3061f15.frag new file mode 100644 index 00000000..a8449c3b --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x3061f15_0x3061f15.frag @@ -0,0 +1,24 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 9071061620f2032c7d385e1156c3d06346385976d258aca5b8ff4506dd916d9d + * ELF offsets: 0x3061f15 + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; + +void main() { + ivec2 base = ivec2(gl_FragCoord.xy) * 2; + ivec2 srcSz = textureSize(uInputTexture0, 0); + vec4 a = texelFetch(uInputTexture0, clamp(base+ivec2(0,0), ivec2(0), srcSz-1), 0); + vec4 b = texelFetch(uInputTexture0, clamp(base+ivec2(1,0), ivec2(0), srcSz-1), 0); + vec4 c = texelFetch(uInputTexture0, clamp(base+ivec2(0,1), ivec2(0), srcSz-1), 0); + vec4 d = texelFetch(uInputTexture0, clamp(base+ivec2(1,1), ivec2(0), srcSz-1), 0); + vec4 sum = a + b + c + d; + float w = sum.a; + FragColor = (w <= 0.0) ? vec4(0.0) : vec4(sum.rgb / w, 1.0); +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x306afe7_0x306afe7.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x306afe7_0x306afe7.frag new file mode 100644 index 00000000..ddf5eb4b --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x306afe7_0x306afe7.frag @@ -0,0 +1,104 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: ecb85eb3453ecfb72f032d171bef7287a0479132b7ff0187712f82bb054a13ab + * ELF offsets: 0x306afe7 + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; // texSrc (srcRect-sized) +uniform sampler2D uInputTexture1; // texFringeMask (srcRect-sized, R = fringeMask) +uniform sampler2D uInputTexture2; // texInpainted (srcRect-sized, RGB = inpainted) +uniform int uSrcOffsetX; +uniform int uSrcOffsetY; +uniform float uPurpleStart; +uniform float uPurpleStop; +uniform float uGreenStart; +uniform float uGreenStop; +uniform float uPurpleAmount; +uniform float uGreenAmount; + +float hueOf(vec4 v) { + float mx = max(v.r, max(v.g, v.b)); + float mn = min(v.r, min(v.g, v.b)); + if (mx <= 0.0 || (mx-mn)/mx <= 0.05) return -1.0; + float c60 = 60.0/(mx-mn); + if (mx == v.r) return (v.g >= v.b) ? c60*(v.g-v.b) : c60*(v.g-v.b)+360.0; + if (mx == v.g) return c60*(v.b-v.r)+120.0; + return c60*(v.r-v.g)+240.0; +} +bool hueInRange(float h, float hStart, float hStop) { + if (h < 0.0) return false; + float hAdj = h; + if (hAdj < hStart) hAdj += 360.0; + return (hStart < hAdj && hAdj <= hStop); +} +float clampedSlope(float x, float x1, float y1, float x2, float y2) { + float a = (y2-y1)/(x2-x1); + return clamp(a*x + (y1-a*x1), min(y1,y2), max(y1,y2)); +} + +void main() { + ivec2 p = ivec2(gl_FragCoord.xy); + ivec2 srcSz = textureSize(uInputTexture0, 0); + // All three input textures are srcRect-sized — use the same srcOffset for all. + ivec2 sp = clamp(p + ivec2(uSrcOffsetX, uSrcOffsetY), ivec2(0), srcSz - 1); + + vec4 res = texelFetch(uInputTexture0, sp, 0); + float fringeMask = texelFetch(uInputTexture1, clamp(sp, ivec2(0), textureSize(uInputTexture1,0)-1), 0).r; + vec4 lr = texelFetch(uInputTexture2, clamp(sp, ivec2(0), textureSize(uInputTexture2,0)-1), 0); + + float h = hueOf(res); + float aVal = 0.0; + bool inHueRange = false; + if (hueInRange(h, uPurpleStart, uPurpleStop)) { aVal = clamp(uPurpleAmount, 0.0, 100.0); inHueRange = true; } + else if (hueInRange(h, uGreenStart, uGreenStop)) { aVal = clamp(uGreenAmount, 0.0, 100.0); inHueRange = true; } + + // CPU GetWeights returns {0, 0} when hue is not in any target range. + // After mask upscale (MAX), some non-matching pixels may have fringeMask > 0; + // they must not be processed. + if (!inHueRange || h < 0.0) { + FragColor = vec4(res.rgb, 1.0); + return; + } + + // BT.601 luma (CPU kRgb = {0.21, 0.72, 0.07}) + const vec3 k = vec3(0.21, 0.72, 0.07); + float oldY = dot(res.rgb, k); + float newY = dot(lr.rgb, k); + + // ReplaceColor with limitSaturation=true — mirrors CPU UColorInpainting::ReplaceColor(). + // Caps chroma expansion to 1.1× original chroma and rescales to preserve oldY luminance. + vec3 inpainted; + if (newY > 1e-6) { + float factor = oldY / newY; + vec3 raw = lr.rgb * factor; + float satNew = max(raw.r, max(raw.g, raw.b)) - min(raw.r, min(raw.g, raw.b)); + float satOld = max(res.r, max(res.g, res.b)) - min(res.r, min(res.g, res.b)); + if (satNew > 1e-6 && satOld > 1e-6) { + float satFactor = min(1.1, satNew / satOld) * satOld / satNew; + vec3 center = vec3((raw.r + raw.g + raw.b) / 3.0); + vec3 adj = (raw - center) * satFactor + center; + float lumaAdj = dot(adj, k); + inpainted = (lumaAdj > 1e-6) ? adj * (oldY / lumaAdj) : adj; + } else { + inpainted = raw; + } + inpainted = clamp(inpainted, 0.0, 1.0); + } else { + inpainted = vec3(oldY); + } + + // Mix(gray, inpainted, recoveryWeight) — CPU GetWeights() recovery formula + float recovery = clampedSlope(aVal, 90.0, 1.0, 100.0, 0.7); + vec3 newRgb = mix(vec3(oldY), inpainted, recovery); + + // alpha = alphaWeight * fringeMask (CPU: alphaWeight * targetRegMask / 65535) + float alphaWeight = clampedSlope(aVal, 0.0, 0.85, 10.0, 1.0); + float alpha = alphaWeight * fringeMask; + + FragColor = vec4(mix(res.rgb, newRgb, alpha), 1.0); +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x3070da7_0x3070da7.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x3070da7_0x3070da7.frag new file mode 100644 index 00000000..7f239ba9 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x3070da7_0x3070da7.frag @@ -0,0 +1,29 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 2eb6d3e8b25809b4772134c99864f4d403f8e3b612ed55cf51f6735b01cb1c0b + * ELF offsets: 0x3070da7 + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; // texProcess (RGBX at processRes) +uniform sampler2D uInputTexture1; // JFA inpainting result (process-space coords) +void main() { + ivec2 p = ivec2(gl_FragCoord.xy); + vec4 seed = texelFetch(uInputTexture1, p, 0); + ivec2 srcSz = textureSize(uInputTexture0, 0); + vec3 color; + if (seed.a > 0.5) { + // Nearest non-fringe pixel in process-space — look up directly (no offset needed) + ivec2 sc = ivec2(int(seed.r), int(seed.g)); + color = texelFetch(uInputTexture0, clamp(sc, ivec2(0), srcSz - 1), 0).rgb; + } else { + // No valid neighbour: keep the original process pixel so that ReplaceColor + // in fcfr_colorRecovery receives lr == src and produces no net change. + color = texelFetch(uInputTexture0, clamp(p, ivec2(0), srcSz - 1), 0).rgb; + } + FragColor = vec4(color, 1.0); +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x3074cae_0x3074cae.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x3074cae_0x3074cae.frag new file mode 100644 index 00000000..93179e02 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x3074cae_0x3074cae.frag @@ -0,0 +1,29 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 1441f909272ff89a1ba21e4def13bdbf502cc17466443f8d592bd9476ed07270 + * ELF offsets: 0x3074cae + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; // half-res inpainted colors + +void main() { + ivec2 p = ivec2(gl_FragCoord.xy); // full-res output coord + ivec2 inSz = textureSize(uInputTexture0, 0); + // Bilinear 2× upscale: output pixel p maps to half-res continuous position p*0.5 + float inX = float(p.x) * 0.5; + float inY = float(p.y) * 0.5; + int x0 = int(floor(inX)); int x1 = min(x0 + 1, inSz.x - 1); + int y0 = int(floor(inY)); int y1 = min(y0 + 1, inSz.y - 1); + float fx = inX - float(x0); + float fy = inY - float(y0); + vec4 s00 = texelFetch(uInputTexture0, ivec2(x0, y0), 0); + vec4 s10 = texelFetch(uInputTexture0, ivec2(x1, y0), 0); + vec4 s01 = texelFetch(uInputTexture0, ivec2(x0, y1), 0); + vec4 s11 = texelFetch(uInputTexture0, ivec2(x1, y1), 0); + FragColor = mix(mix(s00, s10, fx), mix(s01, s11, fx), fy); +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x30798c4_0x30798c4.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x30798c4_0x30798c4.frag new file mode 100644 index 00000000..364de937 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x30798c4_0x30798c4.frag @@ -0,0 +1,28 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 853517e8aca4276ea2c5a150fbce0d3b1efcad5d72a9787163870dabe8f72378 + * ELF offsets: 0x30798c4 + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; + +void main() { + ivec2 sz = textureSize(uInputTexture0, 0); + ivec2 p = ivec2(gl_FragCoord.xy); + float sum = 0.0; + sum += texelFetch(uInputTexture0, clamp(p+ivec2( 1,-1),ivec2(0),sz-1), 0).r; + sum += texelFetch(uInputTexture0, clamp(p+ivec2( 0,-1),ivec2(0),sz-1), 0).r; + sum += texelFetch(uInputTexture0, clamp(p+ivec2(-1,-1),ivec2(0),sz-1), 0).r; + sum += texelFetch(uInputTexture0, clamp(p+ivec2( 1, 0),ivec2(0),sz-1), 0).r; + sum += texelFetch(uInputTexture0, clamp(p+ivec2(-1, 0),ivec2(0),sz-1), 0).r; + sum += texelFetch(uInputTexture0, clamp(p+ivec2( 1, 1),ivec2(0),sz-1), 0).r; + sum += texelFetch(uInputTexture0, clamp(p+ivec2( 0, 1),ivec2(0),sz-1), 0).r; + sum += texelFetch(uInputTexture0, clamp(p+ivec2(-1,-1),ivec2(0),sz-1), 0).r; // iOS duplicate + vec4 center = texelFetch(uInputTexture0, p, 0); + FragColor = (sum < 6.0 && sum > 2.0) ? vec4(1.0) : center; +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x307dbfe_0x307dbfe.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x307dbfe_0x307dbfe.frag new file mode 100644 index 00000000..b2358215 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x307dbfe_0x307dbfe.frag @@ -0,0 +1,32 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: c677a27ae799ca3cd71bd19448694c490a92a3d4f16b9c8a76dbb9c487064425 + * ELF offsets: 0x307dbfe + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; +uniform sampler2D uInputTexture1; + +void main() { + ivec2 p = ivec2(gl_FragCoord.xy); + vec4 src = texelFetch(uInputTexture0, p, 0); + + // 2× bilinear upscale of the lower-level texture + // Output pixel p maps to lower-level position p * 0.5 + ivec2 lowerSz = textureSize(uInputTexture1, 0); + vec2 lf = vec2(p) * 0.5; // continuous position in lower space + ivec2 base = ivec2(lf); // floor → lower texel index + vec2 frac = lf - vec2(base); // fractional position [0,1) + vec4 s00 = texelFetch(uInputTexture1, clamp(base+ivec2(0,0), ivec2(0), lowerSz-1), 0); + vec4 s10 = texelFetch(uInputTexture1, clamp(base+ivec2(1,0), ivec2(0), lowerSz-1), 0); + vec4 s01 = texelFetch(uInputTexture1, clamp(base+ivec2(0,1), ivec2(0), lowerSz-1), 0); + vec4 s11 = texelFetch(uInputTexture1, clamp(base+ivec2(1,1), ivec2(0), lowerSz-1), 0); + vec4 bg = mix(mix(s00, s10, frac.x), mix(s01, s11, frac.x), frac.y); + + FragColor = src + bg * (1.0 - src.a); +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x307e06c_0x307e06c.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x307e06c_0x307e06c.frag new file mode 100644 index 00000000..6de7ad96 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x307e06c_0x307e06c.frag @@ -0,0 +1,33 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 40ac286da16f404b179d003f86ec7776fd5ab941355fe543a4ea6852cf2f1edd + * ELF offsets: 0x307e06c + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; + +void main() { + ivec2 sz = textureSize(uInputTexture0, 0); + ivec2 p = ivec2(gl_FragCoord.xy); + vec4 center = texelFetch(uInputTexture0, p, 0); + // Centre guard: non-edge pixels always pass through (CPU: "in(x,y) &&") + if (center.r >= 0.5) { FragColor = center; return; } + // Count non-edge neighbours (value 1.0). + // Slots mirror CPU ErodeMask exactly: (-1,-1) appears twice, (+1,-1) absent. + float sum = 0.0; + sum += texelFetch(uInputTexture0, clamp(p+ivec2( 0,-1), ivec2(0), sz-1), 0).r; // (0,-1) + sum += texelFetch(uInputTexture0, clamp(p+ivec2( 0, 1), ivec2(0), sz-1), 0).r; // (0,+1) + sum += texelFetch(uInputTexture0, clamp(p+ivec2(-1, 0), ivec2(0), sz-1), 0).r; // (-1,0) + sum += texelFetch(uInputTexture0, clamp(p+ivec2( 1, 0), ivec2(0), sz-1), 0).r; // (+1,0) + sum += texelFetch(uInputTexture0, clamp(p+ivec2(-1,-1), ivec2(0), sz-1), 0).r; // (-1,-1) + sum += texelFetch(uInputTexture0, clamp(p+ivec2(-1, 1), ivec2(0), sz-1), 0).r; // (-1,+1) + sum += texelFetch(uInputTexture0, clamp(p+ivec2(-1,-1), ivec2(0), sz-1), 0).r; // (-1,-1) duplicate (CPU bug) + sum += texelFetch(uInputTexture0, clamp(p+ivec2( 1, 1), ivec2(0), sz-1), 0).r; // (+1,+1) + // CPU: edge-neighbour count > 2 && < 5 ↔ non-edge sum > 3 && < 6 + FragColor = (sum < 6.0 && sum > 3.0) ? vec4(1.0) : center; +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x309326d_0x309326d.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x309326d_0x309326d.frag new file mode 100644 index 00000000..f81d8615 --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x309326d_0x309326d.frag @@ -0,0 +1,32 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: bbff5e6f1bc6526815897213461384a89b1a8ec3314f34dce3c3e66018cd73c9 + * ELF offsets: 0x309326d + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; +uniform int uStep; +void main() { + ivec2 sz = textureSize(uInputTexture0, 0); + ivec2 p = ivec2(gl_FragCoord.xy); + vec2 me = vec2(float(p.x) + 0.5, float(p.y) + 0.5); + vec4 best = texelFetch(uInputTexture0, p, 0); + float bestDist = (best.a > 0.5) ? length(me - best.rg) : 1.0e9; + for (int dy = -1; dy <= 1; dy++) { + for (int dx = -1; dx <= 1; dx++) { + if (dx == 0 && dy == 0) continue; + ivec2 q = clamp(p + ivec2(dx, dy) * uStep, ivec2(0), sz - 1); + vec4 nb = texelFetch(uInputTexture0, q, 0); + if (nb.a > 0.5) { + float d = length(me - nb.rg); + if (d < bestDist) { bestDist = d; best = nb; } + } + } + } + FragColor = best; +} diff --git a/research/phocus_glsl/05_lens_geometry/unattributed_0x30953e0_0x30953e0.frag b/research/phocus_glsl/05_lens_geometry/unattributed_0x30953e0_0x30953e0.frag new file mode 100644 index 00000000..1ff5d70c --- /dev/null +++ b/research/phocus_glsl/05_lens_geometry/unattributed_0x30953e0_0x30953e0.frag @@ -0,0 +1,49 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 6cfbe5b95c1509f6c7a20872b414c64d5150482481be8130ee510028bf0f8eaf + * ELF offsets: 0x30953e0 + * Symbols: unattributed + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; +uniform sampler2D uInputTexture0; +uniform float uS; +uniform float uHueDist; + +float hueOf(vec4 v) { + float mx = max(v.r, max(v.g, v.b)); + float mn = min(v.r, min(v.g, v.b)); + if (mx <= 0.0 || (mx-mn)/mx <= 0.05) return -1.0; + float c60 = 60.0/(mx-mn); + if (mx == v.r) return (v.g >= v.b) ? c60*(v.g-v.b) : c60*(v.g-v.b)+360.0; + if (mx == v.g) return c60*(v.b-v.r)+120.0; + return c60*(v.r-v.g)+240.0; +} +float diffFn(float a, float b, float t) { + if (a < 0.0 || b < 0.0) return 0.0; + float d = min(abs(a-b), 360.0-abs(a-b)); + return (d > t) ? 1.0 : -1.0; +} +void main() { + ivec2 sz = textureSize(uInputTexture0, 0); + ivec2 p = ivec2(gl_FragCoord.xy); + int S = max(1, int(round(uS))); + float lt = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2(-S,-S),ivec2(0),sz-1), 0)); + float mt = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2( 0,-S),ivec2(0),sz-1), 0)); + float rt = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2( S,-S),ivec2(0),sz-1), 0)); + float lm = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2(-S, 0),ivec2(0),sz-1), 0)); + float rm = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2( S, 0),ivec2(0),sz-1), 0)); + float lb = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2(-S, S),ivec2(0),sz-1), 0)); + float mb = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2( 0, S),ivec2(0),sz-1), 0)); + float rb = hueOf(texelFetch(uInputTexture0, clamp(p+ivec2( S, S),ivec2(0),sz-1), 0)); + float t = uHueDist; + float mag = diffFn(rt,lt,t)+diffFn(rb,lb,t)+2.0*diffFn(rm,lm,t) + + diffFn(lt,lb,t)+diffFn(rt,rb,t)+2.0*diffFn(mt,mb,t) + + diffFn(lm,mt,t)+diffFn(mb,rm,t)+2.0*diffFn(lb,rt,t) + + diffFn(lm,mb,t)+diffFn(mt,rm,t)+2.0*diffFn(lt,rb,t); + float res = (mag > 0.0) ? 0.0 : 1.0; + FragColor = vec4(res, res, res, 1.0); +} diff --git a/research/phocus_glsl/06_detail_texture/cikernel_create_film_grain_0x306e683.frag b/research/phocus_glsl/06_detail_texture/cikernel_create_film_grain_0x306e683.frag new file mode 100644 index 00000000..34819b76 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/cikernel_create_film_grain_0x306e683.frag @@ -0,0 +1,100 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: a18e2b102dc046b550c62dc3b340b25376d05213b5b17078066d2835548fbcff + * ELF offsets: 0x306e683 + * Symbols: cikernel_create_film_grain_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp int; + +out vec4 FragColor; + +layout(std140) uniform GrainsParam { + ivec2 offset; // 8 + int color; // 4 + float multiplier; // 4 + // ---- 16 + float resolution; + float grainOffset; // in 65535-domain + float grainScale; // in 65535-domain + float blendAmount; // unused here + // ---- 32 + float zoom; + float _pad0; float _pad1; float _pad2; +} opts; + +const float kMaxRange = 65535.0; + +// Pure-math random hash matching iOS CIKernel Random3 +vec3 Random3(vec3 c) { + float pos = dot(c, vec3(17.0, 59.4, 15.0)); + pos = mod(pos, 256.0 * 2.0 * 3.14159265); + vec3 factors = vec3(262144.0, 32768.0, 2097152.0); + return fract(factors * sin(pos)) - 0.5; +} + +float Simplex(vec3 p) { + const float F3 = 1.0/3.0; + const float G3 = 1.0/6.0; + + float dotp = dot(p, vec3(F3)); + vec3 s = floor(p + dotp); + vec3 x = p - s + dot(s, vec3(G3)); + + vec3 i1, i2; + if (x.x >= x.y) { + if (x.y >= x.z) { i1=vec3(1,0,0); i2=vec3(1,1,0); } + else if (x.x >= x.z) { i1=vec3(1,0,0); i2=vec3(1,0,1); } + else { i1=vec3(0,0,1); i2=vec3(1,0,1); } + } else { + if (x.y < x.z) { i1=vec3(0,0,1); i2=vec3(0,1,1); } + else if (x.x < x.z) { i1=vec3(0,1,0); i2=vec3(0,1,1); } + else { i1=vec3(0,1,0); i2=vec3(1,1,0); } + } + + vec3 x1 = x - i1 + G3; + vec3 x2 = x - i2 + 2.0*G3; + vec3 x3 = x - 1.0 + 3.0*G3; + + vec4 wRaw = vec4(dot(x,x), dot(x1,x1), dot(x2,x2), dot(x3,x3)); + vec4 w = max(vec4(0.6) - wRaw, 0.0); + + vec4 w2 = w*w; + vec4 w4 = w2*w2; + + vec4 d = vec4(dot(Random3(s), x), + dot(Random3(s+i1), x1), + dot(Random3(s+i2), x2), + dot(Random3(s+1.0), x3)); + + return dot(d * w4, vec4(52.0)); +} + +void main() { + float safeZoom = (opts.zoom == 0.0) ? 1.0 : opts.zoom; + float safeMul = (opts.multiplier == 0.0) ? 1.0 : opts.multiplier; + + vec2 gid = floor(gl_FragCoord.xy); + // Match iOS CIKernel: int truncation of coordinate/zoom before adding offset + vec2 pos = vec2(floor(gid.x / safeZoom) + float(opts.offset.x), + floor(gid.y / safeZoom) + float(opts.offset.y)); + pos = pos * opts.resolution / safeMul; + + float n0 = Simplex(vec3(pos, 0.0)); + vec3 noise = vec3(n0); + + if (opts.color > 0) { + float blend = min(float(opts.color), 20.0) / 20.0; + float n1 = Simplex(vec3(pos, 1.0)); + float n2 = Simplex(vec3(pos, 2.0)); + noise.r = mix(n0, n1, blend); + noise.b = mix(n0, n2, blend); + } + + vec3 grain65535 = opts.grainScale * noise + opts.grainOffset; + vec3 grain01 = clamp(grain65535 / kMaxRange, 0.0, 1.0); + + FragColor = vec4(grain01, 1.0); +} diff --git a/research/phocus_glsl/06_detail_texture/cikernel_create_film_grain_blend_0x309ef57.frag b/research/phocus_glsl/06_detail_texture/cikernel_create_film_grain_blend_0x309ef57.frag new file mode 100644 index 00000000..0509cc03 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/cikernel_create_film_grain_blend_0x309ef57.frag @@ -0,0 +1,94 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: b72f1aaffa4d668aa8fef8bf9d539bb56950c28e9c53f3b0e47dcd4227ed5010 + * ELF offsets: 0x309ef57 + * Symbols: cikernel_create_film_grain_blend_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp int; +precision highp sampler2D; + +out vec4 FragColor; + +layout(std140) uniform GrainsParam { + ivec2 offset; + int color; + float multiplier; + float resolution; + float grainOffset; + float grainScale; + float blendAmount; + float zoom; + float _pad0; float _pad1; float _pad2; +} opts; + +uniform sampler2D uInputTexture0; // input image 0..1 + +const float kMaxRange = 65535.0; + +// Pure-math random hash matching iOS CIKernel Random3 +vec3 Random3(vec3 c) { + float pos = dot(c, vec3(17.0, 59.4, 15.0)); + pos = mod(pos, 256.0 * 2.0 * 3.14159265); + vec3 factors = vec3(262144.0, 32768.0, 2097152.0); + return fract(factors * sin(pos)) - 0.5; +} + +float Simplex(vec3 p) { + const float F3=1.0/3.0, G3=1.0/6.0; + float dotp = dot(p, vec3(F3)); + vec3 s = floor(p + dotp); + vec3 x = p - s + dot(s, vec3(G3)); + + vec3 i1,i2; + if (x.x >= x.y) { + if (x.y >= x.z) { i1=vec3(1,0,0); i2=vec3(1,1,0); } + else if (x.x >= x.z) { i1=vec3(1,0,0); i2=vec3(1,0,1); } + else { i1=vec3(0,0,1); i2=vec3(1,0,1); } + } else { + if (x.y < x.z) { i1=vec3(0,0,1); i2=vec3(0,1,1); } + else if (x.x < x.z) { i1=vec3(0,1,0); i2=vec3(0,1,1); } + else { i1=vec3(0,1,0); i2=vec3(1,1,0); } + } + + vec3 x1 = x - i1 + G3; + vec3 x2 = x - i2 + 2.0*G3; + vec3 x3 = x - 1.0 + 3.0*G3; + + vec4 w = max(vec4(0.6) - vec4(dot(x,x), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0); + vec4 w2=w*w, w4=w2*w2; + + vec4 d = vec4(dot(Random3(s),x), + dot(Random3(s+i1),x1), + dot(Random3(s+i2),x2), + dot(Random3(s+1.0),x3)); + + return dot(d*w4, vec4(52.0)); +} + +void main() { + ivec2 gid = ivec2(gl_FragCoord.xy); + + float safeZoom = (opts.zoom == 0.0) ? 1.0 : opts.zoom; + float safeMul = (opts.multiplier == 0.0) ? 1.0 : opts.multiplier; + + // Match iOS CIKernel: int truncation of coordinate/zoom before adding offset + vec2 pos = vec2(floor(float(gid.x) / safeZoom) + float(opts.offset.x), + floor(float(gid.y) / safeZoom) + float(opts.offset.y)); + pos = pos * opts.resolution / safeMul; + + float n0 = Simplex(vec3(pos, 0.0)); + vec3 noise = vec3(n0); + if (opts.color > 0) { + float blend = min(float(opts.color), 20.0) / 20.0; + noise.r = mix(n0, Simplex(vec3(pos, 1.0)), blend); + noise.b = mix(n0, Simplex(vec3(pos, 2.0)), blend); + } + + vec3 grain01 = clamp((opts.grainScale * noise + opts.grainOffset) / kMaxRange, 0.0, 1.0); + vec4 inPix = texelFetch(uInputTexture0, gid, 0); + + FragColor = vec4(mix(inPix.rgb, grain01, opts.blendAmount), inPix.a); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityBlendBlurU16_0x301683e.comp b/research/phocus_glsl/06_detail_texture/clarityBlendBlurU16_0x301683e.comp new file mode 100644 index 00000000..c2b09a37 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityBlendBlurU16_0x301683e.comp @@ -0,0 +1,185 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 808b8fd80c4d37ccba8fc0e4c6fef3f3cceeb388cc3ed780dbfb2462afce49e3 + * ELF offsets: 0x301683e + * Symbols: clarityBlendBlurU16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; +precision highp image2D; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D uSrc; // textureA[i] - agg laplacian +layout(rgba16ui, binding = 1) readonly uniform uimage2D uAux; // textureG[i] - gaussian +layout(rgba16ui, binding = 2) readonly uniform uimage2D uAux2; // textureG[i+1] - gaussian next (half-res) +layout(rgba16ui, binding = 3) readonly uniform uimage2D uLut; // 256x256 LUT (U16, not float — IMG GPU compat) +layout(rgba16ui, binding = 4) writeonly uniform uimage2D uDst; + +layout(std140, binding = 5) uniform ClarityBlendStuffParams_UBO { + int wSrc; + int hSrc; + float clarityLevel; + float clarityMax; + float layerFactor; + float layerFactorDif; + float gain; + float xGamma; + int blurW; + int blurH; + float ba; + float bb; + float bc; + float be; + float bf; + float bi; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +// Returns float4 in [0, 65535] — reads from uAux2 (half-res gaussian) +vec4 readPaddedU16(ivec2 pos, ivec2 pixSize) { + ivec2 maxPos = ivec2((pixSize.x + 3) / 4, pixSize.y) - 1; + vec4 val = vec4(imageLoad(uAux2, clamp(pos, ivec2(0), maxPos))); + if (pos.x >= maxPos.x) { + int rem = pixSize.x % 4; + if (rem == 1) val = val.xxxx; + else if (rem == 2) val = vec4(val.x, val.y, val.y, val.y); + else if (rem == 3) val = vec4(val.x, val.y, val.z, val.z); + if (pos.x > maxPos.x) + val = val.wwww; + } + return val; +} + +vec4 combineUpscale(vec4 a, vec4 b, ivec2 pos) { + if ((pos.x & 1) == 1) + return vec4(a.yzw, b.x); + else + return vec4(a.w, b.xyz); +} + +vec4 upScaleBlurU16(ivec2 pos) { + vec4 vs = vec4(0.0); + ivec2 p = pos / 2; + int deltaY1 = 1, deltaY2 = 0; + + if ((pos.y & 1) != 0) { + p.y += 1; + deltaY1 = -1; + deltaY2 = (pos.y < 2) ? 0 : deltaY1; + if (2 * p.y >= blurH) { p.y--; deltaY1 = 0; } + } else if (pos.y == 0) { + deltaY1 = 0; deltaY2 = 1; + } else { + p.y -= 1; + deltaY2 = (pos.y < 2 || pos.y + 2 >= blurH) ? 0 : deltaY1; + } + + ivec2 halfSize = ivec2((blurW + 1) / 2, (blurH + 1) / 2); + + if (pos.x == 0) { + vec4 tb = readPaddedU16(p, halfSize); + vs.x = ba*tb.x + bb*tb.x + bc*tb.y; vs.y = bc*tb.x + bb*tb.x + ba*tb.y; + vs.z = ba*tb.x + bb*tb.y + bc*tb.z; vs.w = bc*tb.x + bb*tb.y + ba*tb.z; + p.y += deltaY1; + tb = readPaddedU16(p, halfSize); + vs.x += bb*tb.x + be*tb.x + bf*tb.y; vs.y += bf*tb.x + be*tb.x + bb*tb.y; + vs.z += bb*tb.x + be*tb.y + bf*tb.z; vs.w += bf*tb.x + be*tb.y + bb*tb.z; + p.y += deltaY2; + tb = readPaddedU16(p, halfSize); + vs.x += bc*tb.x + bf*tb.x + bi*tb.y; vs.y += bi*tb.x + bf*tb.x + bc*tb.y; + vs.z += bc*tb.x + bf*tb.y + bi*tb.z; vs.w += bi*tb.x + bf*tb.y + bc*tb.z; + } else if ((4 * (pos.x + 1) >= blurW) && ((pos.x & 1) == 1)) { + p.x = (pos.x - 1) / 2; + vec4 ta = readPaddedU16(p, halfSize); + vs.x = ba*ta.y + bb*ta.z + bc*ta.w; vs.y = bc*ta.y + bb*ta.z + ba*ta.w; + vs.z = ba*ta.z + bb*ta.w + bc*ta.w; vs.w = bc*ta.z + bb*ta.w + ba*ta.w; + p.y += deltaY1; + ta = readPaddedU16(p, halfSize); + vs.x += bb*ta.y + be*ta.z + bf*ta.w; vs.y += bf*ta.y + be*ta.z + bb*ta.w; + vs.z += bb*ta.z + be*ta.w + bf*ta.w; vs.w += bf*ta.z + be*ta.w + bb*ta.w; + p.y += deltaY2; + ta = readPaddedU16(p, halfSize); + vs.x += bc*ta.y + bf*ta.z + bi*ta.w; vs.y += bi*ta.y + bf*ta.z + bc*ta.w; + vs.z += bc*ta.z + bf*ta.w + bi*ta.w; vs.w += bi*ta.z + bf*ta.w + bc*ta.w; + } else { + p.x = (pos.x - 1) / 2; + vec4 cv = combineUpscale(readPaddedU16(p, halfSize), readPaddedU16(p + ivec2(1, 0), halfSize), pos); + vs.x = dot(vec3(ba, bb, bc), cv.xyz); vs.y = dot(vec3(bc, bb, ba), cv.xyz); + vs.z = dot(vec3(ba, bb, bc), cv.yzw); vs.w = dot(vec3(bc, bb, ba), cv.yzw); + p.y += deltaY1; + cv = combineUpscale(readPaddedU16(p, halfSize), readPaddedU16(p + ivec2(1, 0), halfSize), pos); + vs.x += dot(vec3(bb, be, bf), cv.xyz); vs.y += dot(vec3(bf, be, bb), cv.xyz); + vs.z += dot(vec3(bb, be, bf), cv.yzw); vs.w += dot(vec3(bf, be, bb), cv.yzw); + p.y += deltaY2; + cv = combineUpscale(readPaddedU16(p, halfSize), readPaddedU16(p + ivec2(1, 0), halfSize), pos); + vs.x += dot(vec3(bc, bf, bi), cv.xyz); vs.y += dot(vec3(bi, bf, bc), cv.xyz); + vs.z += dot(vec3(bc, bf, bi), cv.yzw); vs.w += dot(vec3(bi, bf, bc), cv.yzw); + } + + return clamp(vs, 0.0, 65535.0); +} + +// LUT lookup: input is [0,1], LUT is 256x256, index = floor(val * 65535) +float lookupLut(float val) { + int idx = int(clamp(val * 65535.0, 0.0, 65535.0)); + ivec2 pos = ivec2(idx & 0xFF, (idx >> 8) & 0xFF); + return float(imageLoad(uLut, pos).x) / 65535.0; +} + +vec4 blendCurveFlt4(vec4 inFlt, float alfa) { + vec4 res; + res.x = lookupLut(inFlt.x); + res.y = lookupLut(inFlt.y); + res.z = lookupLut(inFlt.z); + res.w = lookupLut(inFlt.w); + return (1.0 - alfa) * inFlt + alfa * res; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 dstSize = imageSize(uDst); + if (gid.x >= dstSize.x || gid.y >= dstSize.y) return; + + // iOS: float4 lapAgg = float4(int4(src.read(gid)) - 32768) / 65535.0f + vec4 lapAgg = (vec4(ivec4(imageLoad(uSrc, gid))) - 32768.0) / 65535.0; + // iOS: ushort4 gauRaw = aux.read(gid) + uvec4 gauRawU = imageLoad(uAux, gid); + // iOS: int4 vs = upScaleBlur4(aux2, gid, blnd.blur) + // float4 lapRaw = float4(int4(aux.read(gid)) - vs) / 65535.0f + ivec4 vs = ivec4(upScaleBlurU16(gid)); + vec4 lapRaw = (vec4(ivec4(gauRawU)) - vec4(vs)) / 65535.0; + // iOS: float4 gauFlt = float4(gauRaw) / 65535.0f + vec4 gauFlt = vec4(gauRawU) / 65535.0; + + // iOS: float4 val = BlendCurveFlt4(lut, gauFlt, blnd.layerFactorDif) + vec4 val = blendCurveFlt4(gauFlt, layerFactorDif); + float d = 1.0 / 65535.0; + vec4 gauMinus = gauFlt - d; + vec4 gauPlus = gauFlt + d; + float sfea = 2.3; + float sfeb = 10.0; + + // iOS uses per-component conditional via && operator applied to float4 + // In GLSL we must do per-component checks + vec4 curveAlpha = vec4(0.0); + for (int c = 0; c < 4; c++) { + if (gauMinus[c] >= 0.0 && gauPlus[c] <= 1.0) { + vec4 gp = gauFlt; gp[c] = gauPlus[c]; + vec4 gm = gauFlt; gm[c] = gauMinus[c]; + float curvePlus = blendCurveFlt4(gp, layerFactorDif)[c]; + float curveMinus = blendCurveFlt4(gm, layerFactorDif)[c]; + curveAlpha[c] = max(1.0 - (curvePlus - curveMinus) * (65535.0 / 2.0), 0.0) * sfea; + } + } + + // iOS: float4 alpha = min(blnd.clarityMax, blnd.clarityLevel + clamp(sfeb * ((val + d) / (gauFlt + d) - 1.0f) / 2.0f, -1.0f, 1.0f) + curveAlpha) + vec4 alpha = min(vec4(clarityMax), vec4(clarityLevel) + clamp(sfeb * ((val + d) / (gauFlt + d) - 1.0) / 2.0, -1.0, 1.0) + curveAlpha); + // iOS: float4 color = (lapRaw*(1.0f - alpha) + lapAgg*alpha) + BlendCurveFlt4(lut, gauFlt, blnd.layerFactor) - gauFlt + vec4 color = lapRaw * (1.0 - alpha) + lapAgg * alpha + blendCurveFlt4(gauFlt, layerFactor) - gauFlt; + + // iOS: dst.write(ushort4(clamp(color*65535.0f + 32768.0f, 0.0f, 65535.0f)), gid) + imageStore(uDst, gid, uvec4(clamp(color * 65535.0 + 32768.0, 0.0, 65535.0))); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityBlendGlobal2U16_0x307d4af.comp b/research/phocus_glsl/06_detail_texture/clarityBlendGlobal2U16_0x307d4af.comp new file mode 100644 index 00000000..abb71316 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityBlendGlobal2U16_0x307d4af.comp @@ -0,0 +1,56 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 6b8f2d419337fcc8a01151c32132da494e4ca9eebdb9143574c425b4c88edf2c + * ELF offsets: 0x307d4af + * Symbols: clarityBlendGlobal2U16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D uFullCorrA; // neg correction +layout(rgba16ui, binding = 1) writeonly uniform uimage2D uDst; +layout(rgba16ui, binding = 2) readonly uniform uimage2D uBefore; // original gray +layout(rgba16ui, binding = 3) readonly uniform uimage2D uFullCorrB; // pos correction + +layout(std140, binding = 4) uniform ClarityBlendLocalParams_UBO { + int w; + int h; + float global_val; + float local_val; + float alphaNeg; + float alphaPos; + float localMapScaleX; + float localMapScaleY; + int type; + int pad1; + int pad2; + int pad3; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 dstSize = imageSize(uDst); + if (gid.x >= dstSize.x || gid.y >= dstSize.y) return; + + // iOS: float4 uncorr = float4(before.read(gid)) / 65535.0f + vec4 uncorr = vec4(imageLoad(uBefore, gid)) / 65535.0; + // iOS: float4 corrA = float4(fullCorrA.read(gid)) / 65535.0f - uncorr + vec4 corrA = vec4(imageLoad(uFullCorrA, gid)) / 65535.0 - uncorr; + // iOS: float4 corrB = float4(fullCorrB.read(gid)) / 65535.0f - uncorr + vec4 corrB = vec4(imageLoad(uFullCorrB, gid)) / 65535.0 - uncorr; + + // iOS: float4 alpha = float4(blnd.global) + float alpha = global_val; + // iOS: float4 a = select(float4(blnd.alphaPos), float4(blnd.alphaNeg), alpha < float4(0.0f)) + vec4 a = (alpha < 0.0) ? vec4(alphaNeg) : vec4(alphaPos); + // iOS: float4 corr = a * corrB + (1.0 - a) * corrA + vec4 corr = a * corrB + (1.0 - a) * corrA; + + // iOS: dst.write(ushort4(clamp((uncorr + corr*alpha)*65535.0f, 0.0f, 65535.0f)), gid) + imageStore(uDst, gid, uvec4(clamp((uncorr + corr * alpha) * 65535.0, 0.0, 65535.0))); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityBlendGlobalNextU16_0x307923d.comp b/research/phocus_glsl/06_detail_texture/clarityBlendGlobalNextU16_0x307923d.comp new file mode 100644 index 00000000..6eae44b0 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityBlendGlobalNextU16_0x307923d.comp @@ -0,0 +1,51 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 7c86fb5c5d04a646487d987a21565b88b35a9bb9c4c04b0710e1535ff06c8e80 + * ELF offsets: 0x307923d + * Symbols: clarityBlendGlobalNextU16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D uFullCorr; +layout(rgba16ui, binding = 1) writeonly uniform uimage2D uDst; +layout(rgba16ui, binding = 2) readonly uniform uimage2D uBefore; +layout(rgba16ui, binding = 3) readonly uniform uimage2D uLast; + +layout(std140, binding = 4) uniform ClarityBlendLocalParams_UBO { + int w; + int h; + float global_val; + float local_val; + float alphaNeg; + float alphaPos; + float localMapScaleX; + float localMapScaleY; + int type; + int pad1; + int pad2; + int pad3; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 dstSize = imageSize(uDst); + if (gid.x >= dstSize.x || gid.y >= dstSize.y) return; + + // iOS: float4 uncorr = float4(before.read(gid)) / 65535.0f + vec4 uncorr = vec4(imageLoad(uBefore, gid)) / 65535.0; + // iOS: float4 corr = float4(fullCorr.read(gid)) / 65535.0f - uncorr + vec4 corr = vec4(imageLoad(uFullCorr, gid)) / 65535.0 - uncorr; + // iOS: float4 alpha = float4(blnd.global) + float alpha = global_val; + // iOS: float4 prev = float4(last.read(gid)) / 65535.0f + vec4 prev = vec4(imageLoad(uLast, gid)) / 65535.0; + + // iOS: dst.write(ushort4(clamp((prev + corr*alpha)*65535.0f, 0.0f, 65535.0f)), gid) + imageStore(uDst, gid, uvec4(clamp((prev + corr * alpha) * 65535.0, 0.0, 65535.0))); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityBlendLocal2F_0x308b9bd.comp b/research/phocus_glsl/06_detail_texture/clarityBlendLocal2F_0x308b9bd.comp new file mode 100644 index 00000000..91b10e4a --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityBlendLocal2F_0x308b9bd.comp @@ -0,0 +1,53 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: f9fe5e156ec69fb7cb7368c5691d79a4d33a6e178974d4765cbe291550ff6527 + * ELF offsets: 0x308b9bd + * Symbols: clarityBlendLocal2F_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp image2D; + +layout(rgba16f, binding = 0) readonly uniform image2D uFullCorrA; +layout(rgba16f, binding = 1) writeonly uniform image2D uDst; +layout(rgba16f, binding = 2) readonly uniform image2D uBefore; +layout(r32f, binding = 3) readonly uniform image2D uLocalMap; +layout(rgba16f, binding = 4) readonly uniform image2D uFullCorrB; + +layout(std140, binding = 5) uniform ClarityBlendLocalParams_UBO { + int w; int h; + float global_val; float local_val; + float alphaNeg; float alphaPos; + float localMapScaleX; float localMapScaleY; + int type; + int pad1; + int pad2; + int pad3; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +// Mirrors iOS LookupLocal: blend = clamp(map[pos] * local + global, minVal, 1.0) +vec4 lookupLocal(ivec2 gid) { + ivec2 pos = ivec2(round(vec2(gid) * vec2(localMapScaleX, localMapScaleY))); + float mapVal = imageLoad(uLocalMap, pos).r; + float minValue = (type == 0) ? -1.0 : 0.0; // Clarity allows negative, SF/HR does not + return vec4(clamp(mapVal * local_val + global_val, minValue, 1.0)); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 dstSize = imageSize(uDst); + if (gid.x >= dstSize.x || gid.y >= dstSize.y) return; + + vec4 uncorr = imageLoad(uBefore, gid); + vec4 corrA = imageLoad(uFullCorrA, gid) - uncorr; + vec4 corrB = imageLoad(uFullCorrB, gid) - uncorr; + vec4 blend = lookupLocal(gid); + // select: a = (blend < 0) ? alphaNeg : alphaPos (per-component check via blend.r scalar) + vec4 a = (blend.r < 0.0) ? vec4(alphaNeg) : vec4(alphaPos); + vec4 corr = a * corrB + (1.0 - a) * corrA; + imageStore(uDst, gid, clamp(uncorr + corr * blend, 0.0, 1.0)); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityBlendLocalNextF_0x3092c99.comp b/research/phocus_glsl/06_detail_texture/clarityBlendLocalNextF_0x3092c99.comp new file mode 100644 index 00000000..562f552f --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityBlendLocalNextF_0x3092c99.comp @@ -0,0 +1,49 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: bb147c1fa1de6c8e4e6f9ee0b6ff48bb39b16fe8a66e5234a7bfdf66ed326f11 + * ELF offsets: 0x3092c99 + * Symbols: clarityBlendLocalNextF_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp image2D; + +layout(rgba16f, binding = 0) readonly uniform image2D uFullCorr; +layout(rgba16f, binding = 1) writeonly uniform image2D uDst; +layout(rgba16f, binding = 2) readonly uniform image2D uBefore; +layout(rgba16f, binding = 3) readonly uniform image2D uLast; +layout(r32f, binding = 4) readonly uniform image2D uLocalMap; + +layout(std140, binding = 5) uniform ClarityBlendLocalParams_UBO { + int w; int h; + float global_val; float local_val; + float alphaNeg; float alphaPos; + float localMapScaleX; float localMapScaleY; + int type; + int pad1; + int pad2; + int pad3; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +vec4 lookupLocal(ivec2 gid) { + ivec2 pos = ivec2(round(vec2(gid) * vec2(localMapScaleX, localMapScaleY))); + float mapVal = imageLoad(uLocalMap, pos).r; + float minValue = (type == 0) ? -1.0 : 0.0; + return vec4(clamp(mapVal * local_val + global_val, minValue, 1.0)); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 dstSize = imageSize(uDst); + if (gid.x >= dstSize.x || gid.y >= dstSize.y) return; + + vec4 uncorr = imageLoad(uBefore, gid); + vec4 corr = imageLoad(uFullCorr, gid) - uncorr; + vec4 alpha = lookupLocal(gid); + vec4 prev = imageLoad(uLast, gid); + imageStore(uDst, gid, round(clamp(prev + corr * alpha, 0.0, 1.0) * 65535.0) / 65535.0); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityBlendNoLutU16_0x3051d04.comp b/research/phocus_glsl/06_detail_texture/clarityBlendNoLutU16_0x3051d04.comp new file mode 100644 index 00000000..889d5c93 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityBlendNoLutU16_0x3051d04.comp @@ -0,0 +1,142 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 8b77e58847de0bf89a07d52d07156cf6b8b3b8f46f43ebf3cdbeb4cffa81719a + * ELF offsets: 0x3051d04 + * Symbols: clarityBlendNoLutU16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D uSrc; // textureA[i] - agg laplacian +layout(rgba16ui, binding = 1) readonly uniform uimage2D uAux; // textureG[i] - gaussian +layout(rgba16ui, binding = 2) readonly uniform uimage2D uAux2; // textureG[i+1] - gaussian next (half-res) +layout(rgba16ui, binding = 3) writeonly uniform uimage2D uDst; + +layout(std140, binding = 4) uniform ClarityBlendStuffParams_UBO { + int wSrc; + int hSrc; + float clarityLevel; + float clarityMax; + float layerFactor; + float layerFactorDif; + float gain; + float xGamma; + int blurW; + int blurH; + float ba; + float bb; + float bc; + float be; + float bf; + float bi; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +// Returns float4 in [0, 65535] — reads from uAux2 (half-res gaussian) +vec4 readPaddedU16(ivec2 pos, ivec2 pixSize) { + ivec2 maxPos = ivec2((pixSize.x + 3) / 4, pixSize.y) - 1; + vec4 val = vec4(imageLoad(uAux2, clamp(pos, ivec2(0), maxPos))); + if (pos.x >= maxPos.x) { + int rem = pixSize.x % 4; + if (rem == 1) val = val.xxxx; + else if (rem == 2) val = vec4(val.x, val.y, val.y, val.y); + else if (rem == 3) val = vec4(val.x, val.y, val.z, val.z); + if (pos.x > maxPos.x) + val = val.wwww; + } + return val; +} + +vec4 combineUpscale(vec4 a, vec4 b, ivec2 pos) { + if ((pos.x & 1) == 1) + return vec4(a.yzw, b.x); + else + return vec4(a.w, b.xyz); +} + +vec4 upScaleBlurU16(ivec2 pos) { + vec4 vs = vec4(0.0); + ivec2 p = pos / 2; + int deltaY1 = 1, deltaY2 = 0; + + if ((pos.y & 1) != 0) { + p.y += 1; + deltaY1 = -1; + deltaY2 = (pos.y < 2) ? 0 : deltaY1; + if (2 * p.y >= blurH) { p.y--; deltaY1 = 0; } + } else if (pos.y == 0) { + deltaY1 = 0; deltaY2 = 1; + } else { + p.y -= 1; + deltaY2 = (pos.y < 2 || pos.y + 2 >= blurH) ? 0 : deltaY1; + } + + ivec2 halfSize = ivec2((blurW + 1) / 2, (blurH + 1) / 2); + + if (pos.x == 0) { + vec4 tb = readPaddedU16(p, halfSize); + vs.x = ba*tb.x + bb*tb.x + bc*tb.y; vs.y = bc*tb.x + bb*tb.x + ba*tb.y; + vs.z = ba*tb.x + bb*tb.y + bc*tb.z; vs.w = bc*tb.x + bb*tb.y + ba*tb.z; + p.y += deltaY1; + tb = readPaddedU16(p, halfSize); + vs.x += bb*tb.x + be*tb.x + bf*tb.y; vs.y += bf*tb.x + be*tb.x + bb*tb.y; + vs.z += bb*tb.x + be*tb.y + bf*tb.z; vs.w += bf*tb.x + be*tb.y + bb*tb.z; + p.y += deltaY2; + tb = readPaddedU16(p, halfSize); + vs.x += bc*tb.x + bf*tb.x + bi*tb.y; vs.y += bi*tb.x + bf*tb.x + bc*tb.y; + vs.z += bc*tb.x + bf*tb.y + bi*tb.z; vs.w += bi*tb.x + bf*tb.y + bc*tb.z; + } else if ((4 * (pos.x + 1) >= blurW) && ((pos.x & 1) == 1)) { + p.x = (pos.x - 1) / 2; + vec4 ta = readPaddedU16(p, halfSize); + vs.x = ba*ta.y + bb*ta.z + bc*ta.w; vs.y = bc*ta.y + bb*ta.z + ba*ta.w; + vs.z = ba*ta.z + bb*ta.w + bc*ta.w; vs.w = bc*ta.z + bb*ta.w + ba*ta.w; + p.y += deltaY1; + ta = readPaddedU16(p, halfSize); + vs.x += bb*ta.y + be*ta.z + bf*ta.w; vs.y += bf*ta.y + be*ta.z + bb*ta.w; + vs.z += bb*ta.z + be*ta.w + bf*ta.w; vs.w += bf*ta.z + be*ta.w + bb*ta.w; + p.y += deltaY2; + ta = readPaddedU16(p, halfSize); + vs.x += bc*ta.y + bf*ta.z + bi*ta.w; vs.y += bi*ta.y + bf*ta.z + bc*ta.w; + vs.z += bc*ta.z + bf*ta.w + bi*ta.w; vs.w += bi*ta.z + bf*ta.w + bc*ta.w; + } else { + p.x = (pos.x - 1) / 2; + vec4 cv = combineUpscale(readPaddedU16(p, halfSize), readPaddedU16(p + ivec2(1, 0), halfSize), pos); + vs.x = dot(vec3(ba, bb, bc), cv.xyz); vs.y = dot(vec3(bc, bb, ba), cv.xyz); + vs.z = dot(vec3(ba, bb, bc), cv.yzw); vs.w = dot(vec3(bc, bb, ba), cv.yzw); + p.y += deltaY1; + cv = combineUpscale(readPaddedU16(p, halfSize), readPaddedU16(p + ivec2(1, 0), halfSize), pos); + vs.x += dot(vec3(bb, be, bf), cv.xyz); vs.y += dot(vec3(bf, be, bb), cv.xyz); + vs.z += dot(vec3(bb, be, bf), cv.yzw); vs.w += dot(vec3(bf, be, bb), cv.yzw); + p.y += deltaY2; + cv = combineUpscale(readPaddedU16(p, halfSize), readPaddedU16(p + ivec2(1, 0), halfSize), pos); + vs.x += dot(vec3(bc, bf, bi), cv.xyz); vs.y += dot(vec3(bi, bf, bc), cv.xyz); + vs.z += dot(vec3(bc, bf, bi), cv.yzw); vs.w += dot(vec3(bi, bf, bc), cv.yzw); + } + + return clamp(vs, 0.0, 65535.0); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 dstSize = imageSize(uDst); + if (gid.x >= dstSize.x || gid.y >= dstSize.y) return; + + // iOS: float4 lapAgg = float4(int4(src.read(gid)) - 32768) / 65535.0f + vec4 lapAgg = (vec4(ivec4(imageLoad(uSrc, gid))) - 32768.0) / 65535.0; + // iOS: int4 vs = upScaleBlur4(aux2, gid, blnd.blur) + // float4 lapRaw = float4(int4(aux.read(gid)) - vs) / 65535.0f + ivec4 vs = ivec4(upScaleBlurU16(gid)); + vec4 lapRaw = (vec4(ivec4(imageLoad(uAux, gid))) - vec4(vs)) / 65535.0; + + // iOS: float4 alpha = min(blnd.clarityMax, blnd.clarityLevel) + float alpha = min(clarityMax, clarityLevel); + // iOS: float4 color = (lapRaw*(1.0f - alpha) + lapAgg*alpha) + vec4 color = lapRaw * (1.0 - alpha) + lapAgg * alpha; + + // iOS: dst.write(ushort4(clamp(color*65535.0f + 32768.0f, 0.0f, 65535.0f)), gid) + imageStore(uDst, gid, uvec4(clamp(color * 65535.0 + 32768.0, 0.0, 65535.0))); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityCombineFinal4U16_0x301e906.comp b/research/phocus_glsl/06_detail_texture/clarityCombineFinal4U16_0x301e906.comp new file mode 100644 index 00000000..f1ab4f3b --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityCombineFinal4U16_0x301e906.comp @@ -0,0 +1,103 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 14ec460a9b79553f33b090ab75ff8e3a9897c15eb3d346703914db856fdab2df + * ELF offsets: 0x301e906 + * Symbols: clarityCombineFinal4U16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp image2D; +precision highp uimage2D; + +layout(rgba16f, binding = 0) readonly uniform image2D uInput; // original RgbX +layout(rgba16ui, binding = 1) readonly uniform uimage2D uGray; // processed PackedUint16 gray +layout(rgba16ui, binding = 2) readonly uniform uimage2D uGrayRef; // reference (uncorrected) PackedUint16 gray = textureG[0] +layout(rgba16f, binding = 3) writeonly uniform image2D uOutput; // final RgbX + +layout(std140, binding = 4) uniform ClarityCombineFinalParams_UBO { + int marginX; + int marginY; + int pad1; + int pad2; +}; + +layout(std140, binding = 5) uniform ClarityCenterGammaParams_UBO { + float xGamma; + float centerVal; + float stretchFactor; + int gamPad; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +// iOS: ushort4 shiftBytes(ushort4 left, ushort4 right, int amount) +uvec4 shiftBytesU(uvec4 left, uvec4 right, int amount) { + if (amount == 0) return left; + if (amount == 1 || amount == -3) return uvec4(left.yzw, right.x); + if (amount == 2 || amount == -2) return uvec4(left.zw, right.xy); + if (amount == 3 || amount == -1) return uvec4(left.w, right.xyz); + return left; +} + +// factor = processedGray / referenceGray, applied to the (HDR) rgb. +// +// iOS clarityCombine divides by g=(r+g+b)/3 of the *uint16* input, where HDR highlights are +// already clamped to 1.0 (iOS keeps clarity SDR and handles HDR in the client gainmap layer). +// Android clarity runs on rgba16f and keeps values > 1.0, so dividing by the unclamped rgb +// luminance flattens HDR highlights: for a near-neutral highlight rgb≈g the result collapses +// to ≈grays, so e.g. a sun core and its halo end up equally bright (overexposed, bug-0018). +// The reference gray (textureG[0], the uncorrected stretched gray) comes from the Phase-1 gray +// which clamps to [0,1], so it ≈ the clamped luminance iOS divides by; using it gives +// out = rgb * (processed/reference), preserving the HDR rgb gradient. Mirrors the FastPreview +// path (ClarityCreateFinalFactorsU16), including its [0.25,4.0] factor clamp. +vec4 clarityCombine(vec4 src, float gray, float refGray) { + float factor = (refGray > 0.00002) ? clamp(gray / refGray, 0.25, 4.0) : 1.0; + return vec4(src.rgb * factor, src.a); +} + +// Inverse gamma/stretch transform: uint16 stretched-gray → linear gray (mirrors iOS / FastPreview). +vec4 toLinearGray(uvec4 packed) { + return pow(vec4(packed) / 65535.0, vec4(2.0 / xGamma)) / stretchFactor; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 outSize = imageSize(uOutput); + if (gid.x >= outSize.x || gid.y >= outSize.y) return; + + // iOS: auto grayPos = uint2(gid.x + opts.marginX/4, gid.y + opts.marginY) + ivec2 grayPos = ivec2(gid.x + marginX / 4, gid.y + marginY); + // iOS: auto graysIn = gray.read(grayPos) + uvec4 graysIn = imageLoad(uGray, grayPos); + uvec4 refIn = imageLoad(uGrayRef, grayPos); + + // iOS: if (opts.marginX%4 != 0) + // graysIn = shiftBytes(graysIn, gray.read(uint2(grayPos.x+1, grayPos.y)), opts.marginX%4) + int misalign = marginX % 4; + if (misalign != 0) { + uvec4 graysNext = imageLoad(uGray, ivec2(grayPos.x + 1, grayPos.y)); + uvec4 refNext = imageLoad(uGrayRef, ivec2(grayPos.x + 1, grayPos.y)); + graysIn = shiftBytesU(graysIn, graysNext, misalign); + refIn = shiftBytesU(refIn, refNext, misalign); + } + + // Inverse transform both processed and reference gray into linear space. + vec4 grays = toLinearGray(graysIn); + vec4 refs = toLinearGray(refIn); + + // Process 4 RGB pixels per thread + // iOS: auto in = uint2(gid.x*4 + opts.marginX, gid.y + opts.marginY) + ivec2 inBase = ivec2(gid.x * 4 + marginX, gid.y + marginY); + + vec4 rgb0 = imageLoad(uInput, ivec2(inBase.x + 0, inBase.y)); + vec4 rgb1 = imageLoad(uInput, ivec2(inBase.x + 1, inBase.y)); + vec4 rgb2 = imageLoad(uInput, ivec2(inBase.x + 2, inBase.y)); + vec4 rgb3 = imageLoad(uInput, ivec2(inBase.x + 3, inBase.y)); + + imageStore(uOutput, ivec2(gid.x * 4 + 0, gid.y), clarityCombine(rgb0, grays.x, refs.x)); + imageStore(uOutput, ivec2(gid.x * 4 + 1, gid.y), clarityCombine(rgb1, grays.y, refs.y)); + imageStore(uOutput, ivec2(gid.x * 4 + 2, gid.y), clarityCombine(rgb2, grays.z, refs.z)); + imageStore(uOutput, ivec2(gid.x * 4 + 3, gid.y), clarityCombine(rgb3, grays.w, refs.w)); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityCreateFinalFactorsU16_0x30742e2.comp b/research/phocus_glsl/06_detail_texture/clarityCreateFinalFactorsU16_0x30742e2.comp new file mode 100644 index 00000000..807368d5 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityCreateFinalFactorsU16_0x30742e2.comp @@ -0,0 +1,58 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 447319113a0246e3a4198ff07eb0fcbe40f1bc25ce32f667bb79e698e206b3d5 + * ELF offsets: 0x30742e2 + * Symbols: clarityCreateFinalFactorsU16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; +precision highp image2D; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D uGrayRef; // reference (uncorrected) PackedUint16 +layout(rgba16ui, binding = 1) readonly uniform uimage2D uGray; // processed PackedUint16 +layout(rgba16f, binding = 2) writeonly uniform image2D uFactors; // output factor map (.r channel, half-float) + +layout(std140, binding = 3) uniform ClarityCreateFinalFactorsParams_UBO { + float xGamma; + float stretchFactor; + float pad1; + float pad2; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 srcSize = imageSize(uGrayRef); + if (gid.x >= srcSize.x || gid.y >= srcSize.y) return; + + // iOS: float4 ref = float4(grayRef.read(gid)) / 65535.0f + vec4 refIn = vec4(imageLoad(uGrayRef, gid)) / 65535.0; + // iOS: float4 graysIn = float4(gray.read(gid)) / 65535.0f + vec4 grayIn = vec4(imageLoad(uGray, gid)) / 65535.0; + + // iOS: ref = pow(ref, 2.0 / gamma.xGamma) / gamma.stretchFactor + vec4 ref = pow(refIn, vec4(2.0 / xGamma)) / stretchFactor; + // iOS: auto grays = pow(graysIn, 2.0 / gamma.xGamma) / gamma.stretchFactor + vec4 grays = pow(grayIn, vec4(2.0 / xGamma)) / stretchFactor; + + // iOS: float4 result = select(grays / ref, float4(1.0), ref <= 0.00002) + // Defense-in-depth: clamp factor to [0.25, 4.0] to prevent extreme ratios + const float kFactorMin = 0.25; + const float kFactorMax = 4.0; + vec4 result; + result.x = (ref.x > 0.00002) ? clamp(grays.x / ref.x, kFactorMin, kFactorMax) : 1.0; + result.y = (ref.y > 0.00002) ? clamp(grays.y / ref.y, kFactorMin, kFactorMax) : 1.0; + result.z = (ref.z > 0.00002) ? clamp(grays.z / ref.z, kFactorMin, kFactorMax) : 1.0; + result.w = (ref.w > 0.00002) ? clamp(grays.w / ref.w, kFactorMin, kFactorMax) : 1.0; + + // Write 4 individual float values to the r32f factor map (unpacking PackedGray) + // iOS: factors.write(float4(result[0]), uint2(gid.x * 4 + 0, gid.y)) + imageStore(uFactors, ivec2(gid.x * 4 + 0, gid.y), vec4(result.x, 0.0, 0.0, 0.0)); + imageStore(uFactors, ivec2(gid.x * 4 + 1, gid.y), vec4(result.y, 0.0, 0.0, 0.0)); + imageStore(uFactors, ivec2(gid.x * 4 + 2, gid.y), vec4(result.z, 0.0, 0.0, 0.0)); + imageStore(uFactors, ivec2(gid.x * 4 + 3, gid.y), vec4(result.w, 0.0, 0.0, 0.0)); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityDiscretImage4CenterValU16_0x2ffa214.comp b/research/phocus_glsl/06_detail_texture/clarityDiscretImage4CenterValU16_0x2ffa214.comp new file mode 100644 index 00000000..d27af670 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityDiscretImage4CenterValU16_0x2ffa214.comp @@ -0,0 +1,89 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: ffddf4600d0c7322e96cdcb76b02364d0dab0d4054c1f25090cb2249815e16eb + * ELF offsets: 0x2ffa214 + * Symbols: clarityDiscretImage4CenterValU16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D uSrc; +layout(rgba16ui, binding = 1) writeonly uniform uimage2D uDst; + +layout(std140, binding = 2) uniform ClarityDiscretParams_UBO { + int wSrc; + int hSrc; + float discretisation; + float stretchFactor; + float xGammaHalf; + int pad1; + int pad2; + int pad3; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +uvec4 ReadWithPaddingU16(ivec2 gid) { + uvec4 v = imageLoad(uSrc, gid); + if (gid.y >= hSrc) { + ivec2 pos = gid; + pos.y = hSrc - 1; + if (4 * gid.x + 3 >= wSrc) { + int lastx = wSrc - 1; + pos.x = lastx / 4; + v = imageLoad(uSrc, pos); + int idx = lastx & 3; + uint lastVal = v[idx]; + v.w = lastVal; + if (4 * gid.x + 2 >= wSrc) v.z = lastVal; + if (4 * gid.x + 1 >= wSrc) v.y = lastVal; + if (4 * gid.x + 0 >= wSrc) v.x = lastVal; + } else { + v = imageLoad(uSrc, pos); + } + } else if (4 * gid.x + 3 >= wSrc) { + ivec2 pos = gid; + int lastx = wSrc - 1; + pos.x = lastx / 4; + v = imageLoad(uSrc, pos); + int idx = lastx & 3; + uint lastVal = v[idx]; + v.w = lastVal; + if (4 * gid.x + 2 >= wSrc) v.z = lastVal; + if (4 * gid.x + 1 >= wSrc) v.y = lastVal; + if (4 * gid.x + 0 >= wSrc) v.x = lastVal; + } + return v; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 dstSize = imageSize(uDst); + if (gid.x >= dstSize.x || gid.y >= dstSize.y) return; + + // iOS: float4 v = ReadWithPadding(src, hSrc, wSrc, gid) → v / 65535.0f + uvec4 raw = ReadWithPaddingU16(gid); + vec4 v = vec4(raw) / 65535.0; + + // iOS: float4 j = pow(v * stretchFactor, xGamma) * 65535.0 + vec4 j = pow(v * stretchFactor, vec4(xGammaHalf)) * 65535.0; + + // iOS: iclarity=100, factor=1, discSlope=0, parValLow=0, parValHigh=0, sigma=0.055 + const float sigma = 0.055; + const float clarity = 2.0; // 100 / 50 + const float factor = 1.0; + + // Calculate sigma curve + vec4 img_ref = (j / 65535.0) - discretisation; + vec4 img_refSq = img_ref * img_ref; + vec4 remapPixel = factor * clarity * img_ref * exp(-img_refSq / (2.0 * sigma * sigma)); + + // iOS: val = remapPixel * 65535.0f + 32768.0f + vec4 val = remapPixel * 65535.0 + 32768.0; + + // iOS: dst.write(ushort4(clamp(val, 0.0f, 65535.0f)), gid) + imageStore(uDst, gid, uvec4(clamp(val, 0.0, 65535.0))); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityDownScaleBlurU16_0x3050cc9.comp b/research/phocus_glsl/06_detail_texture/clarityDownScaleBlurU16_0x3050cc9.comp new file mode 100644 index 00000000..efd557a5 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityDownScaleBlurU16_0x3050cc9.comp @@ -0,0 +1,158 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: da8e09ea72af7aacdf5cdcfbee513b4b7deca33651e75506d7d245a8606e756d + * ELF offsets: 0x3050cc9 + * Symbols: clarityDownScaleBlurU16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D uSrc; +layout(rgba16ui, binding = 1) writeonly uniform uimage2D uDst; + +layout(std140, binding = 2) uniform ClarityBlurDownParams_UBO { + int srcW; + int srcH; + float blurA; + float blurB; + float blurC; + int pad1; + int pad2; + int pad3; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +// Returns float4 in [0, 65535] — NOT normalized (matches iOS readPadded behavior) +vec4 readPaddedU16(ivec2 pos, ivec2 pixSize) { + ivec2 maxPos = ivec2((pixSize.x + 3) / 4, pixSize.y) - 1; + vec4 val = vec4(imageLoad(uSrc, clamp(pos, ivec2(0), maxPos))); + if (pos.x >= maxPos.x) { + int rem = pixSize.x % 4; + if (rem == 1) val = val.xxxx; + else if (rem == 2) val = vec4(val.x, val.y, val.y, val.y); + else if (rem == 3) val = vec4(val.x, val.y, val.z, val.z); + if (pos.x > maxPos.x) + val = val.wwww; + } + return val; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 dstSize = imageSize(uDst); + if (gid.x >= dstSize.x || gid.y >= dstSize.y) return; + + ivec2 size = ivec2(srcW, srcH); + vec4 v, t; + ivec2 p, pos; + pos = 2 * gid; + if (gid.y > 0) pos.y -= 1; + if (gid.x > 0) pos.x--; + + // --- Row 0 (top row, weights c/b) --- + p = pos; pos.y++; + if (gid.y == 0) p.y = 0; + t = readPaddedU16(p, size); + p.x++; + if (gid.x == 0) { + v.x = blurC * t.x; + } else { + v.x = blurC * t.w; + t = readPaddedU16(p, size); + p.x++; + } + v.x += blurB * t.x + blurB * t.y + blurC * t.z; + v.y = blurC * t.y + blurB * t.z + blurB * t.w; + v.z = blurC * t.w; + t = readPaddedU16(p, size); + p.x++; + v.y += blurC * t.x; + v.z += blurB * t.x + blurB * t.y + blurC * t.z; + v.w = blurC * t.y + blurB * t.z + blurB * t.w; + t = readPaddedU16(p, size); + p.x++; + v.w += blurC * t.x; + + // --- Row 1 (center-top, weights a/b) --- + pos.y = 2 * gid.y; + p = pos; + pos.y++; + if (pos.y >= srcH) pos.y = srcH - 1; + t = readPaddedU16(p, size); + p.x++; + if (gid.x == 0) { + v.x += blurB * t.x; + } else { + v.x += blurB * t.w; + t = readPaddedU16(p, size); + p.x++; + } + v.x += blurA * t.x + blurA * t.y + blurB * t.z; + v.y += blurB * t.y + blurA * t.z + blurA * t.w; + v.z += blurB * t.w; + t = readPaddedU16(p, size); + p.x++; + v.y += blurB * t.x; + v.z += blurA * t.x + blurA * t.y + blurB * t.z; + v.w += blurB * t.y + blurA * t.z + blurA * t.w; + t = readPaddedU16(p, size); + p.x++; + v.w += blurB * t.x; + + // --- Row 2 (center-bottom, weights a/b) --- + p = pos; + pos.y++; + if (pos.y >= srcH) pos.y = srcH - 1; + t = readPaddedU16(p, size); + p.x++; + if (gid.x == 0) { + v.x += blurB * t.x; + } else { + v.x += blurB * t.w; + t = readPaddedU16(p, size); + p.x++; + } + v.x += blurA * t.x + blurA * t.y + blurB * t.z; + v.y += blurB * t.y + blurA * t.z + blurA * t.w; + v.z += blurB * t.w; + t = readPaddedU16(p, size); + p.x++; + v.y += blurB * t.x; + v.z += blurA * t.x + blurA * t.y + blurB * t.z; + v.w += blurB * t.y + blurA * t.z + blurA * t.w; + t = readPaddedU16(p, size); + p.x++; + v.w += blurB * t.x; + + // --- Row 3 (bottom row, weights c/b) --- + p = pos; + pos.y++; + if (pos.y >= srcH) pos.y = srcH - 1; + t = readPaddedU16(p, size); + p.x++; + if (gid.x == 0) { + v.x += blurC * t.x; + } else { + v.x += blurC * t.w; + t = readPaddedU16(p, size); + p.x++; + } + v.x += blurB * t.x + blurB * t.y + blurC * t.z; + v.y += blurC * t.y + blurB * t.z + blurB * t.w; + v.z += blurC * t.w; + t = readPaddedU16(p, size); + p.x++; + v.y += blurC * t.x; + v.z += blurB * t.x + blurB * t.y + blurC * t.z; + v.w += blurC * t.y + blurB * t.z + blurB * t.w; + t = readPaddedU16(p, size); + p.x++; + v.w += blurC * t.x; + + // iOS: dst.write(ushort4(clamp(v, 0.0f, 65535.0f)), gid) + imageStore(uDst, gid, uvec4(clamp(v, 0.0, 65535.0))); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityFastPreviewApply_0x30b231c.comp b/research/phocus_glsl/06_detail_texture/clarityFastPreviewApply_0x30b231c.comp new file mode 100644 index 00000000..89fd4138 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityFastPreviewApply_0x30b231c.comp @@ -0,0 +1,62 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: ec451ea570b0870fb0b16d88ca2ba0ca3b4d5c135696acffaa0d9f070349d659 + * ELF offsets: 0x30b231c + * Symbols: clarityFastPreviewApply_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp image2D; + +layout(rgba16f, binding = 0) readonly uniform image2D uInput; +layout(rgba16f, binding = 1) readonly uniform image2D uHiResMap; // factor map (rgba16f, .r channel) +layout(rgba16f, binding = 2) writeonly uniform image2D uOutput; + +layout(std140, binding = 3) uniform ClarityFastPreviewParams_UBO { + float hiMapScaleX; + float hiMapScaleY; + int offsetX; + int offsetY; + int absRectLeft; // rect.left in absolute image coords (for factor map position fix) + int absRectTop; // rect.top in absolute image coords + int pad0; + int pad1; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 outSize = imageSize(uOutput); + if (gid.x >= outSize.x || gid.y >= outSize.y) return; + + ivec2 srcPos = gid + ivec2(offsetX, offsetY); + vec4 src = imageLoad(uInput, srcPos); + + // Compute position in factor map space using absolute image coordinates. + vec2 fullPos = vec2(srcPos + ivec2(absRectLeft, absRectTop)) + 0.5; + vec2 mapPos = fullPos * vec2(hiMapScaleX, hiMapScaleY); + + // Manual bilinear interpolation on image2D (replaces sampler2D + GL_LINEAR) + ivec2 mapSize = imageSize(uHiResMap); + vec2 texelPos = mapPos - 0.5; // shift to texel center + ivec2 p0 = ivec2(floor(texelPos)); + vec2 frac = texelPos - vec2(p0); + + // Clamp coordinates (equivalent to GL_CLAMP_TO_EDGE) + ivec2 p00 = clamp(p0, ivec2(0), mapSize - 1); + ivec2 p10 = clamp(p0 + ivec2(1,0), ivec2(0), mapSize - 1); + ivec2 p01 = clamp(p0 + ivec2(0,1), ivec2(0), mapSize - 1); + ivec2 p11 = clamp(p0 + ivec2(1,1), ivec2(0), mapSize - 1); + + float f00 = imageLoad(uHiResMap, p00).r; + float f10 = imageLoad(uHiResMap, p10).r; + float f01 = imageLoad(uHiResMap, p01).r; + float f11 = imageLoad(uHiResMap, p11).r; + + float factor = mix(mix(f00, f10, frac.x), mix(f01, f11, frac.x), frac.y); + vec4 result = vec4(src.rgb * factor, src.a); + imageStore(uOutput, gid, result); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityGrayImage4CenterValU16_0x300bd4e.comp b/research/phocus_glsl/06_detail_texture/clarityGrayImage4CenterValU16_0x300bd4e.comp new file mode 100644 index 00000000..7ee9db41 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityGrayImage4CenterValU16_0x300bd4e.comp @@ -0,0 +1,69 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 54c35774225149ef4345604d5dbd9ea8016a8f6e3ddfea8dafda40aa17b5d450 + * ELF offsets: 0x300bd4e + * Symbols: clarityGrayImage4CenterValU16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D uSrc; +layout(rgba16ui, binding = 1) writeonly uniform uimage2D uDst; + +layout(std140, binding = 2) uniform ClarityStretchFactorParams_UBO { + float stretchFactor; + float xGammaHalf; + int wSrc; + int hSrc; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +uvec4 ReadWithPaddingU16(ivec2 gid) { + uvec4 v = imageLoad(uSrc, gid); + if (gid.y >= hSrc) { + ivec2 pos = gid; + pos.y = hSrc - 1; + if (4 * gid.x + 3 >= wSrc) { + int lastx = wSrc - 1; + pos.x = lastx / 4; + v = imageLoad(uSrc, pos); + int idx = lastx & 3; + uint lastVal = v[idx]; + v.w = lastVal; + if (4 * gid.x + 2 >= wSrc) v.z = lastVal; + if (4 * gid.x + 1 >= wSrc) v.y = lastVal; + if (4 * gid.x + 0 >= wSrc) v.x = lastVal; + } else { + v = imageLoad(uSrc, pos); + } + } else if (4 * gid.x + 3 >= wSrc) { + ivec2 pos = gid; + int lastx = wSrc - 1; + pos.x = lastx / 4; + v = imageLoad(uSrc, pos); + int idx = lastx & 3; + uint lastVal = v[idx]; + v.w = lastVal; + if (4 * gid.x + 2 >= wSrc) v.z = lastVal; + if (4 * gid.x + 1 >= wSrc) v.y = lastVal; + if (4 * gid.x + 0 >= wSrc) v.x = lastVal; + } + return v; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 dstSize = imageSize(uDst); + if (gid.x >= dstSize.x || gid.y >= dstSize.y) return; + + uvec4 raw = ReadWithPaddingU16(gid); + // iOS: float4 v = ReadWithPadding(...) → returns v / 65535.0 + vec4 v = vec4(raw) / 65535.0; + // iOS: pow(v * gamma.stretchFactor, gamma.xGamma * 0.5) → * 65535 → ushort + vec4 normalized = pow(v * stretchFactor, vec4(xGammaHalf)); + imageStore(uDst, gid, uvec4(clamp(normalized * 65535.0, 0.0, 65535.0))); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityHRLut_0x3018545.comp b/research/phocus_glsl/06_detail_texture/clarityHRLut_0x3018545.comp new file mode 100644 index 00000000..2d941847 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityHRLut_0x3018545.comp @@ -0,0 +1,43 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: c6ae77a81dd90ba4bd65dbd390ad5e7f025658e36eed95f19a4483189728b65a + * ELF offsets: 0x3018545 + * Symbols: clarityHRLut_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp image2D; +precision highp uimage2D; + +layout(rgba16ui, binding = 0) writeonly uniform uimage2D uDst; + +layout(std140, binding = 1) uniform ClarityLutParams_UBO { + float xGamma; + float centerVal; + float stretchFactor; + int pad; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +float curveHR(float x, float cV) { + const float kMaxHRGamma = 5.0; + cV = cV * 1.2; + cV = clamp(cV, 0.005, 0.995); + if (x > cV) + return 1.0 - pow((1.0 - x) / (1.0 - cV), 1.0 / kMaxHRGamma) * (1.0 - cV); + else + return x; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + if (gid.x >= 256 || gid.y >= 256) return; + + float x = float(gid.x + gid.y * 256) / 65535.0; + // centerVal is in uint16 space from iOS, pass as-is + float result = pow(curveHR(pow(x, 1.0 / xGamma), centerVal / 65535.0), xGamma); + imageStore(uDst, gid, uvec4(uint(result * 65535.0 + 0.5), 0u, 0u, 0u)); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityPackedU16MaxToR32F_0x301ded0.comp b/research/phocus_glsl/06_detail_texture/clarityPackedU16MaxToR32F_0x301ded0.comp new file mode 100644 index 00000000..0b30ea10 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityPackedU16MaxToR32F_0x301ded0.comp @@ -0,0 +1,37 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 18c919f2a855b3727299372c559d2974204d7af412e135e2a4e5d540671d98c0 + * ELF offsets: 0x301ded0 + * Symbols: clarityPackedU16MaxToR32F_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp uimage2D; +precision highp image2D; + +layout(rgba16ui, binding=0) readonly uniform uimage2D uSrc; +layout(r32f, binding=1) writeonly uniform image2D uDst; + +layout(std140, binding=2) uniform ClarityPackedMaxParams_UBO { + int pixW; + int pixH; + int pad0; + int pad1; +}; + +layout(local_size_x=16, local_size_y=16) in; + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + if (gid.x >= imageSize(uDst).x || gid.y >= imageSize(uDst).y) return; + + uvec4 p = imageLoad(uSrc, gid); + int base = gid.x * 4; + // Exclude padding pixels in the last texel column, normalize to [0,1]. + float v0 = (base + 0 < pixW) ? float(p.r) / 65535.0 : 0.0; + float v1 = (base + 1 < pixW) ? float(p.g) / 65535.0 : 0.0; + float v2 = (base + 2 < pixW) ? float(p.b) / 65535.0 : 0.0; + float v3 = (base + 3 < pixW) ? float(p.a) / 65535.0 : 0.0; + imageStore(uDst, gid, vec4(max(max(v0, v1), max(v2, v3)), 0.0, 0.0, 0.0)); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityReduceMaxFinalU16_0x3025b43.comp b/research/phocus_glsl/06_detail_texture/clarityReduceMaxFinalU16_0x3025b43.comp new file mode 100644 index 00000000..ae1ebdff --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityReduceMaxFinalU16_0x3025b43.comp @@ -0,0 +1,22 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: b99c85bb66f9676d006069f148994d40ab48bb4bfba6363d68f1bea39d10d62c + * ELF offsets: 0x3025b43 + * Symbols: clarityReduceMaxFinalU16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp uimage2D; +precision highp image2D; + +layout(r32f, binding=0) readonly uniform image2D uSrc; +layout(rgba16ui, binding=1) writeonly uniform uimage2D uDst; + +layout(local_size_x=1, local_size_y=1) in; + +void main() { + float v = imageLoad(uSrc, ivec2(0, 0)).r; + uint u = uint(clamp(v, 0.0, 1.0) * 65535.0 + 0.5); + imageStore(uDst, ivec2(0, 0), uvec4(u, 0u, 0u, 0u)); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityReduceMax_0x301db79.comp b/research/phocus_glsl/06_detail_texture/clarityReduceMax_0x301db79.comp new file mode 100644 index 00000000..c3228595 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityReduceMax_0x301db79.comp @@ -0,0 +1,34 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: d39ab75d0a0c31220083b5b7dd7532f3918e7bd91c09a7eb482c9ad546043832 + * ELF offsets: 0x301db79 + * Symbols: clarityReduceMax_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp image2D; + +layout(r32f, binding=0) readonly uniform image2D uSrc; +layout(r32f, binding=1) writeonly uniform image2D uDst; + +layout(std140, binding=2) uniform ClarityReduceMaxParams_UBO { + int srcW; + int srcH; + int pad0; + int pad1; +}; + +layout(local_size_x=16, local_size_y=16) in; + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + if (gid.x >= imageSize(uDst).x || gid.y >= imageSize(uDst).y) return; + + ivec2 s = gid * 2; + float v0 = imageLoad(uSrc, ivec2(s.x, s.y)).r; + float v1 = imageLoad(uSrc, ivec2(min(s.x+1, srcW-1), s.y )).r; + float v2 = imageLoad(uSrc, ivec2(s.x, min(s.y+1, srcH-1))).r; + float v3 = imageLoad(uSrc, ivec2(min(s.x+1, srcW-1), min(s.y+1, srcH-1))).r; + imageStore(uDst, gid, vec4(max(max(v0, v1), max(v2, v3)), 0.0, 0.0, 0.0)); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityRgb2Gray4U16_0x301e2b0.comp b/research/phocus_glsl/06_detail_texture/clarityRgb2Gray4U16_0x301e2b0.comp new file mode 100644 index 00000000..f3ec63be --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityRgb2Gray4U16_0x301e2b0.comp @@ -0,0 +1,45 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 914e2b18fb091144567c4ae84d992c382bd7796c43b148b6e0cc25ca78e394f4 + * ELF offsets: 0x301e2b0 + * Symbols: clarityRgb2Gray4U16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp image2D; +precision highp uimage2D; + +layout(rgba16f, binding = 0) readonly uniform image2D uSrc; // RGB input (per-pixel) +layout(rgba16ui, binding = 1) writeonly uniform uimage2D uDst; // PackedUint16 gray output + +layout(local_size_x = 16, local_size_y = 16) in; + +// iOS: ushort Rgb2Gray(ushort4 pix) { int4 scaled = int4(pix) * 21845; +// return (scaled.r + scaled.g + scaled.b) >> 16; } +// This is equivalent to (r + g + b) / 3 in uint16 space, using integer math +// to avoid floating-point precision issues. +uint rgb2grayU16(vec4 pix) { + // Convert from [0,1] float to [0,65535] uint16 space + ivec4 u16 = ivec4(clamp(pix * 65535.0, 0.0, 65535.0)); + // iOS integer math: int4(pix) * 21845 → (scaled.r + scaled.g + scaled.b) >> 16 + // 21845 = floor(65536 / 3), so (a * 21845) >> 16 ~ a / 3 + ivec4 scaled = u16 * 21845; + return uint((scaled.r + scaled.g + scaled.b) >> 16); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 dstSize = imageSize(uDst); + if (gid.x >= dstSize.x || gid.y >= dstSize.y) return; + + // iOS: ushort pix0 = Rgb2Gray(src.read(ushort2(gid.x*4 + 0, gid.y))) + uint g0 = rgb2grayU16(imageLoad(uSrc, ivec2(gid.x * 4 + 0, gid.y))); + uint g1 = rgb2grayU16(imageLoad(uSrc, ivec2(gid.x * 4 + 1, gid.y))); + uint g2 = rgb2grayU16(imageLoad(uSrc, ivec2(gid.x * 4 + 2, gid.y))); + uint g3 = rgb2grayU16(imageLoad(uSrc, ivec2(gid.x * 4 + 3, gid.y))); + + // iOS: dst.write(ushort4(pix0, pix1, pix2, pix3), gid) + imageStore(uDst, gid, uvec4(g0, g1, g2, g3)); +} diff --git a/research/phocus_glsl/06_detail_texture/claritySFLut_0x3078d0e.comp b/research/phocus_glsl/06_detail_texture/claritySFLut_0x3078d0e.comp new file mode 100644 index 00000000..02d66ef6 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/claritySFLut_0x3078d0e.comp @@ -0,0 +1,54 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: e2b02c9c3e8725068a274907ad78184ad82f8710af722a4266e8f8c51943e07b + * ELF offsets: 0x3078d0e + * Symbols: claritySFLut_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp image2D; +precision highp uimage2D; + +layout(rgba16ui, binding = 0) writeonly uniform uimage2D uDst; + +layout(std140, binding = 1) uniform ClarityLutParams_UBO { + float xGamma; + float centerVal; + float stretchFactor; + int pad; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +float curveShadowFillBase(float x) { + const float kMaxShadowfillGamma = 2.0; + if (x >= 0.5) + return x; + else + return 0.5 * pow(x * 2.0, 1.0 / kMaxShadowfillGamma); +} + +float curveShadowFill(float x, float cV) { + cV = clamp(cV, 0.005, 0.995); + float fact = 0.5 / cV; + float ret = curveShadowFillBase(x * fact) / fact; + float endValue = curveShadowFillBase(min(fact, 1.0)) / fact; + float a = max(0.0, 1.0 - endValue) / 65535.0; + if (x * fact < 1.0) + ret += x * a; + else + ret = x; + return clamp(ret, 0.0, 1.0); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + if (gid.x >= 256 || gid.y >= 256) return; + + float x = float(gid.x + gid.y * 256) / 65535.0; + // centerVal is in uint16 space from iOS, pass as-is + float result = pow(curveShadowFill(pow(x, 1.0 / xGamma), centerVal / 65535.0), xGamma); + imageStore(uDst, gid, uvec4(uint(result * 65535.0 + 0.5), 0u, 0u, 0u)); +} diff --git a/research/phocus_glsl/06_detail_texture/claritySubtractColTileU16_0x30a1fbe.comp b/research/phocus_glsl/06_detail_texture/claritySubtractColTileU16_0x30a1fbe.comp new file mode 100644 index 00000000..70454586 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/claritySubtractColTileU16_0x30a1fbe.comp @@ -0,0 +1,91 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 8d16470f554de7df8693c89071c77ac19f5ef17534834471d501cee1ded83566 + * ELF offsets: 0x30a1fbe + * Symbols: claritySubtractColTileU16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D uTemp; // collapsed pyramid col (full image) +layout(rgba16ui, binding = 1) readonly uniform uimage2D uGlobalGauss; // top gaussian (full image) +layout(rgba16ui, binding = 2) readonly uniform uimage2D uLocalGauss; // local gaussian (tile) +layout(rgba16ui, binding = 3) writeonly uniform uimage2D uOut; + +layout(std140, binding = 4) uniform ClaritySubtractColParams_UBO { + int offsetX; + int offsetY; + int maxX; + int maxY; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +// iOS: ushort4 shiftBytes(ushort4 left, ushort4 right, int amount) +ivec4 shiftBytes(ivec4 left, ivec4 right, int amount) { + if (amount == 0) return left; + if (amount == 1 || amount == -3) return ivec4(left.yzw, right.x); + if (amount == 2 || amount == -2) return ivec4(left.zw, right.xy); + if (amount == 3 || amount == -1) return ivec4(left.w, right.xyz); + return left; +} + +// iOS: auto readClamped4(texture2d tex, int2 pos, int2 maxPos) +// texId: 0 = uTemp, 1 = uGlobalGauss +ivec4 readClamped4(int texId, ivec2 pos, ivec2 maxPos) { + ivec2 clampedPos = clamp(pos, ivec2(0), ivec2(maxPos.x / 4, maxPos.y)); + ivec4 res; + if (texId == 0) + res = ivec4(imageLoad(uTemp, clampedPos)); + else + res = ivec4(imageLoad(uGlobalGauss, clampedPos)); + // iOS: res = (pos.x < 0) ? res.xxxx : res + if (pos.x < 0) + res = res.xxxx; + // iOS: int lastX = pos.x*4 + 3; if (lastX > maxPos.x) { switch ... } + int lastX = pos.x * 4 + 3; + if (lastX > maxPos.x) { + int diff = lastX - maxPos.x; + if (diff == 1) res = ivec4(res.xyz, res.z); // xyzz + else if (diff == 2) res = ivec4(res.xy, res.y, res.y); // xyyy + else if (diff == 3) res = res.xxxx; // xxxx + else res = res.wwww; // default + } + return res; +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 dstSize = imageSize(uOut); + if (gid.x >= dstSize.x || gid.y >= dstSize.y) return; + + // iOS: short misalignment = (opts.offsetX) % 4 + int misalignment = offsetX % 4; + + // iOS: int2 rawPos = int2((int)gid.x + opts.offsetX / 4, gid.y + opts.offsetY) + ivec2 rawPos = ivec2(gid.x + offsetX / 4, gid.y + offsetY); + // iOS: if (misalignment < 0) rawPos.x -= 1 + if (misalignment < 0) + rawPos.x -= 1; + + ivec2 maxPos = ivec2(maxX, maxY); + + // iOS: ushort4 temp = readClamped4(texTemp, rawPos, maxPos) + ivec4 temp = readClamped4(0, rawPos, maxPos); + // iOS: ushort4 guassGlobal = readClamped4(texGlobalGauss, rawPos, maxPos) + ivec4 gaussGlobal = readClamped4(1, rawPos, maxPos); + // iOS: ushort4 guassLocal = texLocalGauss.read(gid) + ivec4 gaussLocal = ivec4(imageLoad(uLocalGauss, gid)); + + // iOS: if (misalignment != 0) { ... shift ... } + if (misalignment != 0) { + temp = shiftBytes(temp, readClamped4(0, ivec2(rawPos.x + 1, rawPos.y), maxPos), misalignment); + gaussGlobal = shiftBytes(gaussGlobal, readClamped4(1, ivec2(rawPos.x + 1, rawPos.y), maxPos), misalignment); + } + + // iOS: texOut.write(ushort4(clamp(int4(guassLocal) + int4(temp) - int4(guassGlobal), 0, 65535)), gid) + imageStore(uOut, gid, uvec4(clamp(gaussLocal + temp - gaussGlobal, 0, 65535))); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityUpScaleBlurSubAggU16_0x308a48a.comp b/research/phocus_glsl/06_detail_texture/clarityUpScaleBlurSubAggU16_0x308a48a.comp new file mode 100644 index 00000000..f013b905 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityUpScaleBlurSubAggU16_0x308a48a.comp @@ -0,0 +1,140 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 634bb04af760629a50d330b5e6d8ce621f2cadd6f146a0392ddef5f751d6c1a0 + * ELF offsets: 0x308a48a + * Symbols: clarityUpScaleBlurSubAggU16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D uGauss; +layout(rgba16ui, binding = 1) readonly uniform uimage2D uFullRes; +layout(rgba16ui, binding = 2) readonly uniform uimage2D uHalfRes; +layout(rgba16ui, binding = 3) writeonly uniform uimage2D uDst; +layout(rgba16ui, binding = 4) readonly uniform uimage2D uPrevAgg; + +layout(std140, binding = 5) uniform ClarityAggParams_UBO { + int aggW; + int aggH; + float centerNorm; + float stepNorm; + int blurW; + int blurH; + float ba; + float bb; + float bc; + float be; + float bf; + float bi; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +vec4 readPaddedHalfU16(ivec2 pos, ivec2 pixSize) { + ivec2 maxPos = ivec2((pixSize.x + 3) / 4, pixSize.y) - 1; + vec4 val = vec4(imageLoad(uHalfRes, clamp(pos, ivec2(0), maxPos))); + if (pos.x >= maxPos.x) { + int rem = pixSize.x % 4; + if (rem == 1) val = val.xxxx; + else if (rem == 2) val = vec4(val.x, val.y, val.y, val.y); + else if (rem == 3) val = vec4(val.x, val.y, val.z, val.z); + if (pos.x > maxPos.x) + val = val.wwww; + } + return val; +} + +vec4 combineUpscale(vec4 a, vec4 b, ivec2 pos) { + if ((pos.x & 1) == 1) + return vec4(a.yzw, b.x); + else + return vec4(a.w, b.xyz); +} + +vec4 upScaleBlurU16(ivec2 pos) { + vec4 vs = vec4(0.0); + ivec2 p = pos / 2; + int deltaY1 = 1, deltaY2 = 0; + + if ((pos.y & 1) != 0) { + p.y += 1; + deltaY1 = -1; + deltaY2 = (pos.y < 2) ? 0 : deltaY1; + if (2 * p.y >= blurH) { p.y--; deltaY1 = 0; } + } else if (pos.y == 0) { + deltaY1 = 0; deltaY2 = 1; + } else { + p.y -= 1; + deltaY2 = (pos.y < 2 || pos.y + 2 >= blurH) ? 0 : deltaY1; + } + + ivec2 halfSize = ivec2((blurW + 1) / 2, (blurH + 1) / 2); + + if (pos.x == 0) { + vec4 tb = readPaddedHalfU16(p, halfSize); + vs.x = ba*tb.x + bb*tb.x + bc*tb.y; vs.y = bc*tb.x + bb*tb.x + ba*tb.y; + vs.z = ba*tb.x + bb*tb.y + bc*tb.z; vs.w = bc*tb.x + bb*tb.y + ba*tb.z; + p.y += deltaY1; + tb = readPaddedHalfU16(p, halfSize); + vs.x += bb*tb.x + be*tb.x + bf*tb.y; vs.y += bf*tb.x + be*tb.x + bb*tb.y; + vs.z += bb*tb.x + be*tb.y + bf*tb.z; vs.w += bf*tb.x + be*tb.y + bb*tb.z; + p.y += deltaY2; + tb = readPaddedHalfU16(p, halfSize); + vs.x += bc*tb.x + bf*tb.x + bi*tb.y; vs.y += bi*tb.x + bf*tb.x + bc*tb.y; + vs.z += bc*tb.x + bf*tb.y + bi*tb.z; vs.w += bi*tb.x + bf*tb.y + bc*tb.z; + } else if ((4 * (pos.x + 1) >= blurW) && ((pos.x & 1) == 1)) { + p.x = (pos.x - 1) / 2; + vec4 ta = readPaddedHalfU16(p, halfSize); + vs.x = ba*ta.y + bb*ta.z + bc*ta.w; vs.y = bc*ta.y + bb*ta.z + ba*ta.w; + vs.z = ba*ta.z + bb*ta.w + bc*ta.w; vs.w = bc*ta.z + bb*ta.w + ba*ta.w; + p.y += deltaY1; + ta = readPaddedHalfU16(p, halfSize); + vs.x += bb*ta.y + be*ta.z + bf*ta.w; vs.y += bf*ta.y + be*ta.z + bb*ta.w; + vs.z += bb*ta.z + be*ta.w + bf*ta.w; vs.w += bf*ta.z + be*ta.w + bb*ta.w; + p.y += deltaY2; + ta = readPaddedHalfU16(p, halfSize); + vs.x += bc*ta.y + bf*ta.z + bi*ta.w; vs.y += bi*ta.y + bf*ta.z + bc*ta.w; + vs.z += bc*ta.z + bf*ta.w + bi*ta.w; vs.w += bi*ta.z + bf*ta.w + bc*ta.w; + } else { + p.x = (pos.x - 1) / 2; + vec4 cv = combineUpscale(readPaddedHalfU16(p, halfSize), readPaddedHalfU16(p + ivec2(1, 0), halfSize), pos); + vs.x = dot(vec3(ba, bb, bc), cv.xyz); vs.y = dot(vec3(bc, bb, ba), cv.xyz); + vs.z = dot(vec3(ba, bb, bc), cv.yzw); vs.w = dot(vec3(bc, bb, ba), cv.yzw); + p.y += deltaY1; + cv = combineUpscale(readPaddedHalfU16(p, halfSize), readPaddedHalfU16(p + ivec2(1, 0), halfSize), pos); + vs.x += dot(vec3(bb, be, bf), cv.xyz); vs.y += dot(vec3(bf, be, bb), cv.xyz); + vs.z += dot(vec3(bb, be, bf), cv.yzw); vs.w += dot(vec3(bf, be, bb), cv.yzw); + p.y += deltaY2; + cv = combineUpscale(readPaddedHalfU16(p, halfSize), readPaddedHalfU16(p + ivec2(1, 0), halfSize), pos); + vs.x += dot(vec3(bc, bf, bi), cv.xyz); vs.y += dot(vec3(bi, bf, bc), cv.xyz); + vs.z += dot(vec3(bc, bf, bi), cv.yzw); vs.w += dot(vec3(bi, bf, bc), cv.yzw); + } + + return clamp(vs, 0.0, 65535.0); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 dstSize = imageSize(uDst); + if (gid.x >= dstSize.x || gid.y >= dstSize.y) return; + + // iOS: int4 vs = upScaleBlur4(halfRes, gid, discs.blur) + ivec4 vs = ivec4(upScaleBlurU16(gid)); + // iOS: int4 gauss4 = int4(gauss.read(gid)) + ivec4 gauss4 = ivec4(imageLoad(uGauss, gid)); + // iOS: int4 laplace4 = int4(fullRes.read(gid)) - vs (NOT centered at 32768) + ivec4 laplace4 = ivec4(imageLoad(uFullRes, gid)) - vs; + + // iOS: float4 res4 = float4(laplace4) * (1.0f - min(1.0f, float4(abs(gauss4 - discs.center)) / float4(discs.step))) + // center/step are uint16-scale values (e.g., center=3449, step=3449) + vec4 weight = 1.0 - min(vec4(1.0), abs(vec4(gauss4) - centerNorm) / stepNorm); + ivec4 resi = ivec4(vec4(laplace4) * weight); + + // iOS: int4 prev4 = int4(dst.read(gid)) + ivec4 prev4 = ivec4(imageLoad(uPrevAgg, gid)); + // iOS: dst.write(ushort4(clamp(prev4 + resi, 0, 65535)), gid) + imageStore(uDst, gid, uvec4(clamp(prev4 + resi, 0, 65535))); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityUpScaleBlurSubU16_0x3011f91.comp b/research/phocus_glsl/06_detail_texture/clarityUpScaleBlurSubU16_0x3011f91.comp new file mode 100644 index 00000000..7b5d1124 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityUpScaleBlurSubU16_0x3011f91.comp @@ -0,0 +1,147 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 287d98c06c9498f2acce80018ba202c18849ea0ced91c3b7752762db807a36f4 + * ELF offsets: 0x3011f91 + * Symbols: clarityUpScaleBlurSubU16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D uAux; +layout(rgba16ui, binding = 1) readonly uniform uimage2D uSrc; +layout(rgba16ui, binding = 2) writeonly uniform uimage2D uDst; + +layout(std140, binding = 3) uniform ClarityBlurUpParams_UBO { + int blurW; + int blurH; + float ba; + float bb; + float bc; + float be; + float bf; + float bi; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +// Returns float4 in [0, 65535] +vec4 readPaddedU16(ivec2 pos, ivec2 pixSize) { + ivec2 maxPos = ivec2((pixSize.x + 3) / 4, pixSize.y) - 1; + vec4 val = vec4(imageLoad(uSrc, clamp(pos, ivec2(0), maxPos))); + if (pos.x >= maxPos.x) { + int rem = pixSize.x % 4; + if (rem == 1) val = val.xxxx; + else if (rem == 2) val = vec4(val.x, val.y, val.y, val.y); + else if (rem == 3) val = vec4(val.x, val.y, val.z, val.z); + if (pos.x > maxPos.x) + val = val.wwww; + } + return val; +} + +vec4 combineUpscale(vec4 a, vec4 b, ivec2 pos) { + if ((pos.x & 1) == 1) + return vec4(a.yzw, b.x); + else + return vec4(a.w, b.xyz); +} + +vec4 upScaleBlurU16(ivec2 pos) { + vec4 vs = vec4(0.0); + ivec2 p = pos / 2; + int deltaY1 = 1, deltaY2 = 0; + + if ((pos.y & 1) != 0) { + p.y += 1; + deltaY1 = -1; + deltaY2 = (pos.y < 2) ? 0 : deltaY1; + if (2 * p.y >= blurH) { + p.y--; + deltaY1 = 0; + } + } else if (pos.y == 0) { + deltaY1 = 0; + deltaY2 = 1; + } else { + p.y -= 1; + deltaY2 = (pos.y < 2 || pos.y + 2 >= blurH) ? 0 : deltaY1; + } + + ivec2 halfSize = ivec2((blurW + 1) / 2, (blurH + 1) / 2); + + if (pos.x == 0) { + vec4 tb = readPaddedU16(p, halfSize); + vs.x = ba*tb.x + bb*tb.x + bc*tb.y; + vs.y = bc*tb.x + bb*tb.x + ba*tb.y; + vs.z = ba*tb.x + bb*tb.y + bc*tb.z; + vs.w = bc*tb.x + bb*tb.y + ba*tb.z; + p.y += deltaY1; + tb = readPaddedU16(p, halfSize); + vs.x += bb*tb.x + be*tb.x + bf*tb.y; + vs.y += bf*tb.x + be*tb.x + bb*tb.y; + vs.z += bb*tb.x + be*tb.y + bf*tb.z; + vs.w += bf*tb.x + be*tb.y + bb*tb.z; + p.y += deltaY2; + tb = readPaddedU16(p, halfSize); + vs.x += bc*tb.x + bf*tb.x + bi*tb.y; + vs.y += bi*tb.x + bf*tb.x + bc*tb.y; + vs.z += bc*tb.x + bf*tb.y + bi*tb.z; + vs.w += bi*tb.x + bf*tb.y + bc*tb.z; + } else if ((4 * (pos.x + 1) >= blurW) && ((pos.x & 1) == 1)) { + p.x = (pos.x - 1) / 2; + vec4 ta = readPaddedU16(p, halfSize); + vs.x = ba*ta.y + bb*ta.z + bc*ta.w; + vs.y = bc*ta.y + bb*ta.z + ba*ta.w; + vs.z = ba*ta.z + bb*ta.w + bc*ta.w; + vs.w = bc*ta.z + bb*ta.w + ba*ta.w; + p.y += deltaY1; + ta = readPaddedU16(p, halfSize); + vs.x += bb*ta.y + be*ta.z + bf*ta.w; + vs.y += bf*ta.y + be*ta.z + bb*ta.w; + vs.z += bb*ta.z + be*ta.w + bf*ta.w; + vs.w += bf*ta.z + be*ta.w + bb*ta.w; + p.y += deltaY2; + ta = readPaddedU16(p, halfSize); + vs.x += bc*ta.y + bf*ta.z + bi*ta.w; + vs.y += bi*ta.y + bf*ta.z + bc*ta.w; + vs.z += bc*ta.z + bf*ta.w + bi*ta.w; + vs.w += bi*ta.z + bf*ta.w + bc*ta.w; + } else { + p.x = (pos.x - 1) / 2; + vec4 cv = combineUpscale(readPaddedU16(p, halfSize), readPaddedU16(p + ivec2(1, 0), halfSize), pos); + vs.x = dot(vec3(ba, bb, bc), cv.xyz); + vs.y = dot(vec3(bc, bb, ba), cv.xyz); + vs.z = dot(vec3(ba, bb, bc), cv.yzw); + vs.w = dot(vec3(bc, bb, ba), cv.yzw); + p.y += deltaY1; + cv = combineUpscale(readPaddedU16(p, halfSize), readPaddedU16(p + ivec2(1, 0), halfSize), pos); + vs.x += dot(vec3(bb, be, bf), cv.xyz); + vs.y += dot(vec3(bf, be, bb), cv.xyz); + vs.z += dot(vec3(bb, be, bf), cv.yzw); + vs.w += dot(vec3(bf, be, bb), cv.yzw); + p.y += deltaY2; + cv = combineUpscale(readPaddedU16(p, halfSize), readPaddedU16(p + ivec2(1, 0), halfSize), pos); + vs.x += dot(vec3(bc, bf, bi), cv.xyz); + vs.y += dot(vec3(bi, bf, bc), cv.xyz); + vs.z += dot(vec3(bc, bf, bi), cv.yzw); + vs.w += dot(vec3(bi, bf, bc), cv.yzw); + } + + return clamp(vs, 0.0, 65535.0); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 dstSize = imageSize(uDst); + if (gid.x >= dstSize.x || gid.y >= dstSize.y) return; + + // iOS: int4 v = 32768 + int4(aux.read(gid)) - upScaleBlur4(src, gid, blur); + ivec4 auxVal = ivec4(imageLoad(uAux, gid)); + ivec4 upscaled = ivec4(upScaleBlurU16(gid)); + ivec4 v = ivec4(32768) + auxVal - upscaled; + // iOS: dst.write(ushort4(clamp(v, 0, 65535)), gid) + imageStore(uDst, gid, uvec4(clamp(v, 0, 65535))); +} diff --git a/research/phocus_glsl/06_detail_texture/clarityUpScaleBlurU16_0x3042806.comp b/research/phocus_glsl/06_detail_texture/clarityUpScaleBlurU16_0x3042806.comp new file mode 100644 index 00000000..23e267eb --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/clarityUpScaleBlurU16_0x3042806.comp @@ -0,0 +1,125 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: b35bf0d4ebfddaa394164ed49a6b1edde47e76976f1006eae1a95e4fe002cbc7 + * ELF offsets: 0x3042806 + * Symbols: clarityUpScaleBlurU16_computeShaderSource + */ + +#version 310 es +precision highp float; +precision highp int; +precision highp uimage2D; + +layout(rgba16ui, binding = 0) readonly uniform uimage2D uSrc; // half-res source +layout(rgba16ui, binding = 1) readonly uniform uimage2D uPrev; // previous accumulation (full-res) +layout(rgba16ui, binding = 2) writeonly uniform uimage2D uDst; // output (full-res) + +layout(std140, binding = 3) uniform ClarityBlurUpParams_UBO { + int blurW; + int blurH; + float ba; + float bb; + float bc; + float be; + float bf; + float bi; +}; + +layout(local_size_x = 16, local_size_y = 16) in; + +// Returns float4 in [0, 65535] — reads from uSrc +vec4 readPaddedU16(ivec2 pos, ivec2 pixSize) { + ivec2 maxPos = ivec2((pixSize.x + 3) / 4, pixSize.y) - 1; + vec4 val = vec4(imageLoad(uSrc, clamp(pos, ivec2(0), maxPos))); + if (pos.x >= maxPos.x) { + int rem = pixSize.x % 4; + if (rem == 1) val = val.xxxx; + else if (rem == 2) val = vec4(val.x, val.y, val.y, val.y); + else if (rem == 3) val = vec4(val.x, val.y, val.z, val.z); + if (pos.x > maxPos.x) + val = val.wwww; + } + return val; +} + +vec4 combineUpscale(vec4 a, vec4 b, ivec2 pos) { + if ((pos.x & 1) == 1) + return vec4(a.yzw, b.x); + else + return vec4(a.w, b.xyz); +} + +vec4 upScaleBlurU16(ivec2 pos) { + vec4 vs = vec4(0.0); + ivec2 p = pos / 2; + int deltaY1 = 1, deltaY2 = 0; + + if ((pos.y & 1) != 0) { + p.y += 1; + deltaY1 = -1; + deltaY2 = (pos.y < 2) ? 0 : deltaY1; + if (2 * p.y >= blurH) { p.y--; deltaY1 = 0; } + } else if (pos.y == 0) { + deltaY1 = 0; deltaY2 = 1; + } else { + p.y -= 1; + deltaY2 = (pos.y < 2 || pos.y + 2 >= blurH) ? 0 : deltaY1; + } + + ivec2 halfSize = ivec2((blurW + 1) / 2, (blurH + 1) / 2); + + if (pos.x == 0) { + vec4 tb = readPaddedU16(p, halfSize); + vs.x = ba*tb.x + bb*tb.x + bc*tb.y; vs.y = bc*tb.x + bb*tb.x + ba*tb.y; + vs.z = ba*tb.x + bb*tb.y + bc*tb.z; vs.w = bc*tb.x + bb*tb.y + ba*tb.z; + p.y += deltaY1; + tb = readPaddedU16(p, halfSize); + vs.x += bb*tb.x + be*tb.x + bf*tb.y; vs.y += bf*tb.x + be*tb.x + bb*tb.y; + vs.z += bb*tb.x + be*tb.y + bf*tb.z; vs.w += bf*tb.x + be*tb.y + bb*tb.z; + p.y += deltaY2; + tb = readPaddedU16(p, halfSize); + vs.x += bc*tb.x + bf*tb.x + bi*tb.y; vs.y += bi*tb.x + bf*tb.x + bc*tb.y; + vs.z += bc*tb.x + bf*tb.y + bi*tb.z; vs.w += bi*tb.x + bf*tb.y + bc*tb.z; + } else if ((4 * (pos.x + 1) >= blurW) && ((pos.x & 1) == 1)) { + p.x = (pos.x - 1) / 2; + vec4 ta = readPaddedU16(p, halfSize); + vs.x = ba*ta.y + bb*ta.z + bc*ta.w; vs.y = bc*ta.y + bb*ta.z + ba*ta.w; + vs.z = ba*ta.z + bb*ta.w + bc*ta.w; vs.w = bc*ta.z + bb*ta.w + ba*ta.w; + p.y += deltaY1; + ta = readPaddedU16(p, halfSize); + vs.x += bb*ta.y + be*ta.z + bf*ta.w; vs.y += bf*ta.y + be*ta.z + bb*ta.w; + vs.z += bb*ta.z + be*ta.w + bf*ta.w; vs.w += bf*ta.z + be*ta.w + bb*ta.w; + p.y += deltaY2; + ta = readPaddedU16(p, halfSize); + vs.x += bc*ta.y + bf*ta.z + bi*ta.w; vs.y += bi*ta.y + bf*ta.z + bc*ta.w; + vs.z += bc*ta.z + bf*ta.w + bi*ta.w; vs.w += bi*ta.z + bf*ta.w + bc*ta.w; + } else { + p.x = (pos.x - 1) / 2; + vec4 cv = combineUpscale(readPaddedU16(p, halfSize), readPaddedU16(p + ivec2(1, 0), halfSize), pos); + vs.x = dot(vec3(ba, bb, bc), cv.xyz); vs.y = dot(vec3(bc, bb, ba), cv.xyz); + vs.z = dot(vec3(ba, bb, bc), cv.yzw); vs.w = dot(vec3(bc, bb, ba), cv.yzw); + p.y += deltaY1; + cv = combineUpscale(readPaddedU16(p, halfSize), readPaddedU16(p + ivec2(1, 0), halfSize), pos); + vs.x += dot(vec3(bb, be, bf), cv.xyz); vs.y += dot(vec3(bf, be, bb), cv.xyz); + vs.z += dot(vec3(bb, be, bf), cv.yzw); vs.w += dot(vec3(bf, be, bb), cv.yzw); + p.y += deltaY2; + cv = combineUpscale(readPaddedU16(p, halfSize), readPaddedU16(p + ivec2(1, 0), halfSize), pos); + vs.x += dot(vec3(bc, bf, bi), cv.xyz); vs.y += dot(vec3(bi, bf, bc), cv.xyz); + vs.z += dot(vec3(bc, bf, bi), cv.yzw); vs.w += dot(vec3(bi, bf, bc), cv.yzw); + } + + return clamp(vs, 0.0, 65535.0); +} + +void main() { + ivec2 gid = ivec2(gl_GlobalInvocationID.xy); + ivec2 dstSize = imageSize(uDst); + if (gid.x >= dstSize.x || gid.y >= dstSize.y) return; + + // iOS: int4 prev = int4(dst.read(gid)) + ivec4 prev = ivec4(imageLoad(uPrev, gid)); + // iOS: int4 vs = upScaleBlur4(src, gid, blur) + ivec4 vs = ivec4(upScaleBlurU16(gid)); + // iOS: dst.write(ushort4(clamp(prev + vs - 32768, 0, 65535)), gid) + imageStore(uDst, gid, uvec4(clamp(prev + vs - 32768, 0, 65535))); +} diff --git a/research/phocus_glsl/06_detail_texture/create_film_grain_0x30881be.frag b/research/phocus_glsl/06_detail_texture/create_film_grain_0x30881be.frag new file mode 100644 index 00000000..b906eb4f --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/create_film_grain_0x30881be.frag @@ -0,0 +1,118 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 9312a458283d0b188770711e68a03cbb84c9ee17851521bfade82007f52f9460 + * ELF offsets: 0x30881be + * Symbols: create_film_grain_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp int; +precision highp sampler3D; + +out vec4 FragColor; + +layout(std140) uniform GrainsParam { + ivec2 offset; // 8 + int color; // 4 + float multiplier; // 4 + // ---- 16 + float resolution; + float grainOffset; // in 65535-domain + float grainScale; // in 65535-domain + float blendAmount; // unused here + // ---- 32 + float zoom; + float _pad0; float _pad1; float _pad2; +} opts; + +uniform sampler3D uInputTexture0; // randTex0 (R32F) +uniform sampler3D uInputTexture1; // randTex1 (R32F) +uniform sampler3D uInputTexture2; // randTex2 (R32F) + +const float kMaxRange = 65535.0; +const float kHalfMaxRange = 32767.0; + +vec3 RandomT(vec3 s) { + ivec3 dim0 = textureSize(uInputTexture0, 0); + ivec3 dim1 = textureSize(uInputTexture1, 0); + ivec3 dim2 = textureSize(uInputTexture2, 0); + + ivec3 i = ivec3(floor(s)); + + ivec3 x0 = (i % dim0 + dim0) % dim0; + ivec3 x1 = (i % dim1 + dim1) % dim1; + ivec3 x2 = (i % dim2 + dim2) % dim2; + + float r0 = texelFetch(uInputTexture0, x0, 0).r; + float r1 = texelFetch(uInputTexture1, x1, 0).r; + float r2 = texelFetch(uInputTexture2, x2, 0).r; + + uvec3 fr = uvec3(vec3(kHalfMaxRange + kMaxRange * r0, + kHalfMaxRange + kMaxRange * r1, + kHalfMaxRange + kMaxRange * r2)); + + uvec3 ir = uvec3(fr.y ^ fr.z, fr.x ^ fr.z, fr.x ^ fr.y); + return (vec3(ir) - kHalfMaxRange) / kMaxRange; // ~[-0.5..0.5] +} + +float Simplex(vec3 p) { + const float F3 = 1.0/3.0; + const float G3 = 1.0/6.0; + + float dotp = dot(p, vec3(F3)); + vec3 s = floor(p + dotp); + vec3 x = p - s + dot(s, vec3(G3)); + + vec3 i1, i2; + if (x.x >= x.y) { + if (x.y >= x.z) { i1=vec3(1,0,0); i2=vec3(1,1,0); } + else if (x.x >= x.z) { i1=vec3(1,0,0); i2=vec3(1,0,1); } + else { i1=vec3(0,0,1); i2=vec3(1,0,1); } + } else { + if (x.y < x.z) { i1=vec3(0,0,1); i2=vec3(0,1,1); } + else if (x.x < x.z) { i1=vec3(0,1,0); i2=vec3(0,1,1); } + else { i1=vec3(0,1,0); i2=vec3(1,1,0); } + } + + vec3 x1 = x - i1 + G3; + vec3 x2 = x - i2 + 2.0*G3; + vec3 x3 = x - 1.0 + 3.0*G3; + + vec4 wRaw = vec4(dot(x,x), dot(x1,x1), dot(x2,x2), dot(x3,x3)); + vec4 w = max(vec4(0.6) - wRaw, 0.0); + + vec4 w2 = w*w; + vec4 w4 = w2*w2; + + vec4 d = vec4(dot(RandomT(s), x), + dot(RandomT(s+i1), x1), + dot(RandomT(s+i2), x2), + dot(RandomT(s+1.0), x3)); + + return dot(d * w4, vec4(52.0)); +} + +void main() { + float safeZoom = (opts.zoom == 0.0) ? 1.0 : opts.zoom; + float safeMul = (opts.multiplier == 0.0) ? 1.0 : opts.multiplier; + + vec2 gid = floor(gl_FragCoord.xy); + vec2 pos = (gid / safeZoom + vec2(opts.offset)) * opts.resolution / safeMul; + + float n0 = Simplex(vec3(pos, 0.0)); + vec3 noise = vec3(n0); + + if (opts.color > 0) { + float blend = min(float(opts.color), 20.0) / 20.0; + float n1 = Simplex(vec3(pos, 1.0)); + float n2 = Simplex(vec3(pos, 2.0)); + noise.r = mix(n0, n1, blend); + noise.b = mix(n0, n2, blend); + } + + vec3 grain65535 = opts.grainScale * noise + opts.grainOffset; + vec3 grain01 = clamp(grain65535 / kMaxRange, 0.0, 1.0); + + FragColor = vec4(grain01, 1.0); +} diff --git a/research/phocus_glsl/06_detail_texture/create_film_grain_blend_0x30080d5.frag b/research/phocus_glsl/06_detail_texture/create_film_grain_blend_0x30080d5.frag new file mode 100644 index 00000000..2ccaf954 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/create_film_grain_blend_0x30080d5.frag @@ -0,0 +1,109 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 7e1601b076fb3e2aa1b3dcf0a77dc7b6ae8555136d2a6864cdee1bfd931ec68d + * ELF offsets: 0x30080d5 + * Symbols: create_film_grain_blend_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler3D; + +out vec4 FragColor; + +layout(std140) uniform GrainsParam { + ivec2 offset; + int color; + float multiplier; + float resolution; + float grainOffset; + float grainScale; + float blendAmount; + float zoom; + float _pad0; float _pad1; float _pad2; +} opts; + +uniform sampler2D uInputTexture0; // input image 0..1 +uniform sampler3D uRandTexture0; +uniform sampler3D uRandTexture1; +uniform sampler3D uRandTexture2; + +const float kMaxRange = 65535.0; +const float kHalfMaxRange = 32767.0; + +vec3 RandomT(vec3 s) { + ivec3 dim0 = textureSize(uRandTexture0, 0); + ivec3 dim1 = textureSize(uRandTexture1, 0); + ivec3 dim2 = textureSize(uRandTexture2, 0); + + ivec3 i = ivec3(floor(s)); + ivec3 x0 = (i % dim0 + dim0) % dim0; + ivec3 x1 = (i % dim1 + dim1) % dim1; + ivec3 x2 = (i % dim2 + dim2) % dim2; + + float r0 = texelFetch(uRandTexture0, x0, 0).r; + float r1 = texelFetch(uRandTexture1, x1, 0).r; + float r2 = texelFetch(uRandTexture2, x2, 0).r; + + uvec3 fr = uvec3(vec3(kHalfMaxRange + kMaxRange*r0, + kHalfMaxRange + kMaxRange*r1, + kHalfMaxRange + kMaxRange*r2)); + uvec3 ir = uvec3(fr.y ^ fr.z, fr.x ^ fr.z, fr.x ^ fr.y); + return (vec3(ir) - kHalfMaxRange) / kMaxRange; +} + +float Simplex(vec3 p) { + const float F3=1.0/3.0, G3=1.0/6.0; + float dotp = dot(p, vec3(F3)); + vec3 s = floor(p + dotp); + vec3 x = p - s + dot(s, vec3(G3)); + + vec3 i1,i2; + if (x.x >= x.y) { + if (x.y >= x.z) { i1=vec3(1,0,0); i2=vec3(1,1,0); } + else if (x.x >= x.z) { i1=vec3(1,0,0); i2=vec3(1,0,1); } + else { i1=vec3(0,0,1); i2=vec3(1,0,1); } + } else { + if (x.y < x.z) { i1=vec3(0,0,1); i2=vec3(0,1,1); } + else if (x.x < x.z) { i1=vec3(0,1,0); i2=vec3(0,1,1); } + else { i1=vec3(0,1,0); i2=vec3(1,1,0); } + } + + vec3 x1 = x - i1 + G3; + vec3 x2 = x - i2 + 2.0*G3; + vec3 x3 = x - 1.0 + 3.0*G3; + + vec4 w = max(vec4(0.6) - vec4(dot(x,x), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0); + vec4 w2=w*w, w4=w2*w2; + + vec4 d = vec4(dot(RandomT(s),x), + dot(RandomT(s+i1),x1), + dot(RandomT(s+i2),x2), + dot(RandomT(s+1.0),x3)); + + return dot(d*w4, vec4(52.0)); +} + +void main() { + ivec2 gid = ivec2(gl_FragCoord.xy); + + float safeZoom = (opts.zoom == 0.0) ? 1.0 : opts.zoom; + float safeMul = (opts.multiplier == 0.0) ? 1.0 : opts.multiplier; + + vec2 pos = (vec2(gid) / safeZoom + vec2(opts.offset)) * opts.resolution / safeMul; + + float n0 = Simplex(vec3(pos, 0.0)); + vec3 noise = vec3(n0); + if (opts.color > 0) { + float blend = min(float(opts.color), 20.0) / 20.0; + noise.r = mix(n0, Simplex(vec3(pos, 1.0)), blend); + noise.b = mix(n0, Simplex(vec3(pos, 2.0)), blend); + } + + vec3 grain01 = clamp((opts.grainScale * noise + opts.grainOffset) / kMaxRange, 0.0, 1.0); + vec4 inPix = texelFetch(uInputTexture0, gid, 0); + + FragColor = vec4(mix(inPix.rgb, grain01, opts.blendAmount), inPix.a); +} diff --git a/research/phocus_glsl/06_detail_texture/highRes_0x300594b.frag b/research/phocus_glsl/06_detail_texture/highRes_0x300594b.frag new file mode 100644 index 00000000..a2ddedd9 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/highRes_0x300594b.frag @@ -0,0 +1,22 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 39b941a0ef0e16ff4cf5231186f633cf3d1a21f5c496012c87ee2fb9073b2528 + * ELF offsets: 0x300594b + * Symbols: highRes_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform float uGain; + +void main() { + vec4 pixelColor = texture(uInputTexture0, TexCoord); + pixelColor.rgb *= uGain; + FragColor = pixelColor; +} diff --git a/research/phocus_glsl/06_detail_texture/highRes_0x30a3c90.frag b/research/phocus_glsl/06_detail_texture/highRes_0x30a3c90.frag new file mode 100644 index 00000000..5676ada8 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/highRes_0x30a3c90.frag @@ -0,0 +1,22 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: d43e6aa98922e4a70817554264c0ec3a782bccc2f7ee86eea4d6b2d01b069610 + * ELF offsets: 0x30a3c90 + * Symbols: highResShader + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D inputTexture; +uniform float gain; + +void main() { + vec4 pixelColor = texture(inputTexture, TexCoord); + pixelColor.rgb *= gain; + FragColor = pixelColor; +} diff --git a/research/phocus_glsl/06_detail_texture/unsharpMask_0x300e6ad.frag b/research/phocus_glsl/06_detail_texture/unsharpMask_0x300e6ad.frag new file mode 100644 index 00000000..29941c56 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/unsharpMask_0x300e6ad.frag @@ -0,0 +1,136 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 97a3f91b9d73967ef8a151f9682d7ea985f95daa0f17389816e0aebcd40f95ad + * ELF offsets: 0x300e6ad + * Symbols: unsharpMask_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; // Source +uniform sampler2D uInputTexture1; // Temp (Vertical Blurred) + +layout(std140) uniform ShaderParams { + vec4 weights0123; + float weight4; + float noiseLimit; + float darkLimit; + float sharpenAmount; + float grainScale; + float blendAmount; + float hdrScale; + int marginX; + int marginY; + float padding1; + float padding2; + float padding3; +}; + +const vec3 kYCC = vec3(0.299, 0.587, 0.114); +const float kSharpenValueRange = 16384.0; + +float CalcNoise(float noiseLimit, float x) { + float noiseLim = floor(noiseLimit); + float noiseRange = floor(noiseLim / 4.0); + + if (noiseRange < 128.0) { + noiseRange = 128.0; + } + float i = x * kSharpenValueRange; + float val = (i - (noiseLim - noiseRange)) / noiseRange; + + return clamp(val, 0.0, 1.0); +} + +float CalcAmount(float amount, float darkLimit, float x, float maxRange1) { + float maxRange0 = maxRange1 > 1.0 ? maxRange1 - 1.0 : 1.0; + if (amount <= 0.0) { + return amount; + } + + float scale = (amount + 100.0) / maxRange1; + float X1 = min(darkLimit, maxRange0); + float Y1 = (100.0 * kSharpenValueRange) / (amount + 100.0); + Y1 = clamp(Y1, 1000.0, 10000.0) / kSharpenValueRange * maxRange1; + float dy = 3.0; + + if (x < X1) { + float loA = (dy * X1 - Y1) / (X1 * X1); + float loB = dy - (2.0 * dy * X1 - 2.0 * Y1) / X1; + + float tmp = loA * x * x + loB * x; + + if (tmp > 0.0 && tmp < maxRange1) { + return tmp * scale - 100.0; + } else { + return -100.0; + } + } else if (x < maxRange1) { + float negX1 = maxRange1 - X1; + + float hiA = ((maxRange1 - Y1) - dy * negX1) / (negX1 * negX1); + + float xDiff = x - X1; + + float tmp = hiA * xDiff * xDiff + dy * xDiff + Y1; + + if (tmp > 0.0 && tmp < maxRange1) { + return tmp * scale - 100.0; + } else { + return amount; + } + } else { + return amount; + } +} + +float CalcUsmFactor(float gray, float blurred) { + float normDarkLimit = darkLimit / grainScale; + float local = 0.0; + float rawAmount = CalcAmount(sharpenAmount, normDarkLimit, gray * hdrScale, 1.0); + float amount = clamp(rawAmount + local, 0.0, 1000.0) / 100.0; + + float diff = gray - blurred; + float noise = CalcNoise(noiseLimit, abs(diff) * hdrScale); + return amount * noise * diff; +} + +void main() { + ivec2 fragCoord = ivec2(gl_FragCoord.xy); + + ivec2 srcCoord = fragCoord + ivec2(marginX, marginY); + ivec2 tempCoordCenter = fragCoord + ivec2(marginX, 0); + + float blurredTotal = 0.0; + float totalWeight = 0.0; + float w[5]; + w[0] = weights0123.x; w[1] = weights0123.y; w[2] = weights0123.z; + w[3] = weights0123.w; w[4] = weight4; + + for (int x = -4; x <= 4; x++) { + ivec2 sampleCoord = tempCoordCenter + ivec2(x, 0); + float val = texelFetch(uInputTexture1, sampleCoord, 0).r; + float weight = w[abs(x)]; + if (val > 0.0) { + blurredTotal += val * weight; + totalWeight += weight; + } + } + + if (totalWeight > 0.0) { + blurredTotal /= totalWeight; + } + + vec4 centerColor = texelFetch(uInputTexture0, srcCoord, 0); + float gray = dot(centerColor.rgb, kYCC); + + float usmFactor = CalcUsmFactor(gray, blurredTotal); + + vec3 finalRGB = centerColor.rgb + usmFactor; + finalRGB = clamp(finalRGB, 0.0, 1.0); + + FragColor = vec4(finalRGB, centerColor.a); +} diff --git a/research/phocus_glsl/06_detail_texture/unsharpMask_blend_0x3015512.frag b/research/phocus_glsl/06_detail_texture/unsharpMask_blend_0x3015512.frag new file mode 100644 index 00000000..96ef22ad --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/unsharpMask_blend_0x3015512.frag @@ -0,0 +1,130 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 56d92138369c752b7f33e32596e8e89b847aca6c8d34edd223aa24b03c2da76a + * ELF offsets: 0x3015512 + * Symbols: unsharpMask_blend_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp int; +precision highp sampler2D; + +out vec4 FragColor; + +layout(std140) uniform ShaderParams { + vec4 weights0123; + float weight4; + float noiseLimit; + float darkLimit; + float sharpenAmount; + float grainScale; // in 65535-domain units (like Metal) + float blendAmount; + float hdrScale; + int marginX; + int marginY; + float padding1; + float padding2; + float padding3; +} opts; + +uniform sampler2D uInputTexture0; // TextureUsm (blurred 1-channel stored in .r, 0..1) +uniform sampler2D uInputTexture1; // TextureGrain/Source (0..1 rgb) +uniform sampler2D uInputTexture2; // TextureResult/Background (0..1 rgb) + +const float kMaxRange = 65535.0; +const float kSharpenValueRange = 16384.0; + +float getWeight(int i) { + if (i == 0) return opts.weights0123.x; + if (i == 1) return opts.weights0123.y; + if (i == 2) return opts.weights0123.z; + if (i == 3) return opts.weights0123.w; + return opts.weight4; +} + +float CalcNoise(float nLimit, float x) { + float noiseLim = floor(nLimit); + float noiseRange = floor(noiseLim / 4.0); + if (noiseRange < 128.0) noiseRange = 128.0; + + float i = x * kSharpenValueRange; + float val = (i - (noiseLim - noiseRange)) / noiseRange; + return clamp(val, 0.0, 1.0); +} + +float CalcAmount(float amount, float dLimit, float x, float maxRange1) { + float maxRange0 = maxRange1 > 1.0 ? maxRange1 - 1.0 : 1.0; + if (amount <= 0.0) return amount; + + float scale = (amount + 100.0) / maxRange1; + float X1 = min(dLimit, maxRange0); + float Y1 = (100.0 * kSharpenValueRange) / (amount + 100.0); + Y1 = clamp(Y1, 1000.0, 10000.0) / kSharpenValueRange * maxRange1; + + float dy = 3.0; + if (x < X1) { + float loA = (dy*X1 - Y1) / (X1*X1); + float loB = dy - (2.0*dy*X1 - 2.0*Y1) / X1; + float tmp = loA*x*x + loB*x; + return (tmp > 0.0 && tmp < maxRange1) ? tmp*scale - 100.0 : -100.0; + } else if (x < maxRange1) { + float negX1 = maxRange1 - X1; + float hiA = ((maxRange1 - Y1) - dy*negX1) / (negX1*negX1); + float xDiff = x - X1; + float tmp = hiA*xDiff*xDiff + dy*xDiff + Y1; + return (tmp > 0.0 && tmp < maxRange1) ? tmp*scale - 100.0 : amount; + } + return amount; +} + +float UsmFactor(float value01, float blurred01) { + // map to "ushort domain" + float valueU = value01 * kMaxRange; + float blurU = blurred01 * kMaxRange; + + // normalize by grainScale (which is in ushort-domain) + float v = valueU / max(opts.grainScale, 1e-6); + float b = blurU / max(opts.grainScale, 1e-6); + + float darkLimN = opts.darkLimit / max(opts.grainScale, 1e-6); + + float amountRaw = CalcAmount(opts.sharpenAmount, darkLimN, v * opts.hdrScale, 1.0); + float amount = clamp(amountRaw, 0.0, 1000.0) / 100.0; + + float diff = v - b; + float noise = CalcNoise(opts.noiseLimit, abs(diff) * opts.hdrScale); + + float factorN = amount * noise * diff; // in "normalized" domain + float factorU = factorN * opts.grainScale; // back to ushort-domain delta + return factorU / kMaxRange; // return as 0..1 delta +} + +void main() { + ivec2 gid = ivec2(gl_FragCoord.xy); + + // 1) horizontal blur combine (uInputTexture0 contains blurred line samples in .r, 0..1) + float blurredSum = 0.0; + float weightSum = 0.0; + ivec2 centerCoord = gid + ivec2(opts.marginX, 0); + + for (int x = -4; x <= 4; x++) { + float v = texelFetch(uInputTexture0, centerCoord + ivec2(x, 0), 0).r; + float w = getWeight(abs(x)); + if (v != 0.0) weightSum += w; + blurredSum += v * w; + } + float blurred = (weightSum > 0.0) ? (blurredSum / weightSum) : 0.0; + + // 2) center pixel + vec4 center = texelFetch(uInputTexture1, gid + ivec2(opts.marginX, opts.marginY), 0); + float gray = dot(center.rgb, vec3(0.299, 0.587, 0.114)); + + // 3) USM + float usm = UsmFactor(gray, blurred); + vec3 sharp = clamp(center.rgb + usm, 0.0, 1.0); + + // 4) blend with background + vec4 bg = texelFetch(uInputTexture2, gid, 0); + FragColor = vec4(mix(bg.rgb, sharp, opts.blendAmount), center.a); +} diff --git a/research/phocus_glsl/06_detail_texture/unsharpMask_ver_0x2ff9bfb.frag b/research/phocus_glsl/06_detail_texture/unsharpMask_ver_0x2ff9bfb.frag new file mode 100644 index 00000000..f8ab9cc3 --- /dev/null +++ b/research/phocus_glsl/06_detail_texture/unsharpMask_ver_0x2ff9bfb.frag @@ -0,0 +1,74 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: c868449deef611e5f8a422c002f45d7af1884f8a49c6e911ee974588ca423bf8 + * ELF offsets: 0x2ff9bfb + * Symbols: unsharpMask_ver_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; // TextureIn (SrcRect Size) + +layout(std140) uniform ShaderParams { + vec4 weights0123; + float weight4; + float noiseLimit; + float darkLimit; + float sharpenAmount; + float grainScale; + float blendAmount; + float hdrScale; + int marginX; + int marginY; + float padding1; + float padding2; + float padding3; +}; + +const vec3 kYCC = vec3(0.299, 0.587, 0.114); + +float PixelCastNoScale(float value) { + float clamped = clamp(value, 0.0, 1.0); + float quantized = round(clamped * 65535.0) / 65535.0; + + return quantized; +} + +void main() { + ivec2 fragCoord = ivec2(gl_FragCoord.xy); + + ivec2 inputCenterCoord = fragCoord + ivec2(0, marginY); + + float blurredLum = 0.0; + float totalWeight = 0.0; + float w[5]; + w[0] = weights0123.x; w[1] = weights0123.y; w[2] = weights0123.z; + w[3] = weights0123.w; w[4] = weight4; + + for (int y = -4; y <= 4; y++) { + ivec2 sampleCoord = inputCenterCoord + ivec2(0, y); + + vec3 rgb = texelFetch(uInputTexture0, sampleCoord, 0).rgb; + float lum = dot(rgb, kYCC); + float weight = w[abs(y)]; + + if (any(notEqual(rgb, vec3(0.0)))) { + totalWeight += weight; + } + + blurredLum += lum * weight; + } + + if (totalWeight > 0.0) { + blurredLum /= totalWeight; + } else { + blurredLum = 0.0; + } + + float finalVal = PixelCastNoScale(blurredLum); + + FragColor = vec4(finalVal, 0.0, 0.0, 1.0); +} diff --git a/research/phocus_glsl/07_hdr_ultrahdr/CalculateGainMap_0x3007808.frag b/research/phocus_glsl/07_hdr_ultrahdr/CalculateGainMap_0x3007808.frag new file mode 100644 index 00000000..d6f03517 --- /dev/null +++ b/research/phocus_glsl/07_hdr_ultrahdr/CalculateGainMap_0x3007808.frag @@ -0,0 +1,77 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 91720a36f5ddf2e5682998f88b0e7b64a67bbd938b901c3aef332ec5e4c73b81 + * ELF offsets: 0x3007808 + * Symbols: CalculateGainMap_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +// Constants matching Metal implementation +const float kGammaHasselbladRgb = 2.19921875; +const float kHDRMaxGain = 49.26108374; // kHDRMaxGain +const float kHasselbladHdrRgbLimit = 5.8829245141; // kHasselbladHdrRgbLimit +const float kLStarEpsilon = 0.008856; +const float kLStarKappa = 903.3; +const float kCMSRGBvOffset = 0.055; +const float kCMSRGBvScale = 1.055; +const float kCMSRGBvGamma = 2.4; +const float kCMSRGBvDiv = 12.92; +const float kCMSRGBvLim = 0.04045; + +uniform sampler2D uInputTexture0; // HDR Texture +uniform sampler2D uInputTexture1; // SDR Texture (Cropped) +uniform float uMinGain; +uniform float uMaxGain; +uniform float uOffset; +uniform ivec2 uInMargin; +uniform mat3 uColorMatrix; +uniform int uIsLStar; + +out vec4 FragColor; + +vec3 sRgb2linear(vec3 rgb) { + vec3 a = pow((rgb + kCMSRGBvOffset) / kCMSRGBvScale, vec3(kCMSRGBvGamma)); + vec3 b = rgb / kCMSRGBvDiv; + return mix(a, b, lessThanEqual(rgb, vec3(kCMSRGBvLim))); +} + +vec3 HasselbladCompanding2Linear(vec3 t, int isLStar) { + if (isLStar == 1) { + float eps = kLStarEpsilon; + float kap = kLStarKappa; + vec3 vLo = t * 100.0 / kap; + vec3 vHi = pow((t + 0.16) / 1.16, vec3(3.0)); + return mix(vHi, vLo, lessThanEqual(t, vec3(eps))); + } else { + return pow(t, vec3(kGammaHasselbladRgb)); + } +} + +void main() { + ivec2 gid = ivec2(gl_FragCoord.xy); + ivec2 hdrPos = gid + uInMargin; + ivec2 sdrPos = gid; + + vec3 rawHdr = texelFetch(uInputTexture0, hdrPos, 0).rgb; + vec3 rawSdr = texelFetch(uInputTexture1, sdrPos, 0).rgb; + + vec3 hdrHassGained = rawHdr * kHasselbladHdrRgbLimit; + vec3 hdrHassLinear = HasselbladCompanding2Linear(hdrHassGained, uIsLStar); + vec3 hdrP3Linear = uColorMatrix * hdrHassLinear; + + float hdrApplyGainMapMax = pow(2.0, uMaxGain); + hdrP3Linear = clamp(hdrP3Linear, vec3(0.0), vec3(hdrApplyGainMapMax)); + + vec3 sdrP3Liner = sRgb2linear(rawSdr); + + vec3 gain = log2((hdrP3Linear + uOffset) / (sdrP3Liner + uOffset)); + + float gainRange = uMaxGain - uMinGain; + vec3 normalized = (gain - vec3(uMinGain)) / vec3(gainRange); +// normalized = clamp(normalized, 0.0, 1.0); + + FragColor = vec4(normalized, 1.0); +} diff --git a/research/phocus_glsl/07_hdr_ultrahdr/applyhdrgainmapyuv_0x30a1626.frag b/research/phocus_glsl/07_hdr_ultrahdr/applyhdrgainmapyuv_0x30a1626.frag new file mode 100644 index 00000000..ebcea488 --- /dev/null +++ b/research/phocus_glsl/07_hdr_ultrahdr/applyhdrgainmapyuv_0x30a1626.frag @@ -0,0 +1,101 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 1ba7069316d7577133e3e7016a4aafbed85fa99459e1403a06f899ac94f7a07e + * ELF offsets: 0x30a1626 + * Symbols: applyhdrgainmapyuv_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp int; +precision highp sampler2D; + +uniform sampler2D uInputTexture0; +out vec4 FragColor; + +const float kOffset = 0.055; +const float kScale = 1.055; +const float kGammaSrgb = 2.4; +const float kDiv = 12.92; +const float kLim = 0.04045; + +const float kHDRMaxGain = 10000.0 / 203.0; + +uniform mat3 mat; // P3 -> HasselbladRGB (linear) +uniform vec4 yuvCoeffs; // Rec601Coeffs(): [e, -(a*e/b), -(c*d/b), d] +uniform ivec2 margin; + +uniform float minimumValue; +uniform float maximumValue; +uniform float gamma; +uniform float baseOffset; +uniform float alternateOffset; +uniform float weighting; + +vec3 sRgb2linear(vec3 rgb) +{ + vec3 safeRgb = max(rgb, vec3(0.0)); + vec3 higher = pow((safeRgb + kOffset) / kScale, vec3(kGammaSrgb)); + vec3 lower = safeRgb / kDiv; + return mix(lower, higher, step(vec3(kLim), safeRgb)); +} + +vec3 Yuv2Rgb(float y, float u, float v, vec4 c) +{ + float cb = u - 0.5; + float cr = v - 0.5; + return vec3( + y + c.x * cr, + y + c.y * cr + c.z * cb, + y + c.w * cb + ); +} + +vec3 ApplyGain(vec3 linearRgb, vec3 normalizedGain) +{ + vec3 safeGain = max(normalizedGain, vec3(0.0)); + vec3 gain = (maximumValue - minimumValue) * pow(safeGain, vec3(1.0 / gamma)) + minimumValue; + return ((linearRgb + baseOffset) * pow(vec3(2.0), weighting * gain) - alternateOffset); +} + +vec3 Convert(vec3 baseRgb_srgb, vec3 gainRgb_norm) +{ + vec3 baseLin = sRgb2linear(baseRgb_srgb); + vec3 applied = ApplyGain(baseLin, gainRgb_norm); + vec3 hassLin = mat * applied; + return hassLin / kHDRMaxGain; +} + +void main() +{ + ivec2 size = textureSize(uInputTexture0, 0); + + ivec2 coord = ivec2(gl_FragCoord.xy); + + ivec2 p = clamp(coord + margin, ivec2(0), size - ivec2(1)); + + int xEven = (p.x / 2) * 2; + int xOdd = min(xEven + 1, size.x - 1); + + ivec2 pU = ivec2(xEven, p.y); + ivec2 pV = ivec2(xOdd, p.y); + + vec4 pixY = texelFetch(uInputTexture0, p, 0); + vec4 pixU = texelFetch(uInputTexture0, pU, 0); + vec4 pixV = texelFetch(uInputTexture0, pV, 0); + + float baseY = pixY.r; + float baseU = pixU.g; + float baseV = pixV.g; + + float gainY = pixY.b; + float gainU = pixU.a; + float gainV = pixV.a; + + vec3 baseRgb = Yuv2Rgb(baseY, baseU, baseV, yuvCoeffs); + vec3 gainRgb = Yuv2Rgb(gainY, gainU, gainV, yuvCoeffs); + + vec3 outRgb = Convert(baseRgb, gainRgb); + + FragColor = vec4(outRgb, 1.0); +} diff --git a/research/phocus_glsl/07_hdr_ultrahdr/hdr_0x30b046e.frag b/research/phocus_glsl/07_hdr_ultrahdr/hdr_0x30b046e.frag new file mode 100644 index 00000000..1e31a48a --- /dev/null +++ b/research/phocus_glsl/07_hdr_ultrahdr/hdr_0x30b046e.frag @@ -0,0 +1,28 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 61d96c794a0bb8bb0d588ef4c5b792793971bdcc73cc92994129331f686949c8 + * ELF offsets: 0x30b046e + * Symbols: hdrShader + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D inputTexture; +uniform float gammaGain; +uniform float hdrLimitGain; + +void main() { + vec4 res = texture(inputTexture, TexCoord); + + res.rgb = res.rgb * gammaGain; + + res.rgb = pow(res.rgb, vec3(2.2)); + + res = clamp(res, vec4(0.0), vec4(hdrLimitGain)); + + FragColor = res; +} diff --git a/research/phocus_glsl/07_hdr_ultrahdr/hdr_gamma22_0x30878f3.frag b/research/phocus_glsl/07_hdr_ultrahdr/hdr_gamma22_0x30878f3.frag new file mode 100644 index 00000000..5afffbce --- /dev/null +++ b/research/phocus_glsl/07_hdr_ultrahdr/hdr_gamma22_0x30878f3.frag @@ -0,0 +1,28 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: a38c2123a061abc12f46152f00b08b8964c81fa0f027a5c3d28c1ae96824329b + * ELF offsets: 0x30878f3 + * Symbols: hdr_gamma22_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform float uGammaGain; +uniform float uHdrLimitGain; + +void main() { + vec4 res = texture(uInputTexture0, TexCoord); + + // Apply gamma gain (scale to HDR range) + vec3 c = res.rgb * uGammaGain; + + // Apply Hasselblad gamma (2.19921875 = Adobe RGB gamma) → linear + c = pow(max(c, vec3(0.0)), vec3(2.19921875)); + + FragColor = vec4(c, res.a); +} diff --git a/research/phocus_glsl/07_hdr_ultrahdr/hdr_lstar_0x30463fa.frag b/research/phocus_glsl/07_hdr_ultrahdr/hdr_lstar_0x30463fa.frag new file mode 100644 index 00000000..cbd9b743 --- /dev/null +++ b/research/phocus_glsl/07_hdr_ultrahdr/hdr_lstar_0x30463fa.frag @@ -0,0 +1,36 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 90cc5ac2e908659c19bc8034fda56ad05c823639ae0190a6eea378ee396428b8 + * ELF offsets: 0x30463fa + * Symbols: hdr_lstar_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform float uGammaGain; +uniform float uHdrLimitGain; + +void main() { + const float eps = 216.0 / 24389.0; // kLStarEpsilon + const float kap = 24389.0 / 27.0; // kLStarKappa + + vec4 res = texture(uInputTexture0, TexCoord); + + // Apply gamma gain (scale to HDR range) + res.rgb = res.rgb * uGammaGain; + + // L* space → linear + vec3 vLo = res.rgb * 100.0 / kap; + vec3 vHi = pow(max((res.rgb + 0.16) / 1.16, vec3(0.0)), vec3(3.0)); + + res.r = res.r <= eps ? vLo.r : vHi.r; + res.g = res.g <= eps ? vLo.g : vHi.g; + res.b = res.b <= eps ? vLo.b : vHi.b; + + FragColor = res; +} diff --git a/research/phocus_glsl/99_unattributed/blend_film_0x3091172.frag b/research/phocus_glsl/99_unattributed/blend_film_0x3091172.frag new file mode 100644 index 00000000..578c579d --- /dev/null +++ b/research/phocus_glsl/99_unattributed/blend_film_0x3091172.frag @@ -0,0 +1,219 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 6f5a415b9a5b03f63076fed61003d2bf09f8794669895db848df91efef8e2adb + * ELF offsets: 0x3091172 + * Symbols: blend_film_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp int; +precision highp sampler2D; + +out vec4 FragColor; + +layout(std140) uniform BlendParams { + vec4 alphaBlend; + float grainScale; + float grainOffset; + float blurSigma; + float blurSum; + float brightScale; + float invGamma; + int blurRadius; + int useLumChannel; // 0 rgb, 1 hsv-luma, 2 ycc + int colorMode; + int additiveMode; + int sqrtMode; + int blurMode; // 0 none,1 box,2 gaussian + float gainReduction; + float _pad0; float _pad1; float _pad2; +} opts; + +uniform sampler2D uInputTexture0; // filmGrainImg, 0..1 (stored in RGBA16F) +uniform sampler2D uInputTexture1; // inImg, 0..1 + +const float kMaxRange = 65535.0; +const float PI = 3.14159265358979323846; + +vec3 Rgb2Hsv_360(vec3 rgb65535) { + float mMin = min(min(rgb65535.r, rgb65535.g), rgb65535.b); + float mMax = max(max(rgb65535.r, rgb65535.g), rgb65535.b); + float chroma = mMax - mMin; + + vec3 hsv = vec3(0.0, 0.0, mMax); + hsv.y = (mMax == 0.0) ? 0.0 : (chroma / mMax); + + if (chroma == 0.0) { + hsv.x = 0.0; + } else if (mMax == rgb65535.r) { + hsv.x = (rgb65535.g >= rgb65535.b) + ? 60.0 * (rgb65535.g - rgb65535.b) / chroma + : 60.0 * (rgb65535.g - rgb65535.b) / chroma + 360.0; + } else if (mMax == rgb65535.g) { + hsv.x = 60.0 * (rgb65535.b - rgb65535.r) / chroma + 120.0; + } else { + hsv.x = 60.0 * (rgb65535.r - rgb65535.g) / chroma + 240.0; + } + return hsv; // (H in degrees 0..360, S 0..1, V 0..65535) +} + +vec3 Hsv2Rgb_360(vec3 hsv) { + float hue = hsv.x / 60.0; + int i = int(floor(hue)); + float f = fract(hue); + if ((i & 1) == 0) f = 1.0 - f; + + float m = hsv.z * (1.0 - hsv.y); + float n = hsv.z * (1.0 - hsv.y * f); + + int idx = ((i % 6) + 6) % 6; + if (idx == 0) return vec3(hsv.z, n, m); + if (idx == 1) return vec3(n, hsv.z, m); + if (idx == 2) return vec3(m, hsv.z, n); + if (idx == 3) return vec3(m, n, hsv.z); + if (idx == 4) return vec3(n, m, hsv.z); + return vec3(hsv.z, m, n); +} + +vec3 rgb2ycc(vec3 rgb65535) { + return vec3((rgb65535.r + 2.0*rgb65535.g + rgb65535.b) * 0.25, + rgb65535.r - rgb65535.g, + rgb65535.b - rgb65535.g); +} + +vec3 ycc2rgb(vec3 ycc) { + float lr = 3.0 * ycc.y - ycc.z; + float lb = 3.0 * ycc.z - ycc.y; + float ly4 = ycc.x * 4.0; + + float r = (lr + ly4) * 0.25; + float b = (lb + ly4) * 0.25; + r = max(0.0, r); + b = max(0.0, b); + float g = (ly4 - (r + b)) * 0.5; + g = max(0.0, g); + return vec3(r, g, b); +} + +vec3 BoxBlur_01(ivec2 base, int radius, float amount) { + ivec2 size = textureSize(uInputTexture1, 0); + vec3 sum = vec3(0.0); + for (int j = -radius; j <= radius; ++j) { + for (int i = -radius; i <= radius; ++i) { + ivec2 p = clamp(base + ivec2(i, j), ivec2(0), size - 1); + sum += texelFetch(uInputTexture1, p, 0).rgb; + } + } + return sum / max(amount, 1e-6); +} + +float GaussianW(int x, int y, float sigma) { + float sqrXY = float(x*x + y*y); + float sqr2Sig = 2.0 * sigma * sigma; + float exponent = sqrXY / max(sqr2Sig, 1e-6); + return 1.0 / (exp(exponent) * sqr2Sig * PI); +} + +vec3 GaussianBlur_01(ivec2 base, int radius, float sigma) { + ivec2 size = textureSize(uInputTexture1, 0); + vec3 sum = vec3(0.0); + float gsum = 0.0; + for (int j = -radius; j <= radius; ++j) { + for (int i = -radius; i <= radius; ++i) { + ivec2 p = clamp(base + ivec2(i, j), ivec2(0), size - 1); + float w = GaussianW(i, j, sigma); + sum += w * texelFetch(uInputTexture1, p, 0).rgb; + gsum += w; + } + } + return (gsum > 0.0) ? (sum / gsum) : texelFetch(uInputTexture1, base, 0).rgb; +} + +void main() { + ivec2 gid = ivec2(gl_FragCoord.xy); + ivec2 size = textureSize(uInputTexture1, 0); + + ivec2 gidAdjust = clamp(gid + ivec2(opts.blurRadius), ivec2(0), size - 1); + + vec4 inPix01 = texelFetch(uInputTexture1, gidAdjust, 0); + vec3 inPix65535 = inPix01.rgb * kMaxRange; + + vec3 grainPix65535 = texelFetch(uInputTexture0, gid, 0).rgb * kMaxRange; + + vec3 blur01; + if (opts.blurMode == 1) blur01 = BoxBlur_01(gid, opts.blurRadius, opts.blurSum); + else if (opts.blurMode == 2) blur01 = GaussianBlur_01(gid, opts.blurRadius, opts.blurSigma); + else blur01 = inPix01.rgb; + + vec3 blur65535 = blur01 * kMaxRange; + + vec3 inVal; + if (opts.useLumChannel == 1) inVal = Rgb2Hsv_360(blur65535).zxy; // (V,H,S) + else if (opts.useLumChannel == 2) inVal = rgb2ycc(blur65535); + else inVal = blur65535; + + vec3 grainVal; + if (opts.useLumChannel == 2) { + vec3 ycc = rgb2ycc(grainPix65535); + grainVal = vec3(ycc.x - opts.grainOffset, ycc.yz) / max(opts.grainScale, 1e-6); + if (grainVal.x > 0.0) grainVal.x *= opts.brightScale; + } else { + grainVal = (grainPix65535 - opts.grainOffset) / max(opts.grainScale, 1e-6); + grainVal = mix(grainVal, grainVal * opts.brightScale, step(0.0, grainVal)); + } + + vec3 alpha = opts.alphaBlend.rgb; + float safeGain = (abs(opts.gainReduction) < 1e-6) ? 1.0 : opts.gainReduction; + + vec3 finalVal; + if (opts.additiveMode > 0) { + vec3 base = (opts.useLumChannel > 0) ? vec3(inVal.x) : inVal; + base = pow(abs(base * safeGain / 4.0), vec3(opts.invGamma)); + finalVal = alpha * base * grainVal; + } else { + if (opts.useLumChannel == 1 || opts.useLumChannel == 2) + finalVal = vec3(grainVal.x * 0.5 + 0.5, grainVal.yz); + else + finalVal = grainVal * 0.5 + 0.5; + } + + finalVal /= safeGain; + + vec3 noiseVal; + if (opts.additiveMode > 0) { + noiseVal = inVal + finalVal; + } else { + if (opts.useLumChannel == 1) { + noiseVal = mix(inVal, vec3(finalVal.x * inVal.x), alpha); + } else if (opts.useLumChannel == 2) { + noiseVal.x = mix(inVal.x, finalVal.x * inVal.x, alpha.x); + noiseVal.yz = inVal.yz + alpha.yz * finalVal.yz * inVal.x; + float lumChange = (noiseVal.x + 1.0) / (inVal.x + 1.0); + noiseVal.yz *= lumChange; + } else { + noiseVal = mix(inVal, finalVal * inVal, alpha); + } + } + noiseVal.x = max(0.0, noiseVal.x); + + vec3 rgb65535; + if (opts.useLumChannel == 1) { + if (opts.colorMode > 0) { + float h = noiseVal.y; + if (h > 360.0) h -= 360.0; + if (h < 0.0) h += 360.0; + float s = clamp(noiseVal.z, 0.0, 1.0); + rgb65535 = Hsv2Rgb_360(vec3(h, s, noiseVal.x)); + } else { + rgb65535 = Hsv2Rgb_360(vec3(inVal.y, inVal.z, noiseVal.x)); + } + } else if (opts.useLumChannel == 2) { + rgb65535 = ycc2rgb(noiseVal); + } else { + rgb65535 = clamp(noiseVal, 0.0, kMaxRange); + } + + vec3 out01 = clamp(rgb65535 / kMaxRange, 0.0, 1.0); + FragColor = vec4(out01, inPix01.a); +} diff --git a/research/phocus_glsl/99_unattributed/ev_0x30b1024.frag b/research/phocus_glsl/99_unattributed/ev_0x30b1024.frag new file mode 100644 index 00000000..3cc2819f --- /dev/null +++ b/research/phocus_glsl/99_unattributed/ev_0x30b1024.frag @@ -0,0 +1,36 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 24294ea4f1e778a2a042f992930bcb4cd1ffeefa35dc56093993040b054f3b88 + * ELF offsets: 0x30b1024 + * Symbols: ev_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; + +out vec4 FragColor; + +uniform sampler2D uInputTexture0; +uniform float uEV; +uniform float uMaxValue; +uniform vec2 uMarginOffset; + +vec4 ApplyEVAdjustment(vec4 texColor, float ev, float maxValue) { + vec4 scaledColor = texColor.rgba * 65535.0f; + // round to nearest integer value (.5 will be rounded to the nearest even number) + vec4 adjustedRgb = round(scaledColor * ev); + adjustedRgb = min(adjustedRgb, vec4(maxValue)) / 65535.0f; + + return adjustedRgb; +} + +void main() { + // use texelFetch for actual pixel position fetch + ivec2 srcPos = ivec2(gl_FragCoord.xy) + ivec2(uMarginOffset); + vec4 texColor = texelFetch(uInputTexture0, srcPos, 0); + + vec4 adjustedColor = ApplyEVAdjustment(texColor, uEV, uMaxValue); + + FragColor = adjustedColor; +} diff --git a/research/phocus_glsl/99_unattributed/highlightRecover_0x307f63c.frag b/research/phocus_glsl/99_unattributed/highlightRecover_0x307f63c.frag new file mode 100644 index 00000000..3cddd7c8 --- /dev/null +++ b/research/phocus_glsl/99_unattributed/highlightRecover_0x307f63c.frag @@ -0,0 +1,130 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 27f287476ef495e8bc566249b46216f0cba1d8540d83cee77915f93dad53a1f5 + * ELF offsets: 0x307f63c + * Symbols: highlightRecoverShader + */ + +#version 300 es +precision highp float; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D inputTexture; +uniform vec4 neutGain; +uniform vec4 nLargestGain; +uniform vec4 boInThr; +uniform vec4 boIn2Thr; +uniform vec4 boBlendThr; +uniform vec4 boBlendDiff; + +// ComputeIsoHiPoly函数 +vec4 ComputeIsoHiPoly(float lowX, float lowY, float alphaAtOne) { + float lowXSq = lowX * lowX; + float aContrib0 = (0.5 * alphaAtOne) * (1.0 - lowXSq); + vec4 polyCoeff; + polyCoeff.g = (lowY - 1.0 + aContrib0) / (-lowXSq * 0.5 + lowX - 0.5); + polyCoeff.b = (alphaAtOne - polyCoeff.g) * 0.5; + polyCoeff.r = 1.0 - polyCoeff.g - polyCoeff.b; + return polyCoeff; +} + +// BoColorBlend函数 +vec4 BoColorBlend(vec4 orgColor, vec4 boColor, vec4 boBlendThr, vec4 boBlendDiff) { + vec4 diff = orgColor - boBlendThr; + vec4 normdiff = diff / boBlendDiff; + vec4 normdiff01 = clamp(normdiff, 0.0, 1.0); + vec4 boblend = mix(orgColor, boColor, normdiff01); + return boblend; +} + +vec4 recoverBo(vec4 iRGB, vec4 neutGain, vec4 nLargestGain, vec4 boInThr, + vec4 satNCmp, vec4 boBlendThr, vec4 boBlendDiff) { + const vec4 nearzeroVec = vec4(0.1, 0.1, 0.1, 0.1); + const vec4 oneVec = vec4(1.0, 1.0, 1.0, 1.0); + const vec4 nearOneVec = oneVec - nearzeroVec; + + // Color Ratios + vec4 cRatio = vec4(neutGain.r/neutGain.g, // Red / Green + neutGain.r/neutGain.b, // Red / Blue + neutGain.b/neutGain.g, // Blue / Green + 1.0); // dummy + + // Compute two sets of candidates for BO Recovery + vec4 hrCol0 = vec4(iRGB.g/cRatio.r, // Red from Green + iRGB.r*cRatio.r, // Green from Red + iRGB.r*cRatio.g, // Blue from Red + iRGB.a); + vec4 hrCol1 = vec4(iRGB.b/cRatio.g, // Red from Blue + iRGB.b*cRatio.b, // Green from Blue + iRGB.g/cRatio.b, // Blue from Green + iRGB.a); + + // Decide which estimates are in fact useable for BO recovery + vec4 satCmp = step(boInThr, iRGB); // 1 if boInThr 0.1) ? mmaxColor.g : blendColor.g; + blendColor.b = (satNCmp.b > 0.1) ? mmaxColor.b : blendColor.b; + return blendColor; +} + +void main() { + vec2 texelSize = 1.0 / vec2(textureSize(inputTexture, 0)); + + vec4 iRGB = texture(inputTexture, TexCoord); + vec4 sat2Cmp = step(boIn2Thr, iRGB); // 1 if center near-saturated + + vec4 satNCmp = vec4(0.0); + + vec2 offsets[8] = vec2[]( + vec2(-1.0, -1.0), vec2(0.0, -1.0), vec2(1.0, -1.0), + vec2(-1.0, 0.0), vec2(1.0, 0.0), + vec2(-1.0, 1.0), vec2(0.0, 1.0), vec2(1.0, 1.0) + ); + + for(int i = 0; i < 8; i++) { + vec2 sampleCoord = TexCoord + offsets[i] * texelSize; + vec4 neighborPixel = texture(inputTexture, sampleCoord); + satNCmp += step(boInThr, neighborPixel); // 1 if neighbour saturated + } + + sat2Cmp *= satNCmp; // combine + + vec4 hr = recoverBo(iRGB, neutGain, nLargestGain, boInThr, sat2Cmp, boBlendThr, boBlendDiff); + vec4 nHrRGB = hr * neutGain; // neutralized values + nHrRGB.a = iRGB.a; + + FragColor = nHrRGB; +} diff --git a/research/phocus_glsl/99_unattributed/reversecc_0x3061507.frag b/research/phocus_glsl/99_unattributed/reversecc_0x3061507.frag new file mode 100644 index 00000000..6f7d7427 --- /dev/null +++ b/research/phocus_glsl/99_unattributed/reversecc_0x3061507.frag @@ -0,0 +1,102 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 5f4bda2cc5a1f9e2214c3caf0d9667dc1b42455e50d9ccc2a47b627f38303abe + * ELF offsets: 0x3061507 + * Symbols: reversecc_fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp int; +precision highp sampler2D; + + +uniform sampler2D uInputTexture0; // Input Image (RgbX) +uniform sampler2D uInputTexture1; // Rev Grad (Packed RGBA, size: 64x256) +uniform sampler2D uInputTexture2; // Reverse LUT (cc_rev_lut) + +uniform mat3 uInvYuv2Rgb; +uniform mat3 uInvRawRgb2Yuv; +uniform vec2 uOffset; +uniform vec2 uScale; +uniform float uOutputScale; +uniform ivec2 uMargin; + +out vec4 FragColor; + + +vec2 CoordinateToIndex(vec2 coordinate) +{ + return uOffset + coordinate * uScale; +} + +vec2 IndexToCoordinate(vec2 index) +{ + return (index - uOffset) / uScale; +} + +vec2 ClampIndex(vec2 pos, sampler2D texLut) +{ + ivec2 size = textureSize(texLut, 0); + return min(max(pos, vec2(0.0)), vec2(size) - 1.0); +} + +vec2 LutLookup(vec2 coordinate, sampler2D texLut) +{ + vec2 index = CoordinateToIndex(coordinate); + vec2 restricted = ClampIndex(index, texLut); + vec2 a = IndexToCoordinate(index); + vec2 b = IndexToCoordinate(restricted); + vec2 offset = a - b; + vec2 base = floor(restricted); + vec2 delta = restricted - base; + + ivec2 pos0 = ivec2(ClampIndex(base, texLut)); + ivec2 pos1 = ivec2(ClampIndex(base + 1.0, texLut)); + + vec2 p00 = texelFetch(texLut, ivec2(pos0.x, pos0.y), 0).xy; + vec2 p01 = texelFetch(texLut, ivec2(pos0.x, pos1.y), 0).xy; + vec2 p10 = texelFetch(texLut, ivec2(pos1.x, pos0.y), 0).xy; + vec2 p11 = texelFetch(texLut, ivec2(pos1.x, pos1.y), 0).xy; + + vec2 weighted = mix(mix(p00, p01, delta.y), mix(p10, p11, delta.y), delta.x); + return (weighted / uOutputScale) + offset; +} + +float SampleRevGrad(float val) +{ + int index = int(clamp(val * 65535.0 + 0.5, 0.0, 65535.0)); + + int pixelIndex = index / 4; + + int channelIndex = index % 4; + + int x = pixelIndex % 64; + int y = pixelIndex / 64; + vec4 packedPixel = texelFetch(uInputTexture1, ivec2(x, y), 0); + + return packedPixel[channelIndex]; +} + +void main() +{ + ivec2 fragCoord = ivec2(gl_FragCoord.xy); + ivec2 readCoord = fragCoord + uMargin; + vec3 pix = texelFetch(uInputTexture0, readCoord, 0).rgb; + + float r_grad = SampleRevGrad(pix.r); + float g_grad = SampleRevGrad(pix.g); + float b_grad = SampleRevGrad(pix.b); + + vec3 rgb = vec3(r_grad, g_grad, b_grad) * 65535.0; + + vec3 yuv = uInvYuv2Rgb * rgb; + + if (yuv.x > 0.0) { + vec2 lookupResult = LutLookup(yuv.yz / yuv.x, uInputTexture2); + yuv.yz = lookupResult * yuv.x; + } + + vec3 resRaw = uInvRawRgb2Yuv * yuv; + FragColor = vec4(clamp(resRaw, 0.0, 65535.0) / 65535.0, 1.0); +} diff --git a/research/phocus_glsl/99_unattributed/shader_0x3066a62.frag b/research/phocus_glsl/99_unattributed/shader_0x3066a62.frag new file mode 100644 index 00000000..e393a13a --- /dev/null +++ b/research/phocus_glsl/99_unattributed/shader_0x3066a62.frag @@ -0,0 +1,21 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: a0b9040c8836f53fb25c010f6c687550f122906977f9d0c82ba3bb5f2d63c253 + * ELF offsets: 0x3066a62 + * Symbols: fragmentShaderSource + */ + +#version 300 es +precision highp float; +precision highp sampler2D; +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D textureSampler; +vec3 LinearToGamma(vec3 c, float g) { + return pow(c, vec3(1.0 / g)); +} +void main() { + vec4 texColor = texture(textureSampler, TexCoord); + FragColor = texColor; +} diff --git a/research/phocus_glsl/99_unattributed/unattributed_0x308338f_0x308338f.vert b/research/phocus_glsl/99_unattributed/unattributed_0x308338f_0x308338f.vert new file mode 100644 index 00000000..b1045899 --- /dev/null +++ b/research/phocus_glsl/99_unattributed/unattributed_0x308338f_0x308338f.vert @@ -0,0 +1,15 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 931e3e990f6bc5b1c5054dc46aa339c104ed60393908c8d56fee3d564f7ab898 + * ELF offsets: 0x308338f + * Symbols: unattributed + */ + +#version 300 es +in vec4 aPosition; +in vec2 aTextureCoord; +out vec2 vTextureCoord; +void main() { + gl_Position = aPosition; + vTextureCoord = vec2(aTextureCoord.x,1.0f- aTextureCoord.y); +} diff --git a/research/phocus_glsl/99_unattributed/usm_0x3023371.frag b/research/phocus_glsl/99_unattributed/usm_0x3023371.frag new file mode 100644 index 00000000..2dab13bd --- /dev/null +++ b/research/phocus_glsl/99_unattributed/usm_0x3023371.frag @@ -0,0 +1,83 @@ +/* + * Recovered from a compiled proprietary binary for personal study. + * SHA-256: 2bf98f5b7d9fed788ba4a5fa3a532cee761edddfc47bf54b34e76225416543f5 + * ELF offsets: 0x3023371 + * Symbols: usmShader + */ + +#version 300 es +precision highp float; + +in vec2 TexCoord; +out vec4 FragColor; + +uniform sampler2D inputTexture; +uniform float amount; // 锐化强度 +uniform float darkLimit; // 暗部限制 +uniform float noiseLimit; // 噪声阈值 +uniform float hdrScale; // HDR缩放因子 +uniform vec2 texelSize; // 纹理像素大小 + +// 高斯权重 (5x5 kernel) +uniform float centerWeight; // 中心权重 +uniform vec4 gaussWeights; // 高斯权重 (4个方向) +uniform int numElements; // 权重元素数量 + +// 计算锐化因子 +float UsmFactor(float value, float blurred, float sharpenAmount, float darkLimit, float noiseLimit, float hdrScale) { + // 计算锐化强度,考虑暗部限制 + float amount = clamp(sharpenAmount, 0.0, 1000.0) / 100.0; + + // 计算差值 + float diff = value - blurred; + + // 计算噪声限制 + float noise = 1.0; + if (noiseLimit > 0.0) { + float absDiff = abs(diff) * hdrScale; + noise = 1.0 / (1.0 + absDiff / noiseLimit); + } + + return amount * noise * diff; +} + +// 高斯模糊函数 +float gaussianBlur(sampler2D tex, vec2 coord, vec2 direction) { + float sum = 0.0; + float weightSum = 0.0; + + // 使用5x5高斯核 + for (int i = -2; i <= 2; i++) { + float weight = (i == 0) ? centerWeight : gaussWeights[abs(i) - 1]; + vec2 offset = direction * float(i) * texelSize; + float sample = dot(texture(tex, coord + offset).rgb, vec3(0.299, 0.587, 0.114)); + sum += sample * weight; + weightSum += weight; + } + + return sum / weightSum; +} + +void main() { + vec2 texelSize = 1.0 / vec2(textureSize(inputTexture, 0)); + + // 获取中心像素 + vec4 center = texture(inputTexture, TexCoord); + float gray = dot(center.rgb, vec3(0.299, 0.587, 0.114)); + + // 计算高斯模糊 + float blurredX = gaussianBlur(inputTexture, TexCoord, vec2(1.0, 0.0)); + float blurredY = gaussianBlur(inputTexture, TexCoord, vec2(0.0, 1.0)); + float blurred = (blurredX + blurredY) * 0.5; + + // 应用USM锐化 + float sharpFactor = UsmFactor(gray, blurred, amount, darkLimit, noiseLimit, hdrScale); + + // 计算锐化后的颜色 + vec3 sharpened = center.rgb + sharpFactor; + + // 限制在有效范围内 + sharpened = clamp(sharpened, 0.0, 1.0); + + FragColor = vec4(sharpened, center.a); +} diff --git a/research/phocus_glsl/NOTICE.md b/research/phocus_glsl/NOTICE.md new file mode 100644 index 00000000..61410e07 --- /dev/null +++ b/research/phocus_glsl/NOTICE.md @@ -0,0 +1,8 @@ +# 来源与使用说明 + +这些 GLSL 源码由已编译的 Hasselblad Phocus Android 原生库静态恢复。 + +- 它们不是 PhotonCamera 项目的源代码。 +- 它们不是开源发布物,也未附带可授予再分发权利的许可证。 +- 本目录的用途是个人学习、兼容性分析和算法研究。 +- 若要在产品中实现类似功能,应根据数学原理独立实现,不应直接复制这些源码。 diff --git a/research/phocus_glsl/README.md b/research/phocus_glsl/README.md new file mode 100644 index 00000000..e7535f4d --- /dev/null +++ b/research/phocus_glsl/README.md @@ -0,0 +1,44 @@ +# Phocus GLSL 研究提取集 + +本目录从 Android Phocus 的 `libcrosssdk.so` 中静态恢复 GLSL,仅用于个人学习和互操作研究。 + +## 提取结果 + +- 二进制中的 GLSL 文本实例:177 +- 按源代码内容去重后:177 +- 可解析的导出 Shader 源符号:150 +- 有符号归属的文本实例:150 +- 暂时无法绑定导出符号的文本实例:27 + +完全相同的源码只保存一份;`manifest.json` 和 `manifest.csv` 保留了所有 ELF 偏移、符号别名及重复实例。 + +## 目录 + +| 目录 | 内容 | 文件数 | +|---|---|---:| +| `00_common_io` | 公共顶点、格式转换、填充及输入输出 | 9 | +| `01_raw_sensor` | Bayer、黑电平、坏点、中和、场景校准 | 15 | +| `02_demosaic` | 多阶段 Demosaic 与色噪处理 | 19 | +| `03_denoise` | CMOS/CCD、RGB 与灰度降噪 | 28 | +| `04_color_tone` | 色彩变换、曲线、Gamma、选择性色彩 | 25 | +| `05_lens_geometry` | 镜头、色差、暗角、缩放、方向和透视 | 38 | +| `06_detail_texture` | Clarity、锐化和胶片颗粒 | 31 | +| `07_hdr_ultrahdr` | HDR 传递函数、Gain Map 生成与应用 | 5 | +| `99_unattributed` | 可恢复但不能可靠绑定模块名的源码 | 7 | + +## 阅读顺序 + +建议先看: + +1. `01_raw_sensor`:黑电平、Bayer 中和和高光重建。 +2. `02_demosaic`:按 `pass_0a1 → 0a2 → 0b → 0c → 1 → 2 → 3` 阅读。 +3. `03_denoise`:结合 Demosaic 的 color-noise pass 理解。 +4. `04_color_tone`:Hasselblad Gamma、Film Curve、Gradation 和色彩 LUT。 +5. `07_hdr_ultrahdr`:SDR/HDR 映射以及 UltraHDR Gain Map。 + +## 注意 + +- 文件头注释是提取器添加的,不属于原始 Shader。 +- 部分 Shader 依赖宿主端创建的纹理格式、UBO、LUT 和调度尺寸,不能脱离 C++ 管线直接运行。 +- 分类根据导出符号及源码特征完成,`manifest.json` 才是精确来源索引。 +- 原始程序属于其权利人;请勿把这些文件当作开源代码复制进产品或公开再分发。 diff --git a/research/phocus_glsl/manifest.csv b/research/phocus_glsl/manifest.csv new file mode 100644 index 00000000..8354499a --- /dev/null +++ b/research/phocus_glsl/manifest.csv @@ -0,0 +1,178 @@ +file,category,stage,sha256,bytes,lines,offsets,symbols +00_common_io/FillWithBlack_0x307d438.frag,00_common_io,fragment,70223e71cb5ac64567b5380e8fbaa255c1b38e255e8da0de9b80fec97863dd6e,118,9,0x307d438,FillWithBlack_fragmentShaderSource +00_common_io/block_downsample_0x3065745.frag,00_common_io,fragment,0a3908a02d09d48093007d130c8f231301025cfc3890bab1224d325af566ca28,502,23,0x3065745,block_downsample_fragmentShaderSource +00_common_io/commonVertex_0x3004aaf.vert,00_common_io,vertex,2cabc41351a224550887e53887d0bd2958eeeb6324ec7d02bc6f45ec0e7b30f5,191,11,0x3004aaf,commonVertexShaderSource +00_common_io/formatConvertHalfFloatToU16_0x300348f.comp,00_common_io,compute,bcce94a076806ceb2369010b6db78f96e941170b371e5b72615c3be5dc9134ad,564,18,0x300348f,formatConvertHalfFloatToU16_computeShaderSource +00_common_io/formatConvertU16ToHalfFloat_0x3078b02.comp,00_common_io,compute,ea09e7937d80f293bd7655abc6e2abde296abeb033cc3b2d91dd064b9b4a5fc6,523,18,0x3078b02,formatConvertU16ToHalfFloat_computeShaderSource +00_common_io/shader_0x30451f3.vert,00_common_io,vertex,8b5fee15a4bd109c8dd4d558c7eea81e9fb81539cdd38698c736ae55f8644956,294,14,0x30451f3,vertexShaderSource +00_common_io/shift_0x30aa376.frag,00_common_io,fragment,ceeb71df7570cf8008284d9f509049a60ddc160aed621ed97e82a8a985a529b5,859,38,0x30aa376,shift_fragmentShaderSource +00_common_io/u16f28ui_0x302addd.frag,00_common_io,fragment,c5c354119ccc00f88f045a9b4300fd2d00e8bfabfeb9e4bb21433cf1bf76cc11,432,16,0x302addd,u16f28ui_fragmentShaderSource +00_common_io/yuv2rgb_0x3016546.frag,00_common_io,fragment,5a8b0395d4fc2353a8e44245d6080723fe24656140f8bf28d5346c93ae6adb5d,759,33,0x3016546,yuv2rgb_fragmentShaderSource +01_raw_sensor/bayerfastinterpolatefull_0x2ffd274.frag,01_raw_sensor,fragment,9d87df9b959daa41f5d8eb526f3af10c4fc082485de9a1b3cfc94a50fb9bd795,5413,139,0x2ffd274,bayerfastinterpolatefull_fragmentShaderSource +01_raw_sensor/bayerfastinterpolatehalf_0x302a606.frag,01_raw_sensor,fragment,805ab3ff49fd22152dce086812cac32e9062ddc56861d30aa04aa2b12c46def2,2006,79,0x302a606,bayerfastinterpolatehalf_fragmentShaderSource +01_raw_sensor/blackLevelSubstract_0x3068cdb.frag,01_raw_sensor,fragment,7181e8fe4ab1bebbe1039474ace74f997cc0ca1ee20e6e7aaec7ef86a4deb6ac,413,18,0x3068cdb,blackLevelSubstract_fragmentShaderSource +01_raw_sensor/highlightrecoveryscalarrgb_0x304d54d.frag,01_raw_sensor,fragment,62a796eabf55c35aa9d70843c4c6670f47fc11b59a789fa59e3107a39383b2c4,3683,127,0x304d54d,highlightrecoveryscalarrgb_fragmentShaderSource +01_raw_sensor/hotPixelPlus_0x305adee.frag,01_raw_sensor,fragment,0791fa8fdf096adab2e55a65c1b68b0f4b1e31529202eb0153f89882ee21b144,21780,378,0x305adee,hotPixelPlus_fragmentShaderSource +01_raw_sensor/hotPixel_0x302af8e.frag,01_raw_sensor,fragment,8012955d7c0a1c85bc5fb7d07a3f289631214a7796b86283a33c7b201cd7ce76,20854,358,0x302af8e,hotPixel_fragmentShaderSource +01_raw_sensor/multi2bayer_ms2bayer3_0x303310c.frag,01_raw_sensor,fragment,772e7494a86ba3a7164e9b369e45dd64a1104e56361efa9f6396d5ea49c6a7a9,1093,40,0x303310c,multi2bayer_ms2bayer3_fragmentShaderSource +01_raw_sensor/neutralisationBayer_0x30563ff.comp,01_raw_sensor,compute,54c8e19ec4e856f0546700e84db38fd1983f139aaf7c43e3323fb08650dcd9d4,3922,100,0x30563ff,neutralisationBayer_computeShaderSource +01_raw_sensor/neutralisationRgb_0x2ff8dfa.comp,01_raw_sensor,compute,f139a1b07826c300489b4392699d94238e6f34a998d4dba8d9ca80bf605e6539,2391,71,0x2ff8dfa,neutralisationRgb_computeShaderSource +01_raw_sensor/orientation_180_0x3073882.frag,01_raw_sensor,fragment,84412000fe0b6f27def36bdbb611fafd17343363c7d23dbecb0505ce87fad666,1182,44,0x3073882,orientation_180_fragmentShaderSource +01_raw_sensor/orientation_270_0x2ff9752.frag,01_raw_sensor,fragment,2fe79b91d74441a5a0d8daeb34f87e445ac128112c56008290fceab12d1311ab,1192,44,0x2ff9752,orientation_270_fragmentShaderSource +01_raw_sensor/orientation_90_0x301d6cf.frag,01_raw_sensor,fragment,4802e80060871fd646ac34d63fa30b3779d034e42b559dc1054f76757737e36f,1193,45,0x301d6cf,orientation_90_fragmentShaderSource +01_raw_sensor/sceneCalibrationBayer_0x3060303.comp,01_raw_sensor,compute,ad02e35cd008c247df53d43a9649af52f9063e142b0515ad179780c11c18585c,4611,133,0x3060303,sceneCalibrationBayer_computeShaderSource +01_raw_sensor/sceneCalibrationGray_0x30b1366.comp,01_raw_sensor,compute,b37680e4d072169a7a53fcdc209523e90d1154e05d5d45d437005db9c3ad2a47,4021,116,0x30b1366,sceneCalibrationGray_computeShaderSource +01_raw_sensor/sceneCalibrationRgb_0x3008d0f.comp,01_raw_sensor,compute,4e7ff25df3d5cf99208ee46fa417954a190ec2909af7bfb1eac95f363023f221,5338,143,0x3008d0f,sceneCalibrationRgb_computeShaderSource +02_demosaic/demosaic_calculate_color_noise_error_0x30062f5.comp,02_demosaic,compute,6da3783cd147005c2750b1fe352a0110d3ca2c22e32c35691f4087f45ac1b17b,2006,71,0x30062f5,demosaic_calculate_color_noise_error_computeShaderSource +02_demosaic/demosaic_color_noise_filter_0x3014da8.comp,02_demosaic,compute,d2230d98ddb2e920f96ff833d6b2b064edfe1fd367f3f1b7a1e0dae591238f06,1539,50,0x3014da8,demosaic_color_noise_filter_computeShaderSource +02_demosaic/demosaic_color_noise_pass_1_0x3081fb1.comp,02_demosaic,compute,626b18a415bd88111972b31b26529cbc4c3f0fe86f066c6da8e5ba9b77c0052d,1761,61,0x3081fb1,demosaic_color_noise_pass_1_computeShaderSource +02_demosaic/demosaic_color_noise_pass_2_0x3024978.comp,02_demosaic,compute,77ecea4a4085c9678c82864b7a3a1633b9a173a2746a1c4fae420049edf24f6c,4246,117,0x3024978,demosaic_color_noise_pass_2_computeShaderSource +02_demosaic/demosaic_color_noise_pass_3_0x3049e97.comp,02_demosaic,compute,9f0f02155a6f509830d6ddc3afa540da03684b8c9d752d96012957f74090786e,6408,177,0x3049e97,demosaic_color_noise_pass_3_computeShaderSource +02_demosaic/demosaic_color_noise_pass_3_yccd_0x303704a.comp,02_demosaic,compute,b3af96dca2b14851ada4f1cd7cad4b9e9bfa6c4f499fe6edf9e4367e6fe2246d,5960,153,0x303704a,demosaic_color_noise_pass_3_yccd_computeShaderSource +02_demosaic/demosaic_iir2_pass1_0x3041e8f.comp,02_demosaic,compute,9c22e56ab98ccba2df1047cf363f263ad92e146700c596b8622b03af6ca5233b,2422,79,0x3041e8f,demosaic_iir2_pass1_computeShaderSource +02_demosaic/demosaic_iir2_pass1_init_0x3005a70.comp,02_demosaic,compute,b4203de6cb2b2a0d2d45bf31b94709bcbe51958985b0a49d92728ed4bdeedad2,2180,75,0x3005a70,demosaic_iir2_pass1_init_computeShaderSource +02_demosaic/demosaic_iir2_pass2_0x3006acc.comp,02_demosaic,compute,3880b76927b8cd1ca8c15558912f032c8594312e3180834b0fc36a1c55bd64b0,1625,59,0x3006acc,demosaic_iir2_pass2_computeShaderSource +02_demosaic/demosaic_iir2_pass3_0x3068458.comp,02_demosaic,compute,e665176d25d909367a134dd38315c49c97b9157836dc8165b0225cb611582e96,2178,74,0x3068458,demosaic_iir2_pass3_computeShaderSource +02_demosaic/demosaic_pass_0a1_0x30410af.comp,02_demosaic,compute,54604631e2fdfb4d993170190d5b8dab390379a81b500e43d337af975cade411,3551,143,0x30410af,demosaic_pass_0a1_computeShaderSource +02_demosaic/demosaic_pass_0a2_0x30555c4.comp,02_demosaic,compute,0efa5c950f6502ed9836a8cd18dc935a686aa8e8033e3d36d9cb96ca7d92b347,3642,106,0x30555c4,demosaic_pass_0a2_computeShaderSource +02_demosaic/demosaic_pass_0b_0x30325b5.comp,02_demosaic,compute,6ebfd8f9386e94f8fc0090d4b6379e8ac599ae6581c15edb35a0c1ed5981e6c5,2115,74,0x30325b5,demosaic_pass_0b_computeShaderSource +02_demosaic/demosaic_pass_0c_0x306798d.comp,02_demosaic,compute,cbbd4fee1875088d68c839eb922dffa6be9b1c175ff33941b4465deb990dca95,2762,94,0x306798d,demosaic_pass_0c_computeShaderSource +02_demosaic/demosaic_pass_1_0x3097f8e.comp,02_demosaic,compute,16b1675cddccc6ef185afa37b2b9d4f5af38b3c64e51ec7b0854b474c678221a,17847,389,0x3097f8e,demosaic_pass_1_computeShaderSource +02_demosaic/demosaic_pass_2_0x30a5753.comp,02_demosaic,compute,f6a0ccf9154f8a51129f18a76bfbc63bcb960c646805b2511dbe5ec8c0e90f3d,3921,114,0x30a5753,demosaic_pass_2_computeShaderSource +02_demosaic/demosaic_pass_3_0x30466e2.comp,02_demosaic,compute,f5810f8bf53819324502a8696d7d0bdb94238280be29b7f72139e9701e276111,14260,337,0x30466e2,demosaic_pass_3_computeShaderSource +02_demosaic/demosaic_pass_neutral_0x308ec13.comp,02_demosaic,compute,ca62ac0831390a5415c5703b3a22c344faf8cc3de01c9665783d1ce6a6790da0,1787,61,0x308ec13,demosaic_pass_neutral_computeShaderSource +02_demosaic/demosaic_yuv_to_rgb_0x3007126.comp,02_demosaic,compute,dd4384ae8724f2c7edb40a44214966d9d390cba0e9fa00329be17c814ff0e1c7,1761,58,0x3007126,demosaic_yuv_to_rgb_computeShaderSource +03_denoise/cacheCmosCache0_0x30501d4.frag,03_denoise,fragment,c7f420d715f7cf77f2a9e4f39d3a91210a32fb7ae3f3bb76eb54060c35dbb03a,790,29,0x30501d4,cacheCmosCache0_fragmentShaderSource +03_denoise/cacheCmosCache1_0x30651c8.frag,03_denoise,fragment,75b79c1ff7a65dce4caaa4a318e8831830581262ba3641abbc911404105fd626,1404,35,0x30651c8,cacheCmosCache1_fragmentShaderSource +03_denoise/cacheCmosCache2_0x300e390.frag,03_denoise,fragment,c54309c364704060a762899687cb5552463b112200ba20e6380dfabef41cf04a,796,29,0x300e390,cacheCmosCache2_fragmentShaderSource +03_denoise/cacheCmosCache3_0x307c71b.frag,03_denoise,fragment,ea3760a5920497c1d661adf7132a31d29544b34d386deb1d87ba6b3d41b935a7,1404,35,0x307c71b,cacheCmosCache3_fragmentShaderSource +03_denoise/cacheCmosG1G2Cache0_0x3032df9.frag,03_denoise,fragment,07200b7b375227e9abc24cb9bc8583f5977e8c9e89f6bc9e3363bf04aca6c348,786,29,0x3032df9,cacheCmosG1G2Cache0_fragmentShaderSource +03_denoise/cacheCmosG1G2Cache1_0x302135f.frag,03_denoise,fragment,9f177bedb3419c59f2297600453a289d254763433b0bb6c83256845c271b1cb6,1389,35,0x302135f,cacheCmosG1G2Cache1_fragmentShaderSource +03_denoise/cacheCmosG1G2Cache2_0x303b1b3.frag,03_denoise,fragment,f3fe5f3c34819255ebb82f092eed86346a1e31b351c6d54b2771b7866d3492f7,1271,33,0x303b1b3,cacheCmosG1G2Cache2_fragmentShaderSource +03_denoise/cacheCmosG1G2Cache3_0x3064c8a.frag,03_denoise,fragment,63a9a7da2c59cdee8169bf505f93bba4d04bcb1f4bf20c9acff24ab92b7975de,1341,33,0x3064c8a,cacheCmosG1G2Cache3_fragmentShaderSource +03_denoise/cacheCmosRedBlueCache0_0x306db71.frag,03_denoise,fragment,25d520100eef854bba77d939159fe21fd7680371cc3f7b6f62e6585458e055d6,861,31,0x306db71,cacheCmosRedBlueCache0_fragmentShaderSource +03_denoise/cacheCmosRedBlueCache1_0x306decf.frag,03_denoise,fragment,1fd2aa77c9667d8cfdce32d82f263caaefb216a28936ea7e2864847063731a33,1558,41,0x306decf,cacheCmosRedBlueCache1_fragmentShaderSource +03_denoise/cacheCmosRedBlueCache2_0x3038793.frag,03_denoise,fragment,d3fc268abeb04b0953757c16d8bafcb1907a30fe349cc7f5417371eb5af0aa65,1986,48,0x3038793,cacheCmosRedBlueCache2_fragmentShaderSource +03_denoise/denoiseCcd_0x304b7a0.comp,03_denoise,compute,38ce78e7205eab385f083a58771fba7efdf84e98ab3e79ef6643a7ef0e7c3653,7596,158,0x304b7a0,denoiseCcd_computeShaderSource +03_denoise/denoiseCmosCached_0x309c546.comp,03_denoise,compute,5a71694ed199c558d517899590d5a2c72f4d49e457ccf781e467e7c35119ad30,8364,161,0x309c546,denoiseCmosCached_computeShaderSource +03_denoise/denoiseCmosG1G2Cached_0x30a66a5.frag,03_denoise,fragment,1ea9327fd1b1ce2257eca7ed7bca44ffa74b5d5ba71f8203df26436cd3713f9e,9222,236,0x30a66a5,denoiseCmosG1G2Cached_fragmentShaderSource +03_denoise/denoiseCmosG1G2Cached_0x30ad00c.comp,03_denoise,compute,e1cd535a47146b36cb176de8b5658dc74be20180f1c78f78e4e09924d3fd964f,9203,223,0x30ad00c,denoiseCmosG1G2Cached_computeShaderSource +03_denoise/denoiseCmosRedBlueCached_0x308f30f.frag,03_denoise,fragment,ddf06024ffc6b97bd6e48447543b6b33c79c45a80b2ffdd786f6eaff24177058,6243,176,0x308f30f,denoiseCmosRedBlueCached_fragmentShaderSource +03_denoise/denoiseCmosRedBlueCached_0x30a8aac.comp,03_denoise,compute,ca61491ffb337d564307251c8a95970840228afdc8555f3bb23f75210ea13c12,6345,167,0x30a8aac,denoiseCmosRedBlueCached_computeShaderSource +03_denoise/denoiseGray_0x3068e79.comp,03_denoise,compute,3b723b58db314faac1498ff32b0957b78e2656ad65c28e36e11f52941507401f,8540,216,0x3068e79,denoiseGray_computeShaderSource +03_denoise/noiseMinMax_0x3087ae6.frag,03_denoise,fragment,55a11b0d14cc518110a0c76d9f01a7fb64092fddbc6f6996b1c321964bd9d0fe,1751,51,0x3087ae6,noiseMinMax_fragmentShaderSource +03_denoise/rgbNoise_0x3013e52.frag,03_denoise,fragment,7487a80208c3945d4a0dbdefb2ae83b6696e263985891ee717e0b57ee421b82a,423,20,0x3013e52,rgbNoiseShader +03_denoise/rgbnr_0x3072e51.frag,03_denoise,fragment,0e308203f748e9d878cfd3e0006993f4df8c422e6922b8ad5118a91254fc4103,1821,57,0x3072e51,rgbnr_fragmentShaderSource +03_denoise/rgbnrcdiff_0x309776e.frag,03_denoise,fragment,54386a68d91b8e178b310919a8c991f2752bdd840fe5a53f4c855be5f7a4f8fb,2079,67,0x309776e,rgbnrcdiff_fragmentShaderSource +03_denoise/rgbnrcdiff_0x30a4eb3.comp,03_denoise,compute,52a7d714fa3dcf908389eec8b53aa2dff3e506042127e90909b014dae1708afd,2207,70,0x30a4eb3,rgbnrcdiff_computeShaderSource +03_denoise/rgbnrsimple_0x30ac478.comp,03_denoise,compute,9069bc90a27a2f0b5a7724407e599df01fe3ff0bcd1e09204c41b787eca9886e,2963,96,0x30ac478,rgbnrsimple_computeShaderSource +03_denoise/rgbnrsimple_NoNR_0x30153ac.frag,03_denoise,fragment,0c10fd81f389dc085b1747e60fd9c8c89771230c59cddaa9e8abd4092f901a70,357,17,0x30153ac,rgbnrsimple_NoNR_fragmentShaderSource +03_denoise/rgbnrsimple_RGB16_16_0x307cc98.frag,03_denoise,fragment,e920533ef360bffa8007445902f5797a221900d0bb56e70312ee08e9ad0135ce,1535,56,0x307cc98,rgbnrsimple_RGB16_16_fragmentShaderSource +03_denoise/rgbnrsimple_RGB_4_4_0x3090b73.frag,03_denoise,fragment,47f84ed81f1b2e6cbf16d0263c68697e45353b60ae7299e49cc0614268962284,1534,56,0x3090b73,rgbnrsimple_RGB_4_4_fragmentShaderSource +03_denoise/rgbnrsimple_RGB_8_8_0x3033552.frag,03_denoise,fragment,17b63bef6865200eff7286b24f7f02ed3f28adf656a0f7402779fce3e2a77488,1534,56,0x3033552,rgbnrsimple_RGB_8_8_fragmentShaderSource +04_color_tone/ColorCorrectAll_0x301a79e.frag,04_color_tone,fragment,e88d1cf208ed2067ae4d435a12d1f7cc5ff1367b004315b1c823a6c99f7ee6bf,8370,255,0x301a79e,ColorCorrectAllShader +04_color_tone/HighlightStrength_0x3019721.frag,04_color_tone,fragment,7e01c980ca698783302664399c9fbbf037d161e4df32398671c1faab48b60701,4220,116,0x3019721,HighlightStrengthShader +04_color_tone/colorCorrectAll_0x3027dea.frag,04_color_tone,fragment,dbaac65ca38e9a2fc2156b3cdce40f6bc9ef41150a8e7c5e2473b7556f7de8e7,7885,250,0x3027dea,colorCorrectAll_fragmentShaderSource +04_color_tone/color_correct_0x303b6ab.comp,04_color_tone,compute,708bb034bd1ad908db5512e780831df43eae055e5b1752f29d49d8710d1ed0b5,5078,144,0x303b6ab,color_correct_computeShaderSource +04_color_tone/colorspaceconvert_0x2ff7cb6.frag,04_color_tone,fragment,4af76a0e1e5dc2e9d4788f439d2c1615d0e1086a480d91d016b8d12d9a51f5d6,4419,148,0x2ff7cb6,colorspaceconvert_fragmentShaderSource +04_color_tone/customCmm_0x3011778.frag,04_color_tone,fragment,1d2a52b7d24ec0b6d2d2b4100a2c467d18b50a73cd46a5570e77fd86788fe7a7,2072,73,0x3011778,customCmm_fragmentShaderSource +04_color_tone/customColorSpace_0x3034aab.frag,04_color_tone,fragment,a2290578fd48972ba0cb065428ae5307ac013d2b0d0f4607d20014b480e3c842,2256,77,0x3034aab,customColorSpaceShader +04_color_tone/desatHighLight_0x308164a.frag,04_color_tone,fragment,22ee7adff61fc23e5f879983fa06ae574dbfc040734178d2c83992d4f2350fcc,2406,103,0x308164a,desatHighLight_computeShaderSource +04_color_tone/desatHighLight_0x308e22a.frag,04_color_tone,fragment,992c5335469160b73bcabb680b1cead43a5e0c7669ac3aad4f3c196eb8ac55c3,2536,110,0x308e22a,desatHighLight_fragmentShaderSource +04_color_tone/filmCurve_0x30a3daf.frag,04_color_tone,fragment,7272d4bc97a33ee3855b9d2a7cad4d0843a6480c8fa8cd2341f65b3e6c429e8c,1039,37,0x30a3daf,filmCurveShader +04_color_tone/filmcurve_0x3040c4d.frag,04_color_tone,fragment,c678f85151e14960313ee0e0b16fa1ed9c6041ac3144a9f1174a76853e540d17,1121,41,0x3040c4d,filmcurve_fragmentShaderSource +04_color_tone/gamma_hasselblad_0x30776ff.frag,04_color_tone,fragment,121ebee892224e11b60d72f04e14bd10e2c685e2fdc66d5f4f8dae647bd0e421,478,19,0x30776ff,gamma_hasselblad_fragmentShaderSource +04_color_tone/gamma_lstar_0x307356f.frag,04_color_tone,fragment,3bdbd36600685c42e163ed2aed8e89cb2135cb71e3601d7b002681c923cdcaaf,786,28,0x307356f,gamma_lstar_fragmentShaderSource +04_color_tone/gradation_0x30778de.frag,04_color_tone,fragment,c6952101afd99df4bc3bb0f5b3061b5b7dfaca6392921b3758889f0a6b1aa926,4643,157,0x30778de,gradation_fragmentShaderSource +04_color_tone/highlightstrength_0x3035fd3.frag,04_color_tone,fragment,8c19ed4877e76b4394bb4dd802c890a081f0ba79a1ebcc68ea39c5c5ecfce6b7,4214,116,0x3035fd3,highlightstrength_fragmentShaderSource +04_color_tone/mark_hue_0x30504eb.frag,04_color_tone,fragment,6db1863654d4ec5103e4bc0fdf6e1fddc612afed52d72e114956e65562b7e359,2013,59,0x30504eb,mark_hue_fragmentShaderSource +04_color_tone/rgb2GrayRgb_0x309e5f3.comp,04_color_tone,compute,b781b236056b8b51679cea5da2e98b07839ed5db74eedbec1a0123685792bff7,2403,74,0x309e5f3,rgb2GrayRgb_computeShaderSource +04_color_tone/rgb2Gray_0x2ffe79a.comp,04_color_tone,compute,69b2e3e5510029dac6d1416980e258fdf5c924a43de19e2cb36feb8bc223dd34,2983,78,0x2ffe79a,rgb2Gray_computeShaderSource +04_color_tone/sdr_icc_0x3073d21.frag,04_color_tone,fragment,9f2ec2781a1b115048553c5aba7b729e60c43f6332cc9e4046a4866da43e658e,1472,58,0x3073d21,sdr_icc_fragmentShaderSource +04_color_tone/selectivecolor_0x3088ea2.frag,04_color_tone,fragment,23d9a908fe2ae5baf5f578bac46cbcbb30f711900eef5851e42d60c8441dcc24,5607,172,0x3088ea2,selectivecolor_fragmentShaderSource +04_color_tone/unattributed_0x30308d7_0x30308d7.frag,04_color_tone,fragment,0019263ccb2e3a738b9c6014820b560dc84c5c474955760e2baaf968fab453f0,498,16,0x30308d7, +04_color_tone/unattributed_0x30347c3_0x30347c3.frag,04_color_tone,fragment,555706c2932277ee62b250ebd2625afe9c4e80de00db5e77c6dd38e9bdccd000,209,12,0x30347c3, +04_color_tone/unattributed_0x3065982_0x3065982.frag,04_color_tone,fragment,6f90e80f6193d57e5ee7d79a3beb75aa77d22320d0ecdea771c7580ea2a3cb29,326,12,0x3065982, +04_color_tone/unattributed_0x3079cc5_0x3079cc5.frag,04_color_tone,fragment,d54349859e4310755952cd52a6dce6eacd6e4a8f4cb54b3824a086bd397d19b8,3358,88,0x3079cc5, +04_color_tone/unattributed_0x307f4f7_0x307f4f7.frag,04_color_tone,fragment,93d00d0f37ad0f65522194209275aab523fabc1c8173df5550ca7e0c94a46613,177,12,0x307f4f7, +05_lens_geometry/KeystoneBilinear_0x300f494.frag,05_lens_geometry,fragment,6e41522c4cdf78a589f1e2d7a5cefc0ba1ed514b23edd3369992f0cf90c97e98,1822,56,0x300f494,KeystoneBilinear_fragmentShaderSource +05_lens_geometry/Keystone_0x30847c0.frag,05_lens_geometry,fragment,d3956e2b1df06d05398033f10af7f36f5651d91db0173fa1dc2232390ff8b8dd,5010,120,0x30847c0,Keystone_fragmentShaderSource +05_lens_geometry/alignment_0x3025a0f.frag,05_lens_geometry,fragment,4f0ff853370d74ed985ade5b3f8e5a403962af5789f8eca38a4b97cdc1863fa0,307,15,0x3025a0f,alignment_fragmentShaderSource +05_lens_geometry/grayVignetteCS_0x300a1ea.comp,05_lens_geometry,compute,76ab07ae2bc82a0a7f67d73044d2eff9fdda40e911b98645b3cb935129eeef0c,7011,186,0x300a1ea,grayVignetteCS_computeShaderSource +05_lens_geometry/grayVignetteHtsCS_0x306f136.comp,05_lens_geometry,compute,a462ddc6676773abca3e4f28156aaafddc7924aeab527f6b5d0b63026dd585f5,7262,194,0x306f136,grayVignetteHtsCS_computeShaderSource +05_lens_geometry/htsAberrationCS_0x309f9c3.comp,05_lens_geometry,compute,a7d6c853553ca43a007eca52070267af41ea92582da3e951654cd68728e732c2,7266,183,0x309f9c3,htsAberrationCS_computeShaderSource +05_lens_geometry/orientation_rgb180_0x306e4e6.frag,05_lens_geometry,fragment,81dae8448e22d2a50d7394fbb542a5d64f9d534f5b32b392979fed8612b174d5,412,20,0x306e4e6,orientation_rgb180_fragmentShaderSource +05_lens_geometry/orientation_rgb270_0x303edb0.frag,05_lens_geometry,fragment,b20405eac1c785d1a0359002535ad92b2338a72100b12fd83c800123eb490e83,414,20,0x303edb0,orientation_rgb270_fragmentShaderSource +05_lens_geometry/orientation_rgb90_0x307d298.frag,05_lens_geometry,fragment,b379afb58ea22e4d0d0f4fa880dc1ee053d527d3a82fdb86881459b5a8aee522,415,20,0x307d298,orientation_rgb90_fragmentShaderSource +05_lens_geometry/repeatMargin_0x3084296.frag,05_lens_geometry,fragment,9373e67d9d551351332bb5ad0d8727a1e3a8524bd8cf1d63d27a92baab843eb5,1321,54,0x3084296,repeatMargin_fragmentShaderSource +05_lens_geometry/resize_0x3029cb8.frag,05_lens_geometry,fragment,8c44c4f649d107b2346725d1b018d85e426fded06bd05fbb5a836dbeaf45e569,2381,72,0x3029cb8,resize_fragmentShaderSource +05_lens_geometry/resizeintegraldown_0x2ffcdeb.frag,05_lens_geometry,fragment,abc100e93094e15844f1aac7761b8b78aa5ac10d1fc122c86a131473eb3c0293,1160,46,0x2ffcdeb,resizeintegraldown_fragmentShaderSource +05_lens_geometry/resizesplinehorizontal_0x30768a8.frag,05_lens_geometry,fragment,b89be0128b31698dc01785802e45d89a1313909f8f829e4c5e008788151cdaaa,3670,129,0x30768a8,resizesplinehorizontal_fragmentShaderSource +05_lens_geometry/resizesplinevertical_0x3063ecb.frag,05_lens_geometry,fragment,11d86a505f5d8f109ce72cdb0b7391d559cf63aeaf7e3b6be57081bf47852d81,3518,127,0x3063ecb,resizesplinevertical_fragmentShaderSource +05_lens_geometry/rgbLensFilter_0x2fff342.frag,05_lens_geometry,fragment,242f8a575c32fa3e5b0867f2b2fc3f678bbc86df9650b329650917b3773fc73a,16716,408,0x2fff342,rgbLensFilter_fragmentShaderSource +05_lens_geometry/rgbLensFilter_0x3057352.comp,05_lens_geometry,compute,a21099023c7ef59d903395303ee0c0bfdfe05463d171713e599ee2d21d390291,15003,341,0x3057352,rgbLensFilter_computeShaderSource +05_lens_geometry/standardAberrationCS_0x300fbb3.comp,05_lens_geometry,compute,c17ca8323bf2ae866a700a7e8c03b26006646dc582b747033507adcf8e4295bb,7108,175,0x300fbb3,standardAberrationCS_computeShaderSource +05_lens_geometry/unattributed_0x2ffac4a_0x2ffac4a.frag,05_lens_geometry,fragment,cf8cb93c8b2a90f34a0a41f45509b621135134b1785a57f49437fb5e1813b76b,562,19,0x2ffac4a, +05_lens_geometry/unattributed_0x2ffae7d_0x2ffae7d.frag,05_lens_geometry,fragment,e9f99a8ec73e205e70886530d9f6f60bedd45a4817119e988b77824e84df52db,2222,45,0x2ffae7d, +05_lens_geometry/unattributed_0x3003732_0x3003732.frag,05_lens_geometry,fragment,e42cf5f03a11d8eac27fcc414f6c9d09ee9fd18432530f1d574e0269b8e3139a,879,22,0x3003732, +05_lens_geometry/unattributed_0x300c4fc_0x300c4fc.frag,05_lens_geometry,fragment,68a09bfc4c6bdfd4c327b840a8fe3d2810a7e7b3bb1ccabd50f31c7bdb1461ad,970,24,0x300c4fc, +05_lens_geometry/unattributed_0x30218ea_0x30218ea.frag,05_lens_geometry,fragment,45417504420c2e766d3dc2ace48fc785e9aa1f665d9aa42a7968dd9d0117a8b6,2637,67,0x30218ea, +05_lens_geometry/unattributed_0x3025d0b_0x3025d0b.frag,05_lens_geometry,fragment,be7df9e0bd89a0467177c64df289d56f33585086266c451a570a4e8f93d011b4,970,24,0x3025d0b, +05_lens_geometry/unattributed_0x303011d_0x303011d.frag,05_lens_geometry,fragment,4788646eb655664ed70590e8ac61a52dd2bb31df68599569683e0569158980a0,1977,57,0x303011d, +05_lens_geometry/unattributed_0x3038f66_0x3038f66.frag,05_lens_geometry,fragment,05317b455a0d1d6d9afaa741b05bc34fe23073556dabb500068780abae76dd1c,763,20,0x3038f66, +05_lens_geometry/unattributed_0x303ca82_0x303ca82.frag,05_lens_geometry,fragment,eca183311e10a8a3832fb3b176a9a9df0b7c91c53f8ffdba2ea6c20302d050a1,660,21,0x303ca82, +05_lens_geometry/unattributed_0x303cd17_0x303cd17.frag,05_lens_geometry,fragment,5edd39c1c209941815ef719ebd68a0ad5b9d44e5c6af1634e7dc3d0fbeb2a469,659,19,0x303cd17, +05_lens_geometry/unattributed_0x3043a7a_0x3043a7a.frag,05_lens_geometry,fragment,5032f05ce79cbaba7a0539c9611235df091957795672a17f3d77457625d85336,2410,69,0x3043a7a, +05_lens_geometry/unattributed_0x3053268_0x3053268.frag,05_lens_geometry,fragment,64f9d74a6693cf3660eb633e889e91c4f7e549865bbd55d05ca1472287c93990,705,17,0x3053268, +05_lens_geometry/unattributed_0x3061f15_0x3061f15.frag,05_lens_geometry,fragment,9071061620f2032c7d385e1156c3d06346385976d258aca5b8ff4506dd916d9d,700,18,0x3061f15, +05_lens_geometry/unattributed_0x306afe7_0x306afe7.frag,05_lens_geometry,fragment,ecb85eb3453ecfb72f032d171bef7287a0479132b7ff0187712f82bb054a13ab,4043,98,0x306afe7, +05_lens_geometry/unattributed_0x3070da7_0x3070da7.frag,05_lens_geometry,fragment,2eb6d3e8b25809b4772134c99864f4d403f8e3b612ed55cf51f6735b01cb1c0b,970,23,0x3070da7, +05_lens_geometry/unattributed_0x3074cae_0x3074cae.frag,05_lens_geometry,fragment,1441f909272ff89a1ba21e4def13bdbf502cc17466443f8d592bd9476ed07270,938,23,0x3074cae, +05_lens_geometry/unattributed_0x30798c4_0x30798c4.frag,05_lens_geometry,fragment,853517e8aca4276ea2c5a150fbce0d3b1efcad5d72a9787163870dabe8f72378,1024,22,0x30798c4, +05_lens_geometry/unattributed_0x307dbfe_0x307dbfe.frag,05_lens_geometry,fragment,c677a27ae799ca3cd71bd19448694c490a92a3d4f16b9c8a76dbb9c487064425,1133,26,0x307dbfe, +05_lens_geometry/unattributed_0x307e06c_0x307e06c.frag,05_lens_geometry,fragment,40ac286da16f404b179d003f86ec7776fd5ab941355fe543a4ea6852cf2f1edd,1472,27,0x307e06c, +05_lens_geometry/unattributed_0x309326d_0x309326d.frag,05_lens_geometry,fragment,bbff5e6f1bc6526815897213461384a89b1a8ec3314f34dce3c3e66018cd73c9,874,26,0x309326d, +05_lens_geometry/unattributed_0x30953e0_0x30953e0.frag,05_lens_geometry,fragment,6cfbe5b95c1509f6c7a20872b414c64d5150482481be8130ee510028bf0f8eaf,1912,43,0x30953e0, +06_detail_texture/cikernel_create_film_grain_0x306e683.frag,06_detail_texture,fragment,a18e2b102dc046b550c62dc3b340b25376d05213b5b17078066d2835548fbcff,2738,94,0x306e683,cikernel_create_film_grain_fragmentShaderSource +06_detail_texture/cikernel_create_film_grain_blend_0x309ef57.frag,06_detail_texture,fragment,b72f1aaffa4d668aa8fef8bf9d539bb56950c28e9c53f3b0e47dcd4227ed5010,2667,88,0x309ef57,cikernel_create_film_grain_blend_fragmentShaderSource +06_detail_texture/clarityBlendBlurU16_0x301683e.comp,06_detail_texture,compute,808b8fd80c4d37ccba8fc0e4c6fef3f3cceeb388cc3ed780dbfb2462afce49e3,7430,179,0x301683e,clarityBlendBlurU16_computeShaderSource +06_detail_texture/clarityBlendGlobal2U16_0x307d4af.comp,06_detail_texture,compute,6b8f2d419337fcc8a01151c32132da494e4ca9eebdb9143574c425b4c88edf2c,1844,50,0x307d4af,clarityBlendGlobal2U16_computeShaderSource +06_detail_texture/clarityBlendGlobalNextU16_0x307923d.comp,06_detail_texture,compute,7c86fb5c5d04a646487d987a21565b88b35a9bb9c4c04b0710e1535ff06c8e80,1477,45,0x307923d,clarityBlendGlobalNextU16_computeShaderSource +06_detail_texture/clarityBlendLocal2F_0x308b9bd.comp,06_detail_texture,compute,f9fe5e156ec69fb7cb7368c5691d79a4d33a6e178974d4765cbe291550ff6527,1754,47,0x308b9bd,clarityBlendLocal2F_computeShaderSource +06_detail_texture/clarityBlendLocalNextF_0x3092c99.comp,06_detail_texture,compute,bb147c1fa1de6c8e4e6f9ee0b6ff48bb39b16fe8a66e5234a7bfdf66ed326f11,1425,43,0x3092c99,clarityBlendLocalNextF_computeShaderSource +06_detail_texture/clarityBlendNoLutU16_0x3051d04.comp,06_detail_texture,compute,8b77e58847de0bf89a07d52d07156cf6b8b3b8f46f43ebf3cdbeb4cffa81719a,5475,136,0x3051d04,clarityBlendNoLutU16_computeShaderSource +06_detail_texture/clarityCombineFinal4U16_0x301e906.comp,06_detail_texture,compute,14ec460a9b79553f33b090ab75ff8e3a9897c15eb3d346703914db856fdab2df,4441,97,0x301e906,clarityCombineFinal4U16_computeShaderSource +06_detail_texture/clarityCreateFinalFactorsU16_0x30742e2.comp,06_detail_texture,compute,447319113a0246e3a4198ff07eb0fcbe40f1bc25ce32f667bb79e698e206b3d5,2423,52,0x30742e2,clarityCreateFinalFactorsU16_computeShaderSource +06_detail_texture/clarityDiscretImage4CenterValU16_0x2ffa214.comp,06_detail_texture,compute,ffddf4600d0c7322e96cdcb76b02364d0dab0d4054c1f25090cb2249815e16eb,2577,83,0x2ffa214,clarityDiscretImage4CenterValU16_computeShaderSource +06_detail_texture/clarityDownScaleBlurU16_0x3050cc9.comp,06_detail_texture,compute,da8e09ea72af7aacdf5cdcfbee513b4b7deca33651e75506d7d245a8606e756d,4154,152,0x3050cc9,clarityDownScaleBlurU16_computeShaderSource +06_detail_texture/clarityFastPreviewApply_0x30b231c.comp,06_detail_texture,compute,ec451ea570b0870fb0b16d88ca2ba0ca3b4d5c135696acffaa0d9f070349d659,2080,56,0x30b231c,clarityFastPreviewApply_computeShaderSource +06_detail_texture/clarityGrayImage4CenterValU16_0x300bd4e.comp,06_detail_texture,compute,54c35774225149ef4345604d5dbd9ea8016a8f6e3ddfea8dafda40aa17b5d450,1965,63,0x300bd4e,clarityGrayImage4CenterValU16_computeShaderSource +06_detail_texture/clarityHRLut_0x3018545.comp,06_detail_texture,compute,c6ae77a81dd90ba4bd65dbd390ad5e7f025658e36eed95f19a4483189728b65a,998,37,0x3018545,clarityHRLut_computeShaderSource +06_detail_texture/clarityPackedU16MaxToR32F_0x301ded0.comp,06_detail_texture,compute,18c919f2a855b3727299372c559d2974204d7af412e135e2a4e5d540671d98c0,991,31,0x301ded0,clarityPackedU16MaxToR32F_computeShaderSource +06_detail_texture/clarityReduceMaxFinalU16_0x3025b43.comp,06_detail_texture,compute,b99c85bb66f9676d006069f148994d40ab48bb4bfba6363d68f1bea39d10d62c,431,16,0x3025b43,clarityReduceMaxFinalU16_computeShaderSource +06_detail_texture/clarityReduceMax_0x301db79.comp,06_detail_texture,compute,d39ab75d0a0c31220083b5b7dd7532f3918e7bd91c09a7eb482c9ad546043832,854,28,0x301db79,clarityReduceMax_computeShaderSource +06_detail_texture/clarityRgb2Gray4U16_0x301e2b0.comp,06_detail_texture,compute,914e2b18fb091144567c4ae84d992c382bd7796c43b148b6e0cc25ca78e394f4,1621,39,0x301e2b0,clarityRgb2Gray4U16_computeShaderSource +06_detail_texture/claritySFLut_0x3078d0e.comp,06_detail_texture,compute,e2b02c9c3e8725068a274907ad78184ad82f8710af722a4266e8f8c51943e07b,1326,48,0x3078d0e,claritySFLut_computeShaderSource +06_detail_texture/claritySubtractColTileU16_0x30a1fbe.comp,06_detail_texture,compute,8d16470f554de7df8693c89071c77ac19f5ef17534834471d501cee1ded83566,3399,85,0x30a1fbe,claritySubtractColTileU16_computeShaderSource +06_detail_texture/clarityUpScaleBlurSubAggU16_0x308a48a.comp,06_detail_texture,compute,634bb04af760629a50d330b5e6d8ce621f2cadd6f146a0392ddef5f751d6c1a0,5426,134,0x308a48a,clarityUpScaleBlurSubAggU16_computeShaderSource +06_detail_texture/clarityUpScaleBlurSubU16_0x3011f91.comp,06_detail_texture,compute,287d98c06c9498f2acce80018ba202c18849ea0ced91c3b7752762db807a36f4,4796,141,0x3011f91,clarityUpScaleBlurSubU16_computeShaderSource +06_detail_texture/clarityUpScaleBlurU16_0x3042806.comp,06_detail_texture,compute,b35bf0d4ebfddaa394164ed49a6b1edde47e76976f1006eae1a95e4fe002cbc7,4723,119,0x3042806,clarityUpScaleBlurU16_computeShaderSource +06_detail_texture/create_film_grain_0x30881be.frag,06_detail_texture,fragment,9312a458283d0b188770711e68a03cbb84c9ee17851521bfade82007f52f9460,3299,112,0x30881be,create_film_grain_fragmentShaderSource +06_detail_texture/create_film_grain_blend_0x30080d5.frag,06_detail_texture,fragment,7e1601b076fb3e2aa1b3dcf0a77dc7b6ae8555136d2a6864cdee1bfd931ec68d,3129,103,0x30080d5,create_film_grain_blend_fragmentShaderSource +06_detail_texture/highRes_0x300594b.frag,06_detail_texture,fragment,39b941a0ef0e16ff4cf5231186f633cf3d1a21f5c496012c87ee2fb9073b2528,292,16,0x300594b,highRes_fragmentShaderSource +06_detail_texture/highRes_0x30a3c90.frag,06_detail_texture,fragment,d43e6aa98922e4a70817554264c0ec3a782bccc2f7ee86eea4d6b2d01b069610,286,16,0x30a3c90,highResShader +06_detail_texture/unsharpMask_0x300e6ad.frag,06_detail_texture,fragment,97a3f91b9d73967ef8a151f9682d7ea985f95daa0f17389816e0aebcd40f95ad,3558,130,0x300e6ad,unsharpMask_fragmentShaderSource +06_detail_texture/unsharpMask_blend_0x3015512.frag,06_detail_texture,fragment,56d92138369c752b7f33e32596e8e89b847aca6c8d34edd223aa24b03c2da76a,4147,124,0x3015512,unsharpMask_blend_fragmentShaderSource +06_detail_texture/unsharpMask_ver_0x2ff9bfb.frag,06_detail_texture,fragment,c868449deef611e5f8a422c002f45d7af1884f8a49c6e911ee974588ca423bf8,1560,68,0x2ff9bfb,unsharpMask_ver_fragmentShaderSource +07_hdr_ultrahdr/CalculateGainMap_0x3007808.frag,07_hdr_ultrahdr,fragment,91720a36f5ddf2e5682998f88b0e7b64a67bbd938b901c3aef332ec5e4c73b81,2252,71,0x3007808,CalculateGainMap_fragmentShaderSource +07_hdr_ultrahdr/applyhdrgainmapyuv_0x30a1626.frag,07_hdr_ultrahdr,fragment,1ba7069316d7577133e3e7016a4aafbed85fa99459e1403a06f899ac94f7a07e,2455,95,0x30a1626,applyhdrgainmapyuv_fragmentShaderSource +07_hdr_ultrahdr/hdr_0x30b046e.frag,07_hdr_ultrahdr,fragment,61d96c794a0bb8bb0d588ef4c5b792793971bdcc73cc92994129331f686949c8,407,22,0x30b046e,hdrShader +07_hdr_ultrahdr/hdr_gamma22_0x30878f3.frag,07_hdr_ultrahdr,fragment,a38c2123a061abc12f46152f00b08b8964c81fa0f027a5c3d28c1ae96824329b,498,22,0x30878f3,hdr_gamma22_fragmentShaderSource +07_hdr_ultrahdr/hdr_lstar_0x30463fa.frag,07_hdr_ultrahdr,fragment,90cc5ac2e908659c19bc8034fda56ad05c823639ae0190a6eea378ee396428b8,743,30,0x30463fa,hdr_lstar_fragmentShaderSource +99_unattributed/blend_film_0x3091172.frag,99_unattributed,fragment,6f5a415b9a5b03f63076fed61003d2bf09f8794669895db848df91efef8e2adb,6950,213,0x3091172,blend_film_fragmentShaderSource +99_unattributed/ev_0x30b1024.frag,99_unattributed,fragment,24294ea4f1e778a2a042f992930bcb4cd1ffeefa35dc56093993040b054f3b88,833,30,0x30b1024,ev_fragmentShaderSource +99_unattributed/highlightRecover_0x307f63c.frag,99_unattributed,fragment,27f287476ef495e8bc566249b46216f0cba1d8540d83cee77915f93dad53a1f5,5093,124,0x307f63c,highlightRecoverShader +99_unattributed/reversecc_0x3061507.frag,99_unattributed,fragment,5f4bda2cc5a1f9e2214c3caf0d9667dc1b42455e50d9ccc2a47b627f38303abe,2548,96,0x3061507,reversecc_fragmentShaderSource +99_unattributed/shader_0x3066a62.frag,99_unattributed,fragment,a0b9040c8836f53fb25c010f6c687550f122906977f9d0c82ba3bb5f2d63c253,310,15,0x3066a62,fragmentShaderSource +99_unattributed/unattributed_0x308338f_0x308338f.vert,99_unattributed,vertex,931e3e990f6bc5b1c5054dc46aa339c104ed60393908c8d56fee3d564f7ab898,191,8,0x308338f, +99_unattributed/usm_0x3023371.frag,99_unattributed,fragment,2bf98f5b7d9fed788ba4a5fa3a532cee761edddfc47bf54b34e76225416543f5,2398,77,0x3023371,usmShader diff --git a/research/phocus_glsl/manifest.json b/research/phocus_glsl/manifest.json new file mode 100644 index 00000000..b0a5b954 --- /dev/null +++ b/research/phocus_glsl/manifest.json @@ -0,0 +1,3282 @@ +{ + "source_binary": "C:\\Users\\Hinnka\\Desktop\\phocus\\app\\src\\main\\lib\\arm64-v8a\\libcrosssdk.so", + "stats": { + "binary_bytes": 80752632, + "version_markers": 177, + "glsl_occurrences": 177, + "unique_sources": 177, + "exported_source_symbols": 150, + "resolved_source_symbols": 150, + "unresolved_source_symbols": 0, + "attributed_occurrences": 150, + "unattributed_occurrences": 27 + }, + "categories": [ + "00_common_io", + "01_raw_sensor", + "02_demosaic", + "03_denoise", + "04_color_tone", + "05_lens_geometry", + "06_detail_texture", + "07_hdr_ultrahdr", + "99_unattributed" + ], + "shaders": [ + { + "file": "00_common_io/FillWithBlack_0x307d438.frag", + "category": "00_common_io", + "stage": "fragment", + "sha256": "70223e71cb5ac64567b5380e8fbaa255c1b38e255e8da0de9b80fec97863dd6e", + "bytes": 118, + "lines": 9, + "symbols": [ + "FillWithBlack_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x307d438", + "symbols": [ + "FillWithBlack_fragmentShaderSource" + ] + } + ] + }, + { + "file": "00_common_io/block_downsample_0x3065745.frag", + "category": "00_common_io", + "stage": "fragment", + "sha256": "0a3908a02d09d48093007d130c8f231301025cfc3890bab1224d325af566ca28", + "bytes": 502, + "lines": 23, + "symbols": [ + "block_downsample_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3065745", + "symbols": [ + "block_downsample_fragmentShaderSource" + ] + } + ] + }, + { + "file": "00_common_io/commonVertex_0x3004aaf.vert", + "category": "00_common_io", + "stage": "vertex", + "sha256": "2cabc41351a224550887e53887d0bd2958eeeb6324ec7d02bc6f45ec0e7b30f5", + "bytes": 191, + "lines": 11, + "symbols": [ + "commonVertexShaderSource" + ], + "occurrences": [ + { + "offset": "0x3004aaf", + "symbols": [ + "commonVertexShaderSource" + ] + } + ] + }, + { + "file": "00_common_io/formatConvertHalfFloatToU16_0x300348f.comp", + "category": "00_common_io", + "stage": "compute", + "sha256": "bcce94a076806ceb2369010b6db78f96e941170b371e5b72615c3be5dc9134ad", + "bytes": 564, + "lines": 18, + "symbols": [ + "formatConvertHalfFloatToU16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x300348f", + "symbols": [ + "formatConvertHalfFloatToU16_computeShaderSource" + ] + } + ] + }, + { + "file": "00_common_io/formatConvertU16ToHalfFloat_0x3078b02.comp", + "category": "00_common_io", + "stage": "compute", + "sha256": "ea09e7937d80f293bd7655abc6e2abde296abeb033cc3b2d91dd064b9b4a5fc6", + "bytes": 523, + "lines": 18, + "symbols": [ + "formatConvertU16ToHalfFloat_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3078b02", + "symbols": [ + "formatConvertU16ToHalfFloat_computeShaderSource" + ] + } + ] + }, + { + "file": "00_common_io/shader_0x30451f3.vert", + "category": "00_common_io", + "stage": "vertex", + "sha256": "8b5fee15a4bd109c8dd4d558c7eea81e9fb81539cdd38698c736ae55f8644956", + "bytes": 294, + "lines": 14, + "symbols": [ + "vertexShaderSource" + ], + "occurrences": [ + { + "offset": "0x30451f3", + "symbols": [ + "vertexShaderSource" + ] + } + ] + }, + { + "file": "00_common_io/shift_0x30aa376.frag", + "category": "00_common_io", + "stage": "fragment", + "sha256": "ceeb71df7570cf8008284d9f509049a60ddc160aed621ed97e82a8a985a529b5", + "bytes": 859, + "lines": 38, + "symbols": [ + "shift_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30aa376", + "symbols": [ + "shift_fragmentShaderSource" + ] + } + ] + }, + { + "file": "00_common_io/u16f28ui_0x302addd.frag", + "category": "00_common_io", + "stage": "fragment", + "sha256": "c5c354119ccc00f88f045a9b4300fd2d00e8bfabfeb9e4bb21433cf1bf76cc11", + "bytes": 432, + "lines": 16, + "symbols": [ + "u16f28ui_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x302addd", + "symbols": [ + "u16f28ui_fragmentShaderSource" + ] + } + ] + }, + { + "file": "00_common_io/yuv2rgb_0x3016546.frag", + "category": "00_common_io", + "stage": "fragment", + "sha256": "5a8b0395d4fc2353a8e44245d6080723fe24656140f8bf28d5346c93ae6adb5d", + "bytes": 759, + "lines": 33, + "symbols": [ + "yuv2rgb_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3016546", + "symbols": [ + "yuv2rgb_fragmentShaderSource" + ] + } + ] + }, + { + "file": "01_raw_sensor/bayerfastinterpolatefull_0x2ffd274.frag", + "category": "01_raw_sensor", + "stage": "fragment", + "sha256": "9d87df9b959daa41f5d8eb526f3af10c4fc082485de9a1b3cfc94a50fb9bd795", + "bytes": 5413, + "lines": 139, + "symbols": [ + "bayerfastinterpolatefull_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x2ffd274", + "symbols": [ + "bayerfastinterpolatefull_fragmentShaderSource" + ] + } + ] + }, + { + "file": "01_raw_sensor/bayerfastinterpolatehalf_0x302a606.frag", + "category": "01_raw_sensor", + "stage": "fragment", + "sha256": "805ab3ff49fd22152dce086812cac32e9062ddc56861d30aa04aa2b12c46def2", + "bytes": 2006, + "lines": 79, + "symbols": [ + "bayerfastinterpolatehalf_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x302a606", + "symbols": [ + "bayerfastinterpolatehalf_fragmentShaderSource" + ] + } + ] + }, + { + "file": "01_raw_sensor/blackLevelSubstract_0x3068cdb.frag", + "category": "01_raw_sensor", + "stage": "fragment", + "sha256": "7181e8fe4ab1bebbe1039474ace74f997cc0ca1ee20e6e7aaec7ef86a4deb6ac", + "bytes": 413, + "lines": 18, + "symbols": [ + "blackLevelSubstract_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3068cdb", + "symbols": [ + "blackLevelSubstract_fragmentShaderSource" + ] + } + ] + }, + { + "file": "01_raw_sensor/highlightrecoveryscalarrgb_0x304d54d.frag", + "category": "01_raw_sensor", + "stage": "fragment", + "sha256": "62a796eabf55c35aa9d70843c4c6670f47fc11b59a789fa59e3107a39383b2c4", + "bytes": 3683, + "lines": 127, + "symbols": [ + "highlightrecoveryscalarrgb_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x304d54d", + "symbols": [ + "highlightrecoveryscalarrgb_fragmentShaderSource" + ] + } + ] + }, + { + "file": "01_raw_sensor/hotPixelPlus_0x305adee.frag", + "category": "01_raw_sensor", + "stage": "fragment", + "sha256": "0791fa8fdf096adab2e55a65c1b68b0f4b1e31529202eb0153f89882ee21b144", + "bytes": 21780, + "lines": 378, + "symbols": [ + "hotPixelPlus_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x305adee", + "symbols": [ + "hotPixelPlus_fragmentShaderSource" + ] + } + ] + }, + { + "file": "01_raw_sensor/hotPixel_0x302af8e.frag", + "category": "01_raw_sensor", + "stage": "fragment", + "sha256": "8012955d7c0a1c85bc5fb7d07a3f289631214a7796b86283a33c7b201cd7ce76", + "bytes": 20854, + "lines": 358, + "symbols": [ + "hotPixel_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x302af8e", + "symbols": [ + "hotPixel_fragmentShaderSource" + ] + } + ] + }, + { + "file": "01_raw_sensor/multi2bayer_ms2bayer3_0x303310c.frag", + "category": "01_raw_sensor", + "stage": "fragment", + "sha256": "772e7494a86ba3a7164e9b369e45dd64a1104e56361efa9f6396d5ea49c6a7a9", + "bytes": 1093, + "lines": 40, + "symbols": [ + "multi2bayer_ms2bayer3_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x303310c", + "symbols": [ + "multi2bayer_ms2bayer3_fragmentShaderSource" + ] + } + ] + }, + { + "file": "01_raw_sensor/neutralisationBayer_0x30563ff.comp", + "category": "01_raw_sensor", + "stage": "compute", + "sha256": "54c8e19ec4e856f0546700e84db38fd1983f139aaf7c43e3323fb08650dcd9d4", + "bytes": 3922, + "lines": 100, + "symbols": [ + "neutralisationBayer_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x30563ff", + "symbols": [ + "neutralisationBayer_computeShaderSource" + ] + } + ] + }, + { + "file": "01_raw_sensor/neutralisationRgb_0x2ff8dfa.comp", + "category": "01_raw_sensor", + "stage": "compute", + "sha256": "f139a1b07826c300489b4392699d94238e6f34a998d4dba8d9ca80bf605e6539", + "bytes": 2391, + "lines": 71, + "symbols": [ + "neutralisationRgb_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x2ff8dfa", + "symbols": [ + "neutralisationRgb_computeShaderSource" + ] + } + ] + }, + { + "file": "01_raw_sensor/orientation_180_0x3073882.frag", + "category": "01_raw_sensor", + "stage": "fragment", + "sha256": "84412000fe0b6f27def36bdbb611fafd17343363c7d23dbecb0505ce87fad666", + "bytes": 1182, + "lines": 44, + "symbols": [ + "orientation_180_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3073882", + "symbols": [ + "orientation_180_fragmentShaderSource" + ] + } + ] + }, + { + "file": "01_raw_sensor/orientation_270_0x2ff9752.frag", + "category": "01_raw_sensor", + "stage": "fragment", + "sha256": "2fe79b91d74441a5a0d8daeb34f87e445ac128112c56008290fceab12d1311ab", + "bytes": 1192, + "lines": 44, + "symbols": [ + "orientation_270_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x2ff9752", + "symbols": [ + "orientation_270_fragmentShaderSource" + ] + } + ] + }, + { + "file": "01_raw_sensor/orientation_90_0x301d6cf.frag", + "category": "01_raw_sensor", + "stage": "fragment", + "sha256": "4802e80060871fd646ac34d63fa30b3779d034e42b559dc1054f76757737e36f", + "bytes": 1193, + "lines": 45, + "symbols": [ + "orientation_90_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x301d6cf", + "symbols": [ + "orientation_90_fragmentShaderSource" + ] + } + ] + }, + { + "file": "01_raw_sensor/sceneCalibrationBayer_0x3060303.comp", + "category": "01_raw_sensor", + "stage": "compute", + "sha256": "ad02e35cd008c247df53d43a9649af52f9063e142b0515ad179780c11c18585c", + "bytes": 4611, + "lines": 133, + "symbols": [ + "sceneCalibrationBayer_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3060303", + "symbols": [ + "sceneCalibrationBayer_computeShaderSource" + ] + } + ] + }, + { + "file": "01_raw_sensor/sceneCalibrationGray_0x30b1366.comp", + "category": "01_raw_sensor", + "stage": "compute", + "sha256": "b37680e4d072169a7a53fcdc209523e90d1154e05d5d45d437005db9c3ad2a47", + "bytes": 4021, + "lines": 116, + "symbols": [ + "sceneCalibrationGray_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x30b1366", + "symbols": [ + "sceneCalibrationGray_computeShaderSource" + ] + } + ] + }, + { + "file": "01_raw_sensor/sceneCalibrationRgb_0x3008d0f.comp", + "category": "01_raw_sensor", + "stage": "compute", + "sha256": "4e7ff25df3d5cf99208ee46fa417954a190ec2909af7bfb1eac95f363023f221", + "bytes": 5338, + "lines": 143, + "symbols": [ + "sceneCalibrationRgb_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3008d0f", + "symbols": [ + "sceneCalibrationRgb_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_calculate_color_noise_error_0x30062f5.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "6da3783cd147005c2750b1fe352a0110d3ca2c22e32c35691f4087f45ac1b17b", + "bytes": 2006, + "lines": 71, + "symbols": [ + "demosaic_calculate_color_noise_error_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x30062f5", + "symbols": [ + "demosaic_calculate_color_noise_error_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_color_noise_filter_0x3014da8.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "d2230d98ddb2e920f96ff833d6b2b064edfe1fd367f3f1b7a1e0dae591238f06", + "bytes": 1539, + "lines": 50, + "symbols": [ + "demosaic_color_noise_filter_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3014da8", + "symbols": [ + "demosaic_color_noise_filter_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_color_noise_pass_1_0x3081fb1.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "626b18a415bd88111972b31b26529cbc4c3f0fe86f066c6da8e5ba9b77c0052d", + "bytes": 1761, + "lines": 61, + "symbols": [ + "demosaic_color_noise_pass_1_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3081fb1", + "symbols": [ + "demosaic_color_noise_pass_1_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_color_noise_pass_2_0x3024978.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "77ecea4a4085c9678c82864b7a3a1633b9a173a2746a1c4fae420049edf24f6c", + "bytes": 4246, + "lines": 117, + "symbols": [ + "demosaic_color_noise_pass_2_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3024978", + "symbols": [ + "demosaic_color_noise_pass_2_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_color_noise_pass_3_0x3049e97.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "9f0f02155a6f509830d6ddc3afa540da03684b8c9d752d96012957f74090786e", + "bytes": 6408, + "lines": 177, + "symbols": [ + "demosaic_color_noise_pass_3_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3049e97", + "symbols": [ + "demosaic_color_noise_pass_3_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_color_noise_pass_3_yccd_0x303704a.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "b3af96dca2b14851ada4f1cd7cad4b9e9bfa6c4f499fe6edf9e4367e6fe2246d", + "bytes": 5960, + "lines": 153, + "symbols": [ + "demosaic_color_noise_pass_3_yccd_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x303704a", + "symbols": [ + "demosaic_color_noise_pass_3_yccd_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_iir2_pass1_0x3041e8f.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "9c22e56ab98ccba2df1047cf363f263ad92e146700c596b8622b03af6ca5233b", + "bytes": 2422, + "lines": 79, + "symbols": [ + "demosaic_iir2_pass1_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3041e8f", + "symbols": [ + "demosaic_iir2_pass1_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_iir2_pass1_init_0x3005a70.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "b4203de6cb2b2a0d2d45bf31b94709bcbe51958985b0a49d92728ed4bdeedad2", + "bytes": 2180, + "lines": 75, + "symbols": [ + "demosaic_iir2_pass1_init_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3005a70", + "symbols": [ + "demosaic_iir2_pass1_init_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_iir2_pass2_0x3006acc.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "3880b76927b8cd1ca8c15558912f032c8594312e3180834b0fc36a1c55bd64b0", + "bytes": 1625, + "lines": 59, + "symbols": [ + "demosaic_iir2_pass2_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3006acc", + "symbols": [ + "demosaic_iir2_pass2_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_iir2_pass3_0x3068458.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "e665176d25d909367a134dd38315c49c97b9157836dc8165b0225cb611582e96", + "bytes": 2178, + "lines": 74, + "symbols": [ + "demosaic_iir2_pass3_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3068458", + "symbols": [ + "demosaic_iir2_pass3_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_pass_0a1_0x30410af.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "54604631e2fdfb4d993170190d5b8dab390379a81b500e43d337af975cade411", + "bytes": 3551, + "lines": 143, + "symbols": [ + "demosaic_pass_0a1_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x30410af", + "symbols": [ + "demosaic_pass_0a1_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_pass_0a2_0x30555c4.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "0efa5c950f6502ed9836a8cd18dc935a686aa8e8033e3d36d9cb96ca7d92b347", + "bytes": 3642, + "lines": 106, + "symbols": [ + "demosaic_pass_0a2_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x30555c4", + "symbols": [ + "demosaic_pass_0a2_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_pass_0b_0x30325b5.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "6ebfd8f9386e94f8fc0090d4b6379e8ac599ae6581c15edb35a0c1ed5981e6c5", + "bytes": 2115, + "lines": 74, + "symbols": [ + "demosaic_pass_0b_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x30325b5", + "symbols": [ + "demosaic_pass_0b_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_pass_0c_0x306798d.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "cbbd4fee1875088d68c839eb922dffa6be9b1c175ff33941b4465deb990dca95", + "bytes": 2762, + "lines": 94, + "symbols": [ + "demosaic_pass_0c_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x306798d", + "symbols": [ + "demosaic_pass_0c_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_pass_1_0x3097f8e.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "16b1675cddccc6ef185afa37b2b9d4f5af38b3c64e51ec7b0854b474c678221a", + "bytes": 17847, + "lines": 389, + "symbols": [ + "demosaic_pass_1_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3097f8e", + "symbols": [ + "demosaic_pass_1_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_pass_2_0x30a5753.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "f6a0ccf9154f8a51129f18a76bfbc63bcb960c646805b2511dbe5ec8c0e90f3d", + "bytes": 3921, + "lines": 114, + "symbols": [ + "demosaic_pass_2_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x30a5753", + "symbols": [ + "demosaic_pass_2_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_pass_3_0x30466e2.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "f5810f8bf53819324502a8696d7d0bdb94238280be29b7f72139e9701e276111", + "bytes": 14260, + "lines": 337, + "symbols": [ + "demosaic_pass_3_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x30466e2", + "symbols": [ + "demosaic_pass_3_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_pass_neutral_0x308ec13.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "ca62ac0831390a5415c5703b3a22c344faf8cc3de01c9665783d1ce6a6790da0", + "bytes": 1787, + "lines": 61, + "symbols": [ + "demosaic_pass_neutral_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x308ec13", + "symbols": [ + "demosaic_pass_neutral_computeShaderSource" + ] + } + ] + }, + { + "file": "02_demosaic/demosaic_yuv_to_rgb_0x3007126.comp", + "category": "02_demosaic", + "stage": "compute", + "sha256": "dd4384ae8724f2c7edb40a44214966d9d390cba0e9fa00329be17c814ff0e1c7", + "bytes": 1761, + "lines": 58, + "symbols": [ + "demosaic_yuv_to_rgb_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3007126", + "symbols": [ + "demosaic_yuv_to_rgb_computeShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/cacheCmosCache0_0x30501d4.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "c7f420d715f7cf77f2a9e4f39d3a91210a32fb7ae3f3bb76eb54060c35dbb03a", + "bytes": 790, + "lines": 29, + "symbols": [ + "cacheCmosCache0_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30501d4", + "symbols": [ + "cacheCmosCache0_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/cacheCmosCache1_0x30651c8.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "75b79c1ff7a65dce4caaa4a318e8831830581262ba3641abbc911404105fd626", + "bytes": 1404, + "lines": 35, + "symbols": [ + "cacheCmosCache1_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30651c8", + "symbols": [ + "cacheCmosCache1_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/cacheCmosCache2_0x300e390.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "c54309c364704060a762899687cb5552463b112200ba20e6380dfabef41cf04a", + "bytes": 796, + "lines": 29, + "symbols": [ + "cacheCmosCache2_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x300e390", + "symbols": [ + "cacheCmosCache2_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/cacheCmosCache3_0x307c71b.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "ea3760a5920497c1d661adf7132a31d29544b34d386deb1d87ba6b3d41b935a7", + "bytes": 1404, + "lines": 35, + "symbols": [ + "cacheCmosCache3_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x307c71b", + "symbols": [ + "cacheCmosCache3_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/cacheCmosG1G2Cache0_0x3032df9.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "07200b7b375227e9abc24cb9bc8583f5977e8c9e89f6bc9e3363bf04aca6c348", + "bytes": 786, + "lines": 29, + "symbols": [ + "cacheCmosG1G2Cache0_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3032df9", + "symbols": [ + "cacheCmosG1G2Cache0_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/cacheCmosG1G2Cache1_0x302135f.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "9f177bedb3419c59f2297600453a289d254763433b0bb6c83256845c271b1cb6", + "bytes": 1389, + "lines": 35, + "symbols": [ + "cacheCmosG1G2Cache1_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x302135f", + "symbols": [ + "cacheCmosG1G2Cache1_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/cacheCmosG1G2Cache2_0x303b1b3.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "f3fe5f3c34819255ebb82f092eed86346a1e31b351c6d54b2771b7866d3492f7", + "bytes": 1271, + "lines": 33, + "symbols": [ + "cacheCmosG1G2Cache2_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x303b1b3", + "symbols": [ + "cacheCmosG1G2Cache2_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/cacheCmosG1G2Cache3_0x3064c8a.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "63a9a7da2c59cdee8169bf505f93bba4d04bcb1f4bf20c9acff24ab92b7975de", + "bytes": 1341, + "lines": 33, + "symbols": [ + "cacheCmosG1G2Cache3_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3064c8a", + "symbols": [ + "cacheCmosG1G2Cache3_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/cacheCmosRedBlueCache0_0x306db71.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "25d520100eef854bba77d939159fe21fd7680371cc3f7b6f62e6585458e055d6", + "bytes": 861, + "lines": 31, + "symbols": [ + "cacheCmosRedBlueCache0_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x306db71", + "symbols": [ + "cacheCmosRedBlueCache0_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/cacheCmosRedBlueCache1_0x306decf.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "1fd2aa77c9667d8cfdce32d82f263caaefb216a28936ea7e2864847063731a33", + "bytes": 1558, + "lines": 41, + "symbols": [ + "cacheCmosRedBlueCache1_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x306decf", + "symbols": [ + "cacheCmosRedBlueCache1_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/cacheCmosRedBlueCache2_0x3038793.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "d3fc268abeb04b0953757c16d8bafcb1907a30fe349cc7f5417371eb5af0aa65", + "bytes": 1986, + "lines": 48, + "symbols": [ + "cacheCmosRedBlueCache2_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3038793", + "symbols": [ + "cacheCmosRedBlueCache2_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/denoiseCcd_0x304b7a0.comp", + "category": "03_denoise", + "stage": "compute", + "sha256": "38ce78e7205eab385f083a58771fba7efdf84e98ab3e79ef6643a7ef0e7c3653", + "bytes": 7596, + "lines": 158, + "symbols": [ + "denoiseCcd_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x304b7a0", + "symbols": [ + "denoiseCcd_computeShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/denoiseCmosCached_0x309c546.comp", + "category": "03_denoise", + "stage": "compute", + "sha256": "5a71694ed199c558d517899590d5a2c72f4d49e457ccf781e467e7c35119ad30", + "bytes": 8364, + "lines": 161, + "symbols": [ + "denoiseCmosCached_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x309c546", + "symbols": [ + "denoiseCmosCached_computeShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/denoiseCmosG1G2Cached_0x30a66a5.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "1ea9327fd1b1ce2257eca7ed7bca44ffa74b5d5ba71f8203df26436cd3713f9e", + "bytes": 9222, + "lines": 236, + "symbols": [ + "denoiseCmosG1G2Cached_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30a66a5", + "symbols": [ + "denoiseCmosG1G2Cached_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/denoiseCmosG1G2Cached_0x30ad00c.comp", + "category": "03_denoise", + "stage": "compute", + "sha256": "e1cd535a47146b36cb176de8b5658dc74be20180f1c78f78e4e09924d3fd964f", + "bytes": 9203, + "lines": 223, + "symbols": [ + "denoiseCmosG1G2Cached_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x30ad00c", + "symbols": [ + "denoiseCmosG1G2Cached_computeShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/denoiseCmosRedBlueCached_0x308f30f.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "ddf06024ffc6b97bd6e48447543b6b33c79c45a80b2ffdd786f6eaff24177058", + "bytes": 6243, + "lines": 176, + "symbols": [ + "denoiseCmosRedBlueCached_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x308f30f", + "symbols": [ + "denoiseCmosRedBlueCached_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/denoiseCmosRedBlueCached_0x30a8aac.comp", + "category": "03_denoise", + "stage": "compute", + "sha256": "ca61491ffb337d564307251c8a95970840228afdc8555f3bb23f75210ea13c12", + "bytes": 6345, + "lines": 167, + "symbols": [ + "denoiseCmosRedBlueCached_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x30a8aac", + "symbols": [ + "denoiseCmosRedBlueCached_computeShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/denoiseGray_0x3068e79.comp", + "category": "03_denoise", + "stage": "compute", + "sha256": "3b723b58db314faac1498ff32b0957b78e2656ad65c28e36e11f52941507401f", + "bytes": 8540, + "lines": 216, + "symbols": [ + "denoiseGray_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3068e79", + "symbols": [ + "denoiseGray_computeShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/noiseMinMax_0x3087ae6.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "55a11b0d14cc518110a0c76d9f01a7fb64092fddbc6f6996b1c321964bd9d0fe", + "bytes": 1751, + "lines": 51, + "symbols": [ + "noiseMinMax_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3087ae6", + "symbols": [ + "noiseMinMax_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/rgbNoise_0x3013e52.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "7487a80208c3945d4a0dbdefb2ae83b6696e263985891ee717e0b57ee421b82a", + "bytes": 423, + "lines": 20, + "symbols": [ + "rgbNoiseShader" + ], + "occurrences": [ + { + "offset": "0x3013e52", + "symbols": [ + "rgbNoiseShader" + ] + } + ] + }, + { + "file": "03_denoise/rgbnr_0x3072e51.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "0e308203f748e9d878cfd3e0006993f4df8c422e6922b8ad5118a91254fc4103", + "bytes": 1821, + "lines": 57, + "symbols": [ + "rgbnr_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3072e51", + "symbols": [ + "rgbnr_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/rgbnrcdiff_0x309776e.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "54386a68d91b8e178b310919a8c991f2752bdd840fe5a53f4c855be5f7a4f8fb", + "bytes": 2079, + "lines": 67, + "symbols": [ + "rgbnrcdiff_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x309776e", + "symbols": [ + "rgbnrcdiff_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/rgbnrcdiff_0x30a4eb3.comp", + "category": "03_denoise", + "stage": "compute", + "sha256": "52a7d714fa3dcf908389eec8b53aa2dff3e506042127e90909b014dae1708afd", + "bytes": 2207, + "lines": 70, + "symbols": [ + "rgbnrcdiff_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x30a4eb3", + "symbols": [ + "rgbnrcdiff_computeShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/rgbnrsimple_0x30ac478.comp", + "category": "03_denoise", + "stage": "compute", + "sha256": "9069bc90a27a2f0b5a7724407e599df01fe3ff0bcd1e09204c41b787eca9886e", + "bytes": 2963, + "lines": 96, + "symbols": [ + "rgbnrsimple_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x30ac478", + "symbols": [ + "rgbnrsimple_computeShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/rgbnrsimple_NoNR_0x30153ac.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "0c10fd81f389dc085b1747e60fd9c8c89771230c59cddaa9e8abd4092f901a70", + "bytes": 357, + "lines": 17, + "symbols": [ + "rgbnrsimple_NoNR_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30153ac", + "symbols": [ + "rgbnrsimple_NoNR_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/rgbnrsimple_RGB16_16_0x307cc98.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "e920533ef360bffa8007445902f5797a221900d0bb56e70312ee08e9ad0135ce", + "bytes": 1535, + "lines": 56, + "symbols": [ + "rgbnrsimple_RGB16_16_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x307cc98", + "symbols": [ + "rgbnrsimple_RGB16_16_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/rgbnrsimple_RGB_4_4_0x3090b73.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "47f84ed81f1b2e6cbf16d0263c68697e45353b60ae7299e49cc0614268962284", + "bytes": 1534, + "lines": 56, + "symbols": [ + "rgbnrsimple_RGB_4_4_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3090b73", + "symbols": [ + "rgbnrsimple_RGB_4_4_fragmentShaderSource" + ] + } + ] + }, + { + "file": "03_denoise/rgbnrsimple_RGB_8_8_0x3033552.frag", + "category": "03_denoise", + "stage": "fragment", + "sha256": "17b63bef6865200eff7286b24f7f02ed3f28adf656a0f7402779fce3e2a77488", + "bytes": 1534, + "lines": 56, + "symbols": [ + "rgbnrsimple_RGB_8_8_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3033552", + "symbols": [ + "rgbnrsimple_RGB_8_8_fragmentShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/ColorCorrectAll_0x301a79e.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "e88d1cf208ed2067ae4d435a12d1f7cc5ff1367b004315b1c823a6c99f7ee6bf", + "bytes": 8370, + "lines": 255, + "symbols": [ + "ColorCorrectAllShader" + ], + "occurrences": [ + { + "offset": "0x301a79e", + "symbols": [ + "ColorCorrectAllShader" + ] + } + ] + }, + { + "file": "04_color_tone/HighlightStrength_0x3019721.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "7e01c980ca698783302664399c9fbbf037d161e4df32398671c1faab48b60701", + "bytes": 4220, + "lines": 116, + "symbols": [ + "HighlightStrengthShader" + ], + "occurrences": [ + { + "offset": "0x3019721", + "symbols": [ + "HighlightStrengthShader" + ] + } + ] + }, + { + "file": "04_color_tone/colorCorrectAll_0x3027dea.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "dbaac65ca38e9a2fc2156b3cdce40f6bc9ef41150a8e7c5e2473b7556f7de8e7", + "bytes": 7885, + "lines": 250, + "symbols": [ + "colorCorrectAll_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3027dea", + "symbols": [ + "colorCorrectAll_fragmentShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/color_correct_0x303b6ab.comp", + "category": "04_color_tone", + "stage": "compute", + "sha256": "708bb034bd1ad908db5512e780831df43eae055e5b1752f29d49d8710d1ed0b5", + "bytes": 5078, + "lines": 144, + "symbols": [ + "color_correct_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x303b6ab", + "symbols": [ + "color_correct_computeShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/colorspaceconvert_0x2ff7cb6.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "4af76a0e1e5dc2e9d4788f439d2c1615d0e1086a480d91d016b8d12d9a51f5d6", + "bytes": 4419, + "lines": 148, + "symbols": [ + "colorspaceconvert_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x2ff7cb6", + "symbols": [ + "colorspaceconvert_fragmentShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/customCmm_0x3011778.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "1d2a52b7d24ec0b6d2d2b4100a2c467d18b50a73cd46a5570e77fd86788fe7a7", + "bytes": 2072, + "lines": 73, + "symbols": [ + "customCmm_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3011778", + "symbols": [ + "customCmm_fragmentShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/customColorSpace_0x3034aab.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "a2290578fd48972ba0cb065428ae5307ac013d2b0d0f4607d20014b480e3c842", + "bytes": 2256, + "lines": 77, + "symbols": [ + "customColorSpaceShader" + ], + "occurrences": [ + { + "offset": "0x3034aab", + "symbols": [ + "customColorSpaceShader" + ] + } + ] + }, + { + "file": "04_color_tone/desatHighLight_0x308164a.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "22ee7adff61fc23e5f879983fa06ae574dbfc040734178d2c83992d4f2350fcc", + "bytes": 2406, + "lines": 103, + "symbols": [ + "desatHighLight_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x308164a", + "symbols": [ + "desatHighLight_computeShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/desatHighLight_0x308e22a.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "992c5335469160b73bcabb680b1cead43a5e0c7669ac3aad4f3c196eb8ac55c3", + "bytes": 2536, + "lines": 110, + "symbols": [ + "desatHighLight_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x308e22a", + "symbols": [ + "desatHighLight_fragmentShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/filmCurve_0x30a3daf.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "7272d4bc97a33ee3855b9d2a7cad4d0843a6480c8fa8cd2341f65b3e6c429e8c", + "bytes": 1039, + "lines": 37, + "symbols": [ + "filmCurveShader" + ], + "occurrences": [ + { + "offset": "0x30a3daf", + "symbols": [ + "filmCurveShader" + ] + } + ] + }, + { + "file": "04_color_tone/filmcurve_0x3040c4d.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "c678f85151e14960313ee0e0b16fa1ed9c6041ac3144a9f1174a76853e540d17", + "bytes": 1121, + "lines": 41, + "symbols": [ + "filmcurve_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3040c4d", + "symbols": [ + "filmcurve_fragmentShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/gamma_hasselblad_0x30776ff.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "121ebee892224e11b60d72f04e14bd10e2c685e2fdc66d5f4f8dae647bd0e421", + "bytes": 478, + "lines": 19, + "symbols": [ + "gamma_hasselblad_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30776ff", + "symbols": [ + "gamma_hasselblad_fragmentShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/gamma_lstar_0x307356f.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "3bdbd36600685c42e163ed2aed8e89cb2135cb71e3601d7b002681c923cdcaaf", + "bytes": 786, + "lines": 28, + "symbols": [ + "gamma_lstar_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x307356f", + "symbols": [ + "gamma_lstar_fragmentShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/gradation_0x30778de.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "c6952101afd99df4bc3bb0f5b3061b5b7dfaca6392921b3758889f0a6b1aa926", + "bytes": 4643, + "lines": 157, + "symbols": [ + "gradation_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30778de", + "symbols": [ + "gradation_fragmentShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/highlightstrength_0x3035fd3.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "8c19ed4877e76b4394bb4dd802c890a081f0ba79a1ebcc68ea39c5c5ecfce6b7", + "bytes": 4214, + "lines": 116, + "symbols": [ + "highlightstrength_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3035fd3", + "symbols": [ + "highlightstrength_fragmentShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/mark_hue_0x30504eb.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "6db1863654d4ec5103e4bc0fdf6e1fddc612afed52d72e114956e65562b7e359", + "bytes": 2013, + "lines": 59, + "symbols": [ + "mark_hue_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30504eb", + "symbols": [ + "mark_hue_fragmentShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/rgb2GrayRgb_0x309e5f3.comp", + "category": "04_color_tone", + "stage": "compute", + "sha256": "b781b236056b8b51679cea5da2e98b07839ed5db74eedbec1a0123685792bff7", + "bytes": 2403, + "lines": 74, + "symbols": [ + "rgb2GrayRgb_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x309e5f3", + "symbols": [ + "rgb2GrayRgb_computeShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/rgb2Gray_0x2ffe79a.comp", + "category": "04_color_tone", + "stage": "compute", + "sha256": "69b2e3e5510029dac6d1416980e258fdf5c924a43de19e2cb36feb8bc223dd34", + "bytes": 2983, + "lines": 78, + "symbols": [ + "rgb2Gray_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x2ffe79a", + "symbols": [ + "rgb2Gray_computeShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/sdr_icc_0x3073d21.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "9f2ec2781a1b115048553c5aba7b729e60c43f6332cc9e4046a4866da43e658e", + "bytes": 1472, + "lines": 58, + "symbols": [ + "sdr_icc_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3073d21", + "symbols": [ + "sdr_icc_fragmentShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/selectivecolor_0x3088ea2.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "23d9a908fe2ae5baf5f578bac46cbcbb30f711900eef5851e42d60c8441dcc24", + "bytes": 5607, + "lines": 172, + "symbols": [ + "selectivecolor_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3088ea2", + "symbols": [ + "selectivecolor_fragmentShaderSource" + ] + } + ] + }, + { + "file": "04_color_tone/unattributed_0x30308d7_0x30308d7.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "0019263ccb2e3a738b9c6014820b560dc84c5c474955760e2baaf968fab453f0", + "bytes": 498, + "lines": 16, + "symbols": [], + "occurrences": [ + { + "offset": "0x30308d7", + "symbols": [] + } + ] + }, + { + "file": "04_color_tone/unattributed_0x30347c3_0x30347c3.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "555706c2932277ee62b250ebd2625afe9c4e80de00db5e77c6dd38e9bdccd000", + "bytes": 209, + "lines": 12, + "symbols": [], + "occurrences": [ + { + "offset": "0x30347c3", + "symbols": [] + } + ] + }, + { + "file": "04_color_tone/unattributed_0x3065982_0x3065982.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "6f90e80f6193d57e5ee7d79a3beb75aa77d22320d0ecdea771c7580ea2a3cb29", + "bytes": 326, + "lines": 12, + "symbols": [], + "occurrences": [ + { + "offset": "0x3065982", + "symbols": [] + } + ] + }, + { + "file": "04_color_tone/unattributed_0x3079cc5_0x3079cc5.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "d54349859e4310755952cd52a6dce6eacd6e4a8f4cb54b3824a086bd397d19b8", + "bytes": 3358, + "lines": 88, + "symbols": [], + "occurrences": [ + { + "offset": "0x3079cc5", + "symbols": [] + } + ] + }, + { + "file": "04_color_tone/unattributed_0x307f4f7_0x307f4f7.frag", + "category": "04_color_tone", + "stage": "fragment", + "sha256": "93d00d0f37ad0f65522194209275aab523fabc1c8173df5550ca7e0c94a46613", + "bytes": 177, + "lines": 12, + "symbols": [], + "occurrences": [ + { + "offset": "0x307f4f7", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/KeystoneBilinear_0x300f494.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "6e41522c4cdf78a589f1e2d7a5cefc0ba1ed514b23edd3369992f0cf90c97e98", + "bytes": 1822, + "lines": 56, + "symbols": [ + "KeystoneBilinear_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x300f494", + "symbols": [ + "KeystoneBilinear_fragmentShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/Keystone_0x30847c0.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "d3956e2b1df06d05398033f10af7f36f5651d91db0173fa1dc2232390ff8b8dd", + "bytes": 5010, + "lines": 120, + "symbols": [ + "Keystone_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30847c0", + "symbols": [ + "Keystone_fragmentShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/alignment_0x3025a0f.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "4f0ff853370d74ed985ade5b3f8e5a403962af5789f8eca38a4b97cdc1863fa0", + "bytes": 307, + "lines": 15, + "symbols": [ + "alignment_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3025a0f", + "symbols": [ + "alignment_fragmentShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/grayVignetteCS_0x300a1ea.comp", + "category": "05_lens_geometry", + "stage": "compute", + "sha256": "76ab07ae2bc82a0a7f67d73044d2eff9fdda40e911b98645b3cb935129eeef0c", + "bytes": 7011, + "lines": 186, + "symbols": [ + "grayVignetteCS_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x300a1ea", + "symbols": [ + "grayVignetteCS_computeShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/grayVignetteHtsCS_0x306f136.comp", + "category": "05_lens_geometry", + "stage": "compute", + "sha256": "a462ddc6676773abca3e4f28156aaafddc7924aeab527f6b5d0b63026dd585f5", + "bytes": 7262, + "lines": 194, + "symbols": [ + "grayVignetteHtsCS_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x306f136", + "symbols": [ + "grayVignetteHtsCS_computeShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/htsAberrationCS_0x309f9c3.comp", + "category": "05_lens_geometry", + "stage": "compute", + "sha256": "a7d6c853553ca43a007eca52070267af41ea92582da3e951654cd68728e732c2", + "bytes": 7266, + "lines": 183, + "symbols": [ + "htsAberrationCS_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x309f9c3", + "symbols": [ + "htsAberrationCS_computeShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/orientation_rgb180_0x306e4e6.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "81dae8448e22d2a50d7394fbb542a5d64f9d534f5b32b392979fed8612b174d5", + "bytes": 412, + "lines": 20, + "symbols": [ + "orientation_rgb180_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x306e4e6", + "symbols": [ + "orientation_rgb180_fragmentShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/orientation_rgb270_0x303edb0.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "b20405eac1c785d1a0359002535ad92b2338a72100b12fd83c800123eb490e83", + "bytes": 414, + "lines": 20, + "symbols": [ + "orientation_rgb270_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x303edb0", + "symbols": [ + "orientation_rgb270_fragmentShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/orientation_rgb90_0x307d298.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "b379afb58ea22e4d0d0f4fa880dc1ee053d527d3a82fdb86881459b5a8aee522", + "bytes": 415, + "lines": 20, + "symbols": [ + "orientation_rgb90_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x307d298", + "symbols": [ + "orientation_rgb90_fragmentShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/repeatMargin_0x3084296.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "9373e67d9d551351332bb5ad0d8727a1e3a8524bd8cf1d63d27a92baab843eb5", + "bytes": 1321, + "lines": 54, + "symbols": [ + "repeatMargin_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3084296", + "symbols": [ + "repeatMargin_fragmentShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/resize_0x3029cb8.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "8c44c4f649d107b2346725d1b018d85e426fded06bd05fbb5a836dbeaf45e569", + "bytes": 2381, + "lines": 72, + "symbols": [ + "resize_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3029cb8", + "symbols": [ + "resize_fragmentShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/resizeintegraldown_0x2ffcdeb.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "abc100e93094e15844f1aac7761b8b78aa5ac10d1fc122c86a131473eb3c0293", + "bytes": 1160, + "lines": 46, + "symbols": [ + "resizeintegraldown_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x2ffcdeb", + "symbols": [ + "resizeintegraldown_fragmentShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/resizesplinehorizontal_0x30768a8.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "b89be0128b31698dc01785802e45d89a1313909f8f829e4c5e008788151cdaaa", + "bytes": 3670, + "lines": 129, + "symbols": [ + "resizesplinehorizontal_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30768a8", + "symbols": [ + "resizesplinehorizontal_fragmentShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/resizesplinevertical_0x3063ecb.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "11d86a505f5d8f109ce72cdb0b7391d559cf63aeaf7e3b6be57081bf47852d81", + "bytes": 3518, + "lines": 127, + "symbols": [ + "resizesplinevertical_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3063ecb", + "symbols": [ + "resizesplinevertical_fragmentShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/rgbLensFilter_0x2fff342.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "242f8a575c32fa3e5b0867f2b2fc3f678bbc86df9650b329650917b3773fc73a", + "bytes": 16716, + "lines": 408, + "symbols": [ + "rgbLensFilter_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x2fff342", + "symbols": [ + "rgbLensFilter_fragmentShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/rgbLensFilter_0x3057352.comp", + "category": "05_lens_geometry", + "stage": "compute", + "sha256": "a21099023c7ef59d903395303ee0c0bfdfe05463d171713e599ee2d21d390291", + "bytes": 15003, + "lines": 341, + "symbols": [ + "rgbLensFilter_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3057352", + "symbols": [ + "rgbLensFilter_computeShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/standardAberrationCS_0x300fbb3.comp", + "category": "05_lens_geometry", + "stage": "compute", + "sha256": "c17ca8323bf2ae866a700a7e8c03b26006646dc582b747033507adcf8e4295bb", + "bytes": 7108, + "lines": 175, + "symbols": [ + "standardAberrationCS_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x300fbb3", + "symbols": [ + "standardAberrationCS_computeShaderSource" + ] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x2ffac4a_0x2ffac4a.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "cf8cb93c8b2a90f34a0a41f45509b621135134b1785a57f49437fb5e1813b76b", + "bytes": 562, + "lines": 19, + "symbols": [], + "occurrences": [ + { + "offset": "0x2ffac4a", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x2ffae7d_0x2ffae7d.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "e9f99a8ec73e205e70886530d9f6f60bedd45a4817119e988b77824e84df52db", + "bytes": 2222, + "lines": 45, + "symbols": [], + "occurrences": [ + { + "offset": "0x2ffae7d", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x3003732_0x3003732.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "e42cf5f03a11d8eac27fcc414f6c9d09ee9fd18432530f1d574e0269b8e3139a", + "bytes": 879, + "lines": 22, + "symbols": [], + "occurrences": [ + { + "offset": "0x3003732", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x300c4fc_0x300c4fc.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "68a09bfc4c6bdfd4c327b840a8fe3d2810a7e7b3bb1ccabd50f31c7bdb1461ad", + "bytes": 970, + "lines": 24, + "symbols": [], + "occurrences": [ + { + "offset": "0x300c4fc", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x30218ea_0x30218ea.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "45417504420c2e766d3dc2ace48fc785e9aa1f665d9aa42a7968dd9d0117a8b6", + "bytes": 2637, + "lines": 67, + "symbols": [], + "occurrences": [ + { + "offset": "0x30218ea", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x3025d0b_0x3025d0b.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "be7df9e0bd89a0467177c64df289d56f33585086266c451a570a4e8f93d011b4", + "bytes": 970, + "lines": 24, + "symbols": [], + "occurrences": [ + { + "offset": "0x3025d0b", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x303011d_0x303011d.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "4788646eb655664ed70590e8ac61a52dd2bb31df68599569683e0569158980a0", + "bytes": 1977, + "lines": 57, + "symbols": [], + "occurrences": [ + { + "offset": "0x303011d", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x3038f66_0x3038f66.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "05317b455a0d1d6d9afaa741b05bc34fe23073556dabb500068780abae76dd1c", + "bytes": 763, + "lines": 20, + "symbols": [], + "occurrences": [ + { + "offset": "0x3038f66", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x303ca82_0x303ca82.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "eca183311e10a8a3832fb3b176a9a9df0b7c91c53f8ffdba2ea6c20302d050a1", + "bytes": 660, + "lines": 21, + "symbols": [], + "occurrences": [ + { + "offset": "0x303ca82", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x303cd17_0x303cd17.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "5edd39c1c209941815ef719ebd68a0ad5b9d44e5c6af1634e7dc3d0fbeb2a469", + "bytes": 659, + "lines": 19, + "symbols": [], + "occurrences": [ + { + "offset": "0x303cd17", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x3043a7a_0x3043a7a.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "5032f05ce79cbaba7a0539c9611235df091957795672a17f3d77457625d85336", + "bytes": 2410, + "lines": 69, + "symbols": [], + "occurrences": [ + { + "offset": "0x3043a7a", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x3053268_0x3053268.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "64f9d74a6693cf3660eb633e889e91c4f7e549865bbd55d05ca1472287c93990", + "bytes": 705, + "lines": 17, + "symbols": [], + "occurrences": [ + { + "offset": "0x3053268", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x3061f15_0x3061f15.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "9071061620f2032c7d385e1156c3d06346385976d258aca5b8ff4506dd916d9d", + "bytes": 700, + "lines": 18, + "symbols": [], + "occurrences": [ + { + "offset": "0x3061f15", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x306afe7_0x306afe7.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "ecb85eb3453ecfb72f032d171bef7287a0479132b7ff0187712f82bb054a13ab", + "bytes": 4043, + "lines": 98, + "symbols": [], + "occurrences": [ + { + "offset": "0x306afe7", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x3070da7_0x3070da7.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "2eb6d3e8b25809b4772134c99864f4d403f8e3b612ed55cf51f6735b01cb1c0b", + "bytes": 970, + "lines": 23, + "symbols": [], + "occurrences": [ + { + "offset": "0x3070da7", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x3074cae_0x3074cae.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "1441f909272ff89a1ba21e4def13bdbf502cc17466443f8d592bd9476ed07270", + "bytes": 938, + "lines": 23, + "symbols": [], + "occurrences": [ + { + "offset": "0x3074cae", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x30798c4_0x30798c4.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "853517e8aca4276ea2c5a150fbce0d3b1efcad5d72a9787163870dabe8f72378", + "bytes": 1024, + "lines": 22, + "symbols": [], + "occurrences": [ + { + "offset": "0x30798c4", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x307dbfe_0x307dbfe.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "c677a27ae799ca3cd71bd19448694c490a92a3d4f16b9c8a76dbb9c487064425", + "bytes": 1133, + "lines": 26, + "symbols": [], + "occurrences": [ + { + "offset": "0x307dbfe", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x307e06c_0x307e06c.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "40ac286da16f404b179d003f86ec7776fd5ab941355fe543a4ea6852cf2f1edd", + "bytes": 1472, + "lines": 27, + "symbols": [], + "occurrences": [ + { + "offset": "0x307e06c", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x309326d_0x309326d.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "bbff5e6f1bc6526815897213461384a89b1a8ec3314f34dce3c3e66018cd73c9", + "bytes": 874, + "lines": 26, + "symbols": [], + "occurrences": [ + { + "offset": "0x309326d", + "symbols": [] + } + ] + }, + { + "file": "05_lens_geometry/unattributed_0x30953e0_0x30953e0.frag", + "category": "05_lens_geometry", + "stage": "fragment", + "sha256": "6cfbe5b95c1509f6c7a20872b414c64d5150482481be8130ee510028bf0f8eaf", + "bytes": 1912, + "lines": 43, + "symbols": [], + "occurrences": [ + { + "offset": "0x30953e0", + "symbols": [] + } + ] + }, + { + "file": "06_detail_texture/cikernel_create_film_grain_0x306e683.frag", + "category": "06_detail_texture", + "stage": "fragment", + "sha256": "a18e2b102dc046b550c62dc3b340b25376d05213b5b17078066d2835548fbcff", + "bytes": 2738, + "lines": 94, + "symbols": [ + "cikernel_create_film_grain_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x306e683", + "symbols": [ + "cikernel_create_film_grain_fragmentShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/cikernel_create_film_grain_blend_0x309ef57.frag", + "category": "06_detail_texture", + "stage": "fragment", + "sha256": "b72f1aaffa4d668aa8fef8bf9d539bb56950c28e9c53f3b0e47dcd4227ed5010", + "bytes": 2667, + "lines": 88, + "symbols": [ + "cikernel_create_film_grain_blend_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x309ef57", + "symbols": [ + "cikernel_create_film_grain_blend_fragmentShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityBlendBlurU16_0x301683e.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "808b8fd80c4d37ccba8fc0e4c6fef3f3cceeb388cc3ed780dbfb2462afce49e3", + "bytes": 7430, + "lines": 179, + "symbols": [ + "clarityBlendBlurU16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x301683e", + "symbols": [ + "clarityBlendBlurU16_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityBlendGlobal2U16_0x307d4af.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "6b8f2d419337fcc8a01151c32132da494e4ca9eebdb9143574c425b4c88edf2c", + "bytes": 1844, + "lines": 50, + "symbols": [ + "clarityBlendGlobal2U16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x307d4af", + "symbols": [ + "clarityBlendGlobal2U16_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityBlendGlobalNextU16_0x307923d.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "7c86fb5c5d04a646487d987a21565b88b35a9bb9c4c04b0710e1535ff06c8e80", + "bytes": 1477, + "lines": 45, + "symbols": [ + "clarityBlendGlobalNextU16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x307923d", + "symbols": [ + "clarityBlendGlobalNextU16_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityBlendLocal2F_0x308b9bd.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "f9fe5e156ec69fb7cb7368c5691d79a4d33a6e178974d4765cbe291550ff6527", + "bytes": 1754, + "lines": 47, + "symbols": [ + "clarityBlendLocal2F_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x308b9bd", + "symbols": [ + "clarityBlendLocal2F_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityBlendLocalNextF_0x3092c99.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "bb147c1fa1de6c8e4e6f9ee0b6ff48bb39b16fe8a66e5234a7bfdf66ed326f11", + "bytes": 1425, + "lines": 43, + "symbols": [ + "clarityBlendLocalNextF_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3092c99", + "symbols": [ + "clarityBlendLocalNextF_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityBlendNoLutU16_0x3051d04.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "8b77e58847de0bf89a07d52d07156cf6b8b3b8f46f43ebf3cdbeb4cffa81719a", + "bytes": 5475, + "lines": 136, + "symbols": [ + "clarityBlendNoLutU16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3051d04", + "symbols": [ + "clarityBlendNoLutU16_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityCombineFinal4U16_0x301e906.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "14ec460a9b79553f33b090ab75ff8e3a9897c15eb3d346703914db856fdab2df", + "bytes": 4441, + "lines": 97, + "symbols": [ + "clarityCombineFinal4U16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x301e906", + "symbols": [ + "clarityCombineFinal4U16_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityCreateFinalFactorsU16_0x30742e2.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "447319113a0246e3a4198ff07eb0fcbe40f1bc25ce32f667bb79e698e206b3d5", + "bytes": 2423, + "lines": 52, + "symbols": [ + "clarityCreateFinalFactorsU16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x30742e2", + "symbols": [ + "clarityCreateFinalFactorsU16_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityDiscretImage4CenterValU16_0x2ffa214.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "ffddf4600d0c7322e96cdcb76b02364d0dab0d4054c1f25090cb2249815e16eb", + "bytes": 2577, + "lines": 83, + "symbols": [ + "clarityDiscretImage4CenterValU16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x2ffa214", + "symbols": [ + "clarityDiscretImage4CenterValU16_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityDownScaleBlurU16_0x3050cc9.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "da8e09ea72af7aacdf5cdcfbee513b4b7deca33651e75506d7d245a8606e756d", + "bytes": 4154, + "lines": 152, + "symbols": [ + "clarityDownScaleBlurU16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3050cc9", + "symbols": [ + "clarityDownScaleBlurU16_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityFastPreviewApply_0x30b231c.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "ec451ea570b0870fb0b16d88ca2ba0ca3b4d5c135696acffaa0d9f070349d659", + "bytes": 2080, + "lines": 56, + "symbols": [ + "clarityFastPreviewApply_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x30b231c", + "symbols": [ + "clarityFastPreviewApply_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityGrayImage4CenterValU16_0x300bd4e.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "54c35774225149ef4345604d5dbd9ea8016a8f6e3ddfea8dafda40aa17b5d450", + "bytes": 1965, + "lines": 63, + "symbols": [ + "clarityGrayImage4CenterValU16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x300bd4e", + "symbols": [ + "clarityGrayImage4CenterValU16_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityHRLut_0x3018545.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "c6ae77a81dd90ba4bd65dbd390ad5e7f025658e36eed95f19a4483189728b65a", + "bytes": 998, + "lines": 37, + "symbols": [ + "clarityHRLut_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3018545", + "symbols": [ + "clarityHRLut_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityPackedU16MaxToR32F_0x301ded0.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "18c919f2a855b3727299372c559d2974204d7af412e135e2a4e5d540671d98c0", + "bytes": 991, + "lines": 31, + "symbols": [ + "clarityPackedU16MaxToR32F_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x301ded0", + "symbols": [ + "clarityPackedU16MaxToR32F_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityReduceMaxFinalU16_0x3025b43.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "b99c85bb66f9676d006069f148994d40ab48bb4bfba6363d68f1bea39d10d62c", + "bytes": 431, + "lines": 16, + "symbols": [ + "clarityReduceMaxFinalU16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3025b43", + "symbols": [ + "clarityReduceMaxFinalU16_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityReduceMax_0x301db79.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "d39ab75d0a0c31220083b5b7dd7532f3918e7bd91c09a7eb482c9ad546043832", + "bytes": 854, + "lines": 28, + "symbols": [ + "clarityReduceMax_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x301db79", + "symbols": [ + "clarityReduceMax_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityRgb2Gray4U16_0x301e2b0.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "914e2b18fb091144567c4ae84d992c382bd7796c43b148b6e0cc25ca78e394f4", + "bytes": 1621, + "lines": 39, + "symbols": [ + "clarityRgb2Gray4U16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x301e2b0", + "symbols": [ + "clarityRgb2Gray4U16_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/claritySFLut_0x3078d0e.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "e2b02c9c3e8725068a274907ad78184ad82f8710af722a4266e8f8c51943e07b", + "bytes": 1326, + "lines": 48, + "symbols": [ + "claritySFLut_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3078d0e", + "symbols": [ + "claritySFLut_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/claritySubtractColTileU16_0x30a1fbe.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "8d16470f554de7df8693c89071c77ac19f5ef17534834471d501cee1ded83566", + "bytes": 3399, + "lines": 85, + "symbols": [ + "claritySubtractColTileU16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x30a1fbe", + "symbols": [ + "claritySubtractColTileU16_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityUpScaleBlurSubAggU16_0x308a48a.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "634bb04af760629a50d330b5e6d8ce621f2cadd6f146a0392ddef5f751d6c1a0", + "bytes": 5426, + "lines": 134, + "symbols": [ + "clarityUpScaleBlurSubAggU16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x308a48a", + "symbols": [ + "clarityUpScaleBlurSubAggU16_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityUpScaleBlurSubU16_0x3011f91.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "287d98c06c9498f2acce80018ba202c18849ea0ced91c3b7752762db807a36f4", + "bytes": 4796, + "lines": 141, + "symbols": [ + "clarityUpScaleBlurSubU16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3011f91", + "symbols": [ + "clarityUpScaleBlurSubU16_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/clarityUpScaleBlurU16_0x3042806.comp", + "category": "06_detail_texture", + "stage": "compute", + "sha256": "b35bf0d4ebfddaa394164ed49a6b1edde47e76976f1006eae1a95e4fe002cbc7", + "bytes": 4723, + "lines": 119, + "symbols": [ + "clarityUpScaleBlurU16_computeShaderSource" + ], + "occurrences": [ + { + "offset": "0x3042806", + "symbols": [ + "clarityUpScaleBlurU16_computeShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/create_film_grain_0x30881be.frag", + "category": "06_detail_texture", + "stage": "fragment", + "sha256": "9312a458283d0b188770711e68a03cbb84c9ee17851521bfade82007f52f9460", + "bytes": 3299, + "lines": 112, + "symbols": [ + "create_film_grain_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30881be", + "symbols": [ + "create_film_grain_fragmentShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/create_film_grain_blend_0x30080d5.frag", + "category": "06_detail_texture", + "stage": "fragment", + "sha256": "7e1601b076fb3e2aa1b3dcf0a77dc7b6ae8555136d2a6864cdee1bfd931ec68d", + "bytes": 3129, + "lines": 103, + "symbols": [ + "create_film_grain_blend_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30080d5", + "symbols": [ + "create_film_grain_blend_fragmentShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/highRes_0x300594b.frag", + "category": "06_detail_texture", + "stage": "fragment", + "sha256": "39b941a0ef0e16ff4cf5231186f633cf3d1a21f5c496012c87ee2fb9073b2528", + "bytes": 292, + "lines": 16, + "symbols": [ + "highRes_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x300594b", + "symbols": [ + "highRes_fragmentShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/highRes_0x30a3c90.frag", + "category": "06_detail_texture", + "stage": "fragment", + "sha256": "d43e6aa98922e4a70817554264c0ec3a782bccc2f7ee86eea4d6b2d01b069610", + "bytes": 286, + "lines": 16, + "symbols": [ + "highResShader" + ], + "occurrences": [ + { + "offset": "0x30a3c90", + "symbols": [ + "highResShader" + ] + } + ] + }, + { + "file": "06_detail_texture/unsharpMask_0x300e6ad.frag", + "category": "06_detail_texture", + "stage": "fragment", + "sha256": "97a3f91b9d73967ef8a151f9682d7ea985f95daa0f17389816e0aebcd40f95ad", + "bytes": 3558, + "lines": 130, + "symbols": [ + "unsharpMask_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x300e6ad", + "symbols": [ + "unsharpMask_fragmentShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/unsharpMask_blend_0x3015512.frag", + "category": "06_detail_texture", + "stage": "fragment", + "sha256": "56d92138369c752b7f33e32596e8e89b847aca6c8d34edd223aa24b03c2da76a", + "bytes": 4147, + "lines": 124, + "symbols": [ + "unsharpMask_blend_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3015512", + "symbols": [ + "unsharpMask_blend_fragmentShaderSource" + ] + } + ] + }, + { + "file": "06_detail_texture/unsharpMask_ver_0x2ff9bfb.frag", + "category": "06_detail_texture", + "stage": "fragment", + "sha256": "c868449deef611e5f8a422c002f45d7af1884f8a49c6e911ee974588ca423bf8", + "bytes": 1560, + "lines": 68, + "symbols": [ + "unsharpMask_ver_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x2ff9bfb", + "symbols": [ + "unsharpMask_ver_fragmentShaderSource" + ] + } + ] + }, + { + "file": "07_hdr_ultrahdr/CalculateGainMap_0x3007808.frag", + "category": "07_hdr_ultrahdr", + "stage": "fragment", + "sha256": "91720a36f5ddf2e5682998f88b0e7b64a67bbd938b901c3aef332ec5e4c73b81", + "bytes": 2252, + "lines": 71, + "symbols": [ + "CalculateGainMap_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3007808", + "symbols": [ + "CalculateGainMap_fragmentShaderSource" + ] + } + ] + }, + { + "file": "07_hdr_ultrahdr/applyhdrgainmapyuv_0x30a1626.frag", + "category": "07_hdr_ultrahdr", + "stage": "fragment", + "sha256": "1ba7069316d7577133e3e7016a4aafbed85fa99459e1403a06f899ac94f7a07e", + "bytes": 2455, + "lines": 95, + "symbols": [ + "applyhdrgainmapyuv_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30a1626", + "symbols": [ + "applyhdrgainmapyuv_fragmentShaderSource" + ] + } + ] + }, + { + "file": "07_hdr_ultrahdr/hdr_0x30b046e.frag", + "category": "07_hdr_ultrahdr", + "stage": "fragment", + "sha256": "61d96c794a0bb8bb0d588ef4c5b792793971bdcc73cc92994129331f686949c8", + "bytes": 407, + "lines": 22, + "symbols": [ + "hdrShader" + ], + "occurrences": [ + { + "offset": "0x30b046e", + "symbols": [ + "hdrShader" + ] + } + ] + }, + { + "file": "07_hdr_ultrahdr/hdr_gamma22_0x30878f3.frag", + "category": "07_hdr_ultrahdr", + "stage": "fragment", + "sha256": "a38c2123a061abc12f46152f00b08b8964c81fa0f027a5c3d28c1ae96824329b", + "bytes": 498, + "lines": 22, + "symbols": [ + "hdr_gamma22_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30878f3", + "symbols": [ + "hdr_gamma22_fragmentShaderSource" + ] + } + ] + }, + { + "file": "07_hdr_ultrahdr/hdr_lstar_0x30463fa.frag", + "category": "07_hdr_ultrahdr", + "stage": "fragment", + "sha256": "90cc5ac2e908659c19bc8034fda56ad05c823639ae0190a6eea378ee396428b8", + "bytes": 743, + "lines": 30, + "symbols": [ + "hdr_lstar_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30463fa", + "symbols": [ + "hdr_lstar_fragmentShaderSource" + ] + } + ] + }, + { + "file": "99_unattributed/blend_film_0x3091172.frag", + "category": "99_unattributed", + "stage": "fragment", + "sha256": "6f5a415b9a5b03f63076fed61003d2bf09f8794669895db848df91efef8e2adb", + "bytes": 6950, + "lines": 213, + "symbols": [ + "blend_film_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3091172", + "symbols": [ + "blend_film_fragmentShaderSource" + ] + } + ] + }, + { + "file": "99_unattributed/ev_0x30b1024.frag", + "category": "99_unattributed", + "stage": "fragment", + "sha256": "24294ea4f1e778a2a042f992930bcb4cd1ffeefa35dc56093993040b054f3b88", + "bytes": 833, + "lines": 30, + "symbols": [ + "ev_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x30b1024", + "symbols": [ + "ev_fragmentShaderSource" + ] + } + ] + }, + { + "file": "99_unattributed/highlightRecover_0x307f63c.frag", + "category": "99_unattributed", + "stage": "fragment", + "sha256": "27f287476ef495e8bc566249b46216f0cba1d8540d83cee77915f93dad53a1f5", + "bytes": 5093, + "lines": 124, + "symbols": [ + "highlightRecoverShader" + ], + "occurrences": [ + { + "offset": "0x307f63c", + "symbols": [ + "highlightRecoverShader" + ] + } + ] + }, + { + "file": "99_unattributed/reversecc_0x3061507.frag", + "category": "99_unattributed", + "stage": "fragment", + "sha256": "5f4bda2cc5a1f9e2214c3caf0d9667dc1b42455e50d9ccc2a47b627f38303abe", + "bytes": 2548, + "lines": 96, + "symbols": [ + "reversecc_fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3061507", + "symbols": [ + "reversecc_fragmentShaderSource" + ] + } + ] + }, + { + "file": "99_unattributed/shader_0x3066a62.frag", + "category": "99_unattributed", + "stage": "fragment", + "sha256": "a0b9040c8836f53fb25c010f6c687550f122906977f9d0c82ba3bb5f2d63c253", + "bytes": 310, + "lines": 15, + "symbols": [ + "fragmentShaderSource" + ], + "occurrences": [ + { + "offset": "0x3066a62", + "symbols": [ + "fragmentShaderSource" + ] + } + ] + }, + { + "file": "99_unattributed/unattributed_0x308338f_0x308338f.vert", + "category": "99_unattributed", + "stage": "vertex", + "sha256": "931e3e990f6bc5b1c5054dc46aa339c104ed60393908c8d56fee3d564f7ab898", + "bytes": 191, + "lines": 8, + "symbols": [], + "occurrences": [ + { + "offset": "0x308338f", + "symbols": [] + } + ] + }, + { + "file": "99_unattributed/usm_0x3023371.frag", + "category": "99_unattributed", + "stage": "fragment", + "sha256": "2bf98f5b7d9fed788ba4a5fa3a532cee761edddfc47bf54b34e76225416543f5", + "bytes": 2398, + "lines": 77, + "symbols": [ + "usmShader" + ], + "occurrences": [ + { + "offset": "0x3023371", + "symbols": [ + "usmShader" + ] + } + ] + } + ] +} diff --git a/scripts/research/extract_phocus_glsl.py b/scripts/research/extract_phocus_glsl.py new file mode 100644 index 00000000..5623c48e --- /dev/null +++ b/scripts/research/extract_phocus_glsl.py @@ -0,0 +1,473 @@ +#!/usr/bin/env python3 +"""Extract embedded GLSL sources from Phocus' Android native library. + +The extractor combines three sources of evidence: + +1. NUL-terminated strings beginning with ``#version`` in the ELF file. +2. Exported 8-byte shader-source pointer symbols from ``llvm-nm``. +3. AArch64 relative relocations from ``llvm-readobj`` that connect a pointer + symbol to the corresponding GLSL string. + +Exact duplicate sources are written once. All source offsets and symbol aliases +remain available in manifest.json and manifest.csv. +""" + +from __future__ import annotations + +import argparse +import csv +import hashlib +import json +import re +import shutil +import subprocess +from collections import defaultdict +from dataclasses import dataclass, field +from pathlib import Path + + +NM_LINE = re.compile( + r"^(?P
[0-9a-fA-F]{16})\s+" + r"(?P[0-9a-fA-F]{16})\s+" + r"(?P\S)\s+(?P.+)$" +) +RELOCATION_LINE = re.compile( + r"^\s*0x(?P
[0-9A-Fa-f]+)\s+" + r"R_AARCH64_RELATIVE\s+-\s+0x(?P[0-9A-Fa-f]+)\s*$" +) +SHADER_SYMBOL = re.compile(r"(?i)(shader(source)?|fragmentshader|computeshader|vertexshader)$") + + +@dataclass +class Occurrence: + offset: int + symbols: list[str] = field(default_factory=list) + + +@dataclass +class Shader: + source: str + digest: str + occurrences: list[Occurrence] = field(default_factory=list) + symbols: set[str] = field(default_factory=set) + category: str = "99_unattributed" + stage: str = "fragment" + relative_path: str = "" + + +def run_tool(command: list[str]) -> str: + completed = subprocess.run( + command, + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + encoding="utf-8", + errors="replace", + ) + return completed.stdout + + +def find_tool(name: str) -> str: + path = shutil.which(name) + if path: + return path + llvm_path = Path(r"C:\Program Files\LLVM\bin") / f"{name}.exe" + if llvm_path.exists(): + return str(llvm_path) + raise FileNotFoundError(f"Cannot locate {name}") + + +def read_shader_symbols(binary: Path) -> dict[int, list[str]]: + output = run_tool([find_tool("llvm-nm"), "-D", "-S", "-C", str(binary)]) + result: dict[int, list[str]] = defaultdict(list) + for line in output.splitlines(): + match = NM_LINE.match(line) + if not match: + continue + if match.group("kind") != "D" or int(match.group("size"), 16) != 8: + continue + name = match.group("name") + if not SHADER_SYMBOL.search(name): + continue + result[int(match.group("address"), 16)].append(name) + return result + + +def read_relative_relocations(binary: Path) -> dict[int, int]: + output = run_tool([find_tool("llvm-readobj"), "--relocations", str(binary)]) + result: dict[int, int] = {} + for line in output.splitlines(): + match = RELOCATION_LINE.match(line) + if match: + result[int(match.group("address"), 16)] = int(match.group("target"), 16) + return result + + +def is_plausible_glsl(raw: bytes) -> bool: + return 16 <= len(raw) <= 1_000_000 + + +def scan_glsl(data: bytes) -> dict[int, str]: + result: dict[int, str] = {} + cursor = 0 + marker = b"#version" + while True: + start = data.find(marker, cursor) + if start < 0: + break + end = data.find(b"\0", start) + if end < 0: + break + raw = data[start:end] + if is_plausible_glsl(raw): + result[start] = raw.decode("utf-8", errors="replace").replace("\r\n", "\n") + cursor = start + len(marker) + return result + + +def detect_stage(source: str, symbols: set[str]) -> str: + lowered_source = source.lower() + if "gl_globalinvocationid" in lowered_source or "local_size_" in lowered_source: + return "compute" + if "gl_position" in lowered_source and "gl_fragcoord" not in lowered_source: + return "vertex" + return "fragment" + + +def classify(symbols: set[str], source: str) -> str: + symbol_evidence = " ".join(sorted(symbols)).lower() + evidence = symbol_evidence if symbols else source[:1500].lower() + + rules = [ + ("07_hdr_ultrahdr", ("gainmap", "gain_map", "applyhdr", "hdr_gamma", "hdr_lstar", "hdrshader")), + ("02_demosaic", ("demosaic",)), + ( + "01_raw_sensor", + ( + "bayer", + "blacklevel", + "black_level", + "hotpixel", + "hot_pixel", + "highlightrecovery", + "highlight_recovery", + "multi2", + "neutralisation", + "scene_calibration", + "scenecalibration", + "orientation_90", + "orientation_180", + "orientation_270", + ), + ), + ( + "03_denoise", + ("denoise", "rgbnr", "noise", "cachecmos", "cache_cmos", "graynr"), + ), + ( + "05_lens_geometry", + ( + "lens", + "aberration", + "vignette", + "defringe", + "fringe", + "keystone", + "orientation", + "alignment", + "resize", + "repeatmargin", + "repeat_margin", + ), + ), + ( + "06_detail_texture", + ("clarity", "unsharp", "film_grain", "filmgrain", "highres", "high_res"), + ), + ( + "04_color_tone", + ( + "color", + "gamma", + "gradation", + "filmcurve", + "film_curve", + "selective", + "mark_hue", + "highlightstrength", + "highlight_strength", + "desathighlight", + "desat_highlight", + "icc", + "customcmm", + "custom_cmm", + "grayscale", + "rgb2gray", + ), + ), + ( + "00_common_io", + ( + "vertex", + "fillwithblack", + "fill_black", + "shift", + "yuv2rgb", + "yuv_2_rgb", + "formatconvert", + "format_convert", + "u16f28ui", + "fp16", + "block_downsample", + ), + ), + ] + for category, needles in rules: + if any(needle in evidence for needle in needles): + return category + return "99_unattributed" + + +def simplify_symbol(name: str) -> str: + substitutions = ( + "_computeShaderSource", + "_fragmentShaderSource", + "_vertexShaderSource", + "computeShaderSource", + "fragmentShaderSource", + "vertexShaderSource", + "ShaderSource", + "Shader", + ) + result = name + for suffix in substitutions: + if result.endswith(suffix): + result = result[: -len(suffix)] + break + result = re.sub(r"[^A-Za-z0-9._-]+", "_", result).strip("_.-") + return result or "shader" + + +def choose_name(symbols: set[str], offset: int) -> str: + if not symbols: + return f"unattributed_0x{offset:x}" + candidates = sorted( + symbols, + key=lambda value: ( + value in {"fragmentShaderSource", "vertexShaderSource"}, + "::" in value, + -len(value), + value.lower(), + ), + ) + return simplify_symbol(candidates[0]) + + +def extension_for(stage: str) -> str: + return {"compute": ".comp", "vertex": ".vert", "fragment": ".frag"}[stage] + + +def build_shaders(binary: Path) -> tuple[list[Shader], dict[str, int]]: + data = binary.read_bytes() + scanned = scan_glsl(data) + pointer_symbols = read_shader_symbols(binary) + relocations = read_relative_relocations(binary) + + symbols_by_source: dict[int, list[str]] = defaultdict(list) + unresolved_symbols = 0 + for pointer_address, symbols in pointer_symbols.items(): + target = relocations.get(pointer_address) + if target is None: + unresolved_symbols += len(symbols) + continue + symbols_by_source[target].extend(symbols) + + shaders_by_hash: dict[str, Shader] = {} + for offset, source in sorted(scanned.items()): + digest = hashlib.sha256(source.encode("utf-8")).hexdigest() + shader = shaders_by_hash.setdefault(digest, Shader(source=source, digest=digest)) + aliases = sorted(set(symbols_by_source.get(offset, []))) + shader.occurrences.append(Occurrence(offset=offset, symbols=aliases)) + shader.symbols.update(aliases) + + shaders = list(shaders_by_hash.values()) + for shader in shaders: + first_offset = min(item.offset for item in shader.occurrences) + shader.stage = detect_stage(shader.source, shader.symbols) + shader.category = classify(shader.symbols, shader.source) + base_name = choose_name(shader.symbols, first_offset) + shader.relative_path = str( + Path(shader.category) / f"{base_name}_0x{first_offset:x}{extension_for(shader.stage)}" + ).replace("\\", "/") + + shaders.sort(key=lambda item: (item.category, item.relative_path)) + stats = { + "binary_bytes": len(data), + "version_markers": data.count(b"#version"), + "glsl_occurrences": len(scanned), + "unique_sources": len(shaders), + "exported_source_symbols": sum(len(value) for value in pointer_symbols.values()), + "resolved_source_symbols": sum(len(value) for value in symbols_by_source.values()), + "unresolved_source_symbols": unresolved_symbols, + "attributed_occurrences": sum(bool(symbols_by_source.get(offset)) for offset in scanned), + "unattributed_occurrences": sum(not symbols_by_source.get(offset) for offset in scanned), + } + return shaders, stats + + +def write_output(binary: Path, output: Path, shaders: list[Shader], stats: dict[str, int]) -> None: + output.mkdir(parents=True, exist_ok=True) + managed_categories = { + "00_common_io", + "01_raw_sensor", + "02_demosaic", + "03_denoise", + "04_color_tone", + "05_lens_geometry", + "06_detail_texture", + "07_hdr_ultrahdr", + "99_unattributed", + } + for category in managed_categories: + category_dir = output / category + if category_dir.is_dir(): + shutil.rmtree(category_dir) + for shader in shaders: + target = output / shader.relative_path + target.parent.mkdir(parents=True, exist_ok=True) + header = ( + "/*\n" + " * Recovered from a compiled proprietary binary for personal study.\n" + f" * SHA-256: {shader.digest}\n" + f" * ELF offsets: {', '.join(f'0x{item.offset:x}' for item in shader.occurrences)}\n" + f" * Symbols: {', '.join(sorted(shader.symbols)) if shader.symbols else 'unattributed'}\n" + " */\n\n" + ) + target.write_text(header + shader.source.rstrip() + "\n", encoding="utf-8", newline="\n") + + manifest = { + "source_binary": str(binary.resolve()), + "stats": stats, + "categories": sorted({shader.category for shader in shaders}), + "shaders": [ + { + "file": shader.relative_path, + "category": shader.category, + "stage": shader.stage, + "sha256": shader.digest, + "bytes": len(shader.source.encode("utf-8")), + "lines": shader.source.count("\n") + 1, + "symbols": sorted(shader.symbols), + "occurrences": [ + {"offset": f"0x{item.offset:x}", "symbols": item.symbols} + for item in shader.occurrences + ], + } + for shader in shaders + ], + } + (output / "manifest.json").write_text( + json.dumps(manifest, ensure_ascii=False, indent=2) + "\n", + encoding="utf-8", + newline="\n", + ) + + with (output / "manifest.csv").open("w", encoding="utf-8", newline="") as stream: + writer = csv.writer(stream) + writer.writerow( + ["file", "category", "stage", "sha256", "bytes", "lines", "offsets", "symbols"] + ) + for shader in shaders: + writer.writerow( + [ + shader.relative_path, + shader.category, + shader.stage, + shader.digest, + len(shader.source.encode("utf-8")), + shader.source.count("\n") + 1, + " ".join(f"0x{item.offset:x}" for item in shader.occurrences), + " | ".join(sorted(shader.symbols)), + ] + ) + + category_counts: dict[str, int] = defaultdict(int) + for shader in shaders: + category_counts[shader.category] += 1 + + readme = f"""# Phocus GLSL 研究提取集 + +本目录从 Android Phocus 的 `libcrosssdk.so` 中静态恢复 GLSL,仅用于个人学习和互操作研究。 + +## 提取结果 + +- 二进制中的 GLSL 文本实例:{stats['glsl_occurrences']} +- 按源代码内容去重后:{stats['unique_sources']} +- 可解析的导出 Shader 源符号:{stats['resolved_source_symbols']} +- 有符号归属的文本实例:{stats['attributed_occurrences']} +- 暂时无法绑定导出符号的文本实例:{stats['unattributed_occurrences']} + +完全相同的源码只保存一份;`manifest.json` 和 `manifest.csv` 保留了所有 ELF 偏移、符号别名及重复实例。 + +## 目录 + +| 目录 | 内容 | 文件数 | +|---|---|---:| +| `00_common_io` | 公共顶点、格式转换、填充及输入输出 | {category_counts.get('00_common_io', 0)} | +| `01_raw_sensor` | Bayer、黑电平、坏点、中和、场景校准 | {category_counts.get('01_raw_sensor', 0)} | +| `02_demosaic` | 多阶段 Demosaic 与色噪处理 | {category_counts.get('02_demosaic', 0)} | +| `03_denoise` | CMOS/CCD、RGB 与灰度降噪 | {category_counts.get('03_denoise', 0)} | +| `04_color_tone` | 色彩变换、曲线、Gamma、选择性色彩 | {category_counts.get('04_color_tone', 0)} | +| `05_lens_geometry` | 镜头、色差、暗角、缩放、方向和透视 | {category_counts.get('05_lens_geometry', 0)} | +| `06_detail_texture` | Clarity、锐化和胶片颗粒 | {category_counts.get('06_detail_texture', 0)} | +| `07_hdr_ultrahdr` | HDR 传递函数、Gain Map 生成与应用 | {category_counts.get('07_hdr_ultrahdr', 0)} | +| `99_unattributed` | 可恢复但不能可靠绑定模块名的源码 | {category_counts.get('99_unattributed', 0)} | + +## 阅读顺序 + +建议先看: + +1. `01_raw_sensor`:黑电平、Bayer 中和和高光重建。 +2. `02_demosaic`:按 `pass_0a1 → 0a2 → 0b → 0c → 1 → 2 → 3` 阅读。 +3. `03_denoise`:结合 Demosaic 的 color-noise pass 理解。 +4. `04_color_tone`:Hasselblad Gamma、Film Curve、Gradation 和色彩 LUT。 +5. `07_hdr_ultrahdr`:SDR/HDR 映射以及 UltraHDR Gain Map。 + +## 注意 + +- 文件头注释是提取器添加的,不属于原始 Shader。 +- 部分 Shader 依赖宿主端创建的纹理格式、UBO、LUT 和调度尺寸,不能脱离 C++ 管线直接运行。 +- 分类根据导出符号及源码特征完成,`manifest.json` 才是精确来源索引。 +- 原始程序属于其权利人;请勿把这些文件当作开源代码复制进产品或公开再分发。 +""" + (output / "README.md").write_text(readme, encoding="utf-8", newline="\n") + + notice = """# 来源与使用说明 + +这些 GLSL 源码由已编译的 Hasselblad Phocus Android 原生库静态恢复。 + +- 它们不是 PhotonCamera 项目的源代码。 +- 它们不是开源发布物,也未附带可授予再分发权利的许可证。 +- 本目录的用途是个人学习、兼容性分析和算法研究。 +- 若要在产品中实现类似功能,应根据数学原理独立实现,不应直接复制这些源码。 +""" + (output / "NOTICE.md").write_text(notice, encoding="utf-8", newline="\n") + + +def parse_args() -> argparse.Namespace: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("binary", type=Path, help="Path to libcrosssdk.so") + parser.add_argument("output", type=Path, help="Output directory") + return parser.parse_args() + + +def main() -> None: + args = parse_args() + shaders, stats = build_shaders(args.binary) + write_output(args.binary, args.output, shaders, stats) + print(json.dumps(stats, ensure_ascii=False, indent=2)) + + +if __name__ == "__main__": + main()