Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Simplified global illumination using cubemap?

Discussion in 'Shaders' started by Nemox, May 26, 2014.

  1. Nemox

    Nemox

    Joined:
    Feb 16, 2010
    Posts:
    396
    I'm a bit new to shaders but I generally understand how they work, and I'm now trying to understand the theory behind illumination.

    I'd like to create a really simple shader that mimics global illumination to mess around with until Unity 5 comes out. I figured since ambient lighting on a character/object is merely the light that is reflected off surroundings and then off the character/object, it's essentially a really weak reflection, and therefore a cubemap might suffice.

    In my logic, I've tried using a reflection map but this results in a mirror-like surface for the character. With a plain white reflection this looks exactly how I want. But with any actual reflection cubemaps it looks far too detailed for the actual lighting. It looks like what I'd expect the high-specular parts of the character to look like. I figure the sheer detail is a major part of it.

    Am I on the right track in my thinking? If so, is there some way to get a blurred, approximated value for the reflection?
     
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    You're on the right track. The specific type of blurring required to use a cube or sphere map for diffuse lighting is a hemispherical convolution. Marmoset Skyshop will do this for you.
     
  3. Nemox

    Nemox

    Joined:
    Feb 16, 2010
    Posts:
    396
    Oh, I remember seeing Marmoset before! Looks absolutely beautiful, but unfortunately out of my price range for a while. I'll keep experimenting a bit and see what I come up with. I've just tried giving my shader a second cubemap for this image-based lighting.

    I'd like to have two separate outputs for this; one half3 for diffuse and another for specularity, but if I try to add more to the output it always gives me a "too many interpolators" error. @_@

    UPDATE: I was able to create a custom input with two extra half3 values. One for reflection, one for ambient light. I had to use target 3.0 and target glsl to add them. To make the ambient light cubemap texture I merely copied the reflection texture, blurred it like crazy, and saved it as a much smaller resolution just to be more efficient.

    I had previously tried using Emission but it didn't work out well. Instead I directly applied the ambient lighting cubemap inside the custom lighting function. It's not perfect, but it's pretty enough to use until Unity 5 comes out.
     
    Last edited: May 27, 2014
  4. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,782
    Try Lux http://forum.unity3d.com/threads/235027-Lux-an-open-source-physically-based-shading-framework
     
    Last edited: May 27, 2014