Skip to content

Commit

Permalink
Update shaders.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gamenot committed Oct 24, 2023
1 parent cae52c5 commit 7a3fe6c
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 94 deletions.
42 changes: 42 additions & 0 deletions smarts/core/glsl/common_occulsion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#define DEVICE_HEIGHT 0.8
#define TOPOLOGY_SCALING_FACTOR 1.0
#define CENTER vec2(0.5)
#define SHADERTOY
//#define SPOT_CHECK

#define DENSITY_U 1.6 * 0.1
#define DENSITY_V 1.2 * 0.1


vec2 hash( vec2 p ) // replace this by something better
{
p = vec2( dot(p,vec2(127.1,311.7)), dot(p,vec2(269.5,183.3)) );
return -1.0 + 2.0*fract(sin(p)*43758.5453123);
}

float noise( in vec2 p )
{
const float K1 = 0.366025404; // (sqrt(3)-1)/2;
const float K2 = 0.211324865; // (3-sqrt(3))/6;

vec2 i = floor( p + (p.x+p.y)*K1 );
vec2 a = p - i + (i.x+i.y)*K2;
float m = step(a.y,a.x);
vec2 o = vec2(m,1.0-m);
vec2 b = a - o + K2;
vec2 c = a - 1.0 + 2.0*K2;
vec3 h = max( 0.5-vec3(dot(a,a), dot(b,b), dot(c,c) ), 0.0 );
vec3 n = h*h*h*h*vec3( dot(a,hash(i+0.0)), dot(b,hash(i+o)), dot(c,hash(i+1.0)));
return dot( n, vec3(70.0) );
}

float noise_with_octaves( in vec2 uv, in mat2 m ){
float f = 0.0;
uv *= 5.0;

f = 0.5000*noise( uv ); uv = m*uv;
f += 0.2500*noise( uv ); uv = m*uv;
f += 0.1250*noise( uv ); uv = m*uv;
f += 0.0625*noise( uv ); uv = m*uv;
return f;
}
28 changes: 28 additions & 0 deletions smarts/core/glsl/compound.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#define SPOT_RADIUS 100.0

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 rec_res = 1.0 / iResolution.xy;
vec2 p = fragCoord.xy * rec_res;

fragColor = texture(iChannel2, p);


#ifdef SPOT_CHECK
if( distance(fragCoord, iMouse.xy) < 30.0 )
{
fragColor = texture(iChannel2, p);
}
else if( distance(fragCoord, iMouse.xy) < SPOT_RADIUS )
{
float aspect = iResolution.x/iResolution.y;
vec2 uv = p*vec2(aspect,1.0);
mat2 m = mat2( DENSITY_U, DENSITY_V, -DENSITY_V, DENSITY_U );
float f = 0.0;
f = noise_with_octaves(uv, m);
f = 0.5 + 0.5*f;
f *= 0.3 + f;
fragColor = vec4( f, f, f, 1.0 );
}
#endif
}
43 changes: 43 additions & 0 deletions smarts/core/glsl/occlusion.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Visibility check

// -----------------------------------------------
#define STEP_LENGTH 0.2
#define CENTER_COORD iResolution.xy * 0.5


void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 rec_res = 1.0 / iResolution.xy;
vec2 p = fragCoord.xy * rec_res;

vec2 offset = fragCoord.xy - CENTER_COORD;
vec2 offset_norm = normalize(offset);
float offset_dist = length(offset);

if (texture(iChannel1, vec2(0.5)).x <= 0.0){
fragColor = vec4(0.0, 0.0, 0.0, 1.0);
return;
}

float center_height = texture(iChannel0, vec2(0.5)).x * TOPOLOGY_SCALING_FACTOR + DEVICE_HEIGHT;
float target_height = texture(iChannel0, p).x * TOPOLOGY_SCALING_FACTOR;

float target_slope = (target_height - center_height) / offset_dist;

float total = STEP_LENGTH;
while (total < offset_dist - 0.01 ) {
vec2 intermediary_coord = (CENTER_COORD + offset_norm * total) * rec_res;
float intermediary_height = texture(iChannel0, intermediary_coord).x * TOPOLOGY_SCALING_FACTOR;

if ( target_slope < ((intermediary_height - center_height) * TOPOLOGY_SCALING_FACTOR ) / total){
fragColor = vec4(0.0, 0.0, 0.0, 1.0);
return;
}


total += STEP_LENGTH;
}


fragColor = vec4(1.0,1.0,1.0,1.0);
}
18 changes: 18 additions & 0 deletions smarts/core/glsl/red.comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#version 430

// Set the number of invocations in the work group.
// In this case, we operate on the image in 16x16 pixel tiles.
layout (local_size_x = 16, local_size_y = 16) in;

uniform writeonly image2D toNoiseTex;

void main() {
// Acquire the coordinates to the texel we are to process.
ivec2 texelCoords = ivec2(gl_GlobalInvocationID.xy);

// Read the pixel from the first texture.
vec4 pixel = vec4(1.0, 0.0, 0.0, 0.0);

// Now write the modified pixel to the second texture.
imageStore(toNoiseTex, texelCoords, pixel);
}
19 changes: 14 additions & 5 deletions smarts/core/glsl/simplex.comp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
// https://www.shadertoy.com/playlist/fXlXzf&from=0&num=12
#version 430

layout (local_size_x = 16, local_size_y = 16)
#define WIDTH 16
#define HEIGHT 16

uniform writeonly image2D toNoise;
layout (local_size_x = WIDTH, local_size_y = HEIGHT) in;

uniform writeonly image2D toNoiseTex;

vec2 hash( vec2 p ) // replace this by something better
{
Expand All @@ -42,17 +45,23 @@ float noise( in vec2 p )

void main() {
// get the coordinates
ivec2 texelCoords = ivec2(gl_GlobalInvocationID.xy)
ivec2 texelCoords = ivec2(gl_GlobalInvocationID.xy);

ivec2 dimensions = ivec2(256, 256);
vec2 rec_res = 1.0 / dimensions;
vec2 p = texelCoords * rec_res;
vec2 uv = p*vec2(dimensions.y/dimensions.x,1.0);

uv *= 5.0;
mat2 m = mat2( 1.6, 1.2, -1.2, 1.6 );
f = 0.5000*noise( uv ); uv = m*uv;
float f = 0.5000*noise( uv ); uv = m*uv;
f += 0.2500*noise( uv ); uv = m*uv;
f += 0.1250*noise( uv ); uv = m*uv;
f += 0.0625*noise( uv ); uv = m*uv;

f = 0.5 + 0.5*f;
f *= 255.0;


imageStore(toNoise, texelCoords, vec4(f, f, f, 1.0))
imageStore(toNoiseTex, texelCoords, ivec4(255));
}
99 changes: 99 additions & 0 deletions smarts/core/glsl/simplex.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#version 330 core
#define DEVICE_HEIGHT 0.8
#define TOPOLOGY_SCALING_FACTOR 1.0
#define CENTER vec2(0.5)
//#define SHADERTOY
//#define SPOT_CHECK

#define DENSITY_U 1.6 * 0.1
#define DENSITY_V 1.2 * 0.1

// The MIT License
// Copyright © 2013 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// https://www.youtube.com/c/InigoQuilez
// https://iquilezles.org


// Simplex Noise (http://en.wikipedia.org/wiki/Simplex_noise), a type of gradient noise
// that uses N+1 vertices for random gradient interpolation instead of 2^N as in regular
// latice based Gradient Noise.

// All noise functions here:
//
// https://www.shadertoy.com/playlist/fXlXzf&from=0&num=12


// -----------------------------------------------
#ifdef SHADERTOY

#else
vec2 hash( vec2 p ) // replace this by something better
{
p = vec2( dot(p,vec2(127.1,311.7)), dot(p,vec2(269.5,183.3)) );
return -1.0 + 2.0*fract(sin(p)*43758.5453123);
}

float noise( in vec2 p )
{
const float K1 = 0.366025404; // (sqrt(3)-1)/2;
const float K2 = 0.211324865; // (3-sqrt(3))/6;

vec2 i = floor( p + (p.x+p.y)*K1 );
vec2 a = p - i + (i.x+i.y)*K2;
float m = step(a.y,a.x);
vec2 o = vec2(m,1.0-m);
vec2 b = a - o + K2;
vec2 c = a - 1.0 + 2.0*K2;
vec3 h = max( 0.5-vec3(dot(a,a), dot(b,b), dot(c,c) ), 0.0 );
vec3 n = h*h*h*h*vec3( dot(a,hash(i+0.0)), dot(b,hash(i+o)), dot(c,hash(i+1.0)));
return dot( n, vec3(70.0) );
}

float noise_with_octaves( in vec2 uv, in mat2 m ){
float f = 0.0;
uv *= 5.0;

f = 0.5000*noise( uv ); uv = m*uv;
f += 0.2500*noise( uv ); uv = m*uv;
f += 0.1250*noise( uv ); uv = m*uv;
f += 0.0625*noise( uv ); uv = m*uv;
return f;
}

// Output color
out vec4 p3d_Color;

// inputs
uniform vec2 iResolution;

#endif
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 rec_res = 1.0 / iResolution.xy;
vec2 p = fragCoord.xy * rec_res;
float aspect = iResolution.x/iResolution.y;

#ifdef SHADERTOY
vec2 uv = p*vec2(aspect,1.0) + vec2(iTime * 0.1);
#else
vec2 uv = p*vec2(aspect,1.0);
#endif

float f = 0.0;
float x, y, z;
mat2 m = mat2( DENSITY_U, DENSITY_V, -DENSITY_V, DENSITY_U );

f = noise_with_octaves(uv, m);

//f = 0.5 + 0.5*f;
//f *= 0.3 + f;

fragColor = vec4( f, f, f, 1.0 );
}

#ifndef SHADERTOY
void main(){
mainImage(p3d_Color, gl_FragCoord.xy);
}
#endif
Loading

0 comments on commit 7a3fe6c

Please sign in to comment.