# Aressera

Member

458

• #### Days Won

1

Aressera had the most liked content!

2936 Excellent

• Rank
Member

## Personal Information

• Role
Audio Engineer
• Interests
Audio
Programming

## Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

2. ## Distribute points onto height field according to density

What you want is known as "importance sampling". A simple way to implement it is to interpret the densities as probabilities in the range [0,1]. Then, until your grass budget (e.g. number of instances) is met, pick a random 2D point on the surface. Generate an additional random number in the range [0,1], if that number is less than the density at that point, keep the point as a grass instance. Otherwise, discard that point and generate a new one.
3. ## Quaternion-based camera unwanted roll

The order in which the euler angle rotations are composed is not consistent with your expectations of camera behavior. You would need to build the quaternions for each of the 3 euler angle rotations individually, then multiply them in the correct order for your axes/euler conventions. Usually you would use R=(Yaw)*(Pitch)*(Roll) for a first-person camera, where R*x rotates x from camera space to world space. If you always want the camera to have a consistent orientation, you can also fix the up vector to always point up by first forming the R matrix, then replacing the up column vector (usually either Y or Z) with (0,1,0), then orthonormalizing the matrix.

5. ## Updating Bounding Volume Hierarchy Leaves

Usually this is handled by a 2-level BVH, where each lower level BVH have transformations associated. One BVH for the objects in the scene that is dynamic, and a second static one for each mesh that is nested within the scene BVH. When traversing the scene, you only transform what is necessary. For the case of ray casting, you would just transform the ray into the mesh's local BVH space, and then undo the transform for hit information (normals) when the information is returned. For mesh vs. mesh collision, it might not be so easy. In that case you would probably have to transform the node AABBs of one BVH on the fly during traversal into the other BVH's local space.
6. ## std::shared_ptr to this pointer question

A few tips: Avoid using shared_ptr or unique_ptr in interfaces because they force the user to wrap their objects in smart pointers to use your interface. Smart pointers in interfaces have a tendency to spread to other parts of your code like a disease. shared_ptr obfuscates object ownership and result in poorly designed systems that don't consider object lifetimes in their design. shared_ptr also has some overhead for copying (e.g. when you pass it by value in your function). Use shared_ptr only when the object is actually shared between multiple systems and has unknown lifetime. This should be a small minority of the objects in your program. If not, you need a redesign. Use unique_ptr for internal allocations (but not in interfaces). Everywhere else, use references (if arguments cannot be null), or raw pointers (if arguments can be null). Prefer passing shared_ptr by const reference rather than by value. Every time you copy shared_ptr it flushes the memory pipeline due to its atomic reference count, which takes about 100 cycles.
7. ## Poor audio quality when playing sounds via XAudio2?

What is going on is that XAudio (and WASAPI shared mode) has built-in dynamic range limiting. It is applying a dynamic range limiter/compressor to your audio to avoid the distortion that comes with clipping float data to [-1,1], by reducing the gain of the signal in a level-dependent way. When the signal level approaches -1 or 1, the limiter must reduce the signal gain in anticipation of clipping (this is the compression knee) to produce a smoother gain reduction. This causes loud transients such as your explosion sound to be softened or to lose impact/attack.
8. ## Enemy Variants, Palette Swap in Photoshop for Pixel Art

Couldn't you just use an indexed color image and replace the colors in the color map (assuming 256 colors is ok)? Seems like a better way because you could keep your layers intact.
9. ## Performance testing with bit operations, SSE2 and asm

You realize that aligned malloc is usually just a wrapper around regular malloc that enforces the alignment? and that malloc is a kernel call that requires context switch, acquiring a lock, and various data structure manipulation? You're doing like 1000x the work in that one call than the rest of the function. You should never return memory like that from a function, it'd bad form and requires the caller to free it (and know to use aligned free).    Slightly better code below, but the whole idea of this function is flawed in the first place. typedef union Float4 { __m128 v; float x[4]; }; inline float _sse2_min(float a, float b) { __m128 _a = _mm_set_ps1(a); __m128 _b = _mm_set_ps1(b); Float4 c; c.v = _mm_min_ps(_a,_b); return c.x[0]; } Generally, SIMD code is only an advantage when you layout your data in a vector-friendly format (structures of arrays), then you can directly load/store_ps and operate on multiple values at once and get close to 4x speedup.
10. ## How about UNICODE and UTF-8

I used UTF-8 in my engine/GUI and it works great. I don't really find myself needing to have random-access to characters, and instead use an iterator class to iterate over the characters in a string (returning 32-bit characters).
11. ## more fixed-block audio...

Sounds pretty good, based on the bitrates you posted earlier. It would be interesting to hear a recording of something sonically detailed with more varied dynamic range like a voice, acoustic instrument, or live orchestra.
12. ## fixed block audio codec...

How does this compare in quality/compression to A-law and mu-law encodings?

14. ## Refactoring makes my brain hurt.

I know your pain, I'm 3/4 of the way through the front end of the compiler for my scripting language Mir (similar to C#) and things can get pretty unmanageable if you don't have a clear design in mind. My parser alone is over 3000 lines of code. What kind of syntax are you using for generics? The <> style has proven to be hell to parse correctly in expressions because in my case it makes the grammar context sensitive. I ended up having to defer expression parsing until the contextual analysis phase. The parser just determines the set of tokens that correspond to each place an expression should be and passes those on to the next phase. The contextual analyzer then checks each identifier as it parses to see if it is declared as a template and then if so parses the '<' as the start of a template instantiation, rather than a less-than expression.
15. ## Playing lego

check out this guy's work: [url="http://graphics.stanford.edu/~pmerrell/"]http://graphics.stanford.edu/~pmerrell/[/url]