PDA

View Full Version : Carver Explorer



Carver413
12-04-2012, 06:58 PM
This is some what of a sand boxing frame work. the end goal is to create a firemonkey like solution for the fpc that would be suitable for game engine design graphic tool developement educational software.

The Explorer model is built around a custom link list design and so it inherits a very connected nature. because of this design sharing resources is very second nature to the explorer deticated managers are not really necessary. but should one need such micro management it would be quite easy to insert.

Scripting is also a big part of the design. it provides both structured input/output as well as a modular scripting language. a typical application in the explorer may have a number of script engines within it. each customized to the modules it controls. a shade module will contain commands to build shaders for the opengl while the texture rendering modules would have comands for loading,manipulating or creating texturing purely from script.

currently it is more for tool development and later for exploring game engine design.while my editor still looks a little crude don't be fooled by its appearance. it uses the fold file format I created for my self many years ago. this format works with most all languages and allows me to work with large files. it is quite programable as you can see I was able to throw together a simple interactive texture editor. it still needs alot of work but I am able to high lite a number and roll the mouse wheel to change to value and hit the run button to see the changes. all the textures are create from scripts and will be part of the framework when it is finished.

pstudio
12-04-2012, 08:31 PM
OMG :o Please choose a different font. My eyes are bleeding. ;D

code_glitch
12-04-2012, 08:34 PM
Aside from the font, thats some good work indeed :)

SilverWarior
13-04-2012, 12:34 AM
I see that you are using Perlin Noise for texture generation. Would you mind sharing sorce code for it so I can do some comparison with my Perlin Noise like algorithm that I made for myself? Mostly I would just like to do some speed comparison bethween them.

Carver413
13-04-2012, 02:24 AM
Actually that is not perlin noise, I don't have a good working perlin. if you want a fast perlin then your going to have to cheat like everone else. there are many different methods out there if you take the time to dig around a bit. I'm not really doing much with perlin right now so I haven't really perused it myself this. try this http://drilian.com/category/development/graphics/procedural-textures/ and see if there are some better ideas for you

Carver413
13-04-2012, 02:48 AM
Glscene also contains some perlin stuff maybe you should browse thru that as well

paul_nicholls
13-04-2012, 03:05 AM
Here is my Perlin Noise unit I made up around 2006 - not sure how fast it is?


Unit PerlinNoiseUnit;

Interface

{$R-}
{$Q-}

Const
_B = $100;
BM = $ff;

N = $1000;

Type
TPerlinNoise = Class
Private
P : Array[0..(_B+_B+2)-1] Of Integer;
G1: Array[0..(_B+_B+2)-1] Of Double;
Public
Constructor Create(Seed: Integer);

Procedure InitNoise(Seed: Integer);
Function Noise1d(x: Double): Double;
Function Noise2d(x,y: Double): Double;
Function Noise3d(x,y,z: Double): Double;

Function PerlinNoise1d(x: Double;
Persistence: Single = 0.25;
Frequency: Single = 1;
Octaves: Integer = 4): Double;
Function PerlinNoise2d(x,y: Double;
Persistence: Single = 0.25;
Frequency: Single = 1;
Octaves: Integer = 4): Double;
Function PerlinNoise3d(x,y,z: Double;
Persistence: Single = 0.25;
Frequency: Single = 1;
Octaves: Integer = 4): Double;
End;

Implementation

Uses
SysUtils;

Function TPerlinNoise.Noise1d(x: Double): Double;
Var
bx0,bx1: Integer;
rx0,sx,t,u,v: Double;
Begin
t := x+N;
bx0 := Trunc(t) And BM;
bx1 := (bx0+1) And BM;
rx0 := t-Trunc(t);

sx := (rx0*rx0*(3.0-2.0*rx0));

u := G1[P[bx0]];
v := G1[P[bx1]];

Result := u+sx*(v-u);
End;

Function TPerlinNoise.Noise2d(x,y: Double): Double;
Var
bx0,bx1,by0,by1: Integer;
i,j: Integer;
rx0,ry0: Double;
sx,sy: Double;
a,b,t,u,v: Double;
Begin
t := x+N;
bx0 := Trunc(t) And BM;
bx1 := (bx0+1) And BM;
rx0 := t-Trunc(t);

t := y+N;
by0 := Trunc(t) And BM;
by1 := (by0+1) And BM;
ry0 := t-Trunc(t);

i := P[bx0];
j := P[bx1];

sx := (rx0*rx0*(3.0-2.0*rx0));
sy := (ry0*ry0*(3.0-2.0*ry0));

u := G1[P[i+by0]];
v := G1[P[j+by0]];
a := u+sx*(v-u);

u := G1[P[i+by1]];
v := G1[P[j+by1]];
b := u+sx*(v-u);

Result := a+sy*(b-a);
End;

Function TPerlinNoise.Noise3d(x,y,z: Double): Double;
Var
bx0,bx1,by0,by1,bz0,bz1: Integer;
i,j,k,l: Integer;
rx0,ry0,rz0: Double;
sx,sy,sz: Double;
a,b,c,d,t,u,v: Double;
Begin
t := x+N;
bx0 := Trunc(t) And BM;
bx1 := (bx0+1) And BM;
rx0 := t-Trunc(t);

t := y+N;
by0 := Trunc(t) And BM;
by1 := (by0+1) And BM;
ry0 := t-Trunc(t);

t := z+N;
bz0 := Trunc(t) And BM;
bz1 := (bz0+1) And BM;
rz0 := t-Trunc(t);

i := P[bx0];
j := P[bx1];

k := P[i+by0];
l := P[j+by0];
i := P[i+by1];
j := P[j+by1];

sx := (rx0*rx0*(3.0-2.0*rx0));
sy := (ry0*ry0*(3.0-2.0*ry0));
sz := (rz0*rz0*(3.0-2.0*rz0));

u := G1[P[k+bz0]];
v := G1[P[l+bz0]];
a := u+sx*(v-u);

u := G1[P[i+bz0]];
v := G1[P[j+bz0]];
b := u+sx*(v-u);

c := a+sy*(b-a);

u := G1[P[k+bz1]];
v := G1[P[l+bz1]];
a := u+sx*(v-u);

u := G1[P[i+bz1]];
v := G1[P[j+bz1]];
b := u+sx*(v-u);

d := a+sy*(b-a);

Result := c+sz*(d-c);
End;

constructor TPerlinNoise.Create(Seed: Integer);
Begin
inherited Create;

InitNoise(Seed);
End;

procedure TPerlinNoise.InitNoise(Seed: Integer);
Var
i,j: Integer;
Begin
RandSeed := Seed;

For i := 0 to _B - 1 Do
Begin
P[i] := i;
G1[i] := 2*Random-1;
End;

For i := 0 to _B - 1 Do
Begin
j := Random(_B);
P[i] := P[i] xor P[j];
P[j] := P[j] xor P[i];
P[i] := P[i] xor P[j];
End;

For i := 0 to _B+2 - 1 Do
Begin
P[_B+i] := P[i];
G1[_B+i] := G1[i];
End
End;

Function TPerlinNoise.PerlinNoise1d(x: Double;
Persistence: Single = 0.25;
Frequency: Single = 1;
Octaves: Integer = 4): Double;
Var
i: Integer;
p,s: Double;
Begin
Result := 0;
s := Frequency;
p := 1;
For i := 0 to Octaves - 1 Do
Begin
Result := Result + p * Noise1d(x * s);
s := s * 2;
p := p * Persistence;
End;
End;

Function TPerlinNoise.PerlinNoise2d(x,y: Double;
Persistence: Single = 0.25;
Frequency: Single = 1;
Octaves: Integer = 4): Double;
Var
i: Integer;
p,s: Double;
Begin
Result := 0;
s := Frequency;
p := 1;
For i := 0 to Octaves - 1 Do
Begin
Result := Result + p * Noise2d(x * s,y * s);
s := s * 2;
p := p * Persistence;
End;
End;

