summaryrefslogtreecommitdiffstats
path: root/src/main/java/dev/figboot/cuberender/state/BlendMode.java
blob: 1c1acf453bec5c84b2294393e8b5a9e4bd0978c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package dev.figboot.cuberender.state;

import dev.figboot.cuberender.math.Vector4f;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Getter
public enum BlendMode {
    DISABLE((inOutColor, prev) -> inOutColor.w = 1),
    BLEND_OVER((inOutColor, prev) -> {
        float pAlphaFactor = prev.w * (1 - inOutColor.w);
        float aOut = inOutColor.w + pAlphaFactor;

        inOutColor.x = (inOutColor.x * inOutColor.w + prev.x * pAlphaFactor) / aOut;
        inOutColor.y = (inOutColor.y * inOutColor.w + prev.y * pAlphaFactor) / aOut;
        inOutColor.z = (inOutColor.z * inOutColor.w + prev.z * pAlphaFactor) / aOut;
        inOutColor.w = aOut;
    });

    private final BlendFunction function;

    public interface BlendFunction {
        void blend(Vector4f inOutColor, Vector4f prev);
    }
}