shader lighting example
This commit is contained in:
parent
8eac9f4b51
commit
4c587660e2
70 changed files with 3769 additions and 0 deletions
BIN
examples/shaders/resources/fudesumi.png
Normal file
BIN
examples/shaders/resources/fudesumi.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 218 KiB |
24
examples/shaders/resources/shaders/glsl100/base.fs
Normal file
24
examples/shaders/resources/shaders/glsl100/base.fs
Normal file
|
@ -0,0 +1,24 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
uniform vec2 resolution = vec2(800, 450);
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||
|
||||
// NOTE: Implement here your fragment shader code
|
||||
|
||||
gl_FragColor = texelColor*colDiffuse;
|
||||
}
|
26
examples/shaders/resources/shaders/glsl100/base.vs
Normal file
26
examples/shaders/resources/shaders/glsl100/base.vs
Normal file
|
@ -0,0 +1,26 @@
|
|||
#version 100
|
||||
|
||||
// Input vertex attributes
|
||||
attribute vec3 vertexPosition;
|
||||
attribute vec2 vertexTexCoord;
|
||||
attribute vec3 vertexNormal;
|
||||
attribute vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
// Send vertex attributes to fragment shader
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||
}
|
39
examples/shaders/resources/shaders/glsl100/bloom.fs
Normal file
39
examples/shaders/resources/shaders/glsl100/bloom.fs
Normal file
|
@ -0,0 +1,39 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
const vec2 size = vec2(800, 450); // render size
|
||||
const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance
|
||||
const float quality = 2.5; // lower = smaller glow, better quality
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 sum = vec4(0);
|
||||
vec2 sizeFactor = vec2(1)/size*quality;
|
||||
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 source = texture2D(texture0, fragTexCoord);
|
||||
|
||||
const int range = 2; // should be = (samples - 1)/2;
|
||||
|
||||
for (int x = -range; x <= range; x++)
|
||||
{
|
||||
for (int y = -range; y <= range; y++)
|
||||
{
|
||||
sum += texture2D(texture0, fragTexCoord + vec2(x, y)*sizeFactor);
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate final fragment color
|
||||
gl_FragColor = ((sum/(samples*samples)) + source)*colDiffuse;
|
||||
}
|
34
examples/shaders/resources/shaders/glsl100/blur.fs
Normal file
34
examples/shaders/resources/shaders/glsl100/blur.fs
Normal file
|
@ -0,0 +1,34 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
const float renderHeight = 450.0;
|
||||
|
||||
vec3 offset = vec3(0.0, 1.3846153846, 3.2307692308);
|
||||
vec3 weight = vec3(0.2270270270, 0.3162162162, 0.0702702703);
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec3 tc = texture2D(texture0, fragTexCoord).rgb*weight.x;
|
||||
|
||||
tc += texture2D(texture0, fragTexCoord + vec2(offset.y)/renderWidth, 0.0).rgb*weight.y;
|
||||
tc += texture2D(texture0, fragTexCoord - vec2(offset.y)/renderWidth, 0.0).rgb*weight.y;
|
||||
|
||||
tc += texture2D(texture0, fragTexCoord + vec2(offset.z)/renderWidth, 0.0).rgb*weight.z;
|
||||
tc += texture2D(texture0, fragTexCoord - vec2(offset.z)/renderWidth, 0.0).rgb*weight.z;
|
||||
|
||||
gl_FragColor = vec4(tc, 1.0);
|
||||
}
|
47
examples/shaders/resources/shaders/glsl100/cross_hatching.fs
Normal file
47
examples/shaders/resources/shaders/glsl100/cross_hatching.fs
Normal file
|
@ -0,0 +1,47 @@
|
|||
# version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
float hatchOffsetY = 5.0;
|
||||
float lumThreshold01 = 0.9;
|
||||
float lumThreshold02 = 0.7;
|
||||
float lumThreshold03 = 0.5;
|
||||
float lumThreshold04 = 0.3;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 tc = vec3(1.0, 1.0, 1.0);
|
||||
float lum = length(texture2D(texture0, fragTexCoord).rgb);
|
||||
|
||||
if (lum < lumThreshold01)
|
||||
{
|
||||
if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
if (lum < lumThreshold02)
|
||||
{
|
||||
if (mod(gl_FragCoord .x - gl_FragCoord .y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
if (lum < lumThreshold03)
|
||||
{
|
||||
if (mod(gl_FragCoord .x + gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
if (lum < lumThreshold04)
|
||||
{
|
||||
if (mod(gl_FragCoord .x - gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
gl_FragColor = vec4(tc, 1.0);
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
# version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
const float renderHeight = 450.0;
|
||||
|
||||
float stitchingSize = 6.0;
|
||||
int invert = 0;
|
||||
|
||||
vec4 PostFX(sampler2D tex, vec2 uv)
|
||||
{
|
||||
vec4 c = vec4(0.0);
|
||||
float size = stitchingSize;
|
||||
vec2 cPos = uv * vec2(renderWidth, renderHeight);
|
||||
vec2 tlPos = floor(cPos / vec2(size, size));
|
||||
tlPos *= size;
|
||||
|
||||
int remX = int(mod(cPos.x, size));
|
||||
int remY = int(mod(cPos.y, size));
|
||||
|
||||
if (remX == 0 && remY == 0) tlPos = cPos;
|
||||
|
||||
vec2 blPos = tlPos;
|
||||
blPos.y += (size - 1.0);
|
||||
|
||||
if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y)))))
|
||||
{
|
||||
if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0);
|
||||
else c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (invert == 1) c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
|
||||
else c = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 tc = PostFX(texture0, fragTexCoord).rgb;
|
||||
|
||||
gl_FragColor = vec4(tc, 1.0);
|
||||
}
|
60
examples/shaders/resources/shaders/glsl100/cubes_panning.fs
Normal file
60
examples/shaders/resources/shaders/glsl100/cubes_panning.fs
Normal file
|
@ -0,0 +1,60 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Custom variables
|
||||
#define PI 3.14159265358979323846
|
||||
uniform float uTime = 0.0;
|
||||
|
||||
float divisions = 5.0;
|
||||
float angle = 0.0;
|
||||
|
||||
vec2 VectorRotateTime(vec2 v, float speed)
|
||||
{
|
||||
float time = uTime*speed;
|
||||
float localTime = fract(time); // The time domain this works on is 1 sec.
|
||||
|
||||
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.50) && (localTime < 0.75)) angle = PI*0.25;
|
||||
else if ((localTime >= 0.75) && (localTime < 1.00)) angle = PI/4*sin(2*PI*localTime);
|
||||
|
||||
// Rotate vector by angle
|
||||
v -= 0.5;
|
||||
v = mat2(cos(angle), -sin(angle), sin(angle), cos(angle))*v;
|
||||
v += 0.5;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
float Rectangle(in vec2 st, in float size, in float fill)
|
||||
{
|
||||
float roundSize = 0.5 - size/2.0;
|
||||
float left = step(roundSize, st.x);
|
||||
float top = step(roundSize, st.y);
|
||||
float bottom = step(roundSize, 1.0 - st.y);
|
||||
float right = step(roundSize, 1.0 - st.x);
|
||||
|
||||
return (left*bottom*right*top)*fill;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 fragPos = fragTexCoord;
|
||||
fragPos.xy += uTime/9.0;
|
||||
|
||||
fragPos *= divisions;
|
||||
vec2 ipos = floor(fragPos); // Get the integer coords
|
||||
vec2 fpos = fract(fragPos); // Get the fractional coords
|
||||
|
||||
fpos = VectorRotateTime(fpos, 0.2);
|
||||
|
||||
float alpha = Rectangle(fpos, 0.216, 1.0);
|
||||
vec3 color = vec3(0.3, 0.3, 0.3);
|
||||
|
||||
gl_FragColor = vec4(color, alpha);
|
||||
}
|
26
examples/shaders/resources/shaders/glsl100/depth.fs
Normal file
26
examples/shaders/resources/shaders/glsl100/depth.fs
Normal file
|
@ -0,0 +1,26 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0; // Depth texture
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
float zNear = 0.01; // camera z near
|
||||
float zFar = 10.0; // camera z far
|
||||
float z = texture2D(texture0, fragTexCoord).x;
|
||||
|
||||
// Linearize depth value
|
||||
float depth = (2.0*zNear)/(zFar + zNear - z*(zFar - zNear));
|
||||
|
||||
// Calculate final fragment color
|
||||
gl_FragColor = vec4(depth, depth, depth, 1.0f);
|
||||
}
|
54
examples/shaders/resources/shaders/glsl100/distortion.fs
Normal file
54
examples/shaders/resources/shaders/glsl100/distortion.fs
Normal file
|
@ -0,0 +1,54 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
|
||||
// NOTE: Default parameters for Oculus Rift DK2 device
|
||||
const vec2 LeftLensCenter = vec2(0.2863248, 0.5);
|
||||
const vec2 RightLensCenter = vec2(0.7136753, 0.5);
|
||||
const vec2 LeftScreenCenter = vec2(0.25, 0.5);
|
||||
const vec2 RightScreenCenter = vec2(0.75, 0.5);
|
||||
const vec2 Scale = vec2(0.25, 0.45);
|
||||
const vec2 ScaleIn = vec2(4.0, 2.5);
|
||||
const vec4 HmdWarpParam = vec4(1.0, 0.22, 0.24, 0.0);
|
||||
const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.0);
|
||||
|
||||
void main()
|
||||
{
|
||||
// The following two variables need to be set per eye
|
||||
vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter;
|
||||
vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter;
|
||||
|
||||
// Scales input texture coordinates for distortion: vec2 HmdWarp(vec2 fragTexCoord, vec2 LensCenter)
|
||||
vec2 theta = (fragTexCoord - LensCenter)*ScaleIn; // Scales to [-1, 1]
|
||||
float rSq = theta.x*theta.x + theta.y*theta.y;
|
||||
vec2 theta1 = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq);
|
||||
//vec2 tc = LensCenter + Scale*theta1;
|
||||
|
||||
// Detect whether blue texture coordinates are out of range since these will scaled out the furthest
|
||||
vec2 thetaBlue = theta1*(ChromaAbParam.z + ChromaAbParam.w*rSq);
|
||||
vec2 tcBlue = LensCenter + Scale*thetaBlue;
|
||||
|
||||
if (any(bvec2(clamp(tcBlue, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tcBlue))) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
else
|
||||
{
|
||||
// Do blue texture lookup
|
||||
float blue = texture2D(texture0, tcBlue).b;
|
||||
|
||||
// Do green lookup (no scaling)
|
||||
vec2 tcGreen = LensCenter + Scale*theta1;
|
||||
float green = texture2D(texture0, tcGreen).g;
|
||||
|
||||
// Do red scale and lookup
|
||||
vec2 thetaRed = theta1*(ChromaAbParam.x + ChromaAbParam.y*rSq);
|
||||
vec2 tcRed = LensCenter + Scale*thetaRed;
|
||||
float red = texture2D(texture0, tcRed).r;
|
||||
|
||||
gl_FragColor = vec4(red, green, blue, 1.0);
|
||||
}
|
||||
}
|
37
examples/shaders/resources/shaders/glsl100/dream_vision.fs
Normal file
37
examples/shaders/resources/shaders/glsl100/dream_vision.fs
Normal file
|
@ -0,0 +1,37 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(texture0, fragTexCoord);
|
||||
|
||||
color += texture2D(texture0, fragTexCoord + 0.001);
|
||||
color += texture2D(texture0, fragTexCoord + 0.003);
|
||||
color += texture2D(texture0, fragTexCoord + 0.005);
|
||||
color += texture2D(texture0, fragTexCoord + 0.007);
|
||||
color += texture2D(texture0, fragTexCoord + 0.009);
|
||||
color += texture2D(texture0, fragTexCoord + 0.011);
|
||||
|
||||
color += texture2D(texture0, fragTexCoord - 0.001);
|
||||
color += texture2D(texture0, fragTexCoord - 0.003);
|
||||
color += texture2D(texture0, fragTexCoord - 0.005);
|
||||
color += texture2D(texture0, fragTexCoord - 0.007);
|
||||
color += texture2D(texture0, fragTexCoord - 0.009);
|
||||
color += texture2D(texture0, fragTexCoord - 0.011);
|
||||
|
||||
color.rgb = vec3((color.r + color.g + color.b)/3.0);
|
||||
color = color/9.5;
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
58
examples/shaders/resources/shaders/glsl100/eratosthenes.fs
Normal file
58
examples/shaders/resources/shaders/glsl100/eratosthenes.fs
Normal file
|
@ -0,0 +1,58 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
/*************************************************************************************
|
||||
|
||||
The Sieve of Eratosthenes -- a simple shader by ProfJski
|
||||
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.
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
WARNING: If you make scale too large, your GPU may bog down!
|
||||
|
||||
***************************************************************************************/
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Make a nice spectrum of colors based on counter and maxSize
|
||||
vec4 Colorizer(float counter, float maxSize)
|
||||
{
|
||||
float red = 0.0, green = 0.0, blue = 0.0;
|
||||
float normsize = counter/maxSize;
|
||||
|
||||
red = smoothstep(0.3, 0.7, normsize);
|
||||
green = sin(3.14159*normsize);
|
||||
blue = 1.0 - smoothstep(0.0, 0.4, normsize);
|
||||
|
||||
return vec4(0.8*red, 0.8*green, 0.8*blue, 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = vec4(1.0);
|
||||
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
|
||||
|
||||
if ((value == 0) || (value == 1) || (value == 2)) gl_FragColor = vec4(1.0);
|
||||
else
|
||||
{
|
||||
for (int i = 2; (i < max(2, sqrt(value) + 1)); i++)
|
||||
{
|
||||
if ((value - i*floor(value/i)) == 0)
|
||||
{
|
||||
color = Colorizer(float(i), scale);
|
||||
//break; // Uncomment to color by the largest factor instead
|
||||
}
|
||||
}
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
}
|
43
examples/shaders/resources/shaders/glsl100/fisheye.fs
Normal file
43
examples/shaders/resources/shaders/glsl100/fisheye.fs
Normal file
|
@ -0,0 +1,43 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
const float PI = 3.1415926535;
|
||||
|
||||
void main()
|
||||
{
|
||||
float aperture = 178.0;
|
||||
float apertureHalf = 0.5 * aperture * (PI / 180.0);
|
||||
float maxFactor = sin(apertureHalf);
|
||||
|
||||
vec2 uv = vec2(0.0);
|
||||
vec2 xy = 2.0 * fragTexCoord.xy - 1.0;
|
||||
float d = length(xy);
|
||||
|
||||
if (d < (2.0 - maxFactor))
|
||||
{
|
||||
d = length(xy * maxFactor);
|
||||
float z = sqrt(1.0 - d * d);
|
||||
float r = atan(d, z) / PI;
|
||||
float phi = atan(xy.y, xy.x);
|
||||
|
||||
uv.x = r * cos(phi) + 0.5;
|
||||
uv.y = r * sin(phi) + 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
uv = fragTexCoord.xy;
|
||||
}
|
||||
|
||||
gl_FragColor = texture2D(texture0, uv);
|
||||
}
|
25
examples/shaders/resources/shaders/glsl100/grayscale.fs
Normal file
25
examples/shaders/resources/shaders/glsl100/grayscale.fs
Normal file
|
@ -0,0 +1,25 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord)*colDiffuse*fragColor;
|
||||
|
||||
// Convert texel color to grayscale using NTSC conversion weights
|
||||
float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114));
|
||||
|
||||
// Calculate final fragment color
|
||||
gl_FragColor = vec4(gray, gray, gray, texelColor.a);
|
||||
}
|
81
examples/shaders/resources/shaders/glsl100/julia_set.fs
Normal file
81
examples/shaders/resources/shaders/glsl100/julia_set.fs
Normal file
|
@ -0,0 +1,81 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
uniform vec2 screenDims; // Dimensions of the screen
|
||||
uniform vec2 c; // c.x = real, c.y = imaginary component. Equation done is z^2 + c
|
||||
uniform vec2 offset; // Offset of the scale.
|
||||
uniform float zoom; // Zoom of the scale.
|
||||
|
||||
const int MAX_ITERATIONS = 255; // Max iterations to do.
|
||||
|
||||
// Square a complex number
|
||||
vec2 ComplexSquare(vec2 z)
|
||||
{
|
||||
return vec2(
|
||||
z.x * z.x - z.y * z.y,
|
||||
z.x * z.y * 2.0
|
||||
);
|
||||
}
|
||||
|
||||
// Convert Hue Saturation Value (HSV) color into RGB
|
||||
vec3 Hsv2rgb(vec3 c)
|
||||
{
|
||||
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
/**********************************************************************************************
|
||||
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.
|
||||
|
||||
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).
|
||||
2^2 = 4, 4^2 = 8 and so on.
|
||||
So at 2 we stop 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)?
|
||||
That is what MAX_ITERATIONS is for.
|
||||
Then we can divide the iterations by the MAX_ITERATIONS value to get a normalized value 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.
|
||||
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
|
||||
// NOTE: fragTexCoord already comes as normalized screen coordinates but offset must be normalized before scaling and zoom
|
||||
vec2 z = vec2((fragTexCoord.x + offset.x/screenDims.x)*2.5/zoom, (fragTexCoord.y + offset.y/screenDims.y)*1.5/zoom);
|
||||
|
||||
int iterations = 0;
|
||||
for (iterations = 0; iterations < MAX_ITERATIONS; iterations++)
|
||||
{
|
||||
z = ComplexSquare(z) + c; // Iterate function
|
||||
|
||||
if (dot(z, z) > 4.0) break;
|
||||
}
|
||||
|
||||
// Another few iterations decreases errors in the smoothing calculation.
|
||||
// See http://linas.org/art-gallery/escape/escape.html for more information.
|
||||
z = ComplexSquare(z) + c;
|
||||
z = ComplexSquare(z) + c;
|
||||
|
||||
// This last part smooths the color (again see link above).
|
||||
float smoothVal = float(iterations) + 1.0 - (log(log(length(z)))/log(2.0));
|
||||
|
||||
// Normalize the value so it is between 0 and 1.
|
||||
float norm = smoothVal/float(MAX_ITERATIONS);
|
||||
|
||||
// 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);
|
||||
else gl_FragColor = vec4(Hsv2rgb(vec3(norm, 1.0, 1.0)), 1.0);
|
||||
}
|
29
examples/shaders/resources/shaders/glsl100/palette_switch.fs
Normal file
29
examples/shaders/resources/shaders/glsl100/palette_switch.fs
Normal file
|
@ -0,0 +1,29 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
const int colors = 8;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform ivec3 palette[colors];
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord) * fragColor;
|
||||
|
||||
// Convert the (normalized) texel color RED component (GB would work, too)
|
||||
// to the palette index by scaling up from [0, 1] to [0, 255].
|
||||
int index = int(texelColor.r * 255.0);
|
||||
ivec3 color = palette[index];
|
||||
|
||||
// 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]
|
||||
// for OpenGL to work.
|
||||
gl_FragColor = vec4(color / 255.0, texelColor.a);
|
||||
}
|
32
examples/shaders/resources/shaders/glsl100/pixelizer.fs
Normal file
32
examples/shaders/resources/shaders/glsl100/pixelizer.fs
Normal file
|
@ -0,0 +1,32 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
const float renderHeight = 450.0;
|
||||
|
||||
float pixelWidth = 5.0;
|
||||
float pixelHeight = 5.0;
|
||||
|
||||
void main()
|
||||
{
|
||||
float dx = pixelWidth*(1.0/renderWidth);
|
||||
float dy = pixelHeight*(1.0/renderHeight);
|
||||
|
||||
vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy));
|
||||
|
||||
vec3 tc = texture2D(texture0, coord).rgb;
|
||||
|
||||
gl_FragColor = vec4(tc, 1.0);
|
||||
}
|
29
examples/shaders/resources/shaders/glsl100/posterization.fs
Normal file
29
examples/shaders/resources/shaders/glsl100/posterization.fs
Normal file
|
@ -0,0 +1,29 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
float gamma = 0.6;
|
||||
float numColors = 8.0;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 color = texture2D(texture0, fragTexCoord.xy).rgb;
|
||||
|
||||
color = pow(color, vec3(gamma, gamma, gamma));
|
||||
color = color*numColors;
|
||||
color = floor(color);
|
||||
color = color/numColors;
|
||||
color = pow(color, vec3(1.0/gamma));
|
||||
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}
|
31
examples/shaders/resources/shaders/glsl100/predator.fs
Normal file
31
examples/shaders/resources/shaders/glsl100/predator.fs
Normal file
|
@ -0,0 +1,31 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 color = texture2D(texture0, fragTexCoord).rgb;
|
||||
vec3 colors[3];
|
||||
colors[0] = vec3(0.0, 0.0, 1.0);
|
||||
colors[1] = vec3(1.0, 1.0, 0.0);
|
||||
colors[2] = vec3(1.0, 0.0, 0.0);
|
||||
|
||||
float lum = (color.r + color.g + color.b)/3.0;
|
||||
|
||||
vec3 tc = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
if (lum < 0.5) tc = mix(colors[0], colors[1], lum/0.5);
|
||||
else tc = mix(colors[1], colors[2], (lum - 0.5)/0.5);
|
||||
|
||||
gl_FragColor = vec4(tc, 1.0);
|
||||
}
|
431
examples/shaders/resources/shaders/glsl100/raymarching.fs
Normal file
431
examples/shaders/resources/shaders/glsl100/raymarching.fs
Normal file
|
@ -0,0 +1,431 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
uniform vec3 viewEye;
|
||||
uniform vec3 viewCenter;
|
||||
uniform vec3 viewUp;
|
||||
uniform float deltaTime;
|
||||
uniform float runTime;
|
||||
uniform vec2 resolution;
|
||||
|
||||
// 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.
|
||||
|
||||
// A list of useful distance function to simple primitives, and an example on how to
|
||||
// do some interesting boolean operations, repetition and displacement.
|
||||
//
|
||||
// More info here: http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
||||
|
||||
#define AA 1 // make this 1 is your machine is too slow
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
float sdPlane( vec3 p )
|
||||
{
|
||||
return p.y;
|
||||
}
|
||||
|
||||
float sdSphere( vec3 p, float s )
|
||||
{
|
||||
return length(p)-s;
|
||||
}
|
||||
|
||||
float sdBox( vec3 p, vec3 b )
|
||||
{
|
||||
vec3 d = abs(p) - b;
|
||||
return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0));
|
||||
}
|
||||
|
||||
float sdEllipsoid( in vec3 p, in vec3 r )
|
||||
{
|
||||
return (length( p/r ) - 1.0) * min(min(r.x,r.y),r.z);
|
||||
}
|
||||
|
||||
float udRoundBox( vec3 p, vec3 b, float r )
|
||||
{
|
||||
return length(max(abs(p)-b,0.0))-r;
|
||||
}
|
||||
|
||||
float sdTorus( vec3 p, vec2 t )
|
||||
{
|
||||
return length( vec2(length(p.xz)-t.x,p.y) )-t.y;
|
||||
}
|
||||
|
||||
float sdHexPrism( vec3 p, vec2 h )
|
||||
{
|
||||
vec3 q = abs(p);
|
||||
#if 0
|
||||
return max(q.z-h.y,max((q.x*0.866025+q.y*0.5),q.y)-h.x);
|
||||
#else
|
||||
float d1 = q.z-h.y;
|
||||
float d2 = max((q.x*0.866025+q.y*0.5),q.y)-h.x;
|
||||
return length(max(vec2(d1,d2),0.0)) + min(max(d1,d2), 0.);
|
||||
#endif
|
||||
}
|
||||
|
||||
float sdCapsule( vec3 p, vec3 a, vec3 b, float r )
|
||||
{
|
||||
vec3 pa = p-a, ba = b-a;
|
||||
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
|
||||
return length( pa - ba*h ) - r;
|
||||
}
|
||||
|
||||
float sdEquilateralTriangle( in vec2 p )
|
||||
{
|
||||
const float k = sqrt(3.0);
|
||||
p.x = abs(p.x) - 1.0;
|
||||
p.y = p.y + 1.0/k;
|
||||
if( p.x + k*p.y > 0.0 ) p = vec2( p.x - k*p.y, -k*p.x - p.y )/2.0;
|
||||
p.x += 2.0 - 2.0*clamp( (p.x+2.0)/2.0, 0.0, 1.0 );
|
||||
return -length(p)*sign(p.y);
|
||||
}
|
||||
|
||||
float sdTriPrism( vec3 p, vec2 h )
|
||||
{
|
||||
vec3 q = abs(p);
|
||||
float d1 = q.z-h.y;
|
||||
#if 1
|
||||
// distance bound
|
||||
float d2 = max(q.x*0.866025+p.y*0.5,-p.y)-h.x*0.5;
|
||||
#else
|
||||
// correct distance
|
||||
h.x *= 0.866025;
|
||||
float d2 = sdEquilateralTriangle(p.xy/h.x)*h.x;
|
||||
#endif
|
||||
return length(max(vec2(d1,d2),0.0)) + min(max(d1,d2), 0.);
|
||||
}
|
||||
|
||||
float sdCylinder( vec3 p, vec2 h )
|
||||
{
|
||||
vec2 d = abs(vec2(length(p.xz),p.y)) - h;
|
||||
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
|
||||
}
|
||||
|
||||
float sdCone( in vec3 p, in vec3 c )
|
||||
{
|
||||
vec2 q = vec2( length(p.xz), p.y );
|
||||
float d1 = -q.y-c.z;
|
||||
float d2 = max( dot(q,c.xy), q.y);
|
||||
return length(max(vec2(d1,d2),0.0)) + min(max(d1,d2), 0.);
|
||||
}
|
||||
|
||||
float sdConeSection( in vec3 p, in float h, in float r1, in float r2 )
|
||||
{
|
||||
float d1 = -p.y - h;
|
||||
float q = p.y - h;
|
||||
float si = 0.5*(r1-r2)/h;
|
||||
float d2 = max( sqrt( dot(p.xz,p.xz)*(1.0-si*si)) + q*si - r2, q );
|
||||
return length(max(vec2(d1,d2),0.0)) + min(max(d1,d2), 0.);
|
||||
}
|
||||
|
||||
float sdPryamid4(vec3 p, vec3 h ) // h = { cos a, sin a, height }
|
||||
{
|
||||
// Tetrahedron = Octahedron - Cube
|
||||
float box = sdBox( p - vec3(0,-2.0*h.z,0), vec3(2.0*h.z) );
|
||||
|
||||
float d = 0.0;
|
||||
d = max( d, abs( dot(p, vec3( -h.x, h.y, 0 )) ));
|
||||
d = max( d, abs( dot(p, vec3( h.x, h.y, 0 )) ));
|
||||
d = max( d, abs( dot(p, vec3( 0, h.y, h.x )) ));
|
||||
d = max( d, abs( dot(p, vec3( 0, h.y,-h.x )) ));
|
||||
float octa = d - h.z;
|
||||
return max(-box,octa); // Subtraction
|
||||
}
|
||||
|
||||
float length2( vec2 p )
|
||||
{
|
||||
return sqrt( p.x*p.x + p.y*p.y );
|
||||
}
|
||||
|
||||
float length6( vec2 p )
|
||||
{
|
||||
p = p*p*p; p = p*p;
|
||||
return pow( p.x + p.y, 1.0/6.0 );
|
||||
}
|
||||
|
||||
float length8( vec2 p )
|
||||
{
|
||||
p = p*p; p = p*p; p = p*p;
|
||||
return pow( p.x + p.y, 1.0/8.0 );
|
||||
}
|
||||
|
||||
float sdTorus82( vec3 p, vec2 t )
|
||||
{
|
||||
vec2 q = vec2(length2(p.xz)-t.x,p.y);
|
||||
return length8(q)-t.y;
|
||||
}
|
||||
|
||||
float sdTorus88( vec3 p, vec2 t )
|
||||
{
|
||||
vec2 q = vec2(length8(p.xz)-t.x,p.y);
|
||||
return length8(q)-t.y;
|
||||
}
|
||||
|
||||
float sdCylinder6( vec3 p, vec2 h )
|
||||
{
|
||||
return max( length6(p.xz)-h.x, abs(p.y)-h.y );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
float opS( float d1, float d2 )
|
||||
{
|
||||
return max(-d2,d1);
|
||||
}
|
||||
|
||||
vec2 opU( vec2 d1, vec2 d2 )
|
||||
{
|
||||
return (d1.x<d2.x) ? d1 : d2;
|
||||
}
|
||||
|
||||
vec3 opRep( vec3 p, vec3 c )
|
||||
{
|
||||
return mod(p,c)-0.5*c;
|
||||
}
|
||||
|
||||
vec3 opTwist( vec3 p )
|
||||
{
|
||||
float c = cos(10.0*p.y+10.0);
|
||||
float s = sin(10.0*p.y+10.0);
|
||||
mat2 m = mat2(c,-s,s,c);
|
||||
return vec3(m*p.xz,p.y);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
vec2 map( in vec3 pos )
|
||||
{
|
||||
vec2 res = opU( vec2( sdPlane( pos), 1.0 ),
|
||||
vec2( sdSphere( pos-vec3( 0.0,0.25, 0.0), 0.25 ), 46.9 ) );
|
||||
res = opU( res, vec2( sdBox( pos-vec3( 1.0,0.25, 0.0), vec3(0.25) ), 3.0 ) );
|
||||
res = opU( res, vec2( udRoundBox( pos-vec3( 1.0,0.25, 1.0), vec3(0.15), 0.1 ), 41.0 ) );
|
||||
res = opU( res, vec2( sdTorus( pos-vec3( 0.0,0.25, 1.0), vec2(0.20,0.05) ), 25.0 ) );
|
||||
res = opU( res, vec2( sdCapsule( pos,vec3(-1.3,0.10,-0.1), vec3(-0.8,0.50,0.2), 0.1 ), 31.9 ) );
|
||||
res = opU( res, vec2( sdTriPrism( pos-vec3(-1.0,0.25,-1.0), vec2(0.25,0.05) ),43.5 ) );
|
||||
res = opU( res, vec2( sdCylinder( pos-vec3( 1.0,0.30,-1.0), vec2(0.1,0.2) ), 8.0 ) );
|
||||
res = opU( res, vec2( sdCone( pos-vec3( 0.0,0.50,-1.0), vec3(0.8,0.6,0.3) ), 55.0 ) );
|
||||
res = opU( res, vec2( sdTorus82( pos-vec3( 0.0,0.25, 2.0), vec2(0.20,0.05) ),50.0 ) );
|
||||
res = opU( res, vec2( sdTorus88( pos-vec3(-1.0,0.25, 2.0), vec2(0.20,0.05) ),43.0 ) );
|
||||
res = opU( res, vec2( sdCylinder6( pos-vec3( 1.0,0.30, 2.0), vec2(0.1,0.2) ), 12.0 ) );
|
||||
res = opU( res, vec2( sdHexPrism( pos-vec3(-1.0,0.20, 1.0), vec2(0.25,0.05) ),17.0 ) );
|
||||
res = opU( res, vec2( sdPryamid4( pos-vec3(-1.0,0.15,-2.0), vec3(0.8,0.6,0.25) ),37.0 ) );
|
||||
res = opU( res, vec2( opS( udRoundBox( pos-vec3(-2.0,0.2, 1.0), vec3(0.15),0.05),
|
||||
sdSphere( pos-vec3(-2.0,0.2, 1.0), 0.25)), 13.0 ) );
|
||||
res = opU( res, vec2( opS( sdTorus82( pos-vec3(-2.0,0.2, 0.0), vec2(0.20,0.1)),
|
||||
sdCylinder( opRep( vec3(atan(pos.x+2.0,pos.z)/6.2831, pos.y, 0.02+0.5*length(pos-vec3(-2.0,0.2, 0.0))), vec3(0.05,1.0,0.05)), vec2(0.02,0.6))), 51.0 ) );
|
||||
res = opU( res, vec2( 0.5*sdSphere( pos-vec3(-2.0,0.25,-1.0), 0.2 ) + 0.03*sin(50.0*pos.x)*sin(50.0*pos.y)*sin(50.0*pos.z), 65.0 ) );
|
||||
res = opU( res, vec2( 0.5*sdTorus( opTwist(pos-vec3(-2.0,0.25, 2.0)),vec2(0.20,0.05)), 46.7 ) );
|
||||
res = opU( res, vec2( sdConeSection( pos-vec3( 0.0,0.35,-2.0), 0.15, 0.2, 0.1 ), 13.67 ) );
|
||||
res = opU( res, vec2( sdEllipsoid( pos-vec3( 1.0,0.35,-2.0), vec3(0.15, 0.2, 0.05) ), 43.17 ) );
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
vec2 castRay( in vec3 ro, in vec3 rd )
|
||||
{
|
||||
float tmin = 0.2;
|
||||
float tmax = 30.0;
|
||||
|
||||
#if 1
|
||||
// bounding volume
|
||||
float tp1 = (0.0-ro.y)/rd.y; if( tp1>0.0 ) tmax = min( tmax, tp1 );
|
||||
float tp2 = (1.6-ro.y)/rd.y; if( tp2>0.0 ) { if( ro.y>1.6 ) tmin = max( tmin, tp2 );
|
||||
else tmax = min( tmax, tp2 ); }
|
||||
#endif
|
||||
|
||||
float t = tmin;
|
||||
float m = -1.0;
|
||||
for( int i=0; i<64; i++ )
|
||||
{
|
||||
float precis = 0.0005*t;
|
||||
vec2 res = map( ro+rd*t );
|
||||
if( res.x<precis || t>tmax ) break;
|
||||
t += res.x;
|
||||
m = res.y;
|
||||
}
|
||||
|
||||
if( t>tmax ) m=-1.0;
|
||||
return vec2( t, m );
|
||||
}
|
||||
|
||||
|
||||
float calcSoftshadow( in vec3 ro, in vec3 rd, in float mint, in float tmax )
|
||||
{
|
||||
float res = 1.0;
|
||||
float t = mint;
|
||||
for( int i=0; i<16; i++ )
|
||||
{
|
||||
float h = map( ro + rd*t ).x;
|
||||
res = min( res, 8.0*h/t );
|
||||
t += clamp( h, 0.02, 0.10 );
|
||||
if( h<0.001 || t>tmax ) break;
|
||||
}
|
||||
return clamp( res, 0.0, 1.0 );
|
||||
}
|
||||
|
||||
vec3 calcNormal( in vec3 pos )
|
||||
{
|
||||
vec2 e = vec2(1.0,-1.0)*0.5773*0.0005;
|
||||
return normalize( e.xyy*map( pos + e.xyy ).x +
|
||||
e.yyx*map( pos + e.yyx ).x +
|
||||
e.yxy*map( pos + e.yxy ).x +
|
||||
e.xxx*map( pos + e.xxx ).x );
|
||||
/*
|
||||
vec3 eps = vec3( 0.0005, 0.0, 0.0 );
|
||||
vec3 nor = vec3(
|
||||
map(pos+eps.xyy).x - map(pos-eps.xyy).x,
|
||||
map(pos+eps.yxy).x - map(pos-eps.yxy).x,
|
||||
map(pos+eps.yyx).x - map(pos-eps.yyx).x );
|
||||
return normalize(nor);
|
||||
*/
|
||||
}
|
||||
|
||||
float calcAO( in vec3 pos, in vec3 nor )
|
||||
{
|
||||
float occ = 0.0;
|
||||
float sca = 1.0;
|
||||
for( int i=0; i<5; i++ )
|
||||
{
|
||||
float hr = 0.01 + 0.12*float(i)/4.0;
|
||||
vec3 aopos = nor * hr + pos;
|
||||
float dd = map( aopos ).x;
|
||||
occ += -(dd-hr)*sca;
|
||||
sca *= 0.95;
|
||||
}
|
||||
return clamp( 1.0 - 3.0*occ, 0.0, 1.0 );
|
||||
}
|
||||
|
||||
// http://iquilezles.org/www/articles/checkerfiltering/checkerfiltering.htm
|
||||
float checkersGradBox( in vec2 p )
|
||||
{
|
||||
// filter kernel
|
||||
vec2 w = fwidth(p) + 0.001;
|
||||
// analytical integral (box filter)
|
||||
vec2 i = 2.0*(abs(fract((p-0.5*w)*0.5)-0.5)-abs(fract((p+0.5*w)*0.5)-0.5))/w;
|
||||
// xor pattern
|
||||
return 0.5 - 0.5*i.x*i.y;
|
||||
}
|
||||
|
||||
vec3 render( in vec3 ro, in vec3 rd )
|
||||
{
|
||||
vec3 col = vec3(0.7, 0.9, 1.0) +rd.y*0.8;
|
||||
vec2 res = castRay(ro,rd);
|
||||
float t = res.x;
|
||||
float m = res.y;
|
||||
if( m>-0.5 )
|
||||
{
|
||||
vec3 pos = ro + t*rd;
|
||||
vec3 nor = calcNormal( pos );
|
||||
vec3 ref = reflect( rd, nor );
|
||||
|
||||
// material
|
||||
col = 0.45 + 0.35*sin( vec3(0.05,0.08,0.10)*(m-1.0) );
|
||||
if( m<1.5 )
|
||||
{
|
||||
|
||||
float f = checkersGradBox( 5.0*pos.xz );
|
||||
col = 0.3 + f*vec3(0.1);
|
||||
}
|
||||
|
||||
// lighting
|
||||
float occ = calcAO( pos, nor );
|
||||
vec3 lig = normalize( vec3(cos(-0.4 * runTime), sin(0.7 * runTime), -0.6) );
|
||||
vec3 hal = normalize( lig-rd );
|
||||
float amb = clamp( 0.5+0.5*nor.y, 0.0, 1.0 );
|
||||
float dif = clamp( dot( nor, lig ), 0.0, 1.0 );
|
||||
float bac = clamp( dot( nor, normalize(vec3(-lig.x,0.0,-lig.z))), 0.0, 1.0 )*clamp( 1.0-pos.y,0.0,1.0);
|
||||
float dom = smoothstep( -0.1, 0.1, ref.y );
|
||||
float fre = pow( clamp(1.0+dot(nor,rd),0.0,1.0), 2.0 );
|
||||
|
||||
dif *= calcSoftshadow( pos, lig, 0.02, 2.5 );
|
||||
dom *= calcSoftshadow( pos, ref, 0.02, 2.5 );
|
||||
|
||||
float spe = pow( clamp( dot( nor, hal ), 0.0, 1.0 ),16.0)*
|
||||
dif *
|
||||
(0.04 + 0.96*pow( clamp(1.0+dot(hal,rd),0.0,1.0), 5.0 ));
|
||||
|
||||
vec3 lin = vec3(0.0);
|
||||
lin += 1.30*dif*vec3(1.00,0.80,0.55);
|
||||
lin += 0.40*amb*vec3(0.40,0.60,1.00)*occ;
|
||||
lin += 0.50*dom*vec3(0.40,0.60,1.00)*occ;
|
||||
lin += 0.50*bac*vec3(0.25,0.25,0.25)*occ;
|
||||
lin += 0.25*fre*vec3(1.00,1.00,1.00)*occ;
|
||||
col = col*lin;
|
||||
col += 10.00*spe*vec3(1.00,0.90,0.70);
|
||||
|
||||
col = mix( col, vec3(0.8,0.9,1.0), 1.0-exp( -0.0002*t*t*t ) );
|
||||
}
|
||||
|
||||
return vec3( clamp(col,0.0,1.0) );
|
||||
}
|
||||
|
||||
mat3 setCamera( in vec3 ro, in vec3 ta, float cr )
|
||||
{
|
||||
vec3 cw = normalize(ta-ro);
|
||||
vec3 cp = vec3(sin(cr), cos(cr),0.0);
|
||||
vec3 cu = normalize( cross(cw,cp) );
|
||||
vec3 cv = normalize( cross(cu,cw) );
|
||||
return mat3( cu, cv, cw );
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 tot = vec3(0.0);
|
||||
#if AA>1
|
||||
for( int m=0; m<AA; m++ )
|
||||
for( int n=0; n<AA; n++ )
|
||||
{
|
||||
// pixel coordinates
|
||||
vec2 o = vec2(float(m),float(n)) / float(AA) - 0.5;
|
||||
vec2 p = (-resolution.xy + 2.0*(gl_FragCoord.xy+o))/resolution.y;
|
||||
#else
|
||||
vec2 p = (-resolution.xy + 2.0*gl_FragCoord.xy)/resolution.y;
|
||||
#endif
|
||||
|
||||
// RAY: Camera is provided from raylib
|
||||
//vec3 ro = vec3( -0.5+3.5*cos(0.1*time + 6.0*mo.x), 1.0 + 2.0*mo.y, 0.5 + 4.0*sin(0.1*time + 6.0*mo.x) );
|
||||
|
||||
vec3 ro = viewEye;
|
||||
vec3 ta = viewCenter;
|
||||
|
||||
// camera-to-world transformation
|
||||
mat3 ca = setCamera( ro, ta, 0.0 );
|
||||
// ray direction
|
||||
vec3 rd = ca * normalize( vec3(p.xy,2.0) );
|
||||
|
||||
// render
|
||||
vec3 col = render( ro, rd );
|
||||
|
||||
// gamma
|
||||
col = pow( col, vec3(0.4545) );
|
||||
|
||||
tot += col;
|
||||
#if AA>1
|
||||
}
|
||||
tot /= float(AA*AA);
|
||||
#endif
|
||||
|
||||
gl_FragColor = vec4( tot, 1.0 );
|
||||
}
|
44
examples/shaders/resources/shaders/glsl100/scanlines.fs
Normal file
44
examples/shaders/resources/shaders/glsl100/scanlines.fs
Normal file
|
@ -0,0 +1,44 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
float offset = 0.0;
|
||||
float frequency = 450.0/3.0;
|
||||
|
||||
uniform float time;
|
||||
|
||||
void main()
|
||||
{
|
||||
/*
|
||||
// Scanlines method 1
|
||||
float tval = 0; //time
|
||||
vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval));
|
||||
|
||||
vec4 color = texture2D(texture0, fragTexCoord);
|
||||
|
||||
color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0);
|
||||
color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y);
|
||||
color *= vec4(0.8, 1.0, 0.7, 1);
|
||||
color *= 0.9 + 0.1*sin(10.0*tval + uv.y*1000.0);
|
||||
color *= 0.97 + 0.03*sin(110.0*tval);
|
||||
|
||||
fragColor = color;
|
||||
*/
|
||||
// Scanlines method 2
|
||||
float globalPos = (fragTexCoord.y + offset) * frequency;
|
||||
float wavePos = cos((fract(globalPos) - 0.5)*3.14);
|
||||
|
||||
vec4 color = texture2D(texture0, fragTexCoord);
|
||||
|
||||
gl_FragColor = mix(vec4(0.0, 0.3, 0.0, 0.0), color, wavePos);
|
||||
}
|
40
examples/shaders/resources/shaders/glsl100/sobel.fs
Normal file
40
examples/shaders/resources/shaders/glsl100/sobel.fs
Normal file
|
@ -0,0 +1,40 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
vec2 resolution = vec2(800.0, 450.0);
|
||||
|
||||
void main()
|
||||
{
|
||||
float x = 1.0/resolution.x;
|
||||
float y = 1.0/resolution.y;
|
||||
|
||||
vec4 horizEdge = vec4(0.0);
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
|
||||
vec4 vertEdge = vec4(0.0);
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
|
||||
vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb));
|
||||
|
||||
gl_FragColor = vec4(edge, texture2D(texture0, fragTexCoord).a);
|
||||
}
|
46
examples/shaders/resources/shaders/glsl100/swirl.fs
Normal file
46
examples/shaders/resources/shaders/glsl100/swirl.fs
Normal file
|
@ -0,0 +1,46 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
// NOTE: Render size values should be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
const float renderHeight = 450.0;
|
||||
|
||||
float radius = 250.0;
|
||||
float angle = 0.8;
|
||||
|
||||
uniform vec2 center;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texSize = vec2(renderWidth, renderHeight);
|
||||
vec2 tc = fragTexCoord*texSize;
|
||||
tc -= center;
|
||||
|
||||
float dist = length(tc);
|
||||
|
||||
if (dist < radius)
|
||||
{
|
||||
float percent = (radius - dist)/radius;
|
||||
float theta = percent*percent*angle*8.0;
|
||||
float s = sin(theta);
|
||||
float c = cos(theta);
|
||||
|
||||
tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c)));
|
||||
}
|
||||
|
||||
tc += center;
|
||||
vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
|
||||
|
||||
gl_FragColor = vec4(color.rgb, 1.0);;
|
||||
}
|
36
examples/shaders/resources/shaders/glsl100/wave.fs
Normal file
36
examples/shaders/resources/shaders/glsl100/wave.fs
Normal file
|
@ -0,0 +1,36 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
uniform float secondes;
|
||||
|
||||
uniform vec2 size;
|
||||
|
||||
uniform float freqX;
|
||||
uniform float freqY;
|
||||
uniform float ampX;
|
||||
uniform float ampY;
|
||||
uniform float speedX;
|
||||
uniform float speedY;
|
||||
|
||||
void main() {
|
||||
float pixelWidth = 1.0 / size.x;
|
||||
float pixelHeight = 1.0 / size.y;
|
||||
float aspect = pixelHeight / pixelWidth;
|
||||
float boxLeft = 0.0;
|
||||
float boxTop = 0.0;
|
||||
|
||||
vec2 p = fragTexCoord;
|
||||
p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth;
|
||||
p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight;
|
||||
|
||||
gl_FragColor = texture2D(texture0, p)*colDiffuse*fragColor;
|
||||
}
|
22
examples/shaders/resources/shaders/glsl120/base.fs
Normal file
22
examples/shaders/resources/shaders/glsl120/base.fs
Normal file
|
@ -0,0 +1,22 @@
|
|||
#version 120
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
uniform vec2 resolution = vec2(800, 450);
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||
|
||||
// NOTE: Implement here your fragment shader code
|
||||
|
||||
gl_FragColor = texelColor*colDiffuse;
|
||||
}
|
26
examples/shaders/resources/shaders/glsl120/base.vs
Normal file
26
examples/shaders/resources/shaders/glsl120/base.vs
Normal file
|
@ -0,0 +1,26 @@
|
|||
#version 120
|
||||
|
||||
// Input vertex attributes
|
||||
attribute vec3 vertexPosition;
|
||||
attribute vec2 vertexTexCoord;
|
||||
attribute vec3 vertexNormal;
|
||||
attribute vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
// Send vertex attributes to fragment shader
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||
}
|
37
examples/shaders/resources/shaders/glsl120/bloom.fs
Normal file
37
examples/shaders/resources/shaders/glsl120/bloom.fs
Normal file
|
@ -0,0 +1,37 @@
|
|||
#version 120
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
const vec2 size = vec2(800, 450); // render size
|
||||
const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance
|
||||
const float quality = 2.5; // lower = smaller glow, better quality
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 sum = vec4(0);
|
||||
vec2 sizeFactor = vec2(1)/size*quality;
|
||||
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 source = texture2D(texture0, fragTexCoord);
|
||||
|
||||
const int range = 2; // should be = (samples - 1)/2;
|
||||
|
||||
for (int x = -range; x <= range; x++)
|
||||
{
|
||||
for (int y = -range; y <= range; y++)
|
||||
{
|
||||
sum += texture2D(texture0, fragTexCoord + vec2(x, y)*sizeFactor);
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate final fragment color
|
||||
gl_FragColor = ((sum/(samples*samples)) + source)*colDiffuse;
|
||||
}
|
32
examples/shaders/resources/shaders/glsl120/blur.fs
Normal file
32
examples/shaders/resources/shaders/glsl120/blur.fs
Normal file
|
@ -0,0 +1,32 @@
|
|||
#version 120
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
const float renderHeight = 450.0;
|
||||
|
||||
vec3 offset = vec3(0.0, 1.3846153846, 3.2307692308);
|
||||
vec3 weight = vec3(0.2270270270, 0.3162162162, 0.0702702703);
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec3 tc = texture2D(texture0, fragTexCoord).rgb*weight.x;
|
||||
|
||||
tc += texture2D(texture0, fragTexCoord + vec2(offset.y)/renderWidth, 0.0).rgb*weight.y;
|
||||
tc += texture2D(texture0, fragTexCoord - vec2(offset.y)/renderWidth, 0.0).rgb*weight.y;
|
||||
|
||||
tc += texture2D(texture0, fragTexCoord + vec2(offset.z)/renderWidth, 0.0).rgb*weight.z;
|
||||
tc += texture2D(texture0, fragTexCoord - vec2(offset.z)/renderWidth, 0.0).rgb*weight.z;
|
||||
|
||||
gl_FragColor = vec4(tc, 1.0);
|
||||
}
|
45
examples/shaders/resources/shaders/glsl120/cross_hatching.fs
Normal file
45
examples/shaders/resources/shaders/glsl120/cross_hatching.fs
Normal file
|
@ -0,0 +1,45 @@
|
|||
# version 120
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
float hatchOffsetY = 5.0;
|
||||
float lumThreshold01 = 0.9;
|
||||
float lumThreshold02 = 0.7;
|
||||
float lumThreshold03 = 0.5;
|
||||
float lumThreshold04 = 0.3;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 tc = vec3(1.0, 1.0, 1.0);
|
||||
float lum = length(texture2D(texture0, fragTexCoord).rgb);
|
||||
|
||||
if (lum < lumThreshold01)
|
||||
{
|
||||
if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
if (lum < lumThreshold02)
|
||||
{
|
||||
if (mod(gl_FragCoord .x - gl_FragCoord .y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
if (lum < lumThreshold03)
|
||||
{
|
||||
if (mod(gl_FragCoord .x + gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
if (lum < lumThreshold04)
|
||||
{
|
||||
if (mod(gl_FragCoord .x - gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
gl_FragColor = vec4(tc, 1.0);
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
# version 120
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
const float renderHeight = 450.0;
|
||||
|
||||
float stitchingSize = 6.0;
|
||||
int invert = 0;
|
||||
|
||||
vec4 PostFX(sampler2D tex, vec2 uv)
|
||||
{
|
||||
vec4 c = vec4(0.0);
|
||||
float size = stitchingSize;
|
||||
vec2 cPos = uv * vec2(renderWidth, renderHeight);
|
||||
vec2 tlPos = floor(cPos / vec2(size, size));
|
||||
tlPos *= size;
|
||||
|
||||
int remX = int(mod(cPos.x, size));
|
||||
int remY = int(mod(cPos.y, size));
|
||||
|
||||
if (remX == 0 && remY == 0) tlPos = cPos;
|
||||
|
||||
vec2 blPos = tlPos;
|
||||
blPos.y += (size - 1.0);
|
||||
|
||||
if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y)))))
|
||||
{
|
||||
if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0);
|
||||
else c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (invert == 1) c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
|
||||
else c = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 tc = PostFX(texture0, fragTexCoord).rgb;
|
||||
|
||||
gl_FragColor = vec4(tc, 1.0);
|
||||
}
|
52
examples/shaders/resources/shaders/glsl120/distortion.fs
Normal file
52
examples/shaders/resources/shaders/glsl120/distortion.fs
Normal file
|
@ -0,0 +1,52 @@
|
|||
#version 120
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
|
||||
// NOTE: Default parameters for Oculus Rift DK2 device
|
||||
const vec2 LeftLensCenter = vec2(0.2863248, 0.5);
|
||||
const vec2 RightLensCenter = vec2(0.7136753, 0.5);
|
||||
const vec2 LeftScreenCenter = vec2(0.25, 0.5);
|
||||
const vec2 RightScreenCenter = vec2(0.75, 0.5);
|
||||
const vec2 Scale = vec2(0.25, 0.45);
|
||||
const vec2 ScaleIn = vec2(4.0, 2.5);
|
||||
const vec4 HmdWarpParam = vec4(1.0, 0.22, 0.24, 0.0);
|
||||
const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.0);
|
||||
|
||||
void main()
|
||||
{
|
||||
// The following two variables need to be set per eye
|
||||
vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter;
|
||||
vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter;
|
||||
|
||||
// Scales input texture coordinates for distortion: vec2 HmdWarp(vec2 fragTexCoord, vec2 LensCenter)
|
||||
vec2 theta = (fragTexCoord - LensCenter)*ScaleIn; // Scales to [-1, 1]
|
||||
float rSq = theta.x*theta.x + theta.y*theta.y;
|
||||
vec2 theta1 = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq);
|
||||
//vec2 tc = LensCenter + Scale*theta1;
|
||||
|
||||
// Detect whether blue texture coordinates are out of range since these will scaled out the furthest
|
||||
vec2 thetaBlue = theta1*(ChromaAbParam.z + ChromaAbParam.w*rSq);
|
||||
vec2 tcBlue = LensCenter + Scale*thetaBlue;
|
||||
|
||||
if (any(bvec2(clamp(tcBlue, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tcBlue))) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
else
|
||||
{
|
||||
// Do blue texture lookup
|
||||
float blue = texture2D(texture0, tcBlue).b;
|
||||
|
||||
// Do green lookup (no scaling)
|
||||
vec2 tcGreen = LensCenter + Scale*theta1;
|
||||
float green = texture2D(texture0, tcGreen).g;
|
||||
|
||||
// Do red scale and lookup
|
||||
vec2 thetaRed = theta1*(ChromaAbParam.x + ChromaAbParam.y*rSq);
|
||||
vec2 tcRed = LensCenter + Scale*thetaRed;
|
||||
float red = texture2D(texture0, tcRed).r;
|
||||
|
||||
gl_FragColor = vec4(red, green, blue, 1.0);
|
||||
}
|
||||
}
|
35
examples/shaders/resources/shaders/glsl120/dream_vision.fs
Normal file
35
examples/shaders/resources/shaders/glsl120/dream_vision.fs
Normal file
|
@ -0,0 +1,35 @@
|
|||
#version 120
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(texture0, fragTexCoord);
|
||||
|
||||
color += texture2D(texture0, fragTexCoord + 0.001);
|
||||
color += texture2D(texture0, fragTexCoord + 0.003);
|
||||
color += texture2D(texture0, fragTexCoord + 0.005);
|
||||
color += texture2D(texture0, fragTexCoord + 0.007);
|
||||
color += texture2D(texture0, fragTexCoord + 0.009);
|
||||
color += texture2D(texture0, fragTexCoord + 0.011);
|
||||
|
||||
color += texture2D(texture0, fragTexCoord - 0.001);
|
||||
color += texture2D(texture0, fragTexCoord - 0.003);
|
||||
color += texture2D(texture0, fragTexCoord - 0.005);
|
||||
color += texture2D(texture0, fragTexCoord - 0.007);
|
||||
color += texture2D(texture0, fragTexCoord - 0.009);
|
||||
color += texture2D(texture0, fragTexCoord - 0.011);
|
||||
|
||||
color.rgb = vec3((color.r + color.g + color.b)/3.0);
|
||||
color = color/9.5;
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
41
examples/shaders/resources/shaders/glsl120/fisheye.fs
Normal file
41
examples/shaders/resources/shaders/glsl120/fisheye.fs
Normal file
|
@ -0,0 +1,41 @@
|
|||
#version 120
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
const float PI = 3.1415926535;
|
||||
|
||||
void main()
|
||||
{
|
||||
float aperture = 178.0;
|
||||
float apertureHalf = 0.5 * aperture * (PI / 180.0);
|
||||
float maxFactor = sin(apertureHalf);
|
||||
|
||||
vec2 uv = vec2(0.0);
|
||||
vec2 xy = 2.0 * fragTexCoord.xy - 1.0;
|
||||
float d = length(xy);
|
||||
|
||||
if (d < (2.0 - maxFactor))
|
||||
{
|
||||
d = length(xy * maxFactor);
|
||||
float z = sqrt(1.0 - d * d);
|
||||
float r = atan(d, z) / PI;
|
||||
float phi = atan(xy.y, xy.x);
|
||||
|
||||
uv.x = r * cos(phi) + 0.5;
|
||||
uv.y = r * sin(phi) + 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
uv = fragTexCoord.xy;
|
||||
}
|
||||
|
||||
gl_FragColor = texture2D(texture0, uv);
|
||||
}
|
23
examples/shaders/resources/shaders/glsl120/grayscale.fs
Normal file
23
examples/shaders/resources/shaders/glsl120/grayscale.fs
Normal file
|
@ -0,0 +1,23 @@
|
|||
#version 120
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord)*colDiffuse*fragColor;
|
||||
|
||||
// Convert texel color to grayscale using NTSC conversion weights
|
||||
float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114));
|
||||
|
||||
// Calculate final fragment color
|
||||
gl_FragColor = vec4(gray, gray, gray, texelColor.a);
|
||||
}
|
27
examples/shaders/resources/shaders/glsl120/palette_switch.fs
Normal file
27
examples/shaders/resources/shaders/glsl120/palette_switch.fs
Normal file
|
@ -0,0 +1,27 @@
|
|||
#version 120
|
||||
|
||||
const int colors = 8;
|
||||
|
||||
// Input fragment attributes (from fragment shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform ivec3 palette[colors];
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture(texture0, fragTexCoord) * fragColor;
|
||||
|
||||
// Convert the (normalized) texel color RED component (GB would work, too)
|
||||
// to the palette index by scaling up from [0, 1] to [0, 255].
|
||||
int index = int(texelColor.r * 255.0);
|
||||
ivec3 color = palette[index];
|
||||
|
||||
// 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]
|
||||
// for OpenGL to work.
|
||||
gl_FragColor = vec4(color / 255.0, texelColor.a);
|
||||
}
|
30
examples/shaders/resources/shaders/glsl120/pixelizer.fs
Normal file
30
examples/shaders/resources/shaders/glsl120/pixelizer.fs
Normal file
|
@ -0,0 +1,30 @@
|
|||
#version 120
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
const float renderHeight = 450.0;
|
||||
|
||||
float pixelWidth = 5.0;
|
||||
float pixelHeight = 5.0;
|
||||
|
||||
void main()
|
||||
{
|
||||
float dx = pixelWidth*(1.0/renderWidth);
|
||||
float dy = pixelHeight*(1.0/renderHeight);
|
||||
|
||||
vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy));
|
||||
|
||||
vec3 tc = texture2D(texture0, coord).rgb;
|
||||
|
||||
gl_FragColor = vec4(tc, 1.0);
|
||||
}
|
27
examples/shaders/resources/shaders/glsl120/posterization.fs
Normal file
27
examples/shaders/resources/shaders/glsl120/posterization.fs
Normal file
|
@ -0,0 +1,27 @@
|
|||
#version 120
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
float gamma = 0.6;
|
||||
float numColors = 8.0;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 color = texture2D(texture0, fragTexCoord.xy).rgb;
|
||||
|
||||
color = pow(color, vec3(gamma, gamma, gamma));
|
||||
color = color*numColors;
|
||||
color = floor(color);
|
||||
color = color/numColors;
|
||||
color = pow(color, vec3(1.0/gamma));
|
||||
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}
|
29
examples/shaders/resources/shaders/glsl120/predator.fs
Normal file
29
examples/shaders/resources/shaders/glsl120/predator.fs
Normal file
|
@ -0,0 +1,29 @@
|
|||
#version 120
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 color = texture2D(texture0, fragTexCoord).rgb;
|
||||
vec3 colors[3];
|
||||
colors[0] = vec3(0.0, 0.0, 1.0);
|
||||
colors[1] = vec3(1.0, 1.0, 0.0);
|
||||
colors[2] = vec3(1.0, 0.0, 0.0);
|
||||
|
||||
float lum = (color.r + color.g + color.b)/3.0;
|
||||
|
||||
vec3 tc = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
if (lum < 0.5) tc = mix(colors[0], colors[1], lum/0.5);
|
||||
else tc = mix(colors[1], colors[2], (lum - 0.5)/0.5);
|
||||
|
||||
gl_FragColor = vec4(tc, 1.0);
|
||||
}
|
42
examples/shaders/resources/shaders/glsl120/scanlines.fs
Normal file
42
examples/shaders/resources/shaders/glsl120/scanlines.fs
Normal file
|
@ -0,0 +1,42 @@
|
|||
#version 120
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
float offset = 0.0;
|
||||
float frequency = 450.0/3.0;
|
||||
|
||||
uniform float time;
|
||||
|
||||
void main()
|
||||
{
|
||||
/*
|
||||
// Scanlines method 1
|
||||
float tval = 0; //time
|
||||
vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval));
|
||||
|
||||
vec4 color = texture2D(texture0, fragTexCoord);
|
||||
|
||||
color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0);
|
||||
color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y);
|
||||
color *= vec4(0.8, 1.0, 0.7, 1);
|
||||
color *= 0.9 + 0.1*sin(10.0*tval + uv.y*1000.0);
|
||||
color *= 0.97 + 0.03*sin(110.0*tval);
|
||||
|
||||
fragColor = color;
|
||||
*/
|
||||
// Scanlines method 2
|
||||
float globalPos = (fragTexCoord.y + offset) * frequency;
|
||||
float wavePos = cos((fract(globalPos) - 0.5)*3.14);
|
||||
|
||||
vec4 color = texture2D(texture0, fragTexCoord);
|
||||
|
||||
gl_FragColor = mix(vec4(0.0, 0.3, 0.0, 0.0), color, wavePos);
|
||||
}
|
38
examples/shaders/resources/shaders/glsl120/sobel.fs
Normal file
38
examples/shaders/resources/shaders/glsl120/sobel.fs
Normal file
|
@ -0,0 +1,38 @@
|
|||
#version 120
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
vec2 resolution = vec2(800.0, 450.0);
|
||||
|
||||
void main()
|
||||
{
|
||||
float x = 1.0/resolution.x;
|
||||
float y = 1.0/resolution.y;
|
||||
|
||||
vec4 horizEdge = vec4(0.0);
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
|
||||
vec4 vertEdge = vec4(0.0);
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
|
||||
vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb));
|
||||
|
||||
gl_FragColor = vec4(edge, texture2D(texture0, fragTexCoord).a);
|
||||
}
|
44
examples/shaders/resources/shaders/glsl120/swirl.fs
Normal file
44
examples/shaders/resources/shaders/glsl120/swirl.fs
Normal file
|
@ -0,0 +1,44 @@
|
|||
#version 120
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
// NOTE: Render size values should be passed from code
|
||||
const float renderWidth = 800;
|
||||
const float renderHeight = 450;
|
||||
|
||||
float radius = 250.0;
|
||||
float angle = 0.8;
|
||||
|
||||
uniform vec2 center;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texSize = vec2(renderWidth, renderHeight);
|
||||
vec2 tc = fragTexCoord*texSize;
|
||||
tc -= center;
|
||||
|
||||
float dist = length(tc);
|
||||
|
||||
if (dist < radius)
|
||||
{
|
||||
float percent = (radius - dist)/radius;
|
||||
float theta = percent*percent*angle*8.0;
|
||||
float s = sin(theta);
|
||||
float c = cos(theta);
|
||||
|
||||
tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c)));
|
||||
}
|
||||
|
||||
tc += center;
|
||||
vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
|
||||
|
||||
gl_FragColor = vec4(color.rgb, 1.0);;
|
||||
}
|
25
examples/shaders/resources/shaders/glsl330/base.fs
Normal file
25
examples/shaders/resources/shaders/glsl330/base.fs
Normal file
|
@ -0,0 +1,25 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
|
||||
// NOTE: Implement here your fragment shader code
|
||||
|
||||
finalColor = texelColor*colDiffuse;
|
||||
}
|
||||
|
26
examples/shaders/resources/shaders/glsl330/base.vs
Normal file
26
examples/shaders/resources/shaders/glsl330/base.vs
Normal file
|
@ -0,0 +1,26 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
in vec3 vertexNormal;
|
||||
in vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
out vec2 fragTexCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
// Send vertex attributes to fragment shader
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||
}
|
82
examples/shaders/resources/shaders/glsl330/basic_lighting.fs
Normal file
82
examples/shaders/resources/shaders/glsl330/basic_lighting.fs
Normal file
|
@ -0,0 +1,82 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec3 fragPosition;
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
in vec3 fragNormal;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
#define LIGHT_DIRECTIONAL 0
|
||||
#define LIGHT_POINT 1
|
||||
|
||||
struct MaterialProperty {
|
||||
vec3 color;
|
||||
int useSampler;
|
||||
sampler2D sampler;
|
||||
};
|
||||
|
||||
struct Light {
|
||||
int enabled;
|
||||
int type;
|
||||
vec3 position;
|
||||
vec3 target;
|
||||
vec4 color;
|
||||
};
|
||||
|
||||
// Input lighting values
|
||||
uniform Light lights[MAX_LIGHTS];
|
||||
uniform vec4 ambient;
|
||||
uniform vec3 viewPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
vec3 lightDot = vec3(0.0);
|
||||
vec3 normal = normalize(fragNormal);
|
||||
vec3 viewD = normalize(viewPos - fragPosition);
|
||||
vec3 specular = vec3(0.0);
|
||||
|
||||
// NOTE: Implement here your fragment shader code
|
||||
|
||||
for (int i = 0; i < MAX_LIGHTS; i++)
|
||||
{
|
||||
if (lights[i].enabled == 1)
|
||||
{
|
||||
vec3 light = vec3(0.0);
|
||||
|
||||
if (lights[i].type == LIGHT_DIRECTIONAL)
|
||||
{
|
||||
light = -normalize(lights[i].target - lights[i].position);
|
||||
}
|
||||
|
||||
if (lights[i].type == LIGHT_POINT)
|
||||
{
|
||||
light = normalize(lights[i].position - fragPosition);
|
||||
}
|
||||
|
||||
float NdotL = max(dot(normal, light), 0.0);
|
||||
lightDot += lights[i].color.rgb*NdotL;
|
||||
|
||||
float specCo = 0.0;
|
||||
if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewD, reflect(-(light), normal))), 16); // 16 refers to shine
|
||||
specular += specCo;
|
||||
}
|
||||
}
|
||||
|
||||
finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
|
||||
finalColor += texelColor*(ambient/10.0);
|
||||
|
||||
// Gamma correction
|
||||
finalColor = pow(finalColor, vec4(1.0/2.2));
|
||||
}
|
33
examples/shaders/resources/shaders/glsl330/basic_lighting.vs
Normal file
33
examples/shaders/resources/shaders/glsl330/basic_lighting.vs
Normal file
|
@ -0,0 +1,33 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
in vec3 vertexNormal;
|
||||
in vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 matModel;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
out vec3 fragPosition;
|
||||
out vec2 fragTexCoord;
|
||||
out vec4 fragColor;
|
||||
out vec3 fragNormal;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
// Send vertex attributes to fragment shader
|
||||
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0f));
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
|
||||
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||
fragNormal = normalize(normalMatrix*vertexNormal);
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||
}
|
40
examples/shaders/resources/shaders/glsl330/bloom.fs
Normal file
40
examples/shaders/resources/shaders/glsl330/bloom.fs
Normal file
|
@ -0,0 +1,40 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
const vec2 size = vec2(800, 450); // render size
|
||||
const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance
|
||||
const float quality = 2.5; // lower = smaller glow, better quality
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 sum = vec4(0);
|
||||
vec2 sizeFactor = vec2(1)/size*quality;
|
||||
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 source = texture(texture0, fragTexCoord);
|
||||
|
||||
const int range = 2; // should be = (samples - 1)/2;
|
||||
|
||||
for (int x = -range; x <= range; x++)
|
||||
{
|
||||
for (int y = -range; y <= range; y++)
|
||||
{
|
||||
sum += texture(texture0, fragTexCoord + vec2(x, y)*sizeFactor);
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate final fragment color
|
||||
finalColor = ((sum/(samples*samples)) + source)*colDiffuse;
|
||||
}
|
35
examples/shaders/resources/shaders/glsl330/blur.fs
Normal file
35
examples/shaders/resources/shaders/glsl330/blur.fs
Normal file
|
@ -0,0 +1,35 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800;
|
||||
const float renderHeight = 450;
|
||||
|
||||
float offset[3] = float[](0.0, 1.3846153846, 3.2307692308);
|
||||
float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec3 texelColor = texture(texture0, fragTexCoord).rgb*weight[0];
|
||||
|
||||
for (int i = 1; i < 3; i++)
|
||||
{
|
||||
texelColor += texture(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
|
||||
texelColor += texture(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
|
||||
}
|
||||
|
||||
finalColor = vec4(texelColor, 1.0);
|
||||
}
|
48
examples/shaders/resources/shaders/glsl330/cross_hatching.fs
Normal file
48
examples/shaders/resources/shaders/glsl330/cross_hatching.fs
Normal file
|
@ -0,0 +1,48 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
float hatchOffsetY = 5.0;
|
||||
float lumThreshold01 = 0.9;
|
||||
float lumThreshold02 = 0.7;
|
||||
float lumThreshold03 = 0.5;
|
||||
float lumThreshold04 = 0.3;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 tc = vec3(1.0, 1.0, 1.0);
|
||||
float lum = length(texture(texture0, fragTexCoord).rgb);
|
||||
|
||||
if (lum < lumThreshold01)
|
||||
{
|
||||
if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
if (lum < lumThreshold02)
|
||||
{
|
||||
if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
if (lum < lumThreshold03)
|
||||
{
|
||||
if (mod(gl_FragCoord.x + gl_FragCoord.y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
if (lum < lumThreshold04)
|
||||
{
|
||||
if (mod(gl_FragCoord.x - gl_FragCoord.y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
finalColor = vec4(tc, 1.0);
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
const float renderHeight = 450.0;
|
||||
|
||||
float stitchingSize = 6.0;
|
||||
|
||||
uniform int invert = 0;
|
||||
|
||||
vec4 PostFX(sampler2D tex, vec2 uv)
|
||||
{
|
||||
vec4 c = vec4(0.0);
|
||||
float size = stitchingSize;
|
||||
vec2 cPos = uv * vec2(renderWidth, renderHeight);
|
||||
vec2 tlPos = floor(cPos / vec2(size, size));
|
||||
tlPos *= size;
|
||||
|
||||
int remX = int(mod(cPos.x, size));
|
||||
int remY = int(mod(cPos.y, size));
|
||||
|
||||
if (remX == 0 && remY == 0) tlPos = cPos;
|
||||
|
||||
vec2 blPos = tlPos;
|
||||
blPos.y += (size - 1.0);
|
||||
|
||||
if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y)))))
|
||||
{
|
||||
if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0);
|
||||
else c = texture(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (invert == 1) c = texture(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
|
||||
else c = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 tc = PostFX(texture0, fragTexCoord).rgb;
|
||||
|
||||
finalColor = vec4(tc, 1.0);
|
||||
}
|
61
examples/shaders/resources/shaders/glsl330/cubes_panning.fs
Normal file
61
examples/shaders/resources/shaders/glsl330/cubes_panning.fs
Normal file
|
@ -0,0 +1,61 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// Custom variables
|
||||
#define PI 3.14159265358979323846
|
||||
uniform float uTime = 0.0;
|
||||
|
||||
float divisions = 5.0;
|
||||
float angle = 0.0;
|
||||
|
||||
vec2 VectorRotateTime(vec2 v, float speed)
|
||||
{
|
||||
float time = uTime*speed;
|
||||
float localTime = fract(time); // The time domain this works on is 1 sec.
|
||||
|
||||
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.50) && (localTime < 0.75)) angle = PI*0.25;
|
||||
else if ((localTime >= 0.75) && (localTime < 1.00)) angle = PI/4*sin(2*PI*localTime);
|
||||
|
||||
// Rotate vector by angle
|
||||
v -= 0.5;
|
||||
v = mat2(cos(angle), -sin(angle), sin(angle), cos(angle))*v;
|
||||
v += 0.5;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
float Rectangle(in vec2 st, in float size, in float fill)
|
||||
{
|
||||
float roundSize = 0.5 - size/2.0;
|
||||
float left = step(roundSize, st.x);
|
||||
float top = step(roundSize, st.y);
|
||||
float bottom = step(roundSize, 1.0 - st.y);
|
||||
float right = step(roundSize, 1.0 - st.x);
|
||||
|
||||
return (left*bottom*right*top)*fill;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 fragPos = fragTexCoord;
|
||||
fragPos.xy += uTime/9.0;
|
||||
|
||||
fragPos *= divisions;
|
||||
vec2 ipos = floor(fragPos); // Get the integer coords
|
||||
vec2 fpos = fract(fragPos); // Get the fractional coords
|
||||
|
||||
fpos = VectorRotateTime(fpos, 0.2);
|
||||
|
||||
float alpha = Rectangle(fpos, 0.216, 1.0);
|
||||
vec3 color = vec3(0.3, 0.3, 0.3);
|
||||
|
||||
finalColor = vec4(color, alpha);
|
||||
}
|
27
examples/shaders/resources/shaders/glsl330/depth.fs
Normal file
27
examples/shaders/resources/shaders/glsl330/depth.fs
Normal file
|
@ -0,0 +1,27 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0; // Depth texture
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
float zNear = 0.01; // camera z near
|
||||
float zFar = 10.0; // camera z far
|
||||
float z = texture(texture0, fragTexCoord).x;
|
||||
|
||||
// Linearize depth value
|
||||
float depth = (2.0*zNear)/(zFar + zNear - z*(zFar - zNear));
|
||||
|
||||
// Calculate final fragment color
|
||||
finalColor = vec4(depth, depth, depth, 1.0f);
|
||||
}
|
56
examples/shaders/resources/shaders/glsl330/distortion.fs
Normal file
56
examples/shaders/resources/shaders/glsl330/distortion.fs
Normal file
|
@ -0,0 +1,56 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Default parameters for Oculus Rift DK2 device
|
||||
const vec2 LeftLensCenter = vec2(0.2863248, 0.5);
|
||||
const vec2 RightLensCenter = vec2(0.7136753, 0.5);
|
||||
const vec2 LeftScreenCenter = vec2(0.25, 0.5);
|
||||
const vec2 RightScreenCenter = vec2(0.75, 0.5);
|
||||
const vec2 Scale = vec2(0.25, 0.45);
|
||||
const vec2 ScaleIn = vec2(4.0, 2.5);
|
||||
const vec4 HmdWarpParam = vec4(1.0, 0.22, 0.24, 0.0);
|
||||
const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.0);
|
||||
|
||||
void main()
|
||||
{
|
||||
// The following two variables need to be set per eye
|
||||
vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter;
|
||||
vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter;
|
||||
|
||||
// Scales input texture coordinates for distortion: vec2 HmdWarp(vec2 fragTexCoord, vec2 LensCenter)
|
||||
vec2 theta = (fragTexCoord - LensCenter)*ScaleIn; // Scales to [-1, 1]
|
||||
float rSq = theta.x*theta.x + theta.y*theta.y;
|
||||
vec2 theta1 = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq);
|
||||
//vec2 tc = LensCenter + Scale*theta1;
|
||||
|
||||
// Detect whether blue texture coordinates are out of range since these will scaled out the furthest
|
||||
vec2 thetaBlue = theta1*(ChromaAbParam.z + ChromaAbParam.w*rSq);
|
||||
vec2 tcBlue = LensCenter + Scale*thetaBlue;
|
||||
|
||||
if (any(bvec2(clamp(tcBlue, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tcBlue))) finalColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
else
|
||||
{
|
||||
// Do blue texture lookup
|
||||
float blue = texture(texture0, tcBlue).b;
|
||||
|
||||
// Do green lookup (no scaling)
|
||||
vec2 tcGreen = LensCenter + Scale*theta1;
|
||||
float green = texture(texture0, tcGreen).g;
|
||||
|
||||
// Do red scale and lookup
|
||||
vec2 thetaRed = theta1*(ChromaAbParam.x + ChromaAbParam.y*rSq);
|
||||
vec2 tcRed = LensCenter + Scale*thetaRed;
|
||||
float red = texture(texture0, tcRed).r;
|
||||
|
||||
finalColor = vec4(red, green, blue, 1.0);
|
||||
}
|
||||
}
|
||||
|
34
examples/shaders/resources/shaders/glsl330/dream_vision.fs
Normal file
34
examples/shaders/resources/shaders/glsl330/dream_vision.fs
Normal file
|
@ -0,0 +1,34 @@
|
|||
#version 330
|
||||
|
||||
in vec2 fragTexCoord;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture(texture0, fragTexCoord);
|
||||
|
||||
color += texture(texture0, fragTexCoord + 0.001);
|
||||
color += texture(texture0, fragTexCoord + 0.003);
|
||||
color += texture(texture0, fragTexCoord + 0.005);
|
||||
color += texture(texture0, fragTexCoord + 0.007);
|
||||
color += texture(texture0, fragTexCoord + 0.009);
|
||||
color += texture(texture0, fragTexCoord + 0.011);
|
||||
|
||||
color += texture(texture0, fragTexCoord - 0.001);
|
||||
color += texture(texture0, fragTexCoord - 0.003);
|
||||
color += texture(texture0, fragTexCoord - 0.005);
|
||||
color += texture(texture0, fragTexCoord - 0.007);
|
||||
color += texture(texture0, fragTexCoord - 0.009);
|
||||
color += texture(texture0, fragTexCoord - 0.011);
|
||||
|
||||
color.rgb = vec3((color.r + color.g + color.b)/3.0);
|
||||
color = color/9.5;
|
||||
|
||||
fragColor = color;
|
||||
}
|
59
examples/shaders/resources/shaders/glsl330/eratosthenes.fs
Normal file
59
examples/shaders/resources/shaders/glsl330/eratosthenes.fs
Normal file
|
@ -0,0 +1,59 @@
|
|||
#version 330
|
||||
|
||||
/*************************************************************************************
|
||||
|
||||
The Sieve of Eratosthenes -- a simple shader by ProfJski
|
||||
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.
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
WARNING: If you make scale too large, your GPU may bog down!
|
||||
|
||||
***************************************************************************************/
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// Make a nice spectrum of colors based on counter and maxSize
|
||||
vec4 Colorizer(float counter, float maxSize)
|
||||
{
|
||||
float red = 0.0, green = 0.0, blue = 0.0;
|
||||
float normsize = counter/maxSize;
|
||||
|
||||
red = smoothstep(0.3, 0.7, normsize);
|
||||
green = sin(3.14159*normsize);
|
||||
blue = 1.0 - smoothstep(0.0, 0.4, normsize);
|
||||
|
||||
return vec4(0.8*red, 0.8*green, 0.8*blue, 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = vec4(1.0);
|
||||
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
|
||||
|
||||
if ((value == 0) || (value == 1) || (value == 2)) finalColor = vec4(1.0);
|
||||
else
|
||||
{
|
||||
for (int i = 2; (i < max(2, sqrt(value) + 1)); i++)
|
||||
{
|
||||
if ((value - i*floor(value/i)) == 0)
|
||||
{
|
||||
color = Colorizer(float(i), scale);
|
||||
//break; // Uncomment to color by the largest factor instead
|
||||
}
|
||||
}
|
||||
|
||||
finalColor = color;
|
||||
}
|
||||
}
|
40
examples/shaders/resources/shaders/glsl330/fisheye.fs
Normal file
40
examples/shaders/resources/shaders/glsl330/fisheye.fs
Normal file
|
@ -0,0 +1,40 @@
|
|||
#version 330
|
||||
|
||||
in vec2 fragTexCoord;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
const float PI = 3.1415926535;
|
||||
|
||||
void main()
|
||||
{
|
||||
float aperture = 178.0;
|
||||
float apertureHalf = 0.5 * aperture * (PI / 180.0);
|
||||
float maxFactor = sin(apertureHalf);
|
||||
|
||||
vec2 uv = vec2(0);
|
||||
vec2 xy = 2.0 * fragTexCoord.xy - 1.0;
|
||||
float d = length(xy);
|
||||
|
||||
if (d < (2.0 - maxFactor))
|
||||
{
|
||||
d = length(xy * maxFactor);
|
||||
float z = sqrt(1.0 - d * d);
|
||||
float r = atan(d, z) / PI;
|
||||
float phi = atan(xy.y, xy.x);
|
||||
|
||||
uv.x = r * cos(phi) + 0.5;
|
||||
uv.y = r * sin(phi) + 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
uv = fragTexCoord.xy;
|
||||
}
|
||||
|
||||
fragColor = texture(texture0, uv);
|
||||
}
|
26
examples/shaders/resources/shaders/glsl330/grayscale.fs
Normal file
26
examples/shaders/resources/shaders/glsl330/grayscale.fs
Normal file
|
@ -0,0 +1,26 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture(texture0, fragTexCoord)*colDiffuse*fragColor;
|
||||
|
||||
// Convert texel color to grayscale using NTSC conversion weights
|
||||
float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114));
|
||||
|
||||
// Calculate final fragment color
|
||||
finalColor = vec4(gray, gray, gray, texelColor.a);
|
||||
}
|
81
examples/shaders/resources/shaders/glsl330/julia_set.fs
Normal file
81
examples/shaders/resources/shaders/glsl330/julia_set.fs
Normal file
|
@ -0,0 +1,81 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
uniform vec2 screenDims; // Dimensions of the screen
|
||||
uniform vec2 c; // c.x = real, c.y = imaginary component. Equation done is z^2 + c
|
||||
uniform vec2 offset; // Offset of the scale.
|
||||
uniform float zoom; // Zoom of the scale.
|
||||
|
||||
const int MAX_ITERATIONS = 255; // Max iterations to do.
|
||||
|
||||
// Square a complex number
|
||||
vec2 ComplexSquare(vec2 z)
|
||||
{
|
||||
return vec2(
|
||||
z.x * z.x - z.y * z.y,
|
||||
z.x * z.y * 2.0
|
||||
);
|
||||
}
|
||||
|
||||
// Convert Hue Saturation Value (HSV) color into RGB
|
||||
vec3 Hsv2rgb(vec3 c)
|
||||
{
|
||||
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
/**********************************************************************************************
|
||||
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.
|
||||
|
||||
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).
|
||||
2^2 = 4, 4^2 = 8 and so on.
|
||||
So at 2 we stop 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)?
|
||||
That is what MAX_ITERATIONS is for.
|
||||
Then we can divide the iterations by the MAX_ITERATIONS value to get a normalized value 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.
|
||||
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
|
||||
// NOTE: fragTexCoord already comes as normalized screen coordinates but offset must be normalized before scaling and zoom
|
||||
vec2 z = vec2((fragTexCoord.x + offset.x/screenDims.x)*2.5/zoom, (fragTexCoord.y + offset.y/screenDims.y)*1.5/zoom);
|
||||
|
||||
int iterations = 0;
|
||||
for (iterations = 0; iterations < MAX_ITERATIONS; iterations++)
|
||||
{
|
||||
z = ComplexSquare(z) + c; // Iterate function
|
||||
|
||||
if (dot(z, z) > 4.0) break;
|
||||
}
|
||||
|
||||
// Another few iterations decreases errors in the smoothing calculation.
|
||||
// See http://linas.org/art-gallery/escape/escape.html for more information.
|
||||
z = ComplexSquare(z) + c;
|
||||
z = ComplexSquare(z) + c;
|
||||
|
||||
// This last part smooths the color (again see link above).
|
||||
float smoothVal = float(iterations) + 1.0 - (log(log(length(z)))/log(2.0));
|
||||
|
||||
// Normalize the value so it is between 0 and 1.
|
||||
float norm = smoothVal/float(MAX_ITERATIONS);
|
||||
|
||||
// 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);
|
||||
else finalColor = vec4(Hsv2rgb(vec3(norm, 1.0, 1.0)), 1.0);
|
||||
}
|
26
examples/shaders/resources/shaders/glsl330/overdraw.fs
Normal file
26
examples/shaders/resources/shaders/glsl330/overdraw.fs
Normal file
|
@ -0,0 +1,26 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
// To show overdraw, we just render all the fragments
|
||||
// with a solid color and some transparency
|
||||
|
||||
// NOTE: This is not a postpro render,
|
||||
// it will only render all screen texture in a plain color
|
||||
|
||||
finalColor = vec4(1.0, 0.0, 0.0, 0.2);
|
||||
}
|
||||
|
30
examples/shaders/resources/shaders/glsl330/palette_switch.fs
Normal file
30
examples/shaders/resources/shaders/glsl330/palette_switch.fs
Normal file
|
@ -0,0 +1,30 @@
|
|||
#version 330
|
||||
|
||||
const int colors = 8;
|
||||
|
||||
// Input fragment attributes (from fragment shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform ivec3 palette[colors];
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture(texture0, fragTexCoord)*fragColor;
|
||||
|
||||
// Convert the (normalized) texel color RED component (GB would work, too)
|
||||
// to the palette index by scaling up from [0, 1] to [0, 255].
|
||||
int index = int(texelColor.r*255.0);
|
||||
ivec3 color = palette[index];
|
||||
|
||||
// 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]
|
||||
// for OpenGL to work.
|
||||
finalColor = vec4(color/255.0, texelColor.a);
|
||||
}
|
33
examples/shaders/resources/shaders/glsl330/pixelizer.fs
Normal file
33
examples/shaders/resources/shaders/glsl330/pixelizer.fs
Normal file
|
@ -0,0 +1,33 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800;
|
||||
const float renderHeight = 450;
|
||||
|
||||
uniform float pixelWidth = 5.0;
|
||||
uniform float pixelHeight = 5.0;
|
||||
|
||||
void main()
|
||||
{
|
||||
float dx = pixelWidth*(1.0/renderWidth);
|
||||
float dy = pixelHeight*(1.0/renderHeight);
|
||||
|
||||
vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy));
|
||||
|
||||
vec3 tc = texture(texture0, coord).rgb;
|
||||
|
||||
finalColor = vec4(tc, 1.0);
|
||||
}
|
31
examples/shaders/resources/shaders/glsl330/posterization.fs
Normal file
31
examples/shaders/resources/shaders/glsl330/posterization.fs
Normal file
|
@ -0,0 +1,31 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
float gamma = 0.6;
|
||||
float numColors = 8.0;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec3 texelColor = texture(texture0, fragTexCoord.xy).rgb;
|
||||
|
||||
texelColor = pow(texelColor, vec3(gamma, gamma, gamma));
|
||||
texelColor = texelColor*numColors;
|
||||
texelColor = floor(texelColor);
|
||||
texelColor = texelColor/numColors;
|
||||
texelColor = pow(texelColor, vec3(1.0/gamma));
|
||||
|
||||
finalColor = vec4(texelColor, 1.0);
|
||||
}
|
32
examples/shaders/resources/shaders/glsl330/predator.fs
Normal file
32
examples/shaders/resources/shaders/glsl330/predator.fs
Normal file
|
@ -0,0 +1,32 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec3 texelColor = texture(texture0, fragTexCoord).rgb;
|
||||
vec3 colors[3];
|
||||
colors[0] = vec3(0.0, 0.0, 1.0);
|
||||
colors[1] = vec3(1.0, 1.0, 0.0);
|
||||
colors[2] = vec3(1.0, 0.0, 0.0);
|
||||
|
||||
float lum = (texelColor.r + texelColor.g + texelColor.b)/3.0;
|
||||
|
||||
int ix = (lum < 0.5)? 0:1;
|
||||
|
||||
vec3 tc = mix(colors[ix], colors[ix + 1], (lum - float(ix)*0.5)/0.5);
|
||||
|
||||
finalColor = vec4(tc, 1.0);
|
||||
}
|
432
examples/shaders/resources/shaders/glsl330/raymarching.fs
Normal file
432
examples/shaders/resources/shaders/glsl330/raymarching.fs
Normal file
|
@ -0,0 +1,432 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
uniform vec3 viewEye;
|
||||
uniform vec3 viewCenter;
|
||||
uniform vec3 viewUp;
|
||||
uniform float deltaTime;
|
||||
uniform float runTime;
|
||||
uniform vec2 resolution;
|
||||
|
||||
// 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.
|
||||
|
||||
// A list of useful distance function to simple primitives, and an example on how to
|
||||
// do some interesting boolean operations, repetition and displacement.
|
||||
//
|
||||
// More info here: http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
||||
|
||||
#define AA 1 // make this 1 is your machine is too slow
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
float sdPlane( vec3 p )
|
||||
{
|
||||
return p.y;
|
||||
}
|
||||
|
||||
float sdSphere( vec3 p, float s )
|
||||
{
|
||||
return length(p)-s;
|
||||
}
|
||||
|
||||
float sdBox( vec3 p, vec3 b )
|
||||
{
|
||||
vec3 d = abs(p) - b;
|
||||
return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0));
|
||||
}
|
||||
|
||||
float sdEllipsoid( in vec3 p, in vec3 r )
|
||||
{
|
||||
return (length( p/r ) - 1.0) * min(min(r.x,r.y),r.z);
|
||||
}
|
||||
|
||||
float udRoundBox( vec3 p, vec3 b, float r )
|
||||
{
|
||||
return length(max(abs(p)-b,0.0))-r;
|
||||
}
|
||||
|
||||
float sdTorus( vec3 p, vec2 t )
|
||||
{
|
||||
return length( vec2(length(p.xz)-t.x,p.y) )-t.y;
|
||||
}
|
||||
|
||||
float sdHexPrism( vec3 p, vec2 h )
|
||||
{
|
||||
vec3 q = abs(p);
|
||||
#if 0
|
||||
return max(q.z-h.y,max((q.x*0.866025+q.y*0.5),q.y)-h.x);
|
||||
#else
|
||||
float d1 = q.z-h.y;
|
||||
float d2 = max((q.x*0.866025+q.y*0.5),q.y)-h.x;
|
||||
return length(max(vec2(d1,d2),0.0)) + min(max(d1,d2), 0.);
|
||||
#endif
|
||||
}
|
||||
|
||||
float sdCapsule( vec3 p, vec3 a, vec3 b, float r )
|
||||
{
|
||||
vec3 pa = p-a, ba = b-a;
|
||||
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
|
||||
return length( pa - ba*h ) - r;
|
||||
}
|
||||
|
||||
float sdEquilateralTriangle( in vec2 p )
|
||||
{
|
||||
const float k = sqrt(3.0);
|
||||
p.x = abs(p.x) - 1.0;
|
||||
p.y = p.y + 1.0/k;
|
||||
if( p.x + k*p.y > 0.0 ) p = vec2( p.x - k*p.y, -k*p.x - p.y )/2.0;
|
||||
p.x += 2.0 - 2.0*clamp( (p.x+2.0)/2.0, 0.0, 1.0 );
|
||||
return -length(p)*sign(p.y);
|
||||
}
|
||||
|
||||
float sdTriPrism( vec3 p, vec2 h )
|
||||
{
|
||||
vec3 q = abs(p);
|
||||
float d1 = q.z-h.y;
|
||||
#if 1
|
||||
// distance bound
|
||||
float d2 = max(q.x*0.866025+p.y*0.5,-p.y)-h.x*0.5;
|
||||
#else
|
||||
// correct distance
|
||||
h.x *= 0.866025;
|
||||
float d2 = sdEquilateralTriangle(p.xy/h.x)*h.x;
|
||||
#endif
|
||||
return length(max(vec2(d1,d2),0.0)) + min(max(d1,d2), 0.);
|
||||
}
|
||||
|
||||
float sdCylinder( vec3 p, vec2 h )
|
||||
{
|
||||
vec2 d = abs(vec2(length(p.xz),p.y)) - h;
|
||||
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
|
||||
}
|
||||
|
||||
float sdCone( in vec3 p, in vec3 c )
|
||||
{
|
||||
vec2 q = vec2( length(p.xz), p.y );
|
||||
float d1 = -q.y-c.z;
|
||||
float d2 = max( dot(q,c.xy), q.y);
|
||||
return length(max(vec2(d1,d2),0.0)) + min(max(d1,d2), 0.);
|
||||
}
|
||||
|
||||
float sdConeSection( in vec3 p, in float h, in float r1, in float r2 )
|
||||
{
|
||||
float d1 = -p.y - h;
|
||||
float q = p.y - h;
|
||||
float si = 0.5*(r1-r2)/h;
|
||||
float d2 = max( sqrt( dot(p.xz,p.xz)*(1.0-si*si)) + q*si - r2, q );
|
||||
return length(max(vec2(d1,d2),0.0)) + min(max(d1,d2), 0.);
|
||||
}
|
||||
|
||||
float sdPryamid4(vec3 p, vec3 h ) // h = { cos a, sin a, height }
|
||||
{
|
||||
// Tetrahedron = Octahedron - Cube
|
||||
float box = sdBox( p - vec3(0,-2.0*h.z,0), vec3(2.0*h.z) );
|
||||
|
||||
float d = 0.0;
|
||||
d = max( d, abs( dot(p, vec3( -h.x, h.y, 0 )) ));
|
||||
d = max( d, abs( dot(p, vec3( h.x, h.y, 0 )) ));
|
||||
d = max( d, abs( dot(p, vec3( 0, h.y, h.x )) ));
|
||||
d = max( d, abs( dot(p, vec3( 0, h.y,-h.x )) ));
|
||||
float octa = d - h.z;
|
||||
return max(-box,octa); // Subtraction
|
||||
}
|
||||
|
||||
float length2( vec2 p )
|
||||
{
|
||||
return sqrt( p.x*p.x + p.y*p.y );
|
||||
}
|
||||
|
||||
float length6( vec2 p )
|
||||
{
|
||||
p = p*p*p; p = p*p;
|
||||
return pow( p.x + p.y, 1.0/6.0 );
|
||||
}
|
||||
|
||||
float length8( vec2 p )
|
||||
{
|
||||
p = p*p; p = p*p; p = p*p;
|
||||
return pow( p.x + p.y, 1.0/8.0 );
|
||||
}
|
||||
|
||||
float sdTorus82( vec3 p, vec2 t )
|
||||
{
|
||||
vec2 q = vec2(length2(p.xz)-t.x,p.y);
|
||||
return length8(q)-t.y;
|
||||
}
|
||||
|
||||
float sdTorus88( vec3 p, vec2 t )
|
||||
{
|
||||
vec2 q = vec2(length8(p.xz)-t.x,p.y);
|
||||
return length8(q)-t.y;
|
||||
}
|
||||
|
||||
float sdCylinder6( vec3 p, vec2 h )
|
||||
{
|
||||
return max( length6(p.xz)-h.x, abs(p.y)-h.y );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
float opS( float d1, float d2 )
|
||||
{
|
||||
return max(-d2,d1);
|
||||
}
|
||||
|
||||
vec2 opU( vec2 d1, vec2 d2 )
|
||||
{
|
||||
return (d1.x<d2.x) ? d1 : d2;
|
||||
}
|
||||
|
||||
vec3 opRep( vec3 p, vec3 c )
|
||||
{
|
||||
return mod(p,c)-0.5*c;
|
||||
}
|
||||
|
||||
vec3 opTwist( vec3 p )
|
||||
{
|
||||
float c = cos(10.0*p.y+10.0);
|
||||
float s = sin(10.0*p.y+10.0);
|
||||
mat2 m = mat2(c,-s,s,c);
|
||||
return vec3(m*p.xz,p.y);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
vec2 map( in vec3 pos )
|
||||
{
|
||||
vec2 res = opU( vec2( sdPlane( pos), 1.0 ),
|
||||
vec2( sdSphere( pos-vec3( 0.0,0.25, 0.0), 0.25 ), 46.9 ) );
|
||||
res = opU( res, vec2( sdBox( pos-vec3( 1.0,0.25, 0.0), vec3(0.25) ), 3.0 ) );
|
||||
res = opU( res, vec2( udRoundBox( pos-vec3( 1.0,0.25, 1.0), vec3(0.15), 0.1 ), 41.0 ) );
|
||||
res = opU( res, vec2( sdTorus( pos-vec3( 0.0,0.25, 1.0), vec2(0.20,0.05) ), 25.0 ) );
|
||||
res = opU( res, vec2( sdCapsule( pos,vec3(-1.3,0.10,-0.1), vec3(-0.8,0.50,0.2), 0.1 ), 31.9 ) );
|
||||
res = opU( res, vec2( sdTriPrism( pos-vec3(-1.0,0.25,-1.0), vec2(0.25,0.05) ),43.5 ) );
|
||||
res = opU( res, vec2( sdCylinder( pos-vec3( 1.0,0.30,-1.0), vec2(0.1,0.2) ), 8.0 ) );
|
||||
res = opU( res, vec2( sdCone( pos-vec3( 0.0,0.50,-1.0), vec3(0.8,0.6,0.3) ), 55.0 ) );
|
||||
res = opU( res, vec2( sdTorus82( pos-vec3( 0.0,0.25, 2.0), vec2(0.20,0.05) ),50.0 ) );
|
||||
res = opU( res, vec2( sdTorus88( pos-vec3(-1.0,0.25, 2.0), vec2(0.20,0.05) ),43.0 ) );
|
||||
res = opU( res, vec2( sdCylinder6( pos-vec3( 1.0,0.30, 2.0), vec2(0.1,0.2) ), 12.0 ) );
|
||||
res = opU( res, vec2( sdHexPrism( pos-vec3(-1.0,0.20, 1.0), vec2(0.25,0.05) ),17.0 ) );
|
||||
res = opU( res, vec2( sdPryamid4( pos-vec3(-1.0,0.15,-2.0), vec3(0.8,0.6,0.25) ),37.0 ) );
|
||||
res = opU( res, vec2( opS( udRoundBox( pos-vec3(-2.0,0.2, 1.0), vec3(0.15),0.05),
|
||||
sdSphere( pos-vec3(-2.0,0.2, 1.0), 0.25)), 13.0 ) );
|
||||
res = opU( res, vec2( opS( sdTorus82( pos-vec3(-2.0,0.2, 0.0), vec2(0.20,0.1)),
|
||||
sdCylinder( opRep( vec3(atan(pos.x+2.0,pos.z)/6.2831, pos.y, 0.02+0.5*length(pos-vec3(-2.0,0.2, 0.0))), vec3(0.05,1.0,0.05)), vec2(0.02,0.6))), 51.0 ) );
|
||||
res = opU( res, vec2( 0.5*sdSphere( pos-vec3(-2.0,0.25,-1.0), 0.2 ) + 0.03*sin(50.0*pos.x)*sin(50.0*pos.y)*sin(50.0*pos.z), 65.0 ) );
|
||||
res = opU( res, vec2( 0.5*sdTorus( opTwist(pos-vec3(-2.0,0.25, 2.0)),vec2(0.20,0.05)), 46.7 ) );
|
||||
res = opU( res, vec2( sdConeSection( pos-vec3( 0.0,0.35,-2.0), 0.15, 0.2, 0.1 ), 13.67 ) );
|
||||
res = opU( res, vec2( sdEllipsoid( pos-vec3( 1.0,0.35,-2.0), vec3(0.15, 0.2, 0.05) ), 43.17 ) );
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
vec2 castRay( in vec3 ro, in vec3 rd )
|
||||
{
|
||||
float tmin = 0.2;
|
||||
float tmax = 30.0;
|
||||
|
||||
#if 1
|
||||
// bounding volume
|
||||
float tp1 = (0.0-ro.y)/rd.y; if( tp1>0.0 ) tmax = min( tmax, tp1 );
|
||||
float tp2 = (1.6-ro.y)/rd.y; if( tp2>0.0 ) { if( ro.y>1.6 ) tmin = max( tmin, tp2 );
|
||||
else tmax = min( tmax, tp2 ); }
|
||||
#endif
|
||||
|
||||
float t = tmin;
|
||||
float m = -1.0;
|
||||
for( int i=0; i<64; i++ )
|
||||
{
|
||||
float precis = 0.0005*t;
|
||||
vec2 res = map( ro+rd*t );
|
||||
if( res.x<precis || t>tmax ) break;
|
||||
t += res.x;
|
||||
m = res.y;
|
||||
}
|
||||
|
||||
if( t>tmax ) m=-1.0;
|
||||
return vec2( t, m );
|
||||
}
|
||||
|
||||
|
||||
float calcSoftshadow( in vec3 ro, in vec3 rd, in float mint, in float tmax )
|
||||
{
|
||||
float res = 1.0;
|
||||
float t = mint;
|
||||
for( int i=0; i<16; i++ )
|
||||
{
|
||||
float h = map( ro + rd*t ).x;
|
||||
res = min( res, 8.0*h/t );
|
||||
t += clamp( h, 0.02, 0.10 );
|
||||
if( h<0.001 || t>tmax ) break;
|
||||
}
|
||||
return clamp( res, 0.0, 1.0 );
|
||||
}
|
||||
|
||||
vec3 calcNormal( in vec3 pos )
|
||||
{
|
||||
vec2 e = vec2(1.0,-1.0)*0.5773*0.0005;
|
||||
return normalize( e.xyy*map( pos + e.xyy ).x +
|
||||
e.yyx*map( pos + e.yyx ).x +
|
||||
e.yxy*map( pos + e.yxy ).x +
|
||||
e.xxx*map( pos + e.xxx ).x );
|
||||
/*
|
||||
vec3 eps = vec3( 0.0005, 0.0, 0.0 );
|
||||
vec3 nor = vec3(
|
||||
map(pos+eps.xyy).x - map(pos-eps.xyy).x,
|
||||
map(pos+eps.yxy).x - map(pos-eps.yxy).x,
|
||||
map(pos+eps.yyx).x - map(pos-eps.yyx).x );
|
||||
return normalize(nor);
|
||||
*/
|
||||
}
|
||||
|
||||
float calcAO( in vec3 pos, in vec3 nor )
|
||||
{
|
||||
float occ = 0.0;
|
||||
float sca = 1.0;
|
||||
for( int i=0; i<5; i++ )
|
||||
{
|
||||
float hr = 0.01 + 0.12*float(i)/4.0;
|
||||
vec3 aopos = nor * hr + pos;
|
||||
float dd = map( aopos ).x;
|
||||
occ += -(dd-hr)*sca;
|
||||
sca *= 0.95;
|
||||
}
|
||||
return clamp( 1.0 - 3.0*occ, 0.0, 1.0 );
|
||||
}
|
||||
|
||||
// http://iquilezles.org/www/articles/checkerfiltering/checkerfiltering.htm
|
||||
float checkersGradBox( in vec2 p )
|
||||
{
|
||||
// filter kernel
|
||||
vec2 w = fwidth(p) + 0.001;
|
||||
// analytical integral (box filter)
|
||||
vec2 i = 2.0*(abs(fract((p-0.5*w)*0.5)-0.5)-abs(fract((p+0.5*w)*0.5)-0.5))/w;
|
||||
// xor pattern
|
||||
return 0.5 - 0.5*i.x*i.y;
|
||||
}
|
||||
|
||||
vec3 render( in vec3 ro, in vec3 rd )
|
||||
{
|
||||
vec3 col = vec3(0.7, 0.9, 1.0) +rd.y*0.8;
|
||||
vec2 res = castRay(ro,rd);
|
||||
float t = res.x;
|
||||
float m = res.y;
|
||||
if( m>-0.5 )
|
||||
{
|
||||
vec3 pos = ro + t*rd;
|
||||
vec3 nor = calcNormal( pos );
|
||||
vec3 ref = reflect( rd, nor );
|
||||
|
||||
// material
|
||||
col = 0.45 + 0.35*sin( vec3(0.05,0.08,0.10)*(m-1.0) );
|
||||
if( m<1.5 )
|
||||
{
|
||||
|
||||
float f = checkersGradBox( 5.0*pos.xz );
|
||||
col = 0.3 + f*vec3(0.1);
|
||||
}
|
||||
|
||||
// lighting
|
||||
float occ = calcAO( pos, nor );
|
||||
vec3 lig = normalize( vec3(cos(-0.4 * runTime), sin(0.7 * runTime), -0.6) );
|
||||
vec3 hal = normalize( lig-rd );
|
||||
float amb = clamp( 0.5+0.5*nor.y, 0.0, 1.0 );
|
||||
float dif = clamp( dot( nor, lig ), 0.0, 1.0 );
|
||||
float bac = clamp( dot( nor, normalize(vec3(-lig.x,0.0,-lig.z))), 0.0, 1.0 )*clamp( 1.0-pos.y,0.0,1.0);
|
||||
float dom = smoothstep( -0.1, 0.1, ref.y );
|
||||
float fre = pow( clamp(1.0+dot(nor,rd),0.0,1.0), 2.0 );
|
||||
|
||||
dif *= calcSoftshadow( pos, lig, 0.02, 2.5 );
|
||||
dom *= calcSoftshadow( pos, ref, 0.02, 2.5 );
|
||||
|
||||
float spe = pow( clamp( dot( nor, hal ), 0.0, 1.0 ),16.0)*
|
||||
dif *
|
||||
(0.04 + 0.96*pow( clamp(1.0+dot(hal,rd),0.0,1.0), 5.0 ));
|
||||
|
||||
vec3 lin = vec3(0.0);
|
||||
lin += 1.30*dif*vec3(1.00,0.80,0.55);
|
||||
lin += 0.40*amb*vec3(0.40,0.60,1.00)*occ;
|
||||
lin += 0.50*dom*vec3(0.40,0.60,1.00)*occ;
|
||||
lin += 0.50*bac*vec3(0.25,0.25,0.25)*occ;
|
||||
lin += 0.25*fre*vec3(1.00,1.00,1.00)*occ;
|
||||
col = col*lin;
|
||||
col += 10.00*spe*vec3(1.00,0.90,0.70);
|
||||
|
||||
col = mix( col, vec3(0.8,0.9,1.0), 1.0-exp( -0.0002*t*t*t ) );
|
||||
}
|
||||
|
||||
return vec3( clamp(col,0.0,1.0) );
|
||||
}
|
||||
|
||||
mat3 setCamera( in vec3 ro, in vec3 ta, float cr )
|
||||
{
|
||||
vec3 cw = normalize(ta-ro);
|
||||
vec3 cp = vec3(sin(cr), cos(cr),0.0);
|
||||
vec3 cu = normalize( cross(cw,cp) );
|
||||
vec3 cv = normalize( cross(cu,cw) );
|
||||
return mat3( cu, cv, cw );
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 tot = vec3(0.0);
|
||||
#if AA>1
|
||||
for( int m=0; m<AA; m++ )
|
||||
for( int n=0; n<AA; n++ )
|
||||
{
|
||||
// pixel coordinates
|
||||
vec2 o = vec2(float(m),float(n)) / float(AA) - 0.5;
|
||||
vec2 p = (-resolution.xy + 2.0*(gl_FragCoord.xy+o))/resolution.y;
|
||||
#else
|
||||
vec2 p = (-resolution.xy + 2.0*gl_FragCoord.xy)/resolution.y;
|
||||
#endif
|
||||
|
||||
// RAY: Camera is provided from raylib
|
||||
//vec3 ro = vec3( -0.5+3.5*cos(0.1*time + 6.0*mo.x), 1.0 + 2.0*mo.y, 0.5 + 4.0*sin(0.1*time + 6.0*mo.x) );
|
||||
|
||||
vec3 ro = viewEye;
|
||||
vec3 ta = viewCenter;
|
||||
|
||||
// camera-to-world transformation
|
||||
mat3 ca = setCamera( ro, ta, 0.0 );
|
||||
// ray direction
|
||||
vec3 rd = ca * normalize( vec3(p.xy,2.0) );
|
||||
|
||||
// render
|
||||
vec3 col = render( ro, rd );
|
||||
|
||||
// gamma
|
||||
col = pow( col, vec3(0.4545) );
|
||||
|
||||
tot += col;
|
||||
#if AA>1
|
||||
}
|
||||
tot /= float(AA*AA);
|
||||
#endif
|
||||
|
||||
finalColor = vec4( tot, 1.0 );
|
||||
}
|
49
examples/shaders/resources/shaders/glsl330/scanlines.fs
Normal file
49
examples/shaders/resources/shaders/glsl330/scanlines.fs
Normal file
|
@ -0,0 +1,49 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800;
|
||||
const float renderHeight = 450;
|
||||
float offset = 0.0;
|
||||
|
||||
uniform float time;
|
||||
|
||||
void main()
|
||||
{
|
||||
float frequency = renderHeight/3.0;
|
||||
/*
|
||||
// Scanlines method 1
|
||||
float tval = 0; //time
|
||||
vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval));
|
||||
|
||||
vec4 color = texture(texture0, fragTexCoord);
|
||||
|
||||
color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0);
|
||||
color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y);
|
||||
color *= vec4(0.8, 1.0, 0.7, 1);
|
||||
color *= 0.9 + 0.1*sin(10.0*tval + uv.y*1000.0);
|
||||
color *= 0.97 + 0.03*sin(110.0*tval);
|
||||
|
||||
fragColor = color;
|
||||
*/
|
||||
// Scanlines method 2
|
||||
float globalPos = (fragTexCoord.y + offset) * frequency;
|
||||
float wavePos = cos((fract(globalPos) - 0.5)*3.14);
|
||||
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
|
||||
finalColor = mix(vec4(0.0, 0.3, 0.0, 0.0), texelColor, wavePos);
|
||||
}
|
41
examples/shaders/resources/shaders/glsl330/sobel.fs
Normal file
41
examples/shaders/resources/shaders/glsl330/sobel.fs
Normal file
|
@ -0,0 +1,41 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
uniform vec2 resolution = vec2(800, 450);
|
||||
|
||||
void main()
|
||||
{
|
||||
float x = 1.0/resolution.x;
|
||||
float y = 1.0/resolution.y;
|
||||
|
||||
vec4 horizEdge = vec4(0.0);
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
|
||||
vec4 vertEdge = vec4(0.0);
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
|
||||
vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb));
|
||||
|
||||
finalColor = vec4(edge, texture2D(texture0, fragTexCoord).a);
|
||||
}
|
47
examples/shaders/resources/shaders/glsl330/swirl.fs
Normal file
47
examples/shaders/resources/shaders/glsl330/swirl.fs
Normal file
|
@ -0,0 +1,47 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
// NOTE: Render size values should be passed from code
|
||||
const float renderWidth = 800;
|
||||
const float renderHeight = 450;
|
||||
|
||||
float radius = 250.0;
|
||||
float angle = 0.8;
|
||||
|
||||
uniform vec2 center = vec2(200.0, 200.0);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texSize = vec2(renderWidth, renderHeight);
|
||||
vec2 tc = fragTexCoord*texSize;
|
||||
tc -= center;
|
||||
|
||||
float dist = length(tc);
|
||||
|
||||
if (dist < radius)
|
||||
{
|
||||
float percent = (radius - dist)/radius;
|
||||
float theta = percent*percent*angle*8.0;
|
||||
float s = sin(theta);
|
||||
float c = cos(theta);
|
||||
|
||||
tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c)));
|
||||
}
|
||||
|
||||
tc += center;
|
||||
vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
|
||||
|
||||
finalColor = vec4(color.rgb, 1.0);;
|
||||
}
|
37
examples/shaders/resources/shaders/glsl330/wave.fs
Normal file
37
examples/shaders/resources/shaders/glsl330/wave.fs
Normal file
|
@ -0,0 +1,37 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
uniform float secondes;
|
||||
|
||||
uniform vec2 size;
|
||||
|
||||
uniform float freqX;
|
||||
uniform float freqY;
|
||||
uniform float ampX;
|
||||
uniform float ampY;
|
||||
uniform float speedX;
|
||||
uniform float speedY;
|
||||
|
||||
void main() {
|
||||
float pixelWidth = 1.0 / size.x;
|
||||
float pixelHeight = 1.0 / size.y;
|
||||
float aspect = pixelHeight / pixelWidth;
|
||||
float boxLeft = 0.0;
|
||||
float boxTop = 0.0;
|
||||
|
||||
vec2 p = fragTexCoord;
|
||||
p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth;
|
||||
p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight;
|
||||
|
||||
finalColor = texture(texture0, p)*colDiffuse*fragColor;
|
||||
}
|
BIN
examples/shaders/resources/space.png
Normal file
BIN
examples/shaders/resources/space.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
BIN
examples/shaders/resources/texel_checker.png
Normal file
BIN
examples/shaders/resources/texel_checker.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
345
examples/shaders/shaders_basic_lighting.py
Normal file
345
examples/shaders/shaders_basic_lighting.py
Normal file
|
@ -0,0 +1,345 @@
|
|||
# /*******************************************************************************************
|
||||
# *
|
||||
# * raylib [shaders] example - basic lighting
|
||||
# *
|
||||
# * NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||
# * OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
||||
# *
|
||||
# * NOTE: Shaders used in this example are #version 330 (OpenGL 3.3).
|
||||
# *
|
||||
# * This example has been created using raylib 2.5 (www.raylib.com)
|
||||
# * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
# *
|
||||
# * Example contributed by Chris Camacho (@codifies) and reviewed by Ramon Santamaria (@raysan5)
|
||||
# *
|
||||
# * Chris Camacho (@codifies - http://bedroomcoders.co.uk/) notes:
|
||||
# *
|
||||
# * This is based on the PBR lighting example, but greatly simplified to aid learning...
|
||||
# * actually there is very little of the PBR example left!
|
||||
# * When I first looked at the bewildering complexity of the PBR example I feared
|
||||
# * I would never understand how I could do simple lighting with raylib however its
|
||||
# * a testement to the authors of raylib (including rlights.h) that the example
|
||||
# * came together fairly quickly.
|
||||
# *
|
||||
# * Copyright (c) 2019 Chris Camacho (@codifies) and Ramon Santamaria (@raysan5)
|
||||
# *
|
||||
# ********************************************************************************************/
|
||||
|
||||
from raylib.static import *
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
import math
|
||||
|
||||
MAX_LIGHTS = 4 #// Max dynamic lights supported by shader
|
||||
lightsCount = 0
|
||||
|
||||
|
||||
def MatrixRotateX(angle):
|
||||
result = MatrixIdentity();
|
||||
|
||||
cosres = math.cos(angle);
|
||||
sinres = math.sin(angle);
|
||||
|
||||
result.m5 = cosres;
|
||||
result.m6 = -sinres;
|
||||
result.m9 = sinres;
|
||||
result.m10 = cosres;
|
||||
|
||||
return result;
|
||||
|
||||
|
||||
|
||||
def MatrixRotateY(angle):
|
||||
result = MatrixIdentity()
|
||||
|
||||
cosres = math.cos(angle);
|
||||
sinres = math.sin(angle);
|
||||
|
||||
result.m0 = cosres;
|
||||
result.m2 = sinres;
|
||||
result.m8 = -sinres;
|
||||
result.m10 = cosres;
|
||||
|
||||
return result;
|
||||
|
||||
|
||||
def MatrixIdentity():
|
||||
result = ffi.new("struct Matrix *",[ 1.0, 0.0, 0.0, 0.0,0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ])
|
||||
return result
|
||||
|
||||
|
||||
|
||||
def MatrixRotateZ(angle):
|
||||
result = MatrixIdentity();
|
||||
|
||||
cosres = math.cos(angle);
|
||||
sinres = math.sin(angle);
|
||||
|
||||
result.m0 = cosres;
|
||||
result.m1 = -sinres;
|
||||
result.m4 = sinres;
|
||||
result.m5 = cosres;
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def MatrixMultiply(left, right):
|
||||
result = ffi.new("struct Matrix *")
|
||||
result.m0 = left.m0*right.m0 + left.m1*right.m4 + left.m2*right.m8 + left.m3*right.m12;
|
||||
result.m1 = left.m0*right.m1 + left.m1*right.m5 + left.m2*right.m9 + left.m3*right.m13;
|
||||
result.m2 = left.m0*right.m2 + left.m1*right.m6 + left.m2*right.m10 + left.m3*right.m14;
|
||||
result.m3 = left.m0*right.m3 + left.m1*right.m7 + left.m2*right.m11 + left.m3*right.m15;
|
||||
result.m4 = left.m4*right.m0 + left.m5*right.m4 + left.m6*right.m8 + left.m7*right.m12;
|
||||
result.m5 = left.m4*right.m1 + left.m5*right.m5 + left.m6*right.m9 + left.m7*right.m13;
|
||||
result.m6 = left.m4*right.m2 + left.m5*right.m6 + left.m6*right.m10 + left.m7*right.m14;
|
||||
result.m7 = left.m4*right.m3 + left.m5*right.m7 + left.m6*right.m11 + left.m7*right.m15;
|
||||
result.m8 = left.m8*right.m0 + left.m9*right.m4 + left.m10*right.m8 + left.m11*right.m12;
|
||||
result.m9 = left.m8*right.m1 + left.m9*right.m5 + left.m10*right.m9 + left.m11*right.m13;
|
||||
result.m10 = left.m8*right.m2 + left.m9*right.m6 + left.m10*right.m10 + left.m11*right.m14;
|
||||
result.m11 = left.m8*right.m3 + left.m9*right.m7 + left.m10*right.m11 + left.m11*right.m15;
|
||||
result.m12 = left.m12*right.m0 + left.m13*right.m4 + left.m14*right.m8 + left.m15*right.m12;
|
||||
result.m13 = left.m12*right.m1 + left.m13*right.m5 + left.m14*right.m9 + left.m15*right.m13;
|
||||
result.m14 = left.m12*right.m2 + left.m13*right.m6 + left.m14*right.m10 + left.m15*right.m14;
|
||||
result.m15 = left.m12*right.m3 + left.m13*right.m7 + left.m14*right.m11 + left.m15*right.m15;
|
||||
|
||||
return result
|
||||
|
||||
|
||||
#//----------------------------------------------------------------------------------
|
||||
#// Types and Structures Definition
|
||||
#//----------------------------------------------------------------------------------
|
||||
|
||||
#// Light data
|
||||
@dataclass
|
||||
class Light:
|
||||
def __init__(self):
|
||||
pass
|
||||
type: Any
|
||||
position: Any
|
||||
target: Any
|
||||
color: Any
|
||||
enabled: Any
|
||||
|
||||
#// Shader locations
|
||||
enabledLoc: Any
|
||||
typeLoc: Any
|
||||
posLoc: Any
|
||||
targetLoc: Any
|
||||
colorLoc: Any
|
||||
|
||||
|
||||
#// Light type
|
||||
|
||||
LIGHT_DIRECTIONAL=0
|
||||
LIGHT_POINT=1
|
||||
|
||||
|
||||
#// Create a light and get shader locations
|
||||
def CreateLight(type, position, target, color, shader):
|
||||
global lightsCount
|
||||
light = Light()
|
||||
|
||||
|
||||
if lightsCount < MAX_LIGHTS:
|
||||
light.enabled = True
|
||||
light.type = type
|
||||
light.position = position
|
||||
light.target = target
|
||||
light.color = color
|
||||
|
||||
#// TODO: Below code doesn't look good to me,
|
||||
# // it assumes a specific shader naming and structure
|
||||
# // Probably this implementation could be improved
|
||||
enabledName = f"lights[{lightsCount}].enabled"
|
||||
typeName = f"lights[{lightsCount}].type"
|
||||
posName = f"lights[{lightsCount}].position"
|
||||
targetName = f"lights[{lightsCount}].target"
|
||||
colorName = f"lights[{lightsCount}].color"
|
||||
# enabledName = '0' + str(lightsCount)
|
||||
# typeName = '0' + str(lightsCount)
|
||||
# posName = '0' + str(lightsCount)
|
||||
# targetName = '0' + str(lightsCount)
|
||||
# colorName = '0' + str(lightsCount)
|
||||
|
||||
light.enabledLoc = GetShaderLocation(shader, enabledName.encode('utf-8'))
|
||||
light.typeLoc = GetShaderLocation(shader, typeName.encode('utf-8'))
|
||||
light.posLoc = GetShaderLocation(shader, posName.encode('utf-8'))
|
||||
light.targetLoc = GetShaderLocation(shader, targetName.encode('utf-8'))
|
||||
light.colorLoc = GetShaderLocation(shader, colorName.encode('utf-8'))
|
||||
|
||||
UpdateLightValues(shader, light)
|
||||
|
||||
lightsCount+=1
|
||||
|
||||
|
||||
return light
|
||||
|
||||
|
||||
#// Send light properties to shader
|
||||
# // NOTE: Light shader locations should be available
|
||||
def UpdateLightValues(shader, light):
|
||||
#// Send to shader light enabled state and type
|
||||
SetShaderValue(shader, light.enabledLoc, ffi.new("int *",light.enabled), UNIFORM_INT)
|
||||
SetShaderValue(shader, light.typeLoc, ffi.new("int *",light.type), UNIFORM_INT)
|
||||
|
||||
#// Send to shader light position values
|
||||
position = [ light.position.x, light.position.y, light.position.z]
|
||||
SetShaderValue(shader, light.posLoc, ffi.new("struct Vector3 *",position), UNIFORM_VEC3)
|
||||
|
||||
#// Send to shader light target position values
|
||||
target =[ light.target.x, light.target.y, light.target.z ]
|
||||
SetShaderValue(shader, light.targetLoc, ffi.new("struct Vector3 *",target), UNIFORM_VEC3)
|
||||
|
||||
#// Send to shader light color values
|
||||
color = [light.color[0]/255.0, light.color[1]/255.0, light.color[2]/255.0, light.color[3]/255.0]
|
||||
SetShaderValue(shader, light.colorLoc, ffi.new("struct Vector4 *",color), UNIFORM_VEC4)
|
||||
|
||||
|
||||
|
||||
def Vector3Zero():
|
||||
return ffi.new("struct Vector3 *",[ 0, 0, 0])
|
||||
|
||||
#// Initialization
|
||||
#//--------------------------------------------------------------------------------------
|
||||
screenWidth = 800;
|
||||
screenHeight = 450;
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT); # Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
InitWindow(screenWidth, screenHeight, b"raylib [shaders] example - basic lighting")
|
||||
|
||||
#// Define the camera to look into our 3d world
|
||||
cameraPtr = ffi.new("struct Camera3D *")
|
||||
camera = cameraPtr[0]
|
||||
camera.position = [ 2.0, 2.0, 6.0 ] # // Camera position
|
||||
camera.target = [ 0.0, 0.5, 0.0]# // Camera looking at point
|
||||
camera.up = [ 0.0, 1.0, 0.0]# // Camera up vector (rotation towards target)
|
||||
camera.fovy = 45.0 # // Camera field-of-view Y
|
||||
camera.type = CAMERA_PERSPECTIVE # // Camera mode type
|
||||
|
||||
#// Load models
|
||||
modelA = LoadModelFromMesh(GenMeshTorus(0.4, 1.0, 16, 32))
|
||||
modelB = LoadModelFromMesh(GenMeshCube(1.0, 1.0, 1.0))
|
||||
modelC = LoadModelFromMesh(GenMeshSphere(0.5, 32, 32))
|
||||
|
||||
#// Load models texture
|
||||
texture = LoadTexture(b"resources/texel_checker.png")
|
||||
|
||||
#// Assign texture to default model material
|
||||
modelA.materials[0].maps[MAP_DIFFUSE].texture = texture
|
||||
modelB.materials[0].maps[MAP_DIFFUSE].texture = texture
|
||||
modelC.materials[0].maps[MAP_DIFFUSE].texture = texture
|
||||
|
||||
shader = LoadShader(b"resources/shaders/glsl330/basic_lighting.vs",
|
||||
b"resources/shaders/glsl330/basic_lighting.fs");
|
||||
|
||||
#// Get some shader loactions
|
||||
shader.locs[LOC_MATRIX_MODEL] = GetShaderLocation(shader, b"matModel");
|
||||
shader.locs[LOC_VECTOR_VIEW] = GetShaderLocation(shader, b"viewPos");
|
||||
|
||||
#// ambient light level
|
||||
ambientLoc = GetShaderLocation(shader, b"ambient");
|
||||
v = ffi.new("struct Vector4 *", [ 0.2, 0.2, 0.2, 1.0 ])
|
||||
SetShaderValue(shader, ambientLoc, v, UNIFORM_VEC4);
|
||||
|
||||
|
||||
|
||||
angle = 6.282;
|
||||
|
||||
#// All models use the same shader
|
||||
modelA.materials[0].shader = shader
|
||||
modelB.materials[0].shader = shader
|
||||
modelC.materials[0].shader = shader
|
||||
|
||||
#// Using 4 point lights, white, red, green and blue
|
||||
lights = [0] * 4
|
||||
lights[0] = CreateLight(LIGHT_POINT, ffi.new("struct Vector3 *",[ 4, 2, 4 ]), Vector3Zero(), WHITE, shader)
|
||||
lights[1] = CreateLight(LIGHT_POINT, ffi.new("struct Vector3 *",[4, 2, 4 ]), Vector3Zero(), RED, shader)
|
||||
lights[2] = CreateLight(LIGHT_POINT, ffi.new("struct Vector3 *",[ 0, 4, 2 ]), Vector3Zero(), GREEN, shader)
|
||||
lights[3] = CreateLight(LIGHT_POINT, ffi.new("struct Vector3 *",[ 0, 4, 2 ]), Vector3Zero(), BLUE, shader)
|
||||
|
||||
SetCameraMode(camera, CAMERA_ORBITAL) #// Set an orbital camera mode
|
||||
|
||||
SetTargetFPS(60) # // Set our game to run at 60 frames-per-second
|
||||
#//--------------------------------------------------------------------------------------
|
||||
|
||||
#// Main game loop
|
||||
while not WindowShouldClose(): #// Detect window close button or ESC key
|
||||
#// Update
|
||||
#//----------------------------------------------------------------------------------
|
||||
if IsKeyPressed(KEY_W): lights[0].enabled = not lights[0].enabled
|
||||
if IsKeyPressed(KEY_R): lights[1].enabled = not lights[1].enabled
|
||||
if IsKeyPressed(KEY_G): lights[2].enabled = not lights[2].enabled
|
||||
if IsKeyPressed(KEY_B): lights[3].enabled = not lights[3].enabled
|
||||
|
||||
UpdateCamera(cameraPtr); #// Update camera
|
||||
|
||||
#// Make the lights do differing orbits
|
||||
angle -= 0.02
|
||||
lights[0].position.x = math.cos(angle)*4.0
|
||||
lights[0].position.z = math.sin(angle)*4.0
|
||||
lights[1].position.x = math.cos(-angle*0.6)*4.0
|
||||
lights[1].position.z = math.sin(-angle*0.6)*4.0
|
||||
lights[2].position.y = math.cos(angle*0.2)*4.0
|
||||
lights[2].position.z = math.sin(angle*0.2)*4.0
|
||||
lights[3].position.y = math.cos(-angle*0.35)*4.0
|
||||
lights[3].position.z = math.sin(-angle*0.35)*4.0
|
||||
|
||||
UpdateLightValues(shader, lights[0])
|
||||
UpdateLightValues(shader, lights[1])
|
||||
UpdateLightValues(shader, lights[2])
|
||||
UpdateLightValues(shader, lights[3])
|
||||
|
||||
#// Rotate the torus
|
||||
|
||||
modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateX(-0.025))[0]
|
||||
modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateZ(0.012))[0]
|
||||
|
||||
|
||||
|
||||
#// Update the light shader with the camera view position
|
||||
cameraPos = [ camera.position.x, camera.position.y, camera.position.z ]
|
||||
SetShaderValue(shader, shader.locs[LOC_VECTOR_VIEW], ffi.new("struct Vector3 *",cameraPos), UNIFORM_VEC3)
|
||||
#//----------------------------------------------------------------------------------
|
||||
|
||||
#// Draw
|
||||
#//----------------------------------------------------------------------------------
|
||||
BeginDrawing()
|
||||
|
||||
ClearBackground(RAYWHITE)
|
||||
|
||||
BeginMode3D(camera)
|
||||
|
||||
#// Draw the three models
|
||||
DrawModel(modelA, [0,0,0], 1.0, WHITE)
|
||||
DrawModel(modelB, [-1.6,0,0], 1.0, WHITE)
|
||||
DrawModel(modelC, [ 1.6,0,0], 1.0, WHITE)
|
||||
|
||||
#// Draw markers to show where the lights are
|
||||
if lights[0].enabled: DrawSphereEx(lights[0].position[0], 0.2, 8, 8, WHITE)
|
||||
if lights[1].enabled: DrawSphereEx(lights[1].position[0], 0.2, 8, 8, RED)
|
||||
if lights[2].enabled: DrawSphereEx(lights[2].position[0], 0.2, 8, 8, GREEN)
|
||||
if lights[3].enabled: DrawSphereEx(lights[3].position[0], 0.2, 8, 8, BLUE)
|
||||
|
||||
DrawGrid(10, 1.0)
|
||||
|
||||
EndMode3D()
|
||||
|
||||
DrawFPS(10, 10)
|
||||
|
||||
DrawText(b"Keys RGB & W toggle lights", 10, 30, 20, DARKGRAY)
|
||||
|
||||
EndDrawing()
|
||||
#//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#// De-Initialization
|
||||
#//--------------------------------------------------------------------------------------
|
||||
UnloadModel(modelA) # // Unload the modelA
|
||||
UnloadModel(modelB) # // Unload the modelB
|
||||
UnloadModel(modelC) # // Unload the modelC
|
||||
|
||||
UnloadTexture(texture) #// Unload the texture
|
||||
UnloadShader(shader) #// Unload shader
|
||||
|
||||
CloseWindow(); #// Close window and OpenGL context
|
Reference in a new issue