This repository has been archived by the owner on Feb 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3671fa3
commit e7ab73d
Showing
9 changed files
with
142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// EffectMergerLumaLevelsPIX.metal | ||
// PixelKit Shaders | ||
// | ||
// Created by Hexagons on 2017-11-26. | ||
// Copyright © 2017 Hexagons. All rights reserved. | ||
// | ||
|
||
#include <metal_stdlib> | ||
using namespace metal; | ||
|
||
#import "random_header.metal" | ||
|
||
struct VertexOut{ | ||
float4 position [[position]]; | ||
float2 texCoord; | ||
}; | ||
|
||
struct Uniforms { | ||
float brightness; | ||
float darkness; | ||
float contrast; | ||
float gamma; | ||
float opacity; | ||
}; | ||
|
||
fragment float4 effectMergerLumaLevelsPIX(VertexOut out [[stage_in]], | ||
texture2d<float> inTexA [[ texture(0) ]], | ||
texture2d<float> inTexB [[ texture(1) ]], | ||
const device Uniforms& in [[ buffer(0) ]], | ||
sampler s [[ sampler(0) ]]) { | ||
|
||
float pi = 3.14159265359; | ||
int max_res = 16384 - 1; | ||
|
||
float u = out.texCoord[0]; | ||
float v = out.texCoord[1]; | ||
float2 uv = float2(u, v); | ||
|
||
float4 c = inTexA.sample(s, uv); | ||
|
||
float4 cb = inTexB.sample(s, uv); | ||
float lum = (cb.r + cb.g + cb.b) / 3; | ||
|
||
float opacity = (1.0 - (1.0 - in.opacity) * lum); | ||
float a = c.a * opacity; | ||
|
||
c *= 1 / (1.0 - in.darkness * lum); | ||
c -= 1.0 / (1.0 - in.darkness * lum) - 1; | ||
|
||
c *= 1.0 - (1.0 - in.brightness) * lum; | ||
|
||
c -= 0.5; | ||
c *= 1.0 + in.contrast * lum; | ||
c += 0.5; | ||
|
||
c = pow(c, 1 / max(0.001, 1.0 - (1.0 - in.gamma) * lum)); | ||
|
||
c *= opacity; | ||
|
||
return float4(c.r, c.g, c.b, a); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// LumaLevelsPIX.swift | ||
// PixelKit | ||
// | ||
// Created by Hexagons on 2018-08-09. | ||
// Open Source - MIT License | ||
// | ||
|
||
import CoreGraphics | ||
|
||
public class LumaLevelsPIX: PIXMergerEffect, PIXAuto { | ||
|
||
override open var shader: String { return "effectMergerLumaLevelsPIX" } | ||
|
||
// MARK: - Public Properties | ||
|
||
public var brightness: LiveFloat = 1.0 | ||
public var darkness: LiveFloat = 0.0 | ||
public var contrast: LiveFloat = 0.0 | ||
public var gamma: LiveFloat = 1.0 | ||
public var opacity: LiveFloat = 1.0 | ||
|
||
// MARK: - Property Helpers | ||
|
||
override public var liveValues: [LiveValue] { | ||
return [brightness, darkness, contrast, gamma, opacity] | ||
} | ||
|
||
} | ||
|
||
public extension PIXOut { | ||
|
||
func _lumaLevels(with pix: PIX & PIXOut, brightness: LiveFloat = 1.0, darkness: LiveFloat = 0.0, contrast: LiveFloat = 0.0, gamma: LiveFloat = 1.0, opacity: LiveFloat = 1.0) -> LumaLevelsPIX { | ||
let lumaLevelsPix = LumaLevelsPIX() | ||
lumaLevelsPix.name = ":lumaLevels:" | ||
lumaLevelsPix.inPixA = self as? PIX & PIXOut | ||
lumaLevelsPix.inPixB = pix | ||
lumaLevelsPix.brightness = brightness | ||
lumaLevelsPix.darkness = darkness | ||
lumaLevelsPix.contrast = contrast | ||
lumaLevelsPix.gamma = gamma | ||
lumaLevelsPix.opacity = opacity | ||
return lumaLevelsPix | ||
} | ||
|
||
func _vignetting(radius: LiveFloat = 0.5, inset: LiveFloat = 0.25, gamma: LiveFloat = 0.5) -> LumaLevelsPIX { | ||
let pix = self as! PIX & PIXOut | ||
let rectangle = RectanglePIX(res: pix.resolution ?? ._1024) | ||
rectangle.bgColor = .white | ||
rectangle.color = .black | ||
rectangle.name = "vignetting:rectangle" | ||
rectangle.size = LiveSize(w: (pix.resolution?.aspect ?? 1.0) - inset, h: 1.0 - inset) | ||
let lumaLevelsPix = LumaLevelsPIX() | ||
lumaLevelsPix.name = "vignetting:lumaLevels" | ||
lumaLevelsPix.inPixA = pix | ||
lumaLevelsPix.inPixB = rectangle._blur(radius) | ||
lumaLevelsPix.gamma = gamma | ||
return lumaLevelsPix | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters