• Content count

  • Joined

  • Last visited

Community Reputation

106 Neutral

About Kripke

  • Rank
  1. Thanks for the input! I don't see why that wouldn't work and why I didn't think of it I will tinker a bit and get back!
  2. Hello, Long time lurker, first time poster. Using Java and LWJGL (2d), I am trying to render highlights on specific parts (areas) of a screen sized textured quad: [img][/img] The areas are as you can see irregular and further defined by another image, grayscale, where each area has a unique color value: [img][/img] The purpose is to through the gray scale image and a variably sized collection of grayscale color values (e.g byte[] barr = {56, 59, 61, 46, 51}), specify what areas that should be highlighted. I have something that works somewhat, using shaders, but is horribly slow. It involves sending an array with the areas (gray scale color values) I want highlighted to the shader, setting the color of those areas to for instance green in the shader, and the rest to alpha 0, iterating over the array with a for-loop. When the shader is done, a screen sized quad is rendered, alpha blended with the original color map. This gives the result I want but suffers greatly from increasing the size variable. Highlighting 50 areas gives a framerate of ~5-10. The fragment shader looks something like this: [source lang="cpp"] uniform sampler2d texture; uniform int size; uniform float cols[100]; void main() { vec4 pixel = texture2d(texture,vec2(pos)); for(int i = 0; i < size; i++) { if(pixel.r == (1.0/255.0) * cols[i]) { // set color to transparent green break; } else { // set color to invisible } } } [/source] It seems as the for-loop is the culprit, looping over 1 element for instance is ok, but still slow. Another way would be to create a 1d texture instead of an array to send to the shader, but I guess I still would need to loop over the texels of that texture and do the comparison. Or is it possible to check if the pixel's color "exists" in the 1d texture/array? Is there another way of going about this effect with or without shaders? Some fancy blending technique? Any ideas would be very welcome, and let me know if you need any more information.
  3. Here are some newb-thoughts of mine. As I understand it: If you have a component, you will also need a corresponding system; an implementation acting upon a particular component. The components are just data, they don't know about eachother or anything for that matter, they are just containers. The systems however, sometimes will need information from several different components. Take the ExplodeOnDeath-example. If you have such a system, it's likely that there's also an ExplodeSystem and maybe a HealthSystem. The ExplodeOnDeath-system would fetch all entities with an ExplodeOnDeath-component and check the Health-component of the same entity if the hp have reached zero and if that's the case, the system would add an Explode-component. The Explode-system would then pick up the entity and do what that system does, maybe start an animation in an Animation-component, which the RenderSystem would pick up on and so on. The ExplodeOnDeath-system would need to select all entitites that has a ExplodeOnDeath-component and then for each entity, fetch the Health-component. These kinds of queries seems eerily sql-like and would fit well with a relational database structure. The fact that an entity posseses a particular component, acts as an "event" in it self and i don't see the need for a further event managing "system". I haven't gotten that far in my implementation though so the need might arise. Just some thoughts.