Skip to content

Instantly share code, notes, and snippets.

@sopvop
sopvop / pbr.glsl
Created July 22, 2018 18:31 — forked from galek/pbr.glsl
PBR GLSL SHADER
in vec2 v_texcoord; // texture coords
in vec3 v_normal; // normal
in vec3 v_binormal; // binormal (for TBN basis calc)
in vec3 v_pos; // pixel view space position
out vec4 color;
layout(std140) uniform Transforms
{
mat4x4 world_matrix; // object's world position
void revisedONB(const Vec3f &n, Vec3f &b1, Vec3f &b2)
{
if(n.z<0.){
const float a = 1.0f / (1.0f - n.z);
const float b = n.x * n.y * a;
b1 = Vec3f(1.0f - n.x * n.x * a, -b, n.x);
b2 = Vec3f(b, n.y*n.y*a - 1.0f, -n.y);
}
else {
const float a = 1.0f / (1.0f + n.z);
@sopvop
sopvop / unique.rs
Created June 18, 2018 15:57
unique global id at compile time
#[derive(PartialEq, PartialOrd, Debug, Clone, Copy)]
pub struct UniqueId(pub u64);
macro_rules! unique {
() => {{
#[allow(missing_copy_implementations)]
#[allow(non_camel_case_types)]
#[allow(dead_code)]
struct __unique_id_tag {};
use core::any::TypeId;
@sopvop
sopvop / Overlap.hs
Last active April 5, 2018 10:07
Works in servant-server, can't make my own instances
{-
src/Servant/API/RPC.hs:74:8-55: error: …
Conflicting family instance declarations:
ServerT (RPC e r) m = m (Either (OpenUnion e) r)
-- Defined at /home/lonokhov/work/stagex-store/stagex-api/src/Servant/API/RPC.hs:74:8
ServerT (RPC e (Headers h r)) m = m (Headers
h (Either (OpenUnion e) r))
-- Defined at /home/lonokhov/work/stagex-store/stagex-api/src/Servant/API/RPC.hs:81:8
-}
{-# LANGUAGE OverloadedStrings #-}
module Database.PostgreSQL.Simple.Dsl.Escape
( escapeByteA
, escapeByteAFast
, escapeByteAHex
, escapeString
, escapeIdentifier
, escapeAction
) where
@sopvop
sopvop / traverse_vis.py
Created May 19, 2014 13:28
traverse visible
from smmaya.core.api import as_api_dagpath
import maya.OpenMaya as om
import maya.OpenMayaUI as omu
def get_visible(camera, width=800, height=600):
if not isinstance(camera, om.MDagPath):
camera = as_api_dagpath(camera)
trav = omu.MDrawTraversal()
trav.setFrustum(camera, width, height)
trav.traverse()
@sopvop
sopvop / Utils.hs
Created December 7, 2012 11:01
Last modified and etag for snap
{-# LANGUAGE OverloadedStrings #-}
module SmAssetMan.Utils
(encodeHttpDate
,decodeHttpDate
,getIfModifiedSince
,getIfUnmodifiedSince
,getIfMatch
,getIfNoneMatch
,setETag
,setLastModified
@sopvop
sopvop / RouteBoomerang.hs
Created November 16, 2012 06:28
boomerang in snap without webroutes
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module Snap.Extras.RouteBoomerang
( showUrl
, showUrlMay
, showUrlWithParamsMay
, showUrlWithParams
, routeUrl