Wednesday, November 25, 2009

Decal on terrain

Today I added decals on terrain.
They are nice and you can rotate decals on terrain and use them for selecting effects also I have an idea to use decals for add dynamic lights on terrain.


Monday, November 23, 2009

Ray-Triangle intersection test code

I noticed that most of the blog visitors come here for Ray-Triangle intersection test so I decide to put the code here.

I hope it is useful for you.

//! Checks if the ray and triangle intersects and store the intersection point in the Out parameter.
CollisionType IntersectRay(Ray* pRay, kge::math::Vector& Out)
{
Edge1 = Point2 - Point1;
Edge2 = Point3 - Point1;
Normal.Cross(Edge1, Edge2);
float fGama = -(pRay->Direction * Normal);

if (fGama < fEpsilon)
return ECT_NotIntersect;

Vector b = pRay->Position - Point1;
float fLanda = (b * Normal) / fGama;

if (fLanda >= 0.0f && fLanda <= 1.0f)
{
Vector u;
u.Cross(b, pRay->Direction);
float u1, u2;
u1 = (Edge2 * u) / fGama;
u2 = (-(Edge1 * u)) / fGama;
if (u1 + u2 <= 1.0f && u1 >= 0.0f && u2 >= 0.0f)
{
Out = pRay->Position + (pRay->Direction * fLanda);
return ECT_Intersect;
}
}

return ECT_NotIntersect;

} // IntersectRay

Sunday, November 15, 2009

Refraction

I added refraction to the terrain.
Just want show a screen shot.
If I had a under water texture the result was better :D

click image for bigger view

Saturday, November 14, 2009

RTT(Render To Texture) With Anti Aliasing added

I added Anti Aliasing for rederable textures but It seems there is no way to use it with MRT.

Thursday, November 12, 2009

Attach nodes to bones

Now you can attach objects to the bones and they will be updated automatically.


The terrain is now divided to smaller sections and the ray picking speed is very good now.
I also write a simple shader that represent the water effect that color the terrain depend on height.
You can see the terrain AABB in the picture that get updated during the edit.

Sunday, November 8, 2009

Blend Tiles, AABB & Ray Intersections

The tiles can be blended with each other now. This way there is no hard edge anymore.

You have to use an alpha map for blending so you have more options for blending. I use this alpha map for test. It is not a good one :D



And here is a screen shot.


I also added AABB and ray intersection to the engine, so I can optimize my terrain more and partitioning it.

If anyone has a question about everything I implemented in my engine please ask me and leave a comment for me I try to answer it :D

Sunday, November 1, 2009

Edit terrain

Hi all

After coding for triangle-ray intersection I start to create a class for getting the clicked triangle. I called this class DynamicTriangleMesh.

DynamicTriangleMesh works slow for now and I need to partition the terrain and add AABB(Axis Aligned Bounding Box) to it then I check the ray collision with AABB if it collide then check for triangle intersection.

I added some functions for editing the tiles and height of the terrain.

I also added a flood fill algorithm to fill the tiles and finding the tiles borders for blending them.

I test my idea about blending and tiling it works good and soon the first version of terrain will be ready.

I also added a screen shot for showing the fill and finding the tile borders with flood fill algorithm.

you can get the latest codes from SVN.
https://kge.svn.sourceforge.net/svnroot/kge

Saturday, October 24, 2009

Ray-Triangle intersection test

I added Ray-Triangle intersection test to the engine. First I want to use PhysX for doing this but this library does not support dynamic triangle meshes it means I can’t change the mesh data very frequently with a reasonable speed so I decide to write my own Ray-Triangle intersection test.

I find an algorithm for do this issue on Collision Detection in Interactive 3D Environments Book it says Ray-Triangle test but when I test the algorithm it works as a line-triangle intersection test. The more interesting thing is that the next chapter is talking about line-triangle intersection test but it works good and the performance is very good.

The next thing I worked on this week was on getting the ray from screen coordinates and this part work good too.

Tuesday, September 22, 2009

The first test for new terrain design

Hi

I test the new algorithm for the tiled terrain and it works well with texture ID.

For solving the texture filtering problem with tile texturing I copy 16 pixel from each side to opposite side of the texture and don't use small mipmap level so the hardware texture filtering works well.

Here is a screen shot I know it is not seem to be good but when I add blending you can see a good screen shot. For now I want to add PhysX engine for terrain pickings and future physics dynamics.

Friday, September 4, 2009

A new tiled terrain design

Hello
After many days of thinking hard on tile terrain finally find a good way to build the terrain.

Before start talking about algorithm I have to say I’m not implemented this algorithm yet and things may be change later.

TextureID:

For storing the tile texcoords I use one textureID with A32R32G32B32F format for storing the tile texcoords offsets then in the pixel shader I use it to map the tiles to the terrain.

I get the idea from Journal of Ysaneya.

No mipmap and texture filtering is needed for this texture.

Vertex:

I need one texcoord for my vertices and they start from 0 to number of columns/rows increase one per vertex.

How to map the tiles:

In the pixel shader I read the tiles offset and creates their texcoord.

X = 1 / number of columns in the tile texture
U = Uoffset + u * X;

For reading the Uoffset from TextureID I can use something like above formula.

X = 1 / TextureID size;
U = u * X;

Thursday, August 27, 2009

Tile terrain

Hi

I worked on tile texture and add this to engine but when I saw Red Alert 3 terrain my mind changed.

I want to add a tile terrain something like Red Alert 3 terrain. Its a tile terrain too. I think I can add this type of tile texturing.

I think a way to combine both of them(WarCraft III style and Red Alert 3) is a good idea.

Friday, August 21, 2009

More active this year

Hi all
I want to be more active this year and work on Kochol Game Engine more.
I hope it become a more useful engine soon.

Currently I work on tile texturing for a tile based terrain like WarCraft III terrain.

The problem with tile texturing is the Anisotropic filter that combine the tiles edge with each other and if you turn this off the quality become bad.

I skip one pixel from each side when I create the UV for terrain and the problem solved but there is another problem with mipmaps.

I have to create mipmaps by a custom way that scale each tile and place it on the mipmap. I use devil to achieve this.

And for a 16*16 tile I use a 16*16 mipmap never less mipmap levels.

Wish me luck.