• Welcome to Dark Bit Factory & Gravity.
 

WIP 3D Engine (Update : v0.07 screenie preview) [v0.06]

Started by Hezad, August 21, 2008

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Hezad

hey :)

ok, I see the point, I changed the FOV in zoom and aspect ratio and "putted" them in the camera space transformation. I understood the point with the logical error too. big k++ to you for all your help !! I continue to work on it and I'll post stuff once there'll be new stuff :)

thanks again !!
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

Shockwave

It may not be there yet Hezad but the speed increase already is nice, it was running at around 20fps before, it's not at about 36fps (default zoom), it gets much faster if I zoom it out and crashes if I zoom it in ;)
Shockwave ^ Codigos
Challenge Trophies Won:

Hezad

hehe cool for the speed increase :P And 'glad to see you back shockwave :D

Some news : I'm almost there !!

After days of trying to find a bug making my program to continue to crash, I think I got something ! Now the program don't crash anymore, and it even looks like the Left plane clipping works perfectly. Here is the program if you wanna test (You can still move with the keyboard arrows) :D

Well, there are still glitches with the bottom, right and top clipping .. But I'm glad, I thought I were really stuck here :p



EDIT :
Another good new !! I fixed the Perspective correct mapping bug, now the texture mapping works perfectly :D It looks ... so much better hehe ! The attached file is a version without this correction, i'll post this version later. Just have to finish the clipping, to code the backface culling and to optimize/reorganize a bit the code and then ... Mip Mapping !  :D  (or maybe the camera handling before :p)
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

hellfire

You're really making great progress!
I'm just wondering why you sometimes start your arrays at index 0 and sometimes at index 1 ?
Challenge Trophies Won:

Hezad

uhuh I edited my message at the same time ^^

thanks !

Concerning the arrays, some are starting at index 1 because I used an iteration variable the fill the array which starts to be incremented before the assigning values to the array.

eg : Iter+=1 : Array(iter) = stuff

so the array is used from 1 instead of 0 :P
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

hellfire

Quotesome are starting at index 1
and you don't find that confusing?
Challenge Trophies Won:

Hezad

Well ... lol not really, I'm pretty habituated, I do it all the time (yeah it's not a good habit :s ..)

hum.. But it'd be a good thing to change this habit .. let's start right now :p
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

Hezad

Hi again folks :)

well, I know capital letters are not really welcome on boards but .. this time it's so awesome ..


CLIPPING IS NOW FULLY WORKING !!!! YEYHOO !

Dudes, I don't know how many hours I spent to find what wasn't working, I was almost desperate about it ^^ So it is really, really a liberation to see those cubes moving without any glitches and at ~15 FPS  :updance:  :updance:  :updance:

Oh and like I said in a previous recent post, I found what wasn't working in perspective mapping too ! So The clipping works, but the perspective correct texture mapping also works perfectly (on my computer though .. your turn to say me if it works on yours :D )

Once again, thanks A LOT to hellfire who spent a lot of time to help me with clipping.

Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

hellfire

Well done!
Runs at ~30fps (Intel Core2 3Ghz) and ~20fps (Core2 2Ghz), I guess you can easily make it 60 without even touching assembler.
But before you get your hands dirty in optimization, please take some time to think about conception and class design.
Challenge Trophies Won:

Hotshot

look great....run 25FPS ( mine is E6750)  The checkboard look great.

welldone

:cheers:

Hezad

hellfire :
thanks :D So what would you advise me ? Using kind of a pipeline ?

eg :

- Objects Declaration (User Side)
- Objects Characteristics [texture, shader, rotation, translations] (User Side)
- Store everything in a Global Render List (Engine side)
- Calculate Shaders (Engine Side)
- Calculate Clipping + Projection (Engine Side)
- Render

and/or do you speak about totally changing the way I use my UDT's ?
Concerning the modularization, I thought about putting all engine subs in a .bi file and putting all the objects creation helping subs in another one.

