Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [ODFAEG] (Open Source Development Framework Adapted for Every Game)  (Read 139277 times)

0 Members and 2 Guests are viewing this topic.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #150 on: March 28, 2014, 11:14:31 am »
I think I wasn't clear anought sorry, I use bot, component and scene nodes.

The component is the entity manager.

And the world contains components (entity managers) and systems which updates the entities and components that I use to draw the scene.

I need to use shaders because otherwise if I render 3D vertices with semi-transparent texture (like glass or water per example), semi-transparent object pixels hides opaque pixels.

The first fragment shader solve the first part of the problem : if the z component of the pixel that I want to draw is greater or equal to the z component of the current framebuffer's pixel I perfom an alpha test, and I only draw the pixel on the depth texture if its alpha component is greater or equal than the alpha component of the current framebuffer's pixel.

GL_GREATER_OR_EQUAL is not avalaible for the opengl alpha test, you've to specify a precis value, this is why I can't use the opengl alpha test.

I can't use the GL_DEPTH_COMPONENT because I need to also have the alpha value of the depth texture. (And not only the z value)

The second fragment shader solve the second part of the problem if the z component of the pixel that I want to draw is less greater than the z component of the current framebuffer's pixel.
If the alpha component of the current framebuffer's pixel is less greater than the alpha component of the pixel that I want to draw, I draw nevertheless the pixel.

I don't really knows how vbo's work but I think I'll use them later. ^^ (I'm always confunding VBO and FBO. :@)

For the zfar I can solve the problem if I normalize the z coordinate in the shader. ^^

I thought that it was already done and that the z value was between 0 and 1 but it doesn't seems to be the case, so, I think I just need to do this in the projection matrix.

I have different proportions with perspective and orthographic projections (screen coordinates are between 0 and screewidth with orthographic projection and between -1 and 1 with perspective projection so, I think I have to normalize them in the projection matrix for orthographic projection to pass from viewport coordinates to normalized coordinates)

I thing that's it's what Laurent does it in his projection matrix. (Because I didn't have this problemwith SFML matrix)

Thanks for your answers, but some points are still obscure to me. (It also do this for lurning purpose)

I hope that I've answered to your questions, but I need to read a thrad about modern GLSL, the threads that I've read was made several years ago so I use deprecated functions.
« Last Edit: March 28, 2014, 11:27:22 am by Lolilolight »

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #151 on: March 28, 2014, 11:59:31 am »
I need to use shaders because otherwise if I render 3D vertices with semi-transparent texture (like glass or water per example), semi-transparent object pixels hides opaque pixels.

Why? Do you have blending enabled? Are you rendering the transparent objects last?

I think you are reinventing the wheel in some aspects, and inventing it squared..  There are well known tutorials, books and tips around the internet which tell you how to actually efficiently solve those issues. Try to read Game Engine Architecture for example. Not that it is a prime example, but it should help you structure your mind around 3D engines.. Also a good OpenGL book would be nice. If you still don't know what an VBO is / why is it so important, then you are clearly underestimating the task you re doing..

As far as I know (I might be wrong on this one), after multiplying your 3D vertex with the projection matrix, if its z component is not normalized, between -1 and 1 in case of opengl, I believe you need to divide all components of the vertex by its W. I say between -1 and 1 because I _think_ opengl clips geometry at -1 and 1 to all components of the vertex, after normalizing it(dividing by W internally if needed). http://www.opengl.org/archives/resources/faq/technical/transformations.htm  9.011
« Last Edit: March 28, 2014, 12:01:48 pm by Grimshaw »

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #152 on: March 28, 2014, 12:33:31 pm »
Quote
I need to use shaders because otherwise if I render 3D vertices with semi-transparent texture (like glass or water per example), semi-transparent object pixels hides opaque pixels.

Why? Do you have blending enabled? Are you rendering the transparent objects last?

But what if the alpha component of the texture's pixels of the objects is not the same (I've textures with semi-transparent and opaque pixels)

It'll not work and I can't sort the objects by they z component  if I have pixel's object which are before and other pixel objects with are after another object.

And opengl need all the vertices of my faces to do the interpolation.  (I can't do a sorting by vertices)

So I need to use a shader. :)

I'll read some books about vbo's.
« Last Edit: March 28, 2014, 12:54:00 pm by Lolilolight »

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #153 on: March 28, 2014, 01:46:39 pm »
So the advantage of my shader is that I can draw objects without carrying on the drawing's order of objects using semi-transparent textures.

I can cross every semi-transparent textures of different objects between them. (And creating nice effects)

I only have to regroup vertices using the same texture and the same primitive type in a map, and then, draw everything.

But I use several component to render each entities, because, for light and shadows in 2.5D I don't need to use a shader but a simple render texture.



Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #154 on: March 28, 2014, 02:48:46 pm »
Quite confusing :p I foresee a rewrite of your code  in 3..2..1 :p

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #155 on: March 28, 2014, 03:13:30 pm »
I've found the bug with shadows it was not a bug of the framework, I've forgotten that I have to get visible entities out of the world before getting the shadow map because it's the getVisibleEntities function which draw the shadows on the render texture.

The application class is able to draw object directly on the framebuffer if it's not a tilemap, otherwise the object is drawn on a tilemap and use my shaders.

I know that it's quite confusing but I just want to do animated water by example or other animations by changing the z component of the vertices onwich the textures waters are mapped.

I'll use this same technique is used for the color computation of the pixel with lights. (The only difference is that the view matrix is different because we need to have the depth value relative to the light position and not to the camera's position.

Personnaly I prefer use this rather than cube maps, normal mapping and other older techniques. (I find it more simple)

Moreover, I can computing the pixel color in function of different parameters like refraction, light deviation, the alpha channel and so on.

PS : I have still to correct something because the position of the lights and shadows is not correct when I move the view, mmm...., it's quite difficult if we want to have a view which can point in any direction in a 2D or a 3D world.
« Last Edit: March 28, 2014, 03:18:03 pm by Lolilolight »

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #156 on: March 28, 2014, 04:54:45 pm »
Quote
Personnaly I prefer use this rather than cube maps, normal mapping and other older techniques.

What exactly do you prefer? These techniques are not really old and don't have many replacements.

Quote
But what if the alpha component of the texture's pixels of the objects is not the same (I've textures with semi-transparent and opaque pixels)

It'll not work and I can't sort the objects by they z component  if I have pixel's object which are before and other pixel objects with are after another object.

Your shader will not solve these problems. Also, keep in mind that you cannot read from a framebuffer while you are writing to it.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #157 on: March 28, 2014, 08:59:46 pm »
But my shader works, I have semi-transparent texture that I draw in any order and I have the same result that the sorting that I've made with the z position of my vertices.

I cannot read to a framebuffer while I'm writting on it, it's why I use FBO.

But I've a question, if I put negative size with the glViewport function, will it inverse the x and y vertex positions ???

I would like that the developper can choose the unity.
« Last Edit: March 28, 2014, 09:02:37 pm by Lolilolight »

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #158 on: March 28, 2014, 10:05:00 pm »
I've tried this :

float* ViewMatrix::getGlMatrix () {
    float* matrix = new float[16];
    if (needToUpdate3D) {

        matrix4f.m11 = xAxis.x * s3d.x;
        matrix4f.m12 = yAxis.x * s3d.x;
        matrix4f.m13 = zAxis.x * s3d.x;
        matrix4f.m14 = 0;
        matrix4f.m21 = xAxis.y * s3d.y;
        matrix4f.m22 = yAxis.y * s3d.y;
        matrix4f.m23 = zAxis.y * s3d.y;
        matrix4f.m24 = 0;
        matrix4f.m31 = xAxis.z * s3d.z;
        matrix4f.m32 = yAxis.z * s3d.z;
        matrix4f.m33 = zAxis.z * s3d.z;
        matrix4f.m34 = 0;
        matrix4f.m41 = -xAxis.dot(o3d);
        matrix4f.m42 = -yAxis.dot(o3d);
        matrix4f.m43 = -zAxis.dot(o3d);
        matrix4f.m44 = 1;
        needToUpdate3D = false;
    }

    matrix[0] = matrix4f.m11;
    matrix[1] = matrix4f.m21;
    matrix[2] = matrix4f.m31;
    matrix[3] = matrix4f.m41;
    matrix[4] = matrix4f.m12;
    matrix[5] = matrix4f.m22;
    matrix[6] = matrix4f.m32;
    matrix[7] = matrix4f.m42;
    matrix[8] = matrix4f.m13;
    matrix[9] = matrix4f.m23;
    matrix[10] = matrix4f.m33;
    matrix[11] = matrix4f.m43;
    matrix[12] = matrix4f.m14;
    matrix[13] = matrix4f.m24;
    matrix[14] = matrix4f.m34;
    matrix[15] = matrix4f.m44;
    return matrix;
}
 

I've found this on this following link : http://stackoverflow.com/questions/349050/calculating-a-lookat-matrix


But it doens't work, I'm really wondering about how this guy is doing.

PS : this is only the translation with doesn't work.
« Last Edit: March 28, 2014, 11:13:08 pm by Lolilolight »

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #159 on: March 29, 2014, 12:41:10 am »
You should really calm down and first understand what you are doing.. only then do a library with it..

Didn't look at it, but if you are copying the matrix right, you might need to transpose it or switch the multiplication order..

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #160 on: March 29, 2014, 08:32:27 am »
No, it's ok, I'll keep my Heuler angle camera system, It can manage a lot of different cameras : FPS camera, tack bal camera, free fly camera, etc....

And not every game use a lookat matrix.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #161 on: March 29, 2014, 11:27:36 am »
PBO are they faster than shaders ???

http://www.songho.ca/opengl/gl_pbo.html#pack

If yes I can try to replace my shaders by a pbo but I don't know if I can make special effects with this, but maybe for my own depth and alpha test I can try to use them.

But it's not my priority to do that for the moment, I need to finish all framework functionnalities and to have a demo, I can optimisate this later. :)

I've changed the source code so many times yet so, it can wait. ^^

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #162 on: March 29, 2014, 12:10:48 pm »
I've changed the source code so many times yet so, it can wait. ^^
Maybe it would pay off to think about the design before writing the code...

Especially for a project of this scale, a detailed structure of the code is absolutely mandatory. And instead of trying to implement all features at once (which leads to certain failure), you should rather make the existing functionality robust before you go on. Robust means: Provide a clean API, write documentation, fix bugs, optimize, ...

I doubt that you'll listen to this advice, but who knows. And maybe a future reader of this thread who isn't only here for entertainment can benefit from it ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #163 on: March 29, 2014, 01:45:46 pm »
It's impossible to think about all the design before, there is always something new which can come.

Manytimes you've to change your code, even with a good design I could'nt predict by example that SFML2'll add the possibility to create scene nodes, and I event didn't know about VBO, I've always used classes provided by SFML because until now they where sufficient.
SFML, and vertex arrays because I haven't any problem of performance.
But the most paintfull is to make it work on all plateform, some graphical cards support opengl functionnalities than other graphical cards doesn't support.

But I think that my code design know is robust, even if a passing textures to a shader is maybe a bit slower but I gain performance by executing the code on the GPU and not on the CPU. (I've read before that shader and FBO are fastest anyway than PBO.)

But maybe it was not true in all the cases. If we want we can discuss a lot about performance...

But if it's playable I don't really see an emergency by modifying the source code, I've already done a lot of optimisations until now for the scene rendering.
« Last Edit: March 29, 2014, 01:47:59 pm by Lolilolight »

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #164 on: March 29, 2014, 02:02:39 pm »
What Nexus means is that you are still a beginner using openGL, and you should go back to learning and thinking, making small prototypes, getting familiar with it and then come back..

What you are trying to do is simply above your programming level right now. Nothing you can change with some study and time. But if you keep rushing the task right now like you are, you will waste time and make your own life harder.. I think most developers have been there and learned just the same.. I've been there too (kind of)..

 

anything