Add 2D focus positioning, fix rotation tracking, sync preview with effect

2D positioning:
- Add positionX parameter to BlurParameters (was only Y before)
- Update shader with uPositionX and uPositionY uniforms
- Single-finger drag now moves focus center anywhere on screen
- Update gradient mask generation for capture

Rotation tracking:
- Remove dampening from rotation gesture (1:1 tracking)
- Rotate gesture now directly tracks finger movement
- Preview effect rotates in sync with overlay

Overlay and shader sync:
- Both now use same positionX, positionY, angle parameters
- Preview blur effect matches overlay visualization

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Ole-Morten Duesund 2026-01-28 15:55:17 +01:00
commit e53155e8ee
5 changed files with 53 additions and 41 deletions

View file

@ -4,13 +4,15 @@ package no.naiv.tiltshift.effect
* Parameters controlling the tilt-shift blur effect.
*
* @param angle The rotation angle of the blur gradient in radians (0 = horizontal blur bands)
* @param position The center position of the in-focus region (0.0 to 1.0, relative to screen)
* @param positionX The horizontal center of the in-focus region (0.0 to 1.0)
* @param positionY The vertical center of the in-focus region (0.0 to 1.0)
* @param size The size of the in-focus region (0.0 to 1.0, as fraction of screen height)
* @param blurAmount The intensity of the blur effect (0.0 to 1.0)
*/
data class BlurParameters(
val angle: Float = 0f,
val position: Float = 0.5f,
val positionX: Float = 0.5f,
val positionY: Float = 0.5f,
val size: Float = 0.3f,
val blurAmount: Float = 0.8f
) {
@ -25,17 +27,20 @@ data class BlurParameters(
}
/**
* Returns a copy with the angle adjusted by the given delta.
* Returns a copy with the angle set to the given value.
*/
fun withAngleDelta(delta: Float): BlurParameters {
return copy(angle = angle + delta)
fun withAngle(newAngle: Float): BlurParameters {
return copy(angle = newAngle)
}
/**
* Returns a copy with the position clamped to valid range.
*/
fun withPosition(newPosition: Float): BlurParameters {
return copy(position = newPosition.coerceIn(0f, 1f))
fun withPosition(newX: Float, newY: Float): BlurParameters {
return copy(
positionX = newX.coerceIn(0f, 1f),
positionY = newY.coerceIn(0f, 1f)
)
}
/**

View file

@ -24,7 +24,8 @@ class TiltShiftShader(private val context: Context) {
// Uniform locations
private var uTextureLocation: Int = 0
private var uAngleLocation: Int = 0
private var uPositionLocation: Int = 0
private var uPositionXLocation: Int = 0
private var uPositionYLocation: Int = 0
private var uSizeLocation: Int = 0
private var uBlurAmountLocation: Int = 0
private var uResolutionLocation: Int = 0
@ -61,7 +62,8 @@ class TiltShiftShader(private val context: Context) {
// Get uniform locations
uTextureLocation = GLES20.glGetUniformLocation(programId, "uTexture")
uAngleLocation = GLES20.glGetUniformLocation(programId, "uAngle")
uPositionLocation = GLES20.glGetUniformLocation(programId, "uPosition")
uPositionXLocation = GLES20.glGetUniformLocation(programId, "uPositionX")
uPositionYLocation = GLES20.glGetUniformLocation(programId, "uPositionY")
uSizeLocation = GLES20.glGetUniformLocation(programId, "uSize")
uBlurAmountLocation = GLES20.glGetUniformLocation(programId, "uBlurAmount")
uResolutionLocation = GLES20.glGetUniformLocation(programId, "uResolution")
@ -84,7 +86,8 @@ class TiltShiftShader(private val context: Context) {
// Set effect parameters
GLES20.glUniform1f(uAngleLocation, params.angle)
GLES20.glUniform1f(uPositionLocation, params.position)
GLES20.glUniform1f(uPositionXLocation, params.positionX)
GLES20.glUniform1f(uPositionYLocation, params.positionY)
GLES20.glUniform1f(uSizeLocation, params.size)
GLES20.glUniform1f(uBlurAmountLocation, params.blurAmount)
GLES20.glUniform2f(uResolutionLocation, width.toFloat(), height.toFloat())