I remember you spoke about materials but I thought I can create functions that create textures from procedural materials and a special type which could handle materials layers handling
e.g. in pseudo code :


Type Single_Material
   Tex as Texture
   Opacity as integer
   MapType as integer       '' (BumpMap, TextureMap, ColorMap, etc?)
End Type

Type Material
   Layers(NBLAYERS) as Single_Material
End type

CurrentObject = Apply_Material(Current_Material)



And then using the MapType variable before rendering to know which kind of Material to calculate.

Don't know if it's a good idea though :p


HotShot :

thanks :D
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

Shockwave

Works really nice here too, no clipping bugs at all.

When Hellfire talks about classes he does mean types, yep. I will suggest once you have that implimented that you add backface culling and mip mapping which will give you a further speed boost.

It looks bloody good thought Hezad.

Fair play to you.
Shockwave ^ Codigos
Challenge Trophies Won:

hellfire

Some notes:

In software-rendering, poly- and pixel-throughput are precious, so you'll usually have many special-case-optimized polyfillers.
In my renderer I used a "Material" class which creates all required vertex-data from a mesh and contains the polygon-rasterization-code.

The 3D-models (or complete scenes including animation) are usually loaded from files (exported from your favourite 3d-package).
For testing & debugging reasons my "Mesh" class has some static methods to create some simple objects like cube, cylinder, sphere or torus:
Mesh *mesh= Mesh::createTorus(100, 40);
Here "Mesh" is one of several object-types (all derived from one base-class) that are stored in a scene-tree (the hierarchical structure might not be required for you yet) and basically contains all information that can be applied by the 3d-software.
To get things rendering, I just need to assign it to a material:
Material *mat= new TextureGouraud(scenetree, Texture("texturefilename") );
mat->addMesh(mesh);

Here "Texture" can either be a bitmap loaded from a file or something procedurally generated (it just needs to derive from the same interface-class).

For rendering I just parse the material-list (stored in the scene-tree) and draw everything that got assigned.
The material has a "transform"-method to put the object where it belongs (multiply vertices by mesh' and camera's matrix) and to create all vertex-attributes; here: calculating rgb-values from vertexnormals and lights (which are also stored in the scene-tree, accessible by the material).
When that's done, polygon's are culled, clipped (each material has a vertex-class with a method for interpolation) and drawn.

For animation, each object has several animation-tracks which store position, rotation, scaling at certain timestamps (and interpolate in between).
"Procedural" animation (like deforming vertices) is job of the "Material", too (since it resambles the vertex-shader part).
Other approaches would just manually updated the mesh' transformation-matrix.

QuoteWhen Hellfire talks about classes he does mean types
True. "Classes" were mentioned a couple of times in the freebasic documentation, but I just realized they don't exist: :-\
QuoteThis keyword is supported in the latest fbc compiler, however, its usefulness is limited since classes and inheritance are not yet supported.
This is a knockout for most structured design strategies...



Challenge Trophies Won:

Hezad

Hey :)

Shockwave :
QuoteWorks really nice here too, no clipping bugs at all.

When Hellfire talks about classes he does mean types, yep. I will suggest once you have that implimented that you add backface culling and mip mapping which will give you a further speed boost.

Glad to hear it works :) Backface culling was implemented just after the previous release :) Mip-Mapping is on the todo list, right after the pure code optimization part :) I'll start optimization with using Integers instead of singles most of the time. Then, I'll read once again all the thread to remind myself stuff people told me about optimization but forgotten ;D and then, MIPMAPPING :D

Quote
It looks bloody good thought Hezad.
thanks a lot shockwave  :cheers:



hellfire :

QuoteIn software-rendering, poly- and pixel-throughput are precious, so you'll usually have many special-case-optimized polyfillers.
In my renderer I used a "Material" class which creates all required vertex-data from a mesh and contains the polygon-rasterization-code.

The 3D-models (or complete scenes including animation) are usually loaded from files (exported from your favourite 3d-package).
For testing & debugging reasons my "Mesh" class has some static methods to create some simple objects like cube, cylinder, sphere or torus:
Code:

Mesh *mesh= Mesh::createTorus(100, 40);

Here "Mesh" is one of several object-types (all derived from one base-class) that are stored in a scene-tree (the hierarchical structure might not be required for you yet) and basically contains all information that can be applied by the 3d-software.
To get things rendering, I just need to assign it to a material:
Code:

Material *mat= new TextureGouraud(scenetree, Texture("texturefilename") );
mat->addMesh(mesh);

Here "Texture" can either be a bitmap loaded from a file or something procedurally generated (it just needs to derive from the same interface-class).


Thanks for that, I just implemented a start for a material UDT which I can edit in a similar way of OpenGL surface creation (I'll put here an example at the end of the post). Added a naive bmp loader for textures too. I also replaced the objects creation functions with Object Type subs.


QuoteFor animation, each object has several animation-tracks which store position, rotation, scaling at certain timestamps (and interpolate in between).
"Procedural" animation (like deforming vertices) is job of the "Material", too (since it resambles the vertex-shader part).
Other approaches would just manually updated the mesh' transformation-matrix.

Animation is not planned for now :p But I didn't know I can use materials to implement it :)



QuoteQuote
When Hellfire talks about classes he does mean types
True. "Classes" were mentioned a couple of times in the freebasic documentation, but I just realized they don't exist: Undecided

Badly true :P But Freebasic's UDTs permits already some interesting stuff (Type Subs/functions, Constructors, destructors, properties, Operators), it's totally sufficient for what I wanna do now :)

QuoteThis keyword is supported in the latest fbc compiler, however, its usefulness is limited since classes and inheritance are not yet supported.
This is a knockout for most structured design strategies...

Well I guess so, but since I don't really know all classes stuff, UDT's are fine for me now ^^




Engine News :

Before starting optimizations,  I wanted to modularize and reorganize a bit my code to help comprehension. So here are the news :

- Modularization : code broken into smaller header files (Engine.bi, DataTypes.bi, Materials.bi)
- Texture BMP loader
- Backface Culling
- /!\ New material Type to handle .. well, materials :p
        + Effective way (I hope) to create/edit materials in code
- Texture tiling routine
- Changed textures of the example for realistic ones


An example of material editing :




Dim as ObjectT MyObject

MyObject.GenerateCube(x0,y0,z0,SideSize)

Dim as TextureT CubeTex

CubeTex.LoadBMP "Texture_Cube.bmp"


Dim as MaterialT CubeMaterial

CubeMaterial.Edit
   
    Mat_Shader GOURAUD_SHADER
   
    Mat_Texture CubeTex,tileX,tileY

    Mat_Diffuse r,g,b

    Mat_ambient r,g,b

CubeMaterial.End_Edit

MyObject.Assign_Material CubeMaterial



And a screenshot with the new textures attached
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

hellfire

#94
Everything sounds plausible, I'm just wondering what this does:
Quote- Texture tiling routine
Usually you would make sure your texture-width/height is a power of two, scale your uv-coordinates and  and mask the appropriate bits ("and" instead of modulo).

Quotea material UDT which I can edit in a similar way of OpenGL
It's a good idea to follow standards, but remember that OpenGL's material-model was build around sgi's hardware-capabilities and is sometimes rather unflexible and you'll often want to take some shortcuts in order of optimization.
The important point is to offer the relevant features required to achieve certain effects.
If you want to get some ideas about how to use materials & lighting professionally, I can recommend this book:

Challenge Trophies Won:

Hezad

QuoteEverything sounds plausible, I'm just wondering what this does:
Quote
- Texture tiling routine
Usually you would make sure your texture-width/height is a power of two, scale your uv-coordinates and  and mask the appropriate bits ("and" instead of modulo).

