Skip to content

Commit

Permalink
Progress on the seascape
Browse files Browse the repository at this point in the history
  • Loading branch information
Checkmate50 committed Mar 3, 2020
1 parent 9897619 commit 52b54ed
Show file tree
Hide file tree
Showing 3 changed files with 269 additions and 89 deletions.
125 changes: 121 additions & 4 deletions examples/glsl_defs.lgl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ with vec2 T: declare T -(T v);
with vec2 T: with float U: declare T *(T v, U f);
with vec2 T: with float U: declare T *(U f, T v);
with vec2 T: with float U: declare T /(T f1, U f2);
with vec2 T: declare vec2 *(T v1, T v2);

with vec3 T: declare T +(T v1, T v2);
with vec3 T: declare T -(T v1, T v2);
Expand All @@ -60,6 +61,10 @@ with vec4 T: with float U: declare T *(T v, U f);
with vec4 T: with float U: declare T *(U f, T v);
with vec4 T: declare vec4 *(T v1, T v2);

with mat2 T: with vec2 U: declare vec2 *(T m, U v);
with mat2 T: with mat2 U: declare mat2 +(T m, U v);
with mat2 T: with mat2 U: declare mat2 *(T m, U v);

with mat3 T: with vec3 U: declare vec3 *(T m, U v);
with mat3 T: with mat3 U: declare mat3 +(T m, U v);
with mat3 T: with mat3 U: declare mat3 *(T m, U v);
Expand All @@ -69,11 +74,37 @@ with mat4 T: with mat4 U: declare mat4 +(T m, U v);
with mat4 T: with mat4 U: declare mat4 *(T m, U v);

// GLSL function types

declare float sin(float f);
declare float cos(float f);
declare float sqrt(float f);
declare float acos(float f);
with vec4 T:
declare T fract(T v);
with float[2] T: declare T sin(T f);
with float[2] T: declare T cos(T f);
with float[2] T: declare T sqrt(T f);
with float[2] T: declare T acos(T f);
with float[3] T: declare T sin(T f);
with float[3] T: declare T cos(T f);
with float[3] T: declare T sqrt(T f);
with float[3] T: declare T acos(T f);
with float[4] T: declare T sin(T f);
with float[4] T: declare T cos(T f);
with float[4] T: declare T sqrt(T f);
with float[4] T: declare T acos(T f);

declare float abs(float f);
with float[2] T: declare T abs(T f);
with float[3] T: declare T abs(T f);
with float[4] T: declare T abs(T f);

declare float mix(float a, float b, float c);
with vec2 T: declare T pow(T v, float f);
with vec3 T: declare T pow(T v, float f);
with vec4 T: declare T pow(T v, float f);
with vec2 T: declare T floor(T v);
with float T: declare T fract(T f);
with vec2 T: declare T fract(T v);
with vec4 T: declare T fract(T v);

with float[4] T:
declare T texture2D(sampler2D<T> texture, float[2] coord);
Expand All @@ -83,19 +114,27 @@ declare T textureCube(samplerCube<T> texture, float[2] coord);
with float[4] T:
declare T textureCube(samplerCube<T> texture, float[3] coord);


with float[3] T: with float U: declare vec4 vec4(T v, U f);
declare vec2 vec2(float x, float y);
declare vec3 vec3(float x, float y, float z);
declare vec4 vec4(float x, float y, float z, float w);
with float T: declare vec3 vec3(T f);
with float[4] T: declare vec3 vec3(T v);
with float T: declare vec4 vec4(T f);
with float[3] T: with float U: declare vec4 vec4(T v, U f);
with float[4][4] T: declare mat3 mat3(T v);
with float[3][3] T: declare mat4 mat4(T v);

with vec2 T: declare float dot(T v1, T v2);
with vec3 T: declare float dot(T v1, T v2);
with vec4 T: declare float dot(T v1, T v2);
with vec2 T: declare float length(T v);
with vec3 T: declare float length(T v);
with vec4 T: declare float length(T v);
// declare T normalize<T : vec3>(T x);
declare vec2 normalize(vec2 x);
declare vec3 normalize(vec3 x);
with float T: declare T max(T f1, T f2);
with vec2 T: declare T reflect(T v1, T v2);
with vec3 T: declare T reflect(T v1, T v2);
with float T: declare T pow(T f1, T f2);

Expand Down Expand Up @@ -142,6 +181,84 @@ prototype geometry {

// Coordinate Scheme Definitions

with frame(2) r:
coordinate cart2 : geometry {
object point is float[2];
object vector is float[2];
object direction is float[2];
with frame(2) r2: object transformation is float[2][2];

vector +(vector x, vector y) {
return (x as! vec2 + y as! vec2) as! vector;
}
vector -(vector x, vector y) {
return (x as! vec2 - y as! vec2) as! vector;
}
vector *(vector v, scalar s) {
return (v as! vec2 * s) as! vector;
}
vector *(scalar s, vector v) {
return (s * v as! vec2) as! vector;
}
vector -(vector v) {
return (-v as! vec2) as! vector;
}
direction -(direction v) {
return (-v as! vec2) as! direction;
}
point +(point p, vector v) {
return (p as! vec2 + v as! vec2) as! point;
}
point +(vector v, point p) {
return (p as! vec2 + v as! vec2) as! point;
}
vector -(point x, point y) {
return (x as! vec2 - y as! vec2) as! vector;
}
vector -(point v) {
return (-v as! vec2) as! vector;
}
with frame(2) target:
this<target>.vector *(transformation<target> m, vector v) {
return (m as! mat2 * v as! vec2) as! this<target>.vector;
}
with frame(2) target:
this<target>.vector *(transformation<target> m, direction d) {
return (m as! mat2 * d as! vec2) as! this<target>.vector;
}
with frame(2) target:
this<target>.point *(transformation<target> m, point p) {
return (m as! mat2 * p as! vec2) as! this<target>.point;
}
with frame(2) target:
transformation<target> +(transformation<target> m1, transformation<target> m2) {
return (m1 as! mat2 + m2 as! mat2) as! transformation<target>;
}
with frame(2) middle, target:
transformation<target> *(transformation<middle> m1, this<middle>.transformation<target> m2) {
return (m1 as! mat2 * m2 as! mat2) as! transformation<target>;
}

angle dot(direction v1, direction v2) {
return (dot(v1 as! vec2, v2 as! vec2) as! angle);
}
scalar length(vector v) {
return (length(v as! vec2) as! scalar);
}
direction normalize(vector v) {
return (normalize(v as! vec2) as! direction);
}
direction normalize(direction v) {
return v;
}
vector reflect(direction v1, direction v2) {
return (reflect(v1 as! vec2, v2 as! vec2) as! vector);
}
vector reflect(vector v1, direction v2) {
return (reflect(v1 as! vec2, v2 as! vec2) as! vector);
}
}

with frame(3) r:
coordinate cart3 : geometry {
object point is float[3];
Expand Down
Loading

0 comments on commit 52b54ed

Please sign in to comment.