// It is required for other platform that aren't supporting this format to implement variant of these functions
// (But these kind of platform should use regular render loop and not news shaders).
// RGBM lightmaps are currently always gamma encoded, so we use a constant of range^2.2 = 5^2.2
#define LIGHTMAP_RGBM_RANGE 34.493242
// DLDR lightmaps are currently always gamma encoded, so we use a constant of 2.0^2.2 = 4.59
#define LIGHTMAP_DLDR_RANGE 4.59
// TODO: This is the max value allowed for emissive (bad name - but keep for now to retrieve it) (It is 8^2.2 (gamma) and 8 is the limit of punctual light slider...), comme from UnityCg.cginc. Fix it!
// Ask Jesper if this can be change for HDRenderPipeline
#define EMISSIVE_RGBM_SCALE 97.0
return rgbm;
}
real3 UnpackLightmapRGBM(real4 rgbmInput)
real3 UnpackLightmapRGBM(real4 rgbmInput, real4 decodeInstructions)
// RGBM lightmaps are always gamma encoded for now, so decode with that in mind:
return rgbmInput.rgb * pow(rgbmInput.a, 2.2) * LIGHTMAP_RGBM_RANGE;
return rgbmInput.rgb * pow(rgbmInput.a, decodeInstructions.y) * decodeInstructions.x;
real3 UnpackLightmapDoubleLDR(real4 encodedColor)
real3 UnpackLightmapDoubleLDR(real4 encodedColor, real4 decodeInstructions)
return encodedColor.rgb * LIGHTMAP_DLDR_RANGE;
return encodedColor.rgb * decodeInstructions.x;
real3 DecodeLightmap(real4 encodedIlluminance)
real3 DecodeLightmap(real4 encodedIlluminance, real4 decodeInstructions)
return UnpackLightmapRGBM(encodedIlluminance);
return UnpackLightmapRGBM(encodedIlluminance, decodeInstructions);
return UnpackLightmapDoubleLDR(encodedIlluminance);
return UnpackLightmapDoubleLDR(encodedIlluminance, decodeInstructions);
#endif
}
return (decodeInstructions.x * pow(alpha, decodeInstructions.y)) * encodedIrradiance.rgb;
}
real3 SampleSingleLightmap(TEXTURE2D_ARGS(lightmapTex, lightmapSampler), float2 uv, float4 transform, bool encodedLightmap)
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;
{
real4 encodedIlluminance = SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgba;
illuminance = DecodeLightmap(encodedIlluminance);
illuminance = DecodeLightmap(encodedIlluminance, decodeInstructions );
}
else
{
}
real3 SampleDirectionalLightmap(TEXTURE2D_ARGS(lightmapTex, lightmapSampler), TEXTURE2D_ARGS(lightmapDirTex, lightmapDirSampler), float2 uv, float4 transform, float3 normalWS, bool encodedLightmap)
real3 SampleDirectionalLightmap(TEXTURE2D_ARGS(lightmapTex, lightmapSampler), TEXTURE2D_ARGS(lightmapDirTex, lightmapDirSampler), float2 uv, float4 transform, float3 normalWS, bool encodedLightmap, real4 decodeInstructions )
{
// In directional mode Enlighten bakes dominant light direction
// in a way, that using it for half Lambert and then dividing by a "rebalancing coefficient"
if (encodedLightmap)
{
real4 encodedIlluminance = SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgba;
illuminance = DecodeLightmap(encodedIlluminance);
illuminance = DecodeLightmap(encodedIlluminance, decodeInstructions );
}
else
{