mirror of
https://github.com/raysan5/raylib.git
synced 2025-10-08 19:06:27 +00:00
REVIEWED: Shaders formating to follow raylib code conventions
This commit is contained in:
@@ -10,7 +10,7 @@ uniform vec4 color;
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// Each point is drawn as a screen space square of gl_PointSize size. gl_PointCoord contains where we are inside of
|
// Each point is drawn as a screen space square of gl_PointSize size. gl_PointCoord contains where we are inside of
|
||||||
// it. (0, 0) is the top left, (1, 1) the bottom right corner.
|
// it. (0, 0) is the top left, (1, 1) the bottom right corner
|
||||||
// Draw each point as a colored circle with alpha 1.0 in the center and 0.0 at the outer edges.
|
// Draw each point as a colored circle with alpha 1.0 in the center and 0.0 at the outer edges
|
||||||
gl_FragColor = vec4(color.rgb, color.a*(1.0 - length(gl_PointCoord.xy - vec2(0.5))*2.0));
|
gl_FragColor = vec4(color.rgb, color.a*(1.0 - length(gl_PointCoord.xy - vec2(0.5))*2.0));
|
||||||
}
|
}
|
@@ -11,7 +11,7 @@ out vec4 finalColor;
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// Each point is drawn as a screen space square of gl_PointSize size. gl_PointCoord contains where we are inside of
|
// Each point is drawn as a screen space square of gl_PointSize size. gl_PointCoord contains where we are inside of
|
||||||
// it. (0, 0) is the top left, (1, 1) the bottom right corner.
|
// it. (0, 0) is the top left, (1, 1) the bottom right corner
|
||||||
// Draw each point as a colored circle with alpha 1.0 in the center and 0.0 at the outer edges.
|
// Draw each point as a colored circle with alpha 1.0 in the center and 0.0 at the outer edges
|
||||||
finalColor = vec4(color.rgb, color.a*(1 - length(gl_PointCoord.xy - vec2(0.5))*2));
|
finalColor = vec4(color.rgb, color.a*(1 - length(gl_PointCoord.xy - vec2(0.5))*2));
|
||||||
}
|
}
|
@@ -12,9 +12,9 @@ uniform vec4 colDiffuse;
|
|||||||
|
|
||||||
// NOTE: Add your custom variables here
|
// NOTE: Add your custom variables here
|
||||||
|
|
||||||
const vec2 size = vec2(800, 450); // render size
|
const vec2 size = vec2(800, 450); // Framebuffer size
|
||||||
const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance
|
const float samples = 5.0; // Pixels per axis; higher = bigger glow, worse performance
|
||||||
const float quality = 2.5; // lower = smaller glow, better quality
|
const float quality = 2.5; // Defines size factor: Lower = smaller glow, better quality
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
@@ -16,7 +16,7 @@ float angle = 0.0;
|
|||||||
vec2 VectorRotateTime(vec2 v, float speed)
|
vec2 VectorRotateTime(vec2 v, float speed)
|
||||||
{
|
{
|
||||||
float time = uTime*speed;
|
float time = uTime*speed;
|
||||||
float localTime = fract(time); // The time domain this works on is 1 sec.
|
float localTime = fract(time); // The time domain this works on is 1 sec
|
||||||
|
|
||||||
if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0;
|
if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0;
|
||||||
else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4.0*sin(2.0*PI*localTime - PI/2.0);
|
else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4.0*sin(2.0*PI*localTime - PI/2.0);
|
||||||
|
@@ -13,9 +13,9 @@ uniform sampler2D gAlbedoSpec;
|
|||||||
|
|
||||||
struct Light {
|
struct Light {
|
||||||
int enabled;
|
int enabled;
|
||||||
int type; // Unused in this demo.
|
int type; // Unused in this demo
|
||||||
vec3 position;
|
vec3 position;
|
||||||
vec3 target; // Unused in this demo.
|
vec3 target; // Unused in this demo
|
||||||
vec4 color;
|
vec4 color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -7,12 +7,12 @@ precision mediump float;
|
|||||||
The Sieve of Eratosthenes -- a simple shader by ProfJski
|
The Sieve of Eratosthenes -- a simple shader by ProfJski
|
||||||
An early prime number sieve: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
|
An early prime number sieve: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
|
||||||
|
|
||||||
The screen is divided into a square grid of boxes, each representing an integer value.
|
The screen is divided into a square grid of boxes, each representing an integer value
|
||||||
Each integer is tested to see if it is a prime number. Primes are colored white.
|
Each integer is tested to see if it is a prime number. Primes are colored white
|
||||||
Non-primes are colored with a color that indicates the smallest factor which evenly divdes our integer.
|
Non-primes are colored with a color that indicates the smallest factor which evenly divdes our integer
|
||||||
|
|
||||||
You can change the scale variable to make a larger or smaller grid.
|
You can change the scale variable to make a larger or smaller grid
|
||||||
Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers.
|
Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers
|
||||||
|
|
||||||
WARNING: If you make scale too large, your GPU may bog down!
|
WARNING: If you make scale too large, your GPU may bog down!
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ vec4 Colorizer(float counter, float maxSize)
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 color = vec4(1.0);
|
vec4 color = vec4(1.0);
|
||||||
float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid.
|
float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid
|
||||||
float value = scale*floor(fragTexCoord.y*scale) + floor(fragTexCoord.x*scale); // Group pixels into boxes representing integer values
|
float value = scale*floor(fragTexCoord.y*scale) + floor(fragTexCoord.x*scale); // Group pixels into boxes representing integer values
|
||||||
int valuei = int(value);
|
int valuei = int(value);
|
||||||
|
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
#version 100
|
#version 100
|
||||||
|
|
||||||
#extension GL_EXT_frag_depth : enable // Extension required for writing depth
|
#extension GL_EXT_frag_depth : enable // Extension required for writing depth
|
||||||
precision mediump float; // Precision required for OpenGL ES2 (WebGL)
|
precision mediump float; // Precision required for OpenGL ES2 (WebGL)
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ uniform vec4 colDiffuse;
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||||
|
|
||||||
gl_FragColor = texelColor*colDiffuse*fragColor;
|
gl_FragColor = texelColor*colDiffuse*fragColor;
|
||||||
gl_FragDepthEXT = gl_FragCoord.z;
|
gl_FragDepthEXT = gl_FragCoord.z;
|
||||||
}
|
}
|
@@ -1,9 +1,9 @@
|
|||||||
#version 100
|
#version 100
|
||||||
|
|
||||||
#extension GL_EXT_frag_depth : enable //Extension required for writing depth
|
#extension GL_EXT_frag_depth : enable //Extension required for writing depth
|
||||||
#extension GL_OES_standard_derivatives : enable //Extension used for fwidth()
|
#extension GL_OES_standard_derivatives : enable //Extension used for fwidth()
|
||||||
precision mediump float; // Precision required for OpenGL ES2 (WebGL)
|
precision mediump float; // Precision required for OpenGL ES2 (WebGL)
|
||||||
|
|
||||||
|
|
||||||
// Input vertex attributes (from vertex shader)
|
// Input vertex attributes (from vertex shader)
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
varying vec4 fragColor;
|
varying vec4 fragColor;
|
||||||
@@ -19,13 +19,14 @@ uniform vec2 screenCenter;
|
|||||||
|
|
||||||
#define ZERO 0
|
#define ZERO 0
|
||||||
|
|
||||||
// https://learnopengl.com/Advanced-OpenGL/Depth-testing
|
// SRC: https://learnopengl.com/Advanced-OpenGL/Depth-testing
|
||||||
float CalcDepth(in vec3 rd, in float Idist){
|
float CalcDepth(in vec3 rd, in float Idist)
|
||||||
|
{
|
||||||
float local_z = dot(normalize(camDir),rd)*Idist;
|
float local_z = dot(normalize(camDir),rd)*Idist;
|
||||||
return (1.0/(local_z) - 1.0/0.01)/(1.0/1000.0 -1.0/0.01);
|
return (1.0/(local_z) - 1.0/0.01)/(1.0/1000.0 -1.0/0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://iquilezles.org/articles/distfunctions/
|
// SRC: https://iquilezles.org/articles/distfunctions/
|
||||||
float sdHorseshoe(in vec3 p, in vec2 c, in float r, in float le, vec2 w)
|
float sdHorseshoe(in vec3 p, in vec2 c, in float r, in float le, vec2 w)
|
||||||
{
|
{
|
||||||
p.x = abs(p.x);
|
p.x = abs(p.x);
|
||||||
@@ -57,11 +58,10 @@ float sdSixWayCutHollowSphere( vec3 p, float r, float h, float t )
|
|||||||
|
|
||||||
float w = sqrt(r*r-h*h);
|
float w = sqrt(r*r-h*h);
|
||||||
|
|
||||||
return ((h*q.x<w*q.y) ? length(q-vec2(w,h)) :
|
return ((h*q.x<w*q.y) ? length(q-vec2(w,h)) : abs(length(q)-r)) - t;
|
||||||
abs(length(q)-r) ) - t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://iquilezles.org/articles/boxfunctions
|
// SRC: https://iquilezles.org/articles/boxfunctions
|
||||||
vec2 iBox(in vec3 ro, in vec3 rd, in vec3 rad)
|
vec2 iBox(in vec3 ro, in vec3 rd, in vec3 rad)
|
||||||
{
|
{
|
||||||
vec3 m = 1.0/rd;
|
vec3 m = 1.0/rd;
|
||||||
@@ -69,6 +69,7 @@ vec2 iBox( in vec3 ro, in vec3 rd, in vec3 rad )
|
|||||||
vec3 k = abs(m)*rad;
|
vec3 k = abs(m)*rad;
|
||||||
vec3 t1 = -n - k;
|
vec3 t1 = -n - k;
|
||||||
vec3 t2 = -n + k;
|
vec3 t2 = -n + k;
|
||||||
|
|
||||||
return vec2(max(max(t1.x, t1.y), t1.z),
|
return vec2(max(max(t1.x, t1.y), t1.z),
|
||||||
min(min(t2.x, t2.y), t2.z));
|
min(min(t2.x, t2.y), t2.z));
|
||||||
}
|
}
|
||||||
@@ -78,20 +79,23 @@ vec2 opU( vec2 d1, vec2 d2 )
|
|||||||
return (d1.x<d2.x) ? d1 : d2;
|
return (d1.x<d2.x) ? d1 : d2;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec2 map( in vec3 pos ){
|
vec2 map(in vec3 pos)
|
||||||
|
{
|
||||||
vec2 res = vec2(sdHorseshoe(pos-vec3(-1.0,0.08, 1.0), vec2(cos(1.3),sin(1.3)), 0.2, 0.3, vec2(0.03,0.5)), 11.5) ;
|
vec2 res = vec2(sdHorseshoe(pos-vec3(-1.0,0.08, 1.0), vec2(cos(1.3),sin(1.3)), 0.2, 0.3, vec2(0.03,0.5)), 11.5) ;
|
||||||
res = opU(res, vec2(sdSixWayCutHollowSphere(pos-vec3(0.0, 1.0, 0.0), 4.0, 3.5, 0.5), 4.5)) ;
|
res = opU(res, vec2(sdSixWayCutHollowSphere(pos-vec3(0.0, 1.0, 0.0), 4.0, 3.5, 0.5), 4.5)) ;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.shadertoy.com/view/Xds3zN
|
// SRC: https://www.shadertoy.com/view/Xds3zN
|
||||||
vec2 raycast( in vec3 ro, in vec3 rd ){
|
vec2 raycast(in vec3 ro, in vec3 rd)
|
||||||
|
{
|
||||||
vec2 res = vec2(-1.0,-1.0);
|
vec2 res = vec2(-1.0,-1.0);
|
||||||
|
|
||||||
float tmin = 1.0;
|
float tmin = 1.0;
|
||||||
float tmax = 20.0;
|
float tmax = 20.0;
|
||||||
|
|
||||||
// raytrace floor plane
|
// Raytrace floor plane
|
||||||
float tp1 = (-ro.y)/rd.y;
|
float tp1 = (-ro.y)/rd.y;
|
||||||
if (tp1>0.0)
|
if (tp1>0.0)
|
||||||
{
|
{
|
||||||
|
@@ -1,19 +1,17 @@
|
|||||||
#version 100
|
#version 120
|
||||||
|
|
||||||
precision mediump float;
|
|
||||||
|
|
||||||
// Input vertex attributes (from vertex shader)
|
// Input vertex attributes (from vertex shader)
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
varying vec4 fragColor;
|
varying vec4 fragColor;
|
||||||
|
|
||||||
uniform vec2 c; // c.x = real, c.y = imaginary component. Equation done is z^2 + c
|
uniform vec2 c; // c.x = real, c.y = imaginary component. Equation done is z^2 + c
|
||||||
uniform vec2 offset; // Offset of the scale.
|
uniform vec2 offset; // Offset of the scale
|
||||||
uniform float zoom; // Zoom of the scale.
|
uniform float zoom; // Zoom of the scale
|
||||||
|
|
||||||
// NOTE: Maximum number of shader for-loop iterations depend on GPU,
|
// NOTE: Maximum number of shader for-loop iterations depend on GPU,
|
||||||
// for example, on RasperryPi for this examply only supports up to 60
|
// for example, on RasperryPi for this examply only supports up to 60
|
||||||
const int maxIterations = 48; // Max iterations to do.
|
const int maxIterations = 48; // Max iterations to do
|
||||||
const float colorCycles = 1.0; // Number of times the color palette repeats.
|
const float colorCycles = 1.0; // Number of times the color palette repeats
|
||||||
|
|
||||||
// Square a complex number
|
// Square a complex number
|
||||||
vec2 ComplexSquare(vec2 z)
|
vec2 ComplexSquare(vec2 z)
|
||||||
@@ -32,22 +30,22 @@ vec3 Hsv2rgb(vec3 c)
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
/**********************************************************************************************
|
/**********************************************************************************************
|
||||||
Julia sets use a function z^2 + c, where c is a constant.
|
Julia sets use a function z^2 + c, where c is a constant
|
||||||
This function is iterated until the nature of the point is determined.
|
This function is iterated until the nature of the point is determined
|
||||||
|
|
||||||
If the magnitude of the number becomes greater than 2, then from that point onward
|
If the magnitude of the number becomes greater than 2, then from that point onward
|
||||||
the number will get bigger and bigger, and will never get smaller (tends towards infinity).
|
the number will get bigger and bigger, and will never get smaller (tends towards infinity)
|
||||||
2^2 = 4, 4^2 = 8 and so on.
|
2^2 = 4, 4^2 = 8 and so on
|
||||||
So at 2 we stop iterating.
|
So at 2 we stop iterating
|
||||||
|
|
||||||
If the number is below 2, we keep iterating.
|
If the number is below 2, we keep iterating
|
||||||
But when do we stop iterating if the number is always below 2 (it converges)?
|
But when do we stop iterating if the number is always below 2 (it converges)?
|
||||||
That is what maxIterations is for.
|
That is what maxIterations is for
|
||||||
Then we can divide the iterations by the maxIterations value to get a normalized value that we can
|
Then we can divide the iterations by the maxIterations value to get a normalized value
|
||||||
then map to a color.
|
that we can then map to a color
|
||||||
|
|
||||||
We use dot product (z.x * z.x + z.y * z.y) to determine the magnitude (length) squared.
|
We use dot product (z.x*z.x + z.y*z.y) to determine the magnitude (length) squared
|
||||||
And once the magnitude squared is > 4, then magnitude > 2 is also true (saves computational power).
|
And once the magnitude squared is > 4, then magnitude > 2 is also true (saves computational power)
|
||||||
*************************************************************************************************/
|
*************************************************************************************************/
|
||||||
|
|
||||||
// The pixel coordinates are scaled so they are on the mandelbrot scale
|
// The pixel coordinates are scaled so they are on the mandelbrot scale
|
||||||
@@ -65,18 +63,18 @@ void main()
|
|||||||
iter = iterations;
|
iter = iterations;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Another few iterations decreases errors in the smoothing calculation.
|
// Another few iterations decreases errors in the smoothing calculation
|
||||||
// See http://linas.org/art-gallery/escape/escape.html for more information.
|
// See http://linas.org/art-gallery/escape/escape.html for more information
|
||||||
z = ComplexSquare(z) + c;
|
z = ComplexSquare(z) + c;
|
||||||
z = ComplexSquare(z) + c;
|
z = ComplexSquare(z) + c;
|
||||||
|
|
||||||
// This last part smooths the color (again see link above).
|
// This last part smooths the color (again see link above)
|
||||||
float smoothVal = float(iter) + 1.0 - (log(log(length(z)))/log(2.0));
|
float smoothVal = float(iter) + 1.0 - (log(log(length(z)))/log(2.0));
|
||||||
|
|
||||||
// Normalize the value so it is between 0 and 1.
|
// Normalize the value so it is between 0 and 1
|
||||||
float norm = smoothVal/float(maxIterations);
|
float norm = smoothVal/float(maxIterations);
|
||||||
|
|
||||||
// If in set, color black. 0.999 allows for some float accuracy error.
|
// If in set, color black. 0.999 allows for some float accuracy error
|
||||||
if (norm > 0.999) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
if (norm > 0.999) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
else gl_FragColor = vec4(Hsv2rgb(vec3(norm*colorCycles, 1.0, 1.0)), 1.0);
|
else gl_FragColor = vec4(Hsv2rgb(vec3(norm*colorCycles, 1.0, 1.0)), 1.0);
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,4 @@
|
|||||||
#version 100
|
#version 120
|
||||||
|
|
||||||
precision mediump float;
|
|
||||||
|
|
||||||
// Input vertex attributes (from vertex shader)
|
// Input vertex attributes (from vertex shader)
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
|
@@ -34,7 +34,7 @@ uniform vec2 resolution;
|
|||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
// A list of useful distance function to simple primitives, and an example on how to
|
// A list of useful distance function to simple primitives, and an example on how to
|
||||||
// do some interesting boolean operations, repetition and displacement.
|
// do some interesting boolean operations, repetition and displacement
|
||||||
//
|
//
|
||||||
// More info here: http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
// More info here: http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
||||||
|
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
// Note: SDF by Iñigo Quilez is licensed under MIT License
|
|
||||||
|
|
||||||
#version 100
|
#version 100
|
||||||
|
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
|
|
||||||
|
// NOTE: SDF by Iñigo Quilez, licensed under MIT License
|
||||||
|
|
||||||
// Input vertex attributes (from vertex shader)
|
// Input vertex attributes (from vertex shader)
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
varying vec4 fragColor;
|
varying vec4 fragColor;
|
||||||
|
@@ -6,7 +6,6 @@ precision mediump float;
|
|||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
varying float height;
|
varying float height;
|
||||||
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 darkblue = vec4(0.0, 0.13, 0.18, 1.0);
|
vec4 darkblue = vec4(0.0, 0.13, 0.18, 1.0);
|
||||||
|
@@ -11,9 +11,7 @@ uniform sampler2D texture0;
|
|||||||
uniform vec4 colDiffuse;
|
uniform vec4 colDiffuse;
|
||||||
|
|
||||||
uniform float seconds;
|
uniform float seconds;
|
||||||
|
|
||||||
uniform vec2 size;
|
uniform vec2 size;
|
||||||
|
|
||||||
uniform float freqX;
|
uniform float freqX;
|
||||||
uniform float freqY;
|
uniform float freqY;
|
||||||
uniform float ampX;
|
uniform float ampX;
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#version 100
|
#version 100
|
||||||
|
|
||||||
#extension GL_EXT_frag_depth : enable
|
#extension GL_EXT_frag_depth : enable
|
||||||
precision mediump float; // Precision required for OpenGL ES2 (WebGL)
|
precision mediump float;
|
||||||
|
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
varying vec4 fragColor;
|
varying vec4 fragColor;
|
||||||
|
@@ -16,12 +16,12 @@ void main()
|
|||||||
vec4 texelColor = texture(texture0, fragTexCoord)*fragColor;
|
vec4 texelColor = texture(texture0, fragTexCoord)*fragColor;
|
||||||
|
|
||||||
// Convert the (normalized) texel color RED component (GB would work, too)
|
// Convert the (normalized) texel color RED component (GB would work, too)
|
||||||
// to the palette index by scaling up from [0, 1] to [0, 255].
|
// to the palette index by scaling up from [0, 1] to [0, 255]
|
||||||
int index = int(texelColor.r*255.0);
|
int index = int(texelColor.r*255.0);
|
||||||
ivec3 color = palette[index];
|
ivec3 color = palette[index];
|
||||||
|
|
||||||
// Calculate final fragment color. Note that the palette color components
|
// Calculate final fragment color. Note that the palette color components
|
||||||
// are defined in the range [0, 255] and need to be normalized to [0, 1]
|
// are defined in the range [0, 255] and need to be normalized to [0, 1]
|
||||||
// for OpenGL to work.
|
// for OpenGL to work
|
||||||
gl_FragColor = vec4(color/255.0, texelColor.a);
|
gl_FragColor = vec4(color/255.0, texelColor.a);
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,7 @@ uniform vec2 resolution;
|
|||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
// A list of useful distance function to simple primitives, and an example on how to
|
// A list of useful distance function to simple primitives, and an example on how to
|
||||||
// do some interesting boolean operations, repetition and displacement.
|
// do some interesting boolean operations, repetition and displacement
|
||||||
//
|
//
|
||||||
// More info here: http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
// More info here: http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
// Note: SDF by Iñigo Quilez is licensed under MIT License
|
|
||||||
|
|
||||||
#version 120
|
#version 120
|
||||||
|
|
||||||
|
// NOTE: SDF by Iñigo Quilez, licensed under MIT License
|
||||||
|
|
||||||
// Input vertex attributes (from vertex shader)
|
// Input vertex attributes (from vertex shader)
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
varying vec4 fragColor;
|
varying vec4 fragColor;
|
||||||
|
@@ -52,7 +52,7 @@ void main()
|
|||||||
vec2 sampleCoords = fragPosLightSpace.xy;
|
vec2 sampleCoords = fragPosLightSpace.xy;
|
||||||
float curDepth = fragPosLightSpace.z;
|
float curDepth = fragPosLightSpace.z;
|
||||||
|
|
||||||
// Slope-scale depth bias: depth biasing reduces "shadow acne" artifacts, where dark stripes appear all over the scene.
|
// Slope-scale depth bias: depth biasing reduces "shadow acne" artifacts, where dark stripes appear all over the scene
|
||||||
// The solution is adding a small bias to the depth
|
// The solution is adding a small bias to the depth
|
||||||
// In this case, the bias is proportional to the slope of the surface, relative to the light
|
// In this case, the bias is proportional to the slope of the surface, relative to the light
|
||||||
float bias = max(0.0008*(1.0 - dot(normal, l)), 0.00008);
|
float bias = max(0.0008*(1.0 - dot(normal, l)), 0.00008);
|
||||||
@@ -61,8 +61,8 @@ void main()
|
|||||||
|
|
||||||
// PCF (percentage-closer filtering) algorithm:
|
// PCF (percentage-closer filtering) algorithm:
|
||||||
// Instead of testing if just one point is closer to the current point,
|
// Instead of testing if just one point is closer to the current point,
|
||||||
// we test the surrounding points as well.
|
// we test the surrounding points as well
|
||||||
// This blurs shadow edges, hiding aliasing artifacts.
|
// This blurs shadow edges, hiding aliasing artifacts
|
||||||
vec2 texelSize = vec2(1.0/float(shadowMapResolution));
|
vec2 texelSize = vec2(1.0/float(shadowMapResolution));
|
||||||
for (int x = -1; x <= 1; x++)
|
for (int x = -1; x <= 1; x++)
|
||||||
{
|
{
|
||||||
|
@@ -17,7 +17,7 @@ float angle = 0.0;
|
|||||||
vec2 VectorRotateTime(vec2 v, float speed)
|
vec2 VectorRotateTime(vec2 v, float speed)
|
||||||
{
|
{
|
||||||
float time = uTime*speed;
|
float time = uTime*speed;
|
||||||
float localTime = fract(time); // The time domain this works on is 1 sec.
|
float localTime = fract(time); // The time domain this works on is 1 sec
|
||||||
|
|
||||||
if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0;
|
if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0;
|
||||||
else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4*sin(2*PI*localTime - PI/2);
|
else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4*sin(2*PI*localTime - PI/2);
|
||||||
|
@@ -10,9 +10,9 @@ uniform sampler2D gAlbedoSpec;
|
|||||||
|
|
||||||
struct Light {
|
struct Light {
|
||||||
int enabled;
|
int enabled;
|
||||||
int type; // Unused in this demo.
|
int type; // Unused in this demo
|
||||||
vec3 position;
|
vec3 position;
|
||||||
vec3 target; // Unused in this demo.
|
vec3 target; // Unused in this demo
|
||||||
vec4 color;
|
vec4 color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -5,12 +5,12 @@
|
|||||||
The Sieve of Eratosthenes -- a simple shader by ProfJski
|
The Sieve of Eratosthenes -- a simple shader by ProfJski
|
||||||
An early prime number sieve: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
|
An early prime number sieve: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
|
||||||
|
|
||||||
The screen is divided into a square grid of boxes, each representing an integer value.
|
The screen is divided into a square grid of boxes, each representing an integer value
|
||||||
Each integer is tested to see if it is a prime number. Primes are colored white.
|
Each integer is tested to see if it is a prime number. Primes are colored white
|
||||||
Non-primes are colored with a color that indicates the smallest factor which evenly divdes our integer.
|
Non-primes are colored with a color that indicates the smallest factor which evenly divides our integer
|
||||||
|
|
||||||
You can change the scale variable to make a larger or smaller grid.
|
You can change the scale variable to make a larger or smaller grid
|
||||||
Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers.
|
Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers
|
||||||
|
|
||||||
WARNING: If you make scale too large, your GPU may bog down!
|
WARNING: If you make scale too large, your GPU may bog down!
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ vec4 Colorizer(float counter, float maxSize)
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 color = vec4(1.0);
|
vec4 color = vec4(1.0);
|
||||||
float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid.
|
float scale = 1000.0; // Makes 100x100 square grid, change this variable to make a smaller or larger grid
|
||||||
int value = int(scale*floor(fragTexCoord.y*scale)+floor(fragTexCoord.x*scale)); // Group pixels into boxes representing integer values
|
int value = int(scale*floor(fragTexCoord.y*scale)+floor(fragTexCoord.x*scale)); // Group pixels into boxes representing integer values
|
||||||
|
|
||||||
if ((value == 0) || (value == 1) || (value == 2)) finalColor = vec4(1.0);
|
if ((value == 0) || (value == 1) || (value == 2)) finalColor = vec4(1.0);
|
||||||
|
@@ -8,11 +8,11 @@ in vec4 fragColor;
|
|||||||
out vec4 finalColor;
|
out vec4 finalColor;
|
||||||
|
|
||||||
uniform vec2 c; // c.x = real, c.y = imaginary component. Equation done is z^2 + c
|
uniform vec2 c; // c.x = real, c.y = imaginary component. Equation done is z^2 + c
|
||||||
uniform vec2 offset; // Offset of the scale.
|
uniform vec2 offset; // Offset of the scale
|
||||||
uniform float zoom; // Zoom of the scale.
|
uniform float zoom; // Zoom of the scale
|
||||||
|
|
||||||
const int maxIterations = 255; // Max iterations to do.
|
const int maxIterations = 255; // Max iterations to do
|
||||||
const float colorCycles = 2.0; // Number of times the color palette repeats. Can show higher detail for higher iteration numbers.
|
const float colorCycles = 2.0; // Number of times the color palette repeats. Can show higher detail for higher iteration numbers
|
||||||
|
|
||||||
// Square a complex number
|
// Square a complex number
|
||||||
vec2 ComplexSquare(vec2 z)
|
vec2 ComplexSquare(vec2 z)
|
||||||
@@ -31,22 +31,22 @@ vec3 Hsv2rgb(vec3 c)
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
/**********************************************************************************************
|
/**********************************************************************************************
|
||||||
Julia sets use a function z^2 + c, where c is a constant.
|
Julia sets use a function z^2 + c, where c is a constant
|
||||||
This function is iterated until the nature of the point is determined.
|
This function is iterated until the nature of the point is determined
|
||||||
|
|
||||||
If the magnitude of the number becomes greater than 2, then from that point onward
|
If the magnitude of the number becomes greater than 2, then from that point onward
|
||||||
the number will get bigger and bigger, and will never get smaller (tends towards infinity).
|
the number will get bigger and bigger, and will never get smaller (tends towards infinity)
|
||||||
2^2 = 4, 4^2 = 8 and so on.
|
2^2 = 4, 4^2 = 8 and so on
|
||||||
So at 2 we stop iterating.
|
So at 2 we stop iterating
|
||||||
|
|
||||||
If the number is below 2, we keep iterating.
|
If the number is below 2, we keep iterating
|
||||||
But when do we stop iterating if the number is always below 2 (it converges)?
|
But when do we stop iterating if the number is always below 2 (it converges)?
|
||||||
That is what maxIterations is for.
|
That is what maxIterations is for
|
||||||
Then we can divide the iterations by the maxIterations value to get a normalized value that we can
|
Then we can divide the iterations by the maxIterations value to get a normalized value
|
||||||
then map to a color.
|
that we can then map to a color
|
||||||
|
|
||||||
We use dot product (z.x * z.x + z.y * z.y) to determine the magnitude (length) squared.
|
We use dot product (z.x*z.x + z.y*z.y) to determine the magnitude (length) squared
|
||||||
And once the magnitude squared is > 4, then magnitude > 2 is also true (saves computational power).
|
And once the magnitude squared is > 4, then magnitude > 2 is also true (saves computational power)
|
||||||
*************************************************************************************************/
|
*************************************************************************************************/
|
||||||
|
|
||||||
// The pixel coordinates are scaled so they are on the mandelbrot scale
|
// The pixel coordinates are scaled so they are on the mandelbrot scale
|
||||||
@@ -63,18 +63,18 @@ void main()
|
|||||||
if (dot(z, z) > 4.0) break;
|
if (dot(z, z) > 4.0) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Another few iterations decreases errors in the smoothing calculation.
|
// Another few iterations decreases errors in the smoothing calculation
|
||||||
// See http://linas.org/art-gallery/escape/escape.html for more information.
|
// See http://linas.org/art-gallery/escape/escape.html for more information
|
||||||
z = ComplexSquare(z) + c;
|
z = ComplexSquare(z) + c;
|
||||||
z = ComplexSquare(z) + c;
|
z = ComplexSquare(z) + c;
|
||||||
|
|
||||||
// This last part smooths the color (again see link above).
|
// This last part smooths the color (again see link above)
|
||||||
float smoothVal = float(iterations) + 1.0 - (log(log(length(z)))/log(2.0));
|
float smoothVal = float(iterations) + 1.0 - (log(log(length(z)))/log(2.0));
|
||||||
|
|
||||||
// Normalize the value so it is between 0 and 1.
|
// Normalize the value so it is between 0 and 1
|
||||||
float norm = smoothVal/float(maxIterations);
|
float norm = smoothVal/float(maxIterations);
|
||||||
|
|
||||||
// If in set, color black. 0.999 allows for some float accuracy error.
|
// If in set, color black. 0.999 allows for some float accuracy error
|
||||||
if (norm > 0.999) finalColor = vec4(0.0, 0.0, 0.0, 1.0);
|
if (norm > 0.999) finalColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
else finalColor = vec4(Hsv2rgb(vec3(norm*colorCycles, 1.0, 1.0)), 1.0);
|
else finalColor = vec4(Hsv2rgb(vec3(norm*colorCycles, 1.0, 1.0)), 1.0);
|
||||||
}
|
}
|
||||||
|
@@ -33,7 +33,7 @@ uniform vec2 resolution;
|
|||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
// A list of useful distance function to simple primitives, and an example on how to
|
// A list of useful distance function to simple primitives, and an example on how to
|
||||||
// do some interesting boolean operations, repetition and displacement.
|
// do some interesting boolean operations, repetition and displacement
|
||||||
//
|
//
|
||||||
// More info here: http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
// More info here: http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
||||||
|
|
||||||
|
@@ -55,7 +55,7 @@ void main()
|
|||||||
vec2 sampleCoords = fragPosLightSpace.xy;
|
vec2 sampleCoords = fragPosLightSpace.xy;
|
||||||
float curDepth = fragPosLightSpace.z;
|
float curDepth = fragPosLightSpace.z;
|
||||||
|
|
||||||
// Slope-scale depth bias: depth biasing reduces "shadow acne" artifacts, where dark stripes appear all over the scene.
|
// Slope-scale depth bias: depth biasing reduces "shadow acne" artifacts, where dark stripes appear all over the scene
|
||||||
// The solution is adding a small bias to the depth
|
// The solution is adding a small bias to the depth
|
||||||
// In this case, the bias is proportional to the slope of the surface, relative to the light
|
// In this case, the bias is proportional to the slope of the surface, relative to the light
|
||||||
float bias = max(0.0002*(1.0 - dot(normal, l)), 0.00002) + 0.00001;
|
float bias = max(0.0002*(1.0 - dot(normal, l)), 0.00002) + 0.00001;
|
||||||
@@ -64,8 +64,8 @@ void main()
|
|||||||
|
|
||||||
// PCF (percentage-closer filtering) algorithm:
|
// PCF (percentage-closer filtering) algorithm:
|
||||||
// Instead of testing if just one point is closer to the current point,
|
// Instead of testing if just one point is closer to the current point,
|
||||||
// we test the surrounding points as well.
|
// we test the surrounding points as well
|
||||||
// This blurs shadow edges, hiding aliasing artifacts.
|
// This blurs shadow edges, hiding aliasing artifacts
|
||||||
vec2 texelSize = vec2(1.0/float(shadowMapResolution));
|
vec2 texelSize = vec2(1.0/float(shadowMapResolution));
|
||||||
for (int x = -1; x <= 1; x++)
|
for (int x = -1; x <= 1; x++)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user