Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit afc65bf2 authored by Michel Comin Escude's avatar Michel Comin Escude
Browse files

Adjust fog to work on tablet and foldable

Bug: 332775703
Test: visual
Flag: EXEMPT MP apk not in build yet
Change-Id: I184f605f84f2baa07893f66c7f8164dd874df734
parent 9ba974d8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ vec4 main(float2 fragCoord) {

    /* Prepare fog layers. */
    // Dither to be applied to background noise.
    float bgdDither = triangleNoise((fragCoord + 0.0002 * timeBackground) * pixelDensity) * 0.1;
    float bgdDither = triangleNoise((fragCoord + 0.0002 * timeBackground) * pixelDensity) * 0.15;

    // The furthest fog layer in the background.
    vec4 bgdFogFar = fog.eval(
@@ -84,7 +84,7 @@ vec4 main(float2 fragCoord) {
        // Adds sampling dithering.
        vec2(bgdDither * 22));

    float fgdDither = triangleNoise((fragCoord + 0.003 * timeForeground) * pixelDensity) * 0.07;
    float fgdDither = triangleNoise((fragCoord + 0.003 * timeForeground) * pixelDensity) * 0.1;
    vec4 fgdFogFar = clouds.eval(
        0.5 * cloudsSize * uv +
        // Moves UV based on time.
+21 −13
Original line number Diff line number Diff line
@@ -43,10 +43,14 @@ class FogEffect(
        updateTextureUniforms()
        adjustCropping(surfaceSize)
        prepareColorGrading()
        updateFogGridSize(surfaceSize)
        setIntensity(fogConfig.intensity)
    }

    override fun resize(newSurfaceSize: SizeF) = adjustCropping(newSurfaceSize)
    override fun resize(newSurfaceSize: SizeF) {
        adjustCropping(newSurfaceSize)
        updateFogGridSize(newSurfaceSize)
    }

    override fun update(deltaMillis: Long, frameTimeNanos: Long) {
        val deltaTime = TimeUtils.millisToSeconds(deltaMillis)
@@ -152,23 +156,11 @@ class FogEffect(
            BitmapShader(fogConfig.cloudsTexture, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT)
        )

        fogConfig.shader.setFloatUniform(
            "cloudsSize",
            fogConfig.cloudsTexture.width.toFloat(),
            fogConfig.cloudsTexture.height.toFloat()
        )

        fogConfig.shader.setInputBuffer(
            "fog",
            BitmapShader(fogConfig.fogTexture, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT)
        )

        fogConfig.shader.setFloatUniform(
            "fogSize",
            fogConfig.fogTexture.width.toFloat(),
            fogConfig.fogTexture.height.toFloat()
        )

        fogConfig.shader.setFloatUniform("pixelDensity", fogConfig.pixelDensity)
    }

@@ -182,4 +174,20 @@ class FogEffect(
        }
        fogConfig.colorGradingShader.setFloatUniform("intensity", fogConfig.colorGradingIntensity)
    }

    private fun updateFogGridSize(surfaceSize: SizeF) {
        val widthScreenScale =
            GraphicsUtils.computeDefaultGridSize(surfaceSize, fogConfig.pixelDensity)
        fogConfig.shader.setFloatUniform(
            "cloudsSize",
            widthScreenScale * fogConfig.cloudsTexture.width.toFloat(),
            widthScreenScale * fogConfig.cloudsTexture.height.toFloat()
        )

        fogConfig.shader.setFloatUniform(
            "fogSize",
            widthScreenScale * fogConfig.fogTexture.width.toFloat(),
            widthScreenScale * fogConfig.fogTexture.height.toFloat()
        )
    }
}