Function TPerlinNoise.PerlinNoise3d(x,y,z: Double;
Persistence: Single = 0.25;
Frequency: Single = 1;
Octaves: Integer = 4): Double;
Var
i: Integer;
p,s: Double;
Begin
Result := 0;
s := Frequency;
p := 1;
For i := 0 to Octaves - 1 Do
Begin
Result := Result + p * Noise3d(x * s,y * s,z * s);
s := s * 2;
p := p * Persistence;
End;
End;

End.

Carver413
13-04-2012, 03:58 AM
This looks very nice Paul, I'll have to play around with it a bit and see what kind of trouble I can get into8)

pitfiend
13-04-2012, 04:08 AM
Here is my Perlin Noise unit I made up around 2006 - not sure how fast it is?


Unit PerlinNoiseUnit;

Interface

{$R-}
{$Q-}

Const
_B = $100;
BM = $ff;

N = $1000;

Type
TPerlinNoise = Class
Private
P : Array[0..(_B+_B+2)-1] Of Integer;
G1: Array[0..(_B+_B+2)-1] Of Double;
Public
Constructor Create(Seed: Integer);

Procedure InitNoise(Seed: Integer);
Function Noise1d(x: Double): Double;
Function Noise2d(x,y: Double): Double;
Function Noise3d(x,y,z: Double): Double;

Function PerlinNoise1d(x: Double;
Persistence: Single = 0.25;
Frequency: Single = 1;
Octaves: Integer = 4): Double;
Function PerlinNoise2d(x,y: Double;
Persistence: Single = 0.25;
Frequency: Single = 1;
Octaves: Integer = 4): Double;
Function PerlinNoise3d(x,y,z: Double;
Persistence: Single = 0.25;
Frequency: Single = 1;
Octaves: Integer = 4): Double;
End;

Implementation

Uses
SysUtils;

Function TPerlinNoise.Noise1d(x: Double): Double;
Var
bx0,bx1: Integer;
rx0,sx,t,u,v: Double;
Begin
t := x+N;
bx0 := Trunc(t) And BM;
bx1 := (bx0+1) And BM;
rx0 := t-Trunc(t);

sx := (rx0*rx0*(3.0-2.0*rx0));

u := G1[P[bx0]];
v := G1[P[bx1]];

Result := u+sx*(v-u);
End;

Function TPerlinNoise.Noise2d(x,y: Double): Double;
Var
bx0,bx1,by0,by1: Integer;
i,j: Integer;
rx0,ry0: Double;
sx,sy: Double;
a,b,t,u,v: Double;
Begin
t := x+N;
bx0 := Trunc(t) And BM;
bx1 := (bx0+1) And BM;
rx0 := t-Trunc(t);

t := y+N;
by0 := Trunc(t) And BM;
by1 := (by0+1) And BM;
ry0 := t-Trunc(t);

i := P[bx0];
j := P[bx1];

sx := (rx0*rx0*(3.0-2.0*rx0));
sy := (ry0*ry0*(3.0-2.0*ry0));

u := G1[P[i+by0]];
v := G1[P[j+by0]];
a := u+sx*(v-u);

u := G1[P[i+by1]];
v := G1[P[j+by1]];
b := u+sx*(v-u);

Result := a+sy*(b-a);
End;

Function TPerlinNoise.Noise3d(x,y,z: Double): Double;
Var
bx0,bx1,by0,by1,bz0,bz1: Integer;
i,j,k,l: Integer;
rx0,ry0,rz0: Double;
sx,sy,sz: Double;
a,b,c,d,t,u,v: Double;
Begin
t := x+N;
bx0 := Trunc(t) And BM;
bx1 := (bx0+1) And BM;
rx0 := t-Trunc(t);

t := y+N;
by0 := Trunc(t) And BM;
by1 := (by0+1) And BM;
ry0 := t-Trunc(t);

