浏览代码

HDRenderPipeline: Add support for BC5 normal map

/Branch_batcher
sebastienlagarde 8 年前
当前提交
b8ffdc68
共有 5 个文件被更改,包括 14 次插入20 次删除
  1. 1
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  2. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
  3. 8
      Assets/ScriptableRenderPipeline/ShaderLibrary/NormalSurfaceGradient.hlsl
  4. 9
      Assets/ScriptableRenderPipeline/ShaderLibrary/Packing.hlsl
  5. 14
      Assets/ScriptableRenderPipeline/ShaderLibrary/SampleUVMappingInternal.hlsl

1
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs


public static GUIContent maskMapSText = new GUIContent("Mask Map - M(R), AO(G), S(A)", "Mask map");
public static GUIContent normalMapSpaceText = new GUIContent("Normal/Tangent Map space", "");
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map (DXT5) - Need to implement BC5");
public static GUIContent specularOcclusionMapText = new GUIContent("Specular Occlusion Map (RGBA)", "Specular Occlusion Map");
public static GUIContent horizonFadeText = new GUIContent("Horizon Fade (Spec occlusion)", "horizon fade is use to control specular occlusion");

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl


#endif
surfaceData.normalWS = float3(0.0, 0.0, 0.0); // Need to init this to keep quiet the compiler, but this is overriden later (0, 0, 0) so if we forget to override the compiler may comply.
// TODO: think about using BC5
normalTS = ADD_IDX(GetNormalTS)(input, layerTexCoord, detailNormalTS, detailMask, false, 0.0);
#if defined(_MASKMAP_IDX)

surfaceData.materialId = (_EnableSSS || _MaterialID != MATERIALID_LIT_SSS) ? _MaterialID : MATERIALID_LIT_STANDARD;
// TODO: think about using BC5
#ifdef _TANGENTMAP
#ifdef _NORMALMAP_TANGENT_SPACE_IDX // Normal and tangent use same space
float3 tangentTS = SAMPLE_UVMAPPING_NORMALMAP(_TangentMap, sampler_TangentMap, layerTexCoord.base, 1.0);

8
Assets/ScriptableRenderPipeline/ShaderLibrary/NormalSurfaceGradient.hlsl


return deriv * scale;
}
// Unpack normal as DXT5nm (1, y, 0, x) or BC5 (x, y, 0, 1)
float2 UnpackDerivativeNormalRGorAG(float4 packedNormal, float scale = 1.0)
{
// This do the trick
packedNormal.w *= packedNormal.x;
return UnpackDerivativeNormalAG(packedNormal, scale);
}
float2 UnpackDerivativeNormalRGB(float4 packedNormal, float scale = 1.0)
{
const float fS = 1.0 / (128.0 * 128.0);

9
Assets/ScriptableRenderPipeline/ShaderLibrary/Packing.hlsl


float3 UnpackNormalmapRGorAG(float4 packedNormal, float scale = 1.0)
{
// This do the trick
packedNormal.x *= packedNormal.w;
float3 normal;
normal.xy = packedNormal.xy * 2.0 - 1.0;
normal.xy *= scale;
normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));
return normal;
packedNormal.w *= packedNormal.x;
return UnpackNormalAG(packedNormal, scale);
}
//-----------------------------------------------------------------------------

14
Assets/ScriptableRenderPipeline/ShaderLibrary/SampleUVMappingInternal.hlsl


// Nested multiple includes of the file to handle all variations of normal map (AG, RG or RGB)
// TODO: Handle BC5 format, currently this code is for DXT5nm - After the change, rename this function UnpackNormalmapRGorAG
// This version is use for the base normal map
// This version is use for the base normal map (BC5 or DXT5nm)
#define UNPACK_NORMAL_FUNC UnpackNormalAG
#define UNPACK_DERIVATIVE_FUNC UnpackDerivativeNormalAG
#define UNPACK_NORMAL_FUNC UnpackNormalmapRGorAG
#define UNPACK_DERIVATIVE_FUNC UnpackDerivativeNormalRGorAG
#endif
#include "SampleUVMappingNormalInternal.hlsl"
#undef ADD_NORMAL_FUNC_SUFFIX

// This version is for normalmap with AG encoding only. Mainly use with details map.
// This version is for normalmap with AG encoding only. Use with details map encoded with others properties (like smoothness).
#if defined(UNITY_NO_DXT5nm)
#define UNPACK_NORMAL_FUNC UnpackNormalRGB
#define UNPACK_DERIVATIVE_FUNC UnpackDerivativeNormalRGB
#else
#endif
#include "SampleUVMappingNormalInternal.hlsl"
#undef ADD_NORMAL_FUNC_SUFFIX
#undef UNPACK_NORMAL_FUNC

正在加载...
取消
保存