Skip to content

Instantly share code, notes, and snippets.

@dnevera
dnevera / BilateralFilter
Created February 16, 2020 22:13 — forked from bkitduy/BilateralFilter
GPUImage- Bilateral Filter Android
package jp.co.cyberagent.android.gpuimage;
import android.opengl.GLES20;
/**
* A more generalized 9x9 Gaussian blur filter blurSize value ranging from 0.0
* on up, with a default of 1.0
*/
public class GPUImageBilateralFilter extends
GPUImageTwoPassTextureSamplingFilter {
//
// Created by denn nevera on 2019-06-24.
//
#pragma once
#include <cstdint>
#include <stdexcept>
#include <string>
@dnevera
dnevera / promise.cc
Created June 25, 2019 15:28
Promise implementation
//
// Created by denn nevera on 2019-06-24.
//
//
// source: https://github.com/LifeWanted/liblw/tree/master/source/lw/event
//
#pragma once
static inline float2 __slashReflect(float2 point) {
return (float2){-point.y, point.x};
}
class IMPMLSSolver{
public:
/**
///
/// Говорим делегату рендеренга, что на новом шаге изменяем позции узловых точек RGB-куба в сцене
/// Одновременно с этим на GPU шейдер деформирует координаты вершин нашего монолитного RGB-куба
///
func renderer(_ renderer: SCNSceneRenderer, willRenderScene scene: SCNScene, atTime time: TimeInterval) {
guard isChanged else { return }
for (i,rgb) in colors.enumerated() /*meshGrid.enumerated()*/ {
let p = meshGrid[i]
constexpr sampler lutSampler(address::clamp_to_edge, filter::linear, coord::normalized);
kernel void kernel_clutColorMapper(
texture3d<float, access::sample> clut [[texture(0)]],
device float3 *reference [[buffer(0)]],
device float3 *target [[buffer(1)]],
uint gid [[thread_position_in_grid]]
)
{
float3 rgb = reference[gid];
using namespace metal;
#include <SceneKit/scn_metal>
// Стандартные параметры модели (узла)
typedef struct {
float4x4 modelTransform;
float4x4 modelViewTransform;
float4x4 normalTransform;
float4x4 modelViewProjectionTransform;
} NodeBuffer;
/// Программируем рендеринг материала в GPU на Metal
let program:SCNProgram = {
let p = SCNProgram()
p.vertexFunctionName = "projectionVertex"
p.fragmentFunctionName = "materialFragment"
p.isOpaque = false;
return p
}()
/// Создаем материал который будем рендерить в шейдерах Metal
//
// LutView.swift
// ImageMetalling-15
//
// Created by denis svinarchuk on 24.05.2018.
// Copyright © 2018 Dehancer. All rights reserved.
//
import Cocoa
import IMProcessing
/// Создаем фильтр обзёрвера цветов текстуры
private lazy var patchColors:ColorObserver = {
let f = ColorObserver(context: self.context)
//
// Размер прямоугольной (квадратной) области по которой мы интерполируем
// (на самом деле усредняем) цвет текстуры
//
f.regionSize = 20
//