浏览代码

Fix review comments:

* Put all variables in cbuffer.
* Delete motion vector pass.
* Follow naming convention for basemap gen shader.
/main
Yao Xiaoling 6 年前
当前提交
15531c13
共有 8 个文件被更改,包括 96 次插入133 次删除
  1. 32
      com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLit.shader
  2. 9
      com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLitData.hlsl
  3. 13
      com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLitDataMeshModification.hlsl
  4. 14
      com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLitData_Basemap.hlsl
  5. 81
      com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLitSplatCommon.hlsl
  6. 32
      com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLit_Basemap.shader
  7. 42
      com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLit_Basemap_Gen.shader
  8. 6
      com.unity.render-pipelines.lightweight/LWRP/ShaderLibrary/Terrain/LightweightPassLitTerrain.hlsl

32
com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLit.shader


// variable declaration
//-------------------------------------------------------------------------------------
#include "../../Material/Lit/LitProperties.hlsl"
// All our shaders use same name for entry point
#pragma vertex Vert
#pragma fragment Frag

#include "TerrainLitSharePass.hlsl"
#include "TerrainLitData.hlsl"
#include "../../ShaderPass/ShaderPassLightTransport.hlsl"
ENDHLSL
}
Pass
{
Name "Motion Vectors"
Tags{ "LightMode" = "MotionVectors" } // Caution, this need to be call like this to setup the correct parameters by C++ (legacy Unity)
// If velocity pass (motion vectors) is enabled we tag the stencil so it don't perform CameraMotionVelocity
Stencil
{
WriteMask [_StencilWriteMaskMV]
Ref [_StencilRefMV]
Comp Always
Pass Replace
}
Cull[_CullMode]
ZWrite On
HLSLPROGRAM
#define SHADERPASS SHADERPASS_VELOCITY
#include "../../ShaderVariables.hlsl"
#include "../../Material/Material.hlsl"
#include "../Lit/ShaderPass/LitVelocityPass.hlsl"
#include "TerrainLitData.hlsl"
#include "../../ShaderPass/ShaderPassVelocity.hlsl"
ENDHLSL
}

9
com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLitData.hlsl


#include "CoreRP/ShaderLibrary/Sampling/SampleUVMapping.hlsl"
#include "../MaterialUtilities.hlsl"
// We don't use emission for terrain
#define _EmissiveColor float3(0,0,0)
#define _AlbedoAffectEmissive 0
#include "../Decal/DecalUtilities.hlsl"
#undef _EmissiveColor
#undef _AlbedoAffectEmissive
#include "../Decal/DecalUtilities.hlsl"
#include "TerrainLitDataMeshModification.hlsl"
void GetSurfaceAndBuiltinData(inout FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
{

13
com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLitDataMeshModification.hlsl


#ifdef UNITY_INSTANCING_ENABLED
TEXTURE2D(_TerrainHeightmapTexture);
TEXTURE2D(_TerrainNormalmapTexture);
float4 _TerrainHeightmapRecipSize; // float4(1.0f/width, 1.0f/height, 1.0f/(width-1), 1.0f/(height-1))
float4 _TerrainHeightmapScale; // float4(hmScale.x, hmScale.y / (float)(kMaxHeight), hmScale.z, 0.0f)
#endif
#define API_HAS_GURANTEED_R16_SUPPORT 0 //!(SHADER_API_VULKAN)
#if (API_HAS_GURANTEED_R16_SUPPORT)
return height.r;
#else
// 16-bit height value is packed into two 8-bit channels.
#endif
}
UNITY_INSTANCING_BUFFER_START(Terrain)

14
com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLitData_Basemap.hlsl


#include "CoreRP/ShaderLibrary/Sampling/SampleUVMapping.hlsl"
#include "../MaterialUtilities.hlsl"
#include "../Lit/LitBuiltinData.hlsl"
#include "../Decal/DecalUtilities.hlsl"
TEXTURE2D(_MainTex);
TEXTURE2D(_MetallicTex);
SAMPLER(sampler_MainTex);
// We don't use emission for terrain
#define _EmissiveColor float3(0,0,0)
#define _AlbedoAffectEmissive 0
#include "../Lit/LitBuiltinData.hlsl"
#undef _EmissiveColor
#undef _AlbedoAffectEmissive
#include "TerrainLitDataMeshModification.hlsl"
#include "../Decal/DecalUtilities.hlsl"
#include "TerrainLitSplatCommon.hlsl"
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
{

81
com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLitSplatCommon.hlsl


#define _LAYER_COUNT 4
#endif
#define DECLARE_TERRAIN_LAYER(n) \
TEXTURE2D(_Splat##n); \
TEXTURE2D(_Normal##n); \
TEXTURE2D(_Mask##n); \
float4 _Splat##n##_ST; \
float _Metallic##n; \
float _Smoothness##n; \
float _NormalScale##n; \
float4 _DiffuseRemapScale##n; \
float4 _MaskMapRemapOffset##n; \
float4 _MaskMapRemapScale##n
#define DECLARE_TERRAIN_LAYER_TEXS(n) \
TEXTURE2D(_Splat##n); \
TEXTURE2D(_Normal##n); \
TEXTURE2D(_Mask##n)
DECLARE_TERRAIN_LAYER_TEXS(0);
DECLARE_TERRAIN_LAYER_TEXS(1);
DECLARE_TERRAIN_LAYER_TEXS(2);
DECLARE_TERRAIN_LAYER_TEXS(3);
#ifdef _TERRAIN_8_LAYERS
DECLARE_TERRAIN_LAYER_TEXS(4);
DECLARE_TERRAIN_LAYER_TEXS(5);
DECLARE_TERRAIN_LAYER_TEXS(6);
DECLARE_TERRAIN_LAYER_TEXS(7);
TEXTURE2D(_Control1);
#endif
DECLARE_TERRAIN_LAYER(0);
DECLARE_TERRAIN_LAYER(1);
DECLARE_TERRAIN_LAYER(2);
DECLARE_TERRAIN_LAYER(3);
#undef DECLARE_TERRAIN_LAYER_TEXS
TEXTURE2D(_MainTex);
TEXTURE2D(_MetallicTex);
SAMPLER(sampler_MainTex);
#ifdef _TERRAIN_8_LAYERS
DECLARE_TERRAIN_LAYER(4);
DECLARE_TERRAIN_LAYER(5);
DECLARE_TERRAIN_LAYER(6);
DECLARE_TERRAIN_LAYER(7);
TEXTURE2D(_Control1);
#ifdef UNITY_INSTANCING_ENABLED
TEXTURE2D(_TerrainHeightmapTexture);
TEXTURE2D(_TerrainNormalmapTexture);
#undef DECLARE_TERRAIN_LAYER
#define DECLARE_TERRAIN_LAYER_PROPS(n) \
float4 _Splat##n##_ST; \
float _Metallic##n; \
float _Smoothness##n; \
float _NormalScale##n; \
float4 _DiffuseRemapScale##n; \
float4 _MaskMapRemapOffset##n; \
float4 _MaskMapRemapScale##n
float _HeightTransition;
CBUFFER_START(UnityPerMaterial)
DECLARE_TERRAIN_LAYER_PROPS(0);
DECLARE_TERRAIN_LAYER_PROPS(1);
DECLARE_TERRAIN_LAYER_PROPS(2);
DECLARE_TERRAIN_LAYER_PROPS(3);
#ifdef _TERRAIN_8_LAYERS
DECLARE_TERRAIN_LAYER_PROPS(4);
DECLARE_TERRAIN_LAYER_PROPS(5);
DECLARE_TERRAIN_LAYER_PROPS(6);
DECLARE_TERRAIN_LAYER_PROPS(7);
#endif
float _HeightTransition;
#ifdef UNITY_INSTANCING_ENABLED
float4 _TerrainHeightmapRecipSize; // float4(1.0f/width, 1.0f/height, 1.0f/(width-1), 1.0f/(height-1))
float4 _TerrainHeightmapScale; // float4(hmScale.x, hmScale.y / (float)(kMaxHeight), hmScale.z, 0.0f)
#endif
CBUFFER_END
#undef DECLARE_TERRAIN_LAYER_PROPS
#ifdef HAVE_VERTEX_MODIFICATION
#include "TerrainLitDataMeshModification.hlsl"
#endif
float GetSumHeight(float4 heights0, float4 heights1)
{

32
com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLit_Basemap.shader


// variable declaration
//-------------------------------------------------------------------------------------
#include "../../Material/Lit/LitProperties.hlsl"
// All our shaders use same name for entry point
#pragma vertex Vert
#pragma fragment Frag

#include "TerrainLitSharePass.hlsl"
#include "TerrainLitData_Basemap.hlsl"
#include "../../ShaderPass/ShaderPassLightTransport.hlsl"
ENDHLSL
}
Pass
{
Name "Motion Vectors"
Tags{ "LightMode" = "MotionVectors" } // Caution, this need to be call like this to setup the correct parameters by C++ (legacy Unity)
// If velocity pass (motion vectors) is enabled we tag the stencil so it don't perform CameraMotionVelocity
Stencil
{
WriteMask [_StencilWriteMaskMV]
Ref [_StencilRefMV]
Comp Always
Pass Replace
}
Cull[_CullMode]
ZWrite On
HLSLPROGRAM
#define SHADERPASS SHADERPASS_VELOCITY
#include "../../ShaderVariables.hlsl"
#include "../../Material/Material.hlsl"
#include "../Lit/ShaderPass/LitVelocityPass.hlsl"
#include "TerrainLitData_Basemap.hlsl"
#include "../../ShaderPass/ShaderPassVelocity.hlsl"
ENDHLSL
}

42
com.unity.render-pipelines.high-definition/HDRP/Material/TerrainLit/TerrainLit_Basemap_Gen.shader


#endif
#include "TerrainLitSplatCommon.hlsl"
struct appdata_t {
struct Attributes {
struct v2f
struct Varyings
float4 vertex : SV_POSITION;
float4 positionCS : SV_POSITION;
float2 texcoord : TEXCOORD0;
};

HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma vertex Vert
#pragma fragment Frag
v2f vert(appdata_t v)
Varyings Vert(Attributes input)
v2f o;
o.vertex = TransformWorldToHClip(v.vertex);
o.texcoord = v.texcoord;
return o;
Varyings output;
output.positionCS = TransformWorldToHClip(input.vertex);
output.texcoord = input.texcoord;
return output;
float4 frag(v2f i) : SV_Target
float4 Frag(Varyings input) : SV_Target
TerrainSplatBlend(i.texcoord, float3(0, 0, 0), float3(0, 0, 0),
TerrainSplatBlend(input.texcoord, float3(0, 0, 0), float3(0, 0, 0),
albedo.xyz, normalTS, albedo.w, metallic, ao);
return albedo;

HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma vertex Vert
#pragma fragment Frag
v2f vert(appdata_t v)
Varyings Vert(Attributes input)
v2f o;
o.vertex = TransformWorldToHClip(v.vertex);
o.texcoord = v.texcoord;
return o;
Varyings output;
output.positionCS = TransformWorldToHClip(input.vertex);
output.texcoord = input.texcoord;
return output;
float2 frag(v2f i) : SV_Target
float2 Frag(Varyings input) : SV_Target
TerrainSplatBlend(i.texcoord, float3(0, 0, 0), float3(0, 0, 0),
TerrainSplatBlend(input.texcoord, float3(0, 0, 0), float3(0, 0, 0),
albedo.xyz, normalTS, albedo.w, metallic, ao);
return float2(metallic, ao);

6
com.unity.render-pipelines.lightweight/LWRP/ShaderLibrary/Terrain/LightweightPassLitTerrain.hlsl


float4 _TerrainHeightmapScale; // float4(hmScale.x, hmScale.y / (float)(kMaxHeight), hmScale.z, 0.0f)
#endif
#define API_HAS_GURANTEED_R16_SUPPORT 0 //!(SHADER_API_VULKAN)
#if (API_HAS_GURANTEED_R16_SUPPORT)
return height.r;
#else
// 16-bit height value is packed into two 8-bit channels.
#endif
}
UNITY_INSTANCING_BUFFER_START(Terrain)

正在加载...
取消
保存