From 0edde43422301dad92e4e7fef3562d61f02cb0b2 Mon Sep 17 00:00:00 2001 From: rz5 Date: Wed, 28 Sep 2016 22:12:43 +0100 Subject: [PATCH] Update mudlord-emeraldenvy4.slang --- procedural/mudlord-emeraldenvy4.slang | 135 ++++++++++++++------------ 1 file changed, 72 insertions(+), 63 deletions(-) diff --git a/procedural/mudlord-emeraldenvy4.slang b/procedural/mudlord-emeraldenvy4.slang index 9920ab7..6b097aa 100644 --- a/procedural/mudlord-emeraldenvy4.slang +++ b/procedural/mudlord-emeraldenvy4.slang @@ -1,11 +1,11 @@ #version 450 layout(std140, set = 0, binding = 0) uniform UBO { - mat4 MVP; - vec4 OutputSize; - vec4 OriginalSize; - vec4 SourceSize; - uint FrameCount; + mat4 MVP; + vec4 OutputSize; + vec4 OriginalSize; + vec4 SourceSize; + uint FrameCount; } global; #pragma stage vertex @@ -13,91 +13,100 @@ layout(location = 0) in vec4 Position; layout(location = 1) in vec2 TexCoord; layout(location = 0) out vec2 vTexCoord; const vec2 madd = vec2(0.5, 0.5); + void main() { - gl_Position = global.MVP * Position; - vTexCoord = gl_Position.xy; + gl_Position = global.MVP * Position; + vTexCoord = gl_Position.xy; } #pragma stage fragment layout(location = 0) in vec2 vTexCoord; layout(location = 0) out vec4 FragColor; -float time = float(global.FrameCount)*0.0325; +float time = float(global.FrameCount)*0.0325; vec2 resolution = global.OutputSize.xy; -float fade = 0.45; +float fade = 0.45; -const float PI=3.14159265358979323846; +const float PI = 3.14159265358979323846; -float speed=time*0.25; -float ground_x=0.125-0.25*cos(PI*speed*0.25); -float ground_y=0.125+0.25*sin(PI*speed*0.25); -float ground_z=speed*0.125; +float speed = time*0.25; +float ground_x = 0.125 - 0.25*cos(PI*speed*0.25); +float ground_y = 0.125 + 0.25*sin(PI*speed*0.25); +float ground_z = speed*0.125; 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 ball_p=0.25; - float ball_w=ball_p*1.0; - float ball=length(mod(p.xyz,ball_p)-ball_p*0.5)-ball_w; - float hole_w=ball_p*0.55; - float hole=length(mod(p.xyz,ball_p)-ball_p*0.5)-hole_w; - float pipe_p=0.015; - 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_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))); - } +{ + float ball_p = 0.25; + float ball_w = ball_p*1.0; + float ball = length(mod(p.xyz,ball_p)-ball_p*0.5)-ball_w; + float hole_w = ball_p*0.55; + float hole = length(mod(p.xyz,ball_p)-ball_p*0.5)-hole_w; + float pipe_p = 0.015; + 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_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))); +} + +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 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) ) ); - } float render_scene(vec3 ray_origin, vec3 ray_dir,float t) { const int ray_n=96; - for(int i=0;i