Here’s another trick based on one of Valve’s GDC talks: Ambient Cubemaps. Basically, a cubemap is used to approximate the ambient light of the scene. It is similar to Spherical Harmonics in that it provides low frequency light information but doesn’t require all the scary math.Valve’s Implementation looks quite nice, but requires 3 texture samples as far as i can tell, so i tried to emulate the visual effect while only taking a single sample at a low mip level and adjusting it in the shader. It comes quite close, although Valve’s implementation’s colors are a bit richer. A good improvement would be to bake out a low res cubemap based on Valve’s implementation and then save that into the lowest mip level of the cubemap where you could access it directly, but that’s a little beyond the scope of this demo.Valve’s implementation is enabled by default, but you can re enable my single pass attempt in the shader.

Maya CGFX File:

phongnormalambientcube.cgfx
File Size: 8 kb
File Type: cgfx

Download File


Unity SHADER File:

phongnormalambientcube.shader
File Size: 11 kb
File Type: shader

Download File


2 Responses

  1. ()3/24/2015 06:33:59 pm
    Hey Gabe,
    Do you have same shader without normal map but with dedicated specular/gloss map

    I am trying to find performant mobile shader with ambient and reflection cubemaps.
    And if it has specular/reflection map that’s ideal

    This shader of yours looks quite good, thanks for sharing.
    Too bad doesn’t fit to what I need

    1. This could be done by removing the Normal Map in the pixel shader, and just using “IN.normalDir” from your vert2Pixel struct in place of “normalDir” everywhere it is needed. You could also save a bit by not passing binormal and tangents from the vertex shader – without a normal map you wont need them.

      As far as the spec/gloss map, you could just pack that into your diffuse alpha. So instead of pulling that out of the normal and saving it to the “specMap” variable, you would just use “texSample.a”

      Does that make sense?

      Delete

Leave a Reply

Your email address will not be published. Required fields are marked *