Skip to content

Instantly share code, notes, and snippets.

View kunofellasleep's full-sized avatar

Kuno Fell Asleep kunofellasleep

View GitHub Profile
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TimeScaleController : MonoBehaviour {
[SerializeField] private float speedupScale = 100.0f;
[SerializeField] private float scale = 1.0f;
void Update () {
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UniRx;
/// <summary>
/// 指定のフォルダ(targetPath)に音声ファイルをいれて
/// SoundEffectManager.Instance.Play("filename"); で再生できる
/// </summary>
@kunofellasleep
kunofellasleep / LocalColor.shader
Last active March 14, 2018 04:49
LocalColor.shader
Shader "_kunofellasleep/LocalColor.shader" {
SubShader {
Tags { "RenderType"="Opaque" }
LOD 100
Pass {
CGPROGRAM
// Upgrade NOTE: excluded shader from DX11; has structs without semantics (struct v2f members localPos)
#pragma exclude_renderers d3d11
#pragma vertex vert
// ref :: http://t-pot.com/program/90_BitonicSort/index.html
#include <metal_stdlib>
using namespace metal;
kernel void bitonicSort(texture2d<float, access::read> inTexture [[texture(0)]],
texture2d<float, access::write> outTexture [[texture(1)]],
device float *stepno [[buffer(0)]],
device float *offset [[buffer(1)]],
googleimagesdownload -k keywordA -sk keywordB -f "jpg" -s medium
python retrain.py --image_dir ./images
python label_image.py --image test.jpg --graph output_graph.pb --labels output_labels.txt --input_layer=Placeholder
@kunofellasleep
kunofellasleep / shader.metal
Last active October 6, 2018 03:56
duotone-style shader
#include <metal_stdlib>
using namespace metal;
kernel void duotone(
texture2d<float, access::write> outTex [[texture(0)]],
texture2d<float, access::read> inTex [[texture(1)]],
uint2 gid [[thread_position_in_grid]])
{
float3 c = inTex.read(gid).rgb;
float mn = (c.r + c.g + c.b) / 3.0;
float4 out = float4(0.5, 0.5 + mn, 1.0, 1.0);
//ハードウェアとしてのGPUを抽象化したプロトコル
lazy var device: MTLDevice! = MTLCreateSystemDefaultDevice()
//コマンドバッファの実行順を管理するキュー
var commandQueue: MTLCommandQueue!
public func Setup() {
let defaultLibrary = device.makeDefaultLibrary()!
if let target = defaultLibrary.makeFunction(name: funcName) {
commandQueue = device.makeCommandQueue()
do {
func mtlTexture(from image: UIImage) -> MTLTexture {
//CGImage変換時に向きがおかしくならないように
UIGraphicsBeginImageContext(image.size);
image.draw(in: CGRect(x:0, y:0, width:image.size.width, height:image.size.height))
let orientationImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//CGImageに変換
guard let cgImage = orientationImage?.cgImage else {
fatalError("Can't open image \(image)")
}
public func Run(_ image:UIImage) -> UIImage{
//GPUで実行されるコマンドを格納するコンテナ
let buffer = commandQueue.makeCommandBuffer()
//コマンドを作成し、コマンドバッファに追加する(エンコード)
let encoder = buffer?.makeComputeCommandEncoder()
encoder?.setComputePipelineState(pipelineState)
//出力用テクスチャ作成
let textureDescriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: MTLPixelFormat.rgba8Unorm, width:1920, height: 1080, mipmapped: false)
textureDescriptor.usage = [.shaderRead, .shaderWrite]
outTexture = self.device.makeTexture(descriptor: textureDescriptor)