Skip to content

Instantly share code, notes, and snippets.

@RoyLab
RoyLab / bump.hlsl
Created June 23, 2017 10:51
compute bump
//float3 T = normalize(i.uBase - dot(i.uBase, N)*N);
//float3 B = cross(N, T);
//float3x3 TBN = float3x3(T, B, N);
//float3 normal = mul(rawN, TBN);
//return fixed4((normalize(finalNormal * float3(1,1,1))), 1);
@RoyLab
RoyLab / instance.shader
Created June 23, 2017 03:49
instance rendering example
Shader "SpaceFramework/PlanetShaderInstance"
{
Properties
{
_MainTex("Color Texture", 2D) = "white" {}
}
CGINCLUDE
#include "SFCommon.cginc"
@RoyLab
RoyLab / sample.hlsl
Created June 23, 2017 03:36
sampling in compute shader
//output.height = lerp(lerp(a, b, localUV.x), lerp(c, d, localUV.x), localUV.y);
//output.height = _HeightMap.SampleLevel(MyPointRepeatSampler, uvSphere, 0).x;
//output.height = tex2Dlod(_HeightMap2, float4(uvSphere, 0, 0)).x;
float a = _HeightMap.Load(int3(coord.x, coord.y, 0)).x;
@RoyLab
RoyLab / FPSDisplay.cs
Created June 3, 2017 09:17
FPSDisplay
using UnityEngine;
using System.Collections;
public class FPSDisplay : MonoBehaviour
{
float deltaTime = 0.0f;
void Update()
{
deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
@RoyLab
RoyLab / groupsharedmem.hlsl
Last active June 1, 2017 03:46
groupshared memory
RWStructuredBuffer<float> g_data;
#define groupDim_x 128
groupshared float sdata[groupDim_x];
[numthreads(groupDim_x, 1, 1)]
void reduce1(uint3 threadIdx : SV_GroupThreadID,
uint3 groupIdx : SV_GroupID)
{
// each thread loads one element from global to shared mem
unsigned int tid = threadIdx.x;
unsigned int i = groupIdx.x * groupDim_x + threadIdx.x;
@RoyLab
RoyLab / grey2rgb.hlsl
Created May 19, 2017 17:04
greyscale to rgb
float interpolate(float val, float y0, float x0, float y1, float x1) {
return (val - x0)*(y1 - y0) / (x1 - x0) + y0;
}
float blue(float grayscale) {
if (grayscale < -0.33) return 1.0;
else if (grayscale < 0.33) return interpolate(grayscale, 1.0, -0.33, 0.0, 0.33);
else return 0.0;
}
float green(float grayscale) {
if (grayscale < -1.0) return 0.0; // unexpected grayscale value
@RoyLab
RoyLab / bokehsplatting.shader
Created April 14, 2017 07:51
my bokeh splatting shader
/*
DX11 Bokeh splatting
basic algorithm:
* find bright spots
* verify high frequency (otherwise dont care)
* if possitive, replace with black pixel and add to append buffer
* blend bokeh texture sprites via append buffer on top of blurred buffer
*/
@RoyLab
RoyLab / run compute shader.cs
Created April 14, 2017 04:00
run compute shader in unity
RenderTexture RunShader()
{
int kernelHandle = shader.FindKernel("CSMain");
RenderTexture tex = new RenderTexture(256, 256, 24);
tex.enableRandomWrite = true;
tex.Create();
shader.SetTexture(kernelHandle, "Result", tex);
shader.Dispatch(kernelHandle, 32, 32, 1);
ip 202.120.38.35
mask 255.255.255.0
gateway 202.120.38.254
DNS 202.120.1.101
202.120.1.100
MAC 000874:149325
@RoyLab
RoyLab / cholupdate.py
Last active September 27, 2016 09:28 — forked from mattjj/cholupdate.py
cholesky updates and downdates
from __future__ import division
import numpy as np
from numpy.random import randn
from scipy.linalg.blas import drot, drotg
# references for updates:
# - Golub and van Loan (4th ed.) Section 6.5.4
# - http://mathoverflow.net/questions/30162/is-there-a-way-to-simplify-block-cholesky-decomposition-if-you-already-have-deco
#
# references for downdates: