• Content count

  • Joined

  • Last visited

Community Reputation

668 Good

About jmakitalo

  • Rank
  1. Entity-Component Confusion

      I have similar topic and I was directed to this bitsquid blog that I found very helpful. Making a manager for each type of component avoids problems with storing inhomogeneous data in arrays. I also liked their idea not to constrain the component managers that much. Different type of components may benefit from different type of component storage and entity<->component indirection. I personally would create base component manager classes for some most typical situations to avoid code dublication.     Use the "swap and resize": move the last item to the place of the removed one and reduce the array size by one. Of course if entities refer directly to component arrays, the one moved component will no longer point to the correct entity. You need to add a layer of indirection: one array stores components, the other maps entities to the components.
  2.   This limits entities of having only one component of a given type. Not necessarily that bad constraint, but kind of unnecessary.     At least in C++, I would try to achieve data locality and avoid such storage.     This is reasonable, but you need to have space for all entities in all component arrays. Some components may be used by only a few entities.   I'm currently experimenting with an approach inspired by the bitsquid blog linked above, where component managers may implement different types of component<->entity indirections. For widely used components, the manager stores a vector of indices to components. For infrequently used components, the manager uses a map. I implemented base component manager classes for these two cases, but nothing prevents component managers from implementing some different indirection.
  3. Projection into Spherical Harmonic Basis

      This is strange. If you just interpolate the original measurement points to create more data, you are creating data that is linearly dependent on the original data. No new information should emerge.   Did you take the original measurements at the correct quadrature points, i.e., the points where the integration weights are defined? Keep in mind that you don't "integrate over sample points". Surface integral over a set of isolated points vanishes. What you do is make and approximation to a surface integral in the form   int_S f( r ) dS = sum_n w_n*f(r_n)   where w_n are the weights and r_n the nodes of the quadrature rule.   For 2D surface integrals with smooth surface S, you can use the Fubini's theorem to write your spherical integration as   int_0^pi int_0^2pi f(theta, phi)*sin(theta) dphi dtheta = sum_n sum_m w_n*w_m*f(theta_n, phi_m)*sin(theta_n) + E   where E is some error that we are willing to neglect and the weights and nodes are now for some integration over finite 1D interval (trapezoidal, Simpson's, Gaussians, etc.)   The nodes theta_n and phi_m should coincide with your measurement points. If you can choose your measurement points, you should choose them to match the nodes of the quadrature rule.
  4. OpenGL Quick texture array question

      The code looks fine to me as far as I can interpret it without further information. Are you sure that your uniform ids are properly resolved? Are you binding the shaders before calling glUniform etc?
  5. Resource Manager Design

      Ok, replying to this goes somewhat off topic, but this is very timely for me.   So you do store the parameters as name-value pairs like I suggested. It's a map. I guess that the Parameter class stores some union of admissible parameter types? Anyway, if you don't cache the values to some C++ types, each time you request a parameter from a resource you will need to make O(logN) lookup of the map, performing string comparisons. This may be neglible in some simple 2D game with a few resources, but I would not use it for rendering complex 3D scenes with hundreds of resources (with multitude of parameters) accessed each frame.   Storing the names may not take more than a few kilobytes, but usually such degeneracy suggests that the design could be improved.
  6. OpenGL Quick texture array question

      The value for glUniform1i() maps to the active texture unit, i.e., glUniform1i(textureUniformLoc, 4); corresponds to glActiveTexture(GL_TEXTURE4); This works the same for all types of textures. Only difference is how you access the texture data in the shaders. I usually set the uniform once during initialization when setting up the shaders.
  7. Projection into Spherical Harmonic Basis

      Do you specifically need interpolation property, i.e., that the approximate representation will take on the sample values at their original locations? Or do you want to get a good overall representation of the function of which you have some limited set of samples?   Technically speaking, to get better approximation when increasing the order of the expansion, the original function needs to be in the L2 function space over a sphere.
  8. What is the gradient symbol for

      It is normalized by the r in the denominator. In the given formula, the unit vector is given explicitly in the form r/r.
  9. OpenGL Quick texture array question

    As NumberXaero suggested, you bind the array to one location, say 1: glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D_ARRAY, texturearray); glUniform1i(location, 1); In shaders you use uniform sampler2DArray arrayTex; /* ... */ void main() { float index = 0.0; vec4 color = texture(arrayTex, vec3(texCoord.xy, index)); /* ... */ } The third component of the second argument to texture is the array index. Arrays are great for overcoming texture image unit limitations, although the layers will need to have the same properties
  10. Resource Manager Design

      If I understand correctly, the resources derive from a base class that stores parameters as some name-value pairs.   I have also been thinking a lot how to associate parameters with resources so that they could be easily read from/written to files and perhaps used to automatically generate in-game menus for editing. However, storing the name literals is wasteful. For example, probably most "sprites" contain "frames" parameter. Each resource then stores this same literal for nothing. Also, searching parameters by name is slow, so the values should be cached in actual variables for run-time use.   I think I found a rather good way to overcome these issues. I only store parameters as proper typed variables. For bulk actions (serialization etc.), the resource creates a collection of generic variable objects, which act as mediators. For example: class CSprite { private: int frames; std::string name; public: std::vector<CVar> getParameters() { std::vector<CVar> p; p.push_back(CVar("name", &name)); p.push_back(CVar("frames", &frames)); return p; } }; The generic variables (type CVar) store pointers to the actual data. To construct a resource from a datafile, the getParameters() is called to get a routing to the data. These parameters are only used temporarily. My actual implementation uses a base class CVarBase for CVar<T> and vectors of base class pointers are returned, so this was a simlified example.
  11. Projection into Spherical Harmonic Basis

      Practically, yes. In the continuous formalism, the expansion factors a for function f are obtained by <img src=" a_{lm} = \int_0^{2\pi}\int_0^\pi Y^*_{lm}(\theta,\phi)f(\theta,\phi)sin(\theta)d\theta d\phi" /> Where the sin factor is the Jacobian. You can use which ever numerical integration you find most fit. For smooth functions, you could use the Simpson rule for both angles in a nested way. This is enabled by the Fubini theorem for smooth integrands. You might also use Gauss family of quadrature (e.g. Gauss-Legendre) to reduce the number of evaluation points.     I don't know the precise answer to this, but what you are most likely doing with SH basis is not interpolation, but approximation. When you evaluate your function in the truncated SH basis, there is no guarantee that it will interpolate your sample points. If you have only a few samples, you probably get aliasing issues as with the more traditional Fourier series.
  12. Resource Manager Design

      I strongly agree. Storing inhomogeneous data typesafely and without unnecessary typecasting is difficult in C++. The most natural way is to make one manager per type of resource. This also works in other similar problems, such as in entity component schemes (one manager per component).   You may want to check my recent thread . I'm still in the process of making a generic resource manager framework myself.   Depending on your requirements, you may want to consider the use of handles to mediate resource usage.     I discourage this approach. It's the "C way" and is not typesafe.
  13. Fluid dynamics can be quite heavy on vector analysis. I strongly recommend that you pick some book on the fundamentals on the matter. Otherwise you are relying on copy-pase process and will start many topics in the future for no good reason. I dont have time right now to dig into how eq 9 results, but I can answer the trivial questions. The two vertical lines denote a norm, most probably the L^2 norm. It is a scalar. Subscript pk just refers to which variable grad operates on. Now that there are several possibilities, this is mandatory. However, I find it a bit bad notation that the gradient is with respect to some specific particle positions. The equations could be written more simply with just generic gradient function.
  14. How is your game map different from a collection of objects? Is it a terrain or some unstructured mesh? Anyway, why not split the map into smaller pieces. Then determine the four most important lights for each pice. Do you anticipate that there will be more than four lights that significantly influence small portions of the map?
  15. What is the gradient symbol for

      Assuming that the math routines do what I think they do, this seems fine. How do you know it is not working? Have you plotted the result to see if it looks like you might expect from the geometric interpretation of the gradient?   A word of warning: I once tried out particle hydrodynamics for some fluid simulations. I never got good results, because there are alot of parameters to play with and it requires a lot of iteration to get things work reasonably. Worst of all, usually the behaviour depends sensitively on the number of included particles and the chosen timestep. Change the timestep and all other parameters may need to be revisited.