mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-29 19:01:31 +11:00
Merge branch 'master' of https://github.com/libretro/slang-shaders
This commit is contained in:
commit
3e1b418f7c
|
@ -13,6 +13,7 @@ layout(location = 0) in vec4 Position;
|
||||||
layout(location = 1) in vec2 TexCoord;
|
layout(location = 1) in vec2 TexCoord;
|
||||||
layout(location = 0) out vec2 vTexCoord;
|
layout(location = 0) out vec2 vTexCoord;
|
||||||
const vec2 madd = vec2(0.5, 0.5);
|
const vec2 madd = vec2(0.5, 0.5);
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = global.MVP * Position;
|
gl_Position = global.MVP * Position;
|
||||||
|
@ -39,7 +40,6 @@ vec2 rotate(vec2 k,float t)
|
||||||
return vec2(cos(t)*k.x - sin(t)*k.y, sin(t)*k.x + cos(t)*k.y);
|
return vec2(cos(t)*k.x - sin(t)*k.y, sin(t)*k.x + cos(t)*k.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float scene(vec3 p)
|
float scene(vec3 p)
|
||||||
{
|
{
|
||||||
float ball_p = 0.25;
|
float ball_p = 0.25;
|
||||||
|
@ -51,26 +51,30 @@ float scene(vec3 p)
|
||||||
float pipe_w = pipe_p*0.42; //-0.00375*sync;
|
float pipe_w = pipe_p*0.42; //-0.00375*sync;
|
||||||
float pipe_y = length(max(abs(mod(p.xy, pipe_p) - pipe_p*0.5) - pipe_w,0.0));
|
float pipe_y = length(max(abs(mod(p.xy, pipe_p) - pipe_p*0.5) - pipe_w,0.0));
|
||||||
float pipe_z = length(max(abs(mod(p.xz, pipe_p) - pipe_p*0.5) - pipe_w,0.0));
|
float pipe_z = length(max(abs(mod(p.xz, pipe_p) - pipe_p*0.5) - pipe_w,0.0));
|
||||||
|
|
||||||
return max(max(ball, -hole), max(pipe_y, max(pipe_y, pipe_z)));
|
return max(max(ball, -hole), max(pipe_y, max(pipe_y, pipe_z)));
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 getNormal(vec3 pos)
|
vec3 getNormal(vec3 pos)
|
||||||
{ vec3 e = vec3(0.0,0.0001,0.0);
|
{
|
||||||
return normalize(vec3( scene(pos+e.yxx)-scene(pos-e.yxx),scene(pos+e.xyx)-scene(pos-e.xyx),scene(pos+e.xxy)-scene(pos-e.xxy) ) );
|
vec3 e = vec3(0.0, 0.0001, 0.0);
|
||||||
|
|
||||||
|
return normalize(vec3(scene(pos + e.yxx) - scene(pos - e.yxx),
|
||||||
|
scene(pos + e.xyx) - scene(pos - e.xyx),
|
||||||
|
scene(pos + e.xxy) - scene(pos - e.xxy)));
|
||||||
}
|
}
|
||||||
|
|
||||||
float render_scene(vec3 ray_origin, vec3 ray_dir, float t)
|
float render_scene(vec3 ray_origin, vec3 ray_dir, float t)
|
||||||
{
|
{
|
||||||
const int ray_n = 96;
|
const int ray_n = 96;
|
||||||
for (int i = 0; i < ray_n; i++)
|
for (int i = 0; i < ray_n; i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
float k = scene(ray_origin + ray_dir*t);
|
float k = scene(ray_origin + ray_dir*t);
|
||||||
t += k*fade;
|
t += k*fade;
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
vec2 FragCoord = vTexCoord.xy*global.OutputSize.xy;
|
vec2 FragCoord = vTexCoord.xy*global.OutputSize.xy;
|
||||||
|
@ -78,6 +82,7 @@ void main(void)
|
||||||
|
|
||||||
vec2 position = (FragCoord.xy/resolution.xy);
|
vec2 position = (FragCoord.xy/resolution.xy);
|
||||||
vec2 p = -1.0 + 2.0*position;
|
vec2 p = -1.0 + 2.0*position;
|
||||||
|
|
||||||
//set up camera
|
//set up camera
|
||||||
float speed = time*0.5;
|
float speed = time*0.5;
|
||||||
vec3 dir = normalize(vec3(p*vec2(1.0, 1.0), 1.));
|
vec3 dir = normalize(vec3(p*vec2(1.0, 1.0), 1.));
|
||||||
|
@ -85,13 +90,16 @@ void main(void)
|
||||||
dir.zx = rotate(dir.zx,PI*1.0*cos(speed*0.25)); // rotation y
|
dir.zx = rotate(dir.zx,PI*1.0*cos(speed*0.25)); // rotation y
|
||||||
dir.xy = rotate(dir.xy, -speed*0.5); // rotation z
|
dir.xy = rotate(dir.xy, -speed*0.5); // rotation z
|
||||||
vec3 ray = vec3(ground_x, ground_y, ground_z);
|
vec3 ray = vec3(ground_x, ground_y, ground_z);
|
||||||
|
|
||||||
//the raymarch
|
//the raymarch
|
||||||
float t = 0.0;
|
float t = 0.0;
|
||||||
t = render_scene(ray, dir, t);
|
t = render_scene(ray, dir, t);
|
||||||
vec3 hit = ray + dir*t;
|
vec3 hit = ray + dir*t;
|
||||||
t += hit.x;
|
t += hit.x;
|
||||||
|
|
||||||
//get normal for reflection
|
//get normal for reflection
|
||||||
vec3 n = getNormal(hit);
|
vec3 n = getNormal(hit);
|
||||||
|
|
||||||
//render reflection
|
//render reflection
|
||||||
dir = reflect(dir, n);
|
dir = reflect(dir, n);
|
||||||
dir = normalize(refract(dir, n, .82));
|
dir = normalize(refract(dir, n, .82));
|
||||||
|
@ -99,5 +107,6 @@ void main(void)
|
||||||
float c = (n.x*1.0 + n.y + n.z)*0.5;
|
float c = (n.x*1.0 + n.y + n.z)*0.5;
|
||||||
vec3 color = vec3(0., c*t*0.125*p.x + t*0.1, c*t*0.);
|
vec3 color = vec3(0., c*t*0.125*p.x + t*0.1, c*t*0.);
|
||||||
color *= 2.412;
|
color *= 2.412;
|
||||||
|
|
||||||
FragColor = vec4(color, 1.0);
|
FragColor = vec4(color, 1.0);
|
||||||
}
|
}
|
Loading…
Reference in a new issue