Skip to content

Instantly share code, notes, and snippets.

@otanodesignco
otanodesignco / negate.glsl
Created August 8, 2023 06:14
Negate function to simulate unity negate node in glsl
float negate( float value )
{
return -1.0 * value;
}
@otanodesignco
otanodesignco / vertex.glsl
Created August 3, 2023 06:50
How to transform normals to world space for lighting
out vec3 vWorldSpaceNormal;
void main()
{
vec4 worldSpaceNormal = modelMatrix * vec4( normal, 0.0 );
vWorldSpaceNormal = normalize( worldSpaceNormal.xyz );
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
@otanodesignco
otanodesignco / vertex.glsl
Created August 2, 2023 07:23
glsl view position of the camera based on the model position in three.js
/* calculate view position of the camera */
out vec3 vViewDirection;
void main()
{
vec4 worldPosition = modelMatrix * vec4( position, 1.0 );
@otanodesignco
otanodesignco / vertex.glsl
Created August 2, 2023 07:20
calculate surface normals in three.js
/* calculate surface normals shader material three.js */
out vec3 vSurfaceNormal;
void main()
{
vSurfaceNormal = normalize( normalMatrix * normal );
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1. );
@otanodesignco
otanodesignco / fragment.glsl
Last active August 1, 2023 06:42
Calculate the screen space uv to map a texture over the mesh regardless of the mesh position or orientation
/* Fragment shader
//
// Screen space
//
*/
uniform vec2 uResolution; // screen width and height
void main()
{
out vec2 vWorldUv;
void main()
{
vec4 objectSpace = modelMatrix * vec4( position, 1.0 );
vWorldUv = vec2( objectSpace.x, objectSpace.z );
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
@otanodesignco
otanodesignco / .glsl
Created July 29, 2023 17:22
view direction
out vec3 vViewDirection; // varying to send to the fragment shader
void main()
{
vec4 viewDirection = modelViewMatrix * vec4( position, 1.0 );
vViewDirection = viewDirection.xyz; // set view direction per pixel
gl_Position = projectionMatrix * viewDirection;
@otanodesignco
otanodesignco / gulpfile.js
Created August 20, 2019 01:08
Gulp file for 8/19/2019 for browsersync, and scss compile
const {task, dest, src, watch, series} = require('gulp');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const browsersync = require('browser-sync').create();
sass.compiler = require('node-sass');
function style(cb)
{
return src('./assets/styles/sass/**/*.scss')
.pipe(sourcemaps.init())
@otanodesignco
otanodesignco / hook.php
Created April 14, 2019 02:00
php hook system
<?php
class hookSystem
{
/**
* @abstract Objects array
* @access Private
*/
private static $objects = array();
/**
* @abstract Settings array
<?php
$phpExt = '';
$phpLoadedExt = get_loaded_extensions();
foreach($phpLoadedExt as $ext)
{
$phpExt .= "${ext}<br />";
}
echo $phpExt;