Code Snippets GLSL

Short texts GLSL 🧑‍💻 Code snippets GLSL ✍️ Reading lists GLSL 👀

GLSL_light_sample.frag

void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // Time varying pixel color vec3 lightColor = vec3( clamp(mod(float(iFrame + 50), 100.0) / 100.0, 0.0, 1.0), clamp(mod(float(iFrame + 100), 100.0) / 100.0, 0.0, 1.0), clamp(mod(float(iFrame), 100.0) / 100.0, 0.0, 1.0) ); vec3 pixelColor = vec3(0.0, 1.0, 1.0); vec2 toLight = vec2(iMouse.x – fragCoord.x, iMouse.y […]

A Fragment Shader with various tone mapping algorithms

#version 330 core #extension GL_ARB_shading_language_include : require out vec4 color; uniform sampler2D renderTex; uniform vec2 resolution; uniform int toneMapMode; //////////////////////////////////////////////////////////////////////////////// // Narkowicz 2015, “ACES Filmic Tone Mapping Curve” vec3 aces(vec3 x) { const float a = 2.51; const float b = 0.03; const float c = 2.43; const float d = 0.59; const float e […]

Color Range Swap

//Select a color by changing min and max, and swap it out_hsv shader_type canvas_item; uniform float _min; uniform float _max; uniform vec3 out_hsv; vec3 rgb2hsv(vec3 c) { vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, […]

fragment.fs

in vec3 Normal; in vec3 FragmentPos; uniform vec3 viewPos; uniform struct Fog { vec2 range; vec4 color; } fog; uniform struct PointLight { vec3 position; // attenuation float constant; float linear; float quadratic; vec3 ambient; vec3 diffuse; vec3 specular; } light; vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) { vec3 norm = normalize(Normal); vec3 lightDir […]

photo_texture_pattern.frag

#ifdef GL_ES precision highp float; #endif #define PI 3.141592653589793 #define PI2 6.28318530718 uniform vec2 u_resolution; uniform vec2 u_mouse; uniform float u_time; uniform sampler2D u_tex0;// ./chongo.jpg float plot(vec2 st, float pct){ return smoothstep( pct-0.02, pct, st.y) – smoothstep( pct, pct+0.02, st.y); } vec2 rotate2D(vec2 _st,float _angle){ //_st-=.5; _st=mat2(cos(_angle),-sin(_angle), sin(_angle),cos(_angle))*_st; //_st+=.5; return _st; } void main() { […]