Commit 4591de8a authored by Dave Griffiths's avatar Dave Griffiths
Browse files

moving stuff about

parent 98d641bb
......@@ -33,8 +33,8 @@ LOCAL_SRC_FILES := \
engine/obj_reader.cpp \
engine/nomadic.cpp \
engine/engine.cpp \
jellyfish/jellyfish.cpp \
jellyfish/jellyfish_primitive.cpp \
engine/jellyfish.cpp \
engine/jellyfish_primitive.cpp \
audio.cpp \
app-android.c
......
Jellyfish
=========
Aims to be a fluxus compatible programmable game engine and 3D renderer
for livecoding small devices.
A minimalistic fluxus compatible programmable game engine and 3D
renderer for exprimenting with livecoding ARM devices such as Raspberry
Pi, OUYA and Android as well as legacy support for PlayStation2.
Incorporating:
......@@ -10,16 +11,18 @@ Incorporating:
* REPL for livecoding
* OSC REPL for remote livecoding
* Fixed point maths throughout
* An experimental vector processor and compiler for fast procedural rendering
* An experimental vector processor and compiler for fast procedural
rendering
* OpenGL ES backend for ARM/Android/Rasperry Pi/OUYA
* Linux target: reference version (also running fixed point)
* Playstation 2 target (legacy)
* Custom hardware renderer running on vu1 path
* Linux target as a reference version (also running fixed point)
* Playstation 2 target (legacy) a custom hardware renderer running on
vu1 path
Building
--------
You'll need scons and liblo-dev installed, the Linux version requires GLUT.
You'll need scons and liblo-dev installed, the Linux version requires
GLUT.
### Linux ###
......@@ -35,16 +38,39 @@ As part of an APK:
ndk-build
Running
-------
Inside the testing directory there is a python script for testing the
OSC mode, continuously sending test code to the jellyfish program -
which can be on another machine.
Jellyfish Lisp Language Reference
---------------------------------
### Example programs ###
The purpose of a jellyfish lisp program is to manipulate 3D objects,
move/rotate/scale or change it's vertex positions, lighting normals,
texture coords. It can also act on input from outside. It can do this
faster than in Scheme (particually on ARM devices) as it doesn't require
any memory allocation, and it has access to more data than a GPU shader.
Jellyfish Lisp programs are compiled to bytecode executed by the
Jellyfish VM - there is one per object running parallel. The helper
function (make-jelly-obj) takes a number of cycles to execute per frame,
an OpenGL primitive type and a program. It returns the primitive id
which can be operated on like any normal fluxus primitive.
Inside the jellyfish VM the 3D data exists in the same memory address
space as the program, starting at "positions-start" address. You can
(read) data or (write!) to it using a value as an address.
Randomly move vertex positions
Here is a program that randomly moves vertex positions around:
;; normal fluxus code
(with-primitive
(make-jelly-obj 1000
(make-jelly-obj 1000 prim-tristrip
;; jellyfish lisp starts here
'(let ((vertex positions-start))
(forever
......@@ -54,13 +80,14 @@ Randomly move vertex positions
(set! vertex (+ vertex 1)))
)))
;; jellyfish lisp ends here
;; normal fluxus code
(pdata-map! (lambda (p) (srndvec)) "p")
(pdata-map! (lambda (c) (rndvec)) "c"))
### Core forms ###
TDB
Willdo...
* let
* define
......@@ -103,7 +130,7 @@ TDB
### Low level instruction set ###
TDB
Soon...
jmp jmz jlt jgt ldl lda ldi sta sti
add sub mul div abs scs atn dot crs
......
target = 'nomadic'
target = 'jellyfish'
platform = ARGUMENTS.get('TARGET','LINUX')
env = Environment(CCFLAGS='-O3 -std=gnu++0x -ggdb -DUSE_MATH=1 -Wno-write-strings')
source = ['main.cpp',
......@@ -22,8 +22,8 @@ source = ['main.cpp',
'engine/scenenode.cpp',
'engine/texture.cpp',
'engine/nomadic.cpp',
'jellyfish/jellyfish_primitive.cpp',
'jellyfish/jellyfish.cpp'
'engine/jellyfish_primitive.cpp',
'engine/jellyfish.cpp'
]
if platform=='LINUX':
......
......@@ -29,123 +29,39 @@
p)))
(with-primitive
(make-jelly
10000 prim-triangles
'(let ((vertex positions-start)
(flingdamp (vector 50 -20 0))
(world (vector 0 0 0))
(t 0))
(define recycle
(lambda (dir)
;; shift along x and y coordinates:
;; set z to zero for each vertex
(write! vertex
(+ (*v (read vertex)
(vector 1 1 0)) dir)
(+ (*v (read (+ vertex 1))
(vector 1 1 0)) dir)
(+ (*v (read (+ vertex 2))
(vector 1 1 0)) dir))
;; get the perlin noise values for each vertex
(let ((a (noise (* (- (read vertex) world) 0.2)))
(b (noise (* (- (read (+ vertex 1))
world) 0.2)))
(c (noise (* (- (read (+ vertex 2))
world) 0.2))))
;; set the z coordinate for height
(write-add!
vertex
(+ (*v a (vector 0 0 8))
(vector 0 0 -4))
(+ (*v b (vector 0 0 8))
(vector 0 0 -4))
(+ (*v c (vector 0 0 8))
(vector 0 0 -4)))
;; recalculate normals
(define n (normalise
(cross (- (read vertex)
(read (+ vertex 1)))
(- (read vertex)
(read (+ vertex 2))))))
;; write to normal data
(write! (+ vertex 512) n n n)
;; write the z height as texture coordinates
(write! (+ vertex 1536)
(*v (swizzle zzz a) (vector 0 4 0))
(*v (swizzle zzz b) (vector 0 4 0))
(*v (swizzle zzz c) (vector 0 4 0))))))
;; forever
(forever
(define vel (* flingdamp 0.002))
;; update the world coordinates
(set! world (+ world vel))
(set! t (+ t 0.1))
;; for each vertex
(loop (< vertex (- positions-end 3))
;; update the vertex position
(write-add! vertex vel vel vel)
;; check for out of area polygons to recycle
(cond
((> (read vertex) 5.0)
(recycle (vector -10 0 0)))
((< (read vertex) -5.0)
(recycle (vector 10 0 0))))
(cond
((> (swizzle yzz (read vertex)) 4.0)
(recycle (vector 0 -8 0)))
((< (swizzle yzz (read vertex)) -4.0)
(recycle (vector 0 8 0))))
(set! vertex (+ vertex 3)))
(set! vertex positions-start))))
(pdata-map! (lambda (n) (vmul (vector (crndf) (crndf) 0) 0.001)) "n")
(pdata-map! (lambda (c) (vector 1 1 1)) "c")
(texture (load-texture "stripes.png"))
(translate (vector -1 2 0))
(rotate (vector -45 0 0))
; (rotate (vector 0 0 100))
(scale (vector 1.5 1.5 1.5))
(let ((tsize 1)
(twidth 8))
(make-jelly
10000 prim-triangles
'(let ((vertex positions-start)
(t 0)
(v 0)
(np 0))
(forever
(set! vertex positions-start)
(loop (< vertex positions-end)
(set! np (+ (* (+ (read vertex) vertex) 0.1)
(swizzle yyx t)))
(set! v (+ (*v (noise np) (vector 1 0 0))
(*v (noise (+ np 101.1)) (vector 0 1 0))))
(set! v (*v (- v (vector 0.47 0.47 0.47)) (vector 0.1 0.1 0)))
(write-add! vertex v v v v v v)
(set! vertex (+ vertex 6)))
(set! t (+ t 0.01))
)))
(hint-unlit)
(pdata-index-map!
(lambda (i p)
(let* ((tpos (modulo i 3))
(tri (quotient i 3))
(flip (modulo tri 2))
(quad (quotient tri 2))
(col (modulo quad twidth))
(row (quotient quad twidth)))
(vadd
(vector (+ (* row tsize) 10) (* col tsize) 0)
(vmul
(if (zero? flip)
(cond
((eqv? tpos 0) (vector 0 0 0))
((eqv? tpos 1) (vector tsize 0 0))
((eqv? tpos 2) (vector tsize tsize 0)))
(cond
((eqv? tpos 0) (vector 0 0 0))
((eqv? tpos 1) (vector tsize tsize 0))
((eqv? tpos 2) (vector 0 tsize 0))))
1))))
"p"))
(pdata-map! (lambda (t) (vector 0 0 0)) "t")
)
(let ((z (* i 0.01)))
(if (odd? i)
(list-ref
(list (vector 0 0 z) (vector 1 0 z) (vector 1 1 z))
(modulo i 3))
(list-ref
(list (vector 1 1 z) (vector 0 1 z) (vector 0 0 z))
(modulo i 3))))) "p")
(texture (load-texture "raspberrypi.png"))
(translate (vector -0.5 -0.5 0))
(pdata-copy "p" "t")
(pdata-map! (lambda (t) (vmul t -1)) "t")
(pdata-map! (lambda (c) (vector 1 1 1)) "c")
(pdata-map! (lambda (n) (vector 0 0 0)) "n"))
......@@ -16,7 +16,7 @@
#include "engine.h"
#include "text_primitive.h"
#include "jellyfish/jellyfish_primitive.h"
#include "jellyfish_primitive.h"
#include "fluxa/Graph.h"
#include "obj_reader.h"
......
......@@ -20,7 +20,7 @@
#include "../engine/scenenode.h"
#include "../core/msg.h"
#include "jellyfish/jellyfish.h"
#include "engine/jellyfish.h"
jellyfish_primitive::jellyfish_primitive(u32 size):
primitive(size, TRIANGLES)
......
env = Environment(CCFLAGS='-O3 -ggdb')
env.Append(CPPPATH = '.')
env.Program( target = 'jellyfishtest',
source = ['main.cpp',
'jellyfish.cpp'] )
#define NOP 0
#define JMP 1
#define JMZ 2
#define JLT 3
#define JGT 4
#define LDL 5
#define LDA 6
#define LDI 7
#define STA 8
#define STI 9
#define ADD 10
#define SUB 11
#define MUL 12
#define DIV 13
#define ABS 14
#define SIN 15
#define ATN 16
#define DOT 17
#define CRS 18
#define SQR 19
#define LEN 20
#define DUP 21
#define CMP 22
#define SHF 23
#define BLD 24
#define RET 25
#define REG_PCO 100
#define REG_SPD 101
#define REG_POS 102
#define REG_VEL 103
#define REG_COL 104
#define REG_NIT 105
#define REG_SCC 106
#define REG_SDR 107
#define REG_AND 108
//...
#define REG_MDL 120
//...
#define REG_STP 200
#define REG_STK 201
#define REG_NDT 256
#include <stdio.h>
#include "jellyfish.h"
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
int main()
{
vec3 *heap=new vec3[256];
jellyfish jf(heap,256);
u32 a=0;
jf.poke(a++,vec3(LDA,13,0));
jf.poke(a++,vec3(LDL,20,0));
jf.poke(a++,vec3(ADD,0,0));
jf.poke(a++,vec3(DUP,0,0));
jf.poke(a++,vec3(STA,13,0));
jf.poke(a++,vec3(SIN,0,0));
jf.poke(a++,vec3(STA,14,0));
jf.poke(a++,vec3(LDA,14,0));
jf.poke(a++,vec3(LDA,15,0));
jf.poke(a++,vec3(CRS,0,0));
jf.poke(a++,vec3(STA,16,0));
jf.poke(a++,vec3(JMP,0,0));
jf.poke(15,vec3(0,1,0));
srand(2334);
// jf.trash();
/*
*/
while(1)
{
printf("--\n");
jf.run();
jf.pretty_dump();
sleep(1);
}
return 0;
}
......@@ -2,7 +2,6 @@ import osc,time
from random import choice
code = ["""
(with-primitive
(make-jelly
10000 prim-tristrip
'(let ((vertex positions-start)
......@@ -15,32 +14,23 @@ code = ["""
(set! v (+ (* (normalise (read vertex)) 0.05)
(* (- (read vertex)
(read (- vertex 1))) -0.5)))
(write-add! vertex (+ v (* (sincos (* (read vertex) 0.01)) 0.1)))
(write-add! vertex (+ v (* (sincos (* (read vertex) 0.01)) 0.01)))
(set! vertex (+ vertex 1)))
(set! t (+ t 0.01))
)))
(hint-unlit)
(texture 0)
(pdata-map! (lambda (c) (rndvec)) "c")
(pdata-map! (lambda (n) (vector 0 0 0)) "n"))
""",
"""
(with-primitive
(make-jelly 1000 prim-tristrip
(make-jelly 10000 prim-tristrip
'(let ((vertex positions-start))
(write! reg-graphics (vector 512 1 2))
(forever
(set! vertex positions-start)
(loop (< vertex positions-end)
(write! vertex (+ (read vertex) (rndvec)))
(write-add! vertex (* (sincos (* (read vertex) 0.01)) 0.1))
(++! vertex))
)))
(texture 0)
(pdata-map! (lambda (p) (srndvec)) "p")
(pdata-map! (lambda (c) (rndvec)) "c"))
""",
"""
......@@ -123,9 +113,9 @@ code = ["""
;; recalculate normals
(define n (normalise
(cross (- (read vertex)
(read (+ vertex 1)))
(read (+ vertex 2)))
(- (read vertex)
(read (+ vertex 2))))))
(read (+ vertex 1))))))
;; write to normal data
(write! (+ vertex 512) n n n)
......@@ -137,9 +127,10 @@ code = ["""
(*v (swizzle zzz c) (vector 0 4 0))))))
;; forever
(set! flingdamp (*v (- (rndvec) (vector 0.5 0.5 0.5)) (vector 0.2 0.2 0)))
(forever
(define vel (* flingdamp 0.002))
(define vel flingdamp)
;; update the world coordinates
(set! world (+ world vel))
(set! t (+ t 0.1))
......@@ -165,8 +156,10 @@ code = ["""
(set! vertex (+ vertex 3)))
(set! vertex positions-start))))
(hint-none)(hint-solid)
(pdata-map! (lambda (n) (vmul (vector (crndf) (crndf) 0) 0.001)) "n")
(pdata-map! (lambda (c) (vector 1 1 1)) "c")
(identity)
(texture (load-texture "stripes.png"))
(translate (vector -1 2 0))
(rotate (vector -45 0 0))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment