Sign in to follow this  
mikeman

Specular Cube Maps

Recommended Posts

I've heard that Cube Maps can be used not only for environment mapping, but also to implement specular lighting in objects. How exactly this works? I've searched in google, but the resources I found say you use the reflection vector to index the cube map, but they don't explain how to build the cube map. Can anyone explain this technique or better give some links about this subject? This is about specular mapping ONLY, I'm not asking about environment mapping. Thanks in advance.

Share this post


Link to post
Share on other sites
I´m not sure, but i think you could paint your specular maps in photoshop, just like a gloss map. more white areas correspond to a higher amount of specularity, and dark areas are less specular.

Share this post


Link to post
Share on other sites
I think you can just build a cube map of the surrounding scene and then use the reflection vector of your view vector (i.e. a unit vector pointing from the eye point to the point your shadind) to lookup into the cubemap. You can then modulate this cube map value using a specular/gloss map. Another way to do it would be just to render the lights as blurred spheres into a cubemap.

Share this post


Link to post
Share on other sites
@Gammastrahler: What you're saying is gloss map, using a 2D texture to define the "shininess" of the surface. I'm not talking about that.

@Monder: Rendering the surrounding scene is used for environment mapping. Yes, rendering the lights as spheres is closer to what I'm looking for. I've already done that and it looks like specular lighting, I'm just not sure if this is the standard approach.

Does anyone else has more info about this?

Share this post


Link to post
Share on other sites
Well if you look at the HL2 shading paper here it appears they're doing they specular pretty much the same way as I said (look at pages 34-37 for images of how they build up the specular component and 52 for the shader code they actually use to calculate it). They only thing they do different is they also modulate the looked up cube-map value by a fresnel value.

Share this post


Link to post
Share on other sites
Ok thanks, actually I used that very same paper to implement diffuse lighting, but I missed the part where they talker about speculars. If I understand correctly, the level designers select some key points for the engine to build cubemaps(by rendering the lights as spheres or stars or something), and then at rendering time, the engine selects the most appropriate cubemap for every surface, correct?

Share this post


Link to post
Share on other sites
Yeah that's pretty much it, the cube maps are built by the engine at some point (by typing buildcubemaps into the console actually) and saved into the map file.

As for how they distribute the cube map sample points around the HL2 SDK docs basically say you need to put them distributed evenly over and near any surfaces that have specular reflection I think.

The cube maps themselves aren't just renderings of the lights but of the entire scene surrounding the sample point, note how they cube map sampler in the pixel shader is refered to as an environment map.

Share this post


Link to post
Share on other sites
Thanks for all the help. I would just need one more tiny thing clarified:

Quote:

The cube maps themselves aren't just renderings of the lights but of the entire scene surrounding the sample point, note how they cube map sampler in the pixel shader is refered to as an environment map.


If they rendered in the cubemaps only the scene geometry,as you do normally when you render from eye's POV, they would have only environment mapping, not speculars. Do they render both the scene and the lights as glowing spheres or something?

Share this post


Link to post
Share on other sites
Nope they render the scene normally (Well I'm pretty sure they do).

If you think about specular highlights are just reflections of the surrounding scene. The thing that stops all your specular stuff looking like mirrors is the fresnel part which alters how much is reflected depending on the angle between the surface normal and the indcident ray (i.e. the view vector).

Share this post


Link to post
Share on other sites
Well, if you had just a sphere and a point light, with no geometry around them, the sphere wouldn't have any reflections on it, but it would have specular highlights, so they're not exactly the same thing. Anyway, thanks for the help, I will play around with those ideas and see what I can do with them.

Share this post


Link to post
Share on other sites
Think of specular (atleast the Phong model) as a reflection of the lightsources. The lightsources are probably brighter then the rest of the scene so if the surface is not fully reflective you'll get the lightsource reflections showing up bright compared to the scene reflection. If the glossiness of the surface (specular exponent) is low you'll get glossy reflections, thats why the highlights are bigger. So basically: higher glossiness approaches mirror reflections, low glossiness approaches blurry reflections mainly dominated by the light reflections.
Anyway, the right way to do this would be to render your cube map in high dynamic range (16 bit floats or whatever) with the lights being correct brightness (probably greater then 1). Anyway, when you filter this result, the light reflections will stay bright and the scene will naturally have less effect at lower glossiness values. However, if you do this, might as well render the surfaces emitting the light with the higher brightness instead of the phong light reflections so you get correctly shaped speculars.
On a lot of hardware the above isn't necessarily practical but you can blur the scene in the reflection and render (N.L)^p*Cs directly into you cubemaps for discreet specular levels.
Hope this makes some sense.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this