Skip to content

Instantly share code, notes, and snippets.

View vahan3x's full-sized avatar
💻
Available. Sometimes.

Vahan Babayan vahan3x

💻
Available. Sometimes.
View GitHub Profile
@vahan3x
vahan3x / Shaders.metal
Created October 1, 2018 17:41
Displaying image with normalized Display P3 colors. For use with Metal textures using bgra10_xr_srgb pixel format.
// Simple RGB to Linear RGB function respecting negative values
half channelToLinearChannel(half channel) {
if (fabs(channel) <= 0.04045) {
return channel / 12.92;
}
return sign(channel) * pow((fabs(channel) + 0.055) / 1.055, 2.4);
}
// Converting RGB to Linear RGB
@vahan3x
vahan3x / Comparable+Additions.swift
Last active March 24, 2018 14:03
Useful extensions for Cocoa Touch frameworks
// Swift version: 4.0
public extension Comparable {
/// Returns a copy of the value clamped to the given limiting range.
///
/// Example:
///
/// let a = 50
/// print(a.clamped(to: 0 ... 10)) // prints 10