diff options
author | chai <chaifix@163.com> | 2018-09-08 14:57:29 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-09-08 14:57:29 +0800 |
commit | 93696c0c85afc21e29c7bd57dc9c577a7d662bba (patch) | |
tree | 91187a3bf937cbd161162efc6f3df445c9c3b876 | |
parent | 7c3609b04eabc79db0c0b245a155fc3c5e875053 (diff) |
*update
-rw-r--r-- | bin/Jin.exe | bin | 1417728 -> 552960 bytes | |||
-rw-r--r-- | bin/jin.exe | bin | 1417728 -> 552960 bytes | |||
-rw-r--r-- | bin/main.lua | 18 | ||||
-rw-r--r-- | bin/metaball.shader | 227 | ||||
-rw-r--r-- | build/vc++/jin.rc | bin | 3340 -> 3250 bytes | |||
-rw-r--r-- | build/vc++/jin.vcxproj | 6 | ||||
-rw-r--r-- | build/vc++/libjin/libjin.vcxproj | 4 | ||||
-rw-r--r-- | build/vc++/libjin/libjin.vcxproj.filters | 6 | ||||
-rw-r--r-- | src/libjin/Common/Subsystem.hpp | 3 | ||||
-rw-r--r-- | src/libjin/Filesystem/Buffer.h | 1 | ||||
-rw-r--r-- | src/libjin/Filesystem/Filesystem.h | 1 |
11 files changed, 247 insertions, 19 deletions
diff --git a/bin/Jin.exe b/bin/Jin.exe Binary files differindex 2650fea..90fe1d9 100644 --- a/bin/Jin.exe +++ b/bin/Jin.exe diff --git a/bin/jin.exe b/bin/jin.exe Binary files differindex 2650fea..90fe1d9 100644 --- a/bin/jin.exe +++ b/bin/jin.exe 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 ;i<object_count; i++) + { + vec3 np = p+bpos[i]; + number shape0 = max3(abs(np.x),abs(np.y),abs(np.z))-1.0; + number shape1 = length(np)-1.0; + nd = shape0+(shape1-shape0)*2.0; + d = mix(d,nd,smoothstep(-1.0,+1.0,d-nd)); + } + return d; +} + +vec3 normal(vec3 p,number e) //returns the normal, uses the distance function +{ + number d=dist(p); + return normalize(vec3(dist(p+vec3(e,0,0))-d,dist(p+vec3(0,e,0))-d,dist(p+vec3(0,0,e))-d)); +} + +vec3 light = light_direction; //global variable that holds light direction + +vec3 background(vec3 d)//render background +{ + number t=iGlobalTime*0.5*light_speed_modifier; + number qq = dot(d,light)*.5+.5; + number bgl = qq; + number q = (bgl+noise(bgl*6.0+t)*.85+noise(bgl*12.0+t)*.85); + q+= pow(qq,32.0)*2.0; + vec3 sky = vec3(0.1,0.4,0.6)*q; + return sky; +} + +number occlusion(vec3 p, vec3 d)//returns how much a point is visible from a given direction +{ + number occ = 1.0; + p=p+d; + for (int i=0; i<occlusion_quality; i++) + { + number dd = dist(p); + p+=d*dd; + occ = min(occ,dd); + } + return max(.0,occ); +} + +vec3 object_material(vec3 p, vec3 d) +{ + vec3 color = normalize(object_color*light_color); + vec3 n = normal(p,0.1); + vec3 r = reflect(d,n); + + number reflectance = dot(d,r)*.5+.5;reflectance=pow(reflectance,2.0); + number diffuse = dot(light,n)*.5+.5; diffuse = max(.0,diffuse); + + #ifdef occlusion_enabled + number oa = occlusion(p,n)*.4+.6; + number od = occlusion(p,light)*.95+.05; + number os = occlusion(p,r)*.95+.05; + #else + number oa=1.0; + number ob=1.0; + number oc=1.0; + #endif + + #ifndef occlusion_preview + color = + color*oa*.2 + //ambient + color*diffuse*od*.7 + //diffuse + background(r)*os*reflectance*.7; //reflection + #else + color=vec3((oa+od+os)*.3); + #endif + + return color; +} + +#define offset1 4.7 +#define offset2 4.6 + +void mainImage( out vec4 fragColor, in vec2 fragCoord ) +{ + vec2 uv = fragCoord.xy / iResolution.xy - 0.5; + uv.x *= iResolution.x/iResolution.y; //fix aspect ratio + vec3 mouse = vec3(iMouse.xy/iResolution.xy - 0.5,iMouse.z-.5); + + number t = iGlobalTime*.5*object_speed_modifier + 2.0; + + for (int i=0 ;i<object_count; i++) //position for each metaball + { + bpos[i] = 1.3*vec3( + sin(t*0.967+number(i)*42.0), + sin(t*.423+number(i)*152.0), + sin(t*.76321+number(i))); + } + + //setup the camera + vec3 p = vec3(.0,0.0,-4.0); + p = rotate_x(p,mouse.y*9.0+offset1); + p = rotate_y(p,mouse.x*9.0+offset2); + vec3 d = vec3(uv,1.0); + d.z -= length(d)*.5; //lens distort + d = normalize(d); + d = rotate_x(d,mouse.y*9.0+offset1); + d = rotate_y(d,mouse.x*9.0+offset2); + + //and action! + number dd; + vec3 color; + for (int i=0; i<render_steps; i++) //raymarch + { + dd = dist(p); + p+=d*dd*.7; + if (dd<.04 || dd>4.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 Binary files differindex 5a3a57f..8eb79c8 100644 --- a/build/vc++/jin.rc +++ b/build/vc++/jin.rc 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 @@ <PropertyGroup Label="Globals"> <ProjectGuid>{A3E35ECA-62EB-45CE-8152-674FBC7F7A3B}</ProjectGuid> <RootNamespace>jin</RootNamespace> - <WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion> + <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> <ProjectName>jin(min version)</ProjectName> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> @@ -93,7 +93,7 @@ <Link> <AdditionalDependencies>opengl32.lib;glu32.lib;lua51.lib;SDL2main.lib;SDL2.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalLibraryDirectories>$(SolutionDir)libs\SDL2-2.0.5\lib\x86;$(SolutionDir)libs\LuaJIT-2.0.5\src;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> - <SubSystem>Console</SubSystem> + <SubSystem>Windows</SubSystem> <EntryPointSymbol> </EntryPointSymbol> </Link> @@ -123,7 +123,7 @@ <OptimizeReferences>true</OptimizeReferences> <AdditionalDependencies>opengl32.lib;glu32.lib;lua51.lib;SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalLibraryDirectories>$(SolutionDir)libs\SDL2-2.0.5\lib\x86;$(SolutionDir)libs\LuaJIT-2.0.5\src;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> - <SubSystem>Console</SubSystem> + <SubSystem>Windows</SubSystem> <EntryPointSymbol> </EntryPointSymbol> </Link> 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 @@ <VCProjectVersion>15.0</VCProjectVersion> <ProjectGuid>{9EE02090-C15E-4520-9C05-C435E45EF2FC}</ProjectGuid> <RootNamespace>libjin</RootNamespace> - <WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion> + <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> <ProjectName>libjin(min version)</ProjectName> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> @@ -141,6 +141,8 @@ <ClInclude Include="..\..\..\src\libjin\Audio\SDL\SDLAudio.h" /> <ClInclude Include="..\..\..\src\libjin\Audio\SDL\SDLSource.h" /> <ClInclude Include="..\..\..\src\libjin\Audio\Source.h" /> + <ClInclude Include="..\..\..\src\libjin\Common\Array.hpp" /> + <ClInclude Include="..\..\..\src\libjin\Common\common.h" /> <ClInclude Include="..\..\..\src\libjin\Common\Object.h" /> <ClInclude Include="..\..\..\src\libjin\Common\Singleton.hpp" /> <ClInclude Include="..\..\..\src\libjin\Common\StringMap.hpp" /> 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 @@ <ClInclude Include="..\..\..\src\libjin\jin.h"> <Filter>Source</Filter> </ClInclude> + <ClInclude Include="..\..\..\src\libjin\Common\Array.hpp"> + <Filter>Source\Common</Filter> + </ClInclude> + <ClInclude Include="..\..\..\src\libjin\Common\common.h"> + <Filter>Source\Common</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="..\..\..\src\libjin\README.md"> 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); |