#ifndef __REFLECTIONTEMPLATE_H__ #define __REFLECTIONTEMPLATE_H__ #include "UnityCG.cginc" #include "UnityStandardBRDF.cginc" #include "UnityStandardUtils.cginc" #include "UnityPBSLighting.cginc" UNITY_DECLARE_ABSTRACT_CUBE_ARRAY(_reflCubeTextures); UNITY_DECLARE_TEXCUBE(_reflRootCubeTexture); //uniform int _reflRootSliceIndex; uniform float _reflRootHdrDecodeMult; uniform float _reflRootHdrDecodeExp; half3 Unity_GlossyEnvironment (UNITY_ARGS_ABSTRACT_CUBE_ARRAY(tex), int sliceIndex, half4 hdr, Unity_GlossyEnvironmentData glossIn); half3 distanceFromAABB(half3 p, half3 aabbMin, half3 aabbMax) { return max(max(p - aabbMax, aabbMin - p), half3(0.0, 0.0, 0.0)); } float3 ExecuteReflectionList(uint start, uint numReflProbes, float3 vP, float3 vNw, float3 Vworld, float smoothness) { float3 worldNormalRefl = reflect(-Vworld, vNw); float3 vspaceRefl = mul((float3x3) g_mWorldToView, worldNormalRefl).xyz; float percRoughness = SmoothnessToPerceptualRoughness(smoothness); UnityLight light; light.color = 0; light.dir = 0; float3 ints = 0; // root ibl begin { Unity_GlossyEnvironmentData g; g.roughness = percRoughness; g.reflUVW = worldNormalRefl; half3 env0 = Unity_GlossyEnvironment(UNITY_PASS_TEXCUBE(_reflRootCubeTexture), float4(_reflRootHdrDecodeMult, _reflRootHdrDecodeExp, 0.0, 0.0), g); //half3 env0 = Unity_GlossyEnvironment(UNITY_PASS_TEXCUBEARRAY(_reflCubeTextures), _reflRootSliceIndex, float4(_reflRootHdrDecodeMult, _reflRootHdrDecodeExp, 0.0, 0.0), g); UnityIndirect ind; ind.diffuse = 0; ind.specular = env0;// * data.occlusion; ints = EvalIndirectSpecular(light, ind); } // root ibl end uint l=0; // don't need the outer loop since the probes are sorted by volume type (currently one type in fact) //while(l0) { uint uIndex = l= 30) // TODO: remove pow, store cubemap mips differently half perceptualRoughness = pow(glossIn.roughness, 3.0/4.0); #else half perceptualRoughness = glossIn.roughness; // MM: switched to this #endif //perceptualRoughness = sqrt(sqrt(2/(64.0+2))); // spec power to the square root of real roughness #if 0 float m = perceptualRoughness*perceptualRoughness; // m is the real roughness parameter const float fEps = 1.192092896e-07F; // smallest such that 1.0+FLT_EPSILON != 1.0 (+1e-4h is NOT good here. is visibly very wrong) float n = (2.0/max(fEps, m*m))-2.0; // remap to spec power. See eq. 21 in --> https://dl.dropboxusercontent.com/u/55891920/papers/mm_brdf.pdf n /= 4; // remap from n_dot_h formulatino to n_dot_r. See section "Pre-convolved Cube Maps vs Path Tracers" --> https://s3.amazonaws.com/docs.knaldtech.com/knald/1.0.0/lys_power_drops.html perceptualRoughness = pow( 2/(n+2), 0.25); // remap back to square root of real roughness #else // MM: came up with a surprisingly close approximation to what the #if 0'ed out code above does. perceptualRoughness = perceptualRoughness*(1.7 - 0.7*perceptualRoughness); #endif half mip = perceptualRoughness * UNITY_SPECCUBE_LOD_STEPS; half4 rgbm = UNITY_SAMPLE_ABSTRACT_CUBE_ARRAY_LOD(tex, float4(glossIn.reflUVW.xyz, sliceIndex), mip); return DecodeHDR(rgbm, hdr); } #endif