代码改变世界

ue4 lightmap的解码

2021-02-23 17:25  kk20161206  阅读(199)  评论(0编辑  收藏  举报

一. lq的解码过程     lightmapCommon.ush   GetLightMapColorLQ()函数:

1. 纹理采样:

 

 2. 亮度、颜色还原

 

 3. 还原亮度

 

 4. 还原最大贡献方向

 

 5. 最终颜色还原

 

 二、 hq解码过程  lightmapCommon.ush   GetLightMapColorHQ()函数

1. 纹理采样:分为有vt和没有vt:

 

 2. 亮度还原

 

 3. 颜色还原

 

 4. 还原方向,是否定义方向,是否是双向植被:

 

 5. 最终颜色:

 

 三、 skyOcclusion和aomaterialMask的解码

float4 GetSkyBentNormalAndOcclusion(VTPageTableResult LightmapVTPageTableResult, float2 LightmapUV, uint LightmapDataIndex, float2 SvPositionXY)
{
	float4 TextureValue;
#if LIGHTMAP_VT_ENABLED
	TextureValue = SampleLightmapVT( LightmapVTPageTableResult, 3u, LightmapDataIndex, LightmapResourceCluster.VTSkyOcclusionTexture, LIGHTMAP_SHARED_SAMPLER(SkyOcclusionSampler)); 
#else
	TextureValue = Texture2DSample( LightmapResourceCluster.SkyOcclusionTexture, LIGHTMAP_SHARED_SAMPLER(SkyOcclusionSampler), LightmapUV );
#endif

	// Unpack vector
	TextureValue.rgb = TextureValue.rgb * 2 - 1;
	// Undo sqrt which allocated more precision toward 0
	TextureValue.a = TextureValue.a * TextureValue.a;
	return TextureValue;
}

float GetAOMaterialMask(VTPageTableResult LightmapVTPageTableResult, float2 LightmapUV, uint LightmapDataIndex, float2 SvPositionXY)
{
	float TextureValue;
#if LIGHTMAP_VT_ENABLED
	TextureValue = SampleLightmapVT( LightmapVTPageTableResult, 4u, LightmapDataIndex, LightmapResourceCluster.VTAOMaterialMaskTexture, LIGHTMAP_SHARED_SAMPLER(AOMaterialMaskSampler)).x; 
#else
	TextureValue = Texture2DSample( LightmapResourceCluster.AOMaterialMaskTexture, LIGHTMAP_SHARED_SAMPLER(AOMaterialMaskSampler), LightmapUV ).x;
#endif

	// Undo sqrt which allocated more precision toward 0
	return TextureValue * TextureValue;
}

  

四、 ue4 lightmap编码特点的思考:

1. 好处:

 

 2. 不足: