Watch
3
0
Fork
You've already forked raylib-cs
0

Sync of all the shaders from upstream + LoadFontData did not match anymore with C and crashed on MacOS

This commit is contained in:
Meatcorps 2026-05-24 12:19:24 +02:00
commit 7cd46c491f
82 changed files with 767 additions and 753 deletions

View file

@ -41,7 +41,7 @@ public class FontSdf
// Loading font data from memory data // Loading font data from memory data
// Parameters > font size: 16, no chars array provided (0), chars count: 95 (autogenerate chars array) // Parameters > font size: 16, no chars array provided (0), chars count: 95 (autogenerate chars array)
fontDefault.Glyphs = LoadFontData(fileData, (int)fileSize, 16, null, 95, FontType.Default); fontDefault.Glyphs = LoadFontData(fileData, (int)fileSize, 16, null, 95, FontType.Default, &fontDefault.GlyphCount);
// Parameters > chars count: 95, font size: 16, chars padding in image: 4 px, pack method: 0 (default) // Parameters > chars count: 95, font size: 16, chars padding in image: 4 px, pack method: 0 (default)
Image atlas = GenImageFontAtlas(fontDefault.Glyphs, &fontDefault.Recs, 95, 16, 4, 0); Image atlas = GenImageFontAtlas(fontDefault.Glyphs, &fontDefault.Recs, 95, 16, 4, 0);
fontDefault.Texture = LoadTextureFromImage(atlas); fontDefault.Texture = LoadTextureFromImage(atlas);
@ -52,7 +52,7 @@ public class FontSdf
fontSDF.BaseSize = 16; fontSDF.BaseSize = 16;
fontSDF.GlyphCount = 95; fontSDF.GlyphCount = 95;
// Parameters > font size: 16, no chars array provided (0), chars count: 0 (defaults to 95) // Parameters > font size: 16, no chars array provided (0), chars count: 0 (defaults to 95)
fontSDF.Glyphs = LoadFontData(fileData, (int)fileSize, 16, null, 0, FontType.Sdf); fontSDF.Glyphs = LoadFontData(fileData, (int)fileSize, 16, null, 0, FontType.Sdf, &fontDefault.GlyphCount);
// Parameters > chars count: 95, font size: 16, chars padding in image: 0 px, pack method: 1 (Skyline algorythm) // Parameters > chars count: 95, font size: 16, chars padding in image: 0 px, pack method: 1 (Skyline algorythm)
atlas = GenImageFontAtlas(fontSDF.Glyphs, &fontSDF.Recs, 95, 16, 0, 1); atlas = GenImageFontAtlas(fontSDF.Glyphs, &fontSDF.Recs, 95, 16, 0, 1);
fontSDF.Texture = LoadTextureFromImage(atlas); fontSDF.Texture = LoadTextureFromImage(atlas);

View file

@ -10,7 +10,7 @@ varying vec4 fragColor;
uniform sampler2D texture0; uniform sampler2D texture0;
uniform vec4 colDiffuse; uniform vec4 colDiffuse;
// NOTE: Add here your custom variables // NOTE: Add your custom variables here
void main() void main()
{ {

View file

@ -13,7 +13,7 @@ uniform mat4 mvp;
varying vec2 fragTexCoord; varying vec2 fragTexCoord;
varying vec4 fragColor; varying vec4 fragColor;
// NOTE: Add here your custom variables // NOTE: Add your custom variables here
void main() void main()
{ {

View file

@ -10,11 +10,11 @@ varying vec4 fragColor;
uniform sampler2D texture0; uniform sampler2D texture0;
uniform vec4 colDiffuse; uniform vec4 colDiffuse;
// NOTE: Add here your custom variables // NOTE: Add your custom variables here
const vec2 size = vec2(800, 450); // render size const vec2 size = vec2(800, 450); // Framebuffer size
const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance const float samples = 5.0; // Pixels per axis; higher = bigger glow, worse performance
const float quality = 2.5; // lower = smaller glow, better quality const float quality = 2.5; // Defines size factor: Lower = smaller glow, better quality
void main() void main()
{ {

View file

@ -10,7 +10,7 @@ varying vec4 fragColor;
uniform sampler2D texture0; uniform sampler2D texture0;
uniform vec4 colDiffuse; uniform vec4 colDiffuse;
// NOTE: Add here your custom variables // NOTE: Add your custom variables here
// NOTE: Render size values must be passed from code // NOTE: Render size values must be passed from code
const float renderWidth = 800.0; const float renderWidth = 800.0;

View file

@ -10,7 +10,7 @@ varying vec4 fragColor;
uniform sampler2D texture0; uniform sampler2D texture0;
uniform vec4 colDiffuse; uniform vec4 colDiffuse;
// NOTE: Add here your custom variables // NOTE: Add your custom variables here
float hatchOffsetY = 5.0; float hatchOffsetY = 5.0;
float lumThreshold01 = 0.9; float lumThreshold01 = 0.9;

View file

@ -10,7 +10,7 @@ varying vec4 fragColor;
uniform sampler2D texture0; uniform sampler2D texture0;
uniform vec4 colDiffuse; uniform vec4 colDiffuse;
// NOTE: Add here your custom variables // NOTE: Add your custom variables here
// NOTE: Render size values must be passed from code // NOTE: Render size values must be passed from code
const float renderWidth = 800.0; const float renderWidth = 800.0;
@ -23,8 +23,8 @@ vec4 PostFX(sampler2D tex, vec2 uv)
{ {
vec4 c = vec4(0.0); vec4 c = vec4(0.0);
float size = stitchingSize; float size = stitchingSize;
vec2 cPos = uv * vec2(renderWidth, renderHeight); vec2 cPos = uv*vec2(renderWidth, renderHeight);
vec2 tlPos = floor(cPos / vec2(size, size)); vec2 tlPos = floor(cPos/vec2(size, size));
tlPos *= size; tlPos *= size;
int remX = int(mod(cPos.x, size)); int remX = int(mod(cPos.x, size));
@ -38,11 +38,11 @@ vec4 PostFX(sampler2D tex, vec2 uv)
if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y))))) 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); 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 c = texture2D(tex, tlPos*vec2(1.0/renderWidth, 1.0/renderHeight))*1.4;
} }
else else
{ {
if (invert == 1) c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; 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); else c = vec4(0.0, 0.0, 0.0, 1.0);
} }

View file

@ -16,7 +16,7 @@ float angle = 0.0;
vec2 VectorRotateTime(vec2 v, float speed) vec2 VectorRotateTime(vec2 v, float speed)
{ {
float time = uTime*speed; float time = uTime*speed;
float localTime = fract(time); // The time domain this works on is 1 sec. float localTime = fract(time); // The time domain this works on is 1 sec
if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0; if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0;
else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4.0*sin(2.0*PI*localTime - PI/2.0); else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4.0*sin(2.0*PI*localTime - PI/2.0);

View file

@ -10,7 +10,7 @@ varying vec4 fragColor;
uniform sampler2D texture0; uniform sampler2D texture0;
uniform vec4 colDiffuse; uniform vec4 colDiffuse;
// NOTE: Add here your custom variables // NOTE: Add your custom variables here
void main() void main()
{ {

View file

@ -7,12 +7,12 @@ precision mediump float;
The Sieve of Eratosthenes -- a simple shader by ProfJski The Sieve of Eratosthenes -- a simple shader by ProfJski
An early prime number sieve: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes An early prime number sieve: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
The screen is divided into a square grid of boxes, each representing an integer value. The screen is divided into a square grid of boxes, each representing an integer value
Each integer is tested to see if it is a prime number. Primes are colored white. Each integer is tested to see if it is a prime number. Primes are colored white
Non-primes are colored with a color that indicates the smallest factor which evenly divdes our integer. Non-primes are colored with a color that indicates the smallest factor which evenly divdes our integer
You can change the scale variable to make a larger or smaller grid. You can change the scale variable to make a larger or smaller grid
Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers. Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers
WARNING: If you make scale too large, your GPU may bog down! WARNING: If you make scale too large, your GPU may bog down!
@ -38,7 +38,7 @@ vec4 Colorizer(float counter, float maxSize)
void main() void main()
{ {
vec4 color = vec4(1.0); vec4 color = vec4(1.0);
float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid. float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid
float value = scale*floor(fragTexCoord.y*scale) + floor(fragTexCoord.x*scale); // Group pixels into boxes representing integer values float value = scale*floor(fragTexCoord.y*scale) + floor(fragTexCoord.x*scale); // Group pixels into boxes representing integer values
int valuei = int(value); int valuei = int(value);

View file

@ -10,29 +10,29 @@ varying vec4 fragColor;
uniform sampler2D texture0; uniform sampler2D texture0;
uniform vec4 colDiffuse; uniform vec4 colDiffuse;
// NOTE: Add here your custom variables // NOTE: Add your custom variables here
const float PI = 3.1415926535; const float PI = 3.1415926535;
void main() void main()
{ {
float aperture = 178.0; float aperture = 178.0;
float apertureHalf = 0.5 * aperture * (PI / 180.0); float apertureHalf = 0.5*aperture*(PI/180.0);
float maxFactor = sin(apertureHalf); float maxFactor = sin(apertureHalf);
vec2 uv = vec2(0.0); vec2 uv = vec2(0.0);
vec2 xy = 2.0 * fragTexCoord.xy - 1.0; vec2 xy = 2.0*fragTexCoord.xy - 1.0;
float d = length(xy); float d = length(xy);
if (d < (2.0 - maxFactor)) if (d < (2.0 - maxFactor))
{ {
d = length(xy * maxFactor); d = length(xy*maxFactor);
float z = sqrt(1.0 - d * d); float z = sqrt(1.0 - d*d);
float r = atan(d, z) / PI; float r = atan(d, z)/PI;
float phi = atan(xy.y, xy.x); float phi = atan(xy.y, xy.x);
uv.x = r * cos(phi) + 0.5; uv.x = r*cos(phi) + 0.5;
uv.y = r * sin(phi) + 0.5; uv.y = r*sin(phi) + 0.5;
} }
else else
{ {

View file

@ -12,7 +12,7 @@ varying vec3 fragNormal;
uniform sampler2D texture0; uniform sampler2D texture0;
uniform vec4 colDiffuse; uniform vec4 colDiffuse;
// NOTE: Add here your custom variables // NOTE: Add your custom variables here
#define MAX_LIGHTS 4 #define MAX_LIGHTS 4
#define LIGHT_DIRECTIONAL 0 #define LIGHT_DIRECTIONAL 0

View file

@ -10,7 +10,7 @@ varying vec4 fragColor;
uniform sampler2D texture0; uniform sampler2D texture0;
uniform vec4 colDiffuse; uniform vec4 colDiffuse;
// NOTE: Add here your custom variables // NOTE: Add your custom variables here
void main() void main()
{ {

View file

@ -1,5 +1,7 @@
#version 100 #version 100
#extension GL_EXT_frag_depth : enable // Extension required for writing depth #extension GL_EXT_frag_depth : enable // Extension required for writing depth
precision mediump float; // Precision required for OpenGL ES2 (WebGL) precision mediump float; // Precision required for OpenGL ES2 (WebGL)
varying vec2 fragTexCoord; varying vec2 fragTexCoord;
@ -11,6 +13,7 @@ uniform vec4 colDiffuse;
void main() void main()
{ {
vec4 texelColor = texture2D(texture0, fragTexCoord); vec4 texelColor = texture2D(texture0, fragTexCoord);
gl_FragColor = texelColor*colDiffuse*fragColor; gl_FragColor = texelColor*colDiffuse*fragColor;
gl_FragDepthEXT = gl_FragCoord.z; gl_FragDepthEXT = gl_FragCoord.z;
} }

View file

@ -1,8 +1,11 @@
#version 100 #version 100
#extension GL_EXT_frag_depth : enable //Extension required for writing depth #extension GL_EXT_frag_depth : enable //Extension required for writing depth
#extension GL_OES_standard_derivatives : enable //Extension used for fwidth() #extension GL_OES_standard_derivatives : enable //Extension used for fwidth()
precision mediump float; // Precision required for OpenGL ES2 (WebGL)
#define ZERO 0
precision mediump float; // Precision required for OpenGL ES2 (WebGL)
// Input vertex attributes (from vertex shader) // Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord; varying vec2 fragTexCoord;
@ -17,23 +20,22 @@ uniform vec3 camPos;
uniform vec3 camDir; uniform vec3 camDir;
uniform vec2 screenCenter; uniform vec2 screenCenter;
#define ZERO 0 // SRC: https://learnopengl.com/Advanced-OpenGL/Depth-testing
float CalcDepth(in vec3 rd, in float Idist)
// https://learnopengl.com/Advanced-OpenGL/Depth-testing {
float CalcDepth(in vec3 rd, in float Idist){
float local_z = dot(normalize(camDir),rd)*Idist; float local_z = dot(normalize(camDir),rd)*Idist;
return (1.0/(local_z) - 1.0/0.01)/(1.0/1000.0 -1.0/0.01); return (1.0/(local_z) - 1.0/0.01)/(1.0/1000.0 -1.0/0.01);
} }
// https://iquilezles.org/articles/distfunctions/ // SRC: https://iquilezles.org/articles/distfunctions/
float sdHorseshoe( in vec3 p, in vec2 c, in float r, in float le, vec2 w ) float sdHorseshoe(in vec3 p, in vec2 c, in float r, in float le, vec2 w)
{ {
p.x = abs(p.x); p.x = abs(p.x);
float l = length(p.xy); float l = length(p.xy);
p.xy = mat2(-c.x, c.y, p.xy = mat2(-c.x, c.y,
c.y, c.x)*p.xy; c.y, c.x)*p.xy;
p.xy = vec2((p.y>0.0 || p.x>0.0)?p.x:l*sign(-c.x), p.xy = vec2((p.y>0.0 || p.x>0.0)?p.x:l*sign(-c.x),
(p.x>0.0)?p.y:l ); (p.x>0.0)?p.y:l);
p.xy = vec2(p.x,abs(p.y-r))-vec2(le,0.0); p.xy = vec2(p.x,abs(p.y-r))-vec2(le,0.0);
vec2 q = vec2(length(max(p.xy,0.0)) + min(0.0,max(p.x,p.y)),p.z); vec2 q = vec2(length(max(p.xy,0.0)) + min(0.0,max(p.x,p.y)),p.z);
@ -44,67 +46,70 @@ float sdHorseshoe( in vec3 p, in vec2 c, in float r, in float le, vec2 w )
// r = sphere's radius // r = sphere's radius
// h = cutting's plane's position // h = cutting's plane's position
// t = thickness // t = thickness
float sdSixWayCutHollowSphere( vec3 p, float r, float h, float t ) float sdSixWayCutHollowSphere(vec3 p, float r, float h, float t)
{ {
// Six way symetry Transformation // Six way symetry Transformation
vec3 ap = abs(p); vec3 ap = abs(p);
if(ap.x < max(ap.y, ap.z)){ if (ap.x < max(ap.y, ap.z)){
if(ap.y < ap.z) ap.xz = ap.zx; if (ap.y < ap.z) ap.xz = ap.zx;
else ap.xy = ap.yx; else ap.xy = ap.yx;
} }
vec2 q = vec2( length(ap.yz), ap.x ); vec2 q = vec2(length(ap.yz), ap.x);
float w = sqrt(r*r-h*h); float w = sqrt(r*r-h*h);
return ((h*q.x<w*q.y) ? length(q-vec2(w,h)) : return ((h*q.x<w*q.y) ? length(q-vec2(w,h)) : abs(length(q)-r)) - t;
abs(length(q)-r) ) - t;
} }
// https://iquilezles.org/articles/boxfunctions // SRC: https://iquilezles.org/articles/boxfunctions
vec2 iBox( in vec3 ro, in vec3 rd, in vec3 rad ) vec2 iBox(in vec3 ro, in vec3 rd, in vec3 rad)
{ {
vec3 m = 1.0/rd; vec3 m = 1.0/rd;
vec3 n = m*ro; vec3 n = m*ro;
vec3 k = abs(m)*rad; vec3 k = abs(m)*rad;
vec3 t1 = -n - k; vec3 t1 = -n - k;
vec3 t2 = -n + k; vec3 t2 = -n + k;
return vec2( max( max( t1.x, t1.y ), t1.z ),
min( min( t2.x, t2.y ), t2.z ) ); return vec2(max(max(t1.x, t1.y), t1.z),
min(min(t2.x, t2.y), t2.z));
} }
vec2 opU( vec2 d1, vec2 d2 ) vec2 opU(vec2 d1, vec2 d2)
{ {
return (d1.x<d2.x) ? d1 : d2; return (d1.x<d2.x) ? d1 : d2;
} }
vec2 map( in vec3 pos ){ vec2 map(in vec3 pos)
vec2 res = vec2( sdHorseshoe( pos-vec3(-1.0,0.08, 1.0), vec2(cos(1.3),sin(1.3)), 0.2, 0.3, vec2(0.03,0.5) ), 11.5 ) ; {
res = opU(res, vec2( sdSixWayCutHollowSphere( pos-vec3(0.0, 1.0, 0.0), 4.0, 3.5, 0.5 ), 4.5 )) ; vec2 res = vec2(sdHorseshoe(pos-vec3(-1.0,0.08, 1.0), vec2(cos(1.3),sin(1.3)), 0.2, 0.3, vec2(0.03,0.5)), 11.5) ;
res = opU(res, vec2(sdSixWayCutHollowSphere(pos-vec3(0.0, 1.0, 0.0), 4.0, 3.5, 0.5), 4.5)) ;
return res; return res;
} }
// https://www.shadertoy.com/view/Xds3zN // SRC: https://www.shadertoy.com/view/Xds3zN
vec2 raycast( in vec3 ro, in vec3 rd ){ vec2 raycast(in vec3 ro, in vec3 rd)
{
vec2 res = vec2(-1.0,-1.0); vec2 res = vec2(-1.0,-1.0);
float tmin = 1.0; float tmin = 1.0;
float tmax = 20.0; float tmax = 20.0;
// raytrace floor plane // Raytrace floor plane
float tp1 = (-ro.y)/rd.y; float tp1 = (-ro.y)/rd.y;
if( tp1>0.0 ) if (tp1>0.0)
{ {
tmax = min( tmax, tp1 ); tmax = min(tmax, tp1);
res = vec2( tp1, 1.0 ); res = vec2(tp1, 1.0);
} }
float t = tmin; float t = tmin;
for( int i=0; i<70 ; i++ ) for (int i=0; i<70 ; i++)
{ {
if(t>tmax) break; if (t>tmax) break;
vec2 h = map( ro+rd*t ); vec2 h = map(ro+rd*t);
if( abs(h.x)<(0.0001*t) ) if (abs(h.x) < (0.0001*t))
{ {
res = vec2(t,h.y); res = vec2(t,h.y);
break; break;
@ -117,54 +122,54 @@ vec2 raycast( in vec3 ro, in vec3 rd ){
// https://iquilezles.org/articles/rmshadows // https://iquilezles.org/articles/rmshadows
float calcSoftshadow( in vec3 ro, in vec3 rd, in float mint, in float tmax ) float calcSoftshadow(in vec3 ro, in vec3 rd, in float mint, in float tmax)
{ {
// bounding volume // bounding volume
float tp = (0.8-ro.y)/rd.y; if( tp>0.0 ) tmax = min( tmax, tp ); float tp = (0.8-ro.y)/rd.y; if (tp>0.0) tmax = min(tmax, tp);
float res = 1.0; float res = 1.0;
float t = mint; float t = mint;
for( int i=ZERO; i<24; i++ ) for (int i = ZERO; i < 24; i++)
{ {
float h = map( ro + rd*t ).x; float h = map(ro + rd*t).x;
float s = clamp(8.0*h/t,0.0,1.0); float s = clamp(8.0*h/t,0.0,1.0);
res = min( res, s ); res = min(res, s);
t += clamp( h, 0.01, 0.2 ); t += clamp(h, 0.01, 0.2);
if( res<0.004 || t>tmax ) break; if (res<0.004 || t>tmax) break;
} }
res = clamp( res, 0.0, 1.0 ); res = clamp(res, 0.0, 1.0);
return res*res*(3.0-2.0*res); return res*res*(3.0-2.0*res);
} }
// https://iquilezles.org/articles/normalsSDF // https://iquilezles.org/articles/normalsSDF
vec3 calcNormal( in vec3 pos ) vec3 calcNormal(in vec3 pos)
{ {
vec2 e = vec2(1.0,-1.0)*0.5773*0.0005; vec2 e = vec2(1.0,-1.0)*0.5773*0.0005;
return normalize( e.xyy*map( pos + e.xyy ).x + return normalize(e.xyy*map(pos + e.xyy).x +
e.yyx*map( pos + e.yyx ).x + e.yyx*map(pos + e.yyx).x +
e.yxy*map( pos + e.yxy ).x + e.yxy*map(pos + e.yxy).x +
e.xxx*map( pos + e.xxx ).x ); e.xxx*map(pos + e.xxx).x);
} }
// https://iquilezles.org/articles/nvscene2008/rwwtt.pdf // https://iquilezles.org/articles/nvscene2008/rwwtt.pdf
float calcAO( in vec3 pos, in vec3 nor ) float calcAO(in vec3 pos, in vec3 nor)
{ {
float occ = 0.0; float occ = 0.0;
float sca = 1.0; float sca = 1.0;
for( int i=ZERO; i<5; i++ ) for (int i = ZERO; i < 5; i++)
{ {
float h = 0.01 + 0.12*float(i)/4.0; float h = 0.01 + 0.12*float(i)/4.0;
float d = map( pos + h*nor ).x; float d = map(pos + h*nor).x;
occ += (h-d)*sca; occ += (h-d)*sca;
sca *= 0.95; sca *= 0.95;
if( occ>0.35 ) break; if (occ>0.35) break;
} }
return clamp( 1.0 - 3.0*occ, 0.0, 1.0 ) * (0.5+0.5*nor.y); return clamp(1.0 - 3.0*occ, 0.0, 1.0)*(0.5+0.5*nor.y);
} }
// https://iquilezles.org/articles/checkerfiltering // https://iquilezles.org/articles/checkerfiltering
float checkersGradBox( in vec2 p ) float checkersGradBox(in vec2 p)
{ {
// filter kernel // filter kernel
vec2 w = fwidth(p) + 0.001; vec2 w = fwidth(p) + 0.001;
@ -175,7 +180,7 @@ float checkersGradBox( in vec2 p )
} }
// https://www.shadertoy.com/view/tdS3DG // https://www.shadertoy.com/view/tdS3DG
vec4 render( in vec3 ro, in vec3 rd) vec4 render(in vec3 ro, in vec3 rd)
{ {
// background // background
vec3 col = vec3(0.7, 0.7, 0.9) - max(rd.y,0.0)*0.3; vec3 col = vec3(0.7, 0.7, 0.9) - max(rd.y,0.0)*0.3;
@ -183,37 +188,37 @@ vec4 render( in vec3 ro, in vec3 rd)
// raycast scene // raycast scene
vec2 res = raycast(ro,rd); vec2 res = raycast(ro,rd);
float t = res.x; float t = res.x;
float m = res.y; float m = res.y;
if( m>-0.5 ) if (m>-0.5)
{ {
vec3 pos = ro + t*rd; vec3 pos = ro + t*rd;
vec3 nor = (m<1.5) ? vec3(0.0,1.0,0.0) : calcNormal( pos ); vec3 nor = (m<1.5) ? vec3(0.0,1.0,0.0) : calcNormal(pos);
vec3 ref = reflect( rd, nor ); vec3 ref = reflect(rd, nor);
// material // material
col = 0.2 + 0.2*sin( m*2.0 + vec3(0.0,1.0,2.0) ); col = 0.2 + 0.2*sin(m*2.0 + vec3(0.0,1.0,2.0));
float ks = 1.0; float ks = 1.0;
if( m<1.5 ) if (m<1.5)
{ {
float f = checkersGradBox( 3.0*pos.xz); float f = checkersGradBox(3.0*pos.xz);
col = 0.15 + f*vec3(0.05); col = 0.15 + f*vec3(0.05);
ks = 0.4; ks = 0.4;
} }
// lighting // lighting
float occ = calcAO( pos, nor ); float occ = calcAO(pos, nor);
vec3 lin = vec3(0.0); vec3 lin = vec3(0.0);
// sun // sun
{ {
vec3 lig = normalize( vec3(-0.5, 0.4, -0.6) ); vec3 lig = normalize(vec3(-0.5, 0.4, -0.6));
vec3 hal = normalize( lig-rd ); vec3 hal = normalize(lig-rd);
float dif = clamp( dot( nor, lig ), 0.0, 1.0 ); float dif = clamp(dot(nor, lig), 0.0, 1.0);
//if( dif>0.0001 ) //if (dif>0.0001)
dif *= calcSoftshadow( pos, lig, 0.02, 2.5 ); dif *= calcSoftshadow(pos, lig, 0.02, 2.5);
float spe = pow( clamp( dot( nor, hal ), 0.0, 1.0 ),16.0); float spe = pow(clamp(dot(nor, hal), 0.0, 1.0),16.0);
spe *= dif; spe *= dif;
spe *= 0.04+0.96*pow(clamp(1.0-dot(hal,lig),0.0,1.0),5.0); spe *= 0.04+0.96*pow(clamp(1.0-dot(hal,lig),0.0,1.0),5.0);
//spe *= 0.04+0.96*pow(clamp(1.0-sqrt(0.5*(1.0-dot(rd,lig))),0.0,1.0),5.0); //spe *= 0.04+0.96*pow(clamp(1.0-sqrt(0.5*(1.0-dot(rd,lig))),0.0,1.0),5.0);
@ -222,38 +227,39 @@ vec4 render( in vec3 ro, in vec3 rd)
} }
// sky // sky
{ {
float dif = sqrt(clamp( 0.5+0.5*nor.y, 0.0, 1.0 )); float dif = sqrt(clamp(0.5+0.5*nor.y, 0.0, 1.0));
dif *= occ; dif *= occ;
float spe = smoothstep( -0.2, 0.2, ref.y ); float spe = smoothstep(-0.2, 0.2, ref.y);
spe *= dif; spe *= dif;
spe *= 0.04+0.96*pow(clamp(1.0+dot(nor,rd),0.0,1.0), 5.0 ); spe *= 0.04+0.96*pow(clamp(1.0+dot(nor,rd),0.0,1.0), 5.0);
//if( spe>0.001 ) //if (spe>0.001)
spe *= calcSoftshadow( pos, ref, 0.02, 2.5 ); spe *= calcSoftshadow(pos, ref, 0.02, 2.5);
lin += col*0.60*dif*vec3(0.40,0.60,1.15); lin += col*0.60*dif*vec3(0.40,0.60,1.15);
lin += 2.00*spe*vec3(0.40,0.60,1.30)*ks; lin += 2.00*spe*vec3(0.40,0.60,1.30)*ks;
} }
// back // back
{ {
float dif = clamp( dot( nor, normalize(vec3(0.5,0.0,0.6))), 0.0, 1.0 )*clamp( 1.0-pos.y,0.0,1.0); float dif = clamp(dot(nor, normalize(vec3(0.5,0.0,0.6))), 0.0, 1.0)*clamp(1.0-pos.y,0.0,1.0);
dif *= occ; dif *= occ;
lin += col*0.55*dif*vec3(0.25,0.25,0.25); lin += col*0.55*dif*vec3(0.25,0.25,0.25);
} }
// sss // sss
{ {
float dif = pow(clamp(1.0+dot(nor,rd),0.0,1.0),2.0); float dif = pow(clamp(1.0+dot(nor,rd),0.0,1.0),2.0);
dif *= occ; dif *= occ;
lin += col*0.25*dif*vec3(1.00,1.00,1.00); lin += col*0.25*dif*vec3(1.00,1.00,1.00);
} }
col = lin; col = lin;
col = mix( col, vec3(0.7,0.7,0.9), 1.0-exp( -0.0001*t*t*t ) ); col = mix(col, vec3(0.7,0.7,0.9), 1.0-exp(-0.0001*t*t*t));
} }
return vec4(vec3( clamp(col,0.0,1.0) ),t); return vec4(vec3(clamp(col,0.0,1.0)),t);
} }
vec3 CalcRayDir(vec2 nCoord){ vec3 CalcRayDir(vec2 nCoord)
{
vec3 horizontal = normalize(cross(camDir,vec3(.0 , 1.0, .0))); vec3 horizontal = normalize(cross(camDir,vec3(.0 , 1.0, .0)));
vec3 vertical = normalize(cross(horizontal,camDir)); vec3 vertical = normalize(cross(horizontal,camDir));
return normalize(camDir + horizontal*nCoord.x + vertical*nCoord.y); return normalize(camDir + horizontal*nCoord.x + vertical*nCoord.y);
@ -261,11 +267,11 @@ vec3 CalcRayDir(vec2 nCoord){
mat3 setCamera() mat3 setCamera()
{ {
vec3 cw = normalize(camDir); vec3 cw = normalize(camDir);
vec3 cp = vec3(0.0, 1.0 ,0.0); vec3 cp = vec3(0.0, 1.0 ,0.0);
vec3 cu = normalize( cross(cw,cp) ); vec3 cu = normalize(cross(cw,cp));
vec3 cv = ( cross(cu,cw) ); vec3 cv = (cross(cu,cw));
return mat3( cu, cv, cw ); return mat3(cu, cv, cw);
} }
void main() void main()
@ -275,14 +281,15 @@ void main()
// focal length // focal length
float fl = length(camDir); float fl = length(camDir);
vec3 rd = ca * normalize( vec3(nCoord,fl) ); vec3 rd = ca*normalize(vec3(nCoord,fl));
vec3 color = vec3(nCoord/2.0 + 0.5, 0.0); vec3 color = vec3(nCoord/2.0 + 0.5, 0.0);
float depth = gl_FragCoord.z; float depth = gl_FragCoord.z;
{ {
vec4 res = render( camPos - vec3(0.0, 0.0, 0.0) , rd ); vec4 res = render(camPos - vec3(0.0, 0.0, 0.0) , rd);
color = res.xyz; color = res.xyz;
depth = CalcDepth(rd,res.w); depth = CalcDepth(rd,res.w);
} }
gl_FragColor = vec4(color , 1.0); gl_FragColor = vec4(color , 1.0);
gl_FragDepthEXT = depth; gl_FragDepthEXT = depth;
} }

View file

@ -6,59 +6,58 @@ precision mediump float;
varying vec2 fragTexCoord; varying vec2 fragTexCoord;
varying vec4 fragColor; 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 c; // c.x = real, c.y = imaginary component. Equation done is z^2 + c
uniform vec2 offset; // Offset of the scale. uniform vec2 offset; // Offset of the scale
uniform float zoom; // Zoom of the scale. uniform float zoom; // Zoom of the scale
// NOTE: Maximum number of shader for-loop iterations depend on GPU, // NOTE: Maximum number of shader for-loop iterations depend on GPU,
// for example, on RasperryPi for this examply only supports up to 60 // for example, on RasperryPi for this examply only supports up to 60
const int MAX_ITERATIONS = 48; // Max iterations to do const int maxIterations = 255; // Max iterations to do.
const float colorCycles = 1.0; // Number of times the color palette repeats.
// Square a complex number // Square a complex number
vec2 ComplexSquare(vec2 z) vec2 ComplexSquare(vec2 z)
{ {
return vec2( return vec2(z.x*z.x - z.y*z.y, z.x*z.y*2.0);
z.x * z.x - z.y * z.y,
z.x * z.y * 2.0
);
} }
// Convert Hue Saturation Value (HSV) color into RGB // Convert Hue Saturation Value (HSV) color into RGB
vec3 Hsv2rgb(vec3 c) vec3 Hsv2rgb(vec3 c)
{ {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 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); 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); return c.z*mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
} }
void main() void main()
{ {
/********************************************************************************************** /**********************************************************************************************
Julia sets use a function z^2 + c, where c is a constant. Julia sets use a function z^2 + c, where c is a constant
This function is iterated until the nature of the point is determined. This function is iterated until the nature of the point is determined
If the magnitude of the number becomes greater than 2, then from that point onward If the magnitude of the number becomes greater than 2, then from that point onward
the number will get bigger and bigger, and will never get smaller (tends towards infinity). the number will get bigger and bigger, and will never get smaller (tends towards infinity)
2^2 = 4, 4^2 = 8 and so on. 2^2 = 4, 4^2 = 8 and so on
So at 2 we stop iterating. So at 2 we stop iterating
If the number is below 2, we keep iterating. If the number is below 2, we keep iterating
But when do we stop iterating if the number is always below 2 (it converges)? But when do we stop iterating if the number is always below 2 (it converges)?
That is what MAX_ITERATIONS is for. That is what maxIterations is for
Then we can divide the iterations by the MAX_ITERATIONS value to get a normalized value that we can Then we can divide the iterations by the maxIterations value to get a normalized value
then map to a color. that we can then map to a color
We use dot product (z.x * z.x + z.y * z.y) to determine the magnitude (length) squared. We use dot product (z.x*z.x + z.y*z.y) to determine the magnitude (length) squared
And once the magnitude squared is > 4, then magnitude > 2 is also true (saves computational power). And once the magnitude squared is > 4, then magnitude > 2 is also true (saves computational power)
*************************************************************************************************/ *************************************************************************************************/
// The pixel coordinates are scaled so they are on the mandelbrot scale // The pixel coordinates are scaled so they are on the mandelbrot scale
// NOTE: fragTexCoord already comes as normalized screen coordinates but offset must be normalized before scaling and zoom // 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); vec2 z = vec2((fragTexCoord.x - 0.5)*2.5, (fragTexCoord.y - 0.5)*1.5)/zoom;
z.x += offset.x;
z.y += offset.y;
int iter = 0; int iter = 0;
for (int iterations = 0; iterations < 60; iterations++) for (int iterations = 0; iterations < maxIterations; iterations++)
{ {
z = ComplexSquare(z) + c; // Iterate function z = ComplexSquare(z) + c; // Iterate function
if (dot(z, z) > 4.0) break; if (dot(z, z) > 4.0) break;
@ -66,18 +65,18 @@ void main()
iter = iterations; iter = iterations;
} }
// Another few iterations decreases errors in the smoothing calculation. // Another few iterations decreases errors in the smoothing calculation
// See http://linas.org/art-gallery/escape/escape.html for more information. // See http://linas.org/art-gallery/escape/escape.html for more information
z = ComplexSquare(z) + c; z = ComplexSquare(z) + c;
z = ComplexSquare(z) + c; z = ComplexSquare(z) + c;
// This last part smooths the color (again see link above). // This last part smooths the color (again see link above)
float smoothVal = float(iter) + 1.0 - (log(log(length(z)))/log(2.0)); float smoothVal = float(iter) + 1.0 - (log(log(length(z)))/log(2.0));
// Normalize the value so it is between 0 and 1. // Normalize the value so it is between 0 and 1
float norm = smoothVal/float(MAX_ITERATIONS); float norm = smoothVal/float(maxIterations);
// If in set, color black. 0.999 allows for some float accuracy error. // If in set, color black. 0.999 allows for some float accuracy error
if (norm > 0.999) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); if (norm > 0.999) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
else gl_FragColor = vec4(Hsv2rgb(vec3(norm, 1.0, 1.0)), 1.0); else gl_FragColor = vec4(Hsv2rgb(vec3(norm*colorCycles, 1.0, 1.0)), 1.0);
} }

View file

@ -12,18 +12,12 @@ varying vec3 fragNormal;
uniform sampler2D texture0; uniform sampler2D texture0;
uniform vec4 colDiffuse; uniform vec4 colDiffuse;
// NOTE: Add here your custom variables // NOTE: Add your custom variables here
#define MAX_LIGHTS 4 #define MAX_LIGHTS 4
#define LIGHT_DIRECTIONAL 0 #define LIGHT_DIRECTIONAL 0
#define LIGHT_POINT 1 #define LIGHT_POINT 1
struct MaterialProperty {
vec3 color;
int useSampler;
sampler2D sampler;
};
struct Light { struct Light {
int enabled; int enabled;
int type; int type;
@ -46,6 +40,8 @@ void main()
vec3 viewD = normalize(viewPos - fragPosition); vec3 viewD = normalize(viewPos - fragPosition);
vec3 specular = vec3(0.0); vec3 specular = vec3(0.0);
vec4 tint = colDiffuse*fragColor;
// NOTE: Implement here your fragment shader code // NOTE: Implement here your fragment shader code
for (int i = 0; i < MAX_LIGHTS; i++) for (int i = 0; i < MAX_LIGHTS; i++)
@ -73,7 +69,7 @@ void main()
} }
} }
vec4 finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0))); vec4 finalColor = (texelColor*((tint + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
finalColor += texelColor*(ambient/10.0); finalColor += texelColor*(ambient/10.0);
// Gamma correction // Gamma correction

View file

@ -16,7 +16,7 @@ varying vec2 fragTexCoord;
varying vec4 fragColor; varying vec4 fragColor;
varying vec3 fragNormal; varying vec3 fragNormal;
// NOTE: Add here your custom variables // NOTE: Add your custom variables here
// https://github.com/glslify/glsl-inverse // https://github.com/glslify/glsl-inverse
mat3 inverse(mat3 m) mat3 inverse(mat3 m)

View file

@ -18,7 +18,7 @@ varying vec2 fragTexCoord;
varying vec4 fragColor; varying vec4 fragColor;
varying vec3 fragNormal; varying vec3 fragNormal;
// NOTE: Add here your custom variables // NOTE: Add your custom variables here
void main() void main()
{ {

View file

@ -12,7 +12,7 @@ uniform sampler2D mask;
uniform vec4 colDiffuse; uniform vec4 colDiffuse;
uniform int frame; uniform int frame;
// NOTE: Add here your custom variables // NOTE: Add your custom variables here
void main() void main()
{ {

Some files were not shown because too many files have changed in this diff Show more