Image Based Lighting Shader (W.I.P)

Here is a little demostration of image based lighting using spherical harmonics. Still a work in progress, I want to add normal mapping reflection and diffuse textures.

I made some tests with Cycles, and it works, the process is to render a spherical probe from your scene with the .hdr file format, and then convert it to a .float binary file to get the nine coefficients. I’ll be posting here for more updates.

Great work! My only crit is the floppy monkey chin…its disturbing…

I look forward to more updates though- whats the performance like?

Lol I needed to animate the chin just for testing the reaction of light. About performance, it’s really fast, I’m getting around 250 fps on my low end graphics APU, but this is a very simple scene, I’ll try with more complex scenes and see what happens :slight_smile:

Wow, this is very interesting, can you share the blend? Looking forward to see more.

Damn that looks nice! Hope you’ll teach us.

Sure, the code is a mess, just let me clean it a bit, I’ll let you know when it’s ready.

Damn that looks nice! Hope you’ll teach us.

I’ll make a video tutorial when the shader is ready.

Whoah. Simply, whoah. Nicely done. Looks amazing… :smiley: Have you devised a fashion for the “softness” of the lighting, so to speak? That is, is it entirely diffuse, or can it also apply to specular, like a reflection? Great work, keep it up :smiley:

Could you also add reflections? Like a cubemap?

Really nice work btw, I really would love to see a blend file to try it out!

Thanks, only diffuse, for reflection you can use @martinsh BPCEM.

Really nice work btw, I really would love to see a blend file to try it out!

Here it is.






arrow keys


right control

Wow, fantastic, looks great in here and it’s very fast. You’re talking about BPCEM for having specular, are you planning to add this later on as well?

The plan is to make some tools that helps with the creation of light probes, something similar to this, and yes I want to add BPCEM, the problem will be how to interpolate between the cube maps.

Are you going for suzan in the uncanny valley?

Aryok, maybe you can use a mix shader in the node editor to mix two textures (one for IBL and the other one for BPCEM), what do you think?

  1. What are these numbers?
env1 = [2.536422,  1.406041,  1.743469,
        -1.265607, -1.123857, -1.947913,
        -1.084632, -0.580021, -0.858045,
        -0.936035, -0.178947,  0.027348,
        0.359807,  0.167744,  0.400448,
        0.835642,  0.715156,  1.518228,
        -0.508326, -0.311408, -0.488502,
        1.789974,  0.685822,  0.446169,
        0.672039, -0.179130, -0.983263]

env2 = [1.494715,  1.574811,  1.702009,
        -0.650680, -0.722931, -0.754662,
        0.985967,  1.405565,  1.815914 ,
        -0.112789, -0.088309, -0.047345,
        0.234152,  0.180893,  0.119504,
        -0.567614, -0.897261, -1.217889,
        0.900519,  1.282249,  1.689197,
        0.135465,  0.014728, -0.055600,
        -0.068430, -0.045017, -0.063645]
env3 = [2.032522,  2.290237,  2.422462,
        -1.546187, -1.921798, -2.222124,
        0.211852,  0.168763,  0.064793,
        -0.554543, -0.553630, -0.474834,
        0.327567,  0.290870,  0.206602,
        -0.044700,  0.074438,  0.245067,
        -0.502353, -0.674828, -0.822717,
        -0.310154, -0.272000, -0.196962,
        0.116800, -0.015722, -0.235180]
env4 = [2.068953,  1.499935,  1.329903,
        -1.005251, -0.820573, -0.718976,
        -0.138936, -0.056155, -0.004892,
        0.198255,  0.127739,  0.058105,
        -0.112801, -0.082052, -0.025224,
        0.266107,  0.144318,  0.066899,
        -0.514250, -0.434565, -0.422284,
        0.028605,  0.022023,  0.000436,
        -0.468779, -0.183947,  0.019275]
  1. Would it be possible to do the same thing with a cubemap? And maybe add the box projection mathematics from the BPCEM shader?
  1. Those numbers represents the nine coefficients of the 3 band order of the spherical harmonics, look at them as nine vector3f, and they are required to compute the diffuse lighting in the vertex shader.

  2. As you can see the diffuse lighting is not generated from a bit map directly, the background environments are not contributing with the lighting they are just simple jpg’s, if you try to change them you’ll see that the lighting remain the same. That’s the difference between a cubemap(bitmap) and a computed equation.

I’m sorry if you still don’t get it, it’s very hard to explain. In the future I’ll make some tutorials on how to extract the nine coeffs from any hdr file you have, and even using cycles for your own 3d scenes, it will take some time so please be patient :).

Definitely interpolation of values is possible, I’ll consider that.

Sorry for bumping old thread. I’m interested in learning Spherical Harmonics.
I’m still confused how do you get coefficients of those jpg images?
Can it calculated in realtime?

Ucupumar, they’re like a cubemap of 3*3 resolution per face.
Edit: I mixed up between sh lighting and another IBL method.
You can use something like HDRishop to extract the coefficients.

ucupumar, as Jackii said, though I’m not sure if the new versions of HDRShop can extract the nine coefficients, I’ll paste a previous answer to that same question.

My workflow is to render a panoramic equirectangular image out of cycles(.hdr), then using the free version of HDRShop to convert the image to a Light Probe(Angular Map) in .float format and nine coeff extraction using prefilter.c

I hope that helps.

Thanks for the replies.
After looking around prefilter.c, it looks like too slow to be calculated in realtime. Is there any way to do this kind of process in realtime?

Other question, why you use angular map rather than just cubemap?