Skip to content

Instantly share code, notes, and snippets.

@lhog
lhog / glsl_noise_rand
Last active Dec 3, 2021
Some GLSL Random and Noise functions
View glsl_noise_rand
const float M_PI = 3.1415926535897932384626433832795;
float rand(float p)
{
return fract(sin(p) * 43758.5453123);
}
/*
float rand(vec2 p)
{
return fract(sin(dot(p, vec2(12.9898, 4.1414))) * 43758.5453);
@lhog
lhog / g_shader_inst
Created May 13, 2018
Geometry Shader Instancing in Spring/ZK
View g_shader_inst
-- $Id: gui_metal_features.lua 3171 2008-11-06 09:06:29Z det $
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- file: gui_metal_features.lua
-- brief: highlights features with metal in metal-map viewmode
-- author: Dave Rodgers
--
-- Copyright (C) 2007.
-- Licensed under the terms of the GNU GPL, v2 or later.
View Sobel edge detection (GLSL)
//https://www.shadertoy.com/view/4scBDS
#define sum3(v) (v[0]+v[1]+v[2])
#define sqr(n) (n*n)
#define L(x, y) sqrt(sum3(sqr(vec3(texture(iChannel0, (U+vec2(x,y))/iResolution.xy).rgb)*vec3(.299, .587, .114))))
void mainImage( out vec4 O, in vec2 U ) {
vec3 a = vec3(-1, -2, -1), b = vec3(1, 2, 1);
float x = dot(vec3(L(-1,-1), L(-1,0), L(-1,1)), a)
+dot(vec3(L(1,-1), L(1,0), L(1,1)), b),
View glsl_noise_rand2
//https://www.shadertoy.com/view/4djSRW
// Hash without Sine
// Creative Commons Attribution-ShareAlike 4.0 International Public License
// Created by David Hoskins.
// *** Change these to suit your range of random numbers..
#if 1
// *** Use this for integer stepped ranges, ie Value-Noise/Perlin noise functions.
#define HASHSCALE1 .1031
View lava_gadget2.0
function gadget:GetInfo()
return {
name = "Lava Gadget 2.3",
desc = "lava",
author = "knorke, Beherith, The_Yak, Anarchid, Kloot, Gajop, ivand",
date = "Feb 2011, Nov 2013",
license = "GNU GPL, v2 or later",
layer = -3,
enabled = true
}
View LOD-Octaves.lua
--Inputs
LEVELS = 20
x= 0.15
--Vars
rest = 1.0
sum = 0
array = {}
table.insert(array, 0.0)
@lhog
lhog / SpherePoints_GoldenAngle
Created Feb 10, 2019
SpherePoints_GoldenAngle
View SpherePoints_GoldenAngle
vec3 SpherePoints_GoldenAngle(float i, float numSamples) {
const float goldenAngle = PI * (3.0 - sqrt(5.0));
float theta = i * goldenAngle;
float z = (1.0 - 1.0/numSamples) * (1.0 - 2.0 * i / (numSamples - 1.0));
float radius = sqrt(1.0 - z * z);
return vec3(radius * cos(theta), radius * sin(theta), z);
}
View GLSL Some Std. Matrixes
//https://www.shadertoy.com/view/MslyRr
///////////////////////////////////////////////////////////////////////////////
mat4 RotationMatrix(vec3 axis, float angle)
{
axis = normalize(axis);
float s = sin(angle);
float c = cos(angle);
float oc = 1.0 - c;
return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
@lhog
lhog / formats.txt
Created Feb 27, 2019 — forked from Kos/formats.txt
OpenGL image formats along with their unsized variants and preferred formats for pixel transfer (Written by hand, needs verification) Pixel store for compressed textures not provided because there are glCompressedTexImage and family for them. EXT_texture_compression_s3tc formats not included.
View formats.txt
| Image format (sized) | Unsized | Compr | Pixel format | Pixel type |
|---------------------------------------|--------------------|-------|--------------------|-----------------------------------|
| GL_R8 | GL_RED | False | GL_RED | GL_UNSIGNED_BYTE |
| GL_R8_SNORM | GL_RED | False | GL_RED | GL_BYTE |
| GL_R16 | GL_RED | False | GL_RED | GL_UNSIGNED_SHORT |
| GL_R16_SNORM | GL_RED | False | GL_RED | GL_SHORT |
| GL_R32F | GL_RED | False | GL_RED | GL_FLOAT |
| GL_R8I | GL_RED | False | GL_RED_INTEGER | GL_INT |
View TF vs SSBO
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <memory>
#include <iostream>
#include <cassert>
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void processInput(GLFWwindow *window);