aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-05-16 15:02:43 +0800
committerchai <chaifix@163.com>2018-05-16 15:02:43 +0800
commitfdaf0e7eb6b9d9bdd7d5ab5f814f4ebbf791ff67 (patch)
tree6b9712381d6bce07554491acf900ec4b27e6ecb0 /test
v0.1.0
Diffstat (limited to 'test')
-rw-r--r--test/README7
-rw-r--r--test/dynamic_light/config.lua7
-rw-r--r--test/dynamic_light/main.lua61
-rw-r--r--test/dynamic_light/treestump.pngbin0 -> 4518 bytes
-rw-r--r--test/dynamic_light/treestump_diffuse.pngbin0 -> 581 bytes
-rw-r--r--test/dynamic_light/treestump_lines.pngbin0 -> 324 bytes
6 files changed, 75 insertions, 0 deletions
diff --git a/test/README b/test/README
new file mode 100644
index 0000000..f017cfe
--- /dev/null
+++ b/test/README
@@ -0,0 +1,7 @@
+usage
+
+ jin <game directory> [-d]
+
+for example
+
+ jin test -d
diff --git a/test/dynamic_light/config.lua b/test/dynamic_light/config.lua
new file mode 100644
index 0000000..cf4d721
--- /dev/null
+++ b/test/dynamic_light/config.lua
@@ -0,0 +1,7 @@
+local config = {}
+
+config.width = 500
+config.height = 400
+config.fps = 60
+
+return config
diff --git a/test/dynamic_light/main.lua b/test/dynamic_light/main.lua
new file mode 100644
index 0000000..0920687
--- /dev/null
+++ b/test/dynamic_light/main.lua
@@ -0,0 +1,61 @@
+local shader = [[
+extern Image diffuse;
+extern number mx;
+extern number my;
+
+vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
+{
+ vec3 light_vec = vec3(mx ,my,1);
+ vec3 light_direction = light_vec - vec3(pixel_coords, 0);
+ float distance = length(light_direction);
+ light_direction = normalize(light_direction);
+
+ vec3 normal = Texel(texture, texture_coords).xyz;
+ normal.y = 1 - normal.y;
+ normal = normalize(mix(vec3(-1), vec3(1), normal));
+
+ //float attenuation = 1/(7e-5*pow(distance, 2));
+ float attenuation = 5000/pow(distance, 2);
+ //float attenuation = 1;
+
+ float diffuse_term = clamp(attenuation * dot(normal, light_direction), 0.0, 1.0);
+
+ vec3 dark_color = vec3(0.0, 0.0, 1);
+ //vec3 light_color = vec3(0.6, 0.6, 0.0);
+ vec3 light_color = vec3(0.8, 0.8, 0.0);
+ vec3 ambient = mix(dark_color, light_color, diffuse_term) * 0.20;
+
+ // the shaded cel has a light value of 0.5, the light cel has a light value of 1
+ float cel_diffuse_term = smoothstep(0.49, 0.52, diffuse_term)/2 + 0.5;
+ //float cel_diffuse_term = step(0.5, diffuse_term)/2 + 0.5;
+
+ return vec4((cel_diffuse_term * Texel(diffuse, texture_coords).rgb) + ambient, Texel(texture, texture_coords).a);
+ //return vec4(ambient+Texel(diffuse, texture_coords).rgb/100, Texel(texture, texture_coords).a);
+
+}
+]]
+
+local jg = jin.graphics
+local effect = jg.Shader(shader)
+local diffuse = jg.Image("treestump_diffuse.png")
+local img = jg.Image("treestump.png")
+
+jin.core.onEvent = function(e)
+ if e.type == "quit" then
+ jin.core.quit()
+ end
+end
+
+jin.core.onUpdate = function()
+ local mx, my = jin.mouse.position()
+ my = 400 - my
+ effect:send("number", "mx", mx)
+ effect:send("number", "my", my)
+end
+
+jin.core.onDraw = function()
+ effect:send("Image", "diffuse", diffuse);
+ jg.use(effect)
+ jg.draw(img, 250, 200, 5, 5)
+
+end
diff --git a/test/dynamic_light/treestump.png b/test/dynamic_light/treestump.png
new file mode 100644
index 0000000..45d8d28
--- /dev/null
+++ b/test/dynamic_light/treestump.png
Binary files differ
diff --git a/test/dynamic_light/treestump_diffuse.png b/test/dynamic_light/treestump_diffuse.png
new file mode 100644
index 0000000..272e6a2
--- /dev/null
+++ b/test/dynamic_light/treestump_diffuse.png
Binary files differ
diff --git a/test/dynamic_light/treestump_lines.png b/test/dynamic_light/treestump_lines.png
new file mode 100644
index 0000000..293a757
--- /dev/null
+++ b/test/dynamic_light/treestump_lines.png
Binary files differ