Has anyone here had success in accessing Unity 5 reflection probe textures for use in custom shaders? I had started implementing my own custom reflection probe system, however when it comes to blending between probes, and the box projection calculation I sort of derped out. Would love to be able to just access from the Unity probes... ...or is the blending and box projection handled on the receiving shader?
Either way I would be happy to hear thoughts on accessing this information, even if it is applied as a post process.
Create a shader from the editor and see the generated code, all functions are inside the built-in shaders and you can backtrack. I'm trying myself and it's pretty damn difficult because the code goes back and forth into functions from different files. I've managed to render something from the dynamic lightmaps that reacts to the skybox but it's all garbage data because i'm still missing some vital information that is calculated before that i'm still backtracking. I'm now considering stripping down the generated code instead of creating one from scratch and introduce the necessary code like I am doing now. Look into UnityGlobalIllumination function inside the file UnityGlobalIllumination.cginc I know it doesn't help much but I wanted to at least inform you that it's possible, it's just a lot of heavy lifting from convoluted code that some else wrote
I think you can find the relevant data in the following files. In UnityShaderVariables.cginc: Code (shader): float4 unity_SpecCube0_BoxMax; float4 unity_SpecCube0_BoxMin; float4 unity_SpecCube0_ProbePosition; half4 unity_SpecCube0_HDR; float4 unity_SpecCube1_BoxMax; float4 unity_SpecCube1_BoxMin; float4 unity_SpecCube1_ProbePosition; half4 unity_SpecCube1_HDR; I believe this is the raw reflection probe data passed by Unity to shaders. and then in UnityGlobalIllumination.cginc, look at the snippet starting at line 157 (in Unity5.0.0f4), which is contained in the following block: Code (shader): if (reflections) { ... } This is where the magic happens! Note: you can download the built-in shaders here.
So, can anyone post the actual shader code for this? I tried doing this, but with absolutely no positive result - i only get pure blackness.
I think you can access the cubemap using unity_SpecCube0. The following line worked for me: Code (CSharp): fixed3 reflectionCol = reflColor * UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, reflectDir).rgb;