Jump to content
  • Advertisement

mzbear

Member
  • Content Count

    9
  • Joined

  • Last visited

Community Reputation

220 Neutral

About mzbear

  • Rank
    Newbie

Personal Information

  • Interests
    Art
    Programming
  1. mzbear

    Spaceship weapon ideas?

    How about a huge ball connected to the ship via a chain? What about a massive drill in front of the ship? Perhaps a ship should be able to deploy a minefield, or even completely turn itself into a minefield leaving only a tiny shuttle behind? Wouldn't it be fun to drop a mini black hole that affects gravity in the battlefield and messes with projectiles? Or perhaps you should go super loose with science and make things like "Mirror Matter Annihilator" which fires a massive beam that seriously messes with gravity around the path of the beam, which would cause enemy ships to randomly spin around making their weapons hit friendly targets. Anyway, it makes gameplay fun when weapon variations enable players to play entirely differently rather than just doing damage in different looking way. Damage over time + kiting, single target vs area of effect, crowd control, defensive/mitigative weapons, all sort of concepts can be included. Even if you want to stick with just simple projectiles+lasers, you should probably still deal with drones, carriers and fighters etc, because it really makes no sense economically to put an expensive ship in range of enemy weapons when you can just launch shitloads of cheap mobile weapon platforms to do the job.
  2. That's not how it works. 4 values is 2 bits, while 256 values is 8 bits. With 256 values, you can only store 4 separate maps of 4 values each. You'll do this with bit masking and shifting. To store 64 maps overlaid in this manner, you'd need to pack the data into four 32bit values, hardly a practical solution.
  3. random guess from the dark: it's trying to mipmap a texture that doesn't have mipmaps, i.e. it has nothing to do with texture units and all to do with how you're using the texture bound to the unit.
  4. Short answer: in your vertex shader, FragmentPos is wrong. Instead of copypasting code, please seek to understand exactly what it does and why does it does so. Long answer: The shadow map is supposed to be a depth map, but you're taking vectors out of it in the vertex shader... using completely unrelated texture coordinates, no less, this doesn't make any sense whatsoever. You could think of the shadow map texture as a lookup table for ray tracing the primary light rays, i.e. the ray between the fragment position and the light source. You will basically have to transform the fragment two different ways, for two different "cameras" to get the values you need to do this calculation. One of the cameras represents the main display, and the other represents the light. The light camera was previously used to create the depth map, in which each texel represents a single ray of light, and the depth value is the distance a light ray can travel before it gets obstructed. To perform the shadow calculation, you will test if the distance traveled by the light is shorter than the actual distance to the fragment that's being shaded, to determine if the light is obstructed before it reaches the fragment in question. Thus, your vertex shader shouldn't do texture lookups, it should just output the position of the vertex in lightspace, i.e. lightSpaceMatrix * vec4(vertexPos, 1)
  5. Back in 2012: https://twitter.com/id_aa_carmack/status/174963444779462656 ... maybe this is still the case, so just don't do it.
  6. Do you really need them sorted, or do you just need to go through them in a sorted order?   In the latter case, you could just generate an index array and sort just that... std::vector<int> order; order.reserve(PersonID.size()); for(int i=0; i<PersonID.size(); i++) order.push_back(i); std::sort(begin(order), end(order), [&](int a, int b){ return HitRatio[a] < HitRatio[b]; }); for (int idx : order) { std::cout << PersonID[idx] << ": " << HitRatio[idx] << std::endl; } Or you could abuse std::multimap since it automatically sorts itself... std::multimap<int,int> hack; for (int i=0; i<PersonID.size(); i++) hack.emplace(HitRatio[i], PersonID[i]); for (const auto &hit_person : hack) { std::cout << hit_person.second << ": " << hit_person.first << std::endl; } Or you could make a struct for your hitratio records, even a dummy one just inside your function that needs it... struct HitRatioRecord { int id; int ratio; bool operator< (const HitRatioRecord &other) const { return ratio < other.ratio; } }; std::vector<HitRatioRecord> hrr; for (int i=0; i<PersonID.size(); i++) hrr.push_back({ PersonID[i], HitRatio[i] }); std::sort(begin(hrr), end(hrr)); for (const auto &v : hrr) { std::cout << v.id << ": " << v.ratio << std::endl; } I could come up with a dozen more ways to do this but I suppose I'll stop here :)   EDIT: const auto & instead of just auto to avoid unnecessary temporary object copies...
  7. You should probably make a separate traits-styled mechanic (using specialization) to do Type2Type lookup backwards too, that way your template function can lookup Type without having it as a template parameter directly.
  8. You're rendering as a triangle strip. I don't think you meant to do that.
  9. So, I take it you want to avoid branch mispredictions messing up things. As long as you only do an assignment in the condition block, the compiler (assuming a release build) will be able to do it without branches. I just tried the following with GCC (you would remove the noinline in production code obviously)   template< typename T > bool __attribute__ ((noinline)) AreAllTheSame8( const T (&array)[8] ) { bool same = true; if (array[0]!=array[1]) same = false; if (array[0]!=array[2]) same = false; if (array[0]!=array[3]) same = false; if (array[0]!=array[4]) same = false; if (array[0]!=array[5]) same = false; if (array[0]!=array[6]) same = false; if (array[0]!=array[7]) same = false; return same; } And it produced the following function with gcc -O3 -S for an int array   __Z14AreAllTheSame8IjEbRA8_KT_: ## @_Z14AreAllTheSame8IjEbRA8_KT_ .cfi_startproc ## BB#0: pushq %rbp Ltmp4: .cfi_def_cfa_offset 16 Ltmp5: .cfi_offset %rbp, -16 movq %rsp, %rbp Ltmp6: .cfi_def_cfa_register %rbp movl (%rdi), %eax cmpl 4(%rdi), %eax sete %sil cmpl 8(%rdi), %eax sete %dl cmpl 12(%rdi), %eax sete %cl andb %dl, %cl cmpl 16(%rdi), %eax sete %dl andb %cl, %dl cmpl 20(%rdi), %eax sete %cl andb %dl, %cl cmpl 24(%rdi), %eax sete %dl andb %cl, %dl cmpl 28(%rdi), %eax sete %al andb %dl, %al andb %sil, %al popq %rbp retq .cfi_endproc For 8bit and 16bit integers it generated an additional movzwl or movzbl per array entry respectively, which you could manually try to optimize by building a wider comparison value (well, why not for 32bit values too if compiling for 64bit platform). Using the idea from Álvaro's post we get this which reduces the function down to only a handful of instructions:   template<> bool __attribute__ ((noinline)) AreAllTheSame8( const uint8_t (&array)[8] ) { uint64_t v = *reinterpret_cast<const uint64_t*>(&array); return v == ((v & 0xffull) * 0x0101010101010101ull); } __Z14AreAllTheSame8IhEbRA8_KT_: ## @_Z14AreAllTheSame8IhEbRA8_KT_ .cfi_startproc ## BB#0: pushq %rbp Ltmp0: .cfi_def_cfa_offset 16 Ltmp1: .cfi_offset %rbp, -16 movq %rsp, %rbp Ltmp2: .cfi_def_cfa_register %rbp movq (%rdi), %rax movzbl %al, %ecx movabsq $72340172838076673, %rdx ## imm = 0x101010101010101 imulq %rcx, %rdx cmpq %rdx, %rax sete %al popq %rbp retq .cfi_endproc As you can see, no branches, no need for silly trickery. Just avoid the short-circuiting conditional && and || and the compiler will probably do fine.   EDIT: For the 64bit trick, the array better be alignas(uint64_t), and I'm not 100% sure if that reinterpret_cast is actually legit in C++ (it would be undefined behavior in C at least due to strict aliasing requirements). It might be safer to work around it using unions, but the generated code seems fine.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!