浏览代码

Push draft of layered lit work

/stochastic_alpha_test
sebastienlagarde 7 年前
当前提交
2bfcb077
共有 4 个文件被更改,包括 70 次插入26 次删除
  1. 5
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
  2. 5
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  3. 72
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
  4. 14
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.hlsl

5
ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader


_TexWorldScale2("Tiling", Float) = 1.0
_TexWorldScale3("Tiling", Float) = 1.0
[HideInInspector] _InvTilingScale("Inverse tiling scale = 2 / (abs(_BaseColorMap_ST.x) + abs(_BaseColorMap_ST.y))", Vector) = (1, 1, 1, 1)
[HideInInspector] _InvTilingScale0("Inverse tiling scale = 2 / (abs(_BaseColorMap_ST.x) + abs(_BaseColorMap_ST.y))", Vector) = (1, 1, 1, 1)
[HideInInspector] _InvTilingScale1("Inverse tiling scale = 2 / (abs(_BaseColorMap_ST.x) + abs(_BaseColorMap_ST.y))", Vector) = (1, 1, 1, 1)
[HideInInspector] _InvTilingScale2("Inverse tiling scale = 2 / (abs(_BaseColorMap_ST.x) + abs(_BaseColorMap_ST.y))", Vector) = (1, 1, 1, 1)
[HideInInspector] _InvTilingScale3("Inverse tiling scale = 2 / (abs(_BaseColorMap_ST.x) + abs(_BaseColorMap_ST.y))", Vector) = (1, 1, 1, 1)
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase0("UV Set for base0", Float) = 0 // no UV1/2/3 for main layer (matching Lit.shader and for PPDisplacement restriction)
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase1("UV Set for base1", Float) = 0

5
ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader


_TexWorldScale2("Tiling", Float) = 1.0
_TexWorldScale3("Tiling", Float) = 1.0
[HideInInspector] _InvTilingScale("Inverse tiling scale = 2 / (abs(_BaseColorMap_ST.x) + abs(_BaseColorMap_ST.y))", Vector) = (1, 1, 1, 1)
[HideInInspector] _InvTilingScale0("Inverse tiling scale = 2 / (abs(_BaseColorMap_ST.x) + abs(_BaseColorMap_ST.y))", Vector) = (1, 1, 1, 1)
[HideInInspector] _InvTilingScale1("Inverse tiling scale = 2 / (abs(_BaseColorMap_ST.x) + abs(_BaseColorMap_ST.y))", Vector) = (1, 1, 1, 1)
[HideInInspector] _InvTilingScale2("Inverse tiling scale = 2 / (abs(_BaseColorMap_ST.x) + abs(_BaseColorMap_ST.y))", Vector) = (1, 1, 1, 1)
[HideInInspector] _InvTilingScale3("Inverse tiling scale = 2 / (abs(_BaseColorMap_ST.x) + abs(_BaseColorMap_ST.y))", Vector) = (1, 1, 1, 1)
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase0("UV Set for base0", Float) = 0 // no UV1/2/3 for main layer (matching Lit.shader and for PPDisplacement restriction)
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase1("UV Set for base1", Float) = 0

72
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl


return objectScale;
}
float GetDisplacementInverseTilingScale()
void ApplyDisplacementTileScale(inout float height)
return _InvTilingScale;
#else
return 1.0;
height *= _InvTilingScale;
#endif
}

bool isTriplanar = layerTexCoord.base.mappingType == UV_MAPPING_TRIPLANAR;
// See comment in layered version for details
float maxHeight = GetMaxDisplacement() * GetDisplacementInverseTilingScale();
float maxHeight = GetMaxDisplacement();
ApplyDisplacementTileScale(maxHeight);
float2 minUvSize = GetMinUvSize(layerTexCoord);
float lod = ComputeTextureLOD(minUvSize);

float ComputePerVertexDisplacement(LayerTexCoord layerTexCoord, float4 vertexColor, float lod)
{
float height = (SAMPLE_UVMAPPING_TEXTURE2D_LOD(_HeightMap, sampler_HeightMap, layerTexCoord.base, lod).r - _HeightCenter) * _HeightAmplitude;
return height * GetDisplacementInverseTilingScale();
ApplyDisplacementTileScale(height);
// Applying scaling of the object if requested
#ifdef _VERTEX_DISPLACEMENT_LOCK_OBJECT_SCALE
float3 objectScale = GetDisplacementInverseObjectScale(true);
#else
float3 objectScale = float3(1.0, 1.0, 1.0);
#endif
return height * objectScale;
}
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)

input.positionWS, input.worldToTangent[2].xyz, layerTexCoord);
}
float3 GetDisplacementInverseObjectScale()
{
// TODO: This should be an uniform for the object, this code should be remove once we have it. - Workaround for now
// To handle object scaling with pixel displacement we need to multiply the view vector by the inverse scale.
// To Handle object scaling with vertex/tessellation displacement we must multiply displacement by object scale
// Currently we extract either the scale (ObjectToWorld) or the inverse scale (worldToObject) directly by taking the transform matrix
float4x4 worldTransform;
if (vertexDisplacement)
{
worldTransform = GetObjectToWorldMatrix();
}
else
{
worldTransform = GetWorldToObjectMatrix();
}
objectScale.x = length(float3(worldTransform._m00, worldTransform._m01, worldTransform._m02));
objectScale.y = length(float3(worldTransform._m10, worldTransform._m11, worldTransform._m12));
objectScale.z = length(float3(worldTransform._m20, worldTransform._m21, worldTransform._m22));
return objectScale;
}
void ApplyDisplacementTileScale(inout float height0, inout float height1, inout float height2, inout float height3)
{
// When we change the tiling, we have want to conserve the ratio with the displacement (and this is consistent with per pixel displacement)

#endif
// TODO: precompute all these scaling factors!
height0 /= max(_BaseColorMap0_ST.x, _BaseColorMap0_ST.y) * _TexWorldScale0;
height0 *= _InvTilingScale0;
height0 *= tileObjectScale; // We only affect layer0 in case we are not in influence mode (i.e we should not change the base object)
height0 /= tileObjectScale; // We only affect layer0 in case we are not in influence mode (i.e we should not change the base object)
height1 /= tileObjectScale * max(_BaseColorMap1_ST.x, _BaseColorMap1_ST.y) * _TexWorldScale1;
height2 /= tileObjectScale * max(_BaseColorMap2_ST.x, _BaseColorMap2_ST.y) * _TexWorldScale2;
height3 /= tileObjectScale * max(_BaseColorMap3_ST.x, _BaseColorMap3_ST.y) * _TexWorldScale3;
height1 = (height1 / tileObjectScale) * _InvTilingScale1;
height2 = (height2 / tileObjectScale) * _InvTilingScale2;
height3 = (height3 / tileObjectScale) * _InvTilingScale3;
#endif
}

float height2 = (SAMPLE_UVMAPPING_TEXTURE2D_LOD(_HeightMap2, SAMPLER_HEIGHTMAP_IDX, layerTexCoord.base2, lod).r - _HeightCenter2) * _HeightAmplitude2;
float height3 = (SAMPLE_UVMAPPING_TEXTURE2D_LOD(_HeightMap3, SAMPLER_HEIGHTMAP_IDX, layerTexCoord.base3, lod).r - _HeightCenter3) * _HeightAmplitude3;
ApplyDisplacementTileScale(height0, height1, height2, height3); // Only apply with per vertex displacement
// Applying scaling of the object if requested
#ifdef _VERTEX_DISPLACEMENT_LOCK_OBJECT_SCALE
float3 objectScale = GetDisplacementInverseObjectScale();
#if !defined(_LAYER_MAPPING_PLANAR0) && !defined(_LAYER_MAPPING_TRIPLANAR0)
height0 *= objectScale;
#endif
#if !defined(_LAYER_MAPPING_PLANAR1) && !defined(_LAYER_MAPPING_TRIPLANAR1)
height1 *= objectScale;
#endif
#if !defined(_LAYER_MAPPING_PLANAR2) && !defined(_LAYER_MAPPING_TRIPLANAR2)
height2 *= objectScale;
#endif
#if !defined(_LAYER_MAPPING_PLANAR3) && !defined(_LAYER_MAPPING_TRIPLANAR3)
height3 *= objectScale;
#endif
#else
float3 objectScale = float3(1.0, 1.0, 1.0);
#endif
SetEnabledHeightByLayer(height0, height1, height2, height3);
float4 resultBlendMasks = inputBlendMasks;

14
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.hlsl


// http://www.sebastiansylvan.com/post/the-problem-with-tessellation-in-directx-11/
float lod = 0.0;
float height = ComputePerVertexDisplacement(layerTexCoord, vertexColor, lod);
float3 displ = height * normalWS;
// Applying scaling of the object if requested
// Note: In case of planar mapping there is no object scale as we do world space planar mapping (not object space planar mapping)
#ifdef _VERTEX_DISPLACEMENT_LOCK_OBJECT_SCALE
float3 objectScale = GetDisplacementInverseObjectScale(true);
#else
float3 objectScale = float3(1.0, 1.0, 1.0);
#endif
displ *= objectScale;
return displ;
return height * normalWS;
}
void ApplyVertexModification(AttributesMesh input, float3 normalWS, inout float3 positionWS)

正在加载...
取消
保存