浏览代码

Move PackHeightmap/UnpackHeightmap to Common.hlsl.

/main
Yao Xiao Ling 6 年前
当前提交
5b4c4f1c
共有 3 个文件被更改,包括 31 次插入12 次删除
  1. 31
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Common.hlsl
  2. 6
      com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLitDataMeshModification.hlsl
  3. 6
      com.unity.render-pipelines.lightweight/LWRP/ShaderLibrary/Terrain/LightweightPassLitTerrain.hlsl

31
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Common.hlsl


}
// ----------------------------------------------------------------------------
// Terrain/Brush heightmap encoding/decoding
// ----------------------------------------------------------------------------
#if defined(SHADER_API_VULKAN) || defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)
float4 PackHeightmap(float height)
{
uint a = (uint)(65535.0f * height);
return float4((a >> 0) & 0xFF, (a >> 8) & 0xFF, 0, 0) / 255.0f;
}
float UnpackHeightmap(float4 height)
{
return (height.r + height.g * 256.0f) / 257.0f; // (255.0f * height.r + 255.0f * 256.0f * height.g) / 65535.0f
}
#else
float4 PackHeightmap(float height)
{
return float4(height, 0, 0, 0);
}
float UnpackHeightmap(float4 height)
{
return height.r;
}
#endif
// ----------------------------------------------------------------------------
// Misc utilities
// ----------------------------------------------------------------------------

6
com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLitDataMeshModification.hlsl


float UnpackHeightmap(float4 height)
{
// 16-bit height value is packed into two 8-bit channels.
return (height.r + height.g * 256.0f) / 257.0f; // (255.0f * height.r + 255.0f * 256.0f * height.g) / 65535.0f
}
UNITY_INSTANCING_BUFFER_START(Terrain)
UNITY_DEFINE_INSTANCED_PROP(float4, _TerrainPatchInstanceData) // float4(xBase, yBase, skipScale, ~)
UNITY_INSTANCING_BUFFER_END(Terrain)

6
com.unity.render-pipelines.lightweight/LWRP/ShaderLibrary/Terrain/LightweightPassLitTerrain.hlsl


float4 _TerrainHeightmapScale; // float4(hmScale.x, hmScale.y / (float)(kMaxHeight), hmScale.z, 0.0f)
#endif
float UnpackHeightmap(float4 height)
{
// 16-bit height value is packed into two 8-bit channels.
return (height.r + height.g * 256.0f) / 257.0f; // (255.0f * height.r + 255.0f * 256.0f * height.g) / 65535.0f
}
UNITY_INSTANCING_BUFFER_START(Terrain)
UNITY_DEFINE_INSTANCED_PROP(float4, _TerrainPatchInstanceData) // float4(xBase, yBase, skipScale, ~)
UNITY_INSTANCING_BUFFER_END(Terrain)

正在加载...
取消
保存