t := z+N;
bz0 := Trunc(t) And BM;
bz1 := (bz0+1) And BM;
rz0 := t-Trunc(t);

i := P[bx0];
j := P[bx1];

k := P[i+by0];
l := P[j+by0];
i := P[i+by1];
j := P[j+by1];

sx := (rx0*rx0*(3.0-2.0*rx0));
sy := (ry0*ry0*(3.0-2.0*ry0));
sz := (rz0*rz0*(3.0-2.0*rz0));

u := G1[P[k+bz0]];
v := G1[P[l+bz0]];
a := u+sx*(v-u);

u := G1[P[i+bz0]];
v := G1[P[j+bz0]];
b := u+sx*(v-u);

c := a+sy*(b-a);

u := G1[P[k+bz1]];
v := G1[P[l+bz1]];
a := u+sx*(v-u);

u := G1[P[i+bz1]];
v := G1[P[j+bz1]];
b := u+sx*(v-u);

d := a+sy*(b-a);

Result := c+sz*(d-c);
End;

constructor TPerlinNoise.Create(Seed: Integer);
Begin
inherited Create;

InitNoise(Seed);
End;

procedure TPerlinNoise.InitNoise(Seed: Integer);
Var
i,j: Integer;
Begin
RandSeed := Seed;

For i := 0 to _B - 1 Do
Begin
P[i] := i;
G1[i] := 2*Random-1;
End;

For i := 0 to _B - 1 Do
Begin
j := Random(_B);
P[i] := P[i] xor P[j];
P[j] := P[j] xor P[i];
P[i] := P[i] xor P[j];
End;

For i := 0 to _B+2 - 1 Do
Begin
P[_B+i] := P[i];
G1[_B+i] := G1[i];
End
End;

Function TPerlinNoise.PerlinNoise1d(x: Double;
Persistence: Single = 0.25;
Frequency: Single = 1;
Octaves: Integer = 4): Double;
Var
i: Integer;
p,s: Double;
Begin
Result := 0;
s := Frequency;
p := 1;
For i := 0 to Octaves - 1 Do
Begin
Result := Result + p * Noise1d(x * s);
s := s * 2;
p := p * Persistence;
End;
End;

Function TPerlinNoise.PerlinNoise2d(x,y: Double;
Persistence: Single = 0.25;
Frequency: Single = 1;
Octaves: Integer = 4): Double;
Var
i: Integer;
p,s: Double;
Begin
Result := 0;
s := Frequency;
p := 1;
For i := 0 to Octaves - 1 Do
Begin
Result := Result + p * Noise2d(x * s,y * s);
s := s * 2;
p := p * Persistence;
End;
End;

Function TPerlinNoise.PerlinNoise3d(x,y,z: Double;
Persistence: Single = 0.25;
Frequency: Single = 1;
Octaves: Integer = 4): Double;
Var
i: Integer;
p,s: Double;
Begin
Result := 0;
s := Frequency;
p := 1;
For i := 0 to Octaves - 1 Do
Begin
Result := Result + p * Noise3d(x * s,y * s,z * s);
s := s * 2;
p := p * Persistence;
End;
End;

End.
I think you can improve speed if you use a type cast to integer (t as integer) instead of that trunc(t) function. Also you can remove the sysutils unit as it seems your code didn't use anything from it. Random and RandSeed are declared in the implicit system unit.

SilverWarior
13-04-2012, 06:48 AM
@Paul
Thank you for that. Where were you when I was asking about this in next thread: http://www.pascalgamedevelopment.com/showthread.php?13223-Planet-texture-generation-code
I will test it when I get home. It also gave me solution for improving my own algorithm for some capability that I need.

@Carver431
That site seems verry good. I will take some time reading trough but it will have to wait after the competition.

