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);
}
| 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 |
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).
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. |
| 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; |
| 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; |
| /* | |
| @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/ |
| // 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 | |