代码在:
E:\ OGL \スクリプト可能なレンダリング・パイプライン-08-グローバル・イルミネーション\資産\マイパイプライン\ ShaderLibrary
float3 GlobalIllumination (VertexOutput input, LitSurface surface)
{
#if defined(LIGHTMAP_ON)
float3 gi = SampleLightmap(input.lightmapUV);
#if defined(DYNAMICLIGHTMAP_ON)
gi += SampleDynamicLightmap(input.dynamicLightmapUV);
#endif
return gi;
#elif defined(DYNAMICLIGHTMAP_ON)
return SampleDynamicLightmap(input.dynamicLightmapUV);
#else
return SampleLightProbes(surface);
#endif
}
三例:
1:あなたは、静的な照明、サンプリング静的照明を開いた場合。あなたオープンでダイナミックライティング場合は、ダイナミックな照明は、サンプリングし続けます。
2:唯一のオープン動的照明、動的ライティング。
3:開かなかった動き、デフォルトのサンプリングプローブ光。
静的ライティングをサンプリング:
float3 SampleLightmap (float2 uv)
{
return SampleSingleLightmap(
TEXTURE2D_PARAM(unity_Lightmap, samplerunity_Lightmap), uv,
float4(1, 1, 0, 0),
#if defined(UNITY_LIGHTMAP_FULL_HDR)
false,
#else
true,
#endif
float4(LIGHTMAP_HDR_MULTIPLIER, LIGHTMAP_HDR_EXPONENT, 0.0, 0.0)
);
}
ここでは関数呼び出しSampleSingleLightmap機能、中:
D:\プログラムファイル\ Unity2018.3.0f2 \ユニティ\エディタ\ \ ShaderLibrary \ EntityLighting.hlslのデータ\リソース\ PackageManager \エディタ\パッケージ変更
real3 SampleSingleLightmap(
TEXTURE2D_ARGS(lightmapTex, lightmapSampler),
float2 uv, float4 transform, bool encodedLightmap, real4 decodeInstructions)
{
// transform is scale and bias
uv = uv * transform.xy + transform.zw;
real3 illuminance = real3(0.0, 0.0, 0.0);
// Remark: baked lightmap is RGBM for now, dynamic lightmap is RGB9E5
if (encodedLightmap)
{
real4 encodedIlluminance = SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgba;
illuminance = DecodeLightmap(encodedIlluminance, decodeInstructions);
}
else
{
illuminance = SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgb;
}
return illuminance;
}
TEXTURE2D_PARAMとTEXTURE2D_ARGSマクロ定義:
#define TEXTURE2D_PARAM(textureName, samplerName) textureName, samplerName
#define TEXTURE2D_ARGS(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName)
ここでは4番目のパラメータが:UVがスケーリングおよびオフセットされて変換するfloat4。
// transform is scale and bias
uv = uv * transform.xy + transform.zw;
我々は(頂点シェーダ処理で)スケーリングされ、オフセットされた紫外線を渡すしようとして、それが変換に渡される(1,1,0,0)で、最初の二つは後に、紫外線をスケーリングしていますUVオフセットは2です。
#if defined(LIGHTMAP_ON)
output.lightmapUV = input.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
#endif
最初の5つのパラメータ:encodedLightmap
trueの場合:
if (encodedLightmap)
{
real4 encodedIlluminance = SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgba;
illuminance = DecodeLightmap(encodedIlluminance, decodeInstructions);
}
次のようにSAMPLE_TEXTURE2Dが定義されて:
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
リターンの#define real4 half4(モバイルプラットフォーム)またはREAL4のfloat4の#defineサンプリング
:次のようにDecodeLightmap機能を
//備考:今の焼きライトマップIS RGBM、ダイナミックIS RGB9E5ライトマップを
real3 DecodeLightmap(real4 encodedIlluminance, real4 decodeInstructions)
{
#if defined(UNITY_LIGHTMAP_RGBM_ENCODING)
return UnpackLightmapRGBM(encodedIlluminance, decodeInstructions);
#elif defined(UNITY_LIGHTMAP_DLDR_ENCODING) //双倍低动态double low dynamic range(色值乘二...)
return UnpackLightmapDoubleLDR(encodedIlluminance, decodeInstructions);
#else // (UNITY_LIGHTMAP_FULL_HDR)
return encodedIlluminance.rgb;
#endif
}
まず:UnpackLightmapRGBM
real3 UnpackLightmapRGBM(real4 rgbmInput, real4 decodeInstructions)
{
#ifdef UNITY_COLORSPACE_GAMMA
return rgbmInput.rgb * (rgbmInput.a * decodeInstructions.x);
#else
return rgbmInput.rgb * (PositivePow(rgbmInput.a, decodeInstructions.y) * decodeInstructions.x);
#endif
}
第二:UnpackLightmapDoubleLDR
real3 UnpackLightmapDoubleLDR(real4 encodedColor, real4 decodeInstructions)
{
return encodedColor.rgb * decodeInstructions.x;
}
LIGHTMAP_HDR_MULTIPLIERとLIGHTMAP_HDR_EXPONENT:2つのマクロを参照してください。
#define LIGHTMAP_RGBM_MAX_GAMMA real(5.0) // NB: Must match value in RGBMRanges.h
#define LIGHTMAP_RGBM_MAX_LINEAR real(34.493242) // LIGHTMAP_RGBM_MAX_GAMMA ^ 2.2
#ifdef UNITY_LIGHTMAP_RGBM_ENCODING
#ifdef UNITY_COLORSPACE_GAMMA
#define LIGHTMAP_HDR_MULTIPLIER LIGHTMAP_RGBM_MAX_GAMMA
#define LIGHTMAP_HDR_EXPONENT real(1.0) // Not used in gamma color space
#else
#define LIGHTMAP_HDR_MULTIPLIER LIGHTMAP_RGBM_MAX_LINEAR
#define LIGHTMAP_HDR_EXPONENT real(2.2)
#endif
#elif defined(UNITY_LIGHTMAP_DLDR_ENCODING)
#ifdef UNITY_COLORSPACE_GAMMA
#define LIGHTMAP_HDR_MULTIPLIER real(2.0)
#else
#define LIGHTMAP_HDR_MULTIPLIER real(4.59) // 2.0 ^ 2.2
#endif
#define LIGHTMAP_HDR_EXPONENT real(0.0)
#else // (UNITY_LIGHTMAP_FULL_HDR)
#define LIGHTMAP_HDR_MULTIPLIER real(1.0)
#define LIGHTMAP_HDR_EXPONENT real(1.0)
#endif
SampleDynamicLightmap
float3 SampleDynamicLightmap (float2 uv)
{
return SampleSingleLightmap(
TEXTURE2D_PARAM(unity_DynamicLightmap, samplerunity_DynamicLightmap), uv,
float4(1, 1, 0, 0), false,
float4(LIGHTMAP_HDR_MULTIPLIER, LIGHTMAP_HDR_EXPONENT, 0.0, 0.0)
);
}
SampleLightProbes
float3 SampleLightProbes (LitSurface s)
{
if (unity_ProbeVolumeParams.x)
{
return SampleProbeVolumeSH4(
TEXTURE3D_PARAM(unity_ProbeVolumeSH, samplerunity_ProbeVolumeSH),
s.position, s.normal, unity_ProbeVolumeWorldToObject,
unity_ProbeVolumeParams.y, unity_ProbeVolumeParams.z,
unity_ProbeVolumeMin, unity_ProbeVolumeSizeInv
);
}
else {
float4 coefficients[7];
coefficients[0] = unity_SHAr;
coefficients[1] = unity_SHAg;
coefficients[2] = unity_SHAb;
coefficients[3] = unity_SHBr;
coefficients[4] = unity_SHBg;
coefficients[5] = unity_SHBb;
coefficients[6] = unity_SHC;
return max(0.0, SampleSH9(coefficients, s.normal));
}
ここでは、追跡拒否、さようなら!!!