Carver413
13-04-2012, 01:39 PM
@Paul That site seems verry good. I will take some time reading trough but it will have to wait after the competition. to pull off a good texture rendering system you will need much more then just perlin noise and if your not careful your system could become very bloated and unmanageable rather quickly. my approach may not be the fastest solution but it extremely flexible most effects are applied as nodes and are very small they can often be chained together so the output of one becomes the input for the next. all drawing functions are effected by these nodes, even text rendering. scripting in most cases does not have a big impact but provides a nice interface to fine tune these effects. property editors require alot of extra work and generally preform poorly. my scripting mechanic's is not design for speed but flexibility, modular design. scripting expansion nodes are stack in the same way that the drawing nodes are. each node can have as many commands as needed and and new data types. in this way we can group them together in a way that makes since. and we can include as much or as little as we want. further more the scripting provides many input/output methods. you can export data in a similar xml fashion, only more readable. you can input/output lists of variables in a less orderly fashion. the scripting in the Explorer is for the most part is intended to be a set up language, not intended to handle time critical tasks. by the time this project is finish I will have implemented a chunk library so that if we decide to pre render some of our assets they could be stored there until they are no longer needed.

SilverWarior
13-04-2012, 04:09 PM
Yes I know that I will ned much more than just perlin noise. That's why I'm already developing my algorithm in a way that it will easily alow me to do some postprocessing or even do some preprocessing for each of the layers wich are then used in creation of the final texture. But like stated a few post higher I doubt I could do this by the end of competition. I do have a lot of other owrk on my entry wich still needs to be done. Hence I havent completly decided wich graphic engine will I use. For now I work on the core of the game.

Carver413
13-04-2012, 05:21 PM
@Paul
your perlin is very nice, thank you so much;D
I have implemented as a variable so I could set the seed from a script as well as share it with other functions. still need to play with it some more before I get it all figured out. now I just need to figure out how to make wood grains with it.

SilverWarior
13-04-2012, 06:51 PM
I just need to figure out how to make wood grains with it.

I think next page might come in handy for this as it shows example of how to make wood like textures.
http://freespace.virgin.net/hugo.elias/models/m_perlin.htm

Look at the bottom of the page

paul_nicholls
13-04-2012, 10:27 PM
@Paul
your perlin is very nice, thank you so much;D
I have implemented as a variable so I could set the seed from a script as well as share it with other functions. still need to play with it some more before I get it all figured out. now I just need to figure out how to make wood grains with it.

Glad I could help mate :)

Carver413
27-04-2012, 10:03 PM
I decided to move more to a single window design so I spent the last week ripping up code and trying to put it all back together. I now have my own little windowing system within the window or screen. the layout managers maintain control of the windows as they are added and removed. they also help to channel incoming messages to the point of focus. when I learn more about shaders I will be able to add some nice layouts but at this point the only shader I have is very basic so no point in spending alot of time on that right now. I found a nice mono font (since someone complained about my other one) still lots of tiding to do and then I think I'll spend some time tring to figure out some basic bone anmation.

Carver413
21-11-2012, 10:09 AM
Lights are on finally, I know it don't look like much yet but it is opengl 3.3 so learning is slow. especially when all my reference materal is c++ :(
960

Carver413
28-11-2012, 10:33 AM
well I'm starting to work out some bone animation stuff since I could find anything that worked for me. at least this way when its done I'll know how it works. I'm using a modified version of user137's getangle to pose him at the moment. this version works with negitive values. now all I need is to get it working on the other axis's
in case it's useful to someone.

Function GetAngle(vVec1,vVec2:TFlt3):TFlt;
Var
v1,v2:TFlt3;
vA:TFlt;
begin
v1:=VecFlt3(0,1,0);
v2:=VecNorm(VecSub(vVec1,vVec2));
vA:=ArcCos(VecDot(v1,v2))*(180/PI);
if v2.X<0 then result:=-vA else result:=vA;
end;

971972
as you can see my shader has improved a bit.

paul_nicholls
28-11-2012, 09:17 PM
well I'm starting to work out some bone animation stuff since I could find anything that worked for me. at least this way when its done I'll know how it works. I'm using a modified version of user137's getangle to pose him at the moment. this version works with negitive values. now all I need is to get it working on the other axis's
in case it's useful to someone.

