Skip to content

Instantly share code, notes, and snippets.

@ctrlcctrlv
Created January 2, 2020 13:31
Show Gist options
  • Save ctrlcctrlv/844af75a15627712b7f27289b6d61d23 to your computer and use it in GitHub Desktop.
Save ctrlcctrlv/844af75a15627712b7f27289b6d61d23 to your computer and use it in GitHub Desktop.
TT2020 Style O1 (For use with SHADERed)
#version 400
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
in vec4 coord;
out vec4 outColor;
uniform vec2 iResolution;
uniform sampler2D TTj;
// Perlin Noise 3D
// Return value range of -1.0->1.0
// Source: https://github.com/BrianSharpe/Wombat
// Derived from: https://github.com/BrianSharpe/GPU-Noise-Lib
float Perlin3D( vec3 P )
{
// establish our grid cell and unit position
vec3 Pi = floor(P);
vec3 Pf = P - Pi;
vec3 Pf_min1 = Pf - 1.0;
// clamp the domain
Pi.xyz = Pi.xyz - floor(Pi.xyz * ( 1.0 / 69.0 )) * 69.0;
vec3 Pi_inc1 = step( Pi, vec3( 69.0 - 1.5 ) ) * ( Pi + 1.0 );
// calculate the hash
vec4 Pt = vec4( Pi.xy, Pi_inc1.xy ) + vec2( 50.0, 161.0 ).xyxy;
Pt *= Pt;
Pt = Pt.xzxz * Pt.yyww;
const vec3 SOMELARGEFLOATS = vec3( 635.298681, 682.357502, 668.926525 );
const vec3 ZINC = vec3( 48.500388, 65.294118, 63.934599 );
vec3 lowz_mod = vec3( 1.0 / ( SOMELARGEFLOATS + Pi.zzz * ZINC ) );
vec3 highz_mod = vec3( 1.0 / ( SOMELARGEFLOATS + Pi_inc1.zzz * ZINC ) );
vec4 hashx0 = fract( Pt * lowz_mod.xxxx );
vec4 hashx1 = fract( Pt * highz_mod.xxxx );
vec4 hashy0 = fract( Pt * lowz_mod.yyyy );
vec4 hashy1 = fract( Pt * highz_mod.yyyy );
vec4 hashz0 = fract( Pt * lowz_mod.zzzz );
vec4 hashz1 = fract( Pt * highz_mod.zzzz );
// calculate the gradients
vec4 grad_x0 = hashx0 - 0.49999;
vec4 grad_y0 = hashy0 - 0.49999;
vec4 grad_z0 = hashz0 - 0.49999;
vec4 grad_x1 = hashx1 - 0.49999;
vec4 grad_y1 = hashy1 - 0.49999;
vec4 grad_z1 = hashz1 - 0.49999;
vec4 grad_results_0 = inversesqrt( grad_x0 * grad_x0 + grad_y0 * grad_y0 + grad_z0 * grad_z0 ) * ( vec2( Pf.x, Pf_min1.x ).xyxy * grad_x0 + vec2( Pf.y, Pf_min1.y ).xxyy * grad_y0 + Pf.zzzz * grad_z0 );
vec4 grad_results_1 = inversesqrt( grad_x1 * grad_x1 + grad_y1 * grad_y1 + grad_z1 * grad_z1 ) * ( vec2( Pf.x, Pf_min1.x ).xyxy * grad_x1 + vec2( Pf.y, Pf_min1.y ).xxyy * grad_y1 + Pf_min1.zzzz * grad_z1 );
// classic Perlin Interpolation
vec3 blend = Pf * Pf * Pf * (Pf * (Pf * 6 - 15.0) + 10.0);
vec4 res0 = mix( grad_results_0, grad_results_1, blend.z );
vec4 blend2 = vec4( blend.xy, vec2( 1.0 - blend.xy ) );
float final = dot( res0, blend2.zxzx * blend2.wwyy );
//return ( final * 1.1547005383792515290182975610039 ); // scale things to a strict -1.0->1.0 range *= 1.0/sqrt(0.
final = final+.20;
return ( final * 1.1547005383792515290182975610039 ); // scale things to a strict -1.0->1.0 range *= 1.0/sqrt(0.75)75)
}
float fmod(float value, float modulus) {
return value - modulus * floor(value/modulus);
}
/*
* Copyright (c) 2017 Øyvind Kolås <pippin@gimp.org>
*
* This is the GEGL version, not the website version, so its license is here:
* https://github.com/OpenCL/GEGL-OpenCL/commit/6609e9b8e1a5f8fd8d06de6109f45a8e43c4f6a3
*/
float spachrotyze (
float x,
float y,
float part_white,
float offset,
float hue,
int pattern,
float period,
float turbulence,
float blocksize,
float angleboost,
float twist)
{
int max_aa_samples = 16;
float acc = 0.0;
float angle = 3.1415 / 2- ((hue * angleboost) + twist);
float width = (period * (1.0 - turbulence) +
(period * offset) * turbulence);
float vec0 = cos (angle);
float vec1 = sin (angle);
float xi = 0.5;
float yi = 0.2;
int count = 0;
int in0 = 0;
float old_acc = 0.0;
x += period * 2;
y += period * 2;
for (int i = 0; i < max_aa_samples ; i++)
{
xi = mod (xi + 0.618033988749854, 1.0);
yi = mod (yi + (0.618033988749854/1.61235), 1.0);
old_acc = acc;
{
float u = mod (x + xi - 0.5 * width, blocksize * width);
float v = mod (y + yi - 0.5 * width, blocksize * width);
float w = vec0 * u + vec1 * v;
float q = vec1 * u - vec0 * v;
float wperiod = mod (w, width);
float wphase = (wperiod / width) * 2.0 - 1.0;
float qperiod = mod (q, width);
float qphase = (qperiod / width) * 2.0 - 1.0;
if (pattern == 0) /* line */
{
if (abs (wphase) < part_white)
in0 ++;
}
else if (pattern == 1) /* dot */
{
if (qphase * qphase + wphase * wphase <
part_white * part_white * 2.0)
in0 ++;
}
else if (pattern == 2) /* diamond */
{
if ((abs(wphase) + abs(qphase))/2.0 < part_white )
in0++;
}
else if (pattern == 3) /* dot-to-diamond-to-dot */
{
float ax = abs (wphase ) ;
float ay = abs (qphase ) ;
float v = 0.0;
if (ax + ay > 1.0)
{
ay = 1.0 - ay;
ax = 1.0 - ax;
v = 2.0 - sqrt (ay * ay + ax * ax);
}
else
{
v = sqrt (ay * ay + ax * ax);
}
v/=2.0;
if (v < part_white)
in0++;
}
else if (pattern == 4) /* cross */
{
float part_white2 = pow (part_white, 2.0);
if (abs (wphase) < part_white2 ||
abs (qphase) < part_white2)
in0++;
}
count ++;
acc = in0 * 1.0/ count;
if (i > 3 &&
abs (acc - old_acc) < 0.23)
break;
old_acc = acc;
}
}
return acc;
}
float degrees_to_radians (float degrees)
{
return degrees * (2 * 3.1415 / 360.0);
}
const int TEXTURE_SCALE = 700;
/* Below is from SHADERtoy, their license is:
* "if you don't place a license on a shader, it will be protected by our default license:"
* This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
* By https://www.shadertoy.com/user/mrharicot
*/
float normpdf(in float x, in float sigma)
{
return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;
}
void main( )
{
vec4 fragCoord = gl_FragCoord;
// fragCoord.x += 100000;
fragCoord[1]*=0.5;
vec3 c = texture(TTj, fragCoord.xy / TEXTURE_SCALE).rgb;
//declare stuff
const int mSize = 100;
const int kSize = (mSize-1)/2;
float kernel[mSize];
vec3 final_colour = vec3(0.0);
//create the 1-D kernel
float sigma = 7.0;
float Z = 0.0;
for (int j = 0; j <= kSize; ++j)
{
kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j), sigma);
}
//get the normalization factor (as the gaussian has been clamped)
for (int j = 0; j < mSize; ++j)
{
Z += kernel[j];
}
//read out the texels
for (int i=-kSize; i <= kSize; ++i)
{
for (int j=-kSize; j <= kSize; ++j)
{
final_colour += kernel[kSize+j]*kernel[kSize+i]*texture(TTj, (fragCoord.xy+vec2(float(i),float(j))) / TEXTURE_SCALE).rgb;
}
}
vec2 uvn = gl_FragCoord.xy/iResolution.xx;
vec4 fragColor = vec4(final_colour/(Z*Z), 1.0);
// End of SHADERtoy code. My code below.
float ll;
float l = fragColor.r * fragColor.g * fragColor.b;
ll = l;
float pn = Perlin3D(vec3(uvn*7.7, 6));
// if (l<0.45) l-= (0.4-pn)*4;
// if (l<0.99) { l-= (1.2*pn); }
{ l-= (2*pn); }
if (ll>0.9) l = 1;
// if (-(l-pn)<=0&&l>0.51) l-=0.22;
// l+=0.22;
float cc = abs(fragColor.r-fragColor.g);
float a = abs(fragColor.b-fragColor.g);
// x,y,part_white,offset,hue, pattern,period,tubrulence,blocksize,angleboost,twist
float g = 1-spachrotyze(fragCoord[0], fragCoord[1]/0.5, 1-l,cc,a, 1, 15, 0, 0,0,degrees_to_radians(45));
// Output to screen
outColor = vec4(vec3(g,g,g),1);
}
// I have no idea what this file does.
// I think it's a slight variation on the default distributed with SHADERed.
// I got it from the SHADERtoy/ProceduralGradientVisualizer example.
#version 330
uniform mat4 matVP;
uniform mat4 matGeo;
layout (location = 0) in vec3 pos;
layout (location = 1) in vec3 normal;
out vec4 coord;
void main() {
gl_Position = coord = matVP * matGeo * vec4(pos,1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment