浏览代码
Merge branch 'master' of https://github.com/Unity-Technologies/ScriptableRenderLoop
/Branch_Batching2
Merge branch 'master' of https://github.com/Unity-Technologies/ScriptableRenderLoop
/Branch_Batching2
Evgenii Golubev
8 年前
当前提交
a5c5f339
共有 73 个文件被更改,包括 1221 次插入 和 653 次删除
-
2Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
-
182Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
-
16Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs
-
18Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
-
18Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
-
18Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
-
5Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
-
306Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
-
146Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
-
3Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitProperties.hlsl
-
1Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.hlsl
-
3Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader
-
1Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/ShaderPass/LitDepthPass.hlsl
-
1Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/ShaderPass/LitDistortionPass.hlsl
-
1Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/ShaderPass/LitVelocityPass.hlsl
-
34Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/MaterialUtilities.hlsl
-
8Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Editor/BaseUnlitUI.cs
-
20Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/FragInputs.hlsl
-
34Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl
-
46Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl
-
2Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Resources/SkyHDRI.shader
-
1Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader
-
8Assets/ScriptableRenderPipeline/ShaderLibrary/CommonLighting.hlsl
-
9Assets/ScriptableRenderPipeline/ShaderLibrary/CommonMaterial.hlsl
-
35Assets/TestScenes/HDTest/CascadedShadowsTest.unity
-
18Assets/TestScenes/HDTest/CascadedShadowsTest/Lit_Gray.mat
-
25Assets/TestScenes/HDTest/GlobalIlluminationTest/Material/Chrome.mat
-
6Assets/TestScenes/HDTest/GlobalIlluminationTest/Material/Lit_Green.mat
-
6Assets/TestScenes/HDTest/GlobalIlluminationTest/Material/Lit_Grey.mat
-
21Assets/TestScenes/HDTest/GlobalIlluminationTest/Material/Lit_Red.mat
-
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
-
6Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Lit_Emissive_Blue.mat
-
12Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test details.mat
-
2ProjectSettings/ProjectVersion.txt
-
88Assets/ScriptableRenderPipeline/ShaderLibrary/NormalSurfaceGradient.hlsl
-
9Assets/ScriptableRenderPipeline/ShaderLibrary/NormalSurfaceGradient.hlsl.meta
-
70Assets/ScriptableRenderPipeline/ShaderLibrary/SampleUVMapping.hlsl
-
57Assets/ScriptableRenderPipeline/ShaderLibrary/SampleUVMappingInternal.hlsl
-
55Assets/ScriptableRenderPipeline/ShaderLibrary/SampleUVMappingNormalInternal.hlsl
-
9Assets/ScriptableRenderPipeline/ShaderLibrary/SampleUVMappingNormalInternal.hlsl.meta
-
93Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/SampleLayerInternal.hlsl
-
51Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/SampleLayer.hlsl
-
9Assets/TestScenes/HDTest/LayeredLitTest/Mesh/Materials.meta
-
0/Assets/ScriptableRenderPipeline/ShaderLibrary/SampleUVMapping.hlsl.meta
-
0/Assets/ScriptableRenderPipeline/ShaderLibrary/SampleUVMappingInternal.hlsl.meta
|
|||
m_EditorVersion: 5.6.0b6 |
|||
m_EditorVersion: 2017.1.0a1 |
|
|||
// this produces an orthonormal basis of the tangent and bitangent WITHOUT vertex level tangent/bitangent for any UV including procedurally generated |
|||
// method released with the demo for publication of "bump mapping unparametrized surfaces on the GPU" |
|||
// http://mmikkelsen3d.blogspot.com/2011/07/derivative-maps.html |
|||
void SurfaceGradientGenBasisTB(float3 nrmVertexNormal, float3 sigmaX, float3 sigmaY, float flipSign, float2 texST, out float3 vT, out float3 vB) |
|||
{ |
|||
float2 dSTdx = ddx_fine(texST), dSTdy = ddy_fine(texST); |
|||
|
|||
float det = dot(dSTdx, float2(dSTdy.y, -dSTdy.x)); |
|||
float sign_det = det < 0 ? -1 : 1; |
|||
|
|||
// invC0 represents (dXds, dYds); but we don't divide by determinant (scale by sign instead) |
|||
float2 invC0 = sign_det * float2(dSTdy.y, -dSTdx.y); |
|||
vT = sigmaX * invC0.x + sigmaY * invC0.y; |
|||
if (abs(det) > 0.0) |
|||
vT = normalize(vT); |
|||
vB = (sign_det * flipSign) * cross(nrmVertexNormal, vT); |
|||
} |
|||
|
|||
// surface gradient from an on the fly TBN (deriv obtained using tspaceNormalToDerivative()) or from conventional vertex level TBN (mikktspace compliant and deriv obtained using tspaceNormalToDerivative()) |
|||
float3 SurfaceGradientFromTBN(float2 deriv, float3 vT, float3 vB) |
|||
{ |
|||
return deriv.x * vT + deriv.y * vB; |
|||
} |
|||
|
|||
// surface gradient from an already generated "normal" such as from an object space normal map |
|||
// this allows us to mix the contribution together with a series of other contributions including tangent space normals |
|||
// v does not need to be unit length as long as it establishes the direction. |
|||
float3 SurfaceGradientFromPerturbedNormal(float3 nrmVertexNormal, float3 v) |
|||
{ |
|||
float3 n = nrmVertexNormal; |
|||
float s = 1.0 / max(FLT_EPSILON, abs(dot(n, v))); |
|||
return s * (dot(n, v) * n - v); |
|||
} |
|||
|
|||
// used to produce a surface gradient from the gradient of a volume bump function such as a volume of perlin noise. |
|||
// equation 2. in "bump mapping unparametrized surfaces on the GPU". |
|||
// Observe the difference in figure 2. between using the gradient vs. the surface gradient to do bump mapping (the original method is proved wrong in the paper!). |
|||
float3 SurfaceGradientFromVolumeGradient(float3 nrmVertexNormal, float3 grad) |
|||
{ |
|||
return grad - dot(nrmVertexNormal, grad) * nrmVertexNormal; |
|||
} |
|||
|
|||
// triplanar projection considered special case of volume bump map |
|||
// described here: http://mmikkelsen3d.blogspot.com/2013/10/volume-height-maps-and-triplanar-bump.html |
|||
// derivs obtained using tspaceNormalToDerivative() and weights using computeTriplanarWeights(). |
|||
float3 SurfaceGradientFromTriplanarProjection(float3 nrmVertexNormal, float3 triplanarWeights, float2 deriv_xplane, float2 deriv_yplane, float2 deriv_zplane) |
|||
{ |
|||
const float w0 = triplanarWeights.x, w1 = triplanarWeights.y, w2 = triplanarWeights.z; |
|||
|
|||
// assume deriv_xplane, deriv_yplane and deriv_zplane sampled using (z,y), (z,x) and (x,y) respectively. |
|||
// positive scales of the look-up coordinate will work as well but for negative scales the derivative components will need to be negated accordingly. |
|||
float3 volumeGrad = float3(w2 * deriv_zplane.x + w1 * deriv_yplane.y, w2 * deriv_zplane.y + w0 * deriv_xplane.y, w0 * deriv_xplane.x + w1 * deriv_yplane.x); |
|||
|
|||
return SurfaceGradientFromVolumeGradient(nrmVertexNormal, volumeGrad); |
|||
} |
|||
|
|||
float3 SurfaceGradientResolveNormal(float3 nrmVertexNormal, float3 surfGrad) |
|||
{ |
|||
return normalize(nrmVertexNormal - surfGrad); |
|||
} |
|||
|
|||
// The 128 means the derivative will come out no greater than 128 numerically (where 1 is 45 degrees so 128 is very steap). You can increase it if u like of course |
|||
// Basically tan(angle) limited to 128 |
|||
// So a max angle of 89.55 degrees ;) id argue thats close enough to the vertical limit at 90 degrees |
|||
// vT is channels.xy of a tangent space normal in[-1; 1] |
|||
// out: convert vT to a derivative |
|||
float2 UnpackDerivativeNormalAG(float4 packedNormal, float scale = 1.0) |
|||
{ |
|||
const float fS = 1.0 / (128.0 * 128.0); |
|||
float2 vT = packedNormal.wy * 2.0 - 1.0; |
|||
float2 vTsq = vT * vT; |
|||
float nz_sq = 1 - vTsq.x - vTsq.y; |
|||
float maxcompxy_sq = fS * max(vTsq.x, vTsq.y); |
|||
float z_inv = rsqrt(max(nz_sq, maxcompxy_sq)); |
|||
float2 deriv = -z_inv * float2(vT.x, vT.y); |
|||
return deriv * scale; |
|||
} |
|||
|
|||
float2 UnpackDerivativeNormalRGB(float4 packedNormal, float scale = 1.0) |
|||
{ |
|||
const float fS = 1.0 / (128.0 * 128.0); |
|||
float3 vT = packedNormal.xyz * 2.0 - 1.0; |
|||
float3 vTsq = vT * vT; |
|||
float maxcompxy_sq = fS * max(vTsq.x, vTsq.y); |
|||
float z_inv = rsqrt(max(vTsq.z, maxcompxy_sq)); |
|||
float2 deriv = -z_inv * float2(vT.x, vT.y); |
|||
return deriv * scale; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b6ff088bebec9f941ae19a0086e4f097 |
|||
timeCreated: 1487475828 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// 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 |
|||
|
|||
#include "ShaderLibrary/NormalSurfaceGradient.hlsl" |
|||
|
|||
#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 normalWS; // vertex normal |
|||
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; |
|||
// 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 SurfaceGradientFromVolumeGradient(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 SurfaceGradientFromVolumeGradient(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 |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f941b2119184e624a8ecd126735c5ed0 |
|||
timeCreated: 1487475828 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
|
|||
// 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, float3 triplanarWeights, float param) |
|||
{ |
|||
if (layerUV.isTriplanar) |
|||
{ |
|||
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); |
|||
} |
|||
} |
|||
|
|||
// 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 |
|||
float3 ADD_FUNC_SUFFIX(SampleLayerNormal)(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV, float3 triplanarWeights, float scale, float param) |
|||
{ |
|||
if (layerUV.isTriplanar) |
|||
{ |
|||
float3 val = float3(0.0, 0.0, 0.0); |
|||
|
|||
if (triplanarWeights.x > 0.0) |
|||
val += triplanarWeights.x * UnpackNormalAG(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvZY, param), scale); |
|||
if (triplanarWeights.y > 0.0) |
|||
val += triplanarWeights.y * UnpackNormalAG(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvXZ, param), scale); |
|||
if (triplanarWeights.z > 0.0) |
|||
val += triplanarWeights.z * UnpackNormalAG(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvXY, param), scale); |
|||
|
|||
return normalize(val); |
|||
} |
|||
else |
|||
{ |
|||
return UnpackNormalAG(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uv, param), scale); |
|||
} |
|||
} |
|||
|
|||
// This version is for normalmap with AG encoding only. Mainly use with details map. |
|||
float3 ADD_FUNC_SUFFIX(SampleLayerNormalAG)(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV, float3 triplanarWeights, float scale, float param) |
|||
{ |
|||
if (layerUV.isTriplanar) |
|||
{ |
|||
float3 val = float3(0.0, 0.0, 0.0); |
|||
|
|||
if (triplanarWeights.x > 0.0) |
|||
val += triplanarWeights.x * UnpackNormalAG(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvZY, param), scale); |
|||
if (triplanarWeights.y > 0.0) |
|||
val += triplanarWeights.y * UnpackNormalAG(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvXZ, param), scale); |
|||
if (triplanarWeights.z > 0.0) |
|||
val += triplanarWeights.z * UnpackNormalAG(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvXY, param), scale); |
|||
|
|||
return normalize(val); |
|||
} |
|||
else |
|||
{ |
|||
return UnpackNormalAG(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uv, param), scale); |
|||
} |
|||
} |
|||
|
|||
// This version is for normalmap with RGB encoding only, i.e uncompress or BC7. Mainly used for object space normal. |
|||
float3 ADD_FUNC_SUFFIX(SampleLayerNormalRGB)(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV, float3 triplanarWeights, float scale, float param) |
|||
{ |
|||
if (layerUV.isTriplanar) |
|||
{ |
|||
float3 val = float3(0.0, 0.0, 0.0); |
|||
|
|||
if (triplanarWeights.x > 0.0) |
|||
val += triplanarWeights.x * UnpackNormalRGB(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvZY, param), scale); |
|||
if (triplanarWeights.y > 0.0) |
|||
val += triplanarWeights.y * UnpackNormalRGB(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvXZ, param), scale); |
|||
if (triplanarWeights.z > 0.0) |
|||
val += triplanarWeights.z * UnpackNormalRGB(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uvXY, param), scale); |
|||
|
|||
return normalize(val); |
|||
} |
|||
else |
|||
{ |
|||
return UnpackNormalRGB(SAMPLE_TEXTURE_FUNC(layerTex, layerSampler, layerUV.uv, param), scale); |
|||
} |
|||
} |
|
|||
// 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; |
|||
}; |
|||
|
|||
// 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.triplanarWeights, 0.0) // Last 0.0 is unused |
|||
#define SAMPLE_LAYER_TEXTURE2D_LOD(textureName, samplerName, coord, lod) SampleLayerLod(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.triplanarWeights, lod) |
|||
#define SAMPLE_LAYER_TEXTURE2D_BIAS(textureName, samplerName, coord, bias) SampleLayerBias(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.triplanarWeights, bias) |
|||
|
|||
#define SAMPLE_LAYER_NORMALMAP(textureName, samplerName, coord, scale) SampleLayerNormal(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.triplanarWeights, scale, 0.0) |
|||
#define SAMPLE_LAYER_NORMALMAP_LOD(textureName, samplerName, coord, scale, lod) SampleLayerNormalLod(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.triplanarWeights, scale, lod) |
|||
#define SAMPLE_LAYER_NORMALMAP_BIAS(textureName, samplerName, coord, scale, bias) SampleLayerNormalBias(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.triplanarWeights, scale, bias) |
|||
|
|||
#define SAMPLE_LAYER_NORMALMAP_AG(textureName, samplerName, coord, scale) SampleLayerNormalAG(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.triplanarWeights, scale, 0.0) |
|||
#define SAMPLE_LAYER_NORMALMAP_AG_LOD(textureName, samplerName, coord, scale, lod) SampleLayerNormalAGLod(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.triplanarWeights, scale, lod) |
|||
#define SAMPLE_LAYER_NORMALMAP_AG_BIAS(textureName, samplerName, coord, scale, bias) SampleLayerNormalAGBias(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.triplanarWeights, scale, bias) |
|||
|
|||
#define SAMPLE_LAYER_NORMALMAP_RGB(textureName, samplerName, coord, scale) SampleLayerNormalRGB(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.triplanarWeights, scale, 0.0) |
|||
#define SAMPLE_LAYER_NORMALMAP_RGB_LOD(textureName, samplerName, coord, scale, lod) SampleLayerNormalRGBLod(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.triplanarWeights, scale, lod) |
|||
#define SAMPLE_LAYER_NORMALMAP_RGB_BIAS(textureName, samplerName, coord, scale, bias) SampleLayerNormalRGBBias(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.triplanarWeights, scale, bias) |
|
|||
fileFormatVersion: 2 |
|||
guid: e8f6ad2e481134b4fa6108a280b52de7 |
|||
folderAsset: yes |
|||
timeCreated: 1484331445 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue