Tuesday, November 20, 2018

3d - What exactly is UV and UVW Mapping?


Trying to understand some basic 3D concepts, at the moment I'm trying to figure out how textures actually work. I know that UV and UVW mapping are techniques that map 2D Textures to 3D Objects - Wikipedia told me as much. I googled for explanations but only found tutorials that assumed that I already know what it is.


From my understanding, each 3D Model is made out of Points, and several points create a face? Does each point or face have a secondary coordinate that maps to a x/y position in the 2D Texture? Or how does unwrapping manipulate the model?


Also, what does the W in UVW really do, what does it offer over UV? As I understand it, W maps to the Z coordinate, but in what situation would I have different textures for the same X/Y and different Z, wouldn't the Z part be invisible? Or am I completely misunderstanding this?



Answer



Your understanding is close. Each 3D model is made out of vertices. Each vertex usually defines the location of a point in space, a normal (used in lighting calculations) and 1 or more texture coordinates. These are generally designated as u for the horizontal part of the texture and v for the vertical.


When an object is textured, these coordinates are used to look up which texel or pixel to plot from the texture. I find it easiest to think of them as percentages or ratios between the left edge of texture (u = 0) and the right edge of the texture (u = 1.0) and from the top of the texture (v = 0) and the bottom of it (v = 1.0). They are interpolated between the vertices and looked up for each on-screen pixel that is rendered. They can be larger or smaller than these ranges and the render state that is set when the object is rendered specifies what happens. The options for this are CLAMP and REPEAT. Clamping limits the coordinate to either 0 or 1, causing the texture to smear where it is outside of the range. Repeat causes the texture to repeat when it is outside the range; it is effectively the same as grabbing just the decimal portion of the coordinate and using that in its place.


Before the texture coordinates are applied onto an object, they are multiplied by a texture matrix to apply some transformation to them (such as scaling, translation or rotation). This effect is sometimes animated in games to make it appear as though something is moving across an object without having to move the object itself... the texture is simply scrolling across it. When the texture matrix is multiplied by the texture coordinates, it produces 2 values that are used to look up the texel to plot (lets call them s and t). These are generated automatically from u and v even when the texture matrix is not set; it is the equivalent of multiplying u and v by an identity matrix.



This is where the w coordinate comes in, though it isn't used that often. It is an extra parameter to multiply the texture matrix against and is usually used when you want to take perspective into account (such as in Shadow Mapping). It works the same as when you transform a location in object-space to screen-space via a world-view-projection matrix. By multiplying the UVW with a projection transform, you end up with 2 coordinates, the s and t which are then mapped onto a 2D texture.


How do game bots perceive the game world & other entities?



This question has been on my mind for a while...mainly because I see bots for all sorts of games like WoW and others. My question is; how do the bots know what is appearing on the screen? I don't play WoW so my example may be wrong but if for example there is a monster, how does the bot know where that monster is on the screen and how does it know how to interact with it?


Can you apply this to any game or is it specific for each game? I'm sorry if the question isn't clear...and I'm not asking how to make a bot, more asking how they detect things on the screen as its quite fascinating to me!


Thanks in advance :)



Answer



There are many points where a bot can inject itself into the game.




  • The screen is one of them, but by far not the most useful. However, I have once seen a very early aimbot for Counter Strike which used color coding. It came with alternative character models with single-colored textures (the game was modding-friendly enough to allow this) and then just detected pixels of those colors. Not a very effective method, though. It was already quite clunky back then, and becomes less and less viable because graphic engines become more and more powerful, which means more and more detail to confuse any optical recognition algorithms.





  • Another point is reading the memory directly[1]. It is possible to have one program on your computer read the memory of another. So the developer just needs to find out at which memory address the game is saving the information which is relevant to the bot. There are tools which assist the developer with finding what they want by creating a memory image and providing various search tools. A countermeasure is to use address layout randomization, but a smart bot might be able to still find what they are looking for automatically.




  • It is possible to modify the game executable itself. In order to do this the bot developers need to be able to read and program in assembler, which isn't that hard with some practice. They then look for the code which handles the information they are interested in and rewrite it to pass it to their bot. A possible countermeasure from the perspective of the game developer is to use an obfuscator to make the game's assembler code less readable, but these are usually not good for performance and there are tools for many obfuscators which reverse their work.




  • And then there is the netcode. In an online game, the server sends the properties and positions of all objects in the game via network. The network data stream between server and client can be intercepted and analyzed. A popular tool for doing this is wireshark. When the developer reverse-engineered the netcode, they can write a bot which intercepts the network traffic just like Wireshark does and uses the information to make its decision. When the developer is more motivated, they can even develop a complete game client from scratch which implements the network protocol and plays the game without even having any graphical output. Such bots are very popular with gold farmers because without the graphics output the client is usually far more resource-friendly, which means they can run a lot of them at once on a small server.







