浏览代码
HDRenderPipeline: Change LayerUV to UVMapping + add keyword MAPPING_PLANAR
HDRenderPipeline: Change LayerUV to UVMapping + add keyword MAPPING_PLANAR
- added _LAYER_MAPPING_PLANAR0 keyword - Planar mapping is now a shader feature - Move all SampleLayer to to ShaderLibrary and rename LayerUV to UVMapping - Create an enum UVMappingType instead of using isPlanar / is Triplanar - Move double/mirror sided function to materialUtilities - Update a lot of materials in test scene/Branch_Batching2
Sebastien Lagarde
8 年前
当前提交
0365d4e5
共有 49 个文件被更改,包括 707 次插入 和 504 次删除
-
16Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs
-
18Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
-
18Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
-
9Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
-
4Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
-
247Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
-
79Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
-
3Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitProperties.hlsl
-
3Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader
-
32Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/MaterialUtilities.hlsl
-
4Assets/ScriptableRenderPipeline/ShaderLibrary/NormalSurfaceGradient.hlsl
-
13Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_BlendColor.mat
-
13Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_BlendMask.mat
-
16Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_HeightBased.mat
-
11Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer0_Planar.mat
-
9Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer0_Triplanar.mat
-
8Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer0_UV0.mat
-
10Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer1_Planar.mat
-
8Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer1_Triplanar.mat
-
10Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer1_UV0.mat
-
10Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer1_UV1.mat
-
10Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer1_UV2.mat
-
10Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer1_UV3.mat
-
10Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer2_Planar.mat
-
9Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer2_Triplanar.mat
-
11Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer2_UV0.mat
-
11Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer2_UV1.mat
-
12Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer2_UV2.mat
-
12Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer2_UV3.mat
-
10Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer3_Planar.mat
-
9Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer3_Triplanar.mat
-
8Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer3_UV0.mat
-
8Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer3_UV1.mat
-
10Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer3_UV2.mat
-
10Assets/TestScenes/HDTest/LayeredLitTest/Material/Layered_Layer3_UV3.mat
-
38Assets/TestScenes/HDTest/LayeredLitTest/Material/Lit_UVChart_Layer0_Detail.mat
-
37Assets/TestScenes/HDTest/LayeredLitTest/Material/Lit_UVChart_Layer1_Detail.mat
-
31Assets/TestScenes/HDTest/LayeredLitTest/Material/Lit_UVChart_Layer2_Detail.mat
-
37Assets/TestScenes/HDTest/LayeredLitTest/Material/Lit_UVChart_Layer3_Detail.mat
-
28Assets/TestScenes/HDTest/LayeredLitTest/Material/Lit_White_Detail.mat
-
69Assets/ScriptableRenderPipeline/ShaderLibrary/SampleUVMapping.hlsl
-
57Assets/ScriptableRenderPipeline/ShaderLibrary/SampleUVMappingInternal.hlsl
-
55Assets/ScriptableRenderPipeline/ShaderLibrary/SampleUVMappingNormalInternal.hlsl
-
66Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/SampleLayer.hlsl
-
57Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/SampleLayerInternal.hlsl
-
55Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/SampleLayerNormalInternal.hlsl
-
0/Assets/ScriptableRenderPipeline/ShaderLibrary/SampleUVMapping.hlsl.meta
-
0/Assets/ScriptableRenderPipeline/ShaderLibrary/SampleUVMappingInternal.hlsl.meta
-
0/Assets/ScriptableRenderPipeline/ShaderLibrary/SampleUVMappingNormalInternal.hlsl.meta
|
|||
// This structure abstract uv mapping inside one struct. |
|||
// It represent a mapping of any uv (with its associated tangent space for derivative if SurfaceGradient mode) - UVSet0 to 4, planar, triplanar |
|||
|
|||
#define UV_MAPPING_UVSET 0 |
|||
#define UV_MAPPING_PLANAR 1 |
|||
#define UV_MAPPING_TRIPLANAR 2 |
|||
|
|||
struct UVMapping |
|||
{ |
|||
int mappingType; |
|||
float2 uv; // Current uv or planar uv |
|||
|
|||
// Triplanar specific |
|||
float2 uvZY; |
|||
float2 uvXZ; |
|||
float2 uvXY; |
|||
|
|||
float3 triplanarWeights; |
|||
|
|||
#ifdef SURFACE_GRADIENT |
|||
// tangent basis to use when mappingType is UV_MAPPING_UVSET |
|||
// these are vertex level in world space |
|||
float3 tangentWS; |
|||
float3 bitangentWS; |
|||
// normal only use with planar / triplanar |
|||
float3 normalWS; |
|||
// TODO: store also object normal map for object triplanar |
|||
#endif |
|||
}; |
|||
|
|||
// Multiple includes of the file to handle all variations of textures sampling for regular, lod and bias |
|||
|
|||
// Regular sampling functions |
|||
#define ADD_FUNC_SUFFIX(Name) Name |
|||
#define SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping, unused) SAMPLE_TEXTURE2D(textureName, samplerName, uvMapping) |
|||
#include "SampleUVMappingInternal.hlsl" |
|||
#undef ADD_FUNC_SUFFIX |
|||
#undef SAMPLE_TEXTURE_FUNC |
|||
|
|||
// Lod sampling functions |
|||
#define ADD_FUNC_SUFFIX(Name) Name##Lod |
|||
#define SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, uvMapping, lod) |
|||
#include "SampleUVMappingInternal.hlsl" |
|||
#undef ADD_FUNC_SUFFIX |
|||
#undef SAMPLE_TEXTURE_FUNC |
|||
|
|||
// Bias sampling functions |
|||
#define ADD_FUNC_SUFFIX(Name) Name##Bias |
|||
#define SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping, bias) SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, uvMapping, bias) |
|||
#include "SampleUVMappingInternal.hlsl" |
|||
#undef ADD_FUNC_SUFFIX |
|||
#undef SAMPLE_TEXTURE_FUNC |
|||
|
|||
// Macro to improve readibility of surface data |
|||
#define SAMPLE_UVMAPPING_TEXTURE2D(textureName, samplerName, uvMapping) SampleUVMapping(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, 0.0) // Last 0.0 is unused |
|||
#define SAMPLE_UVMAPPING_TEXTURE2D_LOD(textureName, samplerName, uvMapping, lod) SampleUVMappingLod(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, lod) |
|||
#define SAMPLE_UVMAPPING_TEXTURE2D_BIAS(textureName, samplerName, uvMapping, bias) SampleUVMappingBias(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, bias) |
|||
|
|||
#define SAMPLE_UVMAPPING_NORMALMAP(textureName, samplerName, uvMapping, scale) SampleUVMappingNormal(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, 0.0) |
|||
#define SAMPLE_UVMAPPING_NORMALMAP_LOD(textureName, samplerName, uvMapping, scale, lod) SampleUVMappingNormalLod(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, lod) |
|||
#define SAMPLE_UVMAPPING_NORMALMAP_BIAS(textureName, samplerName, uvMapping, scale, bias) SampleUVMappingNormalBias(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, bias) |
|||
|
|||
#define SAMPLE_UVMAPPING_NORMALMAP_AG(textureName, samplerName, uvMapping, scale) SampleUVMappingNormalAG(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, 0.0) |
|||
#define SAMPLE_UVMAPPING_NORMALMAP_AG_LOD(textureName, samplerName, uvMapping, scale, lod) SampleUVMappingNormalAGLod(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, lod) |
|||
#define SAMPLE_UVMAPPING_NORMALMAP_AG_BIAS(textureName, samplerName, uvMapping, scale, bias) SampleUVMappingNormalAGBias(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, bias) |
|||
|
|||
#define SAMPLE_UVMAPPING_NORMALMAP_RGB(textureName, samplerName, uvMapping, scale) SampleUVMappingNormalRGB(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, 0.0) |
|||
#define SAMPLE_UVMAPPING_NORMALMAP_RGB_LOD(textureName, samplerName, uvMapping, scale, lod) SampleUVMappingNormalRGBLod(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, lod) |
|||
#define SAMPLE_UVMAPPING_NORMALMAP_RGB_BIAS(textureName, samplerName, uvMapping, scale, bias) SampleUVMappingNormalRGBBias(TEXTURE2D_PARAM(textureName, samplerName), uvMapping, scale, bias) |
|
|||
|
|||
// These functions are use to hide the handling of triplanar mapping |
|||
// Normal need a specific treatment as they use special encoding for both base and detail map |
|||
// Also we use multiple inclusion to handle the various variation for lod and bias |
|||
|
|||
// param can be unused, lod or bias |
|||
float4 ADD_FUNC_SUFFIX(SampleUVMapping)(TEXTURE2D_ARGS(textureName, samplerName), UVMapping uvMapping, float param) |
|||
{ |
|||
if (uvMapping.mappingType == UV_MAPPING_TRIPLANAR) |
|||
{ |
|||
float3 triplanarWeights = uvMapping.triplanarWeights; |
|||
float4 val = float4(0.0, 0.0, 0.0, 0.0); |
|||
|
|||
if (triplanarWeights.x > 0.0) |
|||
val += triplanarWeights.x * SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uvZY, param); |
|||
if (triplanarWeights.y > 0.0) |
|||
val += triplanarWeights.y * SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uvXZ, param); |
|||
if (triplanarWeights.z > 0.0) |
|||
val += triplanarWeights.z * SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uvXY, param); |
|||
|
|||
return val; |
|||
} |
|||
else // UV_MAPPING_UVSET / UV_MAPPING_PLANAR |
|||
{ |
|||
return SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uv, param); |
|||
} |
|||
} |
|||
|
|||
// 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 |
|||
#define ADD_NORMAL_FUNC_SUFFIX(Name) Name |
|||
#define UNPACK_NORMAL_FUNC UnpackNormalAG |
|||
#define UNPACK_DERIVATIVE_FUNC UnpackDerivativeNormalAG |
|||
#include "SampleUVMappingNormalInternal.hlsl" |
|||
#undef ADD_NORMAL_FUNC_SUFFIX |
|||
#undef UNPACK_NORMAL_FUNC |
|||
#undef UNPACK_DERIVATIVE_FUNC |
|||
|
|||
// This version is for normalmap with AG encoding only. Mainly use with details map. |
|||
#define ADD_NORMAL_FUNC_SUFFIX(Name) Name##AG |
|||
#define UNPACK_NORMAL_FUNC UnpackNormalAG |
|||
#define UNPACK_DERIVATIVE_FUNC UnpackDerivativeNormalAG |
|||
#include "SampleUVMappingNormalInternal.hlsl" |
|||
#undef ADD_NORMAL_FUNC_SUFFIX |
|||
#undef UNPACK_NORMAL_FUNC |
|||
#undef UNPACK_DERIVATIVE_FUNC |
|||
|
|||
// This version is for normalmap with RGB encoding only, i.e uncompress or BC7. |
|||
#define ADD_NORMAL_FUNC_SUFFIX(Name) Name##RGB |
|||
#define UNPACK_NORMAL_FUNC UnpackNormalRGB |
|||
#define UNPACK_DERIVATIVE_FUNC UnpackDerivativeNormalRGB |
|||
#include "SampleUVMappingNormalInternal.hlsl" |
|||
#undef ADD_NORMAL_FUNC_SUFFIX |
|||
#undef UNPACK_NORMAL_FUNC |
|||
#undef UNPACK_DERIVATIVE_FUNC |
|
|||
float3 ADD_FUNC_SUFFIX(ADD_NORMAL_FUNC_SUFFIX(SampleUVMappingNormal))(TEXTURE2D_ARGS(textureName, samplerName), UVMapping uvMapping, float scale, float param) |
|||
{ |
|||
if (uvMapping.mappingType == UV_MAPPING_TRIPLANAR) |
|||
{ |
|||
float3 triplanarWeights = uvMapping.triplanarWeights; |
|||
|
|||
#ifdef SURFACE_GRADIENT |
|||
float2 derivXplane; |
|||
float2 derivYPlane; |
|||
float2 derivZPlane; |
|||
derivXplane = derivYPlane = derivZPlane = float2(0.0, 0.0); |
|||
|
|||
if (triplanarWeights.x > 0.0) |
|||
derivXplane = triplanarWeights.x * UNPACK_DERIVATIVE_FUNC(SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uvZY, param), scale); |
|||
if (triplanarWeights.y > 0.0) |
|||
derivYPlane = triplanarWeights.y * UNPACK_DERIVATIVE_FUNC(SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uvXZ, param), scale); |
|||
if (triplanarWeights.z > 0.0) |
|||
derivZPlane = triplanarWeights.z * UNPACK_DERIVATIVE_FUNC(SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uvXY, param), scale); |
|||
|
|||
// Assume derivXplane, derivYPlane and derivZPlane sampled using (z,y), (z,x) and (x,y) respectively. |
|||
// TODO: Check with morten convention! Do it follow ours ? |
|||
float3 volumeGrad = float3(derivZPlane.x + derivYPlane.y, derivZPlane.y + derivXplane.y, derivXplane.x + derivYPlane.x); |
|||
return surfgradFromVolumeGradient(uvMapping.normalWS, volumeGrad); |
|||
#else |
|||
float3 val = float3(0.0, 0.0, 0.0); |
|||
|
|||
if (triplanarWeights.x > 0.0) |
|||
val += triplanarWeights.x * UNPACK_NORMAL_FUNC(SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uvZY, param), scale); |
|||
if (triplanarWeights.y > 0.0) |
|||
val += triplanarWeights.y * UNPACK_NORMAL_FUNC(SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uvXZ, param), scale); |
|||
if (triplanarWeights.z > 0.0) |
|||
val += triplanarWeights.z * UNPACK_NORMAL_FUNC(SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uvXY, param), scale); |
|||
|
|||
return normalize(val); |
|||
#endif |
|||
} |
|||
#ifdef SURFACE_GRADIENT |
|||
else if (uvMapping.mappingType == UV_MAPPING_PLANAR) |
|||
{ |
|||
float2 derivYPlane = UNPACK_DERIVATIVE_FUNC(SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uvXZ, param), scale); |
|||
// See comment above |
|||
float3 volumeGrad = float3(derivYPlane.y, 0.0, derivYPlane.x); |
|||
return surfgradFromVolumeGradient(uvMapping.normalWS, volumeGrad); |
|||
} |
|||
#endif |
|||
else |
|||
{ |
|||
#ifdef SURFACE_GRADIENT |
|||
float2 deriv = UNPACK_DERIVATIVE_FUNC(SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uv, param), scale); |
|||
return SurfaceGradientFromTBN(deriv, uvMapping.tangentWS, uvMapping.bitangentWS); |
|||
#else |
|||
return UNPACK_NORMAL_FUNC(SAMPLE_TEXTURE_FUNC(textureName, samplerName, uvMapping.uv, param), scale); |
|||
#endif |
|||
} |
|||
} |
|
|||
// Gather all kind of mapping in one struct, allow to improve code readability |
|||
struct LayerUV |
|||
{ |
|||
float2 uv; |
|||
bool isPlanar; // mutually exclusive with isTriplanar |
|||
// triplanar |
|||
bool isTriplanar; |
|||
float2 uvZY; |
|||
float2 uvXZ; |
|||
float2 uvXY; |
|||
|
|||
#ifdef SURFACE_GRADIENT |
|||
// tangent basis to use for this UV set |
|||
float3 vT, vB; |
|||
// vertex normal for planar/triplanar |
|||
float3 vertexNormalWS; // TODO: Should be part of LayerCoord but require to |
|||
#endif |
|||
}; |
|||
|
|||
struct CommonLayerUV |
|||
{ |
|||
#ifdef SURFACE_GRADIENT |
|||
float3 vertexNormalWS; |
|||
#endif |
|||
float3 triplanarWeights; |
|||
}; |
|||
|
|||
// Multiple includes of the file to handle all variations of textures sampling for regular, lod and bias |
|||
|
|||
// Regular sampling functions |
|||
#define ADD_FUNC_SUFFIX(Name) Name |
|||
#define SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV, unused) SAMPLE_TEXTURE2D(layerTex, layerSampler, layerUV) |
|||
#include "SampleLayerInternal.hlsl" |
|||
#undef ADD_FUNC_SUFFIX |
|||
#undef SAMPLE_TEXTURE_FUNC |
|||
|
|||
// Lod sampling functions |
|||
#define ADD_FUNC_SUFFIX(Name) Name##Lod |
|||
#define SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV, lod) SAMPLE_TEXTURE2D_LOD(layerTex, layerSampler, layerUV, lod) |
|||
#include "SampleLayerInternal.hlsl" |
|||
#undef ADD_FUNC_SUFFIX |
|||
#undef SAMPLE_TEXTURE_FUNC |
|||
|
|||
// Bias sampling functions |
|||
#define ADD_FUNC_SUFFIX(Name) Name##Bias |
|||
#define SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV, bias) SAMPLE_TEXTURE2D_BIAS(layerTex, layerSampler, layerUV, bias) |
|||
#include "SampleLayerInternal.hlsl" |
|||
#undef ADD_FUNC_SUFFIX |
|||
#undef SAMPLE_TEXTURE_FUNC |
|||
|
|||
// Macro to improve readibility of surface data |
|||
#define SAMPLE_LAYER_TEXTURE2D(textureName, samplerName, coord) SampleLayer(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.common, 0.0) // Last 0.0 is unused |
|||
#define SAMPLE_LAYER_TEXTURE2D_LOD(textureName, samplerName, coord, lod) SampleLayerLod(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.common, lod) |
|||
#define SAMPLE_LAYER_TEXTURE2D_BIAS(textureName, samplerName, coord, bias) SampleLayerBias(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.common, bias) |
|||
|
|||
#define SAMPLE_LAYER_NORMALMAP(textureName, samplerName, coord, scale) SampleLayerNormal(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.common, scale, 0.0) |
|||
#define SAMPLE_LAYER_NORMALMAP_LOD(textureName, samplerName, coord, scale, lod) SampleLayerNormalLod(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.common, scale, lod) |
|||
#define SAMPLE_LAYER_NORMALMAP_BIAS(textureName, samplerName, coord, scale, bias) SampleLayerNormalBias(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.common, scale, bias) |
|||
|
|||
#define SAMPLE_LAYER_NORMALMAP_AG(textureName, samplerName, coord, scale) SampleLayerNormalAG(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.common, scale, 0.0) |
|||
#define SAMPLE_LAYER_NORMALMAP_AG_LOD(textureName, samplerName, coord, scale, lod) SampleLayerNormalAGLod(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.common, scale, lod) |
|||
#define SAMPLE_LAYER_NORMALMAP_AG_BIAS(textureName, samplerName, coord, scale, bias) SampleLayerNormalAGBias(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.common, scale, bias) |
|||
|
|||
#define SAMPLE_LAYER_NORMALMAP_RGB(textureName, samplerName, coord, scale) SampleLayerNormalRGB(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.common, scale, 0.0) |
|||
#define SAMPLE_LAYER_NORMALMAP_RGB_LOD(textureName, samplerName, coord, scale, lod) SampleLayerNormalRGBLod(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.common, scale, lod) |
|||
#define SAMPLE_LAYER_NORMALMAP_RGB_BIAS(textureName, samplerName, coord, scale, bias) SampleLayerNormalRGBBias(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.common, scale, bias) |
|
|||
|
|||
// These functions are use to hide the handling of triplanar mapping |
|||
// Normal need a specific treatment as they use special encoding for both base and detail map |
|||
// Also we use multiple inclusion to handle the various variation for lod and bias |
|||
|
|||
// param can be unused, lod or bias |
|||
float4 ADD_FUNC_SUFFIX(SampleLayer)(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV, CommonLayerUV common, float param) |
|||
{ |
|||
if (layerUV.isTriplanar) |
|||
{ |
|||
float3 triplanarWeights = common.triplanarWeights; |
|||
float4 val = float4(0.0, 0.0, 0.0, 0.0); |
|||
|
|||
if (triplanarWeights.x > 0.0) |
|||
val += triplanarWeights.x * SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvZY, param); |
|||
if (triplanarWeights.y > 0.0) |
|||
val += triplanarWeights.y * SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvXZ, param); |
|||
if (triplanarWeights.z > 0.0) |
|||
val += triplanarWeights.z * SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvXY, param); |
|||
|
|||
return val; |
|||
} |
|||
else |
|||
{ |
|||
return SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uv, param); |
|||
} |
|||
} |
|||
|
|||
// 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 |
|||
#define ADD_NORMAL_FUNC_SUFFIX(Name) Name |
|||
#define UNPACK_NORMAL_FUNC UnpackNormalAG |
|||
#define UNPACK_DERIVATIVE_FUNC UnpackDerivativeNormalAG |
|||
#include "SampleLayerNormalInternal.hlsl" |
|||
#undef ADD_NORMAL_FUNC_SUFFIX |
|||
#undef UNPACK_NORMAL_FUNC |
|||
#undef UNPACK_DERIVATIVE_FUNC |
|||
|
|||
// This version is for normalmap with AG encoding only. Mainly use with details map. |
|||
#define ADD_NORMAL_FUNC_SUFFIX(Name) Name##AG |
|||
#define UNPACK_NORMAL_FUNC UnpackNormalAG |
|||
#define UNPACK_DERIVATIVE_FUNC UnpackDerivativeNormalAG |
|||
#include "SampleLayerNormalInternal.hlsl" |
|||
#undef ADD_NORMAL_FUNC_SUFFIX |
|||
#undef UNPACK_NORMAL_FUNC |
|||
#undef UNPACK_DERIVATIVE_FUNC |
|||
|
|||
// This version is for normalmap with RGB encoding only, i.e uncompress or BC7. |
|||
#define ADD_NORMAL_FUNC_SUFFIX(Name) Name##RGB |
|||
#define UNPACK_NORMAL_FUNC UnpackNormalRGB |
|||
#define UNPACK_DERIVATIVE_FUNC UnpackDerivativeNormalRGB |
|||
#include "SampleLayerNormalInternal.hlsl" |
|||
#undef ADD_NORMAL_FUNC_SUFFIX |
|||
#undef UNPACK_NORMAL_FUNC |
|||
#undef UNPACK_DERIVATIVE_FUNC |
|
|||
float3 ADD_FUNC_SUFFIX(ADD_NORMAL_FUNC_SUFFIX(SampleLayerNormal))(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV, CommonLayerUV common, float scale, float param) |
|||
{ |
|||
if (layerUV.isTriplanar) |
|||
{ |
|||
float3 triplanarWeights = common.triplanarWeights; |
|||
|
|||
#ifdef SURFACE_GRADIENT |
|||
float2 derivXplane; |
|||
float2 derivYPlane; |
|||
float2 derivZPlane; |
|||
derivXplane = derivYPlane = derivZPlane = float2(0.0, 0.0); |
|||
|
|||
if (triplanarWeights.x > 0.0) |
|||
derivXplane = triplanarWeights.x * UNPACK_DERIVATIVE_FUNC(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvZY, param), scale); |
|||
if (triplanarWeights.y > 0.0) |
|||
derivYPlane = triplanarWeights.y * UNPACK_DERIVATIVE_FUNC(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvXZ, param), scale); |
|||
if (triplanarWeights.z > 0.0) |
|||
derivZPlane = triplanarWeights.z * UNPACK_DERIVATIVE_FUNC(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvXY, param), scale); |
|||
|
|||
// Assume derivXplane, derivYPlane and derivZPlane sampled using (z,y), (z,x) and (x,y) respectively. |
|||
// TODO: Check with morten convention! Do it follow ours ? |
|||
float3 volumeGrad = float3(derivZPlane.x + derivYPlane.y, derivZPlane.y + derivXplane.y, derivXplane.x + derivYPlane.x); |
|||
return surfgradFromVolumeGradient(layerUV.vertexNormalWS, volumeGrad); |
|||
#else |
|||
float3 val = float3(0.0, 0.0, 0.0); |
|||
|
|||
if (triplanarWeights.x > 0.0) |
|||
val += triplanarWeights.x * UNPACK_NORMAL_FUNC(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvZY, param), scale); |
|||
if (triplanarWeights.y > 0.0) |
|||
val += triplanarWeights.y * UNPACK_NORMAL_FUNC(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvXZ, param), scale); |
|||
if (triplanarWeights.z > 0.0) |
|||
val += triplanarWeights.z * UNPACK_NORMAL_FUNC(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvXY, param), scale); |
|||
|
|||
return normalize(val); |
|||
#endif |
|||
} |
|||
#ifdef SURFACE_GRADIENT |
|||
else if (layerUV.isPlanar) |
|||
{ |
|||
float2 derivYPlane = UNPACK_DERIVATIVE_FUNC(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvXZ, param), scale); |
|||
// See comment above |
|||
float3 volumeGrad = float3(derivYPlane.y, 0.0, derivYPlane.x); |
|||
return surfgradFromVolumeGradient(layerUV.vertexNormalWS, volumeGrad); |
|||
} |
|||
#endif |
|||
else |
|||
{ |
|||
#ifdef SURFACE_GRADIENT |
|||
float2 deriv = UNPACK_DERIVATIVE_FUNC(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uv, param), scale); |
|||
return SurfaceGradientFromTBN(deriv, layerUV.vT, layerUV.vB); |
|||
#else |
|||
return UNPACK_NORMAL_FUNC(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uv, param), scale); |
|||
#endif |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue