From 789895b4b9f99668b8b772f271d07d1ce3115742 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 5 Oct 2018 15:40:31 +0800 Subject: *update --- bin/Jin.exe | Bin 572928 -> 498176 bytes bin/font.ttf | Bin 0 -> 9753284 bytes bin/jin.exe | Bin 572928 -> 498176 bytes bin/main.lua | 36 ++++---- bin/metaball.shader | 231 ++++------------------------------------------------ bin/text.txt | 1 + 6 files changed, 37 insertions(+), 231 deletions(-) create mode 100644 bin/font.ttf create mode 100644 bin/text.txt (limited to 'bin') diff --git a/bin/Jin.exe b/bin/Jin.exe index 6305b49..ba89bf2 100644 Binary files a/bin/Jin.exe and b/bin/Jin.exe differ diff --git a/bin/font.ttf b/bin/font.ttf new file mode 100644 index 0000000..ac64abe Binary files /dev/null and b/bin/font.ttf differ diff --git a/bin/jin.exe b/bin/jin.exe index 6305b49..ba89bf2 100644 Binary files a/bin/jin.exe and b/bin/jin.exe differ diff --git a/bin/main.lua b/bin/main.lua index eeec09e..f4e586a 100644 --- a/bin/main.lua +++ b/bin/main.lua @@ -4,17 +4,27 @@ local img local img2 local canvas local sw, sh = jin.graphics.getSize() +local page +local fontdata +local font + function jin.core.onLoad() local str = jin.filesystem.read("metaball.shader") shader = jin.graphics.newShader(str) local w, h = 256, 240 - local bitmap = jin.graphics.newBitmap(w, h, {255, 255, 0, 255}) + local bitmap = jin.graphics.newBitmap(w, h, {255, 0, 255, 255}) local b = bitmap:clone() bitmap = nil - -- local bitmap2 = jin.graphics.newBitmap("img2.bmp") - img = jin.graphics.newTexture(b) - -- img2 = jin.graphics.newTexture(bitmap2) - canvas = jin.graphics.newCanvas(200, 200) + local bitmap2 = jin.graphics.newBitmap("img2.bmp") + img2 = jin.graphics.newTexture(b) + img = jin.graphics.newTexture(bitmap2) + canvas = jin.graphics.newCanvas(200, 100) + + fontdata = jin.graphics.newFontData("font.ttf") + font = fontdata:newFont(15) + local str = jin.filesystem.read("text.txt") + page = font:typeset(str, 17, 0) + fontdata = nil end -- extern vec3 iResolution; -- extern number iGlobalTime; @@ -40,13 +50,11 @@ end 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.draw(img, 0, 0, 1, 1) - jin.graphics.unuseShader() - jin.graphics.unbindCanvas() - jin.graphics.draw(canvas, 0, 0, 2, 2) + --jin.graphics.useShader(shader) + -- jin.graphics.unuseShader() + jin.graphics.useShader(shader) + shader:sendNumber("dt", dt) + --jin.graphics.draw(canvas, 0, 0, 2, 2) + font:print(page, 0, 0) + -- jin.graphics.unuseShader() end \ No newline at end of file diff --git a/bin/metaball.shader b/bin/metaball.shader index 631ed93..7d3b759 100644 --- a/bin/metaball.shader +++ b/bin/metaball.shader @@ -1,227 +1,24 @@ -extern vec3 iResolution; -extern number iGlobalTime; -extern vec4 iMouse; +#VERTEX_SHADER +uniform float dt; -/*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 +Vertex vert(Vertex v) { - return max(a,max(b,c)); + if(v.xy.x > 3) + v.xy += vec2(100, 100) * sin(dt); + return v; } -vec3 bpos[object_count];//position for each metaball +#END_VERTEX_SHADER -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 +#END_FRAGMENT_SHADER \ No newline at end of file diff --git a/bin/text.txt b/bin/text.txt new file mode 100644 index 0000000..33c6055 --- /dev/null +++ b/bin/text.txt @@ -0,0 +1 @@ +开始 \ No newline at end of file -- cgit v1.1-26-g67d0