feat: chromatic aberration

This commit is contained in:
zhoubinjia committed 2026-03-05 16:56:21 +08:00
1 parent d5067e2fe6
commit 999f794682
11 files changed
+89 -11

No files matched your search

@@ -141,6 +141,7 @@ data class PhotoMetadata(
put("vignette", colorRecipeParams.vignette.toDouble())
put("bleachBypass", colorRecipeParams.bleachBypass.toDouble())
put("halation", colorRecipeParams.halation.toDouble())
put("chromaticAberration", colorRecipeParams.chromaticAberration.toDouble())
put("lutIntensity", colorRecipeParams.lutIntensity.toDouble())
})
} else {
@@ -232,6 +233,7 @@ data class PhotoMetadata(
vignette = colorRecipeParamsObj.optDouble("vignette", 0.0).toFloat(),
bleachBypass = colorRecipeParamsObj.optDouble("bleachBypass", 0.0).toFloat(),
halation = colorRecipeParamsObj.optDouble("halation", 0.0).toFloat(),
chromaticAberration = colorRecipeParamsObj.optDouble("chromaticAberration", 0.0).toFloat(),
lutIntensity = colorRecipeParamsObj.optDouble("lutIntensity", 1.0).toFloat()
)
} else {
@@ -228,6 +228,7 @@ class LutImageProcessor {
val vignette = colorRecipeParams?.vignette ?: 0f
val bleachBypass = colorRecipeParams?.bleachBypass ?: 0f
val halation = colorRecipeParams?.halation ?: 0f
val chromaticAberration = colorRecipeParams?.chromaticAberration ?: 0f
val intensity = colorRecipeParams?.lutIntensity ?: 1f
// 后期处理参数
@@ -270,7 +271,7 @@ class LutImageProcessor {
colorRecipeEnabled,
exposure, contrast, saturation, temperature, tint, fade,
vibrance, highlights, shadows, filmGrain, vignette, bleachBypass,
halation,
halation, chromaticAberration,
intensity, sharpening
// GL_RGBA16 已自动归一化,使用标准 shader
)
@@ -317,6 +318,7 @@ class LutImageProcessor {
val vignette = colorRecipeParams?.vignette ?: 0f
val bleachBypass = colorRecipeParams?.bleachBypass ?: 0f
val halation = colorRecipeParams?.halation ?: 0f
val chromaticAberration = colorRecipeParams?.chromaticAberration ?: 0f
val intensity = colorRecipeParams?.lutIntensity ?: 1f
// 后期处理参数(仅在软件处理模式下生效)
@@ -362,7 +364,7 @@ class LutImageProcessor {
colorRecipeEnabled,
exposure, contrast, saturation, temperature, tint, fade,
vibrance, highlights, shadows, filmGrain, vignette, bleachBypass,
halation,
halation, chromaticAberration,
intensity, sharpening
)
@@ -392,6 +394,7 @@ class LutImageProcessor {
vignette: Float,
bleachBypass: Float,
halation: Float,
chromaticAberration: Float,
intensity: Float,
sharpening: Float
): Bitmap {
@@ -453,6 +456,9 @@ class LutImageProcessor {
GLES30.glUniform1i(GLES30.glGetUniformLocation(program, "uHdfTexture"), 2)
}
// 设置色散参数
GLES30.glUniform1f(GLES30.glGetUniformLocation(program, "uChromaticAberration"), chromaticAberration)
// 设置后期处理参数
GLES30.glUniform1f(GLES30.glGetUniformLocation(program, "uSharpening"), sharpening)
GLES30.glUniform2f(GLES30.glGetUniformLocation(program, "uTexelSize"), 1.0f / width, 1.0f / height)
@@ -1214,6 +1220,9 @@ class LutImageProcessor {
uniform float uHalation; // 0.0 ~ 1.0 (光晕强度)
uniform sampler2D uHdfTexture; // 光晕合成纹理
// 色散效果
uniform float uChromaticAberration; // 0.0 ~ 1.0 (色散强度)
// 后期处理参数
uniform float uSharpening;
uniform vec2 uTexelSize;
@@ -1318,7 +1327,23 @@ class LutImageProcessor {
}
void main() {
vec4 color = sampleImage(vTexCoord);
// 采样图像 (应用色散效果)
vec4 color;
if (uChromaticAberration > 0.0) {
vec2 center = vec2(0.5);
vec2 dir = vTexCoord - center;
float dist = length(dir);
float offset = dist * dist * uChromaticAberration * 0.03;
vec2 rUV = vTexCoord + dir * offset;
vec2 bUV = vTexCoord - dir * offset;
float r = sampleImage(rUV).r;
float g = sampleImage(vTexCoord).g;
float b = sampleImage(bUV).b;
float a = sampleImage(vTexCoord).a;
color = vec4(r, g, b, a);
} else {
color = sampleImage(vTexCoord);
}
// === 色彩配方处理(按专业后期流程顺序) ===
if (uColorRecipeEnabled) {
@@ -49,6 +49,7 @@ class LutManager(private val context: Context) {
private fun vignetteKey(lutId: String) = floatPreferencesKey("${lutId}_vignette")
private fun bleachBypassKey(lutId: String) = floatPreferencesKey("${lutId}_bleachBypass")
private fun halationKey(lutId: String) = floatPreferencesKey("${lutId}_halation")
private fun chromaticAberrationKey(lutId: String) = floatPreferencesKey("${lutId}_chromaticAberration")
private fun lutIntensityKey(lutId: String) = floatPreferencesKey("${lutId}_lutIntensity")
private fun remarksKey(lutId: String) =
androidx.datastore.preferences.core.stringPreferencesKey("${lutId}_remarks")
@@ -82,6 +83,7 @@ class LutManager(private val context: Context) {
vignette = preferences[vignetteKey(lutId)] ?: 0f,
bleachBypass = preferences[bleachBypassKey(lutId)] ?: 0f,
halation = preferences[halationKey(lutId)] ?: 0f,
chromaticAberration = preferences[chromaticAberrationKey(lutId)] ?: 0f,
lutIntensity = preferences[lutIntensityKey(lutId)] ?: 1f,
remarks = preferences[remarksKey(lutId)] ?: ""
)
@@ -221,6 +223,7 @@ class LutManager(private val context: Context) {
preferences[vignetteKey(lutId)] = params.vignette
preferences[bleachBypassKey(lutId)] = params.bleachBypass
preferences[halationKey(lutId)] = params.halation
preferences[chromaticAberrationKey(lutId)] = params.chromaticAberration
preferences[lutIntensityKey(lutId)] = params.lutIntensity
preferences[remarksKey(lutId)] = params.remarks
}
@@ -249,6 +252,7 @@ class LutManager(private val context: Context) {
vignette = preferences[vignetteKey(lutId)] ?: 0f,
bleachBypass = preferences[bleachBypassKey(lutId)] ?: 0f,
halation = preferences[halationKey(lutId)] ?: 0f,
chromaticAberration = preferences[chromaticAberrationKey(lutId)] ?: 0f,
lutIntensity = preferences[lutIntensityKey(lutId)] ?: 1f,
remarks = preferences[remarksKey(lutId)] ?: ""
)
@@ -285,6 +289,7 @@ class LutManager(private val context: Context) {
preferences.remove(vignetteKey(lutId))
preferences.remove(bleachBypassKey(lutId))
preferences.remove(halationKey(lutId))
preferences.remove(chromaticAberrationKey(lutId))
preferences.remove(lutIntensityKey(lutId))
preferences.remove(remarksKey(lutId))
}
@@ -96,6 +96,7 @@ class LutRenderer : GLSurfaceView.Renderer {
private var uFilmGrainLocation: Int = 0
private var uVignetteLocation: Int = 0
private var uBleachBypassLocation: Int = 0
private var uChromaticAberrationLocation: Int = 0
// Attribute 位置
private var aPositionLocation: Int = 0
@@ -176,6 +177,9 @@ class LutRenderer : GLSurfaceView.Renderer {
@Volatile
var bleachBypass: Float = 0f // 0.0 ~ 1.0
@Volatile
var chromaticAberration: Float = 0f // 0.0 ~ 1.0
// 渲染尺寸
private var viewportWidth: Int = 0
private var viewportHeight: Int = 0
@@ -490,6 +494,9 @@ class LutRenderer : GLSurfaceView.Renderer {
GLES30.glUniform1f(uBleachBypassLocation, bleachBypass)
}
// 色散效果独立于色彩配方,始终更新
GLES30.glUniform1f(uChromaticAberrationLocation, chromaticAberration)
// 绑定顶点缓冲
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, vertexBufferId)
GLES30.glEnableVertexAttribArray(aPositionLocation)
@@ -591,6 +598,7 @@ class LutRenderer : GLSurfaceView.Renderer {
uFilmGrainLocation = GLES30.glGetUniformLocation(programId, "uFilmGrain")
uVignetteLocation = GLES30.glGetUniformLocation(programId, "uVignette")
uBleachBypassLocation = GLES30.glGetUniformLocation(programId, "uBleachBypass")
uChromaticAberrationLocation = GLES30.glGetUniformLocation(programId, "uChromaticAberration")
// Attribute 位置
aPositionLocation = GLES30.glGetAttribLocation(programId, "aPosition")
@@ -1264,7 +1272,8 @@ class LutRenderer : GLSurfaceView.Renderer {
fade = fade,
filmGrain = filmGrain,
vignette = vignette,
bleachBypass = bleachBypass
bleachBypass = bleachBypass,
chromaticAberration = chromaticAberration
)
}
}
@@ -135,6 +135,7 @@ object Shaders {
uniform float uFilmGrain; // 0.0 ~ 1.0 (颗粒强度)
uniform float uVignette; // -1.0 ~ +1.0 (晕影,负值暗角,正值亮角)
uniform float uBleachBypass; // 0.0 ~ 1.0 (留银冲洗强度)
uniform float uChromaticAberration; // 0.0 ~ 1.0 (色散强度)
const vec3 W = vec3(0.2126, 0.7152, 0.0722);
@@ -205,11 +206,28 @@ object Shaders {
void main()
{
// 从相机纹理采样原始颜色
vec4 color = texture(uCameraTexture, vTexCoord);
// 从相机纹理采样原始颜色 (应用色散效果)
vec4 color;
if (uChromaticAberration > 0.001) {
// 色散:沿径向偏移 R/B 通道,边缘更强
vec2 center = vec2(0.5);
vec2 dir = vTexCoord - center;
float dist = length(dir);
// 偏移量 = 距离中心的平方 * 强度,模拟真实镜头的二次方色散
float offset = dist * dist * uChromaticAberration * 0.03;
vec2 rUV = vTexCoord + dir * offset;
vec2 bUV = vTexCoord - dir * offset;
float r = texture(uCameraTexture, rUV).r;
float g = texture(uCameraTexture, vTexCoord).g;
float b = texture(uCameraTexture, bUV).b;
float a = texture(uCameraTexture, vTexCoord).a;
color = vec4(r, g, b, a);
} else {
color = texture(uCameraTexture, vTexCoord);
}
// Early exit 优化:无任何调整时直接输出
if (!uColorRecipeEnabled && !uLutEnabled) {
if (!uColorRecipeEnabled && !uLutEnabled && uChromaticAberration <= 0.001) {
fragColor = color;
return;
}
@@ -21,6 +21,7 @@ data class ColorRecipeParams(
val vignette: Float = 0f, // -1.0 ~ +1.0 (晕影,负值暗角,正值亮角)
val bleachBypass: Float = 0f, // 0.0 ~ 1.0 (留银冲洗强度,0为无效果)
val halation: Float = 0f, // 0.0 ~ 1.0 (光晕/高光扩散强度,0为无效果,模拟 GR3 HDF)
val chromaticAberration: Float = 0f, // 0.0 ~ 1.0 (色散/边缘溢色强度,0为无效果)
val lutIntensity: Float = 1f, // 0.0 ~ 1.0 (LUT强度,1为完全应用)
val remarks: String = "", // 用户备注
) {
@@ -41,6 +42,7 @@ data class ColorRecipeParams(
vignette == 0f &&
bleachBypass == 0f &&
halation == 0f &&
chromaticAberration == 0f &&
remarks.isEmpty()
}
@@ -61,6 +63,7 @@ data class ColorRecipeParams(
vignette == other.vignette &&
bleachBypass == other.bleachBypass &&
halation == other.halation &&
chromaticAberration == other.chromaticAberration &&
lutIntensity == other.lutIntensity &&
remarks == other.remarks
}
@@ -97,6 +100,7 @@ enum class RecipeParam(
VIGNETTE(R.string.recipe_param_vignette, -1.0f, 1.0f, 0f),
BLEACH_BYPASS(R.string.recipe_param_bleach_bypass, 0.0f, 1.0f, 0f),
HALATION(R.string.recipe_param_halation, 0.0f, 1.0f, 0f),
CHROMATIC_ABERRATION(R.string.recipe_param_chromatic_aberration, 0.0f, 1.0f, 0f),
LUT_INTENSITY(R.string.recipe_param_lut_intensity, 0.0f, 1.0f, 1f);
/**
@@ -124,6 +128,7 @@ enum class RecipeParam(
VIGNETTE -> params.vignette
BLEACH_BYPASS -> params.bleachBypass
HALATION -> params.halation
CHROMATIC_ABERRATION -> params.chromaticAberration
LUT_INTENSITY -> params.lutIntensity
}
}
@@ -147,6 +152,7 @@ enum class RecipeParam(
VIGNETTE -> params.copy(vignette = clampedValue)
BLEACH_BYPASS -> params.copy(bleachBypass = clampedValue)
HALATION -> params.copy(halation = clampedValue)
CHROMATIC_ABERRATION -> params.copy(chromaticAberration = clampedValue)
LUT_INTENSITY -> params.copy(lutIntensity = clampedValue)
}
}
@@ -173,6 +173,7 @@ class CameraGLSurfaceView @JvmOverloads constructor(
filmGrain: Float,
vignette: Float,
bleachBypass: Float,
chromaticAberration: Float,
lutIntensity: Float,
) {
renderer.exposure = exposure
@@ -187,6 +188,7 @@ class CameraGLSurfaceView @JvmOverloads constructor(
renderer.filmGrain = filmGrain
renderer.vignette = vignette
renderer.bleachBypass = bleachBypass
renderer.chromaticAberration = chromaticAberration
renderer.lutIntensity = lutIntensity
requestRender()
}
@@ -168,6 +168,7 @@ fun CameraPreviewGL(
filmGrain = colorRecipeParams.filmGrain,
vignette = colorRecipeParams.vignette,
bleachBypass = colorRecipeParams.bleachBypass,
chromaticAberration = colorRecipeParams.chromaticAberration,
lutIntensity = colorRecipeParams.lutIntensity,
)
} else {
@@ -53,6 +53,7 @@ fun ColorRecipePanel(
R.string.recipe_tab_light,
R.string.recipe_tab_color,
R.string.recipe_tab_texture,
R.string.recipe_tab_lens,
)
val parameterGroups = listOf(
listOf(
@@ -72,7 +73,10 @@ fun ColorRecipePanel(
RecipeParam.FILM_GRAIN,
RecipeParam.FADE,
RecipeParam.BLEACH_BYPASS,
RecipeParam.HALATION
),
listOf(
RecipeParam.HALATION,
RecipeParam.CHROMATIC_ABERRATION
)
)
@@ -336,7 +340,8 @@ private fun formatParamValue(param: RecipeParam, value: Float): String {
RecipeParam.FADE,
RecipeParam.FILM_GRAIN,
RecipeParam.BLEACH_BYPASS,
RecipeParam.HALATION -> String.format("%.2f", value)
RecipeParam.HALATION,
RecipeParam.CHROMATIC_ABERRATION -> String.format("%.2f", value)
RecipeParam.LUT_INTENSITY -> String.format("%.2f", value)
}
@@ -360,6 +365,7 @@ private fun getParamColor(param: RecipeParam): Color {
RecipeParam.VIGNETTE -> Color(0xFF795548) // 棕色
RecipeParam.BLEACH_BYPASS -> Color(0xFF00BCD4) // 青色
RecipeParam.HALATION -> Color(0xFFFF7043) // 暖橙色(光晕)
RecipeParam.CHROMATIC_ABERRATION -> Color(0xFFAB47BC) // 紫色(色散)
RecipeParam.LUT_INTENSITY -> Color(0xFF9E9E9E) // 灰色
}
}
+3 -1
View File
@@ -218,7 +218,8 @@
<string name="recipe_param_film_grain">颗粒</string>
<string name="recipe_param_vignette">晕影</string>
<string name="recipe_param_bleach_bypass">留银冲洗</string>
<string name="recipe_param_halation">光晕</string>
<string name="recipe_param_halation">HDF</string>
<string name="recipe_param_chromatic_aberration">色散</string>
<string name="recipe_param_lut_intensity">滤镜强度</string>
<!-- Color Recipe Tabs -->
@@ -226,6 +227,7 @@
<string name="recipe_tab_color">颜色</string>
<string name="recipe_tab_light">亮度</string>
<string name="recipe_tab_texture">效果</string>
<string name="recipe_tab_lens">氛围</string>
<string name="recipe_tab_post">细节</string>
<string name="recipe_tab_remarks">备注</string>
<string name="recipe_placeholder_remarks">点击添加备注信息…</string>
+3 -1
View File
@@ -223,7 +223,8 @@
<string name="recipe_param_film_grain">Grain</string>
<string name="recipe_param_vignette">Vignette</string>
<string name="recipe_param_bleach_bypass">Bleach Bypass</string>
<string name="recipe_param_halation">Halation</string>
<string name="recipe_param_halation">HDF</string>
<string name="recipe_param_chromatic_aberration">CA</string>
<string name="recipe_param_lut_intensity">LUT</string>
<!-- Color Recipe Tabs -->
@@ -231,6 +232,7 @@
<string name="recipe_tab_color">Color</string>
<string name="recipe_tab_light">Light</string>
<string name="recipe_tab_texture">Texture</string>
<string name="recipe_tab_lens">Atmosphere</string>
<string name="recipe_tab_post">Post</string>
<string name="recipe_tab_remarks">Notes</string>
<string name="recipe_placeholder_remarks">Tap to add notes…</string>