Function GetAngle(vVec1,vVec2:TFlt3):TFlt;
Var
v1,v2:TFlt3;
vA:TFlt;
begin
v1:=VecFlt3(0,1,0);
v2:=VecNorm(VecSub(vVec1,vVec2));
vA:=ArcCos(VecDot(v1,v2))*(180/PI);
if v2.X<0 then result:=-vA else result:=vA;
end;

971972
as you can see my shader has improved a bit.

Nice work...that looks rather cute actually :)

Maybe Hugo's site can help again in this area too:
(inverse) Kinematics
http://freespace.virgin.net/hugo.elias/models/m_linked.htm
http://freespace.virgin.net/hugo.elias/models/m_ik.htm
http://freespace.virgin.net/hugo.elias/models/m_ik2.htm

cheers,
Paul

Carver413
28-11-2012, 09:24 PM
Thanks Paul, I can use all the help I can get.

Carver413
02-12-2012, 09:37 AM
well I got my angle code working on all 3 planes but it failed as soon as I tried to combine the three. I fared much better on the scripting side of things. my latest model was created entirely from a script and was quite easy to do. I still plan to develope cad tools as well but my main focus right now will be animation and working out any kinks in the bone structure.
975976

Carver413
15-12-2012, 03:56 PM
I've been working on a meshing tool to create simple meshes from script or cad assist. currently I can pass it a 2d array and it will create a complete mesh UV map and all. 3 different UV layouts to choose from. currently it can create about any shape you could make with a lathe and more. I'm going to add cookie cutter style as well but for now I just want to give my guy a little better shape and a face to boot. then maybe I can make a movie.At some point I plan to add blender support but I want a good working modeler set up before I bother.
978

Carver413
12-01-2013, 07:10 PM
well I've been a little side tracked these day's I added a Shell() command to my scripting engine because I wanted to play with some of the TTS commands on linux that opened a whole new world of possibilitys and off I went. I can now do a whole bunch stuff from my editor like opening my favorite web pages getting the TTS to read to me, update my Lazarus. any way I have started working on some sound stuff. I decided to use openal since it is very simular to opengl. I want to make a sort of sound canvas simular to the texturing canvas. with the sound canvas we would be creating sounds in a procedural way by combining nodes together as well as creating custom filters for processing external sounds. can,t say that I know much about it but when did that ever stop me.
1035

Carver413
18-03-2013, 09:22 PM
Lots of good stuff going on here, doing lots of refactoring and cleanup to tie everything together, killed a few bugs and reduced the size of script nessary to create a gui. it is begining to be a very game worthy gui. I developed a tag system for the Gui so only nessary things need to be added. if a button is in a group then defining the frame size is pointless and if a control is anchored then the same applys. Caption is mostly unneeded since most cases we can simple use the name as our caption. we can even do this BUTTON:'Push me please' and aslong as its in quotes it will work just fine. I am continuing to add new things to the canvasing unit Resampling (Blur,Sharpen,Emboss,Edge) all user define able. combine those with the Procedural stuff and you will have endless possibilitys for skinning the gui. because the canvasing unit handles the look of most of the gui it is possible to theme your UI by swaping out the canvas file. and if thats not enough many controls can define an OnPaint script.
11441145

Darkhog
29-05-2013, 08:48 AM
Here is my Perlin Noise unit I made up around 2006 - not sure how fast it is?
snip


X/Y/Z in functions Noise1D/2D/3D are offset from (0,0,0), right? I'm asking because I'm looking into making "infinite" game using chunks scheme (perlin noise is for world generation).

paul_nicholls
30-05-2013, 05:22 AM
X/Y/Z in functions Noise1D/2D/3D are offset from (0,0,0), right? I'm asking because I'm looking into making "infinite" game using chunks scheme (perlin noise is for world generation).

Hi Darkhog, to be honest, I don't know...but I assume that is the case :)

cheers,
Paul