feat: add red halation effect to color recipes
This commit is contained in:
1 parent
b34b4dc998
commit
3d50373f06
9 files changed
+339
-28
No files matched your search
@@ -69,6 +69,14 @@ class LutImageProcessor {
|
||||
private var hdfWidth = 0
|
||||
private var hdfHeight = 0
|
||||
|
||||
// Halation (胶片红晕) 效果资源
|
||||
private var halationExtractBlurHProgram = 0
|
||||
private var halationBlurVProgram = 0
|
||||
private var halationTexId = IntArray(2)
|
||||
private var halationFboId = IntArray(2)
|
||||
private var halationWidth = 0
|
||||
private var halationHeight = 0
|
||||
|
||||
private var isInitialized = false
|
||||
|
||||
// Uniform 位置
|
||||
@@ -237,6 +245,7 @@ class LutImageProcessor {
|
||||
// 提取色彩配方参数
|
||||
val effectiveRecipeParams = colorRecipeParams?.let(ColorPaletteMapper::mergeIntoEffectiveParams)
|
||||
val halation = effectiveRecipeParams?.halation ?: 0f
|
||||
val redHalation = effectiveRecipeParams?.redHalation ?: 0f
|
||||
|
||||
// 后期处理参数
|
||||
val sharpening: Float = sharpeningValue
|
||||
@@ -271,6 +280,10 @@ class LutImageProcessor {
|
||||
renderHDFBlur(inputTexId, width, height, halation)
|
||||
currentCoroutineContext().ensureActive()
|
||||
}
|
||||
if (redHalation > 0f) {
|
||||
renderHalationBlur(inputTexId, width, height, redHalation)
|
||||
currentCoroutineContext().ensureActive()
|
||||
}
|
||||
|
||||
// 执行渲染
|
||||
val outputBitmap = performRender(
|
||||
@@ -376,6 +389,7 @@ class LutImageProcessor {
|
||||
// 提取色彩配方参数
|
||||
val effectiveRecipeParams = colorRecipeParams?.let(ColorPaletteMapper::mergeIntoEffectiveParams)
|
||||
val halation = effectiveRecipeParams?.halation ?: 0f
|
||||
val redHalation = effectiveRecipeParams?.redHalation ?: 0f
|
||||
|
||||
// 后期处理参数(仅在软件处理模式下生效)
|
||||
val sharpening: Float = sharpeningValue
|
||||
@@ -413,6 +427,10 @@ class LutImageProcessor {
|
||||
renderHDFBlur(inputTexId, width, height, halation)
|
||||
currentCoroutineContext().ensureActive()
|
||||
}
|
||||
if (redHalation > 0f) {
|
||||
renderHalationBlur(inputTexId, width, height, redHalation)
|
||||
currentCoroutineContext().ensureActive()
|
||||
}
|
||||
|
||||
// 执行渲染
|
||||
val outputBitmap = performRender(
|
||||
@@ -608,6 +626,7 @@ class LutImageProcessor {
|
||||
val vignette = effectiveRecipeParams?.vignette ?: 0f
|
||||
val bleachBypass = effectiveRecipeParams?.bleachBypass ?: 0f
|
||||
val halation = effectiveRecipeParams?.halation ?: 0f
|
||||
val redHalation = effectiveRecipeParams?.redHalation ?: 0f
|
||||
val chromaticAberration = effectiveRecipeParams?.chromaticAberration ?: 0f
|
||||
val noise = effectiveRecipeParams?.noise ?: 0f
|
||||
val lowRes = effectiveRecipeParams?.lowRes ?: 0f
|
||||
@@ -715,6 +734,14 @@ class LutImageProcessor {
|
||||
GLES30.glUniform1i(GLES30.glGetUniformLocation(program, "uHdfTexture"), 2)
|
||||
}
|
||||
|
||||
// 设置 Halation 参数
|
||||
GLES30.glUniform1f(GLES30.glGetUniformLocation(program, "uRedHalation"), redHalation)
|
||||
if (redHalation > 0f) {
|
||||
GLES30.glActiveTexture(GLES30.GL_TEXTURE4)
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, halationTexId[1])
|
||||
GLES30.glUniform1i(GLES30.glGetUniformLocation(program, "uRedHalationTexture"), 4)
|
||||
}
|
||||
|
||||
// 设置色散参数
|
||||
GLES30.glUniform1f(GLES30.glGetUniformLocation(program, "uChromaticAberration"), chromaticAberration)
|
||||
|
||||
@@ -1002,11 +1029,13 @@ class LutImageProcessor {
|
||||
val vShader = compileShader(GLES30.GL_VERTEX_SHADER, IMAGE_VERTEX_SHADER)
|
||||
hdfExtractBlurHProgram = createProgram(vShader, HDF_EXTRACT_BLUR_H_SHADER)
|
||||
hdfBlurVProgram = createProgram(vShader, HDF_BLUR_V_SHADER)
|
||||
halationExtractBlurHProgram = createProgram(vShader, HALATION_EXTRACT_BLUR_H_SHADER)
|
||||
halationBlurVProgram = createProgram(vShader, HDF_BLUR_V_SHADER)
|
||||
GLES30.glDeleteShader(vShader)
|
||||
|
||||
PLog.d(
|
||||
TAG,
|
||||
"HDF programs initialized: ExtractH=$hdfExtractBlurHProgram BlurV=$hdfBlurVProgram"
|
||||
"HDF/Halation programs initialized"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1227,6 +1256,95 @@ class LutImageProcessor {
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0)
|
||||
}
|
||||
|
||||
private fun setupHalationFramebuffers(width: Int, height: Int) {
|
||||
val dsW = width / 4
|
||||
val dsH = height / 4
|
||||
if (halationWidth == dsW && halationHeight == dsH && halationTexId[0] != 0) return
|
||||
halationWidth = dsW
|
||||
halationHeight = dsH
|
||||
|
||||
for (i in 0..1) {
|
||||
if (halationTexId[i] != 0) GLES30.glDeleteTextures(1, intArrayOf(halationTexId[i]), 0)
|
||||
if (halationFboId[i] != 0) GLES30.glDeleteFramebuffers(1, intArrayOf(halationFboId[i]), 0)
|
||||
val t = IntArray(1)
|
||||
val f = IntArray(1)
|
||||
GLES30.glGenTextures(1, t, 0)
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, t[0])
|
||||
GLES30.glTexImage2D(
|
||||
GLES30.GL_TEXTURE_2D, 0, GLES30.GL_RGBA16F,
|
||||
dsW, dsH, 0,
|
||||
GLES30.GL_RGBA, GLES30.GL_HALF_FLOAT, null
|
||||
)
|
||||
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR)
|
||||
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR)
|
||||
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE)
|
||||
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE)
|
||||
GLES30.glGenFramebuffers(1, f, 0)
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, f[0])
|
||||
GLES30.glFramebufferTexture2D(
|
||||
GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0,
|
||||
GLES30.GL_TEXTURE_2D, t[0], 0
|
||||
)
|
||||
halationTexId[i] = t[0]
|
||||
halationFboId[i] = f[0]
|
||||
}
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0)
|
||||
}
|
||||
|
||||
private fun renderHalationBlur(
|
||||
sourceTexId: Int,
|
||||
width: Int,
|
||||
height: Int,
|
||||
halation: Float
|
||||
) {
|
||||
setupHalationFramebuffers(width, height)
|
||||
if (halationExtractBlurHProgram == 0 || halationBlurVProgram == 0) return
|
||||
|
||||
val dsW = width / 4
|
||||
val dsH = height / 4
|
||||
val texelW = 1.0f / dsW
|
||||
val texelH = 1.0f / dsH
|
||||
|
||||
val threshold = 0.75f // 恒定高光提取阈值,只让强度随滑块变化
|
||||
|
||||
val identityMatrix = FloatArray(16)
|
||||
android.opengl.Matrix.setIdentityM(identityMatrix, 0)
|
||||
|
||||
// Pass 1: Extract + Blur H
|
||||
GLES30.glUseProgram(halationExtractBlurHProgram)
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, halationFboId[0])
|
||||
GLES30.glViewport(0, 0, dsW, dsH)
|
||||
|
||||
GLES30.glActiveTexture(GLES30.GL_TEXTURE0)
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, sourceTexId)
|
||||
GLES30.glUniform1i(GLES30.glGetUniformLocation(halationExtractBlurHProgram, "uInputTexture"), 0)
|
||||
GLES30.glUniform2f(GLES30.glGetUniformLocation(halationExtractBlurHProgram, "uTexelSize"), texelW, texelH)
|
||||
GLES30.glUniform1f(GLES30.glGetUniformLocation(halationExtractBlurHProgram, "uThreshold"), threshold)
|
||||
GLES30.glUniform1f(GLES30.glGetUniformLocation(halationExtractBlurHProgram, "uStrength"), halation)
|
||||
|
||||
GLES30.glUniformMatrix4fv(
|
||||
GLES30.glGetUniformLocation(halationExtractBlurHProgram, "uMVPMatrix"), 1, false, identityMatrix, 0
|
||||
)
|
||||
drawQuad(halationExtractBlurHProgram)
|
||||
|
||||
// Pass 2: Blur V
|
||||
GLES30.glUseProgram(halationBlurVProgram)
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, halationFboId[1])
|
||||
GLES30.glViewport(0, 0, dsW, dsH)
|
||||
|
||||
GLES30.glActiveTexture(GLES30.GL_TEXTURE0)
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, halationTexId[0])
|
||||
GLES30.glUniform1i(GLES30.glGetUniformLocation(halationBlurVProgram, "uInputTexture"), 0)
|
||||
GLES30.glUniform2f(GLES30.glGetUniformLocation(halationBlurVProgram, "uTexelSize"), texelW, texelH)
|
||||
|
||||
GLES30.glUniformMatrix4fv(
|
||||
GLES30.glGetUniformLocation(halationBlurVProgram, "uMVPMatrix"), 1, false, identityMatrix, 0
|
||||
)
|
||||
drawQuad(halationBlurVProgram)
|
||||
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染 HDF 光晕效果
|
||||
* 3 pass: 高光提取+水平模糊 → 垂直模糊 → 全分辨率合成
|
||||
@@ -1417,6 +1535,13 @@ class LutImageProcessor {
|
||||
if (hdfTexId[i] != 0) GLES30.glDeleteTextures(1, intArrayOf(hdfTexId[i]), 0)
|
||||
if (hdfFboId[i] != 0) GLES30.glDeleteFramebuffers(1, intArrayOf(hdfFboId[i]), 0)
|
||||
}
|
||||
|
||||
if (halationExtractBlurHProgram != 0) GLES30.glDeleteProgram(halationExtractBlurHProgram)
|
||||
if (halationBlurVProgram != 0) GLES30.glDeleteProgram(halationBlurVProgram)
|
||||
for (i in 0..1) {
|
||||
if (halationTexId[i] != 0) GLES30.glDeleteTextures(1, intArrayOf(halationTexId[i]), 0)
|
||||
if (halationFboId[i] != 0) GLES30.glDeleteFramebuffers(1, intArrayOf(halationFboId[i]), 0)
|
||||
}
|
||||
|
||||
EGL14.eglMakeCurrent(eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT)
|
||||
EGL14.eglDestroySurface(eglDisplay, eglSurface)
|
||||
@@ -1499,6 +1624,8 @@ class LutImageProcessor {
|
||||
// HDF 光晕效果
|
||||
uniform float uHalation; // 0.0 ~ 1.0 (光晕强度)
|
||||
uniform sampler2D uHdfTexture; // 光晕合成纹理
|
||||
uniform float uRedHalation; // 0.0 ~ 1.0 (胶片红晕强度)
|
||||
uniform sampler2D uRedHalationTexture; // 胶片红晕合成纹理
|
||||
|
||||
// 色散效果
|
||||
uniform float uChromaticAberration; // 0.0 ~ 1.0 (色散强度)
|
||||
@@ -2088,6 +2215,12 @@ class LutImageProcessor {
|
||||
// 5. 稍微削减对比度以获得“电影感”
|
||||
color.rgb = (color.rgb - 0.5) * (1.0 - uHalation * 0.08) + 0.5;
|
||||
}
|
||||
|
||||
if (uRedHalation > 0.0) {
|
||||
vec3 redBloom = texture(uRedHalationTexture, uvCoord).rgb;
|
||||
vec3 redBloomEffect = redBloom * uRedHalation * 3.5;
|
||||
color.rgb = vec3(1.0) - (vec3(1.0) - color.rgb) * (vec3(1.0) - redBloomEffect);
|
||||
}
|
||||
|
||||
// === LUT 处理(在色彩配方之后) ===
|
||||
if (uLutEnabled && uLutIntensity > 0.0) {
|
||||
@@ -2144,7 +2277,41 @@ class LutImageProcessor {
|
||||
"vec4 sampleImage(vec2 uv) { return texture(uImageTexture, uv); }\n" +
|
||||
SHADER_BODY
|
||||
|
||||
// === HDF (Highlight Diffusion Filter) Shaders ===
|
||||
// === HDF (Highlight Diffusion Filter) \u0026 Halation Shaders ===
|
||||
|
||||
private val HALATION_EXTRACT_BLUR_H_SHADER = """
|
||||
#version 300 es
|
||||
precision highp float;
|
||||
|
||||
in vec2 vTexCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D uInputTexture;
|
||||
uniform vec2 uTexelSize;
|
||||
uniform float uThreshold;
|
||||
uniform float uStrength;
|
||||
|
||||
void main() {
|
||||
vec3 tint = vec3(1.0, 0.15, 0.0);
|
||||
|
||||
#define EXTRACT(sampleColor) \
|
||||
(sampleColor * tint * smoothstep(uThreshold, uThreshold + 0.15, mix(dot(sampleColor, vec3(0.2126, 0.7152, 0.0722)), max(sampleColor.r, max(sampleColor.g, sampleColor.b)), 0.6)))
|
||||
|
||||
vec3 color = texture(uInputTexture, vTexCoord).rgb;
|
||||
vec3 sum = EXTRACT(color) * 0.204164;
|
||||
|
||||
float weights[5] = float[](0.204164, 0.304005, 0.093910, 0.010416, 0.000005);
|
||||
float offsets[5] = float[](0.0, 1.407333, 3.294215, 5.176470, 7.058823);
|
||||
|
||||
for (int i = 1; i < 5; i++) {
|
||||
float offset = offsets[i] * uTexelSize.x * 2.0;
|
||||
sum += EXTRACT(texture(uInputTexture, vTexCoord + vec2(offset, 0.0)).rgb) * weights[i];
|
||||
sum += EXTRACT(texture(uInputTexture, vTexCoord - vec2(offset, 0.0)).rgb) * weights[i];
|
||||
}
|
||||
|
||||
fragColor = vec4(sum, 1.0);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
/**
|
||||
* Pass 1: 提取高光区域 + 水平高斯模糊
|
||||
|
||||
@@ -47,7 +47,7 @@ class LutManager(private val context: Context) {
|
||||
"exposure", "contrast", "saturation", "temperature", "tint", "fade", "color",
|
||||
"highlights", "shadows", "toneToe", "toneShoulder", "tonePivot",
|
||||
"paletteX", "paletteY", "paletteDensity",
|
||||
"filmGrain", "vignette", "bleachBypass", "halation", "chromaticAberration",
|
||||
"filmGrain", "vignette", "bleachBypass", "halation", "redHalation", "chromaticAberration",
|
||||
"noise", "lowRes",
|
||||
"skinHue", "skinChroma", "skinLightness",
|
||||
"redHue", "redChroma", "redLightness",
|
||||
@@ -86,6 +86,7 @@ class LutManager(private val context: Context) {
|
||||
vignette = f("vignette"),
|
||||
bleachBypass = f("bleachBypass"),
|
||||
halation = f("halation"),
|
||||
redHalation = f("redHalation"),
|
||||
chromaticAberration = f("chromaticAberration"),
|
||||
noise = f("noise"),
|
||||
lowRes = f("lowRes"),
|
||||
|
||||
@@ -245,6 +245,12 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
private var hdfFboId = IntArray(2)
|
||||
private var hdfWidth: Int = 0
|
||||
private var hdfHeight: Int = 0
|
||||
private var halationExtractBlurHProgram: Int = 0
|
||||
private var halationBlurVProgram: Int = 0
|
||||
private var halationTexId = IntArray(2)
|
||||
private var halationFboId = IntArray(2)
|
||||
private var halationWidth: Int = 0
|
||||
private var halationHeight: Int = 0
|
||||
|
||||
// Bokeh 实时预览资源
|
||||
private var bokehProgramId: Int = 0
|
||||
@@ -402,6 +408,9 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
@Volatile
|
||||
var halation: Float = 0f // 0.0 ~ 1.0
|
||||
|
||||
@Volatile
|
||||
var redHalation: Float = 0f // 0.0 ~ 1.0
|
||||
|
||||
@Volatile var primaryRedHue: Float = 0f
|
||||
@Volatile var primaryRedSaturation: Float = 0f
|
||||
@Volatile var primaryRedLightness: Float = 0f
|
||||
@@ -573,6 +582,12 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
hdfFboId = IntArray(2)
|
||||
hdfWidth = 0
|
||||
hdfHeight = 0
|
||||
halationExtractBlurHProgram = 0
|
||||
halationBlurVProgram = 0
|
||||
halationTexId = IntArray(2)
|
||||
halationFboId = IntArray(2)
|
||||
halationWidth = 0
|
||||
halationHeight = 0
|
||||
bokehProgramId = 0
|
||||
depthTextureId = 0
|
||||
lastDepthMap = null
|
||||
@@ -911,13 +926,15 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
videoRenderStatsFrames = 0
|
||||
}
|
||||
val hdfEnabled = halation > 0.001f
|
||||
val halationEnabled = redHalation > 0.001f
|
||||
val postProcessEffectEnabled = hdfEnabled || halationEnabled
|
||||
val bokehNeeded = aperture > 0f && depthMap != null
|
||||
val suppressBaselineLayerForVideoLog = videoLogProfile.isEnabled
|
||||
val hasBaselineLayer = hasBaselineLayer() && !suppressBaselineLayerForVideoLog
|
||||
val hasCreativeLayer = hasCreativeLayer()
|
||||
val hasDualLayer = hasBaselineLayer && hasCreativeLayer
|
||||
uploadPendingCurveTextures()
|
||||
val needsFbo = (liveRecorder != null || activeVideoRecorder != null || hdfEnabled || bokehNeeded || hasDualLayer || (!isAutoFocus && focusPeakingEnabled)) &&
|
||||
val needsFbo = (liveRecorder != null || activeVideoRecorder != null || postProcessEffectEnabled || bokehNeeded || hasDualLayer || (!isAutoFocus && focusPeakingEnabled)) &&
|
||||
fboId != 0 && fboTextureId != 0
|
||||
|
||||
if (needsFbo) {
|
||||
@@ -982,6 +999,9 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
if (hdfEnabled) {
|
||||
renderHdfPreviewBlur(currentTexId, currentWidth, currentHeight)
|
||||
}
|
||||
if (halationEnabled) {
|
||||
renderHalationPreviewBlur(currentTexId, currentWidth, currentHeight)
|
||||
}
|
||||
|
||||
|
||||
// 确保 FBO 内容已刷入显存
|
||||
@@ -1018,8 +1038,8 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
activeVideoRecorder?.targetSize?.let { targetSize ->
|
||||
ensureRecordFbo(targetSize.width, targetSize.height)
|
||||
if (recordFboId != 0 && recordTextureId != 0) {
|
||||
if (hdfEnabled) {
|
||||
drawHdfComposite(recordFboId, targetSize.width, targetSize.height, currentTexId)
|
||||
if (postProcessEffectEnabled) {
|
||||
drawPostProcessComposite(recordFboId, targetSize.width, targetSize.height, currentTexId)
|
||||
} else if (bokehNeeded) {
|
||||
drawFboToScreen(recordFboId, targetSize.width, targetSize.height, currentTexId)
|
||||
} else {
|
||||
@@ -1054,15 +1074,15 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
}
|
||||
|
||||
// 6. 显示到屏幕
|
||||
if (hdfEnabled) {
|
||||
drawHdfComposite(0, viewportWidth, viewportHeight, currentTexId)
|
||||
if (postProcessEffectEnabled) {
|
||||
drawPostProcessComposite(0, viewportWidth, viewportHeight, currentTexId)
|
||||
} else {
|
||||
drawFboToScreen(0, viewportWidth, viewportHeight, currentTexId)
|
||||
}
|
||||
val finalDisplayTextureId = currentTexId
|
||||
val finalDisplayWidth = viewportWidth
|
||||
val finalDisplayHeight = viewportHeight
|
||||
val needsHdfCompositeForSampling = hdfEnabled
|
||||
val needsHdfCompositeForSampling = postProcessEffectEnabled
|
||||
if (shouldCapturePreview) {
|
||||
shouldCapturePreview = false
|
||||
capturePreviewFrameInternal(
|
||||
@@ -1421,12 +1441,41 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
val compositeFs = GlUtils.compileShader(GLES30.GL_FRAGMENT_SHADER, Shaders.HDF_PREVIEW_COMPOSITE)
|
||||
hdfCompositeProgram = GlUtils.linkProgram(simpleVs, compositeFs)
|
||||
GLES30.glDeleteShader(compositeFs)
|
||||
val halationExtractHFs = GlUtils.compileShader(GLES30.GL_FRAGMENT_SHADER, Shaders.HALATION_PREVIEW_EXTRACT_BLUR_H)
|
||||
val halationBlurVFs = GlUtils.compileShader(GLES30.GL_FRAGMENT_SHADER, Shaders.HALATION_PREVIEW_BLUR_V)
|
||||
halationExtractBlurHProgram = GlUtils.linkProgram(simpleVs, halationExtractHFs)
|
||||
halationBlurVProgram = GlUtils.linkProgram(simpleVs, halationBlurVFs)
|
||||
GLES30.glDeleteShader(halationExtractHFs)
|
||||
GLES30.glDeleteShader(halationBlurVFs)
|
||||
GLES30.glDeleteShader(simpleVs)
|
||||
if (hdfExtractBlurHProgram == 0 || hdfBlurVProgram == 0 || hdfCompositeProgram == 0) {
|
||||
|
||||
if (hdfExtractBlurHProgram == 0 || hdfBlurVProgram == 0 || hdfCompositeProgram == 0 || halationExtractBlurHProgram == 0 || halationBlurVProgram == 0) {
|
||||
PLog.e(TAG, "Failed to link HDF preview programs")
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupHalationFbos(width: Int, height: Int) {
|
||||
val dsW = width / 4; val dsH = height / 4
|
||||
if (halationWidth == dsW && halationHeight == dsH && halationTexId[0] != 0) return
|
||||
halationWidth = dsW; halationHeight = dsH
|
||||
for (i in 0..1) {
|
||||
if (halationTexId[i] != 0) GLES30.glDeleteTextures(1, intArrayOf(halationTexId[i]), 0)
|
||||
if (halationFboId[i] != 0) GLES30.glDeleteFramebuffers(1, intArrayOf(halationFboId[i]), 0)
|
||||
val t = IntArray(1); val f = IntArray(1)
|
||||
GLES30.glGenTextures(1, t, 0); GLES30.glGenFramebuffers(1, f, 0)
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, t[0])
|
||||
GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_RGBA8, dsW, dsH, 0, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, null)
|
||||
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR)
|
||||
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR)
|
||||
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE)
|
||||
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE)
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, f[0])
|
||||
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, t[0], 0)
|
||||
halationTexId[i] = t[0]; halationFboId[i] = f[0]
|
||||
}
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0)
|
||||
}
|
||||
|
||||
private fun setupHdfFbos(width: Int, height: Int) {
|
||||
val dsW = width / 4
|
||||
val dsH = height / 4
|
||||
@@ -1500,7 +1549,36 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0)
|
||||
}
|
||||
|
||||
private fun drawHdfComposite(targetFboId: Int, width: Int, height: Int, sourceTextureId: Int) {
|
||||
private fun renderHalationPreviewBlur(sourceTexId: Int, width: Int, height: Int) {
|
||||
setupHalationFbos(width, height)
|
||||
if (halationExtractBlurHProgram == 0 || halationBlurVProgram == 0) return
|
||||
val dsW = width / 4; val dsH = height / 4
|
||||
val texelW = 1.0f / dsW; val texelH = 1.0f / dsH
|
||||
val threshold = 0.75f // 恒定高光提取阈值
|
||||
|
||||
GLES30.glUseProgram(halationExtractBlurHProgram)
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, halationFboId[0])
|
||||
GLES30.glViewport(0, 0, dsW, dsH)
|
||||
GLES30.glActiveTexture(GLES30.GL_TEXTURE0)
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, sourceTexId)
|
||||
GLES30.glUniform1i(GLES30.glGetUniformLocation(halationExtractBlurHProgram, "uInputTexture"), 0)
|
||||
GLES30.glUniform2f(GLES30.glGetUniformLocation(halationExtractBlurHProgram, "uTexelSize"), texelW, texelH)
|
||||
GLES30.glUniform1f(GLES30.glGetUniformLocation(halationExtractBlurHProgram, "uThreshold"), threshold)
|
||||
GLES30.glUniform1f(GLES30.glGetUniformLocation(halationExtractBlurHProgram, "uStrength"), redHalation)
|
||||
drawSimpleQuad(halationExtractBlurHProgram)
|
||||
|
||||
GLES30.glUseProgram(halationBlurVProgram)
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, halationFboId[1])
|
||||
GLES30.glViewport(0, 0, dsW, dsH)
|
||||
GLES30.glActiveTexture(GLES30.GL_TEXTURE0)
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, halationTexId[0])
|
||||
GLES30.glUniform1i(GLES30.glGetUniformLocation(halationBlurVProgram, "uInputTexture"), 0)
|
||||
GLES30.glUniform2f(GLES30.glGetUniformLocation(halationBlurVProgram, "uTexelSize"), texelW, texelH)
|
||||
drawSimpleQuad(halationBlurVProgram)
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0)
|
||||
}
|
||||
|
||||
private fun drawPostProcessComposite(targetFboId: Int, width: Int, height: Int, sourceTextureId: Int) {
|
||||
if (hdfCompositeProgram == 0) return
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, targetFboId)
|
||||
GLES30.glViewport(0, 0, width, height)
|
||||
@@ -1513,6 +1591,11 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, hdfTexId[1])
|
||||
GLES30.glUniform1i(GLES30.glGetUniformLocation(hdfCompositeProgram, "uBloomTexture"), 1)
|
||||
GLES30.glUniform1f(GLES30.glGetUniformLocation(hdfCompositeProgram, "uHalation"), halation)
|
||||
|
||||
GLES30.glActiveTexture(GLES30.GL_TEXTURE2)
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, if (redHalation > 0f) halationTexId[1] else 0)
|
||||
GLES30.glUniform1i(GLES30.glGetUniformLocation(hdfCompositeProgram, "uRedHalationTexture"), 2)
|
||||
GLES30.glUniform1f(GLES30.glGetUniformLocation(hdfCompositeProgram, "uRedHalation"), redHalation)
|
||||
drawSimpleQuad(hdfCompositeProgram)
|
||||
}
|
||||
|
||||
@@ -2069,7 +2152,7 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
|
||||
if (sourceTextureId != null && sourceTextureId != 0) {
|
||||
if (compositeWithHdf) {
|
||||
drawHdfComposite(captureFboId, captureWidth, captureHeight, sourceTextureId)
|
||||
drawPostProcessComposite(captureFboId, captureWidth, captureHeight, sourceTextureId)
|
||||
} else {
|
||||
drawFboToScreen(
|
||||
fboId = captureFboId,
|
||||
@@ -2151,7 +2234,7 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
|
||||
if (sourceTextureId != null && sourceTextureId != 0) {
|
||||
if (compositeWithHdf) {
|
||||
drawHdfComposite(meteringFboId, METERING_SIZE, METERING_SIZE, sourceTextureId)
|
||||
drawPostProcessComposite(meteringFboId, METERING_SIZE, METERING_SIZE, sourceTextureId)
|
||||
} else {
|
||||
drawFboToScreen(
|
||||
fboId = meteringFboId,
|
||||
@@ -2662,6 +2745,7 @@ class LutRenderer : GLSurfaceView.Renderer {
|
||||
bleachBypass = params.bleachBypass
|
||||
chromaticAberration = params.chromaticAberration
|
||||
halation = params.halation
|
||||
redHalation = params.redHalation
|
||||
noise = params.noise
|
||||
lowRes = params.lowRes
|
||||
primaryRedHue = params.primaryRedHue
|
||||
|
||||
@@ -156,20 +156,67 @@ object Shaders {
|
||||
uniform sampler2D uOriginalTexture;
|
||||
uniform sampler2D uBloomTexture;
|
||||
uniform float uHalation;
|
||||
uniform sampler2D uRedHalationTexture;
|
||||
uniform float uRedHalation;
|
||||
|
||||
void main() {
|
||||
vec4 color = texture(uOriginalTexture, vTexCoord);
|
||||
vec3 bloom = texture(uBloomTexture, vTexCoord).rgb;
|
||||
float bLuma = dot(bloom, vec3(0.2126, 0.7152, 0.0722));
|
||||
bloom = mix(vec3(bLuma), bloom, 1.6);
|
||||
vec3 bloomEffect = bloom * uHalation * 1.4;
|
||||
color.rgb = vec3(1.0) - (vec3(1.0) - color.rgb) * (vec3(1.0) - bloomEffect);
|
||||
float mist = bLuma * uHalation * 0.15;
|
||||
color.rgb += mist;
|
||||
color.rgb = (color.rgb - 0.5) * (1.0 - uHalation * 0.08) + 0.5;
|
||||
|
||||
if (uHalation > 0.0) {
|
||||
vec3 bloom = texture(uBloomTexture, vTexCoord).rgb;
|
||||
float bLuma = dot(bloom, vec3(0.2126, 0.7152, 0.0722));
|
||||
bloom = mix(vec3(bLuma), bloom, 1.6);
|
||||
vec3 bloomEffect = bloom * uHalation * 1.4;
|
||||
color.rgb = vec3(1.0) - (vec3(1.0) - color.rgb) * (vec3(1.0) - bloomEffect);
|
||||
float mist = bLuma * uHalation * 0.15;
|
||||
color.rgb += mist;
|
||||
color.rgb = (color.rgb - 0.5) * (1.0 - uHalation * 0.08) + 0.5;
|
||||
}
|
||||
|
||||
if (uRedHalation > 0.0) {
|
||||
vec3 redBloom = texture(uRedHalationTexture, vTexCoord).rgb;
|
||||
vec3 redBloomEffect = redBloom * uRedHalation * 3.5;
|
||||
color.rgb = vec3(1.0) - (vec3(1.0) - color.rgb) * (vec3(1.0) - redBloomEffect);
|
||||
}
|
||||
|
||||
fragColor = clamp(color, 0.0, 1.0);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
/** Halation Pass 1: 高光提取 + 暖红橙染色 + 水平高斯模糊 (实时预览) */
|
||||
val HALATION_PREVIEW_EXTRACT_BLUR_H = """
|
||||
#version 300 es
|
||||
precision highp float;
|
||||
in vec2 vTexCoord;
|
||||
out vec4 fragColor;
|
||||
uniform sampler2D uInputTexture;
|
||||
uniform vec2 uTexelSize;
|
||||
uniform float uThreshold;
|
||||
uniform float uStrength;
|
||||
void main() {
|
||||
vec3 tint = vec3(1.0, 0.15, 0.0);
|
||||
|
||||
// 提取高光函数
|
||||
#define EXTRACT(sampleColor) \
|
||||
(sampleColor * tint * smoothstep(uThreshold, uThreshold + 0.15, mix(dot(sampleColor, vec3(0.2126, 0.7152, 0.0722)), max(sampleColor.r, max(sampleColor.g, sampleColor.b)), 0.6)))
|
||||
|
||||
vec3 color = texture(uInputTexture, vTexCoord).rgb;
|
||||
vec3 sum = EXTRACT(color) * 0.204164;
|
||||
|
||||
float blurOffsets[4] = float[](1.407333, 3.294215, 5.176470, 7.058823);
|
||||
float blurWeights[4] = float[](0.304005, 0.093910, 0.010416, 0.000005);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
float off = blurOffsets[i] * uTexelSize.x * 2.0;
|
||||
sum += EXTRACT(texture(uInputTexture, vTexCoord + vec2(off, 0.0)).rgb) * blurWeights[i];
|
||||
sum += EXTRACT(texture(uInputTexture, vTexCoord - vec2(off, 0.0)).rgb) * blurWeights[i];
|
||||
}
|
||||
fragColor = vec4(sum, 1.0);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
/** Halation Pass 2: 垂直高斯模糊 */
|
||||
val HALATION_PREVIEW_BLUR_V = HDF_PREVIEW_BLUR_V
|
||||
|
||||
/**
|
||||
* Focus Peaking Shader
|
||||
*/
|
||||
|
||||
@@ -29,7 +29,8 @@ data class ColorRecipeParams(
|
||||
val filmGrain: Float = 0f, // 0.0 ~ 1.0 (颗粒强度,0为无颗粒)
|
||||
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 halation: Float = 0f, // 0.0 ~ 1.0 (高光扩散强度,0为无效果,模拟 GR3 HDF)
|
||||
val redHalation: Float = 0f, // 0.0 ~ 1.0 (胶片暖红色边缘光晕强度,0为无效果)
|
||||
val chromaticAberration: Float = 0f, // 0.0 ~ 1.0 (色散/边缘溢色强度,0为无效果)
|
||||
val noise: Float = 0f, // 0.0 ~ 1.0 (噪点强度,包含亮度和色彩噪点,0为无效果)
|
||||
val lowRes: Float = 0f, // 0.0 ~ 1.0 (低像素强度,0为无效果)
|
||||
@@ -100,6 +101,7 @@ data class ColorRecipeParams(
|
||||
vignette == 0f &&
|
||||
bleachBypass == 0f &&
|
||||
halation == 0f &&
|
||||
redHalation == 0f &&
|
||||
chromaticAberration == 0f &&
|
||||
noise == 0f &&
|
||||
lowRes == 0f &&
|
||||
@@ -169,6 +171,7 @@ data class ColorRecipeParams(
|
||||
vignette == other.vignette &&
|
||||
bleachBypass == other.bleachBypass &&
|
||||
halation == other.halation &&
|
||||
redHalation == other.redHalation &&
|
||||
chromaticAberration == other.chromaticAberration &&
|
||||
noise == other.noise &&
|
||||
lowRes == other.lowRes &&
|
||||
@@ -261,6 +264,7 @@ enum class RecipeParam(
|
||||
FILM_GRAIN(R.string.recipe_param_film_grain, 0.0f, 1.0f, 0f),
|
||||
VIGNETTE(R.string.recipe_param_vignette, -1.0f, 1.0f, 0f),
|
||||
BLEACH_BYPASS(R.string.recipe_param_bleach_bypass, 0.0f, 1.0f, 0f),
|
||||
HDF(R.string.recipe_param_hdf, 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),
|
||||
NOISE(R.string.recipe_param_noise, 0.0f, 1.0f, 0f),
|
||||
@@ -327,7 +331,8 @@ enum class RecipeParam(
|
||||
FILM_GRAIN -> params.filmGrain
|
||||
VIGNETTE -> params.vignette
|
||||
BLEACH_BYPASS -> params.bleachBypass
|
||||
HALATION -> params.halation
|
||||
HDF -> params.halation
|
||||
HALATION -> params.redHalation
|
||||
CHROMATIC_ABERRATION -> params.chromaticAberration
|
||||
NOISE -> params.noise
|
||||
LOW_RES -> params.lowRes
|
||||
@@ -389,7 +394,8 @@ enum class RecipeParam(
|
||||
FILM_GRAIN -> params.copy(filmGrain = clampedValue)
|
||||
VIGNETTE -> params.copy(vignette = clampedValue)
|
||||
BLEACH_BYPASS -> params.copy(bleachBypass = clampedValue)
|
||||
HALATION -> params.copy(halation = clampedValue)
|
||||
HDF -> params.copy(halation = clampedValue)
|
||||
HALATION -> params.copy(redHalation = clampedValue)
|
||||
CHROMATIC_ABERRATION -> params.copy(chromaticAberration = clampedValue)
|
||||
NOISE -> params.copy(noise = clampedValue)
|
||||
LOW_RES -> params.copy(lowRes = clampedValue)
|
||||
|
||||
@@ -89,6 +89,7 @@ fun ColorRecipePanel(
|
||||
RecipeParam.BLEACH_BYPASS,
|
||||
),
|
||||
listOf( // 7 lens
|
||||
RecipeParam.HDF,
|
||||
RecipeParam.HALATION,
|
||||
RecipeParam.CHROMATIC_ABERRATION,
|
||||
RecipeParam.NOISE,
|
||||
@@ -618,6 +619,7 @@ private fun formatParamValue(param: RecipeParam, value: Float): String {
|
||||
RecipeParam.NOISE,
|
||||
RecipeParam.LOW_RES,
|
||||
RecipeParam.BLEACH_BYPASS,
|
||||
RecipeParam.HDF,
|
||||
RecipeParam.HALATION,
|
||||
RecipeParam.CHROMATIC_ABERRATION -> String.format("%.2f", value)
|
||||
|
||||
@@ -679,7 +681,8 @@ private fun getParamColor(param: RecipeParam): Color {
|
||||
RecipeParam.NOISE -> Color(0xFFA1887F) // 浅棕色
|
||||
RecipeParam.VIGNETTE -> Color(0xFF795548) // 棕色
|
||||
RecipeParam.BLEACH_BYPASS -> Color(0xFF00BCD4) // 青色
|
||||
RecipeParam.HALATION -> Color(0xFFFF7043) // 暖橙色(光晕)
|
||||
RecipeParam.HDF -> Color(0xFFFFC107) // 暖黄色(高光扩散)
|
||||
RecipeParam.HALATION -> Color(0xFFFF7043) // 暖橙色(胶片光晕)
|
||||
RecipeParam.CHROMATIC_ABERRATION -> Color(0xFFAB47BC) // 紫色(色散)
|
||||
RecipeParam.LOW_RES -> Color(0xFF8D6E63) // 棕灰色(低像素)
|
||||
RecipeParam.LUT_INTENSITY -> Color(0xFF9E9E9E) // 灰色
|
||||
|
||||
@@ -315,7 +315,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">HDF</string>
|
||||
<string name="recipe_param_hdf">HDF</string>
|
||||
<string name="recipe_param_halation">光晕</string>
|
||||
<string name="recipe_param_chromatic_aberration">色散(CA)</string>
|
||||
<string name="recipe_param_noise">噪点</string>
|
||||
<string name="recipe_param_low_res">低像素</string>
|
||||
|
||||
@@ -246,7 +246,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">HDF</string>
|
||||
<string name="recipe_param_hdf">HDF</string>
|
||||
<string name="recipe_param_halation">光暈</string>
|
||||
<string name="recipe_param_chromatic_aberration">色散(CA)</string>
|
||||
<string name="recipe_param_noise">雜點</string>
|
||||
<string name="recipe_param_low_res">低像素</string>
|
||||
|
||||
@@ -320,7 +320,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">HDF</string>
|
||||
<string name="recipe_param_hdf">HDF</string>
|
||||
<string name="recipe_param_halation">Halation</string>
|
||||
<string name="recipe_param_chromatic_aberration">CA</string>
|
||||
<string name="recipe_param_noise">Noise</string>
|
||||
<string name="recipe_param_low_res">Pixelate</string>
|
||||
|
||||
Reference in new issue
Block a user