Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 25 Mar 2007
Offline Last Active Yesterday, 02:48 PM

Topics I've Started

Specular Highlights Disappear Up Close

16 March 2014 - 09:00 PM

I've noticed that in my engine the specular highlights for shiny objects go away for objects that are closer to the camera. Interestingly, increasing the scale factor for the objects allows the camera to get much closer before the highlights disappear. Therefore, I don't think this is an inherent property of the geometry of specular lighting.


I am using a normalized Blinn-Phong lighting model and this issue exists for both point and directional light sources. I've checked my shader against examples online and it seems to match them. In addition, the same behavior was observed with the Phong lighting model.


I've attached two screenshots showing a series of 4 shiny objects. In the first, the highlight is most prominent on the distant object and least prominent for the closest. In the second, the scene was scaled by 5x, and the highlights are similar for all objects.


Has anyone else noticed this artifact? My only guess is that there is some problem with how I am computing the normal matrix (transpose of the inverse of the upper 3x3 of model view matrix) or view-space light direction (model view matrix * world space direction), but there doesn't seem to be any negative effect on the normals themselves or the diffuse lighting.


Edit: I was just playing around with it again and found that if I calculate the view-space half vector once for the entire view, rather than per-pixel, the highlights behave the way they should.

How to enumerate the installed font paths on a system?

29 January 2013 - 03:40 PM

I'm looking to see if there is a better solution to this problem than my current implementation. Currently, I search certain predefined system paths for font files ("C:\Windows\Fonts\" on Windows and "/System/Library/Fonts/", "/Library/Fonts/" on OS X), then open each file with Freetype to determine the font's family and face names, then cache this information, along with the file's path, for later use. The problem is that this is really slow (a couple of seconds).


I've looked at the available functionality on OS X and Windows and the only font management tools allow you to list the installed font names but don't allow you to get the path on the system where the font file is stored. Therefore, there's no way for me to use a library like Freetype to open the file.


Am I missing something or is there no better way to do this?

Problems with SetParent() and window frames

07 September 2012 - 10:56 PM

I'm trying to implement a cross-platform wrapper for basic window management and OpenGL rendering. I've gotten the OS X version working well. To create an OpenGL rendering view I create an NSOpenGLView (on mac) or an HWND with the WS_CHILD style, then attach the view to a normal window, allowing the user to position the view anywhere in the window.

However, there is something weird that happens whenever I call SetParent() to make the GL view a child window of a normal window - the GL view is resized so that it fits inside in the parent window, but the strange thing is that it is reduced in size by the same amount as if it had a title bar/frame. The result is that there is now a border around the GL view between it and the parent window. This happens even if the client rectangle of the GL view and the normal window should be the same size. (I've attached an image of the behavior).

I should note that it does work as expected unless I call SetWindowPos() to update the frame. SetWindowPos() shouldn't move or size the window if I specify the flags SWP_NOMOVE and SWP_NOSIZE, but it does anyway.

As far as I'm aware, a window with the WS_CHILD style shouldn't have any title bar or frame but it seems like somewhere the windows API treats them as such.

I've spent several hours trying to find a workaround to this apparent problem. Does anyone have any idea what I could be doing wrong, or is there no way I can do what I'm trying to do?

Here is a rundown of the API calls I'm making that cause the problem:
  • CreateWindowEx() for the GL view with the WS_POPUP style. I use that style because I can't seem to create a window with the WS_CHILD style without specifying a parent window at creation. This also allows me to switch the GL view to fullscreen when running in non-windowed mode. I use a size of 800x600 for the window.
  • Change the style of the window from WS_POPUP to WS_CHILD using SetWindowLongPtr() in order to prepare it to be a child of another window.
  • Call SetParent() to make the GL view a child of the normal window.
  • If I call SetWindowPos() at any point after making the GL view a child, it resizes the GL view's client rectangle as described above. The resulting client area rectangle is 780x560, even though the window was created with a client size of 800x600. This makes the invisible frame of the GL view fit within the original 800x600 size.

Equal-area partition of unit sphere

16 February 2012 - 11:40 PM

I'm working on an application that needs to compute a histogram over the surface of a sphere. In order to do this I have to partition the surface of the sphere into pieces that are equal area (or fairly close). The shape of a piece does not matter as long as it covers the same area. I also need to be able to parameterize the partitioning scheme so that I can iterate over the pieces in an efficient manner without having to store their bounds.

I've tried looking into equal area cylindrical projections but I can't seem to get anything to work correctly. Polar distortion is not a problem, so any sort of cylindrical projection could work. I just need to parameterize the latitude generation it so that the area of each rectangular/triangular piece is more or less equal.

Does anyone have a tips for solving this issue?

P.S. the end goal is to use each piece of the sphere to generate a certain number of rays (depending on the histogram) that start at the sphere's center and pass through the bounds of that piece.

Template function won't inline

25 January 2012 - 09:59 PM

I'm writing a wrapper for various SSE and Altivec intrinsics and I've run into a problem when dealing with _mm_shuffle_ps(). This intrinsic requires an immediate argument to determine which elements from each vector are chosen.

Since this value is needed at compile time, I decided to use a template function:

template < int i1, int i2, int i3, int i4 >

FORCE_INLINE SIMDFloat4 shuffle( const SIMDFloat4& a, const SIMDFloat4& b )


	return SIMDFloat4( _mm_shuffle_ps( a, b, _MM_SHUFFLE( i4, i3, i2, i1 ) ) );


This compiles and works just fine, but when I examine assembly code produced by using this function, it doesn't get inlined. This is obviously unacceptable for SSE code whose whole purpose is to be as fast as possible, especially considering that this method should reduce to only 1 or 2 instructions at most.

Does anyone have an idea why GCC would not inline this method, even though I've specified for it to always be inlined using compiler attributes? I don't want to have to use any macros if I don't have to...