Skip to content

Instantly share code, notes, and snippets.

View RGB Color for materials
R G B
Silver 0.971519 0.959915 0.915324
Aluminium 0.913183 0.921494 0.924524
Gold 1 0.765557 0.336057
Copper 0.955008 0.637427 0.538163
Chromium 0.549585 0.556114 0.554256
Nickel 0.659777 0.608679 0.525649
Titanium 0.541931 0.496791 0.449419
Cobalt 0.662124 0.654864 0.633732
Platinum 0.672411 0.637331 0.585456
View PBR_envMap
#extension GL_EXT_shader_texture_lod : enable
uniform samplerCube uRadianceMap;
uniform samplerCube uIrradianceMap;
#define saturate(x) clamp(x, 0.0, 1.0)
#define PI 3.1415926535897932384626433832795
const float A = 0.15;
View XCode Delete line
<key>Delete Line</key>
<string>deleteToBeginningOfLine:, moveToEndOfLine:, deleteToBeginningOfLine:, deleteBackward:, moveDown:, moveToBeginningOfLine:</string>
@yiwenl
yiwenl / hsv2rgb
Last active Nov 5, 2021
GLSL Color Coversions
View hsv2rgb
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
@yiwenl
yiwenl / GLSL_Random
Created Mar 5, 2015
GLSL random function
View GLSL_Random
// From glfx.js : https://github.com/evanw/glfx.js
float random(vec3 scale, float seed) {
/* use the fragment position for a different seed per-pixel */
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
}
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
@yiwenl
yiwenl / GLSL_contrast
Last active May 17, 2021
Greyscale in glsl
View GLSL_contrast
float contrast(float mValue, float mScale, float mMidPoint) {
return clamp( (mValue - mMidPoint) * mScale + mMidPoint, 0.0, 1.0);
}
float contrast(float mValue, float mScale) {
return contrast(mValue, mScale, .5);
}
vec3 contrast(vec3 mValue, float mScale, float mMidPoint) {
return vec3( contrast(mValue.r, mScale, mMidPoint), contrast(mValue.g, mScale, mMidPoint), contrast(mValue.b, mScale, mMidPoint) );
@yiwenl
yiwenl / JsGetBezierPoints
Created Mar 2, 2015
Get Bezier line from points
View JsGetBezierPoints
MathUtils = MathUtils || {};
MathUtils.level = function(i) {
if(i==0) return 1;
else return i*MathUtils.level(i-1);
}
MathUtils.binCoefficient = function(n, i) {
return MathUtils.level(n) / ( MathUtils.level(i) * MathUtils.level(n-i) );
@yiwenl
yiwenl / JsPrototypeGetterSetter
Created Feb 28, 2015
Getter / Setter for Javascript function prototype
View JsPrototypeGetterSetter
p.__defineGetter__("test", function() {
return "testing testing";
});
p.__defineSetter__("test", function() {
// DO SOMETHING
});
@yiwenl
yiwenl / GLSL_getDepthColor
Created Feb 25, 2015
GLSL code for getting the colour of the depth
View GLSL_getDepthColor
//float n = 5.0;
//float f = 800.0;
float getDepth(float z, float n, float f) {
return (2.0 * n) / (f + n - z*(f-n));
}
@yiwenl
yiwenl / JsBlobSaveJson
Last active Apr 8, 2021
Javascript using Blob to save json file
View JsBlobSaveJson
var saveJson = function(obj) {
var str = JSON.stringify(obj);
var data = encode( str );
var blob = new Blob( [ data ], {
type: 'application/octet-stream'
});
var url = URL.createObjectURL( blob );
var link = document.createElement( 'a' );