Skip to content

Instantly share code, notes, and snippets.

View shadercoder's full-sized avatar

PeterLiou shadercoder

  • IGG
  • earth
View GitHub Profile
Shader "Custom/Skin Shader" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Diffuse (RGB)", 2D) = "white" {}
_SpecularTex ("Specular (R) Gloss (G) SSS Mask (B)", 2D) = "yellow" {}
_BumpMap ("Normal (Normal)", 2D) = "bump" {}
// BRDF Lookup texture, light direction on x and curvature on y.
_BRDFTex ("BRDF Lookup (RGB)", 2D) = "gray" {}
// Curvature scale. Multiplier for the curvature - best to keep this very low - between 0.02 and 0.002.
_CurvatureScale ("Curvature Scale", Float) = 0.005
@shadercoder
shadercoder / GLSL-Noise.md
Last active December 31, 2015 06:01 — forked from patriciogonzalezvivo/GLSL-Noise.md
GLSL Noise Algorithms

Generic 1,2,3 Noise

float rand(float n){return fract(sin(n) * 43758.5453123);}

float noise(float p){
	float fl = floor(p);
  float fc = fract(p);
	return mix(rand(fl), rand(fl + 1.0), fc);
}
@shadercoder
shadercoder / custom_brdf.md
Created October 5, 2015 08:20 — forked from aras-p/custom_brdf.md
Custom BRDFs in deferred shading/lighting in Unity

So, https://twitter.com/sunjammer/status/569925239989256192 and https://twitter.com/sunjammer/status/569983534368206848

Now, depends on whether you want custom BRDF in deferred on 1) all your objects (easy) or 2) only some of your objects (harder).

1. change BRDF for everything

That's fairly easy. The actual object shaders more or less just fill the g-buffer (and in Unity 4.x deferred lighting, combine textures with the lighting buffer in the final pass). The actual BRDF is in the "light shader". Start by copying the built-in light shader (4.x deferred lighting: Internal-PrePassLighting.shader; 5.0 deferred shading: Internal-DeferredShading.shader) into your project. In 4.x, put it into Resources folder so it's included into the build; in 5.0 point Unity to use that shader under Project Settings -> Graphics.

Change the shader to do different BRDF.

/*
optimized-ggx.glsl
This file describes several optimizations you can make when creating a GGX shader.
AUTHOR: John Hable
LICENSE:
This is free and unencumbered software released into the public domain.
@shadercoder
shadercoder / pbd_deferred_ycog
Created November 11, 2015 05:45 — forked from Kuranes/pbd_deferred_ycog
glsl pbr encode in ycog gbuffer for deffered
vec4 encodeGBuffer(const in gBufferComponents components, const in vec2 texCoords, const in vec2 resolution, const in float clipFar) {
vec4 res;
vec3 diffuseYcocg = rgbToYcocg(components.diffuse);
vec2 diffuseYc = getCheckerboard(texCoords, resolution) > 0.0 ? diffuseYcocg.xy : diffuseYcocg.xz;
diffuseYc.y += 0.5;
//Divide by clip far * 2.0 to sneak distance into a 0 to 1 range
float depth = components.depth / (clipFar*2.0);
//Scale normal from -1 to 1 to 0 to 1 range
vec3 normal = components.normal * 0.5 + 0.5;
@shadercoder
shadercoder / Perlin_Tiled.cs
Created November 29, 2015 08:05 — forked from Flafla2/Perlin_Tiled.cs
A slightly modified implementation of Ken Perlin's improved noise that allows for tiling the noise arbitrarily.
public class Perlin {
public int repeat;
public Perlin(int repeat = -1) {
this.repeat = repeat;
}
public double OctavePerlin(double x, double y, double z, int octaves, double persistence) {
double total = 0;
@shadercoder
shadercoder / scattering.glsl
Created December 17, 2015 13:41 — forked from geofftnz/scattering.glsl
Rewritten atmospheric scattering shader
/*
@geofftnz
Just mucking around with some fake scattering.
Trying to come up with a nice-looking raymarched solution for atmospheric
scattering out to the edge of the atmosphere, plus a fast non-iterative version
for nearer the viewer.
Some code pinched from here: http://glsl.heroku.com/e#17563.3
and here: http://codeflow.org/entries/2011/apr/13/advanced-webgl-part-2-sky-rendering/
@shadercoder
shadercoder / springer-free-maths-books.md
Created December 29, 2015 09:39 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of books available for free, here are the direct links
@shadercoder
shadercoder / colorTempToRGB.js
Created January 3, 2016 11:13 — forked from paulkaplan/colorTempToRGB.js
Color Temperature to RGB
// From http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
// Start with a temperature, in Kelvin, somewhere between 1000 and 40000. (Other values may work,
// but I can't make any promises about the quality of the algorithm's estimates above 40000 K.)
function colorTemperatureToRGB(kelvin){
var temp = kelvin / 100;
Shader "Custom/QuaternionTest" {
Properties {
_AX("axis", Vector) = (0,0,0,0)
_TH("theta", Float) = 0
}
CGINCLUDE
#include "UnityCG.cginc"
#define PI 3.1416