浏览代码

Pass terrain layer smoothness and metallic to terrainlit shader and stop using _BaseColor properties.

/main
Yao Xiaoling 6 年前
当前提交
3c65014c
共有 3 个文件被更改,包括 37 次插入29 次删除
  1. 26
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/TerrainLit.shader
  2. 16
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/TerrainLitData.hlsl
  3. 24
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitDataIndividualLayer.hlsl

26
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/TerrainLit.shader


[HideInInspector] _Splat2("Layer 2", 2D) = "white" {}
[HideInInspector] _Splat3("Layer 3", 2D) = "white" {}
// Since we don't use a mask texture for getting the mask, we'll need the metallic property to be serialized as in sRGB space.
[HideInInspector] [Gamma] _Metallic0("Metallic 0", Range(0.0, 1.0)) = 0
[HideInInspector] [Gamma] _Metallic1("Metallic 1", Range(0.0, 1.0)) = 0
[HideInInspector] [Gamma] _Metallic2("Metallic 2", Range(0.0, 1.0)) = 0
[HideInInspector] [Gamma] _Metallic3("Metallic 3", Range(0.0, 1.0)) = 0
[HideInInspector] _Smoothness0("Smoothness0", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness1("Smoothness1", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness2("Smoothness2", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness3("Smoothness3", Range(0.0, 1.0)) = 1.0
// TODO: route values from terrain layers. enable _DENSITY_MODE if any of these enabled.
[HideInInspector] [ToggleUI] _OpacityAsDensity0("_OpacityAsDensity0", Float) = 0.0
[HideInInspector] [ToggleUI] _OpacityAsDensity1("_OpacityAsDensity1", Float) = 0.0

// They are use to fill a SurfaceData. With a MaterialGraph this should not exist.
// All the following properties are filled by the referenced lit shader.
// Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear
_BaseColor0("BaseColor0", Color) = (1, 1, 1, 1)
_BaseColor1("BaseColor1", Color) = (1, 1, 1, 1)
_BaseColor2("BaseColor2", Color) = (1, 1, 1, 1)
_BaseColor3("BaseColor3", Color) = (1, 1, 1, 1)
_Metallic0("Metallic0", Range(0.0, 1.0)) = 0
_Metallic1("Metallic1", Range(0.0, 1.0)) = 0
_Metallic2("Metallic2", Range(0.0, 1.0)) = 0
_Metallic3("Metallic3", Range(0.0, 1.0)) = 0
_Smoothness0("Smoothness0", Range(0.0, 1.0)) = 1.0
_Smoothness1("Smoothness1", Range(0.0, 1.0)) = 1.0
_Smoothness2("Smoothness2", Range(0.0, 1.0)) = 1.0
_Smoothness3("Smoothness3", Range(0.0, 1.0)) = 1.0
_SmoothnessRemapMin0("SmoothnessRemapMin0", Range(0.0, 1.0)) = 0.0
_SmoothnessRemapMin1("SmoothnessRemapMin1", Range(0.0, 1.0)) = 0.0

16
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/TerrainLitData.hlsl


float4 _Splat3_ST;
SAMPLER(sampler_Splat0);
#define _BaseColor0 float4(1,1,1,1)
#define _BaseColor1 float4(1,1,1,1)
#define _BaseColor2 float4(1,1,1,1)
#define _BaseColor3 float4(1,1,1,1)
// Number of sampler are limited, we need to share sampler as much as possible with lit material
// for this we put the constraint that the sampler are the same in a layered material for all textures of the same type
// then we take the sampler matching the first textures use of this type

#define ADD_ZERO_IDX(Name) Name##0
#define _BaseColorMap _Splat
#define sampler_BaseColorMap sampler_Splat
#define ALPHA_USED_AS_SMOOTHNESS
// include LitDataInternal multiple time to define the variation of GetSurfaceData for each layer
#define LAYER_INDEX 0

#undef _THICKNESSMAP_IDX
#undef _MASKMAP_IDX
#undef _BENTNORMALMAP_IDX
#undef ALPHA_USED_AS_SMOOTHNESS
float3 BlendLayeredVector3(float3 x0, float3 x1, float3 x2, float3 x3, float weight[4])
{

// We want to calculate the mean color of the texture. For this we will sample a low mipmap
float textureBias = 15.0; // Use maximum bias
float3 baseMeanColor0 = SAMPLE_UVMAPPING_TEXTURE2D_BIAS(_Splat0, sampler_Splat0, layerTexCoord.base0, textureBias).rgb *_BaseColor0.rgb;
float3 baseMeanColor1 = SAMPLE_UVMAPPING_TEXTURE2D_BIAS(_Splat1, sampler_Splat0, layerTexCoord.base1, textureBias).rgb *_BaseColor1.rgb;
float3 baseMeanColor2 = SAMPLE_UVMAPPING_TEXTURE2D_BIAS(_Splat2, sampler_Splat0, layerTexCoord.base2, textureBias).rgb *_BaseColor2.rgb;
float3 baseMeanColor3 = SAMPLE_UVMAPPING_TEXTURE2D_BIAS(_Splat3, sampler_Splat0, layerTexCoord.base3, textureBias).rgb *_BaseColor3.rgb;
float3 baseMeanColor0 = SAMPLE_UVMAPPING_TEXTURE2D_BIAS(_Splat0, sampler_Splat0, layerTexCoord.base0, textureBias).rgb;
float3 baseMeanColor1 = SAMPLE_UVMAPPING_TEXTURE2D_BIAS(_Splat1, sampler_Splat0, layerTexCoord.base1, textureBias).rgb;
float3 baseMeanColor2 = SAMPLE_UVMAPPING_TEXTURE2D_BIAS(_Splat2, sampler_Splat0, layerTexCoord.base2, textureBias).rgb;
float3 baseMeanColor3 = SAMPLE_UVMAPPING_TEXTURE2D_BIAS(_Splat3, sampler_Splat0, layerTexCoord.base3, textureBias).rgb;
float3 meanColor = BlendLayeredVector3(baseMeanColor0, baseMeanColor1, baseMeanColor2, baseMeanColor3, weights);

24
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitDataIndividualLayer.hlsl


{
float alpha = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_BaseColorMap), ADD_ZERO_IDX(sampler_BaseColorMap), ADD_IDX(layerTexCoord.base)).a * ADD_IDX(_BaseColor).a;
#ifndef ALPHA_USED_AS_SMOOTHNESS
#if defined(_ALPHATEST_ON) && !defined(LAYERED_LIT_SHADER)
float alphaCutoff = _AlphaCutoff;
#ifdef CUTOFF_TRANSPARENT_DEPTH_PREPASS
alphaCutoff = _AlphaCutoffPrepass;
#elif defined(CUTOFF_TRANSPARENT_DEPTH_POSTPASS)
alphaCutoff = _AlphaCutoffPostpass;
#if defined(_ALPHATEST_ON) && !defined(LAYERED_LIT_SHADER)
float alphaCutoff = _AlphaCutoff;
#ifdef CUTOFF_TRANSPARENT_DEPTH_PREPASS
alphaCutoff = _AlphaCutoffPrepass;
#elif defined(CUTOFF_TRANSPARENT_DEPTH_POSTPASS)
alphaCutoff = _AlphaCutoffPostpass;
#endif
DoAlphaTest(alpha, alphaCutoff);
DoAlphaTest(alpha, alphaCutoff);
surfaceData.perceptualSmoothness = 1;
#else
surfaceData.perceptualSmoothness = alpha;
alpha = 1;
#endif
float3 detailNormalTS = float3(0.0, 0.0, 0.0);

bentNormalTS = ADD_IDX(GetBentNormalTS)(input, layerTexCoord, normalTS, detailNormalTS, detailMask);
#if defined(_MASKMAP_IDX)
surfaceData.perceptualSmoothness = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_MaskMap), SAMPLER_MASKMAP_IDX, ADD_IDX(layerTexCoord.base)).a;
surfaceData.perceptualSmoothness *= SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_MaskMap), SAMPLER_MASKMAP_IDX, ADD_IDX(layerTexCoord.base)).a;
surfaceData.perceptualSmoothness = ADD_IDX(_Smoothness);
surfaceData.perceptualSmoothness *= ADD_IDX(_Smoothness);
#endif
#ifdef _DETAIL_MAP_IDX

正在加载...
取消
保存