From 93696c0c85afc21e29c7bd57dc9c577a7d662bba Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 8 Sep 2018 14:57:29 +0800 Subject: *update --- bin/Jin.exe | Bin 1417728 -> 552960 bytes bin/jin.exe | Bin 1417728 -> 552960 bytes bin/main.lua | 18 ++--- bin/metaball.shader | 227 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 233 insertions(+), 12 deletions(-) create mode 100644 bin/metaball.shader (limited to 'bin') diff --git a/bin/Jin.exe b/bin/Jin.exe index 2650fea..90fe1d9 100644 Binary files a/bin/Jin.exe and b/bin/Jin.exe differ diff --git a/bin/jin.exe b/bin/jin.exe index 2650fea..90fe1d9 100644 Binary files a/bin/jin.exe and b/bin/jin.exe differ diff --git a/bin/main.lua b/bin/main.lua index 3f6847a..a8663f6 100644 --- a/bin/main.lua +++ b/bin/main.lua @@ -7,16 +7,10 @@ local sw, sh = jin.graphics.getSize() function jin.core.onLoad() local str = jin.filesystem.read("metaball.shader") shader = jin.graphics.newShader(str) - if shader == nil then - print(jin.error) - end local w, h = 256, 240 local bitmap = jin.graphics.newBitmap(w, h, {255, 255, 0, 255}) local b = bitmap:clone() - local b2= jin.graphics.newBitmap("asdasd") - if b2 == nil then - print(jin.error) - end + bitmap = nil -- local bitmap2 = jin.graphics.newBitmap("img2.bmp") img = jin.graphics.newTexture(b) -- img2 = jin.graphics.newTexture(bitmap2) @@ -47,12 +41,12 @@ local dt = 0 function jin.core.onDraw() dt = dt + 0.1 jin.graphics.bindCanvas(canvas) - -- jin.graphics.useShader(shader) - -- shader:sendNumber("iGlobalTime", dt ) - -- shader:sendVec3("iResolution", sw, sh, 1) - -- shader:sendVec4("iMouse", mx, my, mx, my) + jin.graphics.useShader(shader) + shader:sendNumber("iGlobalTime", dt ) + shader:sendVec3("iResolution", sw, sh, 1) + shader:sendVec4("iMouse", mx, my, mx, my) jin.graphics.draw(img, 0, 0, 1, 1) - -- jin.graphics.unuseShader() + jin.graphics.unuseShader() jin.graphics.unbindCanvas() jin.graphics.draw(canvas, 0, 0, 1, 1) end \ No newline at end of file diff --git a/bin/metaball.shader b/bin/metaball.shader new file mode 100644 index 0000000..631ed93 --- /dev/null +++ b/bin/metaball.shader @@ -0,0 +1,227 @@ +extern vec3 iResolution; +extern number iGlobalTime; +extern vec4 iMouse; + +/*by mu6k, Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. + I have no idea how I ended up here, but it demosceneish enough to publish. + You can use the mouse to rotate the camera around the 'object'. + If you can't see the shadows, increase occlusion_quality. + If it doesn't compile anymore decrease object_count and render_steps. + 15/06/2013: + - published + 16/06/2013: + - modified for better performance and compatibility + muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusk!*/ + +#define occlusion_enabled +#define occlusion_quality 4 +//#define occlusion_preview + +#define noise_use_smoothstep + +#define light_color vec3(0.1,0.4,0.6) +#define light_direction normalize(vec3(.2,1.0,-0.2)) +#define light_speed_modifier 1.0 + +#define object_color vec3(0.9,0.1,0.1) +#define object_count 9 +#define object_speed_modifier 1.0 + +#define render_steps 33 + +number hash(number x) +{ + return fract(sin(x*.0127863)*17143.321); +} + +number hash(vec2 x) +{ + return fract(cos(dot(x.xy,vec2(2.31,53.21))*124.123)*412.0); +} + +vec3 cc(vec3 color, number factor,number factor2) //a wierd color modifier +{ + number w = color.x+color.y+color.z; + return mix(color,vec3(w)*factor,w*factor2); +} + +number hashmix(number x0, number x1, number interp) +{ + x0 = hash(x0); + x1 = hash(x1); + #ifdef noise_use_smoothstep + interp = smoothstep(0.0,1.0,interp); + #endif + return mix(x0,x1,interp); +} + +number noise(number p) // 1D noise +{ + number pm = mod(p,1.0); + number pd = p-pm; + return hashmix(pd,pd+1.0,pm); +} + +vec3 rotate_y(vec3 v, number angle) +{ + number ca = cos(angle); number sa = sin(angle); + return v*mat3( + +ca, +.0, -sa, + +.0,+1.0, +.0, + +sa, +.0, +ca); +} + +vec3 rotate_x(vec3 v, number angle) +{ + number ca = cos(angle); number sa = sin(angle); + return v*mat3( + +1.0, +.0, +.0, + +.0, +ca, -sa, + +.0, +sa, +ca); +} + +number max3(number a, number b, number c)//returns the maximum of 3 values +{ + return max(a,max(b,c)); +} + +vec3 bpos[object_count];//position for each metaball + +number dist(vec3 p)//distance function +{ + number d=1024.0; + number nd; + for (int i=0 ;i4.0) break; + } + + if (dd<0.5) //close enough + color = object_material(p,d); + else + color = background(d); + + //post procesing + color *=.85; + color = mix(color,color*color,0.3); + color -= hash(color.xy+uv.xy)*.015; + color -= length(uv)*.1; + color =cc(color,.5,.6); + fragColor = vec4(color,1.0); +} + + + +vec4 effect(vec4 color, Texture texture, vec2 texture_coords, vec2 pixel_coords){ + vec2 fragCoord = texture_coords * iResolution.xy; + mainImage( color, fragCoord ); + return color; +} \ No newline at end of file -- cgit v1.1-26-g67d0