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 +++++++++++++++++++++++++++++++ build/vc++/jin.rc | Bin 3340 -> 3250 bytes build/vc++/jin.vcxproj | 6 +- build/vc++/libjin/libjin.vcxproj | 4 +- build/vc++/libjin/libjin.vcxproj.filters | 6 + src/libjin/Common/Subsystem.hpp | 3 +- src/libjin/Filesystem/Buffer.h | 1 - src/libjin/Filesystem/Filesystem.h | 1 + 11 files changed, 247 insertions(+), 19 deletions(-) create mode 100644 bin/metaball.shader 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 diff --git a/build/vc++/jin.rc b/build/vc++/jin.rc index 5a3a57f..8eb79c8 100644 Binary files a/build/vc++/jin.rc and b/build/vc++/jin.rc differ diff --git a/build/vc++/jin.vcxproj b/build/vc++/jin.vcxproj index ab26905..2fd6086 100644 --- a/build/vc++/jin.vcxproj +++ b/build/vc++/jin.vcxproj @@ -21,7 +21,7 @@ {A3E35ECA-62EB-45CE-8152-674FBC7F7A3B} jin - 10.0.14393.0 + 8.1 jin(min version) @@ -93,7 +93,7 @@ opengl32.lib;glu32.lib;lua51.lib;SDL2main.lib;SDL2.lib;%(AdditionalDependencies) $(SolutionDir)libs\SDL2-2.0.5\lib\x86;$(SolutionDir)libs\LuaJIT-2.0.5\src;%(AdditionalLibraryDirectories) - Console + Windows @@ -123,7 +123,7 @@ true opengl32.lib;glu32.lib;lua51.lib;SDL2.lib;SDL2main.lib;%(AdditionalDependencies) $(SolutionDir)libs\SDL2-2.0.5\lib\x86;$(SolutionDir)libs\LuaJIT-2.0.5\src;%(AdditionalLibraryDirectories) - Console + Windows diff --git a/build/vc++/libjin/libjin.vcxproj b/build/vc++/libjin/libjin.vcxproj index fe5bdb6..dc0ed9b 100644 --- a/build/vc++/libjin/libjin.vcxproj +++ b/build/vc++/libjin/libjin.vcxproj @@ -22,7 +22,7 @@ 15.0 {9EE02090-C15E-4520-9C05-C435E45EF2FC} libjin - 10.0.14393.0 + 8.1 libjin(min version) @@ -141,6 +141,8 @@ + + diff --git a/build/vc++/libjin/libjin.vcxproj.filters b/build/vc++/libjin/libjin.vcxproj.filters index 8cf8ffd..b96ecf5 100644 --- a/build/vc++/libjin/libjin.vcxproj.filters +++ b/build/vc++/libjin/libjin.vcxproj.filters @@ -219,6 +219,12 @@ Source + + Source\Common + + + Source\Common + diff --git a/src/libjin/Common/Subsystem.hpp b/src/libjin/Common/Subsystem.hpp index 70dd4ba..78f4e01 100644 --- a/src/libjin/Common/Subsystem.hpp +++ b/src/libjin/Common/Subsystem.hpp @@ -28,12 +28,11 @@ namespace jin } protected: + SINGLETON(System); Subsystem() {}; virtual ~Subsystem() {}; - SINGLETON(System); - /*onlyonce*/ virtual bool initSystem(const Setting* setting) = 0; /*onlyonce*/ virtual void quitSystem() = 0; diff --git a/src/libjin/Filesystem/Buffer.h b/src/libjin/Filesystem/Buffer.h index 5cb6468..15ea665 100644 --- a/src/libjin/Filesystem/Buffer.h +++ b/src/libjin/Filesystem/Buffer.h @@ -47,7 +47,6 @@ namespace filesystem memcpy(data, buffer.data, size); } - public: void* data; unsigned int size; diff --git a/src/libjin/Filesystem/Filesystem.h b/src/libjin/Filesystem/Filesystem.h index 17b3e0b..ffc0c52 100644 --- a/src/libjin/Filesystem/Filesystem.h +++ b/src/libjin/Filesystem/Filesystem.h @@ -12,6 +12,7 @@ namespace filesystem static Filesystem* get(); Filesystem(); + bool isDir(const char* path); bool isFile(const char* path); bool exists(const char* path); -- cgit v1.1-26-g67d0