1: Since you mention WoW, it's worth pointing out that the early and notorious WoWGlider botting program used direct memory access. Blizzard had a subprogram called Warden that was designed to detect and block outside programs from accessing WoW's internal game state. Since the bot program circumvented this protection and read the memory without permission, the 2006 lawsuit MDY v Blizzard was decided in favor of Blizzard on the grounds that the bot maker was encouraging and enabling its users to commit copyright infringement and violate the DMCA.


Changing background music smoothly


I've got five sounds now for a game I'm working on currently. In the game, you can fight against other civilizations in big battles, but you can also settle on planets in peace.


Some of the songs are more violent, while others are quite peaceful. The question is: what is the best practice for changing between the songs. Is it better if I just look "is it peaceful or not" when the old song ends and then play a new one or should I do that every single frame and change the songs immediately.


The first alternative would sometimes play silent songs in battles (because the song started before the battle and isn't finished yet) and the second one would switch between to different-fast songs properly at the wrong moments so the player would hear a cut.


So I'd like to know what is more natural for the player or if there is a different possibility.


PS: The songs are between 300 and 500 seconds long.



Answer



There are actually some fairly standard approaches for designing music playback in a game. When designing a music playback system, problems you face involve creating smooth transitions, ensuring there is enough variety, and creating a sense of interactivity with the music. Your question title, "changing background music smoothly" tells me your main concern is transitions so that's what I'll primarily be addressing for each method.


Method 1: Layers and Stems


One approach for creating smooth music playback systems in games, what Patrick Hughes called the "AAA way", is to build your music up in layers (also sometimes called stems) such that there's no single definitive version of the track. Instead, you might have a single base track running consistently, with melodic, rhythmic, harmonic variations that get played over it.



You usually (credit again to Patrick Hughes) build these around common motif that runs through each element layer in a piece of music, or even througout all music in the game. A good example of a non-melodic motif is Martin O'Donnell's use of the Phrygian scale in Halo games (http://www.1up.com/features/music-halo-reach). Normally, each of these component music tracks are aligned to be playing in sync on a timeline with each other. Although it is possible to create music layers that do not necessarily depend on a consistent tempo and synchronized timeline, or can work well in multiple tempo and timeline contexts.


Because each layer is designed to work together, it's entirely possible to have a single layered music track that just plays throughout the entire game, making slight transitions between layers within itself to signify game state changes.


Method 2: Branching


You say you have music tracks already produced, so this implies you've already got a specific direction in mind: branching music. With branching music, your primary concern is the transition between music tracks that have been specified to play at particular sections of the game. You can achieve variety by breaking your individual music segments down into loops that have a couple of different versions, so that the same version never plays twice in two iterations and doesn't always start out the same way.


One way to handle transitions in simple branching music is to write more music that purely acts as a transition from these existing music tracks to others. Even if it's not feasible to cover every possible music transition, you can also use the "connector tracks" to make a music track end early in the case where you're trying to avoid simple fade-in, fade-out music changes.


Method 3: CCC-Combo


It's also important to note that the two major approaches discussed here (layers and branching are what they're typically called) can coexist conceptually. "Branching" is such a simple term and description of what's happening that you could very well be branching between layered music systems. This often requires a semi sophisticated playback system, so you have to balance what's worth your time to implement.


Method 4: Pragmatism and Simpler Music Playback


And, of course, you could always just fade-in and fade-out your music as needed. No shame if that's what feels right, or it's not feasible to write connector tracks. Better this than hard cuts to completely unrelated piece of music--that would sound pretty awful.


I'd also like to address your "silent songs" idea. It's not bad, but what happens when you start playing one 300-second track for 5 seconds, then you get immediately into a state where you need to transition to another track? Waiting for the remaining 295 seconds to go by seems impractical if you really care about making that music transition.



However, if the music is purely background music, and its fundamental purpose is to provide to simply set an overall mood, then "simple background music list" is a perfectly legitimate way to think about it. At this point you are talking about a music playlist like you'd build in iTunes or Windows Media Player (is that still at thing?) so you should implement it with that in mind.


Further reading


To learn more about standard approaches for designing music playback in games, you should take a look at learning materials for two of the largest interactive audio middleware tools that see common use in the industry, FMOD and Wwise.


Wwise has good reference material on this page. The "Making Interactive Music for Games" article is especially good as it goes into further depth about the information I've written here. The FMODTV Youtube Channel has videos with Stephan Schutze that cover FMOD Studio as a whole--including the parts of it that can be used to design music playback systems. Learning how these tools approach this problem can help you think about how to address your own game's needs.


path finding - Tweaking AStar to find closest location to unreachable destination



I've implemented AStar in Java and it works ok for an area with obstacles where the chosen destination is reachable.


However, when the destination is unreachable, the calculated "path" is in no way to the closest location (to the unreachable location) but is instead some random path.


Is there a feasible way to tweak AStar into finding the path to the closest location to an unreachable destination?



Answer



Keep track of the node with the lowest EstimatedDistanceToEnd (ie. the lowest h(x)), and if no end-node is reachable to backtrack from, backtrack from that node instead.


ambiguity - Certain kinds of fish or certain kinds of fishes?




Below is an excerpt taken from the passage given at Passage Comprehension page.



Many scientists are working on safer and better ways to kill mosquitoes, but so far, there is no sure way to protect everyone in the world from their deadly bites. Mosquito nets can be placed over beds to protect people against being bitten. These nets help people stay safe at night, but they do not kill any mosquitoes. Mosquitoes have many natural enemies like bats, birds, dragonflies, and certain kinds of fish.



My doubt is regarding the bolded phrase. Is the bolded phrase correct?


Shouldn't it be either certain kinds of fishes or certain kind of fish.



Answer



Not at all. The reason is the way the phrase is constructed: the thing of which there are kinds is fish. You can say "kinds of fishes", but it would be redundant and a bit absurd, since "fish" is a common name referring to an entire species, and thus, referring to "all" the fishes already.


It is not an English thing, it is a common construction in several languages when describing groups of things. The thing itself is singular, and the properties referred of said thing (kinds, weights, heights, colours, whatsoever...) go in plural. This is because the actual subject is the property itself, "they" (since the property is referring to a group, and is therefore plural).



To put it simply, the phrase is actually like "Soldiers of England". Soldiers is the subject. So you could weirdly change it to "they are of england". Different kinds of fish, in the same way, could be substituted by "they are of fish". Which things are of fish? Different kinds.


word choice - Confusion regarding “to doing something” vs. “to do something”



I am always confused with the form of “to doing something”, e.g.:



I admitted to doing something.



vs.:



I admitted to do something.





Monday, November 19, 2018

comprehension - “save for” -- meaning?


Example with a context:



Earlier this evening, I sat in the Salt Lake Roasting Company, a gourmet coffee roaster in Salt Lake City, and, over several cups of hot, fresh, delightfully aromatic Costa Rican coffee, scribbled the notes for this introduction. It occurred to me that selecting an Access development book is much like choosing your next pound of coffee beans: Without some sort of guide, one Access book looks pretty much like the next save for differences in their tables of contents and covers, just as two pounds of coffee from different regions of the world seem indistinguishable but for slight variations in their aroma and appearance. This book is different from the typical Access books sitting right next to it on the bookshelf. Some of the reasons are:



How do you understand that expression? Does that mean something like never mind their differences in the tables of contents and covers?



Answer



Save for means the same as except for.


In this sense of save for, the word save suggests holding some items back, or setting some items aside so they don’t get involved in some activity. “I brought all of my best silverware to Karen’s Christmas party, save for a few delicate antiques.” In other words, you protected the old, delicate pieces of silverware by keeping them at home instead of bringing them to the party. A real example: “The fight went on until the whole Turkish squadron, save for the steamer, was destroyed.”


In the paragraph you quoted, the author is suggesting that as you look over the many books about Microsoft Access, their attributes blur together in your mind so you can't distinguish one book from another. But a few attributes are “saved” from getting blurred together: the tables of contents and the covers.



The metaphor of saving is mostly but not completely dead.


To my native American English ear, save for sounds old-fashioned.


Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...