I multiply (U,V) values of each vertex by NbTileX and NbTileY and then, while rendering, I check if final(u,v) is > 1. If it's the case, I do this :


if ValU>1 then ValU = ValU-int(ValU)
if ValU<0 then ValU=0
if ValV>1 then ValV = ValV-int(ValV)
if ValV<0 then ValV=0


It gives me ValU after int(ValU) repetitions.


QuoteIt's a good idea to follow standards, but remember that OpenGL's material-model was build around sgi's hardware-capabilities and is sometimes rather unflexible and you'll often want to take some shortcuts in order of optimization.
The important point is to offer the relevant features required to achieve certain effects.

Well, in fact I asked myself "what would I like to do for editing a material when coding with a 3d library ?" and I thought about this way. I have to admit I really didn't think about standards, This engine is not supposed to follow the standards since it surely won't be used excepted by myself ^^

QuoteIf you want to get some ideas about how to use materials & lighting professionally, I can recommend this book:
Some ideas, yep ! But I really don't want to code a professional product, I'd be incapable of doing that :p Just a personal learning tool and -hopefully- a nice gadget tool for people demos and/or code wanderings in the future :) But if I plan to buy a 3d book, I'll firstly look for this one :)
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

Shockwave

Quote from: Hezad on September 25, 2008
QuoteIf you want to get some ideas about how to use materials & lighting professionally, I can recommend this book:
Some ideas, yep ! But I really don't want to code a professional product, I'd be incapable of doing that :p
I don't know about that.. All you need to do is what you've done. Break it down into bits and work on it a bit at a time, even appreciating that it's not a professional product you would surely find some useful things in that book to help you improve the engine even more :)

Quote from: Hezad on September 25, 2008
But if I plan to buy a 3d book, I'll firstly look for this one :)

Enter a competition and win it and I'll buy the book for you :)
The prize fund for the remakes comp is £50 because it's joint sponsored by me and Rbz :) Normally they are half that amount.
Shockwave ^ Codigos
Challenge Trophies Won:

Hezad

Quoteeven appreciating that it's not a professional product you would surely find some useful things in that book to help you improve the engine even more Smiley

Yeah i'm sure about it :) I just wanted to underline the fact that my objectives are not professionals at all : They are just "let's make something beautiful (hopefully) and functional".

It doesn't change the fact this book looks bloody interesting :P


QuoteEnter a competition and win it and I'll buy the book for you Smiley
The prize fund for the remakes comp is £50 because it's joint sponsored by me and Rbz Smiley Normally they are half that amount.

:D Neat idea ! I'm not sure I will enter the comp since I don't have a good demo-scene culture, but i'll look for demos not remade yet ; maybe there will be one I want to work on ^^
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

Hezad

Hey :) It's me again !

I'm trying to write a GenerateSphere Procedure ; having a curved surface is pretty useful for testing shaders/lighting ^^ (yeah, I wanted to relax a bit before entering the frightening world of optimization :D)

The routine works almost well : the sphere shape is well generated, the U,V values too. But there's a problem with the shading ! I use the Gouraud shader and some parts are ok, but some other parts looks like it was shaded with a flat shader :S or worse : it can look like the vertices color are inverted on some triangles (a dark vertice becomes bright and vice versa). Here is a screenshot to illustrate what I'm saying.

Here is the procedure :

Sub ObjectT.GenerateSphere(x0 as integer, y0 as integer, z0 as integer,Radius as integer,nbfaces as integer)
       
        '' x = r sin(theta) cos(phi)
        '' z = r sin(theta) sin(phi)
        '' y = r cos(theta)

        this.Center.x = x0
        this.Center.y = y0
        this.Center.z = z0
       
        dim as single dTheta, dPhi,UAng,Vang,UAng2,Vang2
        dim as integer ActualTri = 1
       
        dTheta = PI/nbFaces : dPhi = PIx2/nbFaces
       
        for theta as single = 0 to PI step dTheta
            for Phi as single = 0 to PIx2 step dPhi
               
                Uang = phi/PIx2
                Vang = Theta/PI
                Uang2 = (phi+dPhi)/PIx2
                Vang2 = (Theta+dTheta)/PI
               
                if theta<>0 and theta<>PI then
                    triangle(ActualTri).Vertex(0).pos3d.x = Radius * sin(theta) * cos(Phi)
                    triangle(ActualTri).Vertex(0).pos3d.y = Radius * cos(theta)
                    triangle(ActualTri).Vertex(0).pos3d.z = Radius * sin(theta) * sin(phi)
                    triangle(ActualTri).Vertex(0).U = Uang
                    triangle(ActualTri).Vertex(0).V = Vang
                   
                    triangle(ActualTri).Vertex(1).pos3d.x = Radius * sin(theta+dTheta) * cos(Phi)
                    triangle(ActualTri).Vertex(1).pos3d.y = Radius * cos(theta+dTheta)
                    triangle(ActualTri).Vertex(1).pos3d.z = Radius * sin(theta+dTheta) * sin(phi)
                    triangle(ActualTri).Vertex(1).U = Uang
                    triangle(ActualTri).Vertex(1).V = Vang2
                   
                    triangle(ActualTri).Vertex(2).pos3d.x = Radius * sin(theta) * cos(Phi+dPhi)
                    triangle(ActualTri).Vertex(2).pos3d.y = Radius * cos(theta)
                    triangle(ActualTri).Vertex(2).pos3d.z = Radius * sin(theta) * sin(phi+dPhi)
                    triangle(ActualTri).Vertex(2).U = Uang2
                    triangle(ActualTri).Vertex(2).V = Vang
                   
                end if
               
                ActualTri +=1
               
                If Phi <> PIx2 then
                    triangle(ActualTri).Vertex(0).pos3d.x = Radius * sin(theta) * cos(Phi+dPhi)
                    triangle(ActualTri).Vertex(0).pos3d.y = Radius * cos(theta)
                    triangle(ActualTri).Vertex(0).pos3d.z = Radius * sin(theta) * sin(phi+dPhi)
                    triangle(ActualTri).Vertex(0).U = Uang2
                    triangle(ActualTri).Vertex(0).V = Vang
                   
                    triangle(ActualTri).Vertex(1).pos3d.x = Radius * sin(theta+dTheta) * cos(Phi)
                    triangle(ActualTri).Vertex(1).pos3d.y = Radius * cos(theta+dTheta)
                    triangle(ActualTri).Vertex(1).pos3d.z = Radius * sin(theta+dTheta) * sin(phi)
                    triangle(ActualTri).Vertex(1).U = Uang
                    triangle(ActualTri).Vertex(1).V = Vang2
                   
                    triangle(ActualTri).Vertex(2).pos3d.x = Radius * sin(theta+dTheta) * cos(Phi+dPhi)
                    triangle(ActualTri).Vertex(2).pos3d.y = Radius * cos(theta+dTheta)
                    triangle(ActualTri).Vertex(2).pos3d.z = Radius * sin(theta+dTheta) * sin(phi+dPhi)
                    triangle(ActualTri).Vertex(2).U = Uang2
                    triangle(ActualTri).Vertex(2).V = Vang2
                   
                end if
               
                ActualTri +=1
            next
        next
       
        this.nb_triangles = ActualTri
       
    End sub


Any idea of what could make this procedure to bug ?

Thanks :D
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

Shockwave

It looks flat shaded tbh, it's probably a problem of normals.

Unit normals for a sphere are easy to generate fortunately, just generate a sphere with a radius of 1 for them :)
Shockwave ^ Codigos
Challenge